From 045c319f2655fc45c24951479eb9cd1e59792cef Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 2 Apr 2011 04:10:09 +0200 Subject: [PATCH] simple-greeter: Don't request an invalid size GTK widgets must at all times report a size they can handle. So it is not allowed to return 0 when not realized, because then size allocations break when GTK uses this size for its widget. In this case, GTK uses the pre-realize size to determine the size it should request when creating the greeter window - chicken and egg so to say. This patch just uses the default monitor (I guess the root window's monitor is the default monitor?) for determining the login window size. One thing this patch doesn't do is add a call to gtk_widget_queue_resize() from the realize callback or from monitor-changing signals, though that's probably technically necessary. https://bugzilla.gnome.org/show_bug.cgi?id=646498 --- gui/simple-greeter/gdm-greeter-login-window.c | 28 +++++++++---------------- 1 files changed, 10 insertions(+), 18 deletions(-) diff --git a/gui/simple-greeter/gdm-greeter-login-window.c b/gui/simple-greeter/gdm-greeter-login-window.c index abd6707..3ec9a09 100644 --- a/gui/simple-greeter/gdm-greeter-login-window.c +++ b/gui/simple-greeter/gdm-greeter-login-window.c @@ -1413,25 +1413,22 @@ gdm_greeter_login_window_get_preferred_width (GtkWidget *widget, { int monitor; GdkScreen *screen; + GdkWindow *window; GdkRectangle area; GtkAllocation widget_allocation; int min_size; int nat_size; - min_size = 0; - nat_size = 0; - - if (!gtk_widget_get_realized (widget)) { - goto out; - } - gtk_widget_get_preferred_width (gtk_bin_get_child (GTK_BIN (widget)), &min_size, &nat_size); /* Make width be at least 33% screen width */ screen = gtk_widget_get_screen (widget); - monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (widget)); + window = gtk_widget_get_window (widget); + if (window == NULL) + window = gdk_screen_get_root_window (screen); + monitor = gdk_screen_get_monitor_at_window (screen, window); gdk_screen_get_monitor_geometry (screen, monitor, &area); min_size = MAX (min_size, .33 * area.width); nat_size = MAX (nat_size, .33 * area.width); @@ -1442,7 +1439,6 @@ gdm_greeter_login_window_get_preferred_width (GtkWidget *widget, min_size = MAX (min_size, widget_allocation.width); nat_size = MAX (nat_size, widget_allocation.width); - out: if (minimum_size) *minimum_size = min_size; if (natural_size) @@ -1456,29 +1452,25 @@ gdm_greeter_login_window_get_preferred_height (GtkWidget *widget, { int monitor; GdkScreen *screen; + GdkWindow *window; GdkRectangle area; int min_size; int nat_size; - min_size = 0; - nat_size = 0; - - if (!gtk_widget_get_realized (widget)) { - goto out; - } - gtk_widget_get_preferred_height (gtk_bin_get_child (GTK_BIN (widget)), &min_size, &nat_size); /* Make height be at most 80% of screen height */ screen = gtk_widget_get_screen (widget); - monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (widget)); + window = gtk_widget_get_window (widget); + if (window == NULL) + window = gdk_screen_get_root_window (screen); + monitor = gdk_screen_get_monitor_at_window (screen, window); gdk_screen_get_monitor_geometry (screen, monitor, &area); min_size = MIN (min_size, .8 * area.height); nat_size = MIN (nat_size, .8 * area.height); - out: if (minimum_size) *minimum_size = min_size; if (natural_size) -- 1.7.4