1 ############################################################################
2 ### Functions that can be used as callbacks for mouse/keyboard bindings ###
3 ############################################################################
5 #############################################################################
6 ### Options that can be modified to change the default hooks' behaviors. ###
8 #############################################################################
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
)
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
)
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
)
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
)
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
)
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
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
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)
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():
89 def restart(data
, other
= ""):
90 """Restarts openbox, optionally starting another window manager."""
91 ob
.openbox
.restart(other
)
94 """Raises the window on which the event occured"""
95 if not data
.client
: return
96 ob
.openbox
.screen(data
.screen
).raiseWindow(data
.client
)
99 """Lowers the window on which the event occured"""
100 if not data
.client
: return
101 ob
.openbox
.screen(data
.screen
).lowerWindow(data
.client
)
103 def toggle_shade(data
):
104 """Toggles the shade status of the window on which the event occured"""
108 """Shades the window on which the event occured"""
109 state_shaded(data
, 1)
112 """Unshades the window on which the event occured"""
113 state_shaded(data
, 0)
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
,
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
)
126 n
= screen
.numDesktops()
131 change_desktop(data
, d
)
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
)
138 n
= screen
.numDesktops()
143 change_desktop(data
, d
)
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
)
152 def toggle_all_desktops(data
):
153 """Toggles between sending a client to all desktops and to the current
155 if not data
.client
: return
156 if not data
.client
.desktop() == 0xffffffff:
157 send_to_desktop(data
, 0xffffffff)
159 send_to_desktop(data
, openbox
.screen(data
.screen
).desktop())
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)
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
)
173 n
= screen
.numDesktops()
178 send_to_desktop(data
, d
)
180 change_desktop(data
, d
)
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
)
189 n
= screen
.numDesktops()
194 send_to_desktop(data
, d
)
196 change_desktop(data
, d
)
198 print "Loaded callbacks.py"