use Xrandr to store monitor info; next we must use this info to place windows

This commit is contained in:
Iris Lightshard 2022-02-27 10:18:17 -07:00
parent 4981ffdc8c
commit b171a66b5c
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
14 changed files with 100 additions and 2 deletions

View file

@ -6,6 +6,7 @@
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h>
#include "config.h" #include "config.h"
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"

View file

@ -4,6 +4,7 @@
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h>
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"

View file

@ -3,6 +3,7 @@
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h>
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"

9
dat.h
View file

@ -1,5 +1,7 @@
/* Copyright (c) 1994-1996 David Hogan, see README for licence details */ /* Copyright (c) 1994-1996 David Hogan, see README for licence details */
#ifndef MAX_MONITORS
#define MAX_MONITORS 8
#endif
#ifndef BORDER #ifndef BORDER
#define BORDER _border #define BORDER _border
#endif #endif
@ -196,3 +198,8 @@ extern int ignore_badwindow;
/* key.c and event.c share this */ /* key.c and event.c share this */
extern int kbLaunch; extern int kbLaunch;
/* multimonitor biz */
extern int nmonitors;
extern XRRMonitorInfo* monitorinfo;

View file

@ -5,6 +5,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xproto.h> #include <X11/Xproto.h>
#include <X11/extensions/Xrandr.h>
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"

18
event.c
View file

@ -12,6 +12,7 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>
#include <X11/extensions/Xrandr.h>
#include "config.h" #include "config.h"
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
@ -19,6 +20,7 @@
void mainloop(int shape_event) { void mainloop(int shape_event) {
XEvent ev; XEvent ev;
int i;
for (;;) { for (;;) {
getevent(&ev); getevent(&ev);
@ -37,6 +39,22 @@ void mainloop(int shape_event) {
#endif #endif
fprintf(stderr, "ryudo: unknown ev.type %d\n", ev.type); fprintf(stderr, "ryudo: unknown ev.type %d\n", ev.type);
break; 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: case KeyPress:
keypress(&ev.xkey); keypress(&ev.xkey);
break; break;

4
fns.h
View file

@ -122,3 +122,7 @@ void dotrace();
void initcurs(); void initcurs();
void ShowEvent(XEvent*); void ShowEvent(XEvent*);
void fetchmonitorinfo();
int getmonitorbyclient(Client*);
int getmonitorbymouse();

1
grab.c
View file

@ -4,6 +4,7 @@
#include <X11/Xos.h> #include <X11/Xos.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h>
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"

1
key.c
View file

@ -14,6 +14,7 @@
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>
#include <X11/extensions/Xrandr.h>
#include "config.h" #include "config.h"
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"

4
main.c
View file

@ -12,6 +12,7 @@
#ifdef SHAPE #ifdef SHAPE
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>
#endif #endif
#include <X11/extensions/Xrandr.h>
#include "config.h" #include "config.h"
#ifdef VIRTNOTIFY #ifdef VIRTNOTIFY
#include <libnotify/notify.h> #include <libnotify/notify.h>
@ -392,6 +393,9 @@ void initscreen(ScreenInfo* s, int i, int background) {
s->vis, s->vis,
CWBackPixel | CWBorderPixel | CWColormap, CWBackPixel | CWBorderPixel | CWColormap,
&attrs); &attrs);
XRRSelectInput(dpy, DefaultRootWindow(dpy), RRScreenChangeNotifyMask);
fetchmonitorinfo();
} }
ScreenInfo* getscreen(Window w) { ScreenInfo* getscreen(Window w) {

View file

@ -16,6 +16,7 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>
#include <X11/extensions/Xrandr.h>
#include "config.h" #include "config.h"
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"

1
menu.c
View file

@ -14,6 +14,7 @@
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h>
#include "config.h" #include "config.h"
#ifdef VIRTNOTIFY #ifdef VIRTNOTIFY
#include <libnotify/notify.h> #include <libnotify/notify.h>

3
mkfile
View file

@ -12,6 +12,7 @@ RIOFILES=\
main.$O\ main.$O\
manage.$O\ manage.$O\
menu.$O\ menu.$O\
monitor.$O\
HFILES=dat.h fns.h HFILES=dat.h fns.h
@ -22,7 +23,7 @@ TARG=rio xshove
# Bug in mk? "$L64 -lXext" gobbles the space, so # Bug in mk? "$L64 -lXext" gobbles the space, so
# add trailing slash. # add trailing slash.
L64=`[ -d $X11/lib64 ] && echo 64; echo` 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 <|sh mkriorules.sh

56
monitor.c Normal file
View 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;
}