Getting pid and details for topmost window

前端 未结 9 1062
醉酒成梦
醉酒成梦 2020-12-04 13:08

Does anyone know how to get the PID of the top active window and then how to get the properties of the window using the PID? I mean properties like process name, program nam

9条回答
  •  攒了一身酷
    2020-12-04 13:11

    Am very very late to the party, but I had a similar problem, and I think this can help someone else who has the same problem. There is a command line trick to do this, you can try execvp'ing it, or executing it redirecting the output to your code

    xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) _NET_WM_NAME WM_CLASS
    

    gives the window name, as well as the program name. Eg, for this tab, it gives me

    _NET_WM_NAME(UTF8_STRING) = "linux - Getting pid and details for topmost window - Stack Overflow - Mozilla Firefox"
    
    WM_CLASS(STRING) = "Navigator", "Firefox"
    

提交回复
热议问题