From: Michael D. Lowis Date: Wed, 1 Apr 2020 17:45:58 +0000 (-0400) Subject: removed pointer warping and updated registrar to only rely on _NET_ACTIVE_WINDOW... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=568ee8ec43c1eb7abc69223ca72a1b75ff1580db;p=projs%2Ftide.git removed pointer warping and updated registrar to only rely on _NET_ACTIVE_WINDOW requests for activating windows --- diff --git a/inc/io.h b/inc/io.h index 385e7e7..d5fe389 100644 --- 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); diff --git a/inc/x11.h b/inc/x11.h index d3f59ac..c5a9a0f 100644 --- 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); diff --git a/src/edit.c b/src/edit.c index 4f61aef..c01ad25 100644 --- a/src/edit.c +++ b/src/edit.c @@ -1,5 +1,6 @@ #include #include +#include #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 index 0000000..6333823 --- /dev/null +++ b/src/lib/abspath.c @@ -0,0 +1,12 @@ +#include +#include + +char* abspath(char* path) +{ + char* ap = realpath(path, NULL); + if (!ap) + { + ap = strdup(path); + } + return ap; +} diff --git a/src/lib/draw.c b/src/lib/draw.c index 747ee01..493cdb1 100644 --- a/src/lib/draw.c +++ b/src/lib/draw.c @@ -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); diff --git a/src/lib/x11.c b/src/lib/x11.c index d10b25e..4cbc1bf 100644 --- a/src/lib/x11.c +++ b/src/lib/x11.c @@ -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; +} diff --git a/src/lib/x11_gc.c b/src/lib/x11_gc.c index 77c8211..ef492cb 100644 --- a/src/lib/x11_gc.c +++ b/src/lib/x11_gc.c @@ -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) diff --git a/src/registrar.c b/src/registrar.c index 7a4cc34..f9d4c87 100644 --- a/src/registrar.c +++ b/src/registrar.c @@ -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); diff --git a/src/tide.c b/src/tide.c index 13e2e3a..8fe3fc9 100644 --- a/src/tide.c +++ b/src/tide.c @@ -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)