[Xfce4-commits] <xfwm4:master> Shrink the app icon when out of space

Nick Schermer noreply at xfce.org
Sun Feb 23 21:10:33 CET 2014


Updating branch refs/heads/master
         to 3658e525ac0952a1f98ac7bad59d6a5c4aa8e22c (commit)
       from 3cd369280609cc0e1b3d4ea0be164897a323595d (commit)

commit 3658e525ac0952a1f98ac7bad59d6a5c4aa8e22c
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Sun Dec 15 11:46:25 2013 +0300

    Shrink the app icon when out of space
    
    In the standard icon grid and there's a lot of windows to display,
    shrink the icon size until all the windows will fit. This does it
    by halving the current icon size. If the icon size goes below 8,
    it will stop there so the icons are still present.
    
    Signed-off-by: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>

 src/tabwin.c |   30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/tabwin.c b/src/tabwin.c
index c5d8846..0c6e5f1 100644
--- a/src/tabwin.c
+++ b/src/tabwin.c
@@ -453,10 +453,32 @@ createWindowlist (ScreenInfo *screen_info, TabwinWidget *tbw)
     gtk_widget_style_get (GTK_WIDGET (tbw), "icon-size", &icon_size, NULL);
     tbw->widgets = NULL;
 
+    /* We need to account for changes to the font size in the user's
+     * appearance theme and gtkrc settings */
+    layout = gtk_widget_create_pango_layout (GTK_WIDGET (tbw), "");
+    pango_layout_get_pixel_size (layout, NULL, &app_label_height);
+    g_object_unref (layout);
+
     if (screen_info->params->cycle_tabwin_mode == STANDARD_ICON_GRID)
     {
-        tbw->grid_cols = (monitor_width / (icon_size + 2 * WIN_ICON_BORDER)) * 0.75;
+        tbw->grid_cols = (monitor_width / (icon_size+app_label_height+10)) * 0.75;
         tbw->grid_rows = screen_info->client_count / tbw->grid_cols + 1;
+
+        /* If we run out of space, halve the icon size to make more room. */
+        while ((icon_size + app_label_height + 10) * tbw->grid_rows > monitor_height - app_label_height)
+        {
+            icon_size = icon_size / 2;
+            /* recalculate with new icon size */
+            tbw->grid_cols = (monitor_width / (icon_size+app_label_height+10)) * 0.75;
+            tbw->grid_rows = screen_info->client_count / tbw->grid_cols + 1;
+
+            /* Shrinking the icon too much makes it hard to see */
+            if (icon_size < 8)
+            {
+                icon_size = 8;
+                break;
+            }
+        }
     }
     else
     {
@@ -481,12 +503,6 @@ createWindowlist (ScreenInfo *screen_info, TabwinWidget *tbw)
         g_signal_connect (window_button, "leave-notify-event", G_CALLBACK (cb_window_button_leave), tbw);
         gtk_widget_add_events (window_button, GDK_ENTER_NOTIFY_MASK);
 
-        /* We need to account for changes to the font size in the user's
-         * appearance theme and gtkrc settings */
-        layout = gtk_widget_create_pango_layout (GTK_WIDGET (tbw), "");
-        pango_layout_get_pixel_size (layout, NULL, &app_label_height);
-        g_object_unref (layout);
-
         if (screen_info->params->cycle_tabwin_mode == STANDARD_ICON_GRID)
         {
             gtk_widget_set_size_request (GTK_WIDGET (window_button), icon_size+app_label_height+10, icon_size+app_label_height+10);


More information about the Xfce4-commits mailing list