1 ###########################################################################
2 ### Functions that can be used as callbacks for mouse/keyboard bindings ###
3 ###########################################################################
6 """Closes the window on which the event occured"""
7 client
= Openbox_findClient(openbox
, data
.window())
8 if client
: OBClient_close(client
)
11 """Focuses the window on which the event occured"""
12 client
= Openbox_findClient(openbox
, data
.window())
14 type = OBClient_type(client
)
15 # !normal windows dont get focus from window enter events
16 if data
.action() == EventEnterWindow
and not OBClient_normal(client
):
18 OBClient_focus(client
)
21 """Moves the window interactively. This should only be used with
23 client
= Openbox_findClient(openbox
, data
.window())
26 # !normal windows dont get moved
27 if not OBClient_normal(client
): return
29 dx
= data
.xroot() - data
.pressx()
30 dy
= data
.yroot() - data
.pressy()
31 OBClient_move(client
, data
.press_clientx() + dx
, data
.press_clienty() + dy
)
34 """Resizes the window interactively. This should only be used with
36 client
= Openbox_findClient(openbox
, data
.window())
39 # !normal windows dont get moved
40 if not OBClient_normal(client
): return
44 dx
= data
.xroot() - px
45 dy
= data
.yroot() - py
47 # pick a corner to anchor
48 if not (resize_nearest
or data
.context() == MC_Grip
):
49 corner
= OBClient_TopLeft
51 x
= px
- data
.press_clientx()
52 y
= py
- data
.press_clienty()
53 if y
< data
.press_clientheight() / 2:
54 if x
< data
.press_clientwidth() / 2:
55 corner
= OBClient_BottomRight
58 corner
= OBClient_BottomLeft
61 if x
< data
.press_clientwidth() / 2:
62 corner
= OBClient_TopRight
65 corner
= OBClient_TopLeft
67 OBClient_resize(client
, corner
,
68 data
.press_clientwidth() + dx
,
69 data
.press_clientheight() + dy
);
72 """Restarts openbox"""
73 Openbox_restart(openbox
, "")
76 """Raises the window on which the event occured"""
77 client
= Openbox_findClient(openbox
, data
.window())
79 screen
= Openbox_screen(openbox
, OBClient_screen(client
))
80 OBScreen_restack(screen
, 1, client
)
83 """Lowers the window on which the event occured"""
84 client
= Openbox_findClient(openbox
, data
.window())
86 screen
= Openbox_screen(openbox
, OBClient_screen(client
))
87 OBScreen_restack(screen
, 0, client
)
89 def toggle_shade(data
):
90 """Toggles the shade status of the window on which the event occured"""
91 client
= Openbox_findClient(openbox
, data
.window())
94 OBClient_shade(client
, not OBClient_shaded(client
))
97 """Shades the window on which the event occured"""
98 client
= Openbox_findClient(openbox
, data
.window())
100 OBClient_shade(client
, 1)
103 """Unshades the window on which the event occured"""
104 client
= Openbox_findClient(openbox
, data
.window())
105 if not client
: return
106 OBClient_shade(client
, 0)
108 def change_desktop(data
, num
):
109 """Switches to a specified desktop"""
110 root
= ScreenInfo_rootWindow(OBDisplay_screenInfo(data
.screen()))
111 send_client_msg(root
, OBProperty_net_current_desktop
, root
, num
)
113 def next_desktop(data
, no_wrap
=0):
114 """Switches to the next desktop, optionally (by default) cycling around to
115 the first when going past the last."""
116 screen
= Openbox_screen(openbox
, data
.screen())
117 d
= OBScreen_desktop(screen
)
118 n
= OBScreen_numDesktops(screen
)
123 change_desktop(data
, d
)
125 def prev_desktop(data
, no_wrap
=0):
126 """Switches to the previous desktop, optionally (by default) cycling around
127 to the last when going past the first."""
128 screen
= Openbox_screen(openbox
, data
.screen())
129 d
= OBScreen_desktop(screen
)
130 n
= OBScreen_numDesktops(screen
)
135 change_desktop(data
, d
)
137 def send_to_desktop(data
, num
):
138 """Sends a client to a specified desktop"""
139 root
= ScreenInfo_rootWindow(OBDisplay_screenInfo(data
.screen()))
140 client
= Openbox_findClient(openbox
, data
.window())
142 window
= OBClient_window(client
)
143 send_client_msg(root
, OBProperty_net_wm_desktop
, window
, num
)
145 def send_to_next_desktop(data
, no_wrap
=0, follow
=1):
146 """Sends a window to the next desktop, optionally (by default) cycling
147 around to the first when going past the last. Also optionally moving to
148 the new desktop after sending the window."""
149 client
= Openbox_findClient(openbox
, data
.window())
150 if not client
: return
151 screen
= Openbox_screen(openbox
, data
.screen())
152 d
= OBScreen_desktop(screen
)
153 n
= OBScreen_numDesktops(screen
)
158 send_to_desktop(data
, d
)
160 change_desktop(data
, d
)
162 def send_to_prev_desktop(data
, no_wrap
=0, follow
=1):
163 """Sends a window to the previous desktop, optionally (by default) cycling
164 around to the last when going past the first. Also optionally moving to
165 the new desktop after sending the window."""
166 client
= Openbox_findClient(openbox
, data
.window())
167 if not client
: return
168 screen
= Openbox_screen(openbox
, data
.screen())
169 d
= OBScreen_desktop(screen
)
170 n
= OBScreen_numDesktops(screen
)
175 send_to_desktop(data
, d
)
177 change_desktop(data
, d
)
179 #########################################
180 ### Convenience functions for scripts ###
181 #########################################
183 def execute(bin
, screen
= 0):
184 """Executes a command on the specified screen. It is recommended that you
185 use this call instead of a python system call. If the specified screen
186 is beyond your range of screens, the default is used instead."""
187 Openbox_execute(openbox
, screen
, bin
)
189 print "Loaded builtins.py"