changeset: 2272:392f0fdd29fa
user: Kris Maglione <jg_AT_suckless.org>
date: Sun Feb 03 15:06:21 2008 -0500
summary: Take rotation into account on RandR screen change notify.
diff -r 28abf570b460 -r 392f0fdd29fa cmd/wmii/xext.c
--- a/cmd/wmii/xext.c Fri Feb 01 22:11:06 2008 -0500
+++ b/cmd/wmii/xext.c Sun Feb 03 15:06:21 2008 -0500
@@ -10,9 +10,20 @@
#endif
static void randr_screenchange(XRRScreenChangeNotifyEvent*);
+static bool randr_event_p(XEvent *e);
+
+typedef void (*EvHandler)(XEvent*);
+static EvHandler randr_handlers[RRNumberEvents];
bool have_RandR;
int randr_eventbase;
+
+static void
+handle(XEvent *e, EvHandler ha[], int base) {
+
+ if(ha[e->type-base])
+ ha[e->type-base](e);
+}
void
xext_init(void) {
@@ -22,8 +33,8 @@ void
void
xext_event(XEvent *e) {
- if(have_RandR && (ulong)(e->type - randr_eventbase) < RRNumberEvents)
- randr_event(e);
+ if(randr_event_p(e))
+ handle(e, randr_handlers, randr_eventbase);
}
void
@@ -34,9 +45,14 @@ randr_init(void) {
if(have_RandR)
if(XRRQueryVersion(display, &major, &minor) && major < 1)
have_RandR = false;
- if(!have_RandR)
- return;
- XRRSelectInput(display, scr.root.w, RRScreenChangeNotifyMask);
+ if(have_RandR)
+ XRRSelectInput(display, scr.root.w, RRScreenChangeNotifyMask);
+}
+
+static bool
+randr_event_p(XEvent *e) {
+ return have_RandR
+ && (uint)e->type - randr_eventbase < RRNumberEvents;
}
static void
@@ -45,10 +61,13 @@ randr_screenchange(XRRScreenChangeNotify
Point d;
XRRUpdateConfiguration((XEvent*)ev);
- scr.rect = Rect(0, 0, ev->width, ev->height);
+ if(ev->rotation+90 % 180)
+ scr.rect = Rect(0, 0, ev->width, ev->height);
+ else
+ scr.rect = Rect(0, 0, ev->height, ev->width);
- d.x = ev->width - Dx(screen->r);
- d.y = ev->height - Dy(screen->r);
+ d.x = Dx(scr.rect) - Dx(screen->r);
+ d.y = Dy(scr.rect) - Dy(screen->r);
for(v=view; v; v=v->next) {
v->r.max.x += d.x;
v->r.max.y += d.y;
@@ -57,15 +76,7 @@ randr_screenchange(XRRScreenChangeNotify
bar_resize(screen);
}
-void
-randr_event(XEvent *e) {
+static EvHandler randr_handlers[] = {
+ [RRScreenChangeNotify] = (EvHandler)randr_screenchange,
+};
- switch(e->type-randr_eventbase) {
- default:
- break;
- case RRScreenChangeNotify: /* Yuck. */
- randr_screenchange((XRRScreenChangeNotifyEvent*)e);
- break;
- }
-}
-
Received on Sun Feb 03 2008 - 21:11:53 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:59:15 UTC