Package: xbattbar
Version: 1.4.4-1

Hello,

Attached is the patch which enables xbattbar to react to screen size
changes. However, probably, the proper way would be not to place in to
the edge of a root window, but to the edge of primary screen; that
would require to use Xinerama API or XRandR.

-- 
Cheers,
  Andrew
Subject: Resize bar when the root window size changes.
From: Andrew Shadura <andre...@debian.org>

--- a/xbattbar.c
+++ b/xbattbar.c
@@ -92,6 +92,7 @@ int bi_thick = BI_THICKNESS;        /* t
 int bi_interval = PollingInterval;  /* interval of polling APM */
 
 Display *disp;
+Window root;
 Window winbar;                  /* bar indicator window */
 Window winstat = -1;            /* battery status window */
 GC gcbar;
@@ -163,21 +164,10 @@ Status AllocColor(char *name, unsigned l
   return(status);
 }
 
-/*
- * InitDisplay:
- * create small window in top or bottom
- */
-void InitDisplay(void)
+void ReshapeWindow(void)
 {
-  Window root;
   int x,y;
   unsigned int border,depth;
-  XSetWindowAttributes att;
-
-  if((disp = XOpenDisplay(NULL)) == NULL) {
-      fprintf(stderr, "xbattbar: can't open display.\n");
-      _exit(1);
-  }
 
   if(XGetGeometry(disp, DefaultRootWindow(disp), &root, &x, &y,
                  &width, &height, &border, &depth) == 0) {
@@ -185,14 +175,6 @@ void InitDisplay(void)
     _exit(1);
   }
 
-  if (!AllocColor(ONIN_C,&onin) ||
-       !AllocColor(OFFOUT_C,&offout) ||
-       !AllocColor(OFFIN_C,&offin) ||
-       !AllocColor(ONOUT_C,&onout)) {
-    fprintf(stderr, "xbattbar: can't allocate color resources\n");
-    _exit(1);
-  }
-
   switch (bi_direction) {
   case BI_Top: /* (0,0) - (width, bi_thick) */
     bi_width = width;
@@ -218,6 +200,30 @@ void InitDisplay(void)
     bi_x = width - bi_thick;
     bi_y = 0;
   }
+}
+
+/*
+ * InitDisplay:
+ * create small window in top or bottom
+ */
+void InitDisplay(void)
+{
+  XSetWindowAttributes att;
+
+  if((disp = XOpenDisplay(NULL)) == NULL) {
+      fprintf(stderr, "xbattbar: can't open display.\n");
+      _exit(1);
+  }
+
+  if (!AllocColor(ONIN_C,&onin) ||
+       !AllocColor(OFFOUT_C,&offout) ||
+       !AllocColor(OFFIN_C,&offin) ||
+       !AllocColor(ONOUT_C,&onout)) {
+    fprintf(stderr, "xbattbar: can't allocate color resources\n");
+    _exit(1);
+  }
+
+  ReshapeWindow();
 
   winbar = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
                               bi_x, bi_y, bi_width, bi_height,
@@ -314,6 +320,7 @@ main(int argc, char **argv)
   signal(SIGALRM, (void *)(battery_check));
   battery_check();
   XSelectInput(disp, winbar, myEventMask);
+  XSelectInput(disp, root, StructureNotifyMask);
   while (1) {
     XWindowEvent(disp, winbar, myEventMask, &theEvent);
     switch (theEvent.type) {
@@ -342,6 +349,12 @@ main(int argc, char **argv)
 	      "xbattbar: unknown event (%d) captured\n",
 	      theEvent.type);
     }
+    XWindowEvent(disp, root, StructureNotifyMask, &theEvent);
+    switch (theEvent.type) {
+    case ConfigureNotify:
+      ReshapeWindow();
+      XMoveResizeWindow(disp, winbar, bi_x, bi_y, bi_width, bi_height);
+    }
   }
 }
 

Attachment: signature.asc
Description: PGP signature

Reply via email to