]> Dogcows Code - chaz/openbox/blob - scripts/callbacks.py
new merry theme updates
[chaz/openbox] / scripts / callbacks.py
1 ############################################################################
2 ### Functions that can be used as callbacks for mouse/keyboard bindings ###
3 ############################################################################
4
5 import ob
6 import otk
7
8 StateRemove = 0
9 StateAdd = 1
10 StateToggle = 2
11
12 def state_above(data, add=StateAdd):
13 """Toggles, adds or removes the 'above' state on a window.
14 The second paramater should one of: StateRemove, StateAdd, or
15 StateToggle."""
16 if not data.client: return
17 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
18 otk.Property_atoms().net_wm_state, data.client.window(),
19 add, otk.Property_atoms().net_wm_state_above)
20
21 def state_below(data, add=StateAdd):
22 """Toggles, adds or removes the 'below' state on a window.
23 The second paramater should one of: StateRemove, StateAdd, or
24 StateToggle."""
25 if not data.client: return
26 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
27 otk.Property_atoms().net_wm_state, data.client.window(),
28 add, otk.Property_atoms().net_wm_state_below)
29
30 def state_shaded(data, add=StateAdd):
31 """Toggles, adds or removes the 'shaded' state on a window.
32 The second paramater should one of: StateRemove, StateAdd, or
33 StateToggle."""
34 if not data.client: return
35 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
36 otk.Property_atoms().net_wm_state, data.client.window(),
37 add, otk.Property_atoms().net_wm_state_shaded)
38
39 def state_maximize(data, add=StateAdd):
40 """Toggles, adds or removes the horizontal and vertical 'maximized' state
41 on a window. The second paramater should one of: StateRemove, StateAdd,
42 or StateToggle."""
43 if not data.client: return
44 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
45 otk.Property_atoms().net_wm_state, data.client.window(),
46 add, otk.Property_atoms().net_wm_state_maximized_horz,
47 otk.Property_atoms().net_wm_state_maximized_vert)
48
49 def state_maximize_horz(data, add=StateAdd):
50 """Toggles, adds or removes the horizontal 'maximized' state on a window.
51 The second paramater should one of: StateRemove, StateAdd, or
52 StateToggle."""
53 if not data.client: return
54 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
55 otk.Property_atoms().net_wm_state, data.client.window(),
56 add, otk.Property_atoms().net_wm_state_maximized_horz)
57
58 def state_maximize_vert(data, add=StateAdd):
59 """Toggles, adds or removes the vertical 'maximized' state on a window.
60 The second paramater should one of: StateRemove, StateAdd, or
61 StateToggle."""
62 if not data.client: return
63 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
64 otk.Property_atoms().net_wm_state, data.client.window(),
65 add, otk.Property_atoms().net_wm_state_maximized_vert)
66
67 def state_skip_taskbar(data, add=StateAdd):
68 """Toggles, adds or removes the 'skip_taskbar' state on a window.
69 The second paramater should one of: StateRemove, StateAdd, or
70 StateToggle."""
71 if not data.client: return
72 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
73 otk.Property_atoms().net_wm_state, data.client.window(),
74 add, otk.Property_atoms().net_wm_state_skip_taskbar)
75
76 def state_skip_pager(data, add=StateAdd):
77 """Toggles, adds or removes the 'skip_pager' state on a window.
78 The second paramater should one of: StateRemove, StateAdd, or
79 StateToggle."""
80 if not data.client: return
81 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
82 otk.Property_atoms().net_wm_state, data.client.window(),
83 add, otk.Property_atoms().net_wm_state_skip_pager)
84
85 def iconify(data):
86 """Iconifies the window on which the event occured"""
87 if not data.client: return
88 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
89 otk.Property_atoms().wm_change_state,
90 data.client.window(), 3) # IconicState
91
92 def restore(data):
93 """Un-iconifies the window on which the event occured, but does not focus
94 if. If you want to focus the window too, it is recommended that you
95 use the activate() function."""
96 if not data.client: return
97 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
98 otk.Property_atoms().wm_change_state,
99 data.client.window(), 1) # NormalState
100
101 def close(data):
102 """Closes the window on which the event occured"""
103 if not data.client: return
104 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
105 otk.Property_atoms().net_close_window,
106 data.client.window(), 0)
107
108 def focus(data):
109 """Focuses the window on which the event occured"""
110 if not data.client: return
111 # !normal windows dont get focus from window enter events
112 if data.action == ob.EventAction.EnterWindow and not data.client.normal():
113 return
114 data.client.focus()
115
116 def restart(data, other = ""):
117 """Restarts openbox, optionally starting another window manager."""
118 ob.openbox.restart(other)
119
120 def raise_win(data):
121 """Raises the window on which the event occured"""
122 if not data.client: return
123 ob.openbox.screen(data.screen).raiseWindow(data.client)
124
125 def lower_win(data):
126 """Lowers the window on which the event occured"""
127 if not data.client: return
128 ob.openbox.screen(data.screen).lowerWindow(data.client)
129
130 def toggle_maximize(data):
131 """Toggles the maximized status of the window on which the event occured"""
132 state_maximize(data, StateToggle)
133
134 def toggle_maximize_horz(data):
135 """Toggles the horizontal maximized status of the window on which the event
136 occured"""
137 state_maximize_horz(data, StateToggle)
138
139 def toggle_maximize_vert(data):
140 """Toggles the vertical maximized status of the window on which the event
141 occured"""
142 state_maximize_vert(data, StateToggle)
143
144 def maximize(data):
145 """Maximizes the window on which the event occured"""
146 state_maximize(data, StateAdd)
147
148 def maximize_horz(data):
149 """Horizontally maximizes the window on which the event occured"""
150 state_maximize_horz(data, StateAdd)
151
152 def maximize_vert(data):
153 """Vertically maximizes the window on which the event occured"""
154 state_maximize_vert(data, StateAdd)
155
156 def unmaximize(data):
157 """Unmaximizes the window on which the event occured"""
158 state_maximize(data, StateRemove)
159
160 def unmaximize_horz(data):
161 """Horizontally unmaximizes the window on which the event occured"""
162 state_maximize_horz(data, StateRemove)
163
164 def unmaximize_vert(data):
165 """Vertically unmaximizes the window on which the event occured"""
166 state_maximize_vert(data, StateRemove)
167
168 def toggle_shade(data):
169 """Toggles the shade status of the window on which the event occured"""
170 state_shaded(data, StateToggle)
171
172 def shade(data):
173 """Shades the window on which the event occured"""
174 state_shaded(data, StateAdd)
175
176 def unshade(data):
177 """Unshades the window on which the event occured"""
178 state_shaded(data, StateRemove)
179
180 def change_desktop(data, num):
181 """Switches to a specified desktop"""
182 root = otk.display.screenInfo(data.screen).rootWindow()
183 ob.send_client_msg(root, otk.Property_atoms().net_current_desktop,
184 root, num)
185
186 def next_desktop(data, no_wrap=0):
187 """Switches to the next desktop, optionally (by default) cycling around to
188 the first when going past the last."""
189 screen = ob.openbox.screen(data.screen)
190 d = screen.desktop()
191 n = screen.numDesktops()
192 if (d < (n-1)):
193 d = d + 1
194 elif not no_wrap:
195 d = 0
196 change_desktop(data, d)
197
198 def prev_desktop(data, no_wrap=0):
199 """Switches to the previous desktop, optionally (by default) cycling around
200 to the last when going past the first."""
201 screen = ob.openbox.screen(data.screen)
202 d = screen.desktop()
203 n = screen.numDesktops()
204 if (d > 0):
205 d = d - 1
206 elif not no_wrap:
207 d = n - 1
208 change_desktop(data, d)
209
210 def send_to_desktop(data, num):
211 """Sends a client to a specified desktop"""
212 if not data.client: return
213 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
214 otk.Property_atoms().net_wm_desktop,
215 data.client.window(),num)
216
217 def toggle_all_desktops(data):
218 """Toggles between sending a client to all desktops and to the current
219 desktop."""
220 if not data.client: return
221 if not data.client.desktop() == 0xffffffff:
222 send_to_desktop(data, 0xffffffff)
223 else:
224 send_to_desktop(data, ob.openbox.screen(data.screen).desktop())
225
226 def send_to_all_desktops(data):
227 """Sends a client to all desktops"""
228 if not data.client: return
229 send_to_desktop(data, 0xffffffff)
230
231 def send_to_next_desktop(data, no_wrap=0, follow=1):
232 """Sends a window to the next desktop, optionally (by default) cycling
233 around to the first when going past the last. Also optionally moving to
234 the new desktop after sending the window."""
235 if not data.client: return
236 screen = ob.openbox.screen(data.screen)
237 d = screen.desktop()
238 n = screen.numDesktops()
239 if (d < (n-1)):
240 d = d + 1
241 elif not no_wrap:
242 d = 0
243 send_to_desktop(data, d)
244 if follow:
245 change_desktop(data, d)
246
247 def send_to_prev_desktop(data, no_wrap=0, follow=1):
248 """Sends a window to the previous desktop, optionally (by default) cycling
249 around to the last when going past the first. Also optionally moving to
250 the new desktop after sending the window."""
251 if not data.client: return
252 screen = ob.openbox.screen(data.screen)
253 d = screen.desktop()
254 n = screen.numDesktops()
255 if (d > 0):
256 d = d - 1
257 elif not no_wrap:
258 d = n - 1
259 send_to_desktop(data, d)
260 if follow:
261 change_desktop(data, d)
262
263 print "Loaded callbacks.py"
This page took 0.048046 seconds and 4 git commands to generate.