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, ob_root, 0, 0, 1, 1, 0,
46 RrDepth(ob_rr_inst), InputOutput,
48 CWSaveUnder, &attrib);
49 stacking_add(INTERNAL_AS_WINDOW(&opaque_window));
50 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window));
52 /* a GC to invert stuff */
54 gcv.line_width = ob_rr_theme->bwidth;
55 gcv.foreground = (WhitePixel(ob_display, ob_screen) ^
56 BlackPixel(ob_display, ob_screen));
57 opaque_gc = XCreateGC(ob_display, opaque_window.win,
58 GCFunction | GCForeground | GCLineWidth, &gcv);
61 void moveresize_shutdown()
65 stacking_remove(&opaque_window);
66 XFreeGC(ob_display, opaque_gc);
67 XDestroyWindow(ob_display, opaque_window.win);
70 static void popup_coords(char *format, int a, int b)
75 text = g_strdup_printf(format, a, b);
76 area = screen_physical_area_monitor(0);
77 popup_position(popup, NorthWestGravity,
78 POPUP_X + area->x, POPUP_Y + area->y);
79 popup_show(popup, text, NULL);
83 void moveresize_start(ObClient *c, int x, int y, guint b, guint32 cnr)
88 g_assert(!moveresize_in_progress);
90 moveresize_client = c;
91 start_cx = c->frame->area.x;
92 start_cy = c->frame->area.y;
93 start_cw = c->area.width;
94 start_ch = c->area.height;
97 if (corner == prop_atoms.net_wm_moveresize_move_keyboard ||
98 corner == prop_atoms.net_wm_moveresize_size_keyboard)
99 button = 0; /* mouse can't end it without being pressed first */
104 if (corner == prop_atoms.net_wm_moveresize_move ||
105 corner == prop_atoms.net_wm_moveresize_move_keyboard) {
115 moveresize_in_progress = TRUE;
117 if (corner == prop_atoms.net_wm_moveresize_size_topleft)
118 cur = OB_CURSOR_NORTHWEST;
119 else if (corner == prop_atoms.net_wm_moveresize_size_top)
120 cur = OB_CURSOR_NORTH;
121 else if (corner == prop_atoms.net_wm_moveresize_size_topright)
122 cur = OB_CURSOR_NORTHEAST;
123 else if (corner == prop_atoms.net_wm_moveresize_size_right)
124 cur = OB_CURSOR_EAST;
125 else if (corner == prop_atoms.net_wm_moveresize_size_bottomright)
126 cur = OB_CURSOR_SOUTHEAST;
127 else if (corner == prop_atoms.net_wm_moveresize_size_bottom)
128 cur = OB_CURSOR_SOUTH;
129 else if (corner == prop_atoms.net_wm_moveresize_size_bottomleft)
130 cur = OB_CURSOR_SOUTHWEST;
131 else if (corner == prop_atoms.net_wm_moveresize_size_left)
132 cur = OB_CURSOR_WEST;
133 else if (corner == prop_atoms.net_wm_moveresize_size_keyboard)
134 cur = OB_CURSOR_SOUTHEAST;
135 else if (corner == prop_atoms.net_wm_moveresize_move)
136 cur = OB_CURSOR_MOVE;
137 else if (corner == prop_atoms.net_wm_moveresize_move_keyboard)
138 cur = OB_CURSOR_MOVE;
140 g_assert_not_reached();
142 grab_pointer(TRUE, cur);
145 a = screen_physical_area();
147 XMoveResizeWindow(ob_display, opaque_window.win,
148 a->x, a->y, a->width, a->height);
149 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window));
150 if (corner == prop_atoms.net_wm_moveresize_move ||
151 corner == prop_atoms.net_wm_moveresize_move_keyboard) {
152 if (!config_opaque_move)
153 XMapWindow(ob_display, opaque_window.win);
155 if (!config_opaque_resize)
156 XMapWindow(ob_display, opaque_window.win);
161 void moveresize_end(gboolean cancel)
163 XUnmapWindow(ob_display, opaque_window.win);
165 grab_keyboard(FALSE);
166 grab_pointer(FALSE, None);
171 client_configure(moveresize_client, OB_CORNER_TOPLEFT,
172 (cancel ? start_cx : cur_x),
173 (cancel ? start_cy : cur_y),
174 start_cw, start_ch, TRUE, TRUE);
176 client_configure(moveresize_client, lockcorner,
177 moveresize_client->area.x,
178 moveresize_client->area.y,
179 (cancel ? start_cw : cur_x),
180 (cancel ? start_ch : cur_y), TRUE, TRUE);
183 moveresize_in_progress = FALSE;
184 moveresize_client = NULL;
187 static void do_move()
189 int oldx, oldy, oldw, oldh;
191 dispatch_move(moveresize_client, &cur_x, &cur_y);
193 oldx = moveresize_client->frame->area.x;
194 oldy = moveresize_client->frame->area.y;
195 oldw = moveresize_client->frame->area.width;
196 oldh = moveresize_client->frame->area.height;
197 /* get where the client should be */
198 frame_frame_gravity(moveresize_client->frame, &cur_x, &cur_y);
199 client_configure(moveresize_client, OB_CORNER_TOPLEFT, cur_x, cur_y,
200 start_cw, start_ch, TRUE, FALSE);
201 /* draw the new one */
202 if (moveresize_client->frame->area.x != oldx ||
203 moveresize_client->frame->area.y != oldy ||
204 moveresize_client->frame->area.width != oldw ||
205 moveresize_client->frame->area.height != oldh) {
206 if (!config_opaque_move)
207 XDrawRectangle(ob_display, opaque_window.win, opaque_gc,
208 moveresize_client->frame->area.x,
209 moveresize_client->frame->area.y,
210 moveresize_client->frame->area.width - 1,
211 moveresize_client->frame->area.height - 1);
212 /* erase the old one */
213 if (!config_opaque_move && !first_draw)
214 XDrawRectangle(ob_display, opaque_window.win, opaque_gc,
215 oldx, oldy, oldw - 1, oldh - 1);
219 /* this would be better with a fixed width font ... XXX can do it better
220 if there are 2 text boxes */
221 popup_coords("X: %4d Y: %4d", moveresize_client->frame->area.x,
222 moveresize_client->frame->area.y);
225 static void do_resize()
227 int oldx, oldy, oldw, oldh;
229 /* dispatch_resize needs the frame size */
230 cur_x += moveresize_client->frame->size.left +
231 moveresize_client->frame->size.right;
232 cur_y += moveresize_client->frame->size.top +
233 moveresize_client->frame->size.bottom;
235 dispatch_resize(moveresize_client, &cur_x, &cur_y, lockcorner);
237 cur_x -= moveresize_client->frame->size.left +
238 moveresize_client->frame->size.right;
239 cur_y -= moveresize_client->frame->size.top +
240 moveresize_client->frame->size.bottom;
242 oldx = moveresize_client->frame->area.x;
243 oldy = moveresize_client->frame->area.y;
244 oldw = moveresize_client->frame->area.width;
245 oldh = moveresize_client->frame->area.height;
246 client_configure(moveresize_client, lockcorner,
247 moveresize_client->area.x, moveresize_client->area.y,
248 cur_x, cur_y, TRUE, FALSE);
249 /* draw the new one */
250 if (!config_opaque_resize)
251 XDrawRectangle(ob_display, opaque_window.win, opaque_gc,
252 moveresize_client->frame->area.x,
253 moveresize_client->frame->area.y,
254 moveresize_client->frame->area.width - 1,
255 moveresize_client->frame->area.height - 1);
256 /* erase the old one */
257 if (!config_opaque_resize && !first_draw)
258 XDrawRectangle(ob_display, opaque_window.win, opaque_gc,
259 oldx, oldy, oldw - 1, oldh - 1);
262 /* this would be better with a fixed width font ... XXX can do it better
263 if there are 2 text boxes */
264 popup_coords("W: %4d H: %4d", moveresize_client->logical_size.width,
265 moveresize_client->logical_size.height);
268 void moveresize_event(XEvent *e)
270 g_assert(moveresize_in_progress);
272 if (e->type == ButtonPress) {
274 start_x = e->xbutton.x_root;
275 start_y = e->xbutton.y_root;
276 button = e->xbutton.button; /* this will end it now */
278 } else if (e->type == ButtonRelease) {
279 if (!button || e->xbutton.button == button) {
280 moveresize_end(FALSE);
282 } else if (e->type == MotionNotify) {
284 cur_x = start_cx + e->xmotion.x_root - start_x;
285 cur_y = start_cy + e->xmotion.y_root - start_y;
288 if (corner == prop_atoms.net_wm_moveresize_size_topleft) {
289 cur_x = start_cw - (e->xmotion.x_root - start_x);
290 cur_y = start_ch - (e->xmotion.y_root - start_y);
291 lockcorner = OB_CORNER_BOTTOMRIGHT;
292 } else if (corner == prop_atoms.net_wm_moveresize_size_top) {
294 cur_y = start_ch - (e->xmotion.y_root - start_y);
295 lockcorner = OB_CORNER_BOTTOMRIGHT;
296 } else if (corner == prop_atoms.net_wm_moveresize_size_topright) {
297 cur_x = start_cw + (e->xmotion.x_root - start_x);
298 cur_y = start_ch - (e->xmotion.y_root - start_y);
299 lockcorner = OB_CORNER_BOTTOMLEFT;
300 } else if (corner == prop_atoms.net_wm_moveresize_size_right) {
301 cur_x = start_cw + (e->xmotion.x_root - start_x);
303 lockcorner = OB_CORNER_BOTTOMLEFT;
305 prop_atoms.net_wm_moveresize_size_bottomright) {
306 cur_x = start_cw + (e->xmotion.x_root - start_x);
307 cur_y = start_ch + (e->xmotion.y_root - start_y);
308 lockcorner = OB_CORNER_TOPLEFT;
309 } else if (corner == prop_atoms.net_wm_moveresize_size_bottom) {
311 cur_y = start_ch + (e->xmotion.y_root - start_y);
312 lockcorner = OB_CORNER_TOPLEFT;
314 prop_atoms.net_wm_moveresize_size_bottomleft) {
315 cur_x = start_cw - (e->xmotion.x_root - start_x);
316 cur_y = start_ch + (e->xmotion.y_root - start_y);
317 lockcorner = OB_CORNER_TOPRIGHT;
318 } else if (corner == prop_atoms.net_wm_moveresize_size_left) {
319 cur_x = start_cw - (e->xmotion.x_root - start_x);
321 lockcorner = OB_CORNER_TOPRIGHT;
322 } else if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
323 cur_x = start_cw + (e->xmotion.x_root - start_x);
324 cur_y = start_ch + (e->xmotion.y_root - start_y);
325 lockcorner = OB_CORNER_TOPLEFT;
327 g_assert_not_reached();
331 } else if (e->type == KeyPress) {
332 if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE))
333 moveresize_end(TRUE);
334 else if (e->xkey.keycode == ob_keycode(OB_KEY_RETURN))
335 moveresize_end(FALSE);
337 if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
338 if (e->xkey.keycode == ob_keycode(OB_KEY_RIGHT))
339 cur_x += MAX(4, moveresize_client->size_inc.width);
340 else if (e->xkey.keycode == ob_keycode(OB_KEY_LEFT))
341 cur_x -= MAX(4, moveresize_client->size_inc.width);
342 else if (e->xkey.keycode == ob_keycode(OB_KEY_DOWN))
343 cur_y += MAX(4, moveresize_client->size_inc.height);
344 else if (e->xkey.keycode == ob_keycode(OB_KEY_UP))
345 cur_y -= MAX(4, moveresize_client->size_inc.height);
349 } else if (corner == prop_atoms.net_wm_moveresize_move_keyboard) {
350 if (e->xkey.keycode == ob_keycode(OB_KEY_RIGHT))
352 else if (e->xkey.keycode == ob_keycode(OB_KEY_LEFT))
354 else if (e->xkey.keycode == ob_keycode(OB_KEY_DOWN))
356 else if (e->xkey.keycode == ob_keycode(OB_KEY_UP))