public
Description: A dynamic, hackable window manager written in Python
Homepage: http://incise.org/whimsy.html
Clone URL: git://github.com/mackstann/whimsy.git
whimsy / whimsy / actions / ewmh.py
100644 209 lines (178 sloc) 7.08 kb
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Written by Nick Welch in the years 2005-2008. Author disclaims copyright.
 
from Xlib import X
 
from whimsy import util
from whimsy.x11 import props
 
class startup_and_shutdown_with_wm(object):
    def __init__(self, hub):
        hub.attach('wm_manage_after', self.startup)
        hub.attach('wm_shutdown_before', self.shutdown)
 
class net_supported(startup_and_shutdown_with_wm):
    def startup(self, wm, **kw):
        supported = []
        for attr in globals().keys():
            if attr.startswith('net_'):
                supported.append(wm.dpy.get_atom('_' + attr.upper()))
                if hasattr(attr, 'also_implements'):
                    supported += [
                        wm.dpy.get_atom(a) for a in attr.also_implements
                    ]
 
        props.change_prop(wm.dpy, wm.root, '_NET_SUPPORTED', supported)
 
    def shutdown(self, wm, **kw):
        props.delete_prop(wm.dpy, wm.root, '_NET_SUPPORTED')
 
class net_number_of_desktops(startup_and_shutdown_with_wm):
    def startup(self, wm, **kw):
        props.change_prop(wm.dpy, wm.root, '_NET_NUMBER_OF_DESKTOPS', 1)
    def shutdown(self, wm, **kw):
        props.delete_prop(wm.dpy, wm.root, '_NET_NUMBER_OF_DESKTOPS')
 
class net_current_desktop(startup_and_shutdown_with_wm):
    def startup(self, wm, **kw):
        props.change_prop(wm.dpy, wm.root, '_NET_CURRENT_DESKTOP', 0)
    def shutdown(self, wm, **kw):
        props.delete_prop(wm.dpy, wm.root, '_NET_CURRENT_DESKTOP')
 
class net_supporting_wm_check(startup_and_shutdown_with_wm):
    def startup(self, wm, **kw):
        self.win = wm.root.create_window(-5000, -5000, 1, 1, 0, X.CopyFromParent)
        props.change_prop(wm.dpy, self.win, '_NET_WM_NAME', 'Whimsy')
        props.change_prop(wm.dpy, self.win, '_NET_SUPPORTING_WM_CHECK', self.win.id)
        props.change_prop(wm.dpy, wm.root, '_NET_SUPPORTING_WM_CHECK', self.win.id)
 
    def shutdown(self, wm, **kw):
        props.delete_prop(wm.dpy, wm.root, '_NET_SUPPORTING_WM_CHECK')
        props.delete_prop(wm.dpy, self.win, '_NET_SUPPORTING_WM_CHECK')
        props.delete_prop(wm.dpy, self.win, '_NET_WM_NAME')
        self.win.destroy()
 
 
class net_desktop_geometry(startup_and_shutdown_with_wm):
    def startup(self, wm, **kw):
        props.change_prop(
            wm.dpy, wm.root, '_NET_DESKTOP_GEOMETRY',
            [wm.vwidth, wm.vheight])
 
    def shutdown(self, wm, **kw):
        props.delete_prop(wm.dpy, wm.root, '_NET_DESKTOP_GEOMETRY')
 
class net_client_list(object):
    def __init__(self, hub):
        hub.attach('after_manage_window', self.refresh)
        hub.attach('after_unmanage_window', self.refresh)
        hub.attach('wm_shutdown_before', self.shutdown)
 
    def refresh(self, wm, **kw):
        props.change_prop(
            wm.dpy, wm.root, '_NET_CLIENT_LIST',
            [ c.win.id for c in wm.clients ]
        )
 
    def shutdown(self, wm, **kw):
        props.delete_prop(wm.dpy, wm.root, '_NET_CLIENT_LIST')
 
# what happened to net_client_list_stacking and the focus order one?
 
class net_desktop_viewport(object):
    def __init__(self, hub):
        hub.attach('wm_manage_after', self.startup)
        hub.attach('after_viewport_move', self.refresh)
 
    def startup(self, hub, wm, **kw):
        viewport = props.get_prop(wm.dpy, wm.root,
            '_NET_DESKTOP_VIEWPORT')
 
        if not viewport:
            viewport = [0, 0]
            props.change_prop(wm.dpy, wm.root,
                '_NET_DESKTOP_VIEWPORT', viewport)
 
        hub.emit('viewport_discovered', x=viewport[0], y=viewport[1])
 
    def refresh(self, wm, x, y, **kw):
        props.change_prop(
            wm.dpy, wm.root, '_NET_DESKTOP_VIEWPORT',
            [x, y]
        )
 
#class net_desktop_names(object):
# def startup(self, wm, **kw):
# props.change_prop(wm.dpy, wm.root, '_NET_DESKTOP_NAMES', [])
# def shutdown(self, wm, **kw):
# props.delete_prop(wm.dpy, wm.root, '_NET_DESKTOP_NAMES')
#
#class net_active_window(object):
# def refresh(self, wm, win, **kw):
# props.change_prop(wm.dpy, wm.root, '_NET_ACTIVE_WINDOW', win.id)
# def shutdown(self, wm, **kw):
# props.delete_prop(wm.dpy, wm.root, '_NET_ACTIVE_WINDOW')
 
 
# _NET_VIRTUAL_ROOTS
# _NET_DESKTOP_LAYOUT
# _NET_SHOWING_DESKTOP
# _NET_CLOSE_WINDOW
# _NET_MOVERESIZE_WINDOW
# _NET_WM_MOVERESIZE
# _NET_RESTACK_WINDOW
# _NET_REQUEST_FRAME_EXTENTS
# _NET_WM_NAME
# _NET_WM_VISIBLE_NAME
# _NET_WM_ICON_NAME
# _NET_WM_VISIBLE_ICON_NAME
# _NET_WM_DESKTOP
# _NET_WM_WINDOW_TYPE
# _NET_WM_STATE
# _NET_WM_ALLOWED_ACTIONS
 
# strut example:
#
# for a 50px tall, 400px wide panel that starts at x=200 and runs along the
# bottom of the screen:
#
# bottom = 50
# bottom_start_x = 200
# bottom_end_x = 599
 
#def make_strut(wm, prop_data):
# keys = '''left right top bottom left_start_y left_end_y right_start_y
# right_end_y top_start_x top_end_x bottom_start_x bottom_end_x'''.split()
#
# defaults_for_non_partial_struts = [
# 0, wm.root_geometry.height - 1, 0, wm.root_geometry.height - 1,
# 0, wm.root_geometry.width - 1, 0, wm.root_geometry.width - 1,
# ]
#
# return dict(zip(
# keys,
# prop_data + (
# defaults_for_non_partial_struts if len(prop_data) == 4 else []
# )
# ))
#
#class net_wm_strut_partial(object):
# also_implements = '_NET_WM_STRUT', '_NET_WORKAREA'
# def __init__(self):
# self.struts = {}
#
# def check(self, wm, client, win, **kw):
# # these will trigger our update()
# client.update_prop('_NET_WM_STRUT_PARTIAL')
# client.update_prop('_NET_WM_STRUT')
#
# def property_updated(self, wm, client, win, **kw):
# prop_data = []
# if '_NET_WM_STRUT_PARTIAL' in client.props:
# prop_data = client.props['_NET_WM_STRUT_PARTIAL']
# elif '_NET_WM_STRUT' in client.props:
# prop_data = client.props['_NET_WM_STRUT']
# if not prop_data:
# return
# self.struts[win.id] = make_strut(wm, prop_data)
# self.update_workarea(wm)
#
# def remove_client(self, wm, win, **kw):
# if win.id in self.struts:
# del self.struts[win.id]
# self.update_workarea(wm)
#
# def update_workarea(self, wm):
# if self.struts:
# margin_left = max(map(lambda s: s['left'], self.struts.values()))
# margin_right = min(map(lambda s: s['right'], self.struts.values()))
# margin_top = max(map(lambda s: s['top'], self.struts.values()))
# margin_bottom = min(map(lambda s: s['bottom'], self.struts.values()))
# else:
# margin_left = margin_right = margin_top = margin_bottom = 0
#
# props.change_prop(wm.dpy, wm.root, '_NET_WORKAREA', [
# margin_left, margin_top,
# wm.root_geometry.width - (margin_left + margin_right),
# wm.root_geometry.height - (margin_top + margin_bottom),
# ])
 
# _NET_WM_ICON_GEOMETRY
# _NET_WM_ICON
# _NET_WM_PID
# _NET_WM_HANDLED_ICONS
# _NET_WM_USER_TIME
# _NET_FRAME_EXTENTS
# _NET_WM_PING
# _NET_WM_SYNC_REQUEST