1 ############################################################################
2 ### Functions that can be used as callbacks for mouse/keyboard bindings ###
3 ############################################################################
8 def state_above(data
, add
=2):
9 """Toggles, adds or removes the 'above' state on a window.
10 The second paramater should one of: 0 - removes the state, 1 - adds the
11 state, 2 - toggles the state."""
12 if not data
.client
: return
13 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
14 otk
.Property_atoms().net_wm_state
, data
.client
.window(),
15 add
, otk
.Property_atoms().net_wm_state_above
)
17 def state_below(data
, add
=2):
18 """Toggles, adds or removes the 'below' state on a window.
19 The second paramater should one of: 0 - removes the state, 1 - adds the
20 state, 2 - toggles the state."""
21 if not data
.client
: return
22 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
23 otk
.Property_atoms().net_wm_state
, data
.client
.window(),
24 add
, otk
.Property_atoms().net_wm_state_below
)
26 def state_shaded(data
, add
=2):
27 """Toggles, adds or removes the 'shaded' state on a window.
28 The second paramater should one of: 0 - removes the state, 1 - adds the
29 state, 2 - toggles the state."""
30 if not data
.client
: return
31 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
32 otk
.Property_atoms().net_wm_state
, data
.client
.window(),
33 add
, otk
.Property_atoms().net_wm_state_shaded
)
35 def state_skip_taskbar(data
, add
=2):
36 """Toggles, adds or removes the 'skip_taskbar' state on a window.
37 The second paramater should one of: 0 - removes the state, 1 - adds the
38 state, 2 - toggles the state."""
39 if not data
.client
: return
40 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
41 otk
.Property_atoms().net_wm_state
, data
.client
.window(),
42 add
, otk
.Property_atoms().net_wm_state_skip_taskbar
)
44 def state_skip_pager(data
, add
=2):
45 """Toggles, adds or removes the 'skip_pager' state on a window.
46 The second paramater should one of: 0 - removes the state, 1 - adds the
47 state, 2 - toggles the state."""
48 if not data
.client
: return
49 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
50 otk
.Property_atoms().net_wm_state
, data
.client
.window(),
51 add
, otk
.Property_atoms().net_wm_state_skip_pager
)
54 """Iconifies the window on which the event occured"""
55 if not data
.client
: return
56 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
57 otk
.Property_atoms().wm_change_state
,
58 data
.client
.window(), 3) # IconicState
61 """Un-iconifies the window on which the event occured, but does not focus
62 if. If you want to focus the window too, it is recommended that you
63 use the activate() function."""
64 if not data
.client
: return
65 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
66 otk
.Property_atoms().wm_change_state
,
67 data
.client
.window(), 1) # NormalState
70 """Closes the window on which the event occured"""
71 if not data
.client
: return
72 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
73 otk
.Property_atoms().net_close_window
,
74 data
.client
.window(), 0)
77 """Focuses the window on which the event occured"""
78 if not data
.client
: return
79 # !normal windows dont get focus from window enter events
80 if data
.action
== ob
.EventAction
.EnterWindow
and not data
.client
.normal():
84 def restart(data
, other
= ""):
85 """Restarts openbox, optionally starting another window manager."""
86 ob
.openbox
.restart(other
)
89 """Raises the window on which the event occured"""
90 if not data
.client
: return
91 ob
.openbox
.screen(data
.screen
).raiseWindow(data
.client
)
94 """Lowers the window on which the event occured"""
95 if not data
.client
: return
96 ob
.openbox
.screen(data
.screen
).lowerWindow(data
.client
)
98 def toggle_shade(data
):
99 """Toggles the shade status of the window on which the event occured"""
103 """Shades the window on which the event occured"""
104 state_shaded(data
, 1)
107 """Unshades the window on which the event occured"""
108 state_shaded(data
, 0)
110 def change_desktop(data
, num
):
111 """Switches to a specified desktop"""
112 root
= otk
.display
.screenInfo(data
.screen
).rootWindow()
113 ob
.send_client_msg(root
, otk
.Property_atoms().net_current_desktop
,
116 def next_desktop(data
, no_wrap
=0):
117 """Switches to the next desktop, optionally (by default) cycling around to
118 the first when going past the last."""
119 screen
= ob
.openbox
.screen(data
.screen
)
121 n
= screen
.numDesktops()
126 change_desktop(data
, d
)
128 def prev_desktop(data
, no_wrap
=0):
129 """Switches to the previous desktop, optionally (by default) cycling around
130 to the last when going past the first."""
131 screen
= ob
.openbox
.screen(data
.screen
)
133 n
= screen
.numDesktops()
138 change_desktop(data
, d
)
140 def send_to_desktop(data
, num
):
141 """Sends a client to a specified desktop"""
142 if not data
.client
: return
143 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
144 otk
.Property_atoms().net_wm_desktop
,
145 data
.client
.window(),num
)
147 def toggle_all_desktops(data
):
148 """Toggles between sending a client to all desktops and to the current
150 if not data
.client
: return
151 if not data
.client
.desktop() == 0xffffffff:
152 send_to_desktop(data
, 0xffffffff)
154 send_to_desktop(data
, openbox
.screen(data
.screen
).desktop())
156 def send_to_all_desktops(data
):
157 """Sends a client to all desktops"""
158 if not data
.client
: return
159 send_to_desktop(data
, 0xffffffff)
161 def send_to_next_desktop(data
, no_wrap
=0, follow
=1):
162 """Sends a window to the next desktop, optionally (by default) cycling
163 around to the first when going past the last. Also optionally moving to
164 the new desktop after sending the window."""
165 if not data
.client
: return
166 screen
= ob
.openbox
.screen(data
.screen
)
168 n
= screen
.numDesktops()
173 send_to_desktop(data
, d
)
175 change_desktop(data
, d
)
177 def send_to_prev_desktop(data
, no_wrap
=0, follow
=1):
178 """Sends a window to the previous desktop, optionally (by default) cycling
179 around to the last when going past the first. Also optionally moving to
180 the new desktop after sending the window."""
181 if not data
.client
: return
182 screen
= ob
.openbox
.screen(data
.screen
)
184 n
= screen
.numDesktops()
189 send_to_desktop(data
, d
)
191 change_desktop(data
, d
)
193 print "Loaded callbacks.py"