1 ###########################################################################
2 ### Functions that can be used as callbacks for mouse/keyboard bindings ###
3 ###########################################################################
5 def state_above(data
, add
=2):
6 """Toggles, adds or removes the 'above' state on a window."""
7 client
= Openbox_findClient(openbox
, data
.window())
9 root
= ScreenInfo_rootWindow(OBDisplay_screenInfo(data
.screen()))
10 window
= OBClient_window(client
)
11 above
= OBProperty_atom(Openbox_property(openbox
),
12 OBProperty_net_wm_state_above
)
13 send_client_msg(root
, OBProperty_net_wm_state
, window
, add
,
16 def state_below(data
, add
=2):
17 """Toggles, adds or removes the 'below' state on a window."""
18 client
= Openbox_findClient(openbox
, data
.window())
20 root
= ScreenInfo_rootWindow(OBDisplay_screenInfo(data
.screen()))
21 window
= OBClient_window(client
)
22 below
= OBProperty_atom(Openbox_property(openbox
),
23 OBProperty_net_wm_state_below
)
24 send_client_msg(root
, OBProperty_net_wm_state
, window
, add
,
27 def state_shaded(data
, add
=2):
28 """Toggles, adds or removes the 'shaded' state on a window."""
29 client
= Openbox_findClient(openbox
, data
.window())
31 root
= ScreenInfo_rootWindow(OBDisplay_screenInfo(data
.screen()))
32 window
= OBClient_window(client
)
33 shaded
= OBProperty_atom(Openbox_property(openbox
),
34 OBProperty_net_wm_state_shaded
)
35 send_client_msg(root
, OBProperty_net_wm_state
, window
, add
,
39 """Closes the window on which the event occured"""
40 client
= Openbox_findClient(openbox
, data
.window())
41 if client
: OBClient_close(client
)
44 """Focuses the window on which the event occured"""
45 client
= Openbox_findClient(openbox
, data
.window())
47 type = OBClient_type(client
)
48 # !normal windows dont get focus from window enter events
49 if data
.action() == EventEnterWindow
and not OBClient_normal(client
):
51 OBClient_focus(client
)
54 """Moves the window interactively. This should only be used with
56 client
= Openbox_findClient(openbox
, data
.window())
59 # !normal windows dont get moved
60 if not OBClient_normal(client
): return
62 dx
= data
.xroot() - data
.pressx()
63 dy
= data
.yroot() - data
.pressy()
64 OBClient_move(client
, data
.press_clientx() + dx
, data
.press_clienty() + dy
)
67 """Resizes the window interactively. This should only be used with
69 client
= Openbox_findClient(openbox
, data
.window())
72 # !normal windows dont get moved
73 if not OBClient_normal(client
): return
77 dx
= data
.xroot() - px
78 dy
= data
.yroot() - py
80 # pick a corner to anchor
81 if not (resize_nearest
or data
.context() == MC_Grip
):
82 corner
= OBClient_TopLeft
84 x
= px
- data
.press_clientx()
85 y
= py
- data
.press_clienty()
86 if y
< data
.press_clientheight() / 2:
87 if x
< data
.press_clientwidth() / 2:
88 corner
= OBClient_BottomRight
91 corner
= OBClient_BottomLeft
94 if x
< data
.press_clientwidth() / 2:
95 corner
= OBClient_TopRight
98 corner
= OBClient_TopLeft
100 OBClient_resize(client
, corner
,
101 data
.press_clientwidth() + dx
,
102 data
.press_clientheight() + dy
);
105 """Restarts openbox"""
106 Openbox_restart(openbox
, "")
109 """Raises the window on which the event occured"""
110 client
= Openbox_findClient(openbox
, data
.window())
111 if not client
: return
112 screen
= Openbox_screen(openbox
, OBClient_screen(client
))
113 OBScreen_restack(screen
, 1, client
)
116 """Lowers the window on which the event occured"""
117 client
= Openbox_findClient(openbox
, data
.window())
118 if not client
: return
119 screen
= Openbox_screen(openbox
, OBClient_screen(client
))
120 OBScreen_restack(screen
, 0, client
)
122 def toggle_shade(data
):
123 """Toggles the shade status of the window on which the event occured"""
127 """Shades the window on which the event occured"""
128 state_shaded(data
, 1)
131 """Unshades the window on which the event occured"""
132 state_shaded(data
, 0)
134 def change_desktop(data
, num
):
135 """Switches to a specified desktop"""
136 root
= ScreenInfo_rootWindow(OBDisplay_screenInfo(data
.screen()))
137 send_client_msg(root
, OBProperty_net_current_desktop
, root
, num
)
139 def next_desktop(data
, no_wrap
=0):
140 """Switches to the next desktop, optionally (by default) cycling around to
141 the first when going past the last."""
142 screen
= Openbox_screen(openbox
, data
.screen())
143 d
= OBScreen_desktop(screen
)
144 n
= OBScreen_numDesktops(screen
)
149 change_desktop(data
, d
)
151 def prev_desktop(data
, no_wrap
=0):
152 """Switches to the previous desktop, optionally (by default) cycling around
153 to the last when going past the first."""
154 screen
= Openbox_screen(openbox
, data
.screen())
155 d
= OBScreen_desktop(screen
)
156 n
= OBScreen_numDesktops(screen
)
161 change_desktop(data
, d
)
163 def send_to_desktop(data
, num
):
164 """Sends a client to a specified desktop"""
165 root
= ScreenInfo_rootWindow(OBDisplay_screenInfo(data
.screen()))
166 client
= Openbox_findClient(openbox
, data
.window())
168 window
= OBClient_window(client
)
169 send_client_msg(root
, OBProperty_net_wm_desktop
, window
, num
)
171 def send_to_next_desktop(data
, no_wrap
=0, follow
=1):
172 """Sends a window to the next desktop, optionally (by default) cycling
173 around to the first when going past the last. Also optionally moving to
174 the new desktop after sending the window."""
175 client
= Openbox_findClient(openbox
, data
.window())
176 if not client
: return
177 screen
= Openbox_screen(openbox
, data
.screen())
178 d
= OBScreen_desktop(screen
)
179 n
= OBScreen_numDesktops(screen
)
184 send_to_desktop(data
, d
)
186 change_desktop(data
, d
)
188 def send_to_prev_desktop(data
, no_wrap
=0, follow
=1):
189 """Sends a window to the previous desktop, optionally (by default) cycling
190 around to the last when going past the first. Also optionally moving to
191 the new desktop after sending the window."""
192 client
= Openbox_findClient(openbox
, data
.window())
193 if not client
: return
194 screen
= Openbox_screen(openbox
, data
.screen())
195 d
= OBScreen_desktop(screen
)
196 n
= OBScreen_numDesktops(screen
)
201 send_to_desktop(data
, d
)
203 change_desktop(data
, d
)
205 #########################################
206 ### Convenience functions for scripts ###
207 #########################################
209 def execute(bin
, screen
= 0):
210 """Executes a command on the specified screen. It is recommended that you
211 use this call instead of a python system call. If the specified screen
212 is beyond your range of screens, the default is used instead."""
213 Openbox_execute(openbox
, screen
, bin
)
215 print "Loaded builtins.py"