-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow_store.py
59 lines (50 loc) · 1.66 KB
/
window_store.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
from window import Window
from xcb import xproto
class WindowStore:
def __init__(self, conn, wm, win_list):
self.windows = win_list
self.retained={}
self.different = False
self.conn = conn
self.wm = wm
def add(self, win):
if win in self.windows:
return
self.windows.append(win)
self.different = True
def remove(self, win):
if win in self.windows:
self.windows.remove(win)
self.different = True
def get_list(self):
return self.windows
def retain(self, workspace, windows):
self.retained[workspace] = windows
def get_retained(self, workspace):
try:
windows = self.retained[workspace]
del self.retained[workspace]
return windows
except KeyError:
return []
def get_window(self, win):
'''
A method to get a Window object for an X window ID
If it exists in the Manager object's list of windows, that will be returned.
otherwise a new Window object is created and returned
'''
for window in self.windows:
if window.win ==win:
return window
try:
return Window(win, self.conn, self.wm)
except xproto.BadWindow:
return None
def get_window_by_pos(self, x, y):
'''
A method to get a Window object by where it is
'''
for window in self.windows:
if (x >= window.x and x <= window.x +window.w) and (y >= window.y and y <= window.y + window.h):
return window
return None