diff --git a/api/comms.c b/api/comms.c index 609b95a..01eab9c 100644 --- a/api/comms.c +++ b/api/comms.c @@ -12,48 +12,38 @@ static EXID my_win = 0; static EXID Atom_ENL_COMMS = 0; static EXID Atom_ENL_MSG = 0; -static void +static EXID _CommsFindCommsWindow(void) { unsigned char *s; Atom ar; unsigned long num, after; int format; - Window rt; - int dint; - unsigned int duint; + EXID cwin; + /* Get root window ENLIGHTENMENT_COMMS property */ + cwin = 0; s = NULL; XGetWindowProperty(disp, root, Atom_ENL_COMMS, 0, 14, False, AnyPropertyType, &ar, &format, &num, &after, &s); - if (s) - { - sscanf((char *)s, "%*s %x", (unsigned int *)&comms_win); - XFree(s); - } - else - comms_win = 0; + if (!s) + goto done; - if (comms_win) - { - if (!XGetGeometry(disp, comms_win, &rt, &dint, &dint, - &duint, &duint, &duint, &duint)) - comms_win = 0; - s = NULL; - if (comms_win) - { - XGetWindowProperty(disp, comms_win, Atom_ENL_COMMS, 0, 14, False, - AnyPropertyType, &ar, &format, &num, &after, &s); - if (s) - XFree(s); - else - comms_win = 0; - } - } + sscanf((char *)s, "%*s %x", &cwin); + XFree(s); - if (comms_win) - XSelectInput(disp, comms_win, - StructureNotifyMask | SubstructureNotifyMask); + /* Check that cwin exists and has ENLIGHTENMENT_COMMS */ + s = NULL; + XGetWindowProperty(disp, cwin, Atom_ENL_COMMS, 0, 14, False, + AnyPropertyType, &ar, &format, &num, &after, &s); + if (!s) + goto done; + XFree(s); + + XSelectInput(disp, cwin, StructureNotifyMask | SubstructureNotifyMask); + + done: + return cwin; } void @@ -66,7 +56,7 @@ CommsSetup(void) for (;;) { - _CommsFindCommsWindow(); + comms_win = _CommsFindCommsWindow(); if (comms_win != None) break; sleep(1);