]>
Dogcows Code - chaz/openbox/blob - scripts/callbacks.py
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 # resize_nearest - 1 to resize from the corner nearest where the mouse ###
9 ### is, 0 to resize always from the bottom right corner. ###
10 resize_nearest
= 1 ###
12 #############################################################################
17 def state_above(data
, add
=2):
18 """Toggles, adds or removes the 'above' state on a window."""
19 if not data
.client
: return
20 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
21 otk
.Property_atoms().net_wm_state
, data
.client
.window(),
22 add
, otk
.Property_atoms().net_wm_state_above
)
24 def state_below(data
, add
=2):
25 """Toggles, adds or removes the 'below' state on a window."""
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 if not data
.client
: return
34 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
35 otk
.Property_atoms().net_wm_state
, data
.client
.window(),
36 add
, otk
.Property_atoms().net_wm_state_shaded
)
39 """Iconifies the window on which the event occured"""
40 if not data
.client
: return
41 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
42 otk
.Property_atoms().wm_change_state
,
43 data
.client
.window(), 3) # IconicState
46 """Un-iconifies the window on which the event occured, but does not focus
47 if. If you want to focus the window too, it is recommended that you
48 use the activate() function."""
49 if not data
.client
: return
50 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
51 otk
.Property_atoms().wm_change_state
,
52 data
.client
.window(), 1) # NormalState
55 """Closes the window on which the event occured"""
56 if not data
.client
: return
57 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
58 otk
.Property_atoms().net_close_window
,
59 data
.client
.window(), 0)
62 """Focuses the window on which the event occured"""
63 if not data
.client
: return
64 # !normal windows dont get focus from window enter events
65 if data
.action
== ob
.EventAction
.EnterWindow
and not data
.client
.normal():
70 """Moves the window interactively. This should only be used with
72 if not data
.client
: return
74 # not-normal windows dont get moved
75 if not data
.client
.normal(): return
77 dx
= data
.xroot
- data
.pressx
78 dy
= data
.yroot
- data
.pressy
79 data
.client
.move(data
.press_clientx
+ dx
, data
.press_clienty
+ dy
)
82 """Resizes the window interactively. This should only be used with
84 if not data
.client
: return
86 # not-normal windows dont get resized
87 if not data
.client
.normal(): return
94 # pick a corner to anchor
95 if not (resize_nearest
or data
.context
== MC_Grip
):
96 corner
= ob
.Client
.TopLeft
98 x
= px
- data
.press_clientx
99 y
= py
- data
.press_clienty
100 if y
< data
.press_clientheight
/ 2:
101 if x
< data
.press_clientwidth
/ 2:
102 corner
= ob
.Client
.BottomRight
105 corner
= ob
.Client
.BottomLeft
108 if x
< data
.press_clientwidth
/ 2:
109 corner
= ob
.Client
.TopRight
112 corner
= ob
.Client
.TopLeft
114 data
.client
.resize(corner
,
115 data
.press_clientwidth
+ dx
,
116 data
.press_clientheight
+ dy
);
118 def restart(data
, other
= ""):
119 """Restarts openbox, optionally starting another window manager."""
120 ob
.openbox
.restart(other
)
123 """Raises the window on which the event occured"""
124 if not data
.client
: return
125 ob
.openbox
.screen(data
.screen
).raiseWindow(data
.client
)
128 """Lowers the window on which the event occured"""
129 if not data
.client
: return
130 ob
.openbox
.screen(data
.screen
).lowerWindow(data
.client
)
132 def toggle_shade(data
):
133 """Toggles the shade status of the window on which the event occured"""
137 """Shades the window on which the event occured"""
138 state_shaded(data
, 1)
141 """Unshades the window on which the event occured"""
142 state_shaded(data
, 0)
144 def change_desktop(data
, num
):
145 """Switches to a specified desktop"""
146 root
= otk
.display
.screenInfo(data
.screen
).rootWindow()
147 ob
.send_client_msg(root
, otk
.Property_atoms().net_current_desktop
,
150 def next_desktop(data
, no_wrap
=0):
151 """Switches to the next desktop, optionally (by default) cycling around to
152 the first when going past the last."""
153 screen
= ob
.openbox
.screen(data
.screen
)
155 n
= screen
.numDesktops()
160 change_desktop(data
, d
)
162 def prev_desktop(data
, no_wrap
=0):
163 """Switches to the previous desktop, optionally (by default) cycling around
164 to the last when going past the first."""
165 screen
= ob
.openbox
.screen(data
.screen
)
167 n
= screen
.numDesktops()
172 change_desktop(data
, d
)
174 def send_to_desktop(data
, num
):
175 """Sends a client to a specified desktop"""
176 if not data
.client
: return
177 ob
.send_client_msg(otk
.display
.screenInfo(data
.screen
).rootWindow(),
178 otk
.Property_atoms().net_wm_desktop
,
179 data
.client
.window(),num
)
181 def toggle_all_desktops(data
):
182 """Toggles between sending a client to all desktops and to the current
184 if not data
.client
: return
185 if not data
.client
.desktop() == 0xffffffff:
186 send_to_desktop(data
, 0xffffffff)
188 send_to_desktop(data
, openbox
.screen(data
.screen
).desktop())
190 def send_to_all_desktops(data
):
191 """Sends a client to all desktops"""
192 if not data
.client
: return
193 send_to_desktop(data
, 0xffffffff)
195 def send_to_next_desktop(data
, no_wrap
=0, follow
=1):
196 """Sends a window to the next desktop, optionally (by default) cycling
197 around to the first when going past the last. Also optionally moving to
198 the new desktop after sending the window."""
199 if not data
.client
: return
200 screen
= ob
.openbox
.screen(data
.screen
)
202 n
= screen
.numDesktops()
207 send_to_desktop(data
, d
)
209 change_desktop(data
, d
)
211 def send_to_prev_desktop(data
, no_wrap
=0, follow
=1):
212 """Sends a window to the previous desktop, optionally (by default) cycling
213 around to the last when going past the first. Also optionally moving to
214 the new desktop after sending the window."""
215 if not data
.client
: return
216 screen
= ob
.openbox
.screen(data
.screen
)
218 n
= screen
.numDesktops()
223 send_to_desktop(data
, d
)
225 change_desktop(data
, d
)
227 print "Loaded callbacks.py"
This page took 0.047748 seconds and 4 git commands to generate.