[PATCH] Implemented handler for xrandr change notify event



---
 ChangeLog       |    6 +++++
 src/Makefile.in |    8 +++---
 src/display.c   |    2 +-
 src/events.c    |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 73 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 67579ee..f2d77f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-12-13  dmg  <dmg uvic ca>
+
+	* src/events.c: Added support for catching XRANDR events
+
+	* src/display.c: Set dpy variable to NULL by default
+
 2009-12-08  Christopher Bratusek <zanghar freenet de>
 	* debian/rules
 	* debian/control: depend on automake rather than on automake1.10
diff --git a/src/Makefile.in b/src/Makefile.in
index bfadc71..c1e16ed 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -37,14 +37,14 @@ DL_DSTS = sawfish/wm/util/gradient.la sawfish/wm/util/flippers.la \
 	  sawfish/wm/util/x.la sawfish/wm/util/selection.la
 DL_DIRS = sawfish/wm/util
 
-override CFLAGS := $(CFLAGS) $(REP_CFLAGS) $(IMAGE_CFLAGS) $(X11_CFLAGS) $(PANGO_CFLAGS)
+override CFLAGS := $(CFLAGS) $(REP_CFLAGS) $(IMAGE_CFLAGS) $(X11_CFLAGS) $(PANGO_CFLAGS) 
 
 all : sawfish libclient.o $(DL_OBJS) .libexec gtk-style
 
 sawfish : $(OBJS) $(LIBOBJS)
 	$(rep_LIBTOOL) --mode=link --tag=CC $(CC) -export-dynamic $(LDFLAGS) \
 	  -o sawfish $(OBJS) $(LIBOBJS) $(REP_LIBS) $(PANGO_LIBS) \
-	  $(IMAGE_LIBS) $(X11_LIBS) $(EXTRA_X11_LIBS) $(LIBS)
+	  $(IMAGE_LIBS) $(X11_LIBS) $(EXTRA_X11_LIBS) $(LIBS) $(XRANDR_LIBS)
 
 %.la : %.lo
 	$(rep_DL_LD) $(LDFLAGS) -o $@ $<
@@ -53,10 +53,10 @@ libclient_.lo : libclient.c
 	$(rep_LIBTOOL) --mode=compile --tag=CC $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
 
 client.la : client.lo libclient_.lo
-	$(rep_DL_LD) $(LDFLAGS) -o $@ $^ $(X11_LIBS) $(REP_LIBS) $(LIBS)
+	$(rep_DL_LD) $(LDFLAGS) -o $@ $^ $(X11_LIBS) $(REP_LIBS) $(LIBS) $(XRANDR_LIBS)
 
 gtk-style : gtk-style.c
-	$(CC) $(CFLAGS) $(CPPFLAGS) $(GTK_CFLAGS) $(LDFLAGS) -o $@ $< $(GTK_LIBS) $(LIBS)
+	$(CC) $(CFLAGS) $(CPPFLAGS) $(GTK_CFLAGS) $(LDFLAGS) -o $@ $< $(GTK_LIBS) $(LIBS) $(XRANDR_LIBS)
 
 install : all installdirs
 	for p in sawfish; do \
diff --git a/src/display.c b/src/display.c
index 97b2719..f0e68bf 100644
--- a/src/display.c
+++ b/src/display.c
@@ -45,7 +45,7 @@
 #endif
 
 char *visual_name;
-Display *dpy;
+Display *dpy = NULL;
 int screen_num, screen_width, screen_height;
 Window root_window, no_focus_window;
 int shape_event_base, shape_error_base;
diff --git a/src/events.c b/src/events.c
index 6daefd7..5ad24de 100644
--- a/src/events.c
+++ b/src/events.c
@@ -31,6 +31,7 @@
 #include <X11/Xresource.h>
 #include <X11/Xatom.h>
 #include <glib.h>
+#include <stdio.h>
 
 /* Lookup table of event handlers */
 void (*event_handlers[LASTEvent])(XEvent *ev);
@@ -69,6 +70,13 @@ static XID event_handler_context;
 
 static Atom xa_sawfish_timestamp;
 
+/* is there xrand support? */
+static int has_randr = FALSE;
+#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
+static int randr_event_base; /* Will give us the offset for the xrandr events */
+#endif
+
+
 DEFSYM(visibility_notify_hook, "visibility-notify-hook");
 DEFSYM(destroy_notify_hook, "destroy-notify-hook");
 DEFSYM(map_notify_hook, "map-notify-hook");
@@ -89,6 +97,11 @@ 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");
+
+#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
+DEFSYM(randr_change_notify_hook, "randr-change-notify-hook");
+#endif
+
 DEFSYM(window_state_change_hook, "window-state-change-hook");
 
 DEFSYM(pointer_motion_threshold, "pointer-motion-threshold");
@@ -1265,6 +1278,20 @@ shape_notify (XEvent *ev)
     }
 }
 
+#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
+static void
+randr_screen_change_notify (XEvent *ev)
+{
+    // Only do it if we are sure we are handling the event
+    if (has_randr) {
+        fprintf(stderr, "Yes, we are handling the screen change event\n");
+        // We should add the call to the hook
+        XRRUpdateConfiguration( ev );
+        // Call the hook
+        Fcall_hook(Qrandr_change_notify_hook, Qnil, Qnil);
+    }
+}
+#endif
 
 static int synthetic_configure_mutex;
 
@@ -1404,7 +1431,11 @@ inner_handle_input (repv arg)
 	event_handlers[ev->type] (ev);
     else if (ev->type == shape_event_base + ShapeNotify)
 	shape_notify (ev);
-    else
+#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
+    else if (ev->type == randr_event_base + RRScreenChangeNotify)
+        randr_screen_change_notify(ev);
+#endif
+    else 
 	fprintf (stderr, "warning: unhandled event: %d\n", ev->type);
     return Qnil;
 }
@@ -1669,7 +1700,27 @@ void
 events_init (void)
 {
     repv tem;
+#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
+    int dummy;
+#endif
 
+    has_randr = FALSE;
+#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
+    // This code is executed even in batch mode, in 
+    // which case dpy is not set
+    if (dpy != NULL) {
+        has_randr = XRRQueryExtension( dpy, &randr_event_base, &dummy );
+        if( has_randr )
+        {
+           int major, minor;
+           XRRQueryVersion( dpy, &major, &minor );
+           has_randr = ( major > 1 || ( major == 1 && minor >= 1 ) );
+           fprintf(stderr, "it Has randr %d\n", has_randr);
+           XRRSelectInput( dpy, root_window, RRScreenChangeNotifyMask );
+        }
+    }
+
+#endif
     event_handlers[VisibilityNotify] = visibility_notify;
     event_handlers[ColormapNotify] = colormap_notify;
     event_handlers[KeyPress] = key_press;
@@ -1696,6 +1747,16 @@ events_init (void)
     event_handlers[CirculateNotify] = circulate_notify;
     event_handlers[MappingNotify] = mapping_notify;
 
+#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
+    if (has_randr) 
+    {
+        fprintf(stderr, "Setting handler at event %d\n", randr_event_base + RRScreenChangeNotify);
+        // we can't handle the event in the usual manner because the sizes of the
+        // arrays event_handler and event_names are defined at compile time.
+        rep_INTERN_SPECIAL(randr_change_notify_hook);
+    }
+#endif
+
     event_names[KeyPress] = "KeyPress";
     event_names[KeyRelease] = "KeyRelease";
     event_names[ButtonPress] = "ButtonPress";
-- 
1.6.3.3


--=-=-=




-- 
--
Daniel M. German                  
http://turingmachine.org/
http://silvernegative.com/
dmg (at) uvic (dot) ca
replace (at) with @ and (dot) with .

--=-=-=--


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