2 #include "framerender.h"
11 gboolean moveresize_in_progress = FALSE;
12 Client *moveresize_client = NULL;
14 static gboolean moving = FALSE; /* TRUE - moving, FALSE - resizing */
16 static Window coords = None;
17 static int start_x, start_y, start_cx, start_cy, start_cw, start_ch;
18 static int cur_x, cur_y;
20 static guint32 corner;
21 static Corner lockcorner;
23 static guint button_return, button_escape, button_left, button_right,
24 button_up, button_down;
29 void moveresize_startup()
31 button_return = XKeysymToKeycode(ob_display, XStringToKeysym("Return"));
32 button_escape = XKeysymToKeycode(ob_display, XStringToKeysym("Escape"));
33 button_left = XKeysymToKeycode(ob_display, XStringToKeysym("Left"));
34 button_right = XKeysymToKeycode(ob_display, XStringToKeysym("Right"));
35 button_up = XKeysymToKeycode(ob_display, XStringToKeysym("Up"));
36 button_down = XKeysymToKeycode(ob_display, XStringToKeysym("Down"));
39 static void popup_coords(char *format, int a, int b)
41 XSetWindowAttributes attrib;
46 attrib.override_redirect = TRUE;
47 coords = XCreateWindow(ob_display, ob_root,
48 0, 0, 1, 1, 0, render_depth, InputOutput,
49 render_visual, CWOverrideRedirect, &attrib);
50 g_assert(coords != None);
52 XMapWindow(ob_display, coords);
55 text = g_strdup_printf(format, a, b);
56 framerender_size_popup_label(text, &s);
57 XMoveResizeWindow(ob_display, coords,
58 POPUP_X, POPUP_Y, s.width, s.height);
59 framerender_popup_label(coords, &s, text);
63 void moveresize_start(Client *c, int x, int y, guint b, guint32 cnr)
67 g_assert(!moveresize_in_progress);
69 moveresize_client = c;
70 start_cx = c->frame->area.x;
71 start_cy = c->frame->area.y;
72 start_cw = c->area.width;
73 start_ch = c->area.height;
76 if (corner == prop_atoms.net_wm_moveresize_move_keyboard ||
77 corner == prop_atoms.net_wm_moveresize_size_keyboard)
78 button = 0; /* mouse can't end it without being pressed first */
83 if (corner == prop_atoms.net_wm_moveresize_move ||
84 corner == prop_atoms.net_wm_moveresize_move_keyboard) {
94 moveresize_in_progress = TRUE;
96 if (corner == prop_atoms.net_wm_moveresize_size_topleft)
98 else if (corner == prop_atoms.net_wm_moveresize_size_top)
100 else if (corner == prop_atoms.net_wm_moveresize_size_topright)
102 else if (corner == prop_atoms.net_wm_moveresize_size_right)
104 else if (corner == prop_atoms.net_wm_moveresize_size_bottomright)
106 else if (corner == prop_atoms.net_wm_moveresize_size_bottom)
108 else if (corner == prop_atoms.net_wm_moveresize_size_bottomleft)
110 else if (corner == prop_atoms.net_wm_moveresize_size_left)
112 else if (corner == prop_atoms.net_wm_moveresize_size_keyboard)
114 else if (corner == prop_atoms.net_wm_moveresize_move)
115 cur = ob_cursors.move;
116 else if (corner == prop_atoms.net_wm_moveresize_move_keyboard)
117 cur = ob_cursors.move;
119 g_assert_not_reached();
121 grab_pointer(TRUE, cur);
125 void moveresize_end(gboolean cancel)
127 grab_keyboard(FALSE);
128 grab_pointer(FALSE, None);
130 XDestroyWindow(ob_display, coords);
134 client_configure(moveresize_client, Corner_TopLeft,
135 (cancel ? start_cx : cur_x),
136 (cancel ? start_cy : cur_y),
137 start_cw, start_ch, TRUE, TRUE);
139 client_configure(moveresize_client, lockcorner,
140 moveresize_client->area.x,
141 moveresize_client->area.y,
142 (cancel ? start_cw : cur_x),
143 (cancel ? start_ch : cur_y), TRUE, TRUE);
146 moveresize_in_progress = FALSE;
147 moveresize_client = NULL;
150 static void do_move()
152 dispatch_move(moveresize_client, &cur_x, &cur_y);
154 popup_coords("X: %d Y: %d", cur_x, cur_y);
156 /* get where the client should be */
157 frame_frame_gravity(moveresize_client->frame, &cur_x, &cur_y);
158 client_configure(moveresize_client, Corner_TopLeft, cur_x, cur_y,
159 start_cw, start_ch, TRUE, FALSE);
162 static void do_resize()
164 /* dispatch_resize needs the frame size */
165 cur_x += moveresize_client->frame->size.left +
166 moveresize_client->frame->size.right;
167 cur_y += moveresize_client->frame->size.top +
168 moveresize_client->frame->size.bottom;
170 dispatch_resize(moveresize_client, &cur_x, &cur_y, lockcorner);
172 cur_x -= moveresize_client->frame->size.left +
173 moveresize_client->frame->size.right;
174 cur_y -= moveresize_client->frame->size.top +
175 moveresize_client->frame->size.bottom;
177 client_configure(moveresize_client, lockcorner, moveresize_client->area.x,
178 moveresize_client->area.y, cur_x, cur_y, TRUE, FALSE);
180 popup_coords("W: %d H: %d", moveresize_client->logical_size.width,
181 moveresize_client->logical_size.height);
184 void moveresize_event(XEvent *e)
186 g_assert(moveresize_in_progress);
188 if (e->type == ButtonPress) {
190 start_x = e->xbutton.x_root;
191 start_y = e->xbutton.y_root;
192 button = e->xbutton.button; /* this will end it now */
194 } else if (e->type == ButtonRelease) {
195 if (!button || e->xbutton.button == button) {
196 moveresize_end(FALSE);
198 } else if (e->type == MotionNotify) {
200 cur_x = start_cx + e->xmotion.x_root - start_x;
201 cur_y = start_cy + e->xmotion.y_root - start_y;
204 if (corner == prop_atoms.net_wm_moveresize_size_topleft) {
205 cur_x = start_cw - (e->xmotion.x_root - start_x);
206 cur_y = start_ch - (e->xmotion.y_root - start_y);
207 lockcorner = Corner_BottomRight;
208 } else if (corner == prop_atoms.net_wm_moveresize_size_top) {
210 cur_y = start_ch - (e->xmotion.y_root - start_y);
211 lockcorner = Corner_BottomRight;
212 } else if (corner == prop_atoms.net_wm_moveresize_size_topright) {
213 cur_x = start_cw + (e->xmotion.x_root - start_x);
214 cur_y = start_ch - (e->xmotion.y_root - start_y);
215 lockcorner = Corner_BottomLeft;
216 } else if (corner == prop_atoms.net_wm_moveresize_size_right) {
217 cur_x = start_cw + (e->xmotion.x_root - start_x);
219 lockcorner = Corner_BottomLeft;
221 prop_atoms.net_wm_moveresize_size_bottomright) {
222 cur_x = start_cw + (e->xmotion.x_root - start_x);
223 cur_y = start_ch + (e->xmotion.y_root - start_y);
224 lockcorner = Corner_TopLeft;
225 } else if (corner == prop_atoms.net_wm_moveresize_size_bottom) {
227 cur_y = start_ch + (e->xmotion.y_root - start_y);
228 lockcorner = Corner_TopLeft;
230 prop_atoms.net_wm_moveresize_size_bottomleft) {
231 cur_x = start_cw - (e->xmotion.x_root - start_x);
232 cur_y = start_ch + (e->xmotion.y_root - start_y);
233 lockcorner = Corner_TopRight;
234 } else if (corner == prop_atoms.net_wm_moveresize_size_left) {
235 cur_x = start_cw - (e->xmotion.x_root - start_x);
237 lockcorner = Corner_TopRight;
238 } else if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
239 cur_x = start_cw + (e->xmotion.x_root - start_x);
240 cur_y = start_ch + (e->xmotion.y_root - start_y);
241 lockcorner = Corner_TopLeft;
243 g_assert_not_reached();
247 } else if (e->type == KeyPress) {
248 if (e->xkey.keycode == button_escape)
249 moveresize_end(TRUE);
250 else if (e->xkey.keycode == button_return)
251 moveresize_end(FALSE);
253 if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
254 if (e->xkey.keycode == button_right)
255 cur_x += MAX(4, moveresize_client->size_inc.width);
256 else if (e->xkey.keycode == button_left)
257 cur_x -= MAX(4, moveresize_client->size_inc.width);
258 else if (e->xkey.keycode == button_down)
259 cur_y += MAX(4, moveresize_client->size_inc.height);
260 else if (e->xkey.keycode == button_up)
261 cur_y -= MAX(4, moveresize_client->size_inc.height);
265 } else if (corner == prop_atoms.net_wm_moveresize_move_keyboard) {
266 if (e->xkey.keycode == button_right)
268 else if (e->xkey.keycode == button_left)
270 else if (e->xkey.keycode == button_down)
272 else if (e->xkey.keycode == button_up)