]> Dogcows Code - chaz/openbox/blobdiff - openbox/focus_cycle_popup.c
round up rather than down for figuring out the width of the popup, so it will fit...
[chaz/openbox] / openbox / focus_cycle_popup.c
index dfa2ff4d7857d7feaafab69b0dbd56186680cf45..92f0c0c99fd2070dc79a4f1a889c435ce95eb419 100644 (file)
@@ -32,6 +32,8 @@
 
 #define ICON_SIZE 48
 #define ICON_HILITE_WIDTH 2
+#define ICON_HILITE_MARGIN 1
+#define OUTSIDE_BORDER 3
 
 typedef struct _ObFocusCyclePopup       ObFocusCyclePopup;
 typedef struct _ObFocusCyclePopupTarget ObFocusCyclePopupTarget;
@@ -53,7 +55,7 @@ struct _ObFocusCyclePopup
     GList *targets;
     gint n_targets;
 
-    ObFocusCyclePopupTarget *last_target;
+    const ObFocusCyclePopupTarget *last_target;
 
     gint maxtextw;
 
@@ -69,9 +71,13 @@ struct _ObFocusCyclePopup
 static ObFocusCyclePopup popup;
 
 static gchar *popup_get_name (ObClient *c);
-static void   popup_setup    (ObFocusCyclePopup *p,gboolean all_desktops,
-                              gboolean dock_windows, gboolean desktop_windows);
-static void   popup_render   (ObFocusCyclePopup *p, const ObClient *c);
+static void   popup_setup    (ObFocusCyclePopup *p,
+                              gboolean iconic_windows,
+                              gboolean all_desktops,
+                              gboolean dock_windows,
+                              gboolean desktop_windows);
+static void   popup_render   (ObFocusCyclePopup *p,
+                              const ObClient *c);
 
 static Window create_window(Window parent, guint bwidth, gulong mask,
                             XSetWindowAttributes *attr)
@@ -140,7 +146,8 @@ void focus_cycle_popup_shutdown(gboolean reconfig)
     RrAppearanceFree(popup.a_bg);
 }
 
-static void popup_setup(ObFocusCyclePopup *p,gboolean all_desktops,
+static void popup_setup(ObFocusCyclePopup *p,
+                        gboolean iconic_windows, gboolean all_desktops,
                         gboolean dock_windows, gboolean desktop_windows)
 {
     gint maxwidth, n;
@@ -159,6 +166,7 @@ static void popup_setup(ObFocusCyclePopup *p,gboolean all_desktops,
         ObClient *ft = it->data;
 
         if (focus_cycle_target_valid(ft,
+                                     iconic_windows,
                                      all_desktops,
                                      dock_windows,
                                      desktop_windows))
@@ -218,13 +226,16 @@ static gchar *popup_get_name(ObClient *c)
 
 static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
 {
+    gint ml, mt, mr, mb;
     gint l, t, r, b;
     gint x, y, w, h;
     Rect *screen_area;
     gint icons_per_row;
     gint icon_rows;
     gint textx, texty, textw, texth;
-    gint iconw, iconh;
+    gint rgbax, rgbay, rgbaw, rgbah;
+    gint icons_center_x;
+    gint innerw, innerh;
     gint i;
     GList *it;
     const ObFocusCyclePopupTarget *newtarget;
@@ -234,15 +245,17 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
     screen_area = screen_physical_area_monitor(0);
 
     /* get the outside margins */
-    RrMargins(p->a_bg, &l, &t, &r, &b);
-    l += ob_rr_theme->paddingx;
-    r += ob_rr_theme->paddingx;
-    t += ob_rr_theme->paddingy;
-    b += ob_rr_theme->paddingy;
+    RrMargins(p->a_bg, &ml, &mt, &mr, &mb);
 
-    /* get the icons sizes */
-    iconw = ICON_SIZE - (ICON_HILITE_WIDTH + ob_rr_theme->paddingx) * 2;
-    iconh = ICON_SIZE - (ICON_HILITE_WIDTH + ob_rr_theme->paddingy) * 2;
+    /* get our outside borders */
+    l = ml + OUTSIDE_BORDER;
+    r = mr + OUTSIDE_BORDER;
+    t = mt + OUTSIDE_BORDER;
+    b = mb + OUTSIDE_BORDER;
+
+    /* get the icon pictures' sizes */
+    innerw = ICON_SIZE - (ICON_HILITE_WIDTH + ICON_HILITE_MARGIN) * 2;
+    innerh = ICON_SIZE - (ICON_HILITE_WIDTH + ICON_HILITE_MARGIN) * 2;
 
     /* get the width from the text and keep it within limits */
     w = l + r + p->maxtextw;
@@ -251,7 +264,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
 
     /* how many icons will fit in that row? make the width fit that */
     w -= l + r;
-    icons_per_row = w / ICON_SIZE;
+    icons_per_row = (w + ICON_SIZE - 1) / ICON_SIZE;
     w = icons_per_row * ICON_SIZE + l + r;
 
     /* how many rows do we need? */
@@ -262,11 +275,11 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
     texth = RrMinHeight(p->a_text);
 
     /* find the height of the dialog */
-    h = t + b + (icon_rows * ICON_SIZE) + (ob_rr_theme->paddingy + texth);
+    h = t + b + (icon_rows * ICON_SIZE) + (OUTSIDE_BORDER + texth);
 
     /* get the position of the text */
     textx = l;
-    texty = h - texth;
+    texty = h - texth - b;
 
     /* find the position for the popup (include the outer borders) */
     x = screen_area->x + (screen_area->width -
@@ -274,14 +287,26 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
     y = screen_area->y + (screen_area->height -
                           (h + ob_rr_theme->fbwidth * 2)) / 2;
 
+    /* get the dimensions of the target hilite texture */
+    rgbax = ml;
+    rgbay = mt;
+    rgbaw = w - ml - mr;
+    rgbah = h - mt - mb;
+
+    /* center the icons if there is less than one row */
+    if (icon_rows == 1)
+        icons_center_x = (w - p->n_targets * ICON_SIZE) / 2;
+    else
+        icons_center_x;
+
     if (!p->mapped) {
         /* position the background but don't draw it*/
         XMoveResizeWindow(ob_display, p->bg, x, y, w, h);
 
         /* set up the hilite texture for the background */
-        p->a_bg->texture[0].data.rgba.width = w;
-        p->a_bg->texture[0].data.rgba.height = h;
-        p->hilite_rgba = g_new(RrPixel32, w * h);
+        p->a_bg->texture[0].data.rgba.width = rgbaw;
+        p->a_bg->texture[0].data.rgba.height = rgbah;
+        p->hilite_rgba = g_new(RrPixel32, rgbaw * rgbah);
         p->a_bg->texture[0].data.rgba.data = p->hilite_rgba;
 
         /* position the text, but don't draw it */
@@ -299,7 +324,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
         if (target->client == c) {
             /* save the target */
             newtarget = target;
-            newtargetx = l + (col * ICON_SIZE);
+            newtargetx = icons_center_x + l + (col * ICON_SIZE);
             newtargety = t + (row * ICON_SIZE);
 
             if (!p->mapped)
@@ -311,29 +336,40 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
 
     /* create the hilite under the target icon */
     {
-        RrPixel32 color = 0;
-        gint i, j;
+        RrPixel32 color;
+        gint i, j, o;
 
-        memset(p->hilite_rgba, color, w * h * sizeof(RrPixel32));
+        color = ((ob_rr_theme->osd_color->r & 0xff) << RrDefaultRedOffset) +
+            ((ob_rr_theme->osd_color->g & 0xff) << RrDefaultGreenOffset) +
+            ((ob_rr_theme->osd_color->b & 0xff) << RrDefaultBlueOffset);
 
-        for (i = 0; i < ICON_SIZE; ++i)
-            for (j = 0; j < ICON_SIZE; ++j) {
+        o = 0;
+        for (i = 0; i < rgbah; ++i)
+            for (j = 0; j < rgbaw; ++j) {
                 guchar a;
+                const gint x = j + rgbax - newtargetx;
+                const gint y = i + rgbay - newtargety;
 
-                if (i < ICON_HILITE_WIDTH ||
-                    i >= ICON_SIZE-ICON_HILITE_WIDTH ||
-                    j < ICON_HILITE_WIDTH ||
-                    j >= ICON_SIZE-ICON_HILITE_WIDTH)
+                if (x < 0 || x >= ICON_SIZE ||
+                    y < 0 || y >= ICON_SIZE)
+                {
+                    /* outside the target */
+                    a = 0x00;
+                }
+                else if (x < ICON_HILITE_WIDTH ||
+                         x >= ICON_SIZE - ICON_HILITE_WIDTH ||
+                         y < ICON_HILITE_WIDTH ||
+                         y >= ICON_SIZE - ICON_HILITE_WIDTH)
                 {
                     /* the border of the target */
                     a = 0x88;
                 }
                 else {
                     /* the background of the target */
-                    a = 0x33;
+                    a = 0x22;
                 }
 
-                p->hilite_rgba[(i+newtargety) * w + (j+newtargetx)] =
+                p->hilite_rgba[o++] =
                     color + (a << RrDefaultAlphaOffset);
             }
     }
@@ -353,28 +389,28 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
             const ObClientIcon *icon;
             const gint row = i / icons_per_row; /* starting from 0 */
             const gint col = i % icons_per_row; /* starting from 0 */
-            gint iconx, icony;
+            gint innerx, innery;
 
             /* find the dimensions of the icon inside it */
-            iconx = l + (col * ICON_SIZE) + ICON_HILITE_WIDTH +
-                ob_rr_theme->paddingx;
-            icony = t + (row * ICON_SIZE) + ICON_HILITE_WIDTH +
-                ob_rr_theme->paddingy;
+            innerx = icons_center_x + l + (col * ICON_SIZE);
+            innerx += ICON_HILITE_WIDTH + ICON_HILITE_MARGIN;
+            innery = t + (row * ICON_SIZE);
+            innery += ICON_HILITE_WIDTH + ICON_HILITE_MARGIN;
 
             /* move the icon */
             XMoveResizeWindow(ob_display, target->win,
-                              iconx, icony, iconw, iconh);
+                              innerx, innery, innerw, innerh);
 
             /* get the icon from the client */
-            icon = client_icon(target->client, iconw, iconh);
+            icon = client_icon(target->client, innerw, innerh);
             p->a_icon->texture[0].data.rgba.width = icon->width;
             p->a_icon->texture[0].data.rgba.height = icon->height;
             p->a_icon->texture[0].data.rgba.data = icon->data;
 
             /* draw the icon */
-            p->a_icon->surface.parentx = iconx;
-            p->a_icon->surface.parenty = icony;
-            RrPaint(p->a_icon, target->win, iconw, iconh);
+            p->a_icon->surface.parentx = innerx;
+            p->a_icon->surface.parenty = innery;
+            RrPaint(p->a_icon, target->win, innerw, innerh);
         }
     }
 
@@ -387,7 +423,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
     p->last_target = newtarget;
 }
 
-void focus_cycle_popup_show(ObClient *c,
+void focus_cycle_popup_show(ObClient *c, gboolean iconic_windows,
                             gboolean all_desktops, gboolean dock_windows,
                             gboolean desktop_windows)
 {
@@ -395,7 +431,8 @@ void focus_cycle_popup_show(ObClient *c,
 
     /* do this stuff only when the dialog is first showing */
     if (!popup.mapped)
-        popup_setup(&popup, all_desktops, dock_windows, desktop_windows);
+        popup_setup(&popup, iconic_windows, all_desktops,
+                    dock_windows, desktop_windows);
     g_assert(popup.targets != NULL);
 
     popup_render(&popup, c);
This page took 0.026939 seconds and 4 git commands to generate.