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
;
31 static void client_dest(gpointer client
)
33 if (moveresize_client
== client
)
37 void moveresize_startup(gboolean reconfig
)
39 popup
= popup_new(FALSE
);
42 client_add_destructor(client_dest
);
45 void moveresize_shutdown(gboolean reconfig
)
48 client_remove_destructor(client_dest
);
54 static void popup_coords(ObClient
*c
, char *format
, int a
, int b
)
58 text
= g_strdup_printf(format
, a
, b
);
59 popup_position(popup
, CenterGravity
,
60 c
->frame
->area
.x
+ c
->frame
->size
.left
+
62 c
->frame
->area
.y
+ c
->frame
->size
.top
+
64 popup_show(popup
, text
, NULL
);
68 void moveresize_start(ObClient
*c
, int x
, int y
, guint b
, guint32 cnr
)
72 g_assert(!moveresize_in_progress
);
74 if (!c
->frame
->visible
)
77 moveresize_client
= c
;
78 start_cx
= c
->frame
->area
.x
;
79 start_cy
= c
->frame
->area
.y
;
80 /* these adjustments for the size_inc make resizing a terminal more
81 friendly. you essentially start the resize in the middle of the
82 increment instead of at 0, so you have to move half an increment
83 either way instead of a full increment one and 1 px the other. and this
84 is one large mother fucking comment. */
85 start_cw
= c
->area
.width
+ c
->size_inc
.width
/ 2;
86 start_ch
= c
->area
.height
+ c
->size_inc
.height
/ 2;
93 have to change start_cx and start_cy if going to do this..
94 if (corner == prop_atoms.net_wm_moveresize_move_keyboard ||
95 corner == prop_atoms.net_wm_moveresize_size_keyboard)
96 XWarpPointer(ob_display, None, c->window, 0, 0, 0, 0,
97 c->area.width / 2, c->area.height / 2);
100 if (corner
== prop_atoms
.net_wm_moveresize_move
||
101 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
111 moveresize_in_progress
= TRUE
;
113 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
)
114 cur
= OB_CURSOR_NORTHWEST
;
115 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
116 cur
= OB_CURSOR_NORTH
;
117 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
118 cur
= OB_CURSOR_NORTHEAST
;
119 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
120 cur
= OB_CURSOR_EAST
;
121 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
122 cur
= OB_CURSOR_SOUTHEAST
;
123 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
124 cur
= OB_CURSOR_SOUTH
;
125 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
126 cur
= OB_CURSOR_SOUTHWEST
;
127 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
128 cur
= OB_CURSOR_WEST
;
129 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
130 cur
= OB_CURSOR_SOUTHEAST
;
131 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
132 cur
= OB_CURSOR_MOVE
;
133 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
134 cur
= OB_CURSOR_MOVE
;
136 g_assert_not_reached();
138 grab_pointer(TRUE
, cur
);
142 void moveresize_end(gboolean cancel
)
144 grab_keyboard(FALSE
);
145 grab_pointer(FALSE
, OB_CURSOR_NONE
);
150 client_move(moveresize_client
,
151 (cancel
? start_cx
: cur_x
),
152 (cancel
? start_cy
: cur_y
));
154 client_configure(moveresize_client
, lockcorner
,
155 moveresize_client
->area
.x
,
156 moveresize_client
->area
.y
,
157 (cancel
? start_cw
: cur_x
),
158 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
161 moveresize_in_progress
= FALSE
;
162 moveresize_client
= NULL
;
165 static void do_move(gboolean resist
)
168 resist_move_windows(moveresize_client
, &cur_x
, &cur_y
);
169 resist_move_monitors(moveresize_client
, &cur_x
, &cur_y
);
171 /* get where the client should be */
172 frame_frame_gravity(moveresize_client
->frame
, &cur_x
, &cur_y
);
173 client_configure(moveresize_client
, OB_CORNER_TOPLEFT
, cur_x
, cur_y
,
174 moveresize_client
->area
.width
,
175 moveresize_client
->area
.height
, TRUE
, FALSE
);
178 static void do_resize(gboolean resist
)
180 /* resist_size_* needs the frame size */
181 cur_x
+= moveresize_client
->frame
->size
.left
+
182 moveresize_client
->frame
->size
.right
;
183 cur_y
+= moveresize_client
->frame
->size
.top
+
184 moveresize_client
->frame
->size
.bottom
;
187 resist_size_windows(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
188 resist_size_monitors(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
190 cur_x
-= moveresize_client
->frame
->size
.left
+
191 moveresize_client
->frame
->size
.right
;
192 cur_y
-= moveresize_client
->frame
->size
.top
+
193 moveresize_client
->frame
->size
.bottom
;
195 client_configure(moveresize_client
, lockcorner
,
196 moveresize_client
->area
.x
, moveresize_client
->area
.y
,
197 cur_x
, cur_y
, TRUE
, FALSE
);
199 /* this would be better with a fixed width font ... XXX can do it better
200 if there are 2 text boxes */
201 if (moveresize_client
->size_inc
.width
> 1 ||
202 moveresize_client
->size_inc
.height
> 1)
203 popup_coords(moveresize_client
, "%d x %d",
204 moveresize_client
->logical_size
.width
,
205 moveresize_client
->logical_size
.height
);
208 void moveresize_event(XEvent
*e
)
210 g_assert(moveresize_in_progress
);
212 if (e
->type
== ButtonPress
) {
214 start_x
= e
->xbutton
.x_root
;
215 start_y
= e
->xbutton
.y_root
;
216 button
= e
->xbutton
.button
; /* this will end it now */
218 } else if (e
->type
== ButtonRelease
) {
219 if (!button
|| e
->xbutton
.button
== button
) {
220 moveresize_end(FALSE
);
222 } else if (e
->type
== MotionNotify
) {
224 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
225 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
228 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
229 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
230 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
231 lockcorner
= OB_CORNER_BOTTOMRIGHT
;
232 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
234 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
235 lockcorner
= OB_CORNER_BOTTOMRIGHT
;
236 } else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
) {
237 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
238 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
239 lockcorner
= OB_CORNER_BOTTOMLEFT
;
240 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
241 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
243 lockcorner
= OB_CORNER_BOTTOMLEFT
;
245 prop_atoms
.net_wm_moveresize_size_bottomright
) {
246 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
247 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
248 lockcorner
= OB_CORNER_TOPLEFT
;
249 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
251 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
252 lockcorner
= OB_CORNER_TOPLEFT
;
254 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
255 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
256 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
257 lockcorner
= OB_CORNER_TOPRIGHT
;
258 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
259 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
261 lockcorner
= OB_CORNER_TOPRIGHT
;
262 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
263 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
264 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
265 lockcorner
= OB_CORNER_TOPLEFT
;
267 g_assert_not_reached();
271 } else if (e
->type
== KeyPress
) {
272 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
))
273 moveresize_end(TRUE
);
274 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
))
275 moveresize_end(FALSE
);
277 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
278 int dx
= 0, dy
= 0, ox
= cur_x
, oy
= cur_y
;
280 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
281 dx
= MAX(4, moveresize_client
->size_inc
.width
);
282 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
283 dx
= -MAX(4, moveresize_client
->size_inc
.width
);
284 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
285 dy
= MAX(4, moveresize_client
->size_inc
.height
);
286 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))
287 dy
= -MAX(4, moveresize_client
->size_inc
.height
);
293 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);
294 /* steal the motion events this causes */
295 XSync(ob_display
, FALSE
);
298 while (XCheckTypedEvent(ob_display
, MotionNotify
, &ce
));
303 /* because the cursor moves even though the window does
304 not nessesarily (resistance), this adjusts where the curor
305 thinks it started so that it keeps up with where the window
307 start_x
+= dx
- (cur_x
- ox
);
308 start_y
+= dy
- (cur_y
- oy
);
309 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
310 int dx
= 0, dy
= 0, ox
= cur_x
, oy
= cur_y
;
311 int opx
, px
, opy
, py
;
313 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
315 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
317 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
319 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))
326 screen_pointer_pos(&opx
, &opy
);
327 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);
328 /* steal the motion events this causes */
329 XSync(ob_display
, FALSE
);
332 while (XCheckTypedEvent(ob_display
, MotionNotify
, &ce
));
334 screen_pointer_pos(&px
, &py
);
338 /* because the cursor moves even though the window does
339 not nessesarily (resistance), this adjusts where the curor
340 thinks it started so that it keeps up with where the window
342 start_x
+= (px
- opx
) - (cur_x
- ox
);
343 start_y
+= (py
- opy
) - (cur_y
- oy
);