]>
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 ...
137 print "moving " + str(x
) + " " + str(y
)
138 _client
.move(x
, y
, 1) # move the *frame*
142 global _popwidget
, _poplabel
143 style
= ob
.openbox
.screen(_screen
).style()
144 font
= style
.labelFont()
145 text
= "X: " + str(x
) + " Y: " + str(y
)
146 length
= font
.measureString(text
)
148 _popwidget
= otk
.Widget(ob
.openbox
, style
,
149 otk
.Widget
.Horizontal
, 0,
150 style
.bevelWidth(), 1)
151 _popwidget
.setTexture(style
.titlebarFocusBackground())
152 _poplabel
= otk
.Label(_popwidget
)
153 _poplabel
.setTexture(style
.labelFocusBackground())
154 _poplabel
.fitString(text
)
155 _poplabel
.setText(text
)
157 area
= otk
.display
.screenInfo(_screen
).rect()
158 _popwidget
.move(area
.x() + (area
.width() -
159 _popwidget
.width()) / 2,
160 area
.y() + (area
.height() -
161 _popwidget
.height()) / 2)
165 """Moves the window interactively. This should only be used with
166 MouseMotion events. If move_popup or move_rubberband is enabled, then
167 the end_move function needs to be bound as well."""
168 if not data
.client
: return
170 # not-normal windows dont get moved
171 if not data
.client
.normal(): return
173 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
174 _screen
= data
.screen
175 _client
= data
.client
176 _cx
= data
.press_clientx
177 _cy
= data
.press_clienty
178 _dx
= data
.xroot
- data
.pressx
179 _dy
= data
.yroot
- data
.pressy
183 ob
.kgrab(_screen
, _motion_grab
)
187 """Complete the interactive move of a window."""
188 global move_rubberband
, _inmove
189 global _popwidget
, _poplabel
201 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
206 # pick a corner to anchor
207 if not (resize_nearest
or _context
== ob
.MouseContext
.Grip
):
208 corner
= ob
.Client
.TopLeft
214 corner
= ob
.Client
.BottomRight
217 corner
= ob
.Client
.BottomLeft
221 corner
= ob
.Client
.TopRight
224 corner
= ob
.Client
.TopLeft
230 if resize_rubberband
:
231 # draw the outline ...
234 _client
.resize(corner
, w
, h
)
238 global _popwidget
, _poplabel
239 style
= ob
.openbox
.screen(_screen
).style()
240 ls
= _client
.logicalSize()
241 text
= "W: " + str(ls
.x()) + " H: " + str(ls
.y())
243 _popwidget
= otk
.Widget(ob
.openbox
, style
,
244 otk
.Widget
.Horizontal
, 0,
245 style
.bevelWidth(), 1)
246 _popwidget
.setTexture(style
.titlebarFocusBackground())
247 _poplabel
= otk
.Label(_popwidget
)
248 _poplabel
.setTexture(style
.labelFocusBackground())
249 _poplabel
.fitString(text
)
250 _poplabel
.setText(text
)
251 area
= otk
.display
.screenInfo(_screen
).rect()
253 _popwidget
.move(area
.x() + (area
.width() -
254 _popwidget
.width()) / 2,
255 area
.y() + (area
.height() -
256 _popwidget
.height()) / 2)
260 """Resizes the window interactively. This should only be used with
261 MouseMotion events"""
262 if not data
.client
: return
264 # not-normal windows dont get resized
265 if not data
.client
.normal(): return
267 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
268 _screen
= data
.screen
269 _client
= data
.client
270 _cx
= data
.press_clientx
271 _cy
= data
.press_clienty
272 _cw
= data
.press_clientwidth
273 _ch
= data
.press_clientheight
276 _dx
= data
.xroot
- _px
277 _dy
= data
.yroot
- _py
281 ob
.kgrab(_screen
, _motion_grab
)
284 def end_resize(data
):
285 """Complete the interactive resize of a window."""
286 global resize_rubberband
, _inresize
287 global _popwidget
, _poplabel
289 r
= resize_rubberband
290 resize_rubberband
= 0
292 resize_rubberband
= r
This page took 0.054721 seconds and 5 git commands to generate.