2 #include "framerender.h"
11 #include "render/render.h"
12 #include "render/theme.h"
17 gboolean moveresize_in_progress
= FALSE
;
18 ObClient
*moveresize_client
= NULL
;
20 static gboolean moving
= FALSE
; /* TRUE - moving, FALSE - resizing */
22 static int start_x
, start_y
, start_cx
, start_cy
, start_cw
, start_ch
;
23 static int cur_x
, cur_y
;
25 static guint32 corner
;
26 static ObCorner lockcorner
;
28 static Popup
*popup
= NULL
;
29 static InternalWindow opaque_window
= { { Window_Internal
}, None
};
30 static GC opaque_gc
= None
;
31 static gboolean first_draw
= FALSE
;
36 void moveresize_startup()
38 XSetWindowAttributes attrib
;
41 popup
= popup_new(FALSE
);
42 popup_size_to_string(popup
, "W: 0000 W: 0000");
44 attrib
.save_under
= True
;
45 opaque_window
.win
= XCreateWindow(ob_display
,
46 RootWindow(ob_display
, ob_screen
),
48 RrDepth(ob_rr_inst
), InputOutput
,
50 CWSaveUnder
, &attrib
);
51 stacking_add(INTERNAL_AS_WINDOW(&opaque_window
));
52 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window
));
54 /* a GC to invert stuff */
56 gcv
.line_width
= ob_rr_theme
->bwidth
;
57 gcv
.foreground
= (WhitePixel(ob_display
, ob_screen
) ^
58 BlackPixel(ob_display
, ob_screen
));
59 opaque_gc
= XCreateGC(ob_display
, opaque_window
.win
,
60 GCFunction
| GCForeground
| GCLineWidth
, &gcv
);
63 void moveresize_shutdown()
67 stacking_remove(&opaque_window
);
68 XFreeGC(ob_display
, opaque_gc
);
69 XDestroyWindow(ob_display
, opaque_window
.win
);
72 static void popup_coords(char *format
, int a
, int b
)
77 text
= g_strdup_printf(format
, a
, b
);
78 area
= screen_physical_area_monitor(0);
79 popup_position(popup
, NorthWestGravity
,
80 POPUP_X
+ area
->x
, POPUP_Y
+ area
->y
);
81 popup_show(popup
, text
, NULL
);
85 void moveresize_start(ObClient
*c
, int x
, int y
, guint b
, guint32 cnr
)
90 g_assert(!moveresize_in_progress
);
92 moveresize_client
= c
;
93 start_cx
= c
->frame
->area
.x
;
94 start_cy
= c
->frame
->area
.y
;
95 start_cw
= c
->area
.width
;
96 start_ch
= c
->area
.height
;
99 if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
||
100 corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
101 button
= 0; /* mouse can't end it without being pressed first */
106 if (corner
== prop_atoms
.net_wm_moveresize_move
||
107 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
117 moveresize_in_progress
= TRUE
;
119 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
)
120 cur
= OB_CURSOR_NORTHWEST
;
121 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
122 cur
= OB_CURSOR_NORTH
;
123 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
124 cur
= OB_CURSOR_NORTHEAST
;
125 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
126 cur
= OB_CURSOR_EAST
;
127 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
128 cur
= OB_CURSOR_SOUTHEAST
;
129 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
130 cur
= OB_CURSOR_SOUTH
;
131 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
132 cur
= OB_CURSOR_SOUTHWEST
;
133 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
134 cur
= OB_CURSOR_WEST
;
135 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
136 cur
= OB_CURSOR_SOUTHEAST
;
137 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
138 cur
= OB_CURSOR_MOVE
;
139 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
140 cur
= OB_CURSOR_MOVE
;
142 g_assert_not_reached();
144 grab_pointer(TRUE
, cur
);
147 a
= screen_physical_area();
149 XMoveResizeWindow(ob_display
, opaque_window
.win
,
150 a
->x
, a
->y
, a
->width
, a
->height
);
151 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window
));
152 if (corner
== prop_atoms
.net_wm_moveresize_move
||
153 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
154 if (!config_opaque_move
)
155 XMapWindow(ob_display
, opaque_window
.win
);
157 if (!config_opaque_resize
)
158 XMapWindow(ob_display
, opaque_window
.win
);
163 void moveresize_end(gboolean cancel
)
165 XUnmapWindow(ob_display
, opaque_window
.win
);
167 grab_keyboard(FALSE
);
168 grab_pointer(FALSE
, None
);
173 client_configure(moveresize_client
, OB_CORNER_TOPLEFT
,
174 (cancel
? start_cx
: cur_x
),
175 (cancel
? start_cy
: cur_y
),
176 start_cw
, start_ch
, TRUE
, TRUE
);
178 client_configure(moveresize_client
, lockcorner
,
179 moveresize_client
->area
.x
,
180 moveresize_client
->area
.y
,
181 (cancel
? start_cw
: cur_x
),
182 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
185 moveresize_in_progress
= FALSE
;
186 moveresize_client
= NULL
;
189 static void do_move()
191 int oldx
, oldy
, oldw
, oldh
;
193 dispatch_move(moveresize_client
, &cur_x
, &cur_y
);
195 oldx
= moveresize_client
->frame
->area
.x
;
196 oldy
= moveresize_client
->frame
->area
.y
;
197 oldw
= moveresize_client
->frame
->area
.width
;
198 oldh
= moveresize_client
->frame
->area
.height
;
199 /* get where the client should be */
200 frame_frame_gravity(moveresize_client
->frame
, &cur_x
, &cur_y
);
201 client_configure(moveresize_client
, OB_CORNER_TOPLEFT
, cur_x
, cur_y
,
202 start_cw
, start_ch
, TRUE
, FALSE
);
203 /* draw the new one */
204 if (moveresize_client
->frame
->area
.x
!= oldx
||
205 moveresize_client
->frame
->area
.y
!= oldy
||
206 moveresize_client
->frame
->area
.width
!= oldw
||
207 moveresize_client
->frame
->area
.height
!= oldh
) {
208 if (!config_opaque_move
)
209 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
210 moveresize_client
->frame
->area
.x
,
211 moveresize_client
->frame
->area
.y
,
212 moveresize_client
->frame
->area
.width
- 1,
213 moveresize_client
->frame
->area
.height
- 1);
214 /* erase the old one */
215 if (!config_opaque_move
&& !first_draw
)
216 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
217 oldx
, oldy
, oldw
- 1, oldh
- 1);
221 /* this would be better with a fixed width font ... XXX can do it better
222 if there are 2 text boxes */
223 popup_coords("X: %4d Y: %4d", moveresize_client
->frame
->area
.x
,
224 moveresize_client
->frame
->area
.y
);
227 static void do_resize()
229 int oldx
, oldy
, oldw
, oldh
;
231 /* dispatch_resize needs the frame size */
232 cur_x
+= moveresize_client
->frame
->size
.left
+
233 moveresize_client
->frame
->size
.right
;
234 cur_y
+= moveresize_client
->frame
->size
.top
+
235 moveresize_client
->frame
->size
.bottom
;
237 dispatch_resize(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
239 cur_x
-= moveresize_client
->frame
->size
.left
+
240 moveresize_client
->frame
->size
.right
;
241 cur_y
-= moveresize_client
->frame
->size
.top
+
242 moveresize_client
->frame
->size
.bottom
;
244 oldx
= moveresize_client
->frame
->area
.x
;
245 oldy
= moveresize_client
->frame
->area
.y
;
246 oldw
= moveresize_client
->frame
->area
.width
;
247 oldh
= moveresize_client
->frame
->area
.height
;
248 client_configure(moveresize_client
, lockcorner
,
249 moveresize_client
->area
.x
, moveresize_client
->area
.y
,
250 cur_x
, cur_y
, TRUE
, FALSE
);
251 /* draw the new one */
252 if (!config_opaque_resize
)
253 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
254 moveresize_client
->frame
->area
.x
,
255 moveresize_client
->frame
->area
.y
,
256 moveresize_client
->frame
->area
.width
- 1,
257 moveresize_client
->frame
->area
.height
- 1);
258 /* erase the old one */
259 if (!config_opaque_resize
&& !first_draw
)
260 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
261 oldx
, oldy
, oldw
- 1, oldh
- 1);
264 /* this would be better with a fixed width font ... XXX can do it better
265 if there are 2 text boxes */
266 popup_coords("W: %4d H: %4d", moveresize_client
->logical_size
.width
,
267 moveresize_client
->logical_size
.height
);
270 void moveresize_event(XEvent
*e
)
272 g_assert(moveresize_in_progress
);
274 if (e
->type
== ButtonPress
) {
276 start_x
= e
->xbutton
.x_root
;
277 start_y
= e
->xbutton
.y_root
;
278 button
= e
->xbutton
.button
; /* this will end it now */
280 } else if (e
->type
== ButtonRelease
) {
281 if (!button
|| e
->xbutton
.button
== button
) {
282 moveresize_end(FALSE
);
284 } else if (e
->type
== MotionNotify
) {
286 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
287 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
290 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
291 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
292 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
293 lockcorner
= OB_CORNER_BOTTOMRIGHT
;
294 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
296 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
297 lockcorner
= OB_CORNER_BOTTOMRIGHT
;
298 } else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
) {
299 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
300 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
301 lockcorner
= OB_CORNER_BOTTOMLEFT
;
302 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
303 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
305 lockcorner
= OB_CORNER_BOTTOMLEFT
;
307 prop_atoms
.net_wm_moveresize_size_bottomright
) {
308 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
309 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
310 lockcorner
= OB_CORNER_TOPLEFT
;
311 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
313 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
314 lockcorner
= OB_CORNER_TOPLEFT
;
316 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
317 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
318 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
319 lockcorner
= OB_CORNER_TOPRIGHT
;
320 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
321 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
323 lockcorner
= OB_CORNER_TOPRIGHT
;
324 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
325 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
326 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
327 lockcorner
= OB_CORNER_TOPLEFT
;
329 g_assert_not_reached();
333 } else if (e
->type
== KeyPress
) {
334 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
))
335 moveresize_end(TRUE
);
336 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
))
337 moveresize_end(FALSE
);
339 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
340 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
341 cur_x
+= MAX(4, moveresize_client
->size_inc
.width
);
342 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
343 cur_x
-= MAX(4, moveresize_client
->size_inc
.width
);
344 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
345 cur_y
+= MAX(4, moveresize_client
->size_inc
.height
);
346 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))
347 cur_y
-= MAX(4, moveresize_client
->size_inc
.height
);
351 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
352 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
354 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
356 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
358 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))