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())
42 root
= ScreenInfo_rootWindow(OBDisplay_screenInfo(data
.screen()))
43 window
= OBClient_window(client
)
44 send_client_msg(root
, OBProperty_net_close_window
, window
, 0)
47 """Focuses the window on which the event occured"""
48 client
= Openbox_findClient(openbox
, data
.window())
50 type = OBClient_type(client
)
51 # !normal windows dont get focus from window enter events
52 if data
.action() == EventEnterWindow
and not OBClient_normal(client
):
54 OBClient_focus(client
)
57 """Moves the window interactively. This should only be used with
59 client
= Openbox_findClient(openbox
, data
.window())
62 # !normal windows dont get moved
63 if not OBClient_normal(client
): return
65 dx
= data
.xroot() - data
.pressx()
66 dy
= data
.yroot() - data
.pressy()
67 OBClient_move(client
, data
.press_clientx() + dx
, data
.press_clienty() + dy
)
70 """Resizes the window interactively. This should only be used with
72 client
= Openbox_findClient(openbox
, data
.window())
75 # !normal windows dont get moved
76 if not OBClient_normal(client
): return
80 dx
= data
.xroot() - px
81 dy
= data
.yroot() - py
83 # pick a corner to anchor
84 if not (resize_nearest
or data
.context() == MC_Grip
):
85 corner
= OBClient_TopLeft
87 x
= px
- data
.press_clientx()
88 y
= py
- data
.press_clienty()
89 if y
< data
.press_clientheight() / 2:
90 if x
< data
.press_clientwidth() / 2:
91 corner
= OBClient_BottomRight
94 corner
= OBClient_BottomLeft
97 if x
< data
.press_clientwidth() / 2:
98 corner
= OBClient_TopRight
101 corner
= OBClient_TopLeft
103 OBClient_resize(client
, corner
,
104 data
.press_clientwidth() + dx
,
105 data
.press_clientheight() + dy
);
108 """Restarts openbox"""
109 Openbox_restart(openbox
, "")
112 """Raises the window on which the event occured"""
113 client
= Openbox_findClient(openbox
, data
.window())
114 if not client
: return
115 screen
= Openbox_screen(openbox
, OBClient_screen(client
))
116 OBScreen_restack(screen
, 1, client
)
119 """Lowers the window on which the event occured"""
120 client
= Openbox_findClient(openbox
, data
.window())
121 if not client
: return
122 screen
= Openbox_screen(openbox
, OBClient_screen(client
))
123 OBScreen_restack(screen
, 0, client
)
125 def toggle_shade(data
):
126 """Toggles the shade status of the window on which the event occured"""
130 """Shades the window on which the event occured"""
131 state_shaded(data
, 1)
134 """Unshades the window on which the event occured"""
135 state_shaded(data
, 0)
137 def change_desktop(data
, num
):
138 """Switches to a specified desktop"""
139 root
= ScreenInfo_rootWindow(OBDisplay_screenInfo(data
.screen()))
140 send_client_msg(root
, OBProperty_net_current_desktop
, root
, num
)
142 def next_desktop(data
, no_wrap
=0):
143 """Switches to the next desktop, optionally (by default) cycling around to
144 the first when going past the last."""
145 screen
= Openbox_screen(openbox
, data
.screen())
146 d
= OBScreen_desktop(screen
)
147 n
= OBScreen_numDesktops(screen
)
152 change_desktop(data
, d
)
154 def prev_desktop(data
, no_wrap
=0):
155 """Switches to the previous desktop, optionally (by default) cycling around
156 to the last when going past the first."""
157 screen
= Openbox_screen(openbox
, data
.screen())
158 d
= OBScreen_desktop(screen
)
159 n
= OBScreen_numDesktops(screen
)
164 change_desktop(data
, d
)
166 def send_to_desktop(data
, num
):
167 """Sends a client to a specified desktop"""
168 root
= ScreenInfo_rootWindow(OBDisplay_screenInfo(data
.screen()))
169 client
= Openbox_findClient(openbox
, data
.window())
171 window
= OBClient_window(client
)
172 send_client_msg(root
, OBProperty_net_wm_desktop
, window
, num
)
174 def send_to_next_desktop(data
, no_wrap
=0, follow
=1):
175 """Sends a window to the next desktop, optionally (by default) cycling
176 around to the first when going past the last. Also optionally moving to
177 the new desktop after sending the window."""
178 client
= Openbox_findClient(openbox
, data
.window())
179 if not client
: return
180 screen
= Openbox_screen(openbox
, data
.screen())
181 d
= OBScreen_desktop(screen
)
182 n
= OBScreen_numDesktops(screen
)
187 send_to_desktop(data
, d
)
189 change_desktop(data
, d
)
191 def send_to_prev_desktop(data
, no_wrap
=0, follow
=1):
192 """Sends a window to the previous desktop, optionally (by default) cycling
193 around to the last when going past the first. Also optionally moving to
194 the new desktop after sending the window."""
195 client
= Openbox_findClient(openbox
, data
.window())
196 if not client
: return
197 screen
= Openbox_screen(openbox
, data
.screen())
198 d
= OBScreen_desktop(screen
)
199 n
= OBScreen_numDesktops(screen
)
204 send_to_desktop(data
, d
)
206 change_desktop(data
, d
)
208 #########################################
209 ### Convenience functions for scripts ###
210 #########################################
212 def execute(bin
, screen
= 0):
213 """Executes a command on the specified screen. It is recommended that you
214 use this call instead of a python system call. If the specified screen
215 is beyond your range of screens, the default is used instead."""
216 Openbox_execute(openbox
, screen
, bin
)
218 print "Loaded builtins.py"