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], ':');
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) {
}
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;
void selclear(XConf* x, XEvent* e) {
(void)x, (void)e;
+ puts("quitting");
exit(0);
}
}
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) {
} 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);
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;