diff --git a/client.c b/client.c index 89c4443..81cf5d5 100644 --- a/client.c +++ b/client.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "config.h" #include "dat.h" #include "fns.h" diff --git a/color.c b/color.c index 4d41716..720d94b 100644 --- a/color.c +++ b/color.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "dat.h" #include "fns.h" diff --git a/cursor.c b/cursor.c index 69d0c0f..2c7b67e 100644 --- a/cursor.c +++ b/cursor.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "dat.h" #include "fns.h" diff --git a/dat.h b/dat.h index 8e74b22..e450a4b 100644 --- a/dat.h +++ b/dat.h @@ -1,5 +1,7 @@ /* Copyright (c) 1994-1996 David Hogan, see README for licence details */ - +#ifndef MAX_MONITORS +#define MAX_MONITORS 8 +#endif #ifndef BORDER #define BORDER _border #endif @@ -196,3 +198,8 @@ extern int ignore_badwindow; /* key.c and event.c share this */ extern int kbLaunch; + +/* multimonitor biz */ + +extern int nmonitors; +extern XRRMonitorInfo* monitorinfo; diff --git a/error.c b/error.c index 694f080..b1e349c 100644 --- a/error.c +++ b/error.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "dat.h" #include "fns.h" diff --git a/event.c b/event.c index 0fccb42..8bb8a48 100644 --- a/event.c +++ b/event.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "config.h" #include "dat.h" #include "fns.h" @@ -19,6 +20,7 @@ void mainloop(int shape_event) { XEvent ev; + int i; for (;;) { getevent(&ev); @@ -37,6 +39,22 @@ void mainloop(int shape_event) { #endif fprintf(stderr, "ryudo: unknown ev.type %d\n", ev.type); break; + /* XRANDR related events; idk what the define for this is */ + case 89: + if (XRRUpdateConfiguration(&ev)) { + fetchmonitorinfo(); + fprintf(stderr, "%d monitors:\n", nmonitors); + for (i = 0; i < nmonitors; i++) { + fprintf( + stderr, + " %d,%d,%d,%d\n", + monitorinfo[i].x, + monitorinfo[i].y, + monitorinfo[i].width, + monitorinfo[i].height); + } + } + break; case KeyPress: keypress(&ev.xkey); break; diff --git a/fns.h b/fns.h index 3c9b36e..f35d6b6 100644 --- a/fns.h +++ b/fns.h @@ -122,3 +122,7 @@ void dotrace(); void initcurs(); void ShowEvent(XEvent*); + +void fetchmonitorinfo(); +int getmonitorbyclient(Client*); +int getmonitorbymouse(); \ No newline at end of file diff --git a/grab.c b/grab.c index 6b53ff4..1276006 100644 --- a/grab.c +++ b/grab.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "dat.h" #include "fns.h" diff --git a/key.c b/key.c index 8de96d7..607a891 100644 --- a/key.c +++ b/key.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "config.h" #include "dat.h" #include "fns.h" diff --git a/main.c b/main.c index 6e08bc0..cc00c82 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,7 @@ #ifdef SHAPE #include #endif +#include #include "config.h" #ifdef VIRTNOTIFY #include @@ -392,6 +393,9 @@ void initscreen(ScreenInfo* s, int i, int background) { s->vis, CWBackPixel | CWBorderPixel | CWColormap, &attrs); + + XRRSelectInput(dpy, DefaultRootWindow(dpy), RRScreenChangeNotifyMask); + fetchmonitorinfo(); } ScreenInfo* getscreen(Window w) { diff --git a/manage.c b/manage.c index 2191a84..881d6e7 100644 --- a/manage.c +++ b/manage.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "config.h" #include "dat.h" #include "fns.h" diff --git a/menu.c b/menu.c index cefa878..95953e0 100644 --- a/menu.c +++ b/menu.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "config.h" #ifdef VIRTNOTIFY #include diff --git a/mkfile b/mkfile index aef1123..7226fe1 100755 --- a/mkfile +++ b/mkfile @@ -12,6 +12,7 @@ RIOFILES=\ main.$O\ manage.$O\ menu.$O\ + monitor.$O\ HFILES=dat.h fns.h @@ -22,7 +23,7 @@ TARG=rio xshove # Bug in mk? "$L64 -lXext" gobbles the space, so # add trailing slash. L64=`[ -d $X11/lib64 ] && echo 64; echo` -LDFLAGS=-L$X11/lib$L64/ -Llibnotify/ -lnotify -lXext -lX11 $LDFLAGS +LDFLAGS=-L$X11/lib$L64/ -Llibnotify/ -lnotify -lXext -lX11 -lXrandr $LDFLAGS <|sh mkriorules.sh diff --git a/monitor.c b/monitor.c new file mode 100644 index 0000000..9196a8d --- /dev/null +++ b/monitor.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include "dat.h" +#include "fns.h" + +int nmonitors = 0; +XRRMonitorInfo* monitorinfo; + +void fetchmonitorinfo() { + if (monitorinfo) + XRRFreeMonitors(monitorinfo); + + monitorinfo = XRRGetMonitors(dpy, DefaultRootWindow(dpy), 1, &nmonitors); +} + +int getmonitorbyclient(Client* c) { + XRRMonitorInfo m; + int cx, cy, i, p; + cx = c->x + c->dx / 2; + cy = c->y + c->dy / 2; + + p = 0; + + for (i = 0; i < nmonitors; i++) { + m = monitorinfo[i]; + if (cx >= m.x && cx < m.x + m.width && cy >= m.y && cy < m.y + m.height) { + return i; + } + + if (m.primary) { + p = i; + } + } + + /* if center is not within any window, return primary */ + return p; +} + +int getmonitorbymouse() { + Window w; + int x, y, i; + unsigned int mask; + XRRMonitorInfo m; + + XQueryPointer(dpy, DefaultRootWindow(dpy), &w, &w, &x, &y, &x, &y, &mask); + for (i = 0; i < nmonitors; i++) { + m = monitorinfo[i]; + if (x >= m.x && x < m.x + m.width && y >= m.y && y < m.y + m.height) { + return i; + } + } + /* should never reach here, but return first monitor if we do */ + return 0; +} \ No newline at end of file