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;
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 */
return 0;
}
-char* ARGV0;
-int Foreground = 0;
-
int main(int argc, char** argv) {
OPTBEGIN {
case 'F': Foreground = 1; break;
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);
}
}