2 #include "framerender.h"
10 #include "render2/render.h"
16 static int theme_bwidth = 1;
18 gboolean moveresize_in_progress = FALSE;
19 Client *moveresize_client = NULL;
21 static gboolean moving = FALSE; /* TRUE - moving, FALSE - resizing */
23 static int start_x, start_y, start_cx, start_cy, start_cw, start_ch;
24 static int cur_x, cur_y;
26 static guint32 corner;
27 static Corner lockcorner;
29 static guint button_return, button_escape, button_left, button_right,
30 button_up, button_down;
32 static Popup *popup = NULL;
33 static InternalWindow opaque_window = { { Window_Internal }, None };
34 static GC opaque_gc = None;
35 static gboolean first_draw = FALSE;
40 void moveresize_startup()
42 XSetWindowAttributes attrib;
45 button_return = XKeysymToKeycode(ob_display, XStringToKeysym("Return"));
46 button_escape = XKeysymToKeycode(ob_display, XStringToKeysym("Escape"));
47 button_left = XKeysymToKeycode(ob_display, XStringToKeysym("Left"));
48 button_right = XKeysymToKeycode(ob_display, XStringToKeysym("Right"));
49 button_up = XKeysymToKeycode(ob_display, XStringToKeysym("Up"));
50 button_down = XKeysymToKeycode(ob_display, XStringToKeysym("Down"));
52 popup = popup_new(FALSE);
53 popup_size_to_string(popup, "W: 0000 W: 0000");
54 popup_position(popup, NorthWestGravity, POPUP_X, POPUP_Y);
56 attrib.save_under = True;
57 opaque_window.win = XCreateWindow(ob_display, ob_root, 0, 0, 1, 1, 0,
58 RrInstanceDepth(ob_render_inst),
60 RrInstanceVisual(ob_render_inst),
61 CWSaveUnder, &attrib);
62 stacking_add(INTERNAL_AS_WINDOW(&opaque_window));
63 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window));
65 /* a GC to invert stuff */
67 gcv.line_width = theme_bwidth;
68 gcv.foreground = (WhitePixel(ob_display, ob_screen) ^
69 BlackPixel(ob_display, ob_screen));
70 opaque_gc = XCreateGC(ob_display, opaque_window.win,
71 GCFunction | GCForeground | GCLineWidth, &gcv);
74 void moveresize_shutdown()
78 stacking_remove(&opaque_window);
79 XFreeGC(ob_display, opaque_gc);
80 XDestroyWindow(ob_display, opaque_window.win);
83 static void popup_coords(char *format, int a, int b)
87 text = g_strdup_printf(format, a, b);
88 popup_show(popup, text, NULL);
92 void moveresize_start(Client *c, int x, int y, guint b, guint32 cnr)
96 g_assert(!moveresize_in_progress);
98 moveresize_client = c;
99 start_cx = c->frame->area.x;
100 start_cy = c->frame->area.y;
101 start_cw = c->area.width;
102 start_ch = c->area.height;
105 if (corner == prop_atoms.net_wm_moveresize_move_keyboard ||
106 corner == prop_atoms.net_wm_moveresize_size_keyboard)
107 button = 0; /* mouse can't end it without being pressed first */
112 if (corner == prop_atoms.net_wm_moveresize_move ||
113 corner == prop_atoms.net_wm_moveresize_move_keyboard) {
123 moveresize_in_progress = TRUE;
125 if (corner == prop_atoms.net_wm_moveresize_size_topleft)
127 else if (corner == prop_atoms.net_wm_moveresize_size_top)
129 else if (corner == prop_atoms.net_wm_moveresize_size_topright)
131 else if (corner == prop_atoms.net_wm_moveresize_size_right)
133 else if (corner == prop_atoms.net_wm_moveresize_size_bottomright)
135 else if (corner == prop_atoms.net_wm_moveresize_size_bottom)
137 else if (corner == prop_atoms.net_wm_moveresize_size_bottomleft)
139 else if (corner == prop_atoms.net_wm_moveresize_size_left)
141 else if (corner == prop_atoms.net_wm_moveresize_size_keyboard)
143 else if (corner == prop_atoms.net_wm_moveresize_move)
144 cur = ob_cursors.move;
145 else if (corner == prop_atoms.net_wm_moveresize_move_keyboard)
146 cur = ob_cursors.move;
148 g_assert_not_reached();
150 grab_pointer(TRUE, cur);
153 XResizeWindow(ob_display, opaque_window.win, screen_physical_size.width,
154 screen_physical_size.height);
155 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window));
156 if (corner == prop_atoms.net_wm_moveresize_move ||
157 corner == prop_atoms.net_wm_moveresize_move_keyboard) {
158 if (!config_opaque_move)
159 XMapWindow(ob_display, opaque_window.win);
161 if (!config_opaque_resize)
162 XMapWindow(ob_display, opaque_window.win);
167 void moveresize_end(gboolean cancel)
169 XUnmapWindow(ob_display, opaque_window.win);
171 grab_keyboard(FALSE);
172 grab_pointer(FALSE, None);
177 client_configure(moveresize_client, Corner_TopLeft,
178 (cancel ? start_cx : cur_x),
179 (cancel ? start_cy : cur_y),
180 start_cw, start_ch, TRUE, TRUE);
182 client_configure(moveresize_client, lockcorner,
183 moveresize_client->area.x,
184 moveresize_client->area.y,
185 (cancel ? start_cw : cur_x),
186 (cancel ? start_ch : cur_y), TRUE, TRUE);
189 moveresize_in_progress = FALSE;
190 moveresize_client = NULL;
193 static void do_move()
195 int oldx, oldy, oldw, oldh;
197 dispatch_move(moveresize_client, &cur_x, &cur_y);
199 oldx = moveresize_client->frame->area.x;
200 oldy = moveresize_client->frame->area.y;
201 oldw = moveresize_client->frame->area.width;
202 oldh = moveresize_client->frame->area.height;
203 /* get where the client should be */
204 frame_frame_gravity(moveresize_client->frame, &cur_x, &cur_y);
205 client_configure(moveresize_client, Corner_TopLeft, cur_x, cur_y,
206 start_cw, start_ch, TRUE, FALSE);
207 /* draw the new one */
208 if (moveresize_client->frame->area.x != oldx ||
209 moveresize_client->frame->area.y != oldy ||
210 moveresize_client->frame->area.width != oldw ||
211 moveresize_client->frame->area.height != oldh) {
212 if (!config_opaque_move)
213 XDrawRectangle(ob_display, opaque_window.win, opaque_gc,
214 moveresize_client->frame->area.x,
215 moveresize_client->frame->area.y,
216 moveresize_client->frame->area.width - 1,
217 moveresize_client->frame->area.height - 1);
218 /* erase the old one */
219 if (!config_opaque_move && !first_draw)
220 XDrawRectangle(ob_display, opaque_window.win, opaque_gc,
221 oldx, oldy, oldw - 1, oldh - 1);
225 /* this would be better with a fixed width font ... XXX can do it better
226 if there are 2 text boxes */
227 popup_coords("X: %4d Y: %4d", moveresize_client->frame->area.x,
228 moveresize_client->frame->area.y);
231 static void do_resize()
233 int oldx, oldy, oldw, oldh;
235 /* dispatch_resize needs the frame size */
236 cur_x += moveresize_client->frame->size.left +
237 moveresize_client->frame->size.right;
238 cur_y += moveresize_client->frame->size.top +
239 moveresize_client->frame->size.bottom;
241 dispatch_resize(moveresize_client, &cur_x, &cur_y, lockcorner);
243 cur_x -= moveresize_client->frame->size.left +
244 moveresize_client->frame->size.right;
245 cur_y -= moveresize_client->frame->size.top +
246 moveresize_client->frame->size.bottom;
248 oldx = moveresize_client->frame->area.x;
249 oldy = moveresize_client->frame->area.y;
250 oldw = moveresize_client->frame->area.width;
251 oldh = moveresize_client->frame->area.height;
252 client_configure(moveresize_client, lockcorner,
253 moveresize_client->area.x, moveresize_client->area.y,
254 cur_x, cur_y, TRUE, FALSE);
255 /* draw the new one */
256 if (!config_opaque_resize)
257 XDrawRectangle(ob_display, opaque_window.win, opaque_gc,
258 moveresize_client->frame->area.x,
259 moveresize_client->frame->area.y,
260 moveresize_client->frame->area.width - 1,
261 moveresize_client->frame->area.height - 1);
262 /* erase the old one */
263 if (!config_opaque_resize && !first_draw)
264 XDrawRectangle(ob_display, opaque_window.win, opaque_gc,
265 oldx, oldy, oldw - 1, oldh - 1);
268 /* this would be better with a fixed width font ... XXX can do it better
269 if there are 2 text boxes */
270 popup_coords("W: %4d H: %4d", moveresize_client->logical_size.width,
271 moveresize_client->logical_size.height);
274 void moveresize_event(XEvent *e)
276 g_assert(moveresize_in_progress);
278 if (e->type == ButtonPress) {
280 start_x = e->xbutton.x_root;
281 start_y = e->xbutton.y_root;
282 button = e->xbutton.button; /* this will end it now */
284 } else if (e->type == ButtonRelease) {
285 if (!button || e->xbutton.button == button) {
286 moveresize_end(FALSE);
288 } else if (e->type == MotionNotify) {
290 cur_x = start_cx + e->xmotion.x_root - start_x;
291 cur_y = start_cy + e->xmotion.y_root - start_y;
294 if (corner == prop_atoms.net_wm_moveresize_size_topleft) {
295 cur_x = start_cw - (e->xmotion.x_root - start_x);
296 cur_y = start_ch - (e->xmotion.y_root - start_y);
297 lockcorner = Corner_BottomRight;
298 } else if (corner == prop_atoms.net_wm_moveresize_size_top) {
300 cur_y = start_ch - (e->xmotion.y_root - start_y);
301 lockcorner = Corner_BottomRight;
302 } else if (corner == prop_atoms.net_wm_moveresize_size_topright) {
303 cur_x = start_cw + (e->xmotion.x_root - start_x);
304 cur_y = start_ch - (e->xmotion.y_root - start_y);
305 lockcorner = Corner_BottomLeft;
306 } else if (corner == prop_atoms.net_wm_moveresize_size_right) {
307 cur_x = start_cw + (e->xmotion.x_root - start_x);
309 lockcorner = Corner_BottomLeft;
311 prop_atoms.net_wm_moveresize_size_bottomright) {
312 cur_x = start_cw + (e->xmotion.x_root - start_x);
313 cur_y = start_ch + (e->xmotion.y_root - start_y);
314 lockcorner = Corner_TopLeft;
315 } else if (corner == prop_atoms.net_wm_moveresize_size_bottom) {
317 cur_y = start_ch + (e->xmotion.y_root - start_y);
318 lockcorner = Corner_TopLeft;
320 prop_atoms.net_wm_moveresize_size_bottomleft) {
321 cur_x = start_cw - (e->xmotion.x_root - start_x);
322 cur_y = start_ch + (e->xmotion.y_root - start_y);
323 lockcorner = Corner_TopRight;
324 } else if (corner == prop_atoms.net_wm_moveresize_size_left) {
325 cur_x = start_cw - (e->xmotion.x_root - start_x);
327 lockcorner = Corner_TopRight;
328 } else if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
329 cur_x = start_cw + (e->xmotion.x_root - start_x);
330 cur_y = start_ch + (e->xmotion.y_root - start_y);
331 lockcorner = Corner_TopLeft;
333 g_assert_not_reached();
337 } else if (e->type == KeyPress) {
338 if (e->xkey.keycode == button_escape)
339 moveresize_end(TRUE);
340 else if (e->xkey.keycode == button_return)
341 moveresize_end(FALSE);
343 if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
344 if (e->xkey.keycode == button_right)
345 cur_x += MAX(4, moveresize_client->size_inc.width);
346 else if (e->xkey.keycode == button_left)
347 cur_x -= MAX(4, moveresize_client->size_inc.width);
348 else if (e->xkey.keycode == button_down)
349 cur_y += MAX(4, moveresize_client->size_inc.height);
350 else if (e->xkey.keycode == button_up)
351 cur_y -= MAX(4, moveresize_client->size_inc.height);
355 } else if (corner == prop_atoms.net_wm_moveresize_move_keyboard) {
356 if (e->xkey.keycode == button_right)
358 else if (e->xkey.keycode == button_left)
360 else if (e->xkey.keycode == button_down)
362 else if (e->xkey.keycode == button_up)