1 #!/usr/bin/env python 2 3 """ 4 Simple desktop window enumeration for Python. 5 6 Copyright (C) 2005, 2006, 2007 Paul Boddie <paul@boddie.org.uk> 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 21 22 -------- 23 24 Finding Open Windows on the Desktop 25 ----------------------------------- 26 27 To obtain a list of windows, use the desktop.windows.list function as follows: 28 29 desktop.windows.list() 30 """ 31 32 from desktop import _is_x11, _get_x11_vars, _readfrom, use_desktop 33 34 def list(desktop=None): 35 36 """ 37 Return a list of window handles for the current desktop. If the optional 38 'desktop' parameter is specified then attempt to use that particular desktop 39 environment's mechanisms to look for windows. 40 """ 41 42 # NOTE: The desktop parameter is currently ignored and X11 is tested for 43 # NOTE: directly. 44 45 if _is_x11(): 46 s = _readfrom(_get_x11_vars() + "xlsclients -a -l", shell=1) 47 prefix = "Window " 48 prefix_end = len(prefix) 49 handles = [] 50 51 for line in s.split("\n"): 52 if line.startswith(prefix): 53 handles.append(line[prefix_end:-1]) # NOTE: Assume ":" at end. 54 else: 55 raise OSError, "Desktop '%s' not supported" % use_desktop(desktop) 56 57 return handles 58 59 # vim: tabstop=4 expandtab shiftwidth=4