-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pager.py
94 lines (72 loc) · 3.14 KB
/
Pager.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
91
92
93
94
from gi.repository import Wnck, Clutter, Gdk
import arrow
from PagerModel import PagerModel, switch_workspace
class PagerDot(Clutter.Box):
def __init__(self, conf, workspace):
Clutter.Box.__init__(self)
self.conf = conf
self.pager_model = conf.getpagermodel()
# The workspace name.
self.set_name(workspace.get_name())
self.workspace = workspace
self.lm = Clutter.BinLayout.new(Clutter.BinAlignment.CENTER,
Clutter.BinAlignment.CENTER)
self.set_layout_manager(self.lm)
# Stylin'
size = conf.getint("Pager", "size")
self.main_dot = Clutter.Rectangle.new()
self.main_dot.set_size(size, size)
self.active_dot = Clutter.Rectangle.new()
self.active_dot.set_size(size, size / 4)
self.update()
# Add the components.
self.lm.add(self.main_dot,
Clutter.BinAlignment.CENTER, Clutter.BinAlignment.CENTER)
self.lm.add(self.active_dot,
Clutter.BinAlignment.CENTER, Clutter.BinAlignment.END)
# Connect input & signals.
self.set_reactive(True)
self.connect("button-press-event", self.click)
def update(self, *ignored):
self.set_name(self.workspace.get_name())
state = self.pager_model.get_state(self.workspace)
# Set the colours.
col = None
if state & PagerModel.URGENT:
col = self.conf.getcolour("Pager", "urgent")
elif state & PagerModel.OCCUPIED:
col = self.conf.getcolour("Pager", "occupied")
elif state & PagerModel.MINIMISED:
col = self.conf.getcolour("Pager", "minimised")
elif (state & ~PagerModel.ACTIVE) == PagerModel.NO_WINDOWS:
col = self.conf.getcolour("Pager", "none")
self.main_dot.set_color(col)
if state & PagerModel.ACTIVE:
self.active_dot.set_color(self.conf.getcolour("Pager", "active"))
else:
self.active_dot.set_color(Clutter.Color.from_string("#0000")[1])
def click(self, actor, event):
if event.button == 1:
self.workspace.activate(arrow.now().timestamp)
class Pager(Clutter.Box):
""" A pager widget to show the workspace view. """
def __init__(self, conf):
Clutter.Box.__init__(self)
self.conf = conf
self.dot_spacing = conf.getint("Pager", "size") / 2
self.lm = Clutter.BoxLayout.new()
self.lm.set_spacing(self.dot_spacing)
self.set_layout_manager(self.lm)
for i in conf.getpagermodel().workspaces:
indic = PagerDot(conf, i)
self.add_actor(indic)
# Connect signals.
screen = conf.getscreen()
screen.connect("active-workspace-changed", self.update)
screen.connect("window-opened", self.update)
screen.connect("window-closed", self.update)
conf.getpagermodel().connect("update-pager", self.update)
def update(self, *ignored):
""" Update the display of all the workspaces. """
# Call update on each child with the appropriate workspace state.
self.foreach(PagerDot.update, None)