Results 1 to 3 of 3

Thread: kde pid from window id and vice versa

  1. #1
    Join Date
    Dec 2010
    Posts
    44
    Thanks
    9
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default kde pid from window id and vice versa

    Hi,

    I need a way to get the window id from pid of a process. And the reverse too, ie from the window id I need to get the pid of the process. I have the exepath and from the /proc i get the pid and from the pid I need to get the window Id( or a list of window ids).

    I am trying to write an app which will check if a particular process is currently running or not. If it is running then get its main window and make it active and set focus to it. If it is not running then start it and make it the active window.

    I can go platform specific on this. It need not be cross platform or qt. I am looking for code on KDE, X and gnome.

    Thank you.

  2. The following 2 users say thank you to sky for this useful post:


  3. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: kde pid from window id and vice versa

    If the you are doing this because you want a Qt application to prohibit multiple copies of itself then QtSingleApplication can do that for Qt applications.

    If you want a general, nothing-to-do-with-Qt, approach for X11 systems then I suggest you look at the source of xwininfo to get an idea how to traverse the window information. The "-all" option shows the PID probably using the approach here: http://unix.stackexchange.com/questi...his-x11-window
    The same information is visible using xprop.

  4. The following 3 users say thank you to ChrisW67 for this useful post:

    sky (26th October 2012)

  5. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: kde pid from window id and vice versa

    The other way is to implement what you said manually. That is, to check the state of a process you need to execute a short kernel code to search through kernel process table and extract the process you are looking for. For the other purpose, that is to get the pid, read about fork() wait_pid().

  6. The following user says thank you to saman_artorious for this useful post:


Similar Threads

  1. reinterpretcast help . from struct to stream and vice-versa
    By tonnot in forum General Programming
    Replies: 4
    Last Post: 27th June 2011, 14:21
  2. Replies: 3
    Last Post: 13th May 2011, 14:46
  3. Replies: 0
    Last Post: 25th March 2010, 13:10
  4. conversion between string to hex and vice versa
    By mohanakrishnan in forum Newbie
    Replies: 2
    Last Post: 5th December 2009, 12:25
  5. Convert QByteArray to object and vice versa
    By DiamonDogX in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2009, 21:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.