2 #include "framerender.h"
11 gboolean moveresize_in_progress = FALSE;
12 static gboolean moving = FALSE; /* TRUE - moving, FALSE - resizing */
14 static Window coords = None;
15 static int start_x, start_y, start_cx, start_cy, start_cw, start_ch;
16 static int cur_x, cur_y;
17 static Client *client;
19 static guint32 corner;
20 static Corner lockcorner;
25 static void popup_coords(char *format, int a, int b)
27 XSetWindowAttributes attrib;
32 attrib.override_redirect = TRUE;
33 coords = XCreateWindow(ob_display, ob_root,
34 0, 0, 1, 1, 0, render_depth, InputOutput,
35 render_visual, CWOverrideRedirect, &attrib);
36 g_assert(coords != None);
38 XMapWindow(ob_display, coords);
41 text = g_strdup_printf(format, a, b);
42 framerender_size_popup_label(text, &s);
43 XMoveResizeWindow(ob_display, coords,
44 POPUP_X, POPUP_Y, s.width, s.height);
45 framerender_popup_label(coords, &s, text);
49 void moveresize_start(Client *c, int x, int y, guint b, guint32 cnr)
53 g_assert(!moveresize_in_progress);
56 start_cx = c->frame->area.x;
57 start_cy = c->frame->area.y;
58 start_cw = c->area.width;
59 start_ch = c->area.height;
65 moveresize_in_progress = TRUE;
66 moving = (corner == prop_atoms.net_wm_moveresize_move ||
67 corner == prop_atoms.net_wm_moveresize_move_keyboard);
69 if (corner == prop_atoms.net_wm_moveresize_size_topleft)
71 else if (corner == prop_atoms.net_wm_moveresize_size_top)
73 else if (corner == prop_atoms.net_wm_moveresize_size_topright)
75 else if (corner == prop_atoms.net_wm_moveresize_size_right)
77 else if (corner == prop_atoms.net_wm_moveresize_size_bottomright)
79 else if (corner == prop_atoms.net_wm_moveresize_size_bottom)
81 else if (corner == prop_atoms.net_wm_moveresize_size_bottomleft)
83 else if (corner == prop_atoms.net_wm_moveresize_size_left)
85 else if (corner == prop_atoms.net_wm_moveresize_size_keyboard)
87 else if (corner == prop_atoms.net_wm_moveresize_move)
88 cur = ob_cursors.move;
89 else if (corner == prop_atoms.net_wm_moveresize_move_keyboard)
90 cur = ob_cursors.move;
92 g_assert_not_reached();
95 grab_pointer(TRUE, cur);
98 void moveresize_event(XEvent *e)
100 g_assert(moveresize_in_progress);
102 if (e->type == MotionNotify) {
104 cur_x = start_cx + e->xmotion.x_root - start_x;
105 cur_y = start_cy + e->xmotion.y_root - start_y;
107 dispatch_move(client, &cur_x, &cur_y);
109 popup_coords("X: %d Y: %d", cur_x, cur_y);
111 /* get where the client should be */
112 frame_frame_gravity(client->frame, &cur_x, &cur_y);
113 client_configure(client, Corner_TopLeft, cur_x, cur_y,
114 start_cw, start_ch, TRUE, FALSE);
116 if (corner == prop_atoms.net_wm_moveresize_size_topleft) {
117 cur_x = start_cw - (e->xmotion.x_root - start_x);
118 cur_y = start_ch - (e->xmotion.y_root - start_y);
119 lockcorner = Corner_BottomRight;
120 } else if (corner == prop_atoms.net_wm_moveresize_size_top) {
122 cur_y = start_ch - (e->xmotion.y_root - start_y);
123 lockcorner = Corner_BottomRight;
124 } else if (corner == prop_atoms.net_wm_moveresize_size_topright) {
125 cur_x = start_cw + (e->xmotion.x_root - start_x);
126 cur_y = start_ch - (e->xmotion.y_root - start_y);
127 lockcorner = Corner_BottomLeft;
128 } else if (corner == prop_atoms.net_wm_moveresize_size_right) {
129 cur_x = start_cw + (e->xmotion.x_root - start_x);
131 lockcorner = Corner_BottomLeft;
133 prop_atoms.net_wm_moveresize_size_bottomright) {
134 cur_x = start_cw + (e->xmotion.x_root - start_x);
135 cur_y = start_ch + (e->xmotion.y_root - start_y);
136 lockcorner = Corner_TopLeft;
137 } else if (corner == prop_atoms.net_wm_moveresize_size_bottom) {
139 cur_y = start_ch + (e->xmotion.y_root - start_y);
140 lockcorner = Corner_TopLeft;
142 prop_atoms.net_wm_moveresize_size_bottomleft) {
143 cur_x = start_cw - (e->xmotion.x_root - start_x);
144 cur_y = start_ch + (e->xmotion.y_root - start_y);
145 lockcorner = Corner_TopRight;
146 } else if (corner == prop_atoms.net_wm_moveresize_size_left) {
147 cur_x = start_cw - (e->xmotion.x_root - start_x);
149 lockcorner = Corner_TopRight;
150 } else if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
151 cur_x = start_cw + (e->xmotion.x_root - start_x);
152 cur_y = start_ch + (e->xmotion.y_root - start_y);
153 lockcorner = Corner_TopLeft;
155 g_assert_not_reached();
157 /* dispatch_resize needs the frame size */
158 cur_x += client->frame->size.left + client->frame->size.right;
159 cur_y += client->frame->size.top + client->frame->size.bottom;
161 dispatch_resize(client, &cur_x, &cur_y, lockcorner);
163 cur_x -= client->frame->size.left + client->frame->size.right;
164 cur_y -= client->frame->size.top + client->frame->size.bottom;
166 client_configure(client, lockcorner, client->area.x,
167 client->area.y, cur_x, cur_y, TRUE, FALSE);
169 popup_coords("W: %d H: %d", client->logical_size.width,
170 client->logical_size.height);
172 } else if (e->type == ButtonRelease) {
173 if (e->xbutton.button == button) {
174 grab_keyboard(FALSE);
175 grab_pointer(FALSE, None);
177 XDestroyWindow(ob_display, coords);
180 moveresize_in_progress = FALSE;
183 client_configure(client, Corner_TopLeft, cur_x, cur_y,
184 start_cw, start_ch, TRUE, TRUE);
186 client_configure(client, lockcorner, client->area.x,
187 client->area.y, cur_x, cur_y, TRUE, TRUE);
190 } else if (e->type == KeyPress) {