[GTK3] Prevent startup crash on Wayland sessions
This commit is contained in:
parent
65fe7f2f9c
commit
f46d35528b
28
gtk3/main.c
28
gtk3/main.c
@ -110,6 +110,8 @@ typedef struct GuiData {
|
||||
bool is_fullscreen;
|
||||
bool supports_gl;
|
||||
shader_t shader;
|
||||
unsigned last_screen_width;
|
||||
unsigned last_screen_height;
|
||||
|
||||
// Fast forward / slow motion
|
||||
bool underclock_down;
|
||||
@ -974,6 +976,14 @@ static void action_entries_set_enabled(const GActionEntry *entries, unsigned n_e
|
||||
}
|
||||
|
||||
static void update_window_geometry(void) {
|
||||
g_debug("update_window_geometry: %u×%u → %u×%u", gui_data.last_screen_width, gui_data.last_screen_height, GB_get_screen_width(&gb), GB_get_screen_height(&gb));
|
||||
|
||||
GtkWidget *w = gui_data.fallback_canvas ? GTK_WIDGET(gui_data.fallback_canvas) : GTK_WIDGET(gui_data.gl_area);
|
||||
int win_width = gtk_widget_get_allocated_width(w);
|
||||
int win_height = gtk_widget_get_allocated_height(w);
|
||||
unsigned new_width = GB_get_screen_width(&gb) * 2;
|
||||
unsigned new_height = GB_get_screen_height(&gb) * 2;
|
||||
|
||||
// Set size hints
|
||||
GdkGeometry hints;
|
||||
hints.min_width = GB_get_screen_width(&gb);
|
||||
@ -986,10 +996,9 @@ static void update_window_geometry(void) {
|
||||
(GdkWindowHints)(GDK_HINT_MIN_SIZE)
|
||||
);
|
||||
|
||||
gtk_window_resize(GTK_WINDOW(gui_data.main_window),
|
||||
GB_get_screen_width(&gb) * 2,
|
||||
GB_get_screen_height(&gb) * 2
|
||||
);
|
||||
if (new_width > win_width || new_height > win_height) {
|
||||
gtk_window_resize(GTK_WINDOW(gui_data.main_window), new_width, new_height);
|
||||
}
|
||||
|
||||
// Setup our image buffers
|
||||
if (gui_data.image_buffers[0]) g_free(gui_data.image_buffers[0]);
|
||||
@ -1002,6 +1011,9 @@ static void update_window_geometry(void) {
|
||||
gui_data.image_buffers[1] = g_malloc0(buffer_size);
|
||||
gui_data.image_buffers[2] = g_malloc0(buffer_size);
|
||||
|
||||
gui_data.last_screen_width = GB_get_screen_width(&gb);
|
||||
gui_data.last_screen_height = GB_get_screen_height(&gb);
|
||||
|
||||
if (GB_is_inited(&gb)) {
|
||||
GB_set_pixels_output(&gb, get_pixels());
|
||||
}
|
||||
@ -1475,12 +1487,8 @@ static void reset(void) {
|
||||
|
||||
gui_data.prev_model = get_model();
|
||||
|
||||
GtkRequisition minimum_size;
|
||||
GtkRequisition natural_size;
|
||||
gtk_widget_get_preferred_size(GTK_WIDGET(gui_data.main_window), &minimum_size, &natural_size);
|
||||
|
||||
// Check SGB -> non-SGB and non-SGB to SGB transitions
|
||||
if (GB_get_screen_width(&gb) != minimum_size.width || GB_get_screen_height(&gb) != minimum_size.height) {
|
||||
if (GB_get_screen_width(&gb) != gui_data.last_screen_width || GB_get_screen_height(&gb) != gui_data.last_screen_height) {
|
||||
update_window_geometry();
|
||||
}
|
||||
|
||||
@ -1948,6 +1956,8 @@ static void on_vram_tab_change(GtkWidget *widget, GParamSpec *pspec, GtkStackSwi
|
||||
static void startup(GApplication *app, gpointer null_ptr) {
|
||||
signal(SIGINT, quit_interrupt);
|
||||
|
||||
g_debug("GTK version %u.%u.%u", gtk_get_major_version(), gtk_get_minor_version(), gtk_get_micro_version());
|
||||
|
||||
// Very ugly workaround for GtkGlArea!
|
||||
// When a GtkGlArea is realized and it creates a legacy GL 1.4 context
|
||||
// it tries to use GL 2.0 functions to render the window which leads to the application crashing.
|
||||
|
Loading…
Reference in New Issue
Block a user