]> Dogcows Code - chaz/openbox/blob - scripts/callbacks.py
doc the state functions better
[chaz/openbox] / scripts / callbacks.py
1 ############################################################################
2 ### Functions that can be used as callbacks for mouse/keyboard bindings ###
3 ############################################################################
4
5 #############################################################################
6 ### Options that can be modified to change the default hooks' behaviors. ###
7 ### ###
8 #############################################################################
9
10 import ob
11 import otk
12
13 def state_above(data, add=2):
14 """Toggles, adds or removes the 'above' state on a window.
15 The second paramater should one of: 0 - removes the state, 1 - adds the
16 state, 2 - toggles the state."""
17 if not data.client: return
18 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
19 otk.Property_atoms().net_wm_state, data.client.window(),
20 add, otk.Property_atoms().net_wm_state_above)
21
22 def state_below(data, add=2):
23 """Toggles, adds or removes the 'below' state on a window.
24 The second paramater should one of: 0 - removes the state, 1 - adds the
25 state, 2 - toggles the state."""
26 if not data.client: return
27 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
28 otk.Property_atoms().net_wm_state, data.client.window(),
29 add, otk.Property_atoms().net_wm_state_below)
30
31 def state_shaded(data, add=2):
32 """Toggles, adds or removes the 'shaded' state on a window.
33 The second paramater should one of: 0 - removes the state, 1 - adds the
34 state, 2 - toggles the state."""
35 if not data.client: return
36 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
37 otk.Property_atoms().net_wm_state, data.client.window(),
38 add, otk.Property_atoms().net_wm_state_shaded)
39
40 def state_skip_taskbar(data, add=2):
41 """Toggles, adds or removes the 'skip_taskbar' state on a window.
42 The second paramater should one of: 0 - removes the state, 1 - adds the
43 state, 2 - toggles the state."""
44 if not data.client: return
45 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
46 otk.Property_atoms().net_wm_state, data.client.window(),
47 add, otk.Property_atoms().net_wm_state_skip_taskbar)
48
49 def state_skip_pager(data, add=2):
50 """Toggles, adds or removes the 'skip_pager' state on a window.
51 The second paramater should one of: 0 - removes the state, 1 - adds the
52 state, 2 - toggles the state."""
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_skip_pager)
57
58 def iconify(data):
59 """Iconifies the window on which the event occured"""
60 if not data.client: return
61 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
62 otk.Property_atoms().wm_change_state,
63 data.client.window(), 3) # IconicState
64
65 def restore(data):
66 """Un-iconifies the window on which the event occured, but does not focus
67 if. If you want to focus the window too, it is recommended that you
68 use the activate() function."""
69 if not data.client: return
70 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
71 otk.Property_atoms().wm_change_state,
72 data.client.window(), 1) # NormalState
73
74 def close(data):
75 """Closes the window on which the event occured"""
76 if not data.client: return
77 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
78 otk.Property_atoms().net_close_window,
79 data.client.window(), 0)
80
81 def focus(data):
82 """Focuses the window on which the event occured"""
83 if not data.client: return
84 # !normal windows dont get focus from window enter events
85 if data.action == ob.EventAction.EnterWindow and not data.client.normal():
86 return
87 data.client.focus()
88
89 def restart(data, other = ""):
90 """Restarts openbox, optionally starting another window manager."""
91 ob.openbox.restart(other)
92
93 def raise_win(data):
94 """Raises the window on which the event occured"""
95 if not data.client: return
96 ob.openbox.screen(data.screen).raiseWindow(data.client)
97
98 def lower_win(data):
99 """Lowers the window on which the event occured"""
100 if not data.client: return
101 ob.openbox.screen(data.screen).lowerWindow(data.client)
102
103 def toggle_shade(data):
104 """Toggles the shade status of the window on which the event occured"""
105 state_shaded(data)
106
107 def shade(data):
108 """Shades the window on which the event occured"""
109 state_shaded(data, 1)
110
111 def unshade(data):
112 """Unshades the window on which the event occured"""
113 state_shaded(data, 0)
114
115 def change_desktop(data, num):
116 """Switches to a specified desktop"""
117 root = otk.display.screenInfo(data.screen).rootWindow()
118 ob.send_client_msg(root, otk.Property_atoms().net_current_desktop,
119 root, num)
120
121 def next_desktop(data, no_wrap=0):
122 """Switches to the next desktop, optionally (by default) cycling around to
123 the first when going past the last."""
124 screen = ob.openbox.screen(data.screen)
125 d = screen.desktop()
126 n = screen.numDesktops()
127 if (d < (n-1)):
128 d = d + 1
129 elif not no_wrap:
130 d = 0
131 change_desktop(data, d)
132
133 def prev_desktop(data, no_wrap=0):
134 """Switches to the previous desktop, optionally (by default) cycling around
135 to the last when going past the first."""
136 screen = ob.openbox.screen(data.screen)
137 d = screen.desktop()
138 n = screen.numDesktops()
139 if (d > 0):
140 d = d - 1
141 elif not no_wrap:
142 d = n - 1
143 change_desktop(data, d)
144
145 def send_to_desktop(data, num):
146 """Sends a client to a specified desktop"""
147 if not data.client: return
148 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
149 otk.Property_atoms().net_wm_desktop,
150 data.client.window(),num)
151
152 def toggle_all_desktops(data):
153 """Toggles between sending a client to all desktops and to the current
154 desktop."""
155 if not data.client: return
156 if not data.client.desktop() == 0xffffffff:
157 send_to_desktop(data, 0xffffffff)
158 else:
159 send_to_desktop(data, openbox.screen(data.screen).desktop())
160
161 def send_to_all_desktops(data):
162 """Sends a client to all desktops"""
163 if not data.client: return
164 send_to_desktop(data, 0xffffffff)
165
166 def send_to_next_desktop(data, no_wrap=0, follow=1):
167 """Sends a window to the next desktop, optionally (by default) cycling
168 around to the first when going past the last. Also optionally moving to
169 the new desktop after sending the window."""
170 if not data.client: return
171 screen = ob.openbox.screen(data.screen)
172 d = screen.desktop()
173 n = screen.numDesktops()
174 if (d < (n-1)):
175 d = d + 1
176 elif not no_wrap:
177 d = 0
178 send_to_desktop(data, d)
179 if follow:
180 change_desktop(data, d)
181
182 def send_to_prev_desktop(data, no_wrap=0, follow=1):
183 """Sends a window to the previous desktop, optionally (by default) cycling
184 around to the last when going past the first. Also optionally moving to
185 the new desktop after sending the window."""
186 if not data.client: return
187 screen = ob.openbox.screen(data.screen)
188 d = screen.desktop()
189 n = screen.numDesktops()
190 if (d > 0):
191 d = d - 1
192 elif not no_wrap:
193 d = n - 1
194 send_to_desktop(data, d)
195 if follow:
196 change_desktop(data, d)
197
198 print "Loaded callbacks.py"
This page took 0.046455 seconds and 5 git commands to generate.