fetching a window ID in Linux - X

This is a discussion on fetching a window ID in Linux - X ; Hi, I'm programming under GNOME. Is there any way to fetch the window ID of a GUI app given it's PID? For example, in KDE, window ID can be obtained from DCOP. Any such facility in GNOME. Regards, GVK ps:- ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: fetching a window ID in Linux

  1. fetching a window ID in Linux

    Hi,
    I'm programming under GNOME. Is there any way to fetch the window ID of
    a GUI app given it's PID? For example, in KDE, window ID can be obtained
    from DCOP. Any such facility in GNOME.

    Regards,
    GVK

    ps:- I couldn't find a more appropriate group to post this. Please excuse.

  2. Re: fetching a window ID in Linux

    GVK writes:

    > Hi,
    > I'm programming under GNOME. Is there any way to fetch the
    > window ID of a GUI app given it's PID?


    Any process can create any number of windows, and most GUI create lots
    of them, even if they look like a single window to the user. For
    instance, it is common to create a subwindow for every widget.
    Multiple top-level windows are also commonplace. Which of these
    windows do you want the ID of?

    Also consider that processes can create windows on other machines.

    > For example, in KDE, window ID can be obtained from DCOP.


    That must mean they are imposing artificial restrictions on what a
    program can do.

    --
    Måns Rullgård
    mru@inprovide.com

  3. Re: fetching a window ID in Linux

    In article , Måns Rullgård wrote:
    > GVK writes:
    >
    >> Hi,
    >> I'm programming under GNOME. Is there any way to fetch the
    >> window ID of a GUI app given it's PID?

    >
    > Any process can create any number of windows, and most GUI create lots
    > of them, even if they look like a single window to the user. For
    > instance, it is common to create a subwindow for every widget.
    > Multiple top-level windows are also commonplace. Which of these
    > windows do you want the ID of?
    >
    > Also consider that processes can create windows on other machines.


    Of course, if the OP has access to the GUI source code, this is easily
    doable - just invent a protocol for a client process to obtain the
    ID of a particular window, via IPC (sockets, shared memory, or etc.),
    and implement the GUI and the client process to use this protocol.

    >> For example, in KDE, window ID can be obtained from DCOP.

    >
    > That must mean they are imposing artificial restrictions on what a
    > program can do.
    >



    --
    Jim Cochrane; jtc@dimensional.com
    [When responding by email, include the term non-spam in the subject line to
    get through my spam filter.]

  4. Re: fetching a window ID in Linux

    Måns Rullgård wrote:
    >
    > Any process can create any number of windows, and most GUI create lots
    > of them, even if they look like a single window to the user. For
    > instance, it is common to create a subwindow for every widget.
    > Multiple top-level windows are also commonplace. Which of these
    > windows do you want the ID of?
    >


    The ID of the top-most window(I guess it's called the main widget in
    Qt). And for the sake of simplicity, I'm assuming that a program will
    create just one of these top-level windows and the rest of the windows
    are it's children.

    GVK


  5. Re: fetching a window ID in Linux

    GVK writes:

    > Måns Rullgård wrote:
    >> Any process can create any number of windows, and most GUI create
    >> lots of them, even if they look like a single window to the user.
    >> For instance, it is common to create a subwindow for every widget.
    >> Multiple top-level windows are also commonplace. Which of these
    >> windows do you want the ID of?
    >>

    >
    > The ID of the top-most window(I guess it's called the main widget in
    > Qt). And for the sake of simplicity, I'm assuming that a program will
    > create just one of these top-level windows and the rest of the windows
    > are it's children.


    That excludes a vast range of programs. Supposing dialogs, menus and
    other popups can filtered based on various attributes usually set on
    those windows, very many, if not most, programs can open more than one
    top-level window.

    What are you trying to do anyway? Maybe there is a better way of
    doing it.

    --
    Måns Rullgård
    mru@inprovide.com

  6. Re: fetching a window ID in Linux

    Måns Rullgård wrote:
    >
    > That excludes a vast range of programs. Supposing dialogs, menus and
    > other popups can filtered based on various attributes usually set on
    > those windows, very many, if not most, programs can open more than one
    > top-level window.
    >

    No harm done. Just the top-level ID would do.

    > What are you trying to do anyway? Maybe there is a better way of
    > doing it.
    >

    Given a PID, I want to a list of IDs of it's children and atleast the ID
    of the top widget (if any).

    GVK

  7. Re: fetching a window ID in Linux

    GVK writes:

    > Måns Rullgård wrote:
    >>
    >> That excludes a vast range of programs. Supposing dialogs, menus and
    >> other popups can filtered based on various attributes usually set on
    >> those windows, very many, if not most, programs can open more than one
    >> top-level window.
    >>

    > No harm done. Just the top-level ID would do.


    I was trying to say that there is no THE top-level ID. There can be
    arbitrarily many. You should at least design your program to work
    with a list of windows, instead of a single window.

    >> What are you trying to do anyway? Maybe there is a better way of
    >> doing it.
    >>

    > Given a PID, I want to a list of IDs of it's children and atleast the
    > ID of the top widget (if any).


    And then what? What are you planning on doing with these window IDs?

    --
    Måns Rullgård
    mru@inprovide.com

  8. Re: fetching a window ID in Linux

    Okay, I joined Fix Linux simply to reply to this thread:

    Måns, there are usually very valid reasons for wanting something. Going around in circles as to "oh, you shouldn't do this or that" really doesn't help anyone.

    Here's a real-world example: my boss wanted me to make a script where you pass it a URL, and the script goes and creates a "preview" (if you will) of that page. He was very specific as to the applications I had to use in order to achieve this task.

    The project went thus: we use vncserver to create a "virtual display". We then launch opera on that display (using "-fullscreen") and then pass it the URL to open. We then use "import" to grab the desktop. The problem is that *sometimes* the GNOME bars (menu/task) are visible (inconsistent, can't effectively duplicate it). "import" offers the ability to pass a "window" argument, but for this I need the window ID.

    And presto - here we sit arguing over whether getting the list of windows of a PID is valid or not, and in the end exactly nothing is achieved, and the requirement remains.

    A solution I did fall back on was:
    xwininfo -display :4 -root -children | grep "Speed Dial - Opera" | awk '{print $1}'

    But it's ugly as heck. With more than one Opera open, this would immediately fail. Alternately, I can have another application open with the title "Speed Dial - Opera", and again we're screwed. Being able to isolate the results by PID would be HUGELY helpful, but alas, those who probably know would rather argue the point.

+ Reply to Thread