Basic XRandR support



Hi all,

The attached patch adds basic xrandr support based on how metacity
handles screen size change events. The main thing that this patch
does not do is force a size update on maximised and fullscreen windows.
This is because sawfish doesn't have an
'update-yourself-given-the-screen-properties' function like metacity
does. The upshot is that unless that changes, we have to iterate over
all windows and then, based on window state, tell each window to update
itself in a way that is specific to the window state. ie: Find maximised
windows and tell them to maximise themselves again. I have some
tentative code that does this but it appears that there's a race with
respect to updating the desktop geometry hints because the re-maximised
window tends to be the wrong size in one dimension. Manually
re-maximising it causes it to take the right size.

Even without this auto-adjust behaviour, the patch is still useful as it
was previously necessary to restart sawfish after a resolution change.

Readers will notice that I've added the configure-notify-hook for all
windows when it didn't exist at all before. Perhaps John has a specific
reason for this, and if so, we can narrow down the hook so that it only
applies to the root window (possible performance reasons?)

Enjoy!

--phil
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/sawfish/ChangeLog,v
retrieving revision 1.201
diff -u -r1.201 ChangeLog
--- ChangeLog	2 Apr 2005 00:05:30 -0000	1.201
+++ ChangeLog	26 Jun 2005 22:19:18 -0000
@@ -1,3 +1,9 @@
+2005-06-26  Philip Langdale <philipl mail utexas edu>
+
+	* configure.in
+	* config.h.in
+	* Makedefs.in: Add detection for Xrandr extension.
+
 2005-04-01  Steve Murphy  <murf e-tools com>
 
         * configure.in: Added "rw" to ALL_LINGUAS.
Index: Makedefs.in
===================================================================
RCS file: /cvs/gnome/sawfish/Makedefs.in,v
retrieving revision 1.28
diff -u -r1.28 Makedefs.in
--- Makedefs.in	14 Aug 2003 07:17:24 -0000	1.28
+++ Makedefs.in	26 Jun 2005 22:19:18 -0000
@@ -54,7 +54,7 @@
 LIBOBJS=
 X11_CFLAGS= X_CFLAGS@ @XFT_CFLAGS@
 X11_LIBS= X_PRE_LIBS@ -lX11 @X_LIBS@ @X_EXTRA_LIBS@
-EXTRA_X11_LIBS= XINERAMA_LIBS@ @XFT_LIBS@ -lXext
+EXTRA_X11_LIBS= XINERAMA_LIBS@ @XRANDR_LIBS@ @XFT_LIBS@ -lXext
 IMLIB_CFLAGS= IMLIB_CFLAGS@
 IMLIB_LIBS= IMLIB_LIBS@
 GDK_PIXBUF_CFLAGS= GDK_PIXBUF_CFLAGS@
Index: config.h.in
===================================================================
RCS file: /cvs/gnome/sawfish/config.h.in,v
retrieving revision 1.15
diff -u -r1.15 config.h.in
--- config.h.in	14 Aug 2003 07:17:24 -0000	1.15
+++ config.h.in	26 Jun 2005 22:19:18 -0000
@@ -86,6 +86,9 @@
 /* Define if <X11/extensions/Xinerama.h> exists */
 #undef HAVE_X11_EXTENSIONS_XINERAMA_H
 
+/* Define if <X11/extensions/Xrandr.h> exists */
+#undef HAVE_X11_EXTENSIONS_XRANDR_H
+
 /* Define if <X11/Xft/Xft.h> exists */
 #undef HAVE_X11_XFT_XFT_H
 
Index: configure.in
===================================================================
RCS file: /cvs/gnome/sawfish/configure.in,v
retrieving revision 1.136
diff -u -r1.136 configure.in
--- configure.in	16 Aug 2003 18:37:03 -0000	1.136
+++ configure.in	26 Jun 2005 22:19:18 -0000
@@ -94,16 +94,23 @@
 
 dnl Checks for X extensions/libraries
 XINERAMA_LIBS=""
+XRANDR_LIBS=""
 XFT_LIBS=""
 XFT_CFLAGS=""
 
 AC_SUBST(XINERAMA_LIBS)
+AC_SUBST(XRANDR_LIBS)
 AC_SUBST(XFT_LIBS)
 AC_SUBST(XFT_CFLAGS)
 
 AC_CHECK_LIB(Xinerama, XineramaQueryScreens,
 	     [XINERAMA_LIBS="-lXinerama"
 	      AC_CHECK_HEADERS(X11/extensions/Xinerama.h)],
+	     [],[$X_LIBS -lX11 -lXext])
+
+AC_CHECK_LIB(Xrandr, XRRUpdateConfiguration,
+	     [XRANDR_LIBS="-lXrandr"
+	      AC_CHECK_HEADERS(X11/extensions/Xrandr.h)],
 	     [],[$X_LIBS -lX11 -lXext])
 
 dnl Try using pkg-config first, since it looks like Xft2 may fail our
Index: lisp/ChangeLog
===================================================================
RCS file: /cvs/gnome/sawfish/lisp/ChangeLog,v
retrieving revision 1.623
diff -u -r1.623 ChangeLog
--- lisp/ChangeLog	8 Feb 2005 04:32:02 -0000	1.623
+++ lisp/ChangeLog	26 Jun 2005 22:19:19 -0000
@@ -1,3 +1,9 @@
+2005-06-26  Philip Langdale <philipl mail utexas edu>
+
+	* sawfish/wm/state/wm-spec.jl (init): Add a configure-notify-hook
+	to detect changes to the size of the root window, which implies
+	a screen resolution change, and call update-workspace-hints
+
 2005-02-06  John Harper  <jsh unfactored org>
 
 	* sawfish/wm/menus.jl (popup-menu): synchronize with the server
Index: lisp/sawfish/wm/state/wm-spec.jl
===================================================================
RCS file: /cvs/gnome/sawfish/lisp/sawfish/wm/state/wm-spec.jl,v
retrieving revision 1.48
diff -u -r1.48 wm-spec.jl
--- lisp/sawfish/wm/state/wm-spec.jl	25 Nov 2003 04:01:15 -0000	1.48
+++ lisp/sawfish/wm/state/wm-spec.jl	26 Jun 2005 22:19:20 -0000
@@ -588,6 +588,10 @@
 	 (out '() (cons (aref vec i) out)))
 	((= i (length vec)) (nreverse out))))
 
+  (define (update-on-configure-notify w)
+    (if (eq w 'root)
+      (update-workspace-hints)))
+
 
 ;;; initialisation
 
@@ -619,6 +623,7 @@
     (add-hook 'viewport-resized-hook update-workspace-hints)
     (add-hook 'viewport-moved-hook update-workspace-hints)
     (add-hook 'workarea-changed-hook update-workspace-hints)
+    (add-hook 'configure-notify-hook update-on-configure-notify)
 
     (add-hook 'add-window-hook update-client-list-hints)
     (add-hook 'destroy-notify-hook update-client-list-hints)
Index: src/ChangeLog
===================================================================
RCS file: /cvs/gnome/sawfish/src/ChangeLog,v
retrieving revision 1.442
diff -u -r1.442 ChangeLog
--- src/ChangeLog	12 Feb 2005 06:22:18 -0000	1.442
+++ src/ChangeLog	26 Jun 2005 22:19:20 -0000
@@ -1,3 +1,18 @@
+2005-06-26  Philip Langdale <philipl mail utexas edu>
+
+	* sawmill.h: Add StructureNotify to the root window event mask.
+
+	* sawmill_subrs.h: Add declaration for functions_read_xinerama_info.
+
+	* events.c (configure_notify): Add a configure-notify-hook and emit
+	it on the expected occasions. Respond to configureNotify events on
+	the root window by calling into Xrandr (if the extension is available)
+	and updating the cached screen 	size and xinerama information.
+
+	* functions.c (functions_read_xinerama_info): Refactor xinerama
+	discovery into a separate function so it can be called on Xrandr
+	screen size change events.
+
 2005-02-11  John Harper  <jsh unfactored org>
 
 	* windows.c (Fwindow_frame_id): new function to return the
Index: src/events.c
===================================================================
RCS file: /cvs/gnome/sawfish/src/events.c,v
retrieving revision 1.158
diff -u -r1.158 events.c
--- src/events.c	4 Jan 2005 15:34:25 -0000	1.158
+++ src/events.c	26 Jun 2005 22:19:21 -0000
@@ -24,6 +24,9 @@
 #include <string.h>
 #include <time.h>
 #include <X11/extensions/shape.h>
+#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
+#include <X11/extensions/Xrandr.h>
+#endif
 #include <X11/Xresource.h>
 #include <X11/Xatom.h>
 
@@ -83,6 +86,7 @@
 DEFSYM(enter_frame_part_hook, "enter-frame-part-hook");
 DEFSYM(leave_frame_part_hook, "leave-frame-part-hook");
 DEFSYM(configure_request_hook, "configure-request-hook");
+DEFSYM(configure_notify_hook, "configure-notify-hook");
 DEFSYM(window_state_change_hook, "window-state-change-hook");
 
 DEFSYM(pointer_motion_threshold, "pointer-motion-threshold");
@@ -1099,6 +1103,29 @@
 static void
 configure_notify (XEvent *ev)
 {
+    Window window = ev->xconfigure.window;
+    Lisp_Window *w = find_window_by_id (ev->xcrossing.window);
+
+    if (window == root_window)
+    {
+        /* It will be fairly pathological case where the server
+           supports the randr extension but sawfish binary has been
+           compiled without it, but we can still respond to the
+           configureNotify event in a basic way */
+#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
+        XRRUpdateConfiguration (ev);
+#endif
+        functions_read_xinerama_info ();
+
+        screen_width = ev->xconfigure.width;
+        screen_height = ev->xconfigure.height;
+
+        Fcall_hook (Qconfigure_notify_hook, rep_LIST_1(Qroot), Qnil);
+     }
+     else if (w != 0 && w->id == window)
+     {
+        Fcall_window_hook (Qconfigure_notify_hook, rep_VAL(w), Qnil, Qnil);
+     }
 }
 
 static void
@@ -1670,6 +1697,7 @@
     rep_INTERN_SPECIAL(shape_notify_hook);
     rep_INTERN_SPECIAL(enter_frame_part_hook);
     rep_INTERN_SPECIAL(leave_frame_part_hook);
+    rep_INTERN_SPECIAL(configure_notify_hook);
     rep_INTERN_SPECIAL(configure_request_hook);
     rep_INTERN_SPECIAL(window_state_change_hook);
 
Index: src/functions.c
===================================================================
RCS file: /cvs/gnome/sawfish/src/functions.c,v
retrieving revision 1.101
diff -u -r1.101 functions.c
--- src/functions.c	7 Feb 2005 00:11:23 -0000	1.101
+++ src/functions.c	26 Jun 2005 22:19:21 -0000
@@ -1382,6 +1382,19 @@
     rep_mark_static (&message.font);
     rep_mark_static (&message.justify);
 
+    functions_read_xinerama_info ();
+}
+
+void
+functions_kill (void)
+{
+    if (message_win != 0)
+	XDestroyWindow (dpy, message_win);
+}
+
+void
+functions_read_xinerama_info (void)
+{
 #ifdef HAVE_X11_EXTENSIONS_XINERAMA_H
 # ifndef TEST_XINERAMA
     if (dpy != 0)
@@ -1397,11 +1410,4 @@
     xinerama_heads = debug_nheads;
 # endif
 #endif
-}
-
-void
-functions_kill (void)
-{
-    if (message_win != 0)
-	XDestroyWindow (dpy, message_win);
 }
Index: src/sawmill.h
===================================================================
RCS file: /cvs/gnome/sawfish/src/sawmill.h,v
retrieving revision 1.59
diff -u -r1.59 sawmill.h
--- src/sawmill.h	12 Jan 2003 20:35:23 -0000	1.59
+++ src/sawmill.h	26 Jun 2005 22:19:21 -0000
@@ -73,7 +73,7 @@
 #define ROOT_EVENTS (SubstructureRedirectMask | SubstructureNotifyMask \
 		     | ButtonPressMask | ButtonReleaseMask | KeyPressMask \
 		     | ButtonMotionMask | PointerMotionHintMask \
-		     | EnterWindowMask | LeaveWindowMask)
+		     | EnterWindowMask | LeaveWindowMask | StructureNotifyMask)
 
 /* Events selected on each frame part */
 #define FP_EVENTS (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask \
Index: src/sawmill_subrs.h
===================================================================
RCS file: /cvs/gnome/sawfish/src/sawmill_subrs.h,v
retrieving revision 1.109
diff -u -r1.109 sawmill_subrs.h
--- src/sawmill_subrs.h	4 Jan 2005 15:34:25 -0000	1.109
+++ src/sawmill_subrs.h	26 Jun 2005 22:19:21 -0000
@@ -182,6 +182,7 @@
 extern repv Fdisplay_message (repv text, repv attrs);
 extern void functions_init (void);
 extern void functions_kill (void);
+extern void functions_read_xinerama_info (void);
 
 /* from images.c */
 extern int image_type;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]