resize lockscreen window after Xrandr resize

This commit is contained in:
Markus Teich 2015-02-25 23:06:45 +01:00
parent f2ea92c3dd
commit f5ef1b8eb5
2 changed files with 17 additions and 3 deletions

View file

@ -11,7 +11,7 @@ X11LIB = /usr/X11R6/lib
# includes and libs # includes and libs
INCS = -I. -I/usr/include -I${X11INC} INCS = -I. -I/usr/include -I${X11INC}
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr
# flags # flags
CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H

16
slock.c
View file

@ -13,6 +13,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <X11/extensions/Xrandr.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
@ -41,6 +42,9 @@ typedef struct {
static Lock **locks; static Lock **locks;
static int nscreens; static int nscreens;
static Bool running = True; static Bool running = True;
static Bool rr;
static int rrevbase;
static int rrerrbase;
static void static void
die(const char *errstr, ...) die(const char *errstr, ...)
@ -179,8 +183,15 @@ readpw(Display *dpy, const char *pws)
} }
} }
llen = len; llen = len;
} else if (rr && ev.type == rrevbase + RRScreenChangeNotify) {
XRRScreenChangeNotifyEvent *rre = (XRRScreenChangeNotifyEvent*)&ev;
for (screen = 0; screen < nscreens; screen++) {
if (locks[screen]->win == rre->window) {
XResizeWindow(dpy, locks[screen]->win, rre->width, rre->height);
XClearWindow(dpy, locks[screen]->win);
} }
else for (screen = 0; screen < nscreens; screen++) }
} else for (screen = 0; screen < nscreens; screen++)
XRaiseWindow(dpy, locks[screen]->win); XRaiseWindow(dpy, locks[screen]->win);
} }
} }
@ -236,6 +247,8 @@ lockscreen(Display *dpy, int screen)
invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0); invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0);
XDefineCursor(dpy, lock->win, invisible); XDefineCursor(dpy, lock->win, invisible);
XMapRaised(dpy, lock->win); XMapRaised(dpy, lock->win);
if (rr)
XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask);
for (len = 1000; len; len--) { for (len = 1000; len; len--) {
if (XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, if (XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess) GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess)
@ -295,6 +308,7 @@ main(int argc, char **argv) {
if (!(dpy = XOpenDisplay(0))) if (!(dpy = XOpenDisplay(0)))
die("slock: cannot open display\n"); die("slock: cannot open display\n");
rr = XRRQueryExtension(dpy, &rrevbase, &rrerrbase);
/* Get the number of screens in display "dpy" and blank them all. */ /* Get the number of screens in display "dpy" and blank them all. */
nscreens = ScreenCount(dpy); nscreens = ScreenCount(dpy);
locks = malloc(sizeof(Lock *) * nscreens); locks = malloc(sizeof(Lock *) * nscreens);