From: Michael D. Lowis Date: Tue, 8 Jan 2019 19:59:34 +0000 (-0500) Subject: fixed bug in property scanning of registrar X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=b5ceb8af6739d7d991b054a8743c86ed85e29941;p=projs%2Ftide.git fixed bug in property scanning of registrar --- diff --git a/src/edit.c b/src/edit.c index 4c92598..c210f37 100644 --- a/src/edit.c +++ b/src/edit.c @@ -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], ':'); diff --git a/src/registrar.c b/src/registrar.c index 653f423..29d5895 100644 --- a/src/registrar.c +++ b/src/registrar.c @@ -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;