summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Watson <mattdangerw@gmail.com>2013-12-09 14:55:23 -0800
committerMatt Watson <mattdangerw@gmail.com>2013-12-10 14:36:54 -0800
commit2fb947b8e3dddec3357a2e7b388d898c2789f5a7 (patch)
tree8b3d8f957dbd822c0e041f6a4f8e757bd43780fa
parent777048f6f9c679d67af6171011fb903f6eb6769f (diff)
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]
-rw-r--r--endless/eoswindow.c37
1 files 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