]>
Dogcows Code - chaz/openbox/blob - scripts/motion.py
e0a1d3522fbe6c3e1cb9f55136157f1e272e79fc
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. ###
8 #############################################################################
10 """The amount of resistance to provide to moving a window past a screen
11 boundary. Specify a value of 0 to disable edge resistance."""
13 """Display a coordinates popup when moving windows."""
15 """NOT IMPLEMENTED (yet?)
16 Display an outline while moving instead of moving the actual window,
17 until the move is completed. Good for slower systems."""
19 """Display a size popup when resizing windows."""
21 """NOT IMPLEMENTED (yet?)
22 Display an outline while resizing instead of resizing the actual
23 window, until the resize is completed. Good for slower systems."""
25 """Non-zero to resize from the corner nearest where the mouse is, 0 to
26 resize always from the bottom right corner."""
27 #############################################################################
30 """Moves the window interactively. This should only be used with
31 MouseAction.Motion events. If MOVE_POPUP or MOVE_RUBBERBAND is enabled,
32 then the end_move function needs to be bound as well."""
36 """Complete the interactive move of a window."""
40 """Resizes the window interactively. This should only be used with
41 MouseMotion events. If RESIZE_POPUP or RESIZE_RUBBERBAND is enabled,
42 then the end_resize function needs to be bound as well."""
46 """Complete the interactive resize of a window."""
49 ###########################################################################
50 ###########################################################################
52 ###########################################################################
53 ### Internal stuff, should not be accessed outside the module. ###
54 ###########################################################################
80 def _motion_grab(data
):
81 global _motion_mask
, _inmove
, _inresize
;
83 if data
.action
== ob
.KeyAction
.Release
:
84 # have all the modifiers this started with been released?
85 if not _motion_mask
& data
.state
:
97 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
99 # get destination x/y for the *frame*
100 x
= _cx
+ _dx
+ _client
.frame
.area().x() - _client
.area().x()
101 y
= _cy
+ _dy
+ _client
.frame
.area().y() - _client
.area().y()
103 global _last_x
, _last_y
105 fs
= _client
.frame
.size()
106 w
= _client
.area().width() + fs
.left
+ fs
.right
107 h
= _client
.area().height() + fs
.top
+ fs
.bottom
108 # use the area based on the struts
109 area
= ob
.openbox
.screen(_screen
).area(_client
.desktop())
111 r
= area
.right() - w
+ 1
113 b
= area
.bottom() - h
+ 1
115 if _last_x
> x
and x
< l
and x
>= l
- EDGE_RESISTANCE
:
118 if _last_x
< x
and x
> r
and x
<= r
+ EDGE_RESISTANCE
:
121 if _last_y
> y
and y
< t
and y
>= t
- EDGE_RESISTANCE
:
124 if _last_y
< y
and y
> b
and y
<= b
+ EDGE_RESISTANCE
:
136 # draw the outline ...
142 global _popwidget
, _poplabel
143 text
= "X: " + str(x
) + " Y: " + str(y
)
145 _popwidget
= otk
.Widget(_screen
, ob
.openbox
,
146 otk
.Widget
.Horizontal
, 0, 1)
147 _poplabel
= otk
.Label(_popwidget
)
148 _poplabel
.setHighlighted(1)
149 _poplabel
.setText(text
)
150 scsize
= otk
.display
.screenInfo(_screen
).size()
151 size
= _poplabel
.minSize()
152 _popwidget
.moveresize(otk
.Rect((scsize
.width() - size
.width()) / 2,
153 (scsize
.height() - size
.height()) / 2,
154 size
.width(), size
.height()))
158 if not data
.client
: return
160 # not-normal windows dont get moved
161 if not data
.client
.normal(): return
163 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
164 _screen
= data
.screen
165 _client
= data
.client
166 _cx
= data
.press_clientx
167 _cy
= data
.press_clienty
168 _dx
= data
.xroot
- data
.pressx
169 _dy
= data
.yroot
- data
.pressy
173 ob
.kgrab(_screen
, _motion_grab
)
177 global MOVE_RUBBERBAND
178 global _inmove
, _popwidget
, _poplabel
190 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
195 # pick a corner to anchor
196 if not (RESIZE_NEAREST
or _context
== ob
.MouseContext
.Grip
):
197 corner
= ob
.Client
.TopLeft
203 corner
= ob
.Client
.BottomRight
206 corner
= ob
.Client
.BottomLeft
210 corner
= ob
.Client
.TopRight
213 corner
= ob
.Client
.TopLeft
218 if RESIZE_RUBBERBAND
:
219 # draw the outline ...
222 _client
.resize(corner
, w
, h
)
225 global _popwidget
, _poplabel
226 ls
= _client
.logicalSize()
227 text
= "W: " + str(ls
.width()) + " H: " + str(ls
.height())
229 _popwidget
= otk
.Widget(_screen
, ob
.openbox
,
230 otk
.Widget
.Horizontal
, 0, 1)
231 _poplabel
= otk
.Label(_popwidget
)
232 _poplabel
.setHighlighted(1)
233 _poplabel
.setText(text
)
234 scsize
= otk
.display
.screenInfo(_screen
).size()
235 size
= _poplabel
.minSize()
236 _popwidget
.moveresize(otk
.Rect((scsize
.width() - size
.width()) / 2,
237 (scsize
.height() - size
.height()) / 2,
238 size
.width(), size
.height()))
242 if not data
.client
: return
244 # not-normal windows dont get resized
245 if not data
.client
.normal(): return
247 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
248 _screen
= data
.screen
249 _client
= data
.client
250 _cx
= data
.press_clientx
251 _cy
= data
.press_clienty
252 _cw
= data
.press_clientwidth
253 _ch
= data
.press_clientheight
256 _dx
= data
.xroot
- _px
257 _dy
= data
.yroot
- _py
261 ob
.kgrab(_screen
, _motion_grab
)
264 def _end_resize(data
):
265 global RESIZE_RUBBERBAND
, _inresize
266 global _popwidget
, _poplabel
268 r
= RESIZE_RUBBERBAND
269 RESIZE_RUBBERBAND
= 0
271 RESIZE_RUBBERBAND
= r
This page took 0.049243 seconds and 4 git commands to generate.