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:
93 global _screen, _client, _cx, _cy, _dx, _dy
98 global edge_resistance
99 global _last_x, _last_y
101 fs = _client.frame.size()
102 w = _client.area().width() + fs.left + fs.right
103 h = _client.area().height() + fs.top + fs.bottom
104 # use the area based on the struts
105 area = ob.openbox.screen(_screen).area()
107 r = area.right() - w + 1
109 b = area.bottom() - h + 1
111 if _last_x > x and x < l and x >= l - edge_resistance:
114 if _last_x < x and x > r and x <= r + edge_resistance:
117 if _last_y > y and y < t and y >= t - edge_resistance:
120 if _last_y < y and y > b and y <= b + edge_resistance:
131 global move_rubberband
133 # draw the outline ...
140 global _popwidget, _poplabel
141 style = ob.openbox.screen(_screen).style()
142 font = style.labelFont()
143 text = "X: " + str(x) + " Y: " + str(y)
144 length = font.measureString(text)
146 _popwidget = otk.Widget(ob.openbox, style,
147 otk.Widget.Horizontal, 0,
148 style.bevelWidth(), 1)
149 _popwidget.setTexture(style.titlebarFocusBackground())
150 _poplabel = otk.Label(_popwidget)
151 _poplabel.setTexture(style.labelFocusBackground())
152 _poplabel.fitString(text)
153 _poplabel.setText(text)
155 area = otk.display.screenInfo(_screen).rect()
156 _popwidget.move(area.x() + (area.width() -
157 _popwidget.width()) / 2,
158 area.y() + (area.height() -
159 _popwidget.height()) / 2)
163 """Moves the window interactively. This should only be used with
164 MouseMotion events. If move_popup or move_rubberband is enabled, then
165 the end_move function needs to be bound as well."""
166 if not data.client: return
168 # not-normal windows dont get moved
169 if not data.client.normal(): return
171 global _screen, _client, _cx, _cy, _dx, _dy
172 _screen = data.screen
173 _client = data.client
174 _cx = data.press_clientx
175 _cy = data.press_clienty
176 _dx = data.xroot - data.pressx
177 _dy = data.yroot - data.pressy
181 ob.kgrab(_screen, _motion_grab)
185 """Complete the interactive move of a window."""
186 global move_rubberband, _inmove
187 global _popwidget, _poplabel
199 global _screen, _client, _cx, _cy, _cw, _ch, _px, _py, _dx, _dy
204 # pick a corner to anchor
205 if not (resize_nearest or _context == ob.MouseContext.Grip):
206 corner = ob.Client.TopLeft
212 corner = ob.Client.BottomRight
215 corner = ob.Client.BottomLeft
219 corner = ob.Client.TopRight
222 corner = ob.Client.TopLeft
228 if resize_rubberband:
229 # draw the outline ...
232 _client.resize(corner, w, h)
236 global _popwidget, _poplabel
237 style = ob.openbox.screen(_screen).style()
238 ls = _client.logicalSize()
239 text = "W: " + str(ls.x()) + " H: " + str(ls.y())
241 _popwidget = otk.Widget(ob.openbox, style,
242 otk.Widget.Horizontal, 0,
243 style.bevelWidth(), 1)
244 _popwidget.setTexture(style.titlebarFocusBackground())
245 _poplabel = otk.Label(_popwidget)
246 _poplabel.setTexture(style.labelFocusBackground())
247 _poplabel.fitString(text)
248 _poplabel.setText(text)
249 area = otk.display.screenInfo(_screen).rect()
251 _popwidget.move(area.x() + (area.width() -
252 _popwidget.width()) / 2,
253 area.y() + (area.height() -
254 _popwidget.height()) / 2)
258 """Resizes the window interactively. This should only be used with
259 MouseMotion events"""
260 if not data.client: return
262 # not-normal windows dont get resized
263 if not data.client.normal(): return
265 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
279 ob.kgrab(_screen, _motion_grab)
282 def end_resize(data):
283 """Complete the interactive resize of a window."""
284 global resize_rubberband, _inresize
285 global _popwidget, _poplabel
287 r = resize_rubberband
288 resize_rubberband = 0
290 resize_rubberband = r