]> Dogcows Code - chaz/openbox/blob - scripts/callbacks.py
maximizing!
[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 maximize(data):
135 """Maximizes the window on which the event occured"""
136 state_maximize(data, StateAdd)
137
138 def unmaximize(data):
139 """Unmaximizes the window on which the event occured"""
140 state_maximize(data, StateRemove)
141
142 def toggle_shade(data):
143 """Toggles the shade status of the window on which the event occured"""
144 state_shaded(data, StateToggle)
145
146 def shade(data):
147 """Shades the window on which the event occured"""
148 state_shaded(data, StateAdd)
149
150 def unshade(data):
151 """Unshades the window on which the event occured"""
152 state_shaded(data, StateRemove)
153
154 def change_desktop(data, num):
155 """Switches to a specified desktop"""
156 root = otk.display.screenInfo(data.screen).rootWindow()
157 ob.send_client_msg(root, otk.Property_atoms().net_current_desktop,
158 root, num)
159
160 def next_desktop(data, no_wrap=0):
161 """Switches to the next desktop, optionally (by default) cycling around to
162 the first when going past the last."""
163 screen = ob.openbox.screen(data.screen)
164 d = screen.desktop()
165 n = screen.numDesktops()
166 if (d < (n-1)):
167 d = d + 1
168 elif not no_wrap:
169 d = 0
170 change_desktop(data, d)
171
172 def prev_desktop(data, no_wrap=0):
173 """Switches to the previous desktop, optionally (by default) cycling around
174 to the last when going past the first."""
175 screen = ob.openbox.screen(data.screen)
176 d = screen.desktop()
177 n = screen.numDesktops()
178 if (d > 0):
179 d = d - 1
180 elif not no_wrap:
181 d = n - 1
182 change_desktop(data, d)
183
184 def send_to_desktop(data, num):
185 """Sends a client to a specified desktop"""
186 if not data.client: return
187 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
188 otk.Property_atoms().net_wm_desktop,
189 data.client.window(),num)
190
191 def toggle_all_desktops(data):
192 """Toggles between sending a client to all desktops and to the current
193 desktop."""
194 if not data.client: return
195 if not data.client.desktop() == 0xffffffff:
196 send_to_desktop(data, 0xffffffff)
197 else:
198 send_to_desktop(data, ob.openbox.screen(data.screen).desktop())
199
200 def send_to_all_desktops(data):
201 """Sends a client to all desktops"""
202 if not data.client: return
203 send_to_desktop(data, 0xffffffff)
204
205 def send_to_next_desktop(data, no_wrap=0, follow=1):
206 """Sends a window to the next desktop, optionally (by default) cycling
207 around to the first when going past the last. Also optionally moving to
208 the new desktop after sending the window."""
209 if not data.client: return
210 screen = ob.openbox.screen(data.screen)
211 d = screen.desktop()
212 n = screen.numDesktops()
213 if (d < (n-1)):
214 d = d + 1
215 elif not no_wrap:
216 d = 0
217 send_to_desktop(data, d)
218 if follow:
219 change_desktop(data, d)
220
221 def send_to_prev_desktop(data, no_wrap=0, follow=1):
222 """Sends a window to the previous desktop, optionally (by default) cycling
223 around to the last when going past the first. Also optionally moving to
224 the new desktop after sending the window."""
225 if not data.client: return
226 screen = ob.openbox.screen(data.screen)
227 d = screen.desktop()
228 n = screen.numDesktops()
229 if (d > 0):
230 d = d - 1
231 elif not no_wrap:
232 d = n - 1
233 send_to_desktop(data, d)
234 if follow:
235 change_desktop(data, d)
236
237 print "Loaded callbacks.py"
This page took 0.045558 seconds and 4 git commands to generate.