XGetWindowAttributes: 1x1 pixel for GTK apps?


   I'm trying to get the dimensions (width and height) of current 'in focus' window using XGetWindowAttributes.

   It works fine with KDE or Xlib based applications, but fails with
all GTK based applications (window_attr.width and window_attr.height
reports just '1'). The same behavior happens in Ubuntu 6.06, 6.10, 7.04
when running Metacity as window manager (but not with Compiz or Beryl).

   Following bellow a test app that demonstrates what I'm saying:

#include <X11/Xlib.h>
#include <stdio.h>

int main(void)
    Display *display;
    int res = -1, tmp, revert_to;
    Window window;
    XWindowAttributes window_attr;

    display = XOpenDisplay(NULL);
    if (!res)
        return -1;

    while (1) {
        printf("will grab a window in 3s...\n");

        tmp = XGetInputFocus(display, &window, &revert_to);
        if ((tmp == BadValue) || (tmp == BadWindow))
            return -1;

        tmp = XGetWindowAttributes(display, window, &window_attr);
        if ((tmp == BadDrawable) || (tmp == BadWindow))
            return -1 ;

        printf("width = %d\theigth = %d\n", window_attr.width,


    return 0;


   I already searched the internet for any information concerning
this, with no success. The gtk-app-devel-list doesn't return anything
(as also gtk-devel-list).

   The only reference in bugzilla to XGetWindowAttributes is:
"GDK cannot give input focus to an override_redirect window"

   Maybe I'm forgetting something related to Xlib, do you guys have
any idea of what is wrong here? Any of you know a way to known the
window dimensions of GTK apps *using xlib*?

Best regards


Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's on, when.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]