diff options
-rw-r--r-- | endless/eoswindow.c | 65 | ||||
-rw-r--r-- | test/smoke-tests/large-content.js | 2 |
2 files changed, 64 insertions, 3 deletions
diff --git a/endless/eoswindow.c b/endless/eoswindow.c index 3037e4f..cabf94b 100644 --- a/endless/eoswindow.c +++ b/endless/eoswindow.c @@ -414,12 +414,67 @@ eos_window_set_property (GObject *object, } } +/* Clamp our size request calls so we never ask for a minimal size greater than + the available work area. */ +static void +clamp_size_request (GtkWidget *widget, + GtkOrientation orientation, + gint *minimum_size, + gint *natural_size) +{ + + if (gtk_widget_get_realized (widget)) + { + GdkScreen *default_screen = gdk_screen_get_default (); + GdkWindow *gdkwindow = gtk_widget_get_window (widget); + int monitor = gdk_screen_get_monitor_at_window (default_screen, gdkwindow); + GdkRectangle workarea; + gdk_screen_get_monitor_workarea (default_screen, monitor, &workarea); + gint available_size = workarea.width; + gchar *orientation_string = "width"; + if (orientation == GTK_ORIENTATION_VERTICAL) + { + available_size = workarea.height; + orientation_string = "height"; + } + + if (*minimum_size > available_size) + { + g_critical ("Requested window %s %d greater than available work area %s %d. " \ + "Clamping size request to fit. This means there is a bug in your " \ + "program, and it is not ready for production. Try checking if any " \ + "of your widgets have minimum size requests that make the page not " \ + "able to fit on the screen.", + orientation_string, + *minimum_size, + orientation_string, + available_size); + *minimum_size = available_size; + *natural_size = MAX (*minimum_size, *natural_size); + } + } +} + +static void +eos_window_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width) +{ + GTK_WIDGET_CLASS (eos_window_parent_class)->get_preferred_width (widget, + minimum_width, natural_width); + + clamp_size_request (widget, + GTK_ORIENTATION_HORIZONTAL, + minimum_width, + natural_width); +} + /* Piggy-back on the parent class's get_preferred_height(), but add the height of our top bar. Do not assume any borders on the top bar. */ static void eos_window_get_preferred_height (GtkWidget *widget, - int *minimum_height, - int *natural_height) + gint *minimum_height, + gint *natural_height) { EosWindow *self = EOS_WINDOW (widget); EosWindowPrivate *priv = eos_window_get_instance_private (self); @@ -433,6 +488,11 @@ eos_window_get_preferred_height (GtkWidget *widget, *minimum_height += top_bar_minimum; if (natural_height != NULL) *natural_height += top_bar_natural; + + clamp_size_request (widget, + GTK_ORIENTATION_VERTICAL, + minimum_height, + natural_height); } /* Remove space for our top bar from the allocation before doing a normal @@ -547,6 +607,7 @@ eos_window_class_init (EosWindowClass *klass) gtk_window_set_titlebar(), available from GTK >= 3.10. But for now we are targeting GTK 3.8. Issue: [endlessm/eos-sdk#28] */ widget_class->get_preferred_height = eos_window_get_preferred_height; + widget_class->get_preferred_width = eos_window_get_preferred_width; widget_class->size_allocate = eos_window_size_allocate; widget_class->map = eos_window_map; widget_class->unmap = eos_window_unmap; diff --git a/test/smoke-tests/large-content.js b/test/smoke-tests/large-content.js index da34f53..d554a1a 100644 --- a/test/smoke-tests/large-content.js +++ b/test/smoke-tests/large-content.js @@ -22,7 +22,7 @@ const TestApplication = new Lang.Class ({ new Gdk.RGBA({ red: 0, green: 0, blue: 1, alpha: 1 })); big_button.override_background_color(Gtk.StateFlags.ACTIVE, new Gdk.RGBA({ red: 1, green: 0, blue: 0, alpha: 1 })); - //big_button.set_size_request(9999, 9999); + big_button.set_size_request(3000, 2000); let window = new Endless.Window({ application: this |