]>
Dogcows Code - chaz/openbox/blob - scripts/callbacks.py
caea758632403802e0de5bd71e902ef1260e1e8c
1 ###########################################################################
2 ### Functions that can be used as callbacks for mouse/keyboard bindings ###
3 ###########################################################################
7 def state_above(data
, add
=2):
8 """Toggles, adds or removes the 'above' state on a window."""
9 if not data
.client
: return
10 ob
.send_client_msg(ob
.display
.screenInfo(data
.screen
).rootWindow(),
11 ob
.Property_atoms().net_wm_state
, data
.client
.window(),
12 add
, ob
.Property_atoms().net_wm_state_above
)
14 def state_below(data
, add
=2):
15 """Toggles, adds or removes the 'below' state on a window."""
16 if not data
.client
: return
17 ob
.send_client_msg(ob
.display
.screenInfo(data
.screen
).rootWindow(),
18 ob
.Property_atoms().net_wm_state
, data
.client
.window(),
19 add
, ob
.Property_atoms().net_wm_state_below
)
21 def state_shaded(data
, add
=2):
22 """Toggles, adds or removes the 'shaded' state on a window."""
23 if not data
.client
: return
24 ob
.send_client_msg(ob
.display
.screenInfo(data
.screen
).rootWindow(),
25 ob
.Property_atoms().net_wm_state
, data
.client
.window(),
26 add
, ob
.Property_atoms().net_wm_state_shaded
)
29 """Iconifies the window on which the event occured"""
30 if not data
.client
: return
31 ob
.send_client_msg(ob
.display
.screenInfo(data
.screen
).rootWindow(),
32 ob
.Property_atoms().wm_change_state
,
33 data
.client
.window(), 3) # IconicState
36 """Un-iconifies the window on which the event occured, but does not focus
37 if. If you want to focus the window too, it is recommended that you
38 use the activate() function."""
39 if not data
.client
: return
40 ob
.send_client_msg(ob
.display
.screenInfo(data
.screen
).rootWindow(),
41 ob
.Property_atoms().wm_change_state
,
42 data
.client
.window(), 1) # NormalState
45 """Closes the window on which the event occured"""
46 if not data
.client
: return
47 ob
.send_client_msg(ob
.display
.screenInfo(data
.screen
).rootWindow(),
48 ob
.Property_atoms().net_close_window
,
49 data
.client
.window(), 0)
52 """Focuses the window on which the event occured"""
53 if not data
.client
: return
54 # !normal windows dont get focus from window enter events
55 if data
.action
== ob
.EventAction
.EnterWindow
and not data
.client
.normal():
60 """Moves the window interactively. This should only be used with
62 if not data
.client
: return
64 # not-normal windows dont get moved
65 if not data
.client
.normal(): return
67 dx
= data
.xroot
- data
.pressx
68 dy
= data
.yroot
- data
.pressy
69 data
.client
.move(data
.press_clientx
+ dx
, data
.press_clienty
+ dy
)
72 """Resizes the window interactively. This should only be used with
74 if not data
.client
: return
76 # not-normal windows dont get resized
77 if not data
.client
.normal(): return
84 # pick a corner to anchor
85 if not (resize_nearest
or data
.context
== MC_Grip
):
86 corner
= Client
.TopLeft
88 x
= px
- data
.press_clientx
89 y
= py
- data
.press_clienty
90 if y
< data
.press_clientheight
/ 2:
91 if x
< data
.press_clientwidth
/ 2:
92 corner
= Client
.BottomRight
95 corner
= Client
.BottomLeft
98 if x
< data
.press_clientwidth
/ 2:
99 corner
= Client
.TopRight
102 corner
= Client
.TopLeft
104 data
.client
.resize(corner
,
105 data
.press_clientwidth
+ dx
,
106 data
.press_clientheight
+ dy
);
108 def restart(data
, other
= ""):
109 """Restarts openbox, optionally starting another window manager."""
110 ob
.openbox
.restart(other
)
113 """Raises the window on which the event occured"""
114 if not data
.client
: return
115 ob
.openbox
.screen(data
.screen
).raiseWindow(data
.client
)
118 """Lowers the window on which the event occured"""
119 if not data
.client
: return
120 ob
.openbox
.screen(data
.screen
).lowerWindow(data
.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
= ob
.display
.screenInfo(data
.screen
).rootWindow()
137 ob
.send_client_msg(root
, ob
.Property_atoms().net_current_desktop
,
140 def next_desktop(data
, no_wrap
=0):
141 """Switches to the next desktop, optionally (by default) cycling around to
142 the first when going past the last."""
143 screen
= ob
.openbox
.screen(data
.screen
)
145 n
= screen
.numDesktops()
150 change_desktop(data
, d
)
152 def prev_desktop(data
, no_wrap
=0):
153 """Switches to the previous desktop, optionally (by default) cycling around
154 to the last when going past the first."""
155 screen
= ob
.openbox
.screen(data
.screen
)
157 n
= screen
.numDesktops()
162 change_desktop(data
, d
)
164 def send_to_desktop(data
, num
):
165 """Sends a client to a specified desktop"""
166 if not data
.client
: return
167 ob
.send_client_msg(ob
.display
.screenInfo(data
.screen
).rootWindow(),
168 ob
.Property_atoms().net_wm_desktop
,
169 data
.client
.window(),num
)
171 def toggle_all_desktops(data
):
172 """Toggles between sending a client to all desktops and to the current
174 if not data
.client
: return
175 if not data
.client
.desktop() == 0xffffffff:
176 send_to_desktop(data
, 0xffffffff)
178 send_to_desktop(data
, openbox
.screen(data
.screen
).desktop())
180 def send_to_all_desktops(data
):
181 """Sends a client to all desktops"""
182 if not data
.client
: return
183 send_to_desktop(data
, 0xffffffff)
185 def send_to_next_desktop(data
, no_wrap
=0, follow
=1):
186 """Sends a window to the next desktop, optionally (by default) cycling
187 around to the first when going past the last. Also optionally moving to
188 the new desktop after sending the window."""
189 if not data
.client
: return
190 screen
= ob
.openbox
.screen(data
.screen
)
192 n
= screen
.numDesktops()
197 send_to_desktop(data
, d
)
199 change_desktop(data
, d
)
201 def send_to_prev_desktop(data
, no_wrap
=0, follow
=1):
202 """Sends a window to the previous desktop, optionally (by default) cycling
203 around to the last when going past the first. Also optionally moving to
204 the new desktop after sending the window."""
205 if not data
.client
: return
206 screen
= ob
.openbox
.screen(data
.screen
)
208 n
= screen
.numDesktops()
213 send_to_desktop(data
, d
)
215 change_desktop(data
, d
)
217 print "Loaded callbacks.py"
This page took 0.042494 seconds and 4 git commands to generate.