]>
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. ###
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 """When this is non-zero, the coordinates popups will be placed relative to
14 the window being moved/resized. When zero, they will appear relative to the
17 """When this is non-zero, the coordinates popups will be centered relative to
18 the window or screen (see POPUP_IN_WINDOW). When zero, they will be placed
19 at based upon POPUP_COORDS."""
21 """When POPUP_CENTERED is zero, these coordinates will be used to place the
22 coordinates popup. The popup will be placed relative to the window or the
23 screen (see POPUP_IN_WINDOW). A value of 0, 0 would place it in the top
24 left corner, while a value of -1, -1 would place it in the bottom right.
25 These values behave simmilarly to those passed to the -geometry flag of many
28 """Display a coordinates popup when moving windows."""
30 """NOT IMPLEMENTED (yet?)
31 Display an outline while moving instead of moving the actual window,
32 until the move is completed. Good for slower systems."""
34 """Display a size popup when resizing windows."""
36 """NOT IMPLEMENTED (yet?)
37 Display an outline while resizing instead of resizing the actual
38 window, until the resize is completed. Good for slower systems."""
40 """Non-zero to resize from the corner nearest where the mouse is, 0 to
41 resize always from the bottom right corner."""
42 #############################################################################
45 """Moves the window interactively. This should only be used with
46 MouseAction.Motion events. If MOVE_POPUP or MOVE_RUBBERBAND is enabled,
47 then the end_move function needs to be bound as well."""
51 """Complete the interactive move of a window."""
55 """Resizes the window interactively. This should only be used with
56 MouseMotion events. If RESIZE_POPUP or RESIZE_RUBBERBAND is enabled,
57 then the end_resize function needs to be bound as well."""
61 """Complete the interactive resize of a window."""
64 ###########################################################################
65 ###########################################################################
67 ###########################################################################
68 ### Internal stuff, should not be accessed outside the module. ###
69 ###########################################################################
96 area
= _client
.frame
.area()
98 area
= otk
.Rect(otk
.Point(0, 0), ob
.openbox
.screen(_screen
).size())
99 size
= _popwidget
.minSize()
101 x
= area
.position().x() + (area
.size().width() - size
.width()) / 2
102 y
= area
.position().y() + (area
.size().height() - size
.height()) / 2
104 try: x
, y
= POPUP_COORDS
106 if x
< 0: x
+= area
.right() - size
.width() + 2
107 if y
< 0: y
+= area
.bottom() - size
.height() + 2
108 x
+= area
.position().x()
109 y
+= area
.position().y()
110 _popwidget
.moveresize(otk
.Rect(x
, y
, size
.width(), size
.height()))
112 def _motion_grab(data
):
113 global _motion_mask
, _inmove
, _inresize
;
115 # are all the modifiers this started with still pressed?
116 if not _motion_mask
& data
.state
:
128 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
130 # get destination x/y for the *frame*
131 x
= _cx
+ _dx
+ _client
.frame
.area().x() - _client
.area().x()
132 y
= _cy
+ _dy
+ _client
.frame
.area().y() - _client
.area().y()
134 global _last_x
, _last_y
136 fs
= _client
.frame
.size()
137 w
= _client
.area().width() + fs
.left
+ fs
.right
138 h
= _client
.area().height() + fs
.top
+ fs
.bottom
139 # use the area based on the struts
140 area
= ob
.openbox
.screen(_screen
).area(_client
.desktop())
142 r
= area
.right() - w
+ 1
144 b
= area
.bottom() - h
+ 1
146 if _last_x
> x
and x
< l
and x
>= l
- EDGE_RESISTANCE
:
149 if _last_x
< x
and x
> r
and x
<= r
+ EDGE_RESISTANCE
:
152 if _last_y
> y
and y
< t
and y
>= t
- EDGE_RESISTANCE
:
155 if _last_y
< y
and y
> b
and y
<= b
+ EDGE_RESISTANCE
:
167 # draw the outline ...
170 _client
.move(x
, y
, final
)
174 text
= "X: " + str(x
) + " Y: " + str(y
)
176 _popwidget
= otk
.Label(_screen
, ob
.openbox
)
177 _popwidget
.setHighlighted(1)
178 _popwidget
.setText(text
)
183 if not data
.client
: return
185 # not-normal windows dont get moved
186 if not data
.client
.normal(): return
188 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
, _motion_mask
189 _screen
= data
.screen
190 _client
= data
.client
191 _cx
= data
.press_clientx
192 _cy
= data
.press_clienty
193 _dx
= data
.xroot
- data
.pressx
194 _dy
= data
.yroot
- data
.pressy
195 _motion_mask
= data
.state
199 ob
.kgrab(_screen
, _motion_grab
)
203 global MOVE_RUBBERBAND
204 global _inmove
, _popwidget
215 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
220 # pick a corner to anchor
221 if not (RESIZE_NEAREST
or _context
== ob
.MouseContext
.Grip
):
222 corner
= ob
.Client
.TopLeft
228 corner
= ob
.Client
.BottomRight
231 corner
= ob
.Client
.BottomLeft
235 corner
= ob
.Client
.TopRight
238 corner
= ob
.Client
.TopLeft
243 if RESIZE_RUBBERBAND
:
244 # draw the outline ...
247 _client
.resize(corner
, w
, h
)
251 ls
= _client
.logicalSize()
252 text
= "W: " + str(ls
.width()) + " H: " + str(ls
.height())
254 _popwidget
= otk
.Label(_screen
, ob
.openbox
)
255 _popwidget
.setHighlighted(1)
256 _popwidget
.setText(text
)
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
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
278 _motion_mask
= data
.state
282 ob
.kgrab(_screen
, _motion_grab
)
285 def _end_resize(data
):
286 global RESIZE_RUBBERBAND
, _inresize
289 r
= RESIZE_RUBBERBAND
290 RESIZE_RUBBERBAND
= 0
292 RESIZE_RUBBERBAND
= r
This page took 0.049871 seconds and 5 git commands to generate.