]>
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
95 # get destination x/y for the *frame*
96 x
= _cx
+ _dx
+ _client
.frame
.rect().x() - _client
.area().x()
97 y
= _cy
+ _dy
+ _client
.frame
.rect().y() - _client
.area().y()
99 global edge_resistance
100 global _last_x
, _last_y
102 fs
= _client
.frame
.size()
103 w
= _client
.area().width() + fs
.left
+ fs
.right
104 h
= _client
.area().height() + fs
.top
+ fs
.bottom
105 # use the area based on the struts
106 area
= ob
.openbox
.screen(_screen
).area()
108 r
= area
.right() - w
+ 1
110 b
= area
.bottom() - h
+ 1
112 if _last_x
> x
and x
< l
and x
>= l
- edge_resistance
:
115 if _last_x
< x
and x
> r
and x
<= r
+ edge_resistance
:
118 if _last_y
> y
and y
< t
and y
>= t
- edge_resistance
:
121 if _last_y
< y
and y
> b
and y
<= b
+ edge_resistance
:
132 global move_rubberband
134 # draw the outline ...
141 global _popwidget
, _poplabel
142 style
= ob
.openbox
.screen(_screen
).style()
143 font
= style
.labelFont()
144 text
= "X: " + str(x
) + " Y: " + str(y
)
145 length
= font
.measureString(text
)
147 _popwidget
= otk
.Widget(ob
.openbox
, style
,
148 otk
.Widget
.Horizontal
, 0,
149 style
.bevelWidth(), 1)
150 _popwidget
.setTexture(style
.titlebarFocusBackground())
151 _poplabel
= otk
.Label(_popwidget
)
152 _poplabel
.setTexture(style
.labelFocusBackground())
153 _poplabel
.fitString(text
)
154 _poplabel
.setText(text
)
156 area
= otk
.display
.screenInfo(_screen
).rect()
157 _popwidget
.move(area
.x() + (area
.width() -
158 _popwidget
.width()) / 2,
159 area
.y() + (area
.height() -
160 _popwidget
.height()) / 2)
164 """Moves the window interactively. This should only be used with
165 MouseMotion events. If move_popup or move_rubberband is enabled, then
166 the end_move function needs to be bound as well."""
167 if not data
.client
: return
169 # not-normal windows dont get moved
170 if not data
.client
.normal(): return
172 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
173 _screen
= data
.screen
174 _client
= data
.client
175 _cx
= data
.press_clientx
176 _cy
= data
.press_clienty
177 _dx
= data
.xroot
- data
.pressx
178 _dy
= data
.yroot
- data
.pressy
182 ob
.kgrab(_screen
, _motion_grab
)
186 """Complete the interactive move of a window."""
187 global move_rubberband
, _inmove
188 global _popwidget
, _poplabel
200 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
205 # pick a corner to anchor
206 if not (resize_nearest
or _context
== ob
.MouseContext
.Grip
):
207 corner
= ob
.Client
.TopLeft
213 corner
= ob
.Client
.BottomRight
216 corner
= ob
.Client
.BottomLeft
220 corner
= ob
.Client
.TopRight
223 corner
= ob
.Client
.TopLeft
229 if resize_rubberband
:
230 # draw the outline ...
233 _client
.resize(corner
, w
, h
)
237 global _popwidget
, _poplabel
238 style
= ob
.openbox
.screen(_screen
).style()
239 ls
= _client
.logicalSize()
240 text
= "W: " + str(ls
.x()) + " H: " + str(ls
.y())
242 _popwidget
= otk
.Widget(ob
.openbox
, style
,
243 otk
.Widget
.Horizontal
, 0,
244 style
.bevelWidth(), 1)
245 _popwidget
.setTexture(style
.titlebarFocusBackground())
246 _poplabel
= otk
.Label(_popwidget
)
247 _poplabel
.setTexture(style
.labelFocusBackground())
248 _poplabel
.fitString(text
)
249 _poplabel
.setText(text
)
250 area
= otk
.display
.screenInfo(_screen
).rect()
252 _popwidget
.move(area
.x() + (area
.width() -
253 _popwidget
.width()) / 2,
254 area
.y() + (area
.height() -
255 _popwidget
.height()) / 2)
259 """Resizes the window interactively. This should only be used with
260 MouseMotion events"""
261 if not data
.client
: return
263 # not-normal windows dont get resized
264 if not data
.client
.normal(): return
266 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
267 _screen
= data
.screen
268 _client
= data
.client
269 _cx
= data
.press_clientx
270 _cy
= data
.press_clienty
271 _cw
= data
.press_clientwidth
272 _ch
= data
.press_clientheight
275 _dx
= data
.xroot
- _px
276 _dy
= data
.yroot
- _py
280 ob
.kgrab(_screen
, _motion_grab
)
283 def end_resize(data
):
284 """Complete the interactive resize of a window."""
285 global resize_rubberband
, _inresize
286 global _popwidget
, _poplabel
288 r
= resize_rubberband
289 resize_rubberband
= 0
291 resize_rubberband
= r
This page took 0.049434 seconds and 5 git commands to generate.