Skip to content

Instantly share code, notes, and snippets.

@arifnd
Created July 3, 2014 11:47
Show Gist options
  • Select an option

  • Save arifnd/1caea0697bef46706b5e to your computer and use it in GitHub Desktop.

Select an option

Save arifnd/1caea0697bef46706b5e to your computer and use it in GitHub Desktop.
show gtk windows list
#!/usr/bin/python
import gtk
import wnck
from time import time
class NayaTask:
def __init__(self):
self.screen = wnck.screen_get_default()
def get_windows(self, mode = 'list', xid = 0):
while gtk.events_pending(): gtk.main_iteration()
windows = self.screen.get_windows()
result = ""
for win in windows:
if win.get_window_type() == wnck.WindowType.__enum_values__[0]:
data = '{"xid":%s,"app_name":"%s","win_name":"%s"' % (win.get_xid(), win.get_application().get_name(), win.get_name())
if mode is 'list':
if win.is_active():
result = data + ',"active":1},' + result
else:
result = data + ',"active":0},' + result
else:
if win.get_xid() == xid:
if mode is 'active':
win.activate(int(time()))
result = data + ',"active":1},' + result
elif mode is 'close':
win.close(int(time()))
elif mode is 'maximize':
win.maximize()
result = data + ',"active":1},' + result
elif mode is 'minimize':
win.minimize()
result = data + ',"active":0},' + result
else:
result = data + ',"active":0},' + result
count = len(result)-1
return '{"success":true,"program":[' + result[:count] + ']}'
def show_desktop(self):
self.screen.toggle_showing_desktop(True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment