Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 277271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:03:10+00:00 2026-05-12T01:03:10+00:00

I am attempting to get the X Window at a certain location on screen.

  • 0

I am attempting to get the X Window at a certain location on screen. When I asked people for a function to do this, they said you would just call XQueryTree recursively.

This is the code snippet which I think is somehow wrong. When I debug it, it seems to work perfectly. The only problem is that the output it gives seems a little strange. When I do XQueryTree on the root window, I get hundreds of children, when I only have five or so open. Also, it seems to think that there is a top-level window somewhere where there simply isn’t one, and returns it as a result. No matter how I move my actual windows around, XQueryTree seems to indicate that there is another window on top of my windows (not covering the entire screen.) When I look at where it says the window is, it is at some arbitrary point on my desktop.

If this is of any help:
The display is from XOpenDisplay(NULL), and the root window I originally pass it is XDefaultRootWindow(display). I am running gnome under debian with metacity.

point getwindowatloc(Display * display, Window root, jint x, jint y) {
        Window returnedroot;
        Window returnedparent;
        Window * children;
        unsigned int numchildren;
        XQueryTree(display,root,&returnedroot,&returnedparent,&children, &numchildren);
        XWindowAttributes w;
        int i;
        for(i=numchildren-1; i>=0; i--) {
            XGetWindowAttributes(display,children[i],&w);   
            if(x>=w.x && x<=w.x+w.width && y>=w.y && y <= w.y+w.height) {
                point result={w.x,w.y};
                XFree(children);
                return result;
            } else {
                point result=getwindowatloc(display,children[i],x-w.x,y-w.y);
                if(result.x!=INT_MAX) {
                    result.x+=w.x;
                    result.y+=w.y;
                    XFree(children);
                    return result;
                }
            }
        }
        if(children) {
            XFree(children);
        }
        return notfound;
    }

Thanks!

EDIT: For anyone who is searching for similar information: I ended up looking into the source of xwininfo. The key function is Find_Client in dsimple.c, which somehow ignores window managers to get the window you are actually looking for. If you want to look into subwindows, this is some code I added to Select_Window in dsimple.c which will recursively look inside subwindows, using XTranslateCoordinates.

Window child;
do {
  XTranslateCoordinates(dpy,target_temp,target_win,x,y,&x,&y,&child);
  target_temp=target_win;
  target_win=child;
} while(target_win);
return target_temp;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T01:03:10+00:00Added an answer on May 12, 2026 at 1:03 am

    Your code looks right (I haven’t tested it), and the results you describe don’t seem strange at all. Metacity (and other X window managers) will create lots of windows around and near the application-owned windows to show the window title, borders and other decorations.

    Try running your test with some simpler window manager like TVM (or even none at all). TVM should create a lot less windows than current window managers. This should make things easier to understand.

    Usually, however, it’s a bad idea to fight against the window manager. Can’t you solve your problem in a higher level way withour having to use xlib directly?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 142k
  • Answers 142k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer git rm --cached file should do what you want. You… May 12, 2026 at 8:17 am
  • Editorial Team
    Editorial Team added an answer Okay, as both Andrew and Guffa have given answers which… May 12, 2026 at 8:17 am
  • Editorial Team
    Editorial Team added an answer You should precache your images and not do it lazily.… May 12, 2026 at 8:17 am

Related Questions

I've promised to take a look at an old DotNetNuke installation for a client
I have a C# (2008/.NET 3.5) class library assembly that supports WPF (based on
I have a web site that uses Microsoft Indexing Service to index and query
I am attempting to get the last modified time of a file that definately

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.