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