]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed bug in property scanning of registrar
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 8 Jan 2019 19:59:34 +0000 (14:59 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 8 Jan 2019 19:59:34 +0000 (14:59 -0500)
src/edit.c
src/registrar.c

index 4c925986bdc9a238bf871c0bc826bf3d49279a33..c210f37bdb721a2c1e6c2f05762e54603d5446e4 100644 (file)
@@ -73,6 +73,10 @@ int main(int argc, char** argv) {
         XA_OPEN = XInternAtom(x.display, "OPEN", 0);
         XA_DONE = XInternAtom(x.display, "DONE", 0);
         Window registrar = start_registrar(&x);
+        if (registrar == None) {
+            fprintf(stderr, "Failed to contact registrar.\n");
+            return 1;
+        }
         /* Loop over files and send an OPEN message for each one. */
         for (int i = 0; i < argc; i++) {
             char* addr = strrchr(argv[i], ':');
index 653f423882d29dbc023197f2d74ff5d7beab73ce..29d5895a41333c7ed5e4d58cd5c0263cfdbdc9e4 100644 (file)
@@ -20,7 +20,7 @@ void* readprop(XConf* x, Window win, char* prop, Atom type, size_t* length) {
     unsigned long datalen, nleft;
     unsigned char* data = NULL;
     XGetWindowProperty(
-        x->display, win, xa_prop, 0, -1, True, type,
+        x->display, win, xa_prop, 0, -1, False, type,
         &rtype, &format, &datalen, &nleft, &data);
     if (length) *length = datalen;
     if (rtype != type) {
@@ -31,8 +31,20 @@ void* readprop(XConf* x, Window win, char* prop, Atom type, size_t* length) {
 }
 
 void win_add(XConf* x, Window id) {
-    char* path = readprop(x, id, "FILE", XA_STRING, 0);
+    int nprops;
+    char* path = NULL;
+    Atom xa_file = XInternAtom(x->display, "FILE", False);
+    Atom* props = XListProperties(x->display, id, &nprops);
+    if (!props) return;
+    for (int i = 0; i < nprops; i++) {
+        if (props[i] == xa_file) {
+            path = readprop(x, id, "FILE", XA_STRING, 0);
+            break;
+        }
+    }
+    XFree(props);
     if (!path) return;
+    printf("ADD 0x%x: '%s'\n", (unsigned int)id, path);
     TWindow* win = calloc(1, sizeof(TWindow));
     win->win = id;
     win->next = Windows;
@@ -88,6 +100,7 @@ void win_open(XConf* x, Window winid, char* path, char* addr) {
 
 void selclear(XConf* x, XEvent* e) {
     (void)x, (void)e;
+    puts("quitting");
     exit(0);
 }
 
@@ -119,11 +132,15 @@ void propnotify(XConf* x, XEvent* e) {
 }
 
 void find_windows(XConf* x) {
+    XGrabServer(x->display);
     size_t nwindows = 0;
     Window* windows = readprop(x, x->root, "_NET_CLIENT_LIST", XA_WINDOW, &nwindows);
+    printf("nwindows: %lu\n", nwindows);
+    XUngrabServer(x->display);
     for (size_t i = 0; i < nwindows; i++)
         win_add(x, windows[i]);
     if (windows) XFree(windows);
+    puts("done finding windows");
 }
 
 int daemonize(void) {
@@ -156,6 +173,7 @@ int main(int argc, char** argv) {
     } OPTEND;
     if (!Foreground && daemonize() != 0) return 1;
     XConf x = {0};
+    puts("start");
     x11_init(&x);
     x11_mkwin(&x, 1, 1, PropertyChangeMask);
     XA_REGISTRAR = XInternAtom(x.display, "TIDE_REGISTRAR", 0);
@@ -166,11 +184,18 @@ int main(int argc, char** argv) {
     x.eventfns[SelectionClear] = selclear;
     x.eventfns[ClientMessage] = clientmsg;
     x.eventfns[PropertyNotify] = propnotify;
+    puts("inited");
     if (None == XGetSelectionOwner(x.display, XA_REGISTRAR)) {
         XSetSelectionOwner(x.display, XA_REGISTRAR, x.self, CurrentTime);
+        puts("made owner");
         if (x.self == XGetSelectionOwner(x.display, XA_REGISTRAR)) {
+            puts("finding windows");
             find_windows(&x);
+            puts("event loop");
             x11_event_loop(&x, 0);
+            puts("done");
+        } else {
+            puts("fail");
         }
     }
     return 1;