1 ############################################################################
2 ### Functions that provide callbacks for motion events to move and ###
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 ###
31 #############################################################################
57 def _motion_grab(data):
58 global _motion_mask, _inmove, _inresize;
60 if data.action == ob.KeyAction.Release:
61 # have all the modifiers this started with been released?
62 if not _motion_mask & data.state:
71 global _screen, _client, _cx, _cy, _dx, _dy
76 global move_rubberband
78 # draw the outline ...
85 global _popwidget, _poplabel
86 style = ob.openbox.screen(_screen).style()
87 font = style.labelFont()
88 text = "X: " + str(x) + " Y: " + str(y)
89 length = font.measureString(text)
91 _popwidget = otk.Widget(ob.openbox, style,
92 otk.Widget.Horizontal, 0,
93 style.bevelWidth(), 1)
94 _popwidget.setTexture(style.titlebarFocusBackground())
95 _poplabel = otk.Label(_popwidget)
96 _poplabel.setTexture(style.labelFocusBackground())
98 _poplabel.resize(length, font.height())
99 _poplabel.setText(text)
100 area = otk.display.screenInfo(_screen).rect()
102 _popwidget.move(area.x() + (area.width() -
103 _popwidget.width()) / 2,
104 area.y() + (area.height() -
105 _popwidget.height()) / 2)
108 """Moves the window interactively. This should only be used with
109 MouseMotion events. If move_popup or move_rubberband is enabled, then
110 the end_move function needs to be bound as well."""
111 if not data.client: return
113 # not-normal windows dont get moved
114 if not data.client.normal(): return
116 global _screen, _client, _cx, _cy, _dx, _dy
117 _screen = data.screen
118 _client = data.client
119 _cx = data.press_clientx
120 _cy = data.press_clienty
121 _dx = data.xroot - data.pressx
122 _dy = data.yroot - data.pressy
126 ob.kgrab(_screen, _motion_grab)
130 """Complete the interactive move of a window."""
131 global move_rubberband, _inmove
132 global _popwidget, _poplabel
144 global _screen, _client, _cx, _cy, _cw, _ch, _px, _py, _dx, _dy
146 # pick a corner to anchor
147 if not (resize_nearest or _context == ob.MouseContext.Grip):
148 corner = ob.Client.TopLeft
154 corner = ob.Client.BottomRight
157 corner = ob.Client.BottomLeft
161 corner = ob.Client.TopRight
164 corner = ob.Client.TopLeft
170 if resize_rubberband:
171 # draw the outline ...
174 _client.resize(corner, w, h)
178 global _popwidget, _poplabel
179 style = ob.openbox.screen(_screen).style()
180 ls = _client.logicalSize()
181 text = "W: " + str(ls.x()) + " H: " + str(ls.y())
183 _popwidget = otk.Widget(ob.openbox, style,
184 otk.Widget.Horizontal, 0,
185 style.bevelWidth(), 1)
186 _popwidget.setTexture(style.titlebarFocusBackground())
187 _poplabel = otk.Label(_popwidget)
188 _poplabel.setTexture(style.labelFocusBackground())
190 _poplabel.fitString(text)
191 _poplabel.setText(text)
192 area = otk.display.screenInfo(_screen).rect()
194 _popwidget.move(area.x() + (area.width() -
195 _popwidget.width()) / 2,
196 area.y() + (area.height() -
197 _popwidget.height()) / 2)
200 """Resizes the window interactively. This should only be used with
201 MouseMotion events"""
202 if not data.client: return
204 # not-normal windows dont get resized
205 if not data.client.normal(): return
207 global _screen, _client, _cx, _cy, _cw, _ch, _px, _py, _dx, _dy
208 _screen = data.screen
209 _client = data.client
210 _cx = data.press_clientx
211 _cy = data.press_clienty
212 _cw = data.press_clientwidth
213 _ch = data.press_clientheight
216 _dx = data.xroot - _px
217 _dy = data.yroot - _py
221 ob.kgrab(_screen, _motion_grab)
224 def end_resize(data):
225 """Complete the interactive resize of a window."""
226 global resize_rubberband, _inresize
227 global _popwidget, _poplabel
229 r = resize_rubberband
230 resize_rubberband = 0
232 resize_rubberband = r