What's the problem with the XGetInputFocus and XGetWindowAttributes? - Xwindows

This is a discussion on What's the problem with the XGetInputFocus and XGetWindowAttributes? - Xwindows ; I want to get the attribute of the current active window , but failed in the code below, I don't know what is the problem ,please help me ,thanks! //gcc -O2 -o test test.c -L/usr/X11R6/lib -lX11 #include #include #include int ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: What's the problem with the XGetInputFocus and XGetWindowAttributes?

  1. What's the problem with the XGetInputFocus and XGetWindowAttributes?

    I want to get the attribute of the current active window , but failed
    in the code below, I don't know what is the problem ,please help me
    ,thanks!

    //gcc -O2 -o test test.c -L/usr/X11R6/lib -lX11

    #include
    #include
    #include

    int main() {
    Display *display;
    Window focus;
    XWindowAttributes win_attr;
    int revert;

    display = XOpenDisplay(NULL);

    XGetInputFocus(display,&focus,&revert);
    XGetWindowAttributes(display, focus, &win_attr);

    printf("%x\n",focus);
    printf("width:%d,height:%d\n",win_attr.width,win_attr.height);
    }


  2. Re: What's the problem with the XGetInputFocus and XGetWindowAttributes?


    wrote in message
    news:1143021653.900866.72490@j33g2000cwa.googlegro ups.com...
    >I want to get the attribute of the current active window , but failed
    > in the code below, I don't know what is the problem ,please help me
    > ,thanks!
    >
    > //gcc -O2 -o test test.c -L/usr/X11R6/lib -lX11
    >
    > #include
    > #include
    > #include
    >
    > int main() {
    > Display *display;
    > Window focus;
    > XWindowAttributes win_attr;
    > int revert;
    >
    > display = XOpenDisplay(NULL);
    >
    > XGetInputFocus(display,&focus,&revert);
    > XGetWindowAttributes(display, focus, &win_attr);
    >
    > printf("%x\n",focus);
    > printf("width:%d,height:%d\n",win_attr.width,win_attr.height);
    > }
    >

    What do you mean when you say "it failed"?
    Did the app crash?
    If not, how are you defining "failure"?
    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Software Reuse Project



  3. Re: What's the problem with the XGetInputFocus and XGetWindowAttributes?

    no.99@263.net wrote:
    > I want to get the attribute of the current active window , but failed
    > in the code below, I don't know what is the problem ,please help me
    > ,thanks!

    ---8<---

    Except for small ANSI compliance mistakes your code is correct. This
    program fixes it:

    /* xgetattr.c */
    #include
    #include

    int main(int argc, char *argv[])
    {
    Display *display;
    Window focus;
    XWindowAttributes attr;
    int revert;

    display = XOpenDisplay(NULL);
    XGetInputFocus(display, &focus, &revert);
    XGetWindowAttributes(display, focus, &attr);
    printf("[0x%x] %d x %d\n", (unsigned)focus, attr.width,
    attr.height);

    return 0;
    }

    Observe that you will ever get the information from your terminal
    window (the one that has the focus when the program is started).
    To get information from a different window, put a sleep first in the
    command line:

    $ sleep 2; ./xgetattr

    Now way you have two seconds to change the focus.

    BTW, you may want to look at the source code of "xwininfo".

    --- Casantos


  4. Re: What's the problem with the XGetInputFocus and XGetWindowAttributes?

    Sorry that I didn't show the result after running the code , the result
    is below:

    [root@localhost test]# ./test
    300001c
    width:1,height:1

    "it failed" means it didn't give me the decent result


  5. Re: What's the problem with the XGetInputFocus and XGetWindowAttributes?

    Thank you very much for your help : )


+ Reply to Thread