]> git.mdlowis.com Git - projs/tide.git/commitdiff
added logic to find all tide windows when registrar starts
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 8 Jan 2019 18:52:09 +0000 (13:52 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 8 Jan 2019 18:52:09 +0000 (13:52 -0500)
TODO.md
config.h
src/registrar.c

diff --git a/TODO.md b/TODO.md
index 39559c97c0e4ce71e8874d6421edc2bf73adc0ac..b520f69722b66101d6874c2982e25a51b251c46e 100644 (file)
--- 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
index 32fb3186bcc8f7d2cb5d3e9dbd5677bd8e140c30..9dfd6a5d835e6b42553d142f2f6b8c9204aacef4 100644 (file)
--- 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 };
index b6c6f624de0c930208d0f00b1b51f53ee8863586..653f423882d29dbc023197f2d74ff5d7beab73ce 100644 (file)
@@ -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);
         }
     }