The attached patch causes ratpoison to listen for events
generated when a screen changes its size (Which may happen
if someone executes "xrandr -s 1" or something like that)
and change the frameset accordingly.

Additionally framedumps/restores are modified to remember
the current screen size/recalculate coordinates for the
current screen size.

Hochachtungsvoll,
        Bernhard R. Link
Index: ChangeLog
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/ChangeLog,v
retrieving revision 1.419
diff -u -p -r1.419 ChangeLog
--- ChangeLog   11 Mar 2006 00:31:30 -0000      1.419
+++ ChangeLog   11 Mar 2006 12:24:18 -0000
@@ -1,3 +1,21 @@
+2006-04-11  Bernhard R. Link  <[EMAIL PROTECTED]>
+
+       * src/screen.c: new function screen_update to update the size of a 
screen
+         (init_screen): listen for screen resizes
+       * src/screen.h: new prototype
+
+       * src/events.c: new function configure_notify to call screen_update
+         (delegate_event): call configure_notify for ConfigureNotify events
+
+       * src/frame.c (frame_dump): remember the size of the screen the frame
+                                   coordinates are relative to.
+         (frame_restore): adopt coordinates to possible screen resizes.
+
+       * src/frame.h: frame_fump and frame_read need a screen argument now.
+
+       * src/actions.c (cmd_tmpwm): listen for screen resizes again
+         (fdump, frestore, cmd_fdump): supply screen to frame_dump, frameread
+
 2006-04-10  Bernhard R. Link  <[EMAIL PROTECTED]>
 
        * src/manage.c (maximize_transient,maximize_normal):
Index: src/actions.c
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/actions.c,v
retrieving revision 1.262
diff -u -p -r1.262 actions.c
--- src/actions.c       8 Mar 2006 00:33:29 -0000       1.262
+++ src/actions.c       11 Mar 2006 12:24:19 -0000
@@ -4255,7 +4255,8 @@ cmd_tmpwm (int interactive, struct cmdar
     {
       XSelectInput(dpy, RootWindow (dpy, screens[i].screen_num),
                   PropertyChangeMask | ColormapChangeMask
-                  | SubstructureRedirectMask | SubstructureNotifyMask);
+                  | SubstructureRedirectMask | SubstructureNotifyMask
+                  | StructureNotifyMask);
       /* Map its key window */
       XMapWindow (dpy, screens[i].key_window);
     }
@@ -4306,7 +4307,7 @@ fdump (rp_screen *screen)
     {
       char *tmp;
 
-      tmp = frame_dump (cur);
+      tmp = frame_dump (cur, screen);
       sbuf_concat (s, tmp);
       sbuf_concat (s, ",");
       free (tmp);
@@ -4368,7 +4369,7 @@ frestore (char *data, rp_screen *s)
   /* Build the new frame set. */
   while (token != NULL)
     {
-      new = frame_read (token);
+      new = frame_read (token, s);
       if (new == NULL)
        {
          free (dup);
@@ -4895,7 +4896,7 @@ cmd_sfdump (int interactively, struct cm
        {
          char *tmp;
 
-         tmp = frame_dump (cur);
+         tmp = frame_dump (cur, &screens[i]);
          sbuf_concat (s, tmp);
          sbuf_concat (s, tmp2);
          free (tmp);
Index: src/events.c
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/events.c,v
retrieving revision 1.125
diff -u -p -r1.125 events.c
--- src/events.c        26 Feb 2006 23:20:07 -0000      1.125
+++ src/events.c        11 Mar 2006 12:24:19 -0000
@@ -712,6 +712,18 @@ mapping_notify (XMappingEvent *ev)
     }
 }
 
+static void
+configure_notify (XConfigureEvent *ev)
+{
+  rp_screen *s;
+
+  s = find_screen(ev->window);
+  if (s != NULL)
+    /* This is a root window of a screen,
+     * look if its width or height changed: */
+    screen_update(s,ev->width,ev->height);
+}
+
 /* This is called whan an application has requested the
    selection. Copied from rxvt. */
 static void
@@ -857,6 +869,10 @@ delegate_event (XEvent *ev)
       break;
 
     case ConfigureNotify:
+      PRINT_DEBUG (("--- Handling ConfigureNotify ---\n"));
+      configure_notify( &ev->xconfigure );
+      break;
+       
     case MapNotify:
     case Expose:
     case MotionNotify:
Index: src/frame.c
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/frame.c,v
retrieving revision 1.15
diff -u -p -r1.15 frame.c
--- src/frame.c 17 Jan 2005 23:26:05 -0000      1.15
+++ src/frame.c 11 Mar 2006 12:24:19 -0000
@@ -161,7 +161,7 @@ frame_copy (rp_frame *frame)
 }
 
 char *
-frame_dump (rp_frame *frame)
+frame_dump (rp_frame *frame, rp_screen *screen)
 {
   rp_window *win;
   char *tmp;
@@ -171,12 +171,14 @@ frame_dump (rp_frame *frame)
   win = find_window_number (frame->win_number);
 
   s = sbuf_new (0);
-  sbuf_printf (s, "(frame :number %d :x %d :y %d :width %d :height %d :window 
%ld :last-access %d :dedicated %d)", 
+  sbuf_printf (s, "(frame :number %d :x %d :y %d :width %d :height %d :screenw 
%d :screenh %d :window %ld :last-access %d :dedicated %d)", 
               frame->number,
               frame->x,
               frame->y,
               frame->width,
               frame->height,
+              screen->width,
+              screen->height,
               win ? win->w:0,
               frame->last_access,
               frame->dedicated);
@@ -191,12 +193,14 @@ frame_dump (rp_frame *frame)
 #define read_slot(x) do { tmp = strtok (NULL, " "); x = strtol(tmp,NULL,10); } 
while(0)
 
 rp_frame *
-frame_read (char *str)
+frame_read (char *str, rp_screen *screen)
 {
   Window w = 0L;
   rp_window *win;
   rp_frame *f;
   char *tmp, *dup;
+  int screen_width = -1;
+  int screen_height = -1;
 
   /* Create a blank frame. */
   f = xmalloc (sizeof (rp_frame));
@@ -229,6 +233,10 @@ frame_read (char *str)
        read_slot(f->width);
       else if (!strcmp(tmp, ":height"))
        read_slot(f->height);
+      else if (!strcmp(tmp, ":screenw"))
+       read_slot(screen_width);
+      else if (!strcmp(tmp, ":screenh"))
+       read_slot(screen_height);
       else if (!strcmp(tmp, ":window"))
        read_slot(w);
       else if (!strcmp(tmp, ":last-access"))
@@ -246,6 +254,18 @@ frame_read (char *str)
     PRINT_ERROR(("Frame has trailing garbage\n"));
   free (dup);
 
+  /* adjust x, y, width and height to a possible screen size change */
+  if (screen_width > 0)
+    {
+      f->x = (f->x*screen->width)/screen_width;
+      f->width = (f->width*screen->width)/screen_width;
+    }
+  if (screen_height > 0)
+    {
+      f->y = (f->y*screen->height)/screen_height;
+      f->height = (f->height*screen->height)/screen_height;
+    }
+
   /* Perform some integrity checks on what we got and fix any
      problems. */
   if (f->number <= 0)
Index: src/frame.h
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/frame.h,v
retrieving revision 1.9
diff -u -p -r1.9 frame.h
--- src/frame.h 4 Dec 2004 03:33:24 -0000       1.9
+++ src/frame.h 11 Mar 2006 12:24:19 -0000
@@ -39,7 +39,7 @@ int frame_left (rp_frame *frame);
 rp_frame *frame_new (rp_screen *s);
 void frame_free (rp_screen *s, rp_frame *f);
 rp_frame *frame_copy (rp_frame *frame);
-char *frame_dump (rp_frame *frame);
-rp_frame *frame_read (char *str);
+char *frame_dump (rp_frame *frame, rp_screen *screen);
+rp_frame *frame_read (char *str, rp_screen *screen);
 
 #endif
Index: src/screen.c
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/screen.c,v
retrieving revision 1.11
diff -u -p -r1.11 screen.c
--- src/screen.c        20 Oct 2005 06:21:44 -0000      1.11
+++ src/screen.c        11 Mar 2006 12:24:19 -0000
@@ -266,7 +266,8 @@ init_screen (rp_screen *s, int screen_nu
      it, terminating ratpoison. */
   XSelectInput(dpy, RootWindow (dpy, screen_num),
               PropertyChangeMask | ColormapChangeMask
-              | SubstructureRedirectMask | SubstructureNotifyMask );
+              | SubstructureRedirectMask | SubstructureNotifyMask
+              | StructureNotifyMask);
   XSync (dpy, False);
 
   /* Add netwm support. FIXME: I think this is busted. */
@@ -394,3 +395,33 @@ screen_dump (rp_screen *screen)
   free (s);
   return tmp;
 }
+
+void
+screen_update (rp_screen *s, int width, int height)
+{
+  rp_frame *f;
+  int oldwidth,oldheight;
+
+  PRINT_DEBUG (("screen_update(%d,%d)\n", width, height));
+  if (rp_have_xinerama)
+    {
+      /* TODO: how to do this with xinerama? */
+      return;
+    }
+
+  if (s->width == width && s->height == height)
+    /* nothing to do */
+    return;
+
+  oldwidth = s->width; oldheight = s->height;
+  s->width = width; s->height = height;
+
+  list_for_each_entry (f, &s->frames, node)
+    {
+      f->x = (f->x*width)/oldwidth;
+      f->width = (f->width*width)/oldwidth;
+      f->y = (f->y*height)/oldheight;
+      f->height = (f->height*height)/oldheight;
+      maximize_all_windows_in_frame (f);
+    }
+}
Index: src/screen.h
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/screen.h,v
retrieving revision 1.11
diff -u -p -r1.11 screen.h
--- src/screen.h        20 Oct 2005 06:21:44 -0000      1.11
+++ src/screen.h        11 Mar 2006 12:24:19 -0000
@@ -42,4 +42,5 @@ int is_a_root_window (int w);
 
 char *screen_dump (rp_screen *screen);
 
+void screen_update (rp_screen *s, int width, int height);
 #endif
_______________________________________________
Ratpoison-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/ratpoison-devel

Reply via email to