This patch makes wmaker automatically Restart() to take into account
resolution changes done by xrandr.
The motivation to write this patch is that when I start my laptop connected
to an external monitor (VGA1), the resolution in the monitor is initially
wrong (perhaps this is a bug in XOrg or OpenSuse, but anyway), so I always
do this after starting wmaker:
xrandr --output VGA1 --preferred
The resolution in the external monitor gets fixed, but wmaker does not
recognize the change automatically and I have to manually restart it.
So this patch avoids the last step by making wmaker be XRandR-aware.
Wmaker now restarts automatically when it receives a RRChangeScreenNotify
event and I don't have to do the last part of the silly procedure described
above.
I am not sure if restarting wmaker is the most elegant solution, but
it at least solves part of my issue with wmaker + xrandr.
---
configure.ac | 16 ++++++++++++++++
src/event.c | 13 +++++++++++++
src/main.c | 5 +++++
src/screen.c | 12 +++++++++++-
src/startup.c | 16 +++++++++++++++-
5 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 85eddb5..ba268b7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -480,6 +480,21 @@ if test "$shape" = yes; then
shape=no, $XLFLAGS $XLIBS)
fi
+dnl XRandR support
+dnl =============
+xrandr=yes
+AC_ARG_ENABLE(XRandR,
+[ --disable-xrandr disable XRandR window extension support],
+ xrandr=$enableval, xrandr=yes)
+
+added_xext=no
+
+if test "$xrandr" = yes; then
+ AC_CHECK_LIB(Xrandr, XRRQueryExtension, [XLIBS="-lXrandr $XLIBS"
+ added_xext=yes
+ AC_DEFINE(HAVE_XRANDR, 1, [define if you want support for
XRandR (set by configure)])],
+ xrandr=no, $XLFLAGS $XLIBS)
+fi
dnl
dnl libWINGS uses math functions, check whether usage requires linking
@@ -1072,6 +1087,7 @@ echo "Use assembly routines for wrlib : $asm_support"
echo "Use inline MMX(tm) x86 assembly : $mmx_support"
echo "Antialiased text support in WINGs : $xft"
echo "Xinerama extension support : $xinerama"
+echo "XRandR extension support : $xrandr"
echo "Translated message files to install : $mof"
dnl echo "Supported languages beside English : $languages"
if test "x$MOFILES" != "x"; then
diff --git a/src/event.c b/src/event.c
index 4f1287c..5d80fbe 100644
--- a/src/event.c
+++ b/src/event.c
@@ -40,6 +40,10 @@
#include "xdnd.h"
#endif
+#ifdef HAVE_XRANDR
+#include <X11/extensions/Xrandr.h>
+#endif
+
#ifdef KEEP_XKB_LOCK_STATUS
#include <X11/XKBlib.h>
#endif /* KEEP_XKB_LOCK_STATUS */
@@ -96,6 +100,11 @@ extern int wShapeEventBase;
extern int wXkbEventBase;
#endif
+#ifdef HAVE_XRANDR
+extern Bool has_randr;
+extern int randr_event_base;
+#endif
+
/* special flags */
/*extern char WDelayedActionSet;*/
@@ -562,6 +571,10 @@ static void handleExtensions(XEvent * event)
handleXkbIndicatorStateNotify(event);
}
#endif /*KEEP_XKB_LOCK_STATUS */
+#ifdef HAVE_XRANDR
+ if (has_randr && event->type == (randr_event_base +
RRScreenChangeNotify))
+ Restart(NULL,True);
+#endif
}
static void handleMapRequest(XEvent * ev)
diff --git a/src/main.c b/src/main.c
index bd59b68..5833a11 100644
--- a/src/main.c
+++ b/src/main.c
@@ -143,6 +143,11 @@ Bool wXkbSupported;
int wXkbEventBase;
#endif
+#ifdef HAVE_XRANDR
+Bool has_randr;
+int randr_event_base;
+#endif
+
/* special flags */
char WProgramSigState = 0;
char WProgramState = WSTATE_NORMAL;
diff --git a/src/screen.c b/src/screen.c
index 1a119c2..a9e52e6 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -35,9 +35,11 @@
#ifdef KEEP_XKB_LOCK_STATUS
#include <X11/XKBlib.h>
#endif /* KEEP_XKB_LOCK_STATUS */
+#ifdef HAVE_XRANDR
+#include <X11/extensions/Xrandr.h>
+#endif
#include <wraster.h>
-
#include "WindowMaker.h"
#include "def_pixmaps.h"
#include "screen.h"
@@ -77,6 +79,9 @@ extern int wScreenCount;
#ifdef KEEP_XKB_LOCK_STATUS
extern int wXkbSupported;
#endif
+#ifdef HAVE_XRANDR
+extern int has_randr;
+#endif
extern WDDomain *WDWindowMaker;
@@ -598,6 +603,11 @@ WScreen *wScreenInit(int screen_number)
}
#endif /* KEEP_XKB_LOCK_STATUS */
+#ifdef HAVE_XRANDR
+ if (has_randr)
+ XRRSelectInput(dpy, scr->root_win, RRScreenChangeNotifyMask);
+#endif
+
XSync(dpy, False);
XSetErrorHandler(oldHandler);
diff --git a/src/startup.c b/src/startup.c
index 9b63687..b16b979 100644
--- a/src/startup.c
+++ b/src/startup.c
@@ -45,6 +45,9 @@
#ifdef KEEP_XKB_LOCK_STATUS
#include <X11/XKBlib.h>
#endif
+#ifdef HAVE_XRANDR
+#include <X11/extensions/Xrandr.h>
+#endif
#include "WindowMaker.h"
#include "GNUstep.h"
@@ -97,6 +100,11 @@ extern Bool wXkbSupported;
extern int wXkbEventBase;
#endif
+#ifdef HAVE_XRANDR
+extern Bool has_randr;
+extern int randr_event_base;
+#endif
+
/* contexts */
extern XContext wWinContext;
extern XContext wAppWinContext;
@@ -501,7 +509,7 @@ static char *atomNames[] = {
void StartUp(Bool defaultScreenOnly)
{
struct sigaction sig_action;
- int j, max;
+ int j, max, dummy;
Atom atom[sizeof(atomNames) / sizeof(char *)];
/*
@@ -692,6 +700,12 @@ void StartUp(Bool defaultScreenOnly)
wShapeSupported = XShapeQueryExtension(dpy, &wShapeEventBase, &j);
#endif
+#ifdef HAVE_XRANDR
+ has_randr = XRRQueryExtension(dpy, &randr_event_base, &dummy);
+#else
+ has_randr = false;
+#endif
+
#ifdef KEEP_XKB_LOCK_STATUS
wXkbSupported = XkbQueryExtension(dpy, NULL, &wXkbEventBase, NULL,
NULL, NULL);
if (wPreferences.modelock && !wXkbSupported) {
--
1.7.2.2.119.gf9c33
--
To unsubscribe, send mail to [email protected].