]> git.mdlowis.com Git - projs/tide.git/commitdiff
implemented logic to center the pick window on the currently active monitor
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 11 Dec 2018 15:24:17 +0000 (10:24 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 11 Dec 2018 15:24:17 +0000 (10:24 -0500)
TODO.md
config.mk
inc/x11.h
src/pick.c

diff --git a/TODO.md b/TODO.md
index ea22584cff6c873e40e6306f1330541df27b1cf5..4f72d7ee33bb906bc646cd7539024d52cbe357cb 100644 (file)
--- 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
index f203e4f00c9302fb810c7efc0f6eb77b2171c0c4..b5ca15e3fd251e3070ad10abfb349b7049786038 100644 (file)
--- 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
index b9c6571e62219e05346b00a7bc75c560d1a06fc5..bb4cb650181fcaf26382d94db77ca6603b1a434c 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -1,6 +1,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #include <X11/Xft/Xft.h>
+#include <X11/extensions/Xinerama.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <signal.h>
@@ -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)))
index b932e43cfa21f1373044a4048fc88eef856bc265..c2810a77c3bca3eda39b74bbf7659900a2887e74 100644 (file)
@@ -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;