diff options
author | raveit65 <[email protected]> | 2017-04-07 15:07:39 +0200 |
---|---|---|
committer | raveit65 <[email protected]> | 2017-04-15 19:01:37 +0200 |
commit | 7773a9a4b65c5219f57c344925ffd94d30367c0b (patch) | |
tree | a362ac49220c1cbb0f0e7e180727a8fc390f75cf /libcaja-private | |
parent | 78814d408a684ca88858254effdd8223a9621c2b (diff) | |
download | caja-7773a9a4b65c5219f57c344925ffd94d30367c0b.tar.bz2 caja-7773a9a4b65c5219f57c344925ffd94d30367c0b.tar.xz |
Add size_request to IconContainer to work around unncecessary
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
Diffstat (limited to 'libcaja-private')
-rw-r--r-- | libcaja-private/caja-icon-container.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 75ecefc0..1a92caec 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -4518,6 +4518,67 @@ size_allocate (GtkWidget *widget, } } +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) { @@ -6519,6 +6580,9 @@ caja_icon_container_class_init (CajaIconContainerClass *class) widget_class = GTK_WIDGET_CLASS (class); widget_class->size_allocate = size_allocate; + 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; widget_class->realize = realize; widget_class->unrealize = unrealize; |