use Xrandr to store monitor info; next we must use this info to place windows
This commit is contained in:
parent
4981ffdc8c
commit
b171a66b5c
14 changed files with 100 additions and 2 deletions
1
client.c
1
client.c
|
@ -6,6 +6,7 @@
|
|||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "config.h"
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
|
1
color.c
1
color.c
|
@ -4,6 +4,7 @@
|
|||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
||||
|
|
1
cursor.c
1
cursor.c
|
@ -3,6 +3,7 @@
|
|||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
||||
|
|
9
dat.h
9
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;
|
||||
|
|
1
error.c
1
error.c
|
@ -5,6 +5,7 @@
|
|||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xproto.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
||||
|
|
18
event.c
18
event.c
|
@ -12,6 +12,7 @@
|
|||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#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;
|
||||
|
|
4
fns.h
4
fns.h
|
@ -122,3 +122,7 @@ void dotrace();
|
|||
void initcurs();
|
||||
|
||||
void ShowEvent(XEvent*);
|
||||
|
||||
void fetchmonitorinfo();
|
||||
int getmonitorbyclient(Client*);
|
||||
int getmonitorbymouse();
|
1
grab.c
1
grab.c
|
@ -4,6 +4,7 @@
|
|||
#include <X11/Xos.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
||||
|
|
1
key.c
1
key.c
|
@ -14,6 +14,7 @@
|
|||
#include <X11/Xatom.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "config.h"
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
|
4
main.c
4
main.c
|
@ -12,6 +12,7 @@
|
|||
#ifdef SHAPE
|
||||
#include <X11/extensions/shape.h>
|
||||
#endif
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "config.h"
|
||||
#ifdef VIRTNOTIFY
|
||||
#include <libnotify/notify.h>
|
||||
|
@ -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) {
|
||||
|
|
1
manage.c
1
manage.c
|
@ -16,6 +16,7 @@
|
|||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "config.h"
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
|
1
menu.c
1
menu.c
|
@ -14,6 +14,7 @@
|
|||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "config.h"
|
||||
#ifdef VIRTNOTIFY
|
||||
#include <libnotify/notify.h>
|
||||
|
|
3
mkfile
3
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
|
||||
|
||||
|
|
56
monitor.c
Normal file
56
monitor.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#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;
|
||||
}
|
Loading…
Reference in a new issue