From 777048f6f9c679d67af6171011fb903f6eb6769f Mon Sep 17 00:00:00 2001 From: Matt Watson Date: Mon, 9 Dec 2013 14:37:38 -0800 Subject: Warn when window minimal size is greater than screen size test/smoke-tests/large-content.js shows the warnings in action [endlessm/eos-sdk#191] --- endless/eoswindow.c | 55 +++++++++++++++++++++++++++++++++++++-- test/smoke-tests/large-content.js | 2 +- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/endless/eoswindow.c b/endless/eoswindow.c index 3037e4f..3d7b9bd 100644 --- a/endless/eoswindow.c +++ b/endless/eoswindow.c @@ -414,12 +414,57 @@ eos_window_set_property (GObject *object, } } +static void +check_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", + orientation_string, + minimum_size, + orientation_string, + available_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); + + check_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 +478,11 @@ eos_window_get_preferred_height (GtkWidget *widget, *minimum_height += top_bar_minimum; if (natural_height != NULL) *natural_height += top_bar_natural; + + check_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 +597,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 -- cgit v1.2.3 From 2fb947b8e3dddec3357a2e7b388d898c2789f5a7 Mon Sep 17 00:00:00 2001 From: Matt Watson Date: Mon, 9 Dec 2013 14:55:23 -0800 Subject: Clamp minimal size request for windows to fit inside screen This clamping code should not be used in anything production. If you see a warning about your minimal size request being to large fix the size request [endlessm/eos-sdk#191] --- endless/eoswindow.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/endless/eoswindow.c b/endless/eoswindow.c index 3d7b9bd..7eefe30 100644 --- a/endless/eoswindow.c +++ b/endless/eoswindow.c @@ -414,11 +414,13 @@ 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 -check_size_request (GtkWidget *widget, +clamp_size_request (GtkWidget *widget, GtkOrientation orientation, - gint minimum_size, - gint natural_size) + gint *minimum_size, + gint *natural_size) { if (gtk_widget_get_realized (widget)) @@ -436,12 +438,17 @@ check_size_request (GtkWidget *widget, orientation_string = "height"; } - if (minimum_size > available_size) - g_critical ("Requested window %s %d greater than available work area %s %d", - orientation_string, - minimum_size, - orientation_string, - available_size); + if (*minimum_size > available_size) + { + g_critical ("Requested window %s %d greater than available work area %s %d. " \ + "Clamping size request to fit.", + orientation_string, + *minimum_size, + orientation_string, + available_size); + *minimum_size = available_size; + *natural_size = MAX (*minimum_size, *natural_size); + } } } @@ -453,10 +460,10 @@ eos_window_get_preferred_width (GtkWidget *widget, GTK_WIDGET_CLASS (eos_window_parent_class)->get_preferred_width (widget, minimum_width, natural_width); - check_size_request (widget, + clamp_size_request (widget, GTK_ORIENTATION_HORIZONTAL, - *minimum_width, - *natural_width); + minimum_width, + natural_width); } /* Piggy-back on the parent class's get_preferred_height(), but add the @@ -479,10 +486,10 @@ eos_window_get_preferred_height (GtkWidget *widget, if (natural_height != NULL) *natural_height += top_bar_natural; - check_size_request (widget, + clamp_size_request (widget, GTK_ORIENTATION_VERTICAL, - *minimum_height, - *natural_height); + minimum_height, + natural_height); } /* Remove space for our top bar from the allocation before doing a normal -- cgit v1.2.3 From 090d7bf137d94d1bf76eac3706adaa3fec71a623 Mon Sep 17 00:00:00 2001 From: Matt Watson Date: Tue, 10 Dec 2013 14:39:31 -0800 Subject: Added nicer warning message when clamping size request [endlessm/eos-sdk#191] --- endless/eoswindow.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/endless/eoswindow.c b/endless/eoswindow.c index 7eefe30..cabf94b 100644 --- a/endless/eoswindow.c +++ b/endless/eoswindow.c @@ -441,7 +441,10 @@ clamp_size_request (GtkWidget *widget, if (*minimum_size > available_size) { g_critical ("Requested window %s %d greater than available work area %s %d. " \ - "Clamping size request to fit.", + "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, -- cgit v1.2.3