]> icculus.org git repositories - mikachu/openbox.git/blob - scripts/callbacks.py
all new stacked cycling code. so much sexy.
[mikachu/openbox.git] / 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 raise_win(data):
117     """Raises the window on which the event occured"""
118     if not data.client: return
119     ob.openbox.screen(data.screen).raiseWindow(data.client)
120
121 def lower_win(data):
122     """Lowers the window on which the event occured"""
123     if not data.client: return
124     ob.openbox.screen(data.screen).lowerWindow(data.client)
125
126 def toggle_maximize(data):
127     """Toggles the maximized status of the window on which the event occured"""
128     state_maximize(data, StateToggle)
129
130 def toggle_maximize_horz(data):
131     """Toggles the horizontal maximized status of the window on which the event
132        occured"""
133     state_maximize_horz(data, StateToggle)
134
135 def toggle_maximize_vert(data):
136     """Toggles the vertical maximized status of the window on which the event
137        occured"""
138     state_maximize_vert(data, StateToggle)
139
140 def maximize(data):
141     """Maximizes the window on which the event occured"""
142     state_maximize(data, StateAdd)
143
144 def maximize_horz(data):
145     """Horizontally maximizes the window on which the event occured"""
146     state_maximize_horz(data, StateAdd)
147
148 def maximize_vert(data):
149     """Vertically maximizes the window on which the event occured"""
150     state_maximize_vert(data, StateAdd)
151
152 def unmaximize(data):
153     """Unmaximizes the window on which the event occured"""
154     state_maximize(data, StateRemove)
155
156 def unmaximize_horz(data):
157     """Horizontally unmaximizes the window on which the event occured"""
158     state_maximize_horz(data, StateRemove)
159
160 def unmaximize_vert(data):
161     """Vertically unmaximizes the window on which the event occured"""
162     state_maximize_vert(data, StateRemove)
163
164 def toggle_shade(data):
165     """Toggles the shade status of the window on which the event occured"""
166     state_shaded(data, StateToggle)
167
168 def shade(data):
169     """Shades the window on which the event occured"""
170     state_shaded(data, StateAdd)
171
172 def unshade(data):
173     """Unshades the window on which the event occured"""
174     state_shaded(data, StateRemove)
175
176 def change_desktop(data, num):
177     """Switches to a specified desktop"""
178     root = otk.display.screenInfo(data.screen).rootWindow()
179     ob.send_client_msg(root, otk.Property_atoms().net_current_desktop,
180                        root, num)
181
182 def next_desktop(data, no_wrap=0):
183     """Switches to the next desktop, optionally (by default) cycling around to
184        the first when going past the last."""
185     screen = ob.openbox.screen(data.screen)
186     d = screen.desktop()
187     n = screen.numDesktops()
188     if (d < (n-1)):
189         d = d + 1
190     elif not no_wrap:
191         d = 0
192     change_desktop(data, d)
193     
194 def prev_desktop(data, no_wrap=0):
195     """Switches to the previous desktop, optionally (by default) cycling around
196        to the last when going past the first."""
197     screen = ob.openbox.screen(data.screen)
198     d = screen.desktop()
199     n = screen.numDesktops()
200     if (d > 0):
201         d = d - 1
202     elif not no_wrap:
203         d = n - 1
204     change_desktop(data, d)
205
206 def send_to_desktop(data, num):
207     """Sends a client to a specified desktop"""
208     if not data.client: return
209     ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
210                        otk.Property_atoms().net_wm_desktop,
211                        data.client.window(),num)
212
213 def toggle_all_desktops(data):
214     """Toggles between sending a client to all desktops and to the current
215        desktop."""
216     if not data.client: return
217     if not data.client.desktop() == 0xffffffff:
218         send_to_desktop(data, 0xffffffff)
219     else:
220         send_to_desktop(data, ob.openbox.screen(data.screen).desktop())
221     
222 def send_to_all_desktops(data):
223     """Sends a client to all desktops"""
224     if not data.client: return
225     send_to_desktop(data, 0xffffffff)
226     
227 def send_to_next_desktop(data, no_wrap=0, follow=1):
228     """Sends a window to the next desktop, optionally (by default) cycling
229        around to the first when going past the last. Also optionally moving to
230        the new desktop after sending the window."""
231     if not data.client: return
232     screen = ob.openbox.screen(data.screen)
233     d = screen.desktop()
234     n = screen.numDesktops()
235     if (d < (n-1)):
236         d = d + 1
237     elif not no_wrap:
238         d = 0
239     send_to_desktop(data, d)
240     if follow:
241         change_desktop(data, d)
242     
243 def send_to_prev_desktop(data, no_wrap=0, follow=1):
244     """Sends a window to the previous desktop, optionally (by default) cycling
245        around to the last when going past the first. Also optionally moving to
246        the new desktop after sending the window."""
247     if not data.client: return
248     screen = ob.openbox.screen(data.screen)
249     d = screen.desktop()
250     n = screen.numDesktops()
251     if (d > 0):
252         d = d - 1
253     elif not no_wrap:
254         d = n - 1
255     send_to_desktop(data, d)
256     if follow:
257         change_desktop(data, d)
258
259 def restart(data=0, other = ""):
260     """Restarts Openbox, optionally starting another window manager."""
261     ob.openbox.restart(other)
262
263 def exit(data=0):
264     """Exits Openbox."""
265     ob.openbox.shutdown()
266
267 print "Loaded callbacks.py"