Guest User

example python-xlib script to get a window by its id

a guest
Nov 18th, 2011
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import Xlib
  2. import Xlib.display
  3.  
  4. def get_window_by_id(winid):
  5.     mydisplay = Xlib.display.Display()
  6.     root = mydisplay.screen().root # should loop over all screens
  7.     inspection_list = [root]
  8.  
  9.     while len(inspection_list) != 0:
  10.         awin = inspection_list.pop(0)
  11.         if awin.id == winid:
  12.             return awin
  13.         children = awin.query_tree().children
  14.         if children != None:
  15.             inspection_list += children
  16.  
  17.     return None
  18.  
  19. # use xwininfo -tree to click on something (panel was good for me)
  20. # until you find a window with a name, then put that id in here
  21. print get_window_by_id(0x1400003)
  22. print get_window_by_id(0x1400003).get_wm_name()
  23.  
  24.  
Advertisement
Add Comment
Please, Sign In to add comment