From 82b9773e95ced8426f1de27b07bb198b44d44b4c Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 11 Dec 2018 10:24:17 -0500 Subject: [PATCH] implemented logic to center the pick window on the currently active monitor --- TODO.md | 1 + config.mk | 2 +- inc/x11.h | 33 +++++++++++++++++++++++++++++++++ src/pick.c | 3 ++- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index ea22584..4f72d7e 100644 --- a/TODO.md +++ b/TODO.md @@ -4,6 +4,7 @@ * registrar doesnt match open windows when new file created and is then opened for edit or line number * fetch should stuff match strings in environment variables instead of evaling +* implement a mini-sed command to standardize scripts across platforms without relying on sed * registrar should remove invalid windows from registry when detected * tide should re-register with the registrar when a new registrar is launched * edit command should have a force option to launch tide without registrar notification diff --git a/config.mk b/config.mk index f203e4f..b5ca15e 100644 --- a/config.mk +++ b/config.mk @@ -26,7 +26,7 @@ CFLAGS += -Wno-missing-field-initializers # Linker Setup LD = $(CC) -LDFLAGS = $(LIBS) -lX11 -lXft -lfontconfig -lutil +LDFLAGS = $(LIBS) -lX11 -lXft -lfontconfig -lXinerama -lutil # Archive Setup AR = ar diff --git a/inc/x11.h b/inc/x11.h index b9c6571..bb4cb65 100644 --- a/inc/x11.h +++ b/inc/x11.h @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,38 @@ static void x11_mkwin(XConf* x, int width, int height, int evmask) { XSelectInput(x->display, x->self, evmask); } +static void x11_mkdialog(XConf* x, int width, int height, int evmask) { + x11_mkwin(x, width, height, evmask); + Atom WindowType = XInternAtom(x->display, "_NET_WM_WINDOW_TYPE", False); + Atom DialogType = XInternAtom(x->display, "_NET_WM_WINDOW_TYPE_DIALOG", False); + XChangeProperty(x->display, x->self, WindowType, XA_ATOM, 32, PropModeReplace, (unsigned char*)&DialogType, 1); +} + +static int x11_getptr(XConf* x, int* ptrx, int* ptry) { + Window root = 0, child = 0; + int winx = 0, winy = 0, mask = 0; + return XQueryPointer(x->display, x->self, &root, &child, ptrx, ptry, &winx, &winy, (unsigned int*)&mask); +} + +static void x11_centerwin(XConf* x) { + int ptrx = 0, ptry = 0; + (void)x11_getptr(x, &ptrx, &ptry); + int nscreens = 0; + XineramaScreenInfo* p_screens = XineramaQueryScreens(x->display, &nscreens); + for (int i = 0; i < nscreens; i++) { + int minx = p_screens[i].x_org, + maxx = p_screens[i].x_org + p_screens[i].width, + miny = p_screens[i].y_org, + maxy = p_screens[i].y_org + p_screens[i].height; + if (minx <= ptrx && ptrx <= maxx && miny <= ptry && ptry <= maxy) { + XMoveWindow(x->display, x->self, + p_screens[i].width/2 - x->width/2, + p_screens[i].height/2 - x->height/2); + break; + } + } +} + static void x11_init_gc(XConf* x) { /* set input methods */ if ((x->xim = XOpenIM(x->display, 0, 0, 0))) diff --git a/src/pick.c b/src/pick.c index b932e43..c2810a7 100644 --- a/src/pick.c +++ b/src/pick.c @@ -150,13 +150,14 @@ static void redraw(XConf* x) { static void filter(void) { XConf x = {0}; x11_init(&x); - x11_mkwin(&x, 1, 1, 0 + x11_mkdialog(&x, 640, 480, 0 | StructureNotifyMask | KeyPressMask | ButtonPressMask | ExposureMask ); x11_init_gc(&x); + x11_centerwin(&x); x11_show(&x); x.eventfns[KeyPress] = xkeypress; x.eventfns[ButtonPress] = xbtnpress; -- 2.51.0