]>
Dogcows Code - chaz/openbox/blob - scripts/motion.py
1 ############################################################################
2 ### Functions that provide callbacks for motion events to move and ###
3 ### resize windows. ###
4 ############################################################################
6 #############################################################################
7 ### Options that can be modified to change the functions' behaviors. ###
9 # edge_resistance - the amount of resistance to provide to moving a ###
10 ### window past a screen boundary. Specify a value of 0 ###
11 ### to disable edge resistance. ###
12 edge_resistance
= 10 ###
14 # move_popup - display a coordinates popup when moving windows. ###
17 # NOT IMPLEMENTED (yet?) ###
18 # move_rubberband - display an outline while moving instead of moving the ###
19 ### actual window, until the move is completed. Good for ###
20 ### slower systems. ###
21 move_rubberband
= 0 ###
23 # resize_popup - display a size popup when resizing windows. ###
26 # NOT IMPLEMENTED (yet?) ###
27 # resize_rubberband - display an outline while resizing instead of ###
28 ### resizing the actual window, until the resize is ###
29 ### completed. Good for slower systems. ###
30 resize_rubberband
= 0 ###
32 # resize_nearest - 1 to resize from the corner nearest where the mouse ###
33 ### is, 0 to resize always from the bottom right corner. ###
34 resize_nearest
= 1 ###
39 # """Moves the window interactively. This should only be used with ###
40 # MouseMotion events. If move_popup or move_rubberband is enabled, ###
41 # then the end_move function needs to be bound as well.""" ###
42 # def end_move(data): ###
43 # """Complete the interactive move of a window.""" ###
44 # def resize(data): ###
45 # """Resizes the window interactively. This should only be used with ###
46 # MouseMotion events""" ###
47 # def end_resize(data): ###
48 # """Complete the interactive resize of a window.""" ###
50 #############################################################################
76 def _motion_grab(data
):
77 global _motion_mask
, _inmove
, _inresize
;
79 if data
.action
== ob
.KeyAction
.Release
:
80 # have all the modifiers this started with been released?
81 if not _motion_mask
& data
.state
:
93 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
98 global edge_resistance
, _last_x
, _last_y
100 fs
= _client
.frame
.size()
101 w
= _client
.area().width() + fs
.left
+ fs
.right
102 h
= _client
.area().height() + fs
.top
+ fs
.bottom
103 # use the area based on the struts
104 area
= ob
.openbox
.screen(_screen
).area()
106 r
= area
.right() - w
+ 1
108 b
= area
.bottom() - h
+ 1
110 if _last_x
> x
and x
< l
and x
>= l
- edge_resistance
:
113 if _last_x
< x
and x
> r
and x
<= r
+ edge_resistance
:
116 if _last_y
> y
and y
< t
and y
>= t
- edge_resistance
:
119 if _last_y
< y
and y
> b
and y
<= b
+ edge_resistance
:
125 global move_rubberband
127 # draw the outline ...
134 global _popwidget
, _poplabel
135 style
= ob
.openbox
.screen(_screen
).style()
136 font
= style
.labelFont()
137 text
= "X: " + str(x
) + " Y: " + str(y
)
138 length
= font
.measureString(text
)
140 _popwidget
= otk
.Widget(ob
.openbox
, style
,
141 otk
.Widget
.Horizontal
, 0,
142 style
.bevelWidth(), 1)
143 _popwidget
.setTexture(style
.titlebarFocusBackground())
144 _poplabel
= otk
.Label(_popwidget
)
145 _poplabel
.setTexture(style
.labelFocusBackground())
146 _poplabel
.fitString(text
)
147 _poplabel
.setText(text
)
149 area
= otk
.display
.screenInfo(_screen
).rect()
150 _popwidget
.move(area
.x() + (area
.width() -
151 _popwidget
.width()) / 2,
152 area
.y() + (area
.height() -
153 _popwidget
.height()) / 2)
157 """Moves the window interactively. This should only be used with
158 MouseMotion events. If move_popup or move_rubberband is enabled, then
159 the end_move function needs to be bound as well."""
160 if not data
.client
: return
162 # not-normal windows dont get moved
163 if not data
.client
.normal(): return
165 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
166 _screen
= data
.screen
167 _client
= data
.client
168 _cx
= data
.press_clientx
169 _cy
= data
.press_clienty
170 _dx
= data
.xroot
- data
.pressx
171 _dy
= data
.yroot
- data
.pressy
175 ob
.kgrab(_screen
, _motion_grab
)
179 """Complete the interactive move of a window."""
180 global move_rubberband
, _inmove
181 global _popwidget
, _poplabel
193 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
198 # pick a corner to anchor
199 if not (resize_nearest
or _context
== ob
.MouseContext
.Grip
):
200 corner
= ob
.Client
.TopLeft
206 corner
= ob
.Client
.BottomRight
209 corner
= ob
.Client
.BottomLeft
213 corner
= ob
.Client
.TopRight
216 corner
= ob
.Client
.TopLeft
222 if resize_rubberband
:
223 # draw the outline ...
226 _client
.resize(corner
, w
, h
)
230 global _popwidget
, _poplabel
231 style
= ob
.openbox
.screen(_screen
).style()
232 ls
= _client
.logicalSize()
233 text
= "W: " + str(ls
.x()) + " H: " + str(ls
.y())
235 _popwidget
= otk
.Widget(ob
.openbox
, style
,
236 otk
.Widget
.Horizontal
, 0,
237 style
.bevelWidth(), 1)
238 _popwidget
.setTexture(style
.titlebarFocusBackground())
239 _poplabel
= otk
.Label(_popwidget
)
240 _poplabel
.setTexture(style
.labelFocusBackground())
241 _poplabel
.fitString(text
)
242 _poplabel
.setText(text
)
243 area
= otk
.display
.screenInfo(_screen
).rect()
245 _popwidget
.move(area
.x() + (area
.width() -
246 _popwidget
.width()) / 2,
247 area
.y() + (area
.height() -
248 _popwidget
.height()) / 2)
252 """Resizes the window interactively. This should only be used with
253 MouseMotion events"""
254 if not data
.client
: return
256 # not-normal windows dont get resized
257 if not data
.client
.normal(): return
259 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
260 _screen
= data
.screen
261 _client
= data
.client
262 _cx
= data
.press_clientx
263 _cy
= data
.press_clienty
264 _cw
= data
.press_clientwidth
265 _ch
= data
.press_clientheight
268 _dx
= data
.xroot
- _px
269 _dy
= data
.yroot
- _py
273 ob
.kgrab(_screen
, _motion_grab
)
276 def end_resize(data
):
277 """Complete the interactive resize of a window."""
278 global resize_rubberband
, _inresize
279 global _popwidget
, _poplabel
281 r
= resize_rubberband
282 resize_rubberband
= 0
284 resize_rubberband
= r
This page took 0.04961 seconds and 5 git commands to generate.