]>
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 # snap - snap windows to other windows and screen edges while moving them ###
12 # move_popup - display a coordinates popup when moving windows. ###
15 # NOT IMPLEMENTED (yet?) ###
16 # move_rubberband - display an outline while moving instead of moving the ###
17 ### actual window, until the move is completed. Good for ###
18 ### slower systems. ###
19 move_rubberband
= 0 ###
21 # resize_popup - display a size popup when resizing windows. ###
24 # NOT IMPLEMENTED (yet?) ###
25 # resize_rubberband - display an outline while resizing instead of ###
26 ### resizing the actual window, until the resize is ###
27 ### completed. Good for slower systems. ###
28 resize_rubberband
= 0 ###
30 # resize_nearest - 1 to resize from the corner nearest where the mouse ###
31 ### is, 0 to resize always from the bottom right corner. ###
32 resize_nearest
= 1 ###
37 # """Moves the window interactively. This should only be used with ###
38 # MouseMotion events. If move_popup or move_rubberband is enabled, ###
39 # then the end_move function needs to be bound as well.""" ###
40 # def end_move(data): ###
41 # """Complete the interactive move of a window.""" ###
42 # def resize(data): ###
43 # """Resizes the window interactively. This should only be used with ###
44 # MouseMotion events""" ###
45 # def end_resize(data): ###
46 # """Complete the interactive resize of a window.""" ###
48 #############################################################################
74 def _motion_grab(data
):
75 global _motion_mask
, _inmove
, _inresize
;
77 if data
.action
== ob
.KeyAction
.Release
:
78 # have all the modifiers this started with been released?
79 if not _motion_mask
& data
.state
:
88 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
97 global move_rubberband
99 # draw the outline ...
106 global _popwidget
, _poplabel
107 style
= ob
.openbox
.screen(_screen
).style()
108 font
= style
.labelFont()
109 text
= "X: " + str(x
) + " Y: " + str(y
)
110 length
= font
.measureString(text
)
112 _popwidget
= otk
.Widget(ob
.openbox
, style
,
113 otk
.Widget
.Horizontal
, 0,
114 style
.bevelWidth(), 1)
115 _popwidget
.setTexture(style
.titlebarFocusBackground())
116 _poplabel
= otk
.Label(_popwidget
)
117 _poplabel
.setTexture(style
.labelFocusBackground())
119 _poplabel
.fitString(text
)
120 _poplabel
.setText(text
)
121 area
= otk
.display
.screenInfo(_screen
).rect()
123 _popwidget
.move(area
.x() + (area
.width() -
124 _popwidget
.width()) / 2,
125 area
.y() + (area
.height() -
126 _popwidget
.height()) / 2)
129 """Moves the window interactively. This should only be used with
130 MouseMotion events. If move_popup or move_rubberband is enabled, then
131 the end_move function needs to be bound as well."""
132 if not data
.client
: return
134 # not-normal windows dont get moved
135 if not data
.client
.normal(): return
137 global _screen
, _client
, _cx
, _cy
, _dx
, _dy
138 _screen
= data
.screen
139 _client
= data
.client
140 _cx
= data
.press_clientx
141 _cy
= data
.press_clienty
142 _dx
= data
.xroot
- data
.pressx
143 _dy
= data
.yroot
- data
.pressy
147 ob
.kgrab(_screen
, _motion_grab
)
151 """Complete the interactive move of a window."""
152 global move_rubberband
, _inmove
153 global _popwidget
, _poplabel
165 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
170 # pick a corner to anchor
171 if not (resize_nearest
or _context
== ob
.MouseContext
.Grip
):
172 corner
= ob
.Client
.TopLeft
178 corner
= ob
.Client
.BottomRight
181 corner
= ob
.Client
.BottomLeft
185 corner
= ob
.Client
.TopRight
188 corner
= ob
.Client
.TopLeft
194 if resize_rubberband
:
195 # draw the outline ...
198 _client
.resize(corner
, w
, h
)
202 global _popwidget
, _poplabel
203 style
= ob
.openbox
.screen(_screen
).style()
204 ls
= _client
.logicalSize()
205 text
= "W: " + str(ls
.x()) + " H: " + str(ls
.y())
207 _popwidget
= otk
.Widget(ob
.openbox
, style
,
208 otk
.Widget
.Horizontal
, 0,
209 style
.bevelWidth(), 1)
210 _popwidget
.setTexture(style
.titlebarFocusBackground())
211 _poplabel
= otk
.Label(_popwidget
)
212 _poplabel
.setTexture(style
.labelFocusBackground())
214 _poplabel
.fitString(text
)
215 _poplabel
.setText(text
)
216 area
= otk
.display
.screenInfo(_screen
).rect()
218 _popwidget
.move(area
.x() + (area
.width() -
219 _popwidget
.width()) / 2,
220 area
.y() + (area
.height() -
221 _popwidget
.height()) / 2)
224 """Resizes the window interactively. This should only be used with
225 MouseMotion events"""
226 if not data
.client
: return
228 # not-normal windows dont get resized
229 if not data
.client
.normal(): return
231 global _screen
, _client
, _cx
, _cy
, _cw
, _ch
, _px
, _py
, _dx
, _dy
232 _screen
= data
.screen
233 _client
= data
.client
234 _cx
= data
.press_clientx
235 _cy
= data
.press_clienty
236 _cw
= data
.press_clientwidth
237 _ch
= data
.press_clientheight
240 _dx
= data
.xroot
- _px
241 _dy
= data
.yroot
- _py
245 ob
.kgrab(_screen
, _motion_grab
)
248 def end_resize(data
):
249 """Complete the interactive resize of a window."""
250 global resize_rubberband
, _inresize
251 global _popwidget
, _poplabel
253 r
= resize_rubberband
254 resize_rubberband
= 0
256 resize_rubberband
= r
This page took 0.048001 seconds and 5 git commands to generate.