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