New functions in Pager. (Patch included)

Johan Bengtsson (johanb@DoCS.UU.SE)
Fri, 30 Oct 1998 10:57:09 +0100 (CET)


--Multipart_Fri_Oct_30_10:57:09_1998-1
Content-Type: text/plain; charset=US-ASCII


I made some small additions to the Pager module, that also might be
interesting to other people. The supplied patches makes it possible to 
have the desk labels below the desks instead of above. It also makes 
it possible to hide labels of inactive desks.

	/ Johan


--Multipart_Fri_Oct_30_10:57:09_1998-1
Content-Type: application/octet-stream; type=patch
Content-Disposition: attachment; filename="AfterStep-Pager.patch"
Content-Transfer-Encoding: 8bit

diff -r -u Pager/Pager.c MyPager/Pager.c
--- Pager/Pager.c	Wed Oct  7 11:21:16 1998
+++ MyPager/Pager.c	Wed Oct 28 13:33:48 1998
@@ -106,6 +106,9 @@
 int desk1 = 0, desk2 = 0;
 int ndesks = 0;
 int StickyIcons = 0;
+int LabelBelowDesk = 0;
+int HideInactiveLabel = 0;
+
 
 extern unsigned long MaxBackgroundColors ;
 
@@ -949,6 +952,10 @@
          if (flags & YValue)               icon_y = g_y;
     
       }else if ((strlen (&tline[0]) > 1) &&
+               (mystrncasecmp (tline, CatString3 ("*", MyName, "LabelBelowDesk"), Clength + 15) == 0))
+      {
+         LabelBelowDesk = 1;
+      }else if ((strlen (&tline[0]) > 1) &&
                (mystrncasecmp (tline, CatString3 ("*", MyName, "Label"), Clength + 6) == 0))
       {
          desk = desk1;
@@ -1038,6 +1045,10 @@
                (mystrncasecmp (tline, CatString3 ("*", MyName, "RedrawBg"), Clength + 9) == 0))
       {
          sscanf (&tline[Clength + 9], "%d", &RedrawBg);
+      }else if ((strlen (&tline[0]) > 1) &&
+               (mystrncasecmp (tline, CatString3 ("*", MyName, "HideInactiveLabels"), Clength + 19) == 0))
+      {
+         HideInactiveLabel = 1;
       }
       else if ((strlen (&tline[0]) > 1) &&
                (mystrncasecmp (tline, CatString3 ("*", MyName, "Font"), Clength + 5) == 0))
diff -r -u Pager/Pager.man MyPager/Pager.man
--- Pager/Pager.man	Wed Oct  7 11:21:16 1998
+++ MyPager/Pager.man	Wed Oct 28 13:39:16 1998
@@ -129,6 +129,13 @@
 The active page and desk label will be highlighted by using this
 background pattern instead of the normal background.
 
+.IP "*PagerLabelBelowDesk"
+Causes the labels to be drawn below its corresponding desk instead of above.
+
+.IP "*PagerHideInactiveLabels"
+Uses SHAPE extensions to hide the labels of all the inactive desks. 
+As a bonus, all unused positions in the pager are hidden as well.
+
 .IP "*PagerLabel \fIdesk label\fP"
 Assigns the text \fIlabel\fP to desk \fIdesk\fP in the pager window.
 Useful for assigning symbolic names to desktops, ie
Only in MyPager: TAGS
diff -r -u Pager/x_pager.c MyPager/x_pager.c
--- Pager/x_pager.c	Wed Oct  7 11:21:16 1998
+++ MyPager/x_pager.c	Wed Oct 28 13:19:33 1998
@@ -54,6 +54,7 @@
 #include <X11/Xatom.h>
 #include <X11/Intrinsic.h>
 #include <X11/xpm.h>
+#include <X11/extensions/shape.h>
 
 #include "../../include/afterstep.h"
 #include "Pager.h"
@@ -77,6 +78,9 @@
 extern int window_w, window_h, window_x, window_y, usposition, uselabel;
 extern int StartIconic;
 extern int icon_w, icon_h, icon_x, icon_y;
+extern int LabelBelowDesk;
+extern int HideInactiveLabel;
+
 MyFont font, windowFont;
   
 GC NormalGC, HiliteGC, rvGC;
@@ -99,6 +103,7 @@
 int scr_w = 0;
 int scr_h = 0;
 int label_h = 0;
+int label_y = 0;
 
 DeskInfo *Desks;
 
@@ -210,6 +215,15 @@
    focus_fore_pix = GetColor (HiFore);
    hi_pix = GetColor (HilightC);
 
+
+   /* We need SHAPE extensions to hide inactive lables. */
+   if (HideInactiveLabel) {
+       int s1, s2;
+
+       HideInactiveLabel = (XShapeQueryExtension (dpy, &s1, &s2) ? 1 : 0);
+   }
+
+
    /* Load pixmaps for mono use */
    if (Scr.d_depth < 2)
    {
@@ -380,6 +394,7 @@
                InputOutput, CopyFromParent,
                valuemask,
                &attributes);
+
       attributes.event_mask = (ExposureMask | ButtonReleaseMask |
                   ButtonPressMask | ButtonMotionMask);
       desk_h = window_h - label_h;
@@ -394,6 +409,8 @@
       w = (window_w - n) / (n + 1);
       h = (window_h - label_h - m) / (m + 1);
 
+      label_y = (LabelBelowDesk ? desk_h + 1 : 0); 
+
       Desks[i].CPagerWin[0] = XCreateWindow (dpy, Desks[i].w, -1000, -1000, w + 6, 3, 0,
                      CopyFromParent, InputOutput, CopyFromParent,
                      valuemask, &attributes);
@@ -593,6 +610,47 @@
 }
 
 
+/* Update window shaping when using HideInactiveLabels */
+void UpdateWindowShape ()
+{
+   int i, j, desk_cnt;
+   XRectangle *shape = 0;
+
+   if (!HideInactiveLabel) return;
+
+   shape = alloca ((ndesks + 1) * sizeof (XRectangle));
+
+   desk_cnt = 0;
+
+   for (i = 0; i < Rows; i++)
+   {
+      for (j = 0; j < Columns; j++)
+      {
+	 if (desk_cnt < ndesks) 
+	 {
+	    shape[desk_cnt].x = (desk_w + 1) * j - 1;
+	    shape[desk_cnt].y = ((desk_h + label_h + 1) * i - 1 +
+				  (LabelBelowDesk ? 0 : label_h));
+	    shape[desk_cnt].width = desk_w;
+	    shape[desk_cnt].height = desk_h;
+	    
+	    if (desk_cnt == Scr.CurrentDesk - desk1) 
+	    {
+	       shape[ndesks].x = (desk_w + 1) * j - 1;
+	       shape[ndesks].y = (desk_h + label_h + 1) * i - 1 + label_y;
+	       shape[ndesks].width = desk_w;
+	       shape[ndesks].height = label_h;
+	    }	       
+	    desk_cnt++;
+	 }
+      }
+   }
+
+   XShapeCombineRectangles (dpy, Scr.Pager_w, ShapeBounding, 0, 0, 
+			    shape, ndesks + 1, ShapeSet, 0);
+}
+
+
 /****************************************************************************
  *
  * Respond to a change in window geometry.
@@ -600,21 +658,24 @@
  ****************************************************************************/
 void ReConfigure (void)
 {
-  Window root;
-  unsigned border_width, depth;
-  int n, m, w, h, n1, m1, x, y, i, j, k;
-
-
+   Window root;
+   unsigned border_width, depth;
+   int n, m, w, h, n1, m1, x, y, i, j, k;
+   
    XGetGeometry (dpy, Scr.Pager_w, &root, &x, &y,
-      (unsigned *) &window_w, (unsigned *) &window_h,
-      &border_width, &depth);
-
+		 (unsigned *) &window_w, (unsigned *) &window_h,
+		 &border_width, &depth);
+   
    n1 = Scr.Vx / Scr.MyDisplayWidth;
    m1 = Scr.Vy / Scr.MyDisplayHeight;
    n = (Scr.VxMax) / Scr.MyDisplayWidth;
    m = (Scr.VyMax) / Scr.MyDisplayHeight;
    desk_w = (window_w - Columns + 1) / Columns;
    desk_h = (window_h - Rows * label_h - Rows + 2) / Rows;
+
+   label_y = (LabelBelowDesk ? desk_h + 1 : 0); 
+
+
    w = (desk_w - n) / (n + 1);
    h = (desk_h - m) / (m + 1);
 
@@ -623,6 +684,7 @@
 
    scr_w = w;
    scr_h = h;
+
    for (k = 0; k < Rows; k++)
    {
       for (j = 0; j < Columns; j++)
@@ -634,8 +696,9 @@
             XMoveResizeWindow (dpy, Desks[i].title_w,
                (desk_w + 1) * j - 1, (desk_h + label_h + 1) * k - 1,
                desk_w, window_h);
-            XMoveResizeWindow (dpy, Desks[i].w, -1, label_h - 1,
-               desk_w, desk_h);
+            XMoveResizeWindow (dpy, Desks[i].w, 
+			       -1, (LabelBelowDesk ? 0 : label_h - 1),
+			       desk_w, desk_h);
             if (i == Scr.CurrentDesk - desk1)
             {
                XMoveResizeWindow (dpy, Desks[i].CPagerWin[0], x - 3, y - 3, w + 6, 3);
@@ -651,10 +714,14 @@
                XMoveResizeWindow (dpy, Desks[i].CPagerWin[3], -1000, -1000, 3, h);
             }
             XClearArea (dpy, Desks[i].w, 0, 0, desk_w, desk_h, True);
-            if (uselabel)     XClearArea (dpy, Desks[i].title_w, 0, 0, desk_w, label_h, True);
+            if (uselabel)     XClearArea (dpy, Desks[i].title_w, 0, label_y, desk_w, label_h, True);
          }
       }
    }
+
+   /* Update window shapes. */
+   UpdateWindowShape ();
+
    /* reconfigure all the subordinate windows */
    ReConfigureAll ();
 }
@@ -799,16 +866,17 @@
       XDrawLine (dpy, Desks[i].w, NormalGC, x1, y1, x2, y1);
       y += Scr.MyDisplayHeight;
    }
+   
    if ((Scr.CurrentDesk - desk1) == i)
    {
       if (uselabel)
          XFillRectangle (dpy, Desks[i].title_w, HiliteGC,
-                         0, 0, desk_w, label_h - 1);
+                         0, label_y, desk_w, label_h - 1);
    }
    else
    {
       if (uselabel && erase)
-         XClearArea (dpy, Desks[i].title_w, 0, 0, desk_w, label_h - 1, False);
+         XClearArea (dpy, Desks[i].title_w, 0, label_y, desk_w, label_h - 1, False);
    }
    d = desk1 + i;
    ptr = Desks[i].label;
@@ -826,19 +894,24 @@
 #define FONTSET font.fontset
 
       hor_off = (desk_w - w) / 2;
+
       if (TitleAlign > 0)
          XDrawString (dpy, Desks[i].title_w,
                (i == (Scr.CurrentDesk - desk1)) ? rvGC : NormalGC,
-		   TitleAlign, font.y + 1, ptr, strlen (ptr));
+		   TitleAlign, label_y + font.y + 1, ptr, strlen (ptr));
       else if (TitleAlign == 0)
          XDrawString (dpy, Desks[i].title_w,
                (i == (Scr.CurrentDesk - desk1)) ? rvGC : NormalGC,
-               hor_off, font.y + 1, ptr, strlen (ptr));
+               hor_off, label_y + font.y + 1, ptr, strlen (ptr));
       else
          XDrawString (dpy, Desks[i].title_w,
                (i == (Scr.CurrentDesk - desk1)) ? rvGC : NormalGC,
-               desk_w - w + TitleAlign, font.y + 1, ptr, strlen (ptr));
+               desk_w - w + TitleAlign, label_y + font.y + 1, ptr, strlen (ptr));
    }
+
+   /* Update window shapes. */
+   UpdateWindowShape ();
+
 }
 
 void DrawIconGrid (int erase)
@@ -1465,8 +1538,9 @@
       XClearWindow (dpy, t->PagerView);
 #undef FONTSET
 #define FONTSET windowFont.fontset
+
       XDrawImageString (dpy, t->PagerView, tgc, 2, windowFont.y + 2,
-      t->icon_name, strlen (t->icon_name));
+			t->icon_name, strlen (t->icon_name));
    }
 }
 

--Multipart_Fri_Oct_30_10:57:09_1998-1--

--
   WWW:   http://www.afterstep.org/
   FTP:   ftp://ftp.afterstep.org/
   MAIL:  http://www.caldera.com/linuxcenter/forums/afterstep.html