-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi3wl.py
executable file
·90 lines (76 loc) · 2.78 KB
/
i3wl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python2
#-*- encoding:UTF-8 -*-
import pygtk
pygtk.require('2.0')
import gtk
import i3ipc
class Focuser(object):
def __init__(self, connection, wid):
self.id = wid
self.connection = connection
def focus(self, data):
self.connection.command('[con_id=%s] focus' % self.id)
class WorkspaceSwitcher(object):
def __init__(self, connection, workspace):
self.workspace = workspace
self.connection = connection
def switch(self, data):
self.connection.command("workspace %s" % self.workspace)
def populate(widget, connection):
tree = connection.get_tree()
workspaces = tree.workspaces()
workspaces.sort()
for workspace in workspaces:
workspace_menu = gtk.MenuItem(workspace.name, True)
submenu = gtk.Menu()
switch = gtk.ImageMenuItem(gtk.STOCK_GO_FORWARD)
switch.get_child().set_text("go to")
switch.connect('activate', WorkspaceSwitcher(connection, workspace.name).switch)
submenu.append(switch)
submenu.append(gtk.SeparatorMenuItem())
for window in workspace.leaves():
text = window.name if len(window.name) < 30 else window.name[:27] + "..."
elem = gtk.MenuItem(text)
if window.urgent:
elem.get_children()[0].set_markup("<b><i>%s</i></b>" % text)
elem.connect('activate', Focuser(connection, window.id).focus)
submenu.append(elem)
workspace_menu.set_submenu(submenu)
widget.append(workspace_menu)
class Gui:
def __init__(self):
self.i3 = i3ipc.Connection()
self.statusIcon = gtk.StatusIcon()
self.statusIcon.set_from_stock(gtk.STOCK_INDEX)
self.statusIcon.set_visible(True)
self.statusIcon.set_tooltip("Windows list")
self.statusIcon.connect('button-press-event', self.on_click)
self.statusIcon.set_visible(True)
def generate_menu(self):
menu = gtk.Menu()
quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT)
quit_item.connect('activate', gtk.main_quit, self.statusIcon)
menu.append(quit_item)
menu.append(gtk.SeparatorMenuItem())
try:
populate(menu, self.i3)
except i3ipc.socket.error as error:
print(error)
try:
self.i3 = i3ipc.Connection()
populate(menu, self.i3)
except i3ipc.socket.error as error:
item = gtk.MenuItem("")
item.get_children()[0].set_markup("<i>error connecting to i3wm: %s</i>" % error.strerror)
menu.append(item)
menu.show_all()
return menu
def on_click(self, widget, event):
menu = self.generate_menu()
menu.popup(None, None, gtk.status_icon_position_menu, 3, event.time, widget)
if __name__=='__main__':
try:
gui=Gui()
gtk.main()
except:
print('Exception thrown... bye!')