altdesktop / i3ipc-python

🐍 An improved Python library to control i3wm and sway.
http://i3ipc-python.readthedocs.io
BSD 3-Clause "New" or "Revised" License
851 stars 109 forks source link

add find_by_pid #142

Closed geeseven closed 4 years ago

geeseven commented 4 years ago

Add a way to find a container based on pid.

In [1]: import i3ipc                                               

In [2]: i3 = i3ipc.Connection()                                    

In [3]: x = i3.get_tree().find_by_pid(1337)                        

In [4]: x.pid                                                      
Out[4]: 1337
acrisci commented 4 years ago

I think this is a case where you could expect multiple windows for one pid.

geeseven commented 4 years ago

@acrisci, thanks for the timely reply. That is a good point. I have made the requested change.

In [1]: import i3ipc                                                                                                                    

In [2]: i3 = i3ipc.Connection()                                                                                                         

In [3]: y = i3.get_tree().find_by_pid(1384)                                                                                             

In [4]: y[0].id                                                                                                                         
Out[4]: 11

In [5]: y[0].workspace().name                                                                                                           
Out[5]: '1'

In [6]: y[1].id                                                                                                                         
Out[6]: 344

In [7]: y[1].workspace().name                                                                                                           
Out[7]: '10'
acrisci commented 4 years ago

:+1: