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(-) (limited to 'endless') 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