summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2017-04-14 12:32:41 +0200
committerraveit65 <[email protected]>2017-04-14 16:01:23 +0200
commit8140e40379ce94f975c65a8bf2e11c636998c05c (patch)
tree96dc6de8c9c8988c6a3d9f3d245721ff88c388d9
parent1042cd8eeac2dc10114ab9e35f6e066c5e131ec0 (diff)
downloadcaja-8140e40379ce94f975c65a8bf2e11c636998c05c.tar.bz2
caja-8140e40379ce94f975c65a8bf2e11c636998c05c.tar.xz
Add size_request to IconContainer to work around uncecessary relayouting
The GtkScrolledWindow uses the widget prefered size as a guess as to whether scrollbars are needed or not in the automatic scrollbars case. If we don't report anything for them we typically get it wrong and cause two size allocate calls on the child each time, with different sizes. This (the two sizes speicifically) will cause unnecessary relayouts of the window. So, we just report the current size of the layed out icons as the prefered size. This is somewhat wrong as its depending on previous size_allocation calls rather than the "ideal" size of the widget, but since the ideal size is ignored anyway and just used for this it works well. taken from: https://git.gnome.org/browse/nautilus/commit/?id=fa6e447
-rw-r--r--libcaja-private/caja-icon-container.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c
index 1c61184d..6e95d4b6 100644
--- a/libcaja-private/caja-icon-container.c
+++ b/libcaja-private/caja-icon-container.c
@@ -4701,6 +4701,67 @@ size_allocate (GtkWidget *widget,
}
#if GTK_CHECK_VERSION (3, 0, 0)
+static GtkSizeRequestMode
+get_request_mode (GtkWidget *widget)
+{
+ /* Don't trade size at all, since we get whatever we get anyway. */
+ return GTK_SIZE_REQUEST_CONSTANT_SIZE;
+}
+
+ /* We need to implement these since the GtkScrolledWindow uses them
+ to guess whether to show scrollbars or not, and if we don't report
+ anything it'll tend to get it wrong causing double calls
+ to size_allocate (at different sizes) during its size allocation. */
+static void
+get_prefered_width (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ EelCanvasGroup *root;
+ double x1, x2;
+ int cx1, cx2;
+ int width;
+
+ root = eel_canvas_root (EEL_CANVAS (widget));
+ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (root),
+ &x1, NULL, &x2, NULL);
+ eel_canvas_w2c (EEL_CANVAS (widget), x1, 0, &cx1, NULL);
+ eel_canvas_w2c (EEL_CANVAS (widget), x2, 0, &cx2, NULL);
+
+ width = cx2 - cx1;
+ if (natural_size) {
+ *natural_size = width;
+ }
+ if (minimum_size) {
+ *minimum_size = width;
+ }
+}
+
+static void
+get_prefered_height (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ EelCanvasGroup *root;
+ double y1, y2;
+ int cy1, cy2;
+ int height;
+
+ root = eel_canvas_root (EEL_CANVAS (widget));
+ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (root),
+ NULL, &y1, NULL, &y2);
+ eel_canvas_w2c (EEL_CANVAS (widget), 0, y1, NULL, &cy1);
+ eel_canvas_w2c (EEL_CANVAS (widget), 0, y2, NULL, &cy2);
+
+ height = cy2 - cy1;
+ if (natural_size) {
+ *natural_size = height;
+ }
+ if (minimum_size) {
+ *minimum_size = height;
+ }
+}
+
static gboolean
draw (GtkWidget *widget, cairo_t *cr)
{
@@ -6766,6 +6827,9 @@ caja_icon_container_class_init (CajaIconContainerClass *class)
widget_class = GTK_WIDGET_CLASS (class);
widget_class->size_allocate = size_allocate;
#if GTK_CHECK_VERSION (3, 0, 0)
+ widget_class->get_request_mode = get_request_mode;
+ widget_class->get_preferred_width = get_prefered_width;
+ widget_class->get_preferred_height = get_prefered_height;
widget_class->draw = draw;
#endif
widget_class->realize = realize;