]>
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
:
90 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
95 global edge_resistance
97 fs
= _client
.frame
.size()
98 w
= _client
.area().width() + fs
.left
+ fs
.right
99 h
= _client
.area().height() + fs
.top
+ fs
.bottom
100 # use the area based on the struts
101 area
= ob
.openbox
.screen(_screen
).area()
105 b
= area
.bottom() - h
107 if x
< l
and x
>= l
- edge_resistance
:
110 if x
> r
and x
<= r
+ edge_resistance
:
113 if y
< t
and y
>= t
- edge_resistance
:
116 if y
> b
and y
<= b
+ edge_resistance
:
119 global move_rubberband
121 # draw the outline ...
128 global _popwidget
, _poplabel
129 style
= ob
.openbox
.screen(_screen
).style()
130 font
= style
.labelFont()
131 text
= "X: " + str(x
) + " Y: " + str(y
)
132 length
= font
.measureString(text
)
134 _popwidget
= otk
.Widget(ob
.openbox
, style
,
135 otk
.Widget
.Horizontal
, 0,
136 style
.bevelWidth(), 1)
137 _popwidget
.setTexture(style
.titlebarFocusBackground())
138 _poplabel
= otk
.Label(_popwidget
)
139 _poplabel
.setTexture(style
.labelFocusBackground())
140 _poplabel
.fitString(text
)
141 _poplabel
.setText(text
)
143 area
= otk
.display
.screenInfo(_screen
).rect()
144 _popwidget
.move(area
.x() + (area
.width() -
145 _popwidget
.width()) / 2,
146 area
.y() + (area
.height() -
147 _popwidget
.height()) / 2)
151 """Moves the window interactively. This should only be used with
152 MouseMotion events. If move_popup or move_rubberband is enabled, then
153 the end_move function needs to be bound as well."""
154 if not data
.client
: return
156 # not-normal windows dont get moved
157 if not data
.client
.normal(): return
159 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
160 _screen
= data
.screen
161 _client
= data
.client
162 _cx
= data
.press_clientx
163 _cy
= data
.press_clienty
164 _dx
= data
.xroot
- data
.pressx
165 _dy
= data
.yroot
- data
.pressy
169 ob
.kgrab(_screen
, _motion_grab
)
173 """Complete the interactive move of a window."""
174 global move_rubberband
, _inmove
175 global _popwidget
, _poplabel
187 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
192 # pick a corner to anchor
193 if not (resize_nearest
or _context
== ob
.MouseContext
.Grip
):
194 corner
= ob
.Client
.TopLeft
200 corner
= ob
.Client
.BottomRight
203 corner
= ob
.Client
.BottomLeft
207 corner
= ob
.Client
.TopRight
210 corner
= ob
.Client
.TopLeft
216 if resize_rubberband
:
217 # draw the outline ...
220 _client
.resize(corner
, w
, h
)
224 global _popwidget
, _poplabel
225 style
= ob
.openbox
.screen(_screen
).style()
226 ls
= _client
.logicalSize()
227 text
= "W: " + str(ls
.x()) + " H: " + str(ls
.y())
229 _popwidget
= otk
.Widget(ob
.openbox
, style
,
230 otk
.Widget
.Horizontal
, 0,
231 style
.bevelWidth(), 1)
232 _popwidget
.setTexture(style
.titlebarFocusBackground())
233 _poplabel
= otk
.Label(_popwidget
)
234 _poplabel
.setTexture(style
.labelFocusBackground())
235 _poplabel
.fitString(text
)
236 _poplabel
.setText(text
)
237 area
= otk
.display
.screenInfo(_screen
).rect()
239 _popwidget
.move(area
.x() + (area
.width() -
240 _popwidget
.width()) / 2,
241 area
.y() + (area
.height() -
242 _popwidget
.height()) / 2)
246 """Resizes the window interactively. This should only be used with
247 MouseMotion events"""
248 if not data
.client
: return
250 # not-normal windows dont get resized
251 if not data
.client
.normal(): return
253 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
254 _screen
= data
.screen
255 _client
= data
.client
256 _cx
= data
.press_clientx
257 _cy
= data
.press_clienty
258 _cw
= data
.press_clientwidth
259 _ch
= data
.press_clientheight
262 _dx
= data
.xroot
- _px
263 _dy
= data
.yroot
- _py
267 ob
.kgrab(_screen
, _motion_grab
)
270 def end_resize(data
):
271 """Complete the interactive resize of a window."""
272 global resize_rubberband
, _inresize
273 global _popwidget
, _poplabel
275 r
= resize_rubberband
276 resize_rubberband
= 0
278 resize_rubberband
= r
This page took 0.051486 seconds and 4 git commands to generate.