2 #include "framerender.h"
10 #include "moveresize.h"
12 #include "render/render.h"
13 #include "render/theme.h"
18 gboolean moveresize_in_progress = FALSE;
19 ObClient *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 ObCorner lockcorner;
29 static Popup *popup = NULL;
34 static void client_dest(ObClient *c)
36 if (moveresize_client == c)
40 void moveresize_startup()
42 XSetWindowAttributes attrib;
44 popup = popup_new(FALSE);
45 popup_size_to_string(popup, "W: 0000 W: 0000");
47 attrib.save_under = True;
49 client_add_destructor(client_dest);
52 void moveresize_shutdown()
54 client_remove_destructor(client_dest);
60 static void popup_coords(char *format, int a, int b)
65 text = g_strdup_printf(format, a, b);
66 area = screen_physical_area_monitor(0);
67 popup_position(popup, NorthWestGravity,
68 POPUP_X + area->x, POPUP_Y + area->y);
69 popup_show(popup, text, NULL);
73 void moveresize_start(ObClient *c, int x, int y, guint b, guint32 cnr)
77 g_assert(!moveresize_in_progress);
79 moveresize_client = c;
80 start_cx = c->frame->area.x;
81 start_cy = c->frame->area.y;
82 start_cw = c->area.width;
83 start_ch = c->area.height;
90 have to change start_cx and start_cy if going to do this..
91 if (corner == prop_atoms.net_wm_moveresize_move_keyboard ||
92 corner == prop_atoms.net_wm_moveresize_size_keyboard)
93 XWarpPointer(ob_display, None, c->window, 0, 0, 0, 0,
94 c->area.width / 2, c->area.height / 2);
97 if (corner == prop_atoms.net_wm_moveresize_move ||
98 corner == prop_atoms.net_wm_moveresize_move_keyboard) {
108 moveresize_in_progress = TRUE;
110 if (corner == prop_atoms.net_wm_moveresize_size_topleft)
111 cur = OB_CURSOR_NORTHWEST;
112 else if (corner == prop_atoms.net_wm_moveresize_size_top)
113 cur = OB_CURSOR_NORTH;
114 else if (corner == prop_atoms.net_wm_moveresize_size_topright)
115 cur = OB_CURSOR_NORTHEAST;
116 else if (corner == prop_atoms.net_wm_moveresize_size_right)
117 cur = OB_CURSOR_EAST;
118 else if (corner == prop_atoms.net_wm_moveresize_size_bottomright)
119 cur = OB_CURSOR_SOUTHEAST;
120 else if (corner == prop_atoms.net_wm_moveresize_size_bottom)
121 cur = OB_CURSOR_SOUTH;
122 else if (corner == prop_atoms.net_wm_moveresize_size_bottomleft)
123 cur = OB_CURSOR_SOUTHWEST;
124 else if (corner == prop_atoms.net_wm_moveresize_size_left)
125 cur = OB_CURSOR_WEST;
126 else if (corner == prop_atoms.net_wm_moveresize_size_keyboard)
127 cur = OB_CURSOR_SOUTHEAST;
128 else if (corner == prop_atoms.net_wm_moveresize_move)
129 cur = OB_CURSOR_MOVE;
130 else if (corner == prop_atoms.net_wm_moveresize_move_keyboard)
131 cur = OB_CURSOR_MOVE;
133 g_assert_not_reached();
135 grab_pointer(TRUE, cur);
139 void moveresize_end(gboolean cancel)
141 grab_keyboard(FALSE);
142 grab_pointer(FALSE, None);
147 client_move(moveresize_client,
148 (cancel ? start_cx : cur_x),
149 (cancel ? start_cy : cur_y));
151 client_configure(moveresize_client, lockcorner,
152 moveresize_client->area.x,
153 moveresize_client->area.y,
154 (cancel ? start_cw : cur_x),
155 (cancel ? start_ch : cur_y), TRUE, TRUE);
158 moveresize_in_progress = FALSE;
159 moveresize_client = NULL;
162 static void do_move(gboolean resist)
167 resist_move(moveresize_client, &cur_x, &cur_y);
169 /* get where the client should be */
170 frame_frame_gravity(moveresize_client->frame, &cur_x, &cur_y);
171 client_configure(moveresize_client, OB_CORNER_TOPLEFT, cur_x, cur_y,
172 start_cw, start_ch, TRUE, FALSE);
174 /* this would be better with a fixed width font ... XXX can do it better
175 if there are 2 text boxes */
176 a = screen_area(screen_desktop);
177 popup_coords("X: %4d Y: %4d",
178 moveresize_client->frame->area.x - a->x,
179 moveresize_client->frame->area.y - a->y);
182 static void do_resize(gboolean resist)
185 /* resist_size needs the frame size */
186 cur_x += moveresize_client->frame->size.left +
187 moveresize_client->frame->size.right;
188 cur_y += moveresize_client->frame->size.top +
189 moveresize_client->frame->size.bottom;
191 resist_size(moveresize_client, &cur_x, &cur_y, lockcorner);
193 cur_x -= moveresize_client->frame->size.left +
194 moveresize_client->frame->size.right;
195 cur_y -= moveresize_client->frame->size.top +
196 moveresize_client->frame->size.bottom;
199 client_configure(moveresize_client, lockcorner,
200 moveresize_client->area.x, moveresize_client->area.y,
201 cur_x, cur_y, TRUE, FALSE);
203 /* this would be better with a fixed width font ... XXX can do it better
204 if there are 2 text boxes */
205 popup_coords("W: %4d H: %4d", moveresize_client->logical_size.width,
206 moveresize_client->logical_size.height);
209 void moveresize_event(XEvent *e)
211 g_assert(moveresize_in_progress);
213 if (e->type == ButtonPress) {
215 start_x = e->xbutton.x_root;
216 start_y = e->xbutton.y_root;
217 button = e->xbutton.button; /* this will end it now */
219 } else if (e->type == ButtonRelease) {
220 if (!button || e->xbutton.button == button) {
221 moveresize_end(FALSE);
223 } else if (e->type == MotionNotify) {
225 cur_x = start_cx + e->xmotion.x_root - start_x;
226 cur_y = start_cy + e->xmotion.y_root - start_y;
229 if (corner == prop_atoms.net_wm_moveresize_size_topleft) {
230 cur_x = start_cw - (e->xmotion.x_root - start_x);
231 cur_y = start_ch - (e->xmotion.y_root - start_y);
232 lockcorner = OB_CORNER_BOTTOMRIGHT;
233 } else if (corner == prop_atoms.net_wm_moveresize_size_top) {
235 cur_y = start_ch - (e->xmotion.y_root - start_y);
236 lockcorner = OB_CORNER_BOTTOMRIGHT;
237 } else if (corner == prop_atoms.net_wm_moveresize_size_topright) {
238 cur_x = start_cw + (e->xmotion.x_root - start_x);
239 cur_y = start_ch - (e->xmotion.y_root - start_y);
240 lockcorner = OB_CORNER_BOTTOMLEFT;
241 } else if (corner == prop_atoms.net_wm_moveresize_size_right) {
242 cur_x = start_cw + (e->xmotion.x_root - start_x);
244 lockcorner = OB_CORNER_BOTTOMLEFT;
246 prop_atoms.net_wm_moveresize_size_bottomright) {
247 cur_x = start_cw + (e->xmotion.x_root - start_x);
248 cur_y = start_ch + (e->xmotion.y_root - start_y);
249 lockcorner = OB_CORNER_TOPLEFT;
250 } else if (corner == prop_atoms.net_wm_moveresize_size_bottom) {
252 cur_y = start_ch + (e->xmotion.y_root - start_y);
253 lockcorner = OB_CORNER_TOPLEFT;
255 prop_atoms.net_wm_moveresize_size_bottomleft) {
256 cur_x = start_cw - (e->xmotion.x_root - start_x);
257 cur_y = start_ch + (e->xmotion.y_root - start_y);
258 lockcorner = OB_CORNER_TOPRIGHT;
259 } else if (corner == prop_atoms.net_wm_moveresize_size_left) {
260 cur_x = start_cw - (e->xmotion.x_root - start_x);
262 lockcorner = OB_CORNER_TOPRIGHT;
263 } else if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
264 cur_x = start_cw + (e->xmotion.x_root - start_x);
265 cur_y = start_ch + (e->xmotion.y_root - start_y);
266 lockcorner = OB_CORNER_TOPLEFT;
268 g_assert_not_reached();
272 } else if (e->type == KeyPress) {
273 if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE))
274 moveresize_end(TRUE);
275 else if (e->xkey.keycode == ob_keycode(OB_KEY_RETURN))
276 moveresize_end(FALSE);
278 if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
281 if (e->xkey.keycode == ob_keycode(OB_KEY_RIGHT))
282 dx = MAX(4, moveresize_client->size_inc.width);
283 else if (e->xkey.keycode == ob_keycode(OB_KEY_LEFT))
284 dx = -MAX(4, moveresize_client->size_inc.width);
285 else if (e->xkey.keycode == ob_keycode(OB_KEY_DOWN))
286 dy = MAX(4, moveresize_client->size_inc.height);
287 else if (e->xkey.keycode == ob_keycode(OB_KEY_UP))
288 dy = -MAX(4, moveresize_client->size_inc.height);
294 XWarpPointer(ob_display, None, None, 0, 0, 0, 0, dx, dy);
297 } else if (corner == prop_atoms.net_wm_moveresize_move_keyboard) {
300 if (e->xkey.keycode == ob_keycode(OB_KEY_RIGHT))
302 else if (e->xkey.keycode == ob_keycode(OB_KEY_LEFT))
304 else if (e->xkey.keycode == ob_keycode(OB_KEY_DOWN))
306 else if (e->xkey.keycode == ob_keycode(OB_KEY_UP))
313 XWarpPointer(ob_display, None, None, 0, 0, 0, 0, dx, dy);