]> git.mdlowis.com Git - projs/tide.git/commitdiff
removed pointer warping and updated registrar to only rely on _NET_ACTIVE_WINDOW...
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 1 Apr 2020 17:45:58 +0000 (13:45 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 1 Apr 2020 17:45:58 +0000 (13:45 -0400)
inc/io.h
inc/x11.h
src/edit.c
src/lib/abspath.c [new file with mode: 0644]
src/lib/draw.c
src/lib/x11.c
src/lib/x11_gc.c
src/registrar.c
src/tide.c

index 385e7e779920cd08172a0e69e4a80a61969df6c2..d5fe389f2b5f61ef165f580c0035167a1c0f198a 100644 (file)
--- a/inc/io.h
+++ b/inc/io.h
@@ -6,3 +6,4 @@ void telem_send(char* fmt, ...);
 long writefd(int fd, char* data, long towrite);
 long readfd(int fd, char* data, long toread);
 char* readfile(char* path);
+char* abspath(char* path);
index d3f59ac0eb6e41305b5696722eea9dee5e44a92a..c5a9a0f14ef022a222988f7bdf3429de2e222b8b 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -140,6 +140,7 @@ void x11_event_loop(XConf* x, void (*redraw)(XConf* x));
 int x11_getptr(XConf* x, int* ptrx, int* ptry);
 uint32_t x11_getkey(XConf* x, XEvent* e);
 uint32_t x11_process_key(XConf* x, XEvent* e, KeyBinding* keys);
+int x11_seturgent(XConf* x, int urgent);
 
 void x11_centerwin(XConf* x);
 void x11_init_gc(XConf* x);
index 4f61aefa7f5b614cb1329f06662b77803600c621..c01ad258bcc350eb5130d682b5c6e3cf74103ae9 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdc.h>
 #include <x11.h>
+#include <io.h>
 
 #include "config.h"
 
@@ -40,14 +41,13 @@ void prop_set(XConf* x, Window win, char* prop, char* value)
 void edit_file(XConf* x, Window registrar, char* path, char* addr, int force)
 {
     char host[8192];
-    char* rpath = realpath(path, NULL);
-    prop_set(x, x->self, "FILE", (rpath ? rpath : path));
+    path = abspath(path);
+    prop_set(x, x->self, "FILE", path);
     prop_set(x, x->self, "ADDR", addr);
     if (!gethostname(host, sizeof(host)))
     {
         prop_set(x, x->self, "HOST", host);
     }
-    free(rpath);
     XChangeProperty(
         x->display, registrar, XA_OPEN, XA_WINDOW, 32, PropModeAppend,
         (const unsigned char *)&(x->self), 1);
@@ -80,6 +80,7 @@ void edit_file(XConf* x, Window registrar, char* path, char* addr, int force)
             }
         }
     }
+    free(path);
 }
 
 int main(int argc, char** argv)
diff --git a/src/lib/abspath.c b/src/lib/abspath.c
new file mode 100644 (file)
index 0000000..6333823
--- /dev/null
@@ -0,0 +1,12 @@
+#include <stdlib.h>
+#include <string.h>
+
+char* abspath(char* path)
+{
+    char* ap = realpath(path, NULL);
+    if (!ap)
+    {
+        ap = strdup(path);
+    }
+    return ap;
+}
index 747ee010dcfa13fa0cf56b4f3e6c4a231be0219b..493cdb12c63aedfee74cac90594faa54dc955544 100644 (file)
@@ -65,7 +65,7 @@ void draw_view(XConf* x, View* view, XftFont* font, size_t nrows, drawcsr* csr,
                     csr_drawn = draw_csr(x, view, fg, fheight, posx, y, csr_drawn);
                 if (csrsync && row->cols[i].off == view->buffer.selection.beg)
                 {
-                    XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, posx + row->cols[i].width/2, y + fheight*3/4);
+                    //XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, posx + row->cols[i].width/2, y + fheight*3/4);
                     csrsync = false;
                 }
                 specs = realloc(specs, sizeof(XftGlyphSpec) * ++nspecs);
index d10b25e821240df5e1c0847c242e5f4ba9e0de22..4cbc1bf20999664c61948e3552ba03d2e5cb44e6 100644 (file)
@@ -62,7 +62,7 @@ void x11_mkwin(XConf* x, int width, int height, int evmask)
     attr.bit_gravity = NorthWestGravity;
     attr.backing_store = WhenMapped;
     attr.event_mask = evmask
-        | FocusChangeMask
+        | EnterWindowMask
         | ExposureMask
         | VisibilityChangeMask
         | StructureNotifyMask
@@ -232,3 +232,25 @@ uint32_t x11_process_key(XConf* x, XEvent* e, KeyBinding* keys)
      * the private use area is used to encode special keys */
     return (key < 0xE000 || key > 0xF8FF ? key : RUNE_ERR);
 }
+
+int x11_seturgent(XConf* x, int urgent)
+{
+    int status = 0;
+    XWMHints hints = {0}, *prevhints = XGetWMHints(x->display, x->self);
+    if (prevhints)
+    {
+        hints = *prevhints;
+        XFree(prevhints);
+    }
+    if (urgent)
+    {
+        hints.flags |= XUrgencyHint;
+    }
+    else
+    {
+        hints.flags &= ~XUrgencyHint;
+    }
+    status = XSetWMHints(x->display, x->self, &hints);
+    telem_send("URGENT(%d %d)\n", urgent, status);
+    return status;
+}
index 77c8211d8a4a59e67d1446124ae120ce9479e148..ef492cb8f4c97a67b98caffb3cfd0e289471b8a1 100644 (file)
@@ -19,7 +19,13 @@ void x11_resize(XConf* x, XEvent* e)
 void x11_mapnotify(XConf* x, XEvent* e)
 {
     telem_send("XMAPNOTIFY(0x%x)\n", e->xmap.window);
-    XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, x->width/2, x->height/2);
+//    XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, x->width/2, x->height/2);
+}
+
+void x11_enternotify(XConf* x, XEvent* e)
+{
+    telem_send("XENTERNOTIFY(0x%x)\n", e->xmap.window);
+    x11_seturgent(x, 0);
 }
 
 void x11_init_gc(XConf* x)
@@ -37,6 +43,7 @@ void x11_init_gc(XConf* x)
     x->gc = XCreateGC(x->display, x->self, GCGraphicsExposures, &gcv);
     x->eventfns[ConfigureNotify] = x11_resize;
     x->eventfns[MapNotify] = x11_mapnotify;
+    x->eventfns[EnterNotify] = x11_enternotify;
 }
 
 void x11_centerwin(XConf* x)
@@ -91,7 +98,7 @@ void x11_show(XConf* x)
         }
     }
     while (ev.type != MapNotify);
-    XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, x->width/2, x->height/2);
+//    XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, x->width/2, x->height/2);
 }
 
 XftFont* x11_font_load(XConf* x, char* name)
index 7a4cc345f4e4d894f0c35e035ff16ace95cbf8b0..f9d4c87dfa40b7fb40c53c52062751ce71b44ebb 100644 (file)
@@ -93,6 +93,7 @@ static void win_del(Window id)
 
 static void win_send(XConf* x, Window from, Window to, int mask, char* atom, size_t val)
 {
+    telem_send("WIN_SEND(from: %lx, to: %lx, atom: %d)\n", from, to, atom);
     XEvent ev = {0};
     ev.xclient.type = ClientMessage;
     ev.xclient.send_event = True;
@@ -107,6 +108,7 @@ static void win_open(XConf* x, Window winid, char* path, char* addr, char* host)
 {
     if (path)
     {
+        telem_send("WIN_OPEN(%lx '%s' '%s')\n", winid, path, host);
         /* search for an existing window */
         for (TWindow* win = Windows; win; win = win->next)
         {
@@ -115,7 +117,7 @@ static void win_open(XConf* x, Window winid, char* path, char* addr, char* host)
             win->path = NULL;
             char* file = readprop(x, win->win, "FILE", XA_STRING, NULL);
             win->path = (file ? file : NULL);
-
+            telem_send("    %lx '%s' '%s'\n", win->win, win->path, win->host);
             if (win->host && !strcmp(win->host, host) &&
                 win->path && !strcmp(win->path, path))
             {
@@ -125,7 +127,6 @@ static void win_open(XConf* x, Window winid, char* path, char* addr, char* host)
                 char* type = readprop(x, win->win, "TIDE", XA_STRING, 0);
                 if (!type || x11_error_get())
                 {
-                    puts("window invalid, marking for cleanup");
                     free(win->path), win->path = NULL;
                     free(win->host), win->host = NULL;
                     free(type);
@@ -133,15 +134,16 @@ static void win_open(XConf* x, Window winid, char* path, char* addr, char* host)
                 }
                 else
                 {
-                    puts("window still valid, raising");
                     XEvent ev = {0};
                     ev.xclient.type = ClientMessage;
                     ev.xclient.send_event = True;
                     ev.xclient.message_type = XInternAtom(x->display, "_NET_ACTIVE_WINDOW", False);
                     ev.xclient.window = win->win;
                     ev.xclient.format = 32;
+                    ev.xclient.data.l[0] = 1;
+                    ev.xclient.data.l[1] = CurrentTime;
+                    ev.xclient.data.l[2] = 0;
                     XSendEvent(x->display, x->root, False, SubstructureRedirectMask|SubstructureNotifyMask, &ev);
-                    XMapRaised(x->display, win->win);
                     win_send(x, x->self, win->win, 0,  "GOTO", strtoul(addr, NULL, 0));
                     win_send(x, x->self, winid, 0,  "DONE", 0);
                     free(type);
index 13e2e3ab0350b30e3f38b074c598dd5730c284d5..8fe3fc97a595fe82f42a27e5c86619c3bbba4a66 100644 (file)
@@ -235,9 +235,14 @@ static void xbtnmotion(XConf* x, XEvent* e)
 static void xclientmsg(XConf* x, XEvent* e)
 {
     if ((Atom)(e->xclient.data.l[0]) == XInternAtom(x->display, "WM_DELETE_WINDOW", False))
+    {
         win_quit();
+    }
     else if (e->xclient.message_type == XInternAtom(x->display, "GOTO", False))
+    {
+        x11_seturgent(x, 1);
         win_setln(e->xclient.data.l[0]);
+    }
 }
 
 void xresize(XConf* x, XEvent* e)
@@ -441,7 +446,7 @@ static void put(char* arg)
     if (buf_save(buf, arg) == NORMAL)
     {
         /* convert saved path to absolute path */
-        char* path = realpath(buf->path, NULL);
+        char* path = abspath(buf->path);
         buf_setpath(buf, path);
         free(path);
     }
@@ -716,20 +721,19 @@ static void usage(void)
 
 static void edit_file(char* file, int line_num)
 {
-    char* path = realpath(file, NULL);
-    if (!path) path = strdup(file); /* if file doesnt exist, use the original name */
-    if (!strcmp("-", path))
+    file = abspath(file);
+    if (!strcmp("-", file))
     {
         job_readfd(STDIN_FILENO, win_view(EDIT));
     }
     else
     {
-        view_init(win_view(EDIT), path);
+        view_init(win_view(EDIT), file);
         win_setln(line_num);
-        win_title(path);
-        win_prop_set("FILE", "file", path);
+        win_title(file);
+        win_prop_set("FILE", "file", file);
     }
-    free(path);
+    free(file);
 }
 
 int main(int argc, char** argv)