]>
Dogcows Code - chaz/openbox/blob - scripts/motion.py
bf52bd9634698a7f5b5a87edfd12b5e87d77267d
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 _popwidget
.moveresize(otk
.Rect(x
, y
, size
.width(), size
.height()))
110 def _motion_grab(data
):
111 global _motion_mask
, _inmove
, _inresize
;
113 # are all the modifiers this started with still pressed?
114 if not _motion_mask
& data
.state
:
126 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
128 # get destination x/y for the *frame*
129 x
= _cx
+ _dx
+ _client
.frame
.area().x() - _client
.area().x()
130 y
= _cy
+ _dy
+ _client
.frame
.area().y() - _client
.area().y()
132 global _last_x
, _last_y
134 fs
= _client
.frame
.size()
135 w
= _client
.area().width() + fs
.left
+ fs
.right
136 h
= _client
.area().height() + fs
.top
+ fs
.bottom
137 # use the area based on the struts
138 area
= ob
.openbox
.screen(_screen
).area(_client
.desktop())
140 r
= area
.right() - w
+ 1
142 b
= area
.bottom() - h
+ 1
144 if _last_x
> x
and x
< l
and x
>= l
- EDGE_RESISTANCE
:
147 if _last_x
< x
and x
> r
and x
<= r
+ EDGE_RESISTANCE
:
150 if _last_y
> y
and y
< t
and y
>= t
- EDGE_RESISTANCE
:
153 if _last_y
< y
and y
> b
and y
<= b
+ EDGE_RESISTANCE
:
165 # draw the outline ...
168 _client
.move(x
, y
, final
)
172 text
= "X: " + str(x
) + " Y: " + str(y
)
174 _popwidget
= otk
.Label(_screen
, ob
.openbox
)
175 _popwidget
.setHighlighted(1)
176 _popwidget
.setText(text
)
181 if not data
.client
: return
183 # not-normal windows dont get moved
184 if not data
.client
.normal(): return
186 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
, _motion_mask
187 _screen
= data
.screen
188 _client
= data
.client
189 _cx
= data
.press_clientx
190 _cy
= data
.press_clienty
191 _dx
= data
.xroot
- data
.pressx
192 _dy
= data
.yroot
- data
.pressy
193 _motion_mask
= data
.state
197 ob
.kgrab(_screen
, _motion_grab
)
201 global MOVE_RUBBERBAND
202 global _inmove
, _popwidget
213 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
218 # pick a corner to anchor
219 if not (RESIZE_NEAREST
or _context
== ob
.MouseContext
.Grip
):
220 corner
= ob
.Client
.TopLeft
226 corner
= ob
.Client
.BottomRight
229 corner
= ob
.Client
.BottomLeft
233 corner
= ob
.Client
.TopRight
236 corner
= ob
.Client
.TopLeft
241 if RESIZE_RUBBERBAND
:
242 # draw the outline ...
245 _client
.resize(corner
, w
, h
)
249 ls
= _client
.logicalSize()
250 text
= "W: " + str(ls
.width()) + " H: " + str(ls
.height())
252 _popwidget
= otk
.Label(_screen
, ob
.openbox
)
253 _popwidget
.setHighlighted(1)
254 _popwidget
.setText(text
)
259 if not data
.client
: return
261 # not-normal windows dont get resized
262 if not data
.client
.normal(): return
264 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
266 _screen
= data
.screen
267 _client
= data
.client
268 _cx
= data
.press_clientx
269 _cy
= data
.press_clienty
270 _cw
= data
.press_clientwidth
271 _ch
= data
.press_clientheight
274 _dx
= data
.xroot
- _px
275 _dy
= data
.yroot
- _py
276 _motion_mask
= data
.state
280 ob
.kgrab(_screen
, _motion_grab
)
283 def _end_resize(data
):
284 global RESIZE_RUBBERBAND
, _inresize
287 r
= RESIZE_RUBBERBAND
288 RESIZE_RUBBERBAND
= 0
290 RESIZE_RUBBERBAND
= r
This page took 0.053968 seconds and 3 git commands to generate.