From b511da0eddb95606c99ceefda8e74f74660f4a75 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 8 Jan 2019 13:52:09 -0500 Subject: [PATCH] added logic to find all tide windows when registrar starts --- TODO.md | 1 - config.h | 2 +- src/registrar.c | 34 +++++++++++++++++++++++----------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/TODO.md b/TODO.md index 39559c9..b520f69 100644 --- a/TODO.md +++ b/TODO.md @@ -8,7 +8,6 @@ * registrar: group by hostname or group env var in registrar * registrar: should remove invalid windows from registry when detected * tide: Ctrl+D should not pass tag name as arg when executing tag commands -* tide: should re-register with the registrar when a new registrar is launched * tide: gap buffer does not handle UTF-8 currently ## BACKLOG diff --git a/config.h b/config.h index 32fb318..9dfd6a5 100644 --- a/config.h +++ b/config.h @@ -24,7 +24,7 @@ static char* EditCmd[] = { "tide", "-l", 0, 0, 0 }; static char* ShellCmd[] = { 0, "-c", 0, 0 }; /* Sed command used to execute commands marked with ':' sigil */ -static char* SedCmd[] = { "sed", "-e", 0, 0 }; +static char* SedCmd[] = { "sed", "-Ee", 0, 0 }; /* Command used to fetch some text based on a set of rules */ static char* FetchCmd[] = { "fetch", 0, 0 }; diff --git a/src/registrar.c b/src/registrar.c index b6c6f62..653f423 100644 --- a/src/registrar.c +++ b/src/registrar.c @@ -9,23 +9,29 @@ typedef struct TWindow { char* path; } TWindow; +char* ARGV0; +int Foreground = 0; Atom XA_REGISTRAR, XA_ADD, XA_DEL, XA_OPEN, XA_DONE; TWindow* Windows = NULL; -char* readprop(XConf* x, Window win, char* prop, size_t* length) { - Atom type, xa_prop = XInternAtom(x->display, prop, False); +void* readprop(XConf* x, Window win, char* prop, Atom type, size_t* length) { + Atom rtype, xa_prop = XInternAtom(x->display, prop, False); int format; unsigned long datalen, nleft; unsigned char* data = NULL; XGetWindowProperty( - x->display, win, xa_prop, 0, -1, True, XA_STRING, - &type, &format, &datalen, &nleft, &data); + x->display, win, xa_prop, 0, -1, True, type, + &rtype, &format, &datalen, &nleft, &data); if (length) *length = datalen; - return (char*)data; + if (rtype != type) { + if (data) XFree(data); + data = 0, *length = 0; + } + return (void*)data; } void win_add(XConf* x, Window id) { - char* path = readprop(x, id, "FILE", 0); + char* path = readprop(x, id, "FILE", XA_STRING, 0); if (!path) return; TWindow* win = calloc(1, sizeof(TWindow)); win->win = id; @@ -104,14 +110,22 @@ void propnotify(XConf* x, XEvent* e) { x->display, x->self, XA_OPEN, 0, -1, True, XA_WINDOW, &type, &format, &datalen, &nleft, &data); for (Window* win = (Window*)data; datalen && win && *win; win++, datalen--) { - char* file = readprop(x, *win, "FILE", NULL); - char* addr = readprop(x, *win, "ADDR", NULL); + char* file = readprop(x, *win, "FILE", XA_STRING, NULL); + char* addr = readprop(x, *win, "ADDR", XA_STRING, NULL); win_open(x, *win, file, (addr ? addr : "0")); if(file) XFree(file); if(addr) XFree(addr); } } +void find_windows(XConf* x) { + size_t nwindows = 0; + Window* windows = readprop(x, x->root, "_NET_CLIENT_LIST", XA_WINDOW, &nwindows); + for (size_t i = 0; i < nwindows; i++) + win_add(x, windows[i]); + if (windows) XFree(windows); +} + int daemonize(void) { int status; /* fork into the background first */ @@ -136,9 +150,6 @@ int daemonize(void) { return 0; } -char* ARGV0; -int Foreground = 0; - int main(int argc, char** argv) { OPTBEGIN { case 'F': Foreground = 1; break; @@ -158,6 +169,7 @@ int main(int argc, char** argv) { if (None == XGetSelectionOwner(x.display, XA_REGISTRAR)) { XSetSelectionOwner(x.display, XA_REGISTRAR, x.self, CurrentTime); if (x.self == XGetSelectionOwner(x.display, XA_REGISTRAR)) { + find_windows(&x); x11_event_loop(&x, 0); } } -- 2.51.0