--- root-tail.c.old 2004-07-30 21:33:20.000000000 +0200 +++ root-tail.c 2006-12-03 14:24:46.000000000 +0100 @@ -52,6 +52,8 @@ /* some italic fonts still go over the margin - this margin of error cleans up the mess */ #define MARGIN_OF_ERROR 2 +#define ATOM(a) XInternAtom(disp, #a, False) + /* data structures */ struct logfile_entry { @@ -136,6 +138,8 @@ Display *disp; Window root; GC WinGC; +int workarea[4]; + #if HAS_REGEX struct re_list { @@ -282,12 +286,85 @@ find_root_window (Display *display, int } #endif /* USE_TOON_GET_ROOT_WINDOW */ + +static void update_workarea() +{ + int screen = DefaultScreen(disp); + Window root = RootWindow(disp, screen); + unsigned long nitems, bytes; + unsigned char *buf = NULL; + Atom type; + int format; + /* default work area is display */ + + workarea[0] = 0; + workarea[1] = 0; + workarea[2] = DisplayWidth(disp, screen); + workarea[3] = DisplayHeight(disp, screen); + + /* get current desktop */ + if (XGetWindowProperty(disp, root, ATOM(_NET_CURRENT_DESKTOP), + 0, 1, False, XA_CARDINAL, &type, &format, + &nitems, &bytes, &buf) == Success + && type == XA_CARDINAL && nitems > 0) { + + //Currently unused + /* long desktop = * (long *) buf; */ + + XFree(buf); + buf = 0; + + } + + if (buf) { + XFree(buf); + buf = 0; + } +} + +static Window find_subwindow(Window win, int w, int h) +{ + unsigned int i, j; + Window troot, parent, *children; + unsigned int n; + + /* search subwindows with same size as display or work area */ + + for (i = 0; i < 10; i++) { + XQueryTree(disp, win, &troot, &parent, &children, &n); + + for (j = 0; j < n; j++) { + XWindowAttributes attrs; + + if (XGetWindowAttributes + (disp, children[j], &attrs)) { + /* Window must be mapped and same size as display or work space */ + if (attrs.map_state != 0 && + ((attrs.width == DisplayWidth(disp, DefaultScreen(disp)) + && attrs.height == DisplayHeight(disp, DefaultScreen(disp))) + || (attrs.width == w + && attrs.height == h))) { + win = children[j]; + break; + } + } + } + + XFree(children); + if (j == n) + break; + } + + return win; +} + void InitWindow (void) { XGCValues gcv; unsigned long gcm; int screen, ScreenWidth, ScreenHeight; + Window win; struct logfile_entry *e; if (!(disp = XOpenDisplay (dispname))) @@ -302,6 +379,14 @@ InitWindow (void) find_root_window (disp, screen); + /* get subwindows from root */ + win = find_subwindow(root, -1, -1); + + update_workarea(); + + win = find_subwindow(win, workarea[2], workarea[3]); + + root=win; gcm = GCBackground; gcv.graphics_exposures = True; WinGC = XCreateGC (disp, root, gcm, &gcv);