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 # move_popup - display a coordinates popup when moving windows. ###
12 # NOT IMPLEMENTED (yet?) ###
13 # move_rubberband - display an outline while moving instead of moving the ###
14 ### actual window, until the move is completed. Good for ###
15 ### slower systems. ###
16 move_rubberband = 0 ###
18 # resize_popup - display a size popup when resizing windows. ###
21 # NOT IMPLEMENTED (yet?) ###
22 # resize_rubberband - display an outline while resizing instead of ###
23 ### resizing the actual window, until the resize is ###
24 ### completed. Good for slower systems. ###
25 resize_rubberband = 0 ###
27 # resize_nearest - 1 to resize from the corner nearest where the mouse ###
28 ### is, 0 to resize always from the bottom right corner. ###
29 resize_nearest = 1 ###
34 # """Moves the window interactively. This should only be used with ###
35 # MouseMotion events. If move_popup or move_rubberband is enabled, ###
36 # then the end_move function needs to be bound as well.""" ###
37 # def end_move(data): ###
38 # """Complete the interactive move of a window.""" ###
39 # def resize(data): ###
40 # """Resizes the window interactively. This should only be used with ###
41 # MouseMotion events""" ###
42 # def end_resize(data): ###
43 # """Complete the interactive resize of a window.""" ###
45 #############################################################################
71 def _motion_grab(data):
72 global _motion_mask, _inmove, _inresize;
74 if data.action == ob.KeyAction.Release:
75 # have all the modifiers this started with been released?
76 if not _motion_mask & data.state:
85 global _screen, _client, _cx, _cy, _dx, _dy
90 global move_rubberband
92 # draw the outline ...
99 global _popwidget, _poplabel
100 style = ob.openbox.screen(_screen).style()
101 font = style.labelFont()
102 text = "X: " + str(x) + " Y: " + str(y)
103 length = font.measureString(text)
105 _popwidget = otk.Widget(ob.openbox, style,
106 otk.Widget.Horizontal, 0,
107 style.bevelWidth(), 1)
108 _popwidget.setTexture(style.titlebarFocusBackground())
109 _poplabel = otk.Label(_popwidget)
110 _poplabel.setTexture(style.labelFocusBackground())
112 _poplabel.fitString(text)
113 _poplabel.setText(text)
114 area = otk.display.screenInfo(_screen).rect()
116 _popwidget.move(area.x() + (area.width() -
117 _popwidget.width()) / 2,
118 area.y() + (area.height() -
119 _popwidget.height()) / 2)
122 """Moves the window interactively. This should only be used with
123 MouseMotion events. If move_popup or move_rubberband is enabled, then
124 the end_move function needs to be bound as well."""
125 if not data.client: return
127 # not-normal windows dont get moved
128 if not data.client.normal(): return
130 global _screen, _client, _cx, _cy, _dx, _dy
131 _screen = data.screen
132 _client = data.client
133 _cx = data.press_clientx
134 _cy = data.press_clienty
135 _dx = data.xroot - data.pressx
136 _dy = data.yroot - data.pressy
140 ob.kgrab(_screen, _motion_grab)
144 """Complete the interactive move of a window."""
145 global move_rubberband, _inmove
146 global _popwidget, _poplabel
158 global _screen, _client, _cx, _cy, _cw, _ch, _px, _py, _dx, _dy
163 # pick a corner to anchor
164 if not (resize_nearest or _context == ob.MouseContext.Grip):
165 corner = ob.Client.TopLeft
171 corner = ob.Client.BottomRight
174 corner = ob.Client.BottomLeft
178 corner = ob.Client.TopRight
181 corner = ob.Client.TopLeft
187 if resize_rubberband:
188 # draw the outline ...
191 _client.resize(corner, w, h)
195 global _popwidget, _poplabel
196 style = ob.openbox.screen(_screen).style()
197 ls = _client.logicalSize()
198 text = "W: " + str(ls.x()) + " H: " + str(ls.y())
200 _popwidget = otk.Widget(ob.openbox, style,
201 otk.Widget.Horizontal, 0,
202 style.bevelWidth(), 1)
203 _popwidget.setTexture(style.titlebarFocusBackground())
204 _poplabel = otk.Label(_popwidget)
205 _poplabel.setTexture(style.labelFocusBackground())
207 _poplabel.fitString(text)
208 _poplabel.setText(text)
209 area = otk.display.screenInfo(_screen).rect()
211 _popwidget.move(area.x() + (area.width() -
212 _popwidget.width()) / 2,
213 area.y() + (area.height() -
214 _popwidget.height()) / 2)
217 """Resizes the window interactively. This should only be used with
218 MouseMotion events"""
219 if not data.client: return
221 # not-normal windows dont get resized
222 if not data.client.normal(): return
224 global _screen, _client, _cx, _cy, _cw, _ch, _px, _py, _dx, _dy
225 _screen = data.screen
226 _client = data.client
227 _cx = data.press_clientx
228 _cy = data.press_clienty
229 _cw = data.press_clientwidth
230 _ch = data.press_clientheight
233 _dx = data.xroot - _px
234 _dy = data.yroot - _py
238 ob.kgrab(_screen, _motion_grab)
241 def end_resize(data):
242 """Complete the interactive resize of a window."""
243 global resize_rubberband, _inresize
244 global _popwidget, _poplabel
246 r = resize_rubberband
247 resize_rubberband = 0
249 resize_rubberband = r