forked from BurntSushi/pyndow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.py
116 lines (85 loc) · 2.87 KB
/
state.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from collections import OrderedDict
import sys
import xcb
import xcb.xproto as xproto
import xpybutil.cursor as cursor
import xpybutil.keysym as keysym
d = open('/home/andrew/pyndow.txt', 'w+')
die = False
conn = xcb.connect()
core = conn.core
setup = conn.get_setup()
rsetup = setup.roots[0]
root = rsetup.root
# Temporary hack
rsetup.width_in_pixels = 1920
rsetup.height_in_pixels = 1080
pyndow = conn.generate_id()
core.CreateWindow(rsetup.root_depth, pyndow, root, -1000, -1000, 1,
1, 0, xproto.WindowClass.InputOutput, rsetup.root_visual,
xproto.CW.EventMask | xproto.CW.OverrideRedirect,
[xproto.EventMask.PropertyChange, 1])
core.MapWindow(pyndow)
grab_pointer = False
grab_keyboard = False
__kbmap = keysym.get_keyboard_mapping(conn)
__keystomods = keysym.get_keys_to_mods(conn)
FC = cursor.FontCursor
cursors = {
'LeftPtr': cursor.create_font_cursor(conn, FC.LeftPtr),
'Fleur': cursor.create_font_cursor(conn, FC.Fleur),
'Watch': cursor.create_font_cursor(conn, FC.Watch),
'TopSide': cursor.create_font_cursor(conn, FC.TopSide),
'TopRightCorner': cursor.create_font_cursor(conn, FC.TopRightCorner),
'RightSide': cursor.create_font_cursor(conn, FC.RightSide),
'BottomRightCorner': cursor.create_font_cursor(conn, FC.BottomRightCorner),
'BottomSide': cursor.create_font_cursor(conn, FC.BottomSide),
'BottomLeftCorner': cursor.create_font_cursor(conn, FC.BottomLeftCorner),
'LeftSide': cursor.create_font_cursor(conn, FC.LeftSide),
'TopLeftCorner': cursor.create_font_cursor(conn, FC.TopLeftCorner)
}
# The set of all windows being managed.
windows = OrderedDict()
# The set of all existing workspaces.
workspaces = None
def reconnect():
global conn
conn = xcb.connect()
def get_kbmap():
global __kbmap
if isinstance(__kbmap, xproto.GetKeyboardMappingCookie):
__kbmap = __kbmap.reply()
return __kbmap
def set_kbmap(kbmap):
global __kbmap
__kbmap = kbmap
def get_mod_for_key(keycode):
return keycode in __keystomods and __keystomods[keycode] or 0
def set_keys_to_mods(ktom):
global __keystomods
__keystomods = ktom
def replay_pointer():
core.AllowEventsChecked(xproto.Allow.ReplayPointer,
xproto.Time.CurrentTime).check()
def root_focus():
core.SetInputFocusChecked(xproto.InputFocus.PointerRoot, root,
xproto.Time.CurrentTime).check()
def grab():
core.GrabServerChecked().check()
def ungrab():
core.UngrabServerChecked().check()
def sync():
core.GetInputFocus().reply()
def debug(s):
print >> d, s
d.flush()
def debug_obj(o, f=False):
out = sys.stdout
if f:
out = d
print >> out, o
for i in dir(o):
if i.startswith('__'): continue
print >> out, i, getattr(o, i)
print >> out, '-' * 45
out.flush()