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
;
22 static guint button_return
, button_escape
, button_left
, button_right
,
23 button_up
, button_down
;
28 void moveresize_startup()
30 button_return
= XKeysymToKeycode(ob_display
, XStringToKeysym("Return"));
31 button_escape
= XKeysymToKeycode(ob_display
, XStringToKeysym("Escape"));
32 button_left
= XKeysymToKeycode(ob_display
, XStringToKeysym("Left"));
33 button_right
= XKeysymToKeycode(ob_display
, XStringToKeysym("Right"));
34 button_up
= XKeysymToKeycode(ob_display
, XStringToKeysym("Up"));
35 button_down
= XKeysymToKeycode(ob_display
, XStringToKeysym("Down"));
38 static void popup_coords(char *format
, int a
, int b
)
40 XSetWindowAttributes attrib
;
45 attrib
.override_redirect
= TRUE
;
46 coords
= XCreateWindow(ob_display
, ob_root
,
47 0, 0, 1, 1, 0, render_depth
, InputOutput
,
48 render_visual
, CWOverrideRedirect
, &attrib
);
49 g_assert(coords
!= None
);
51 XMapWindow(ob_display
, coords
);
54 text
= g_strdup_printf(format
, a
, b
);
55 framerender_size_popup_label(text
, &s
);
56 XMoveResizeWindow(ob_display
, coords
,
57 POPUP_X
, POPUP_Y
, s
.width
, s
.height
);
58 framerender_popup_label(coords
, &s
, text
);
62 void moveresize_start(Client
*c
, int x
, int y
, guint b
, guint32 cnr
)
66 g_assert(!moveresize_in_progress
);
69 start_cx
= c
->frame
->area
.x
;
70 start_cy
= c
->frame
->area
.y
;
71 start_cw
= c
->area
.width
;
72 start_ch
= c
->area
.height
;
73 if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
||
74 corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
75 button
= 0; /* mouse can't end it without being pressed first */
80 if (corner
== prop_atoms
.net_wm_moveresize_move
||
81 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
91 moveresize_in_progress
= TRUE
;
93 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
)
95 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
97 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
99 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
101 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
103 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
105 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
107 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
109 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
111 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
112 cur
= ob_cursors
.move
;
113 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
114 cur
= ob_cursors
.move
;
116 g_assert_not_reached();
119 grab_pointer(TRUE
, cur
);
122 static void end_moveresize(gboolean cancel
)
124 grab_keyboard(FALSE
);
125 grab_pointer(FALSE
, None
);
127 XDestroyWindow(ob_display
, coords
);
130 moveresize_in_progress
= FALSE
;
133 client_configure(client
, Corner_TopLeft
, (cancel
? start_cx
: cur_x
),
134 (cancel
? start_cy
: cur_y
),
135 start_cw
, start_ch
, TRUE
, TRUE
);
137 client_configure(client
, lockcorner
, client
->area
.x
,
138 client
->area
.y
, (cancel
? start_cw
: cur_x
),
139 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
143 static void do_move()
145 dispatch_move(client
, &cur_x
, &cur_y
);
147 popup_coords("X: %d Y: %d", cur_x
, cur_y
);
149 /* get where the client should be */
150 frame_frame_gravity(client
->frame
, &cur_x
, &cur_y
);
151 client_configure(client
, Corner_TopLeft
, cur_x
, cur_y
,
152 start_cw
, start_ch
, TRUE
, FALSE
);
155 static void do_resize()
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
);
173 void moveresize_event(XEvent
*e
)
175 g_assert(moveresize_in_progress
);
177 if (e
->type
== ButtonPress
) {
179 start_x
= e
->xbutton
.x_root
;
180 start_y
= e
->xbutton
.y_root
;
181 button
= e
->xbutton
.button
; /* this will end it now */
183 } else if (e
->type
== ButtonRelease
) {
184 if (e
->xbutton
.button
== button
) {
185 end_moveresize(FALSE
);
187 } else if (e
->type
== MotionNotify
) {
189 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
190 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
194 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
195 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
196 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
197 lockcorner
= Corner_BottomRight
;
198 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
200 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
201 lockcorner
= Corner_BottomRight
;
202 } else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
) {
203 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
204 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
205 lockcorner
= Corner_BottomLeft
;
206 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
207 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
209 lockcorner
= Corner_BottomLeft
;
211 prop_atoms
.net_wm_moveresize_size_bottomright
) {
212 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
213 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
214 lockcorner
= Corner_TopLeft
;
215 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
217 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
218 lockcorner
= Corner_TopLeft
;
220 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
221 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
222 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
223 lockcorner
= Corner_TopRight
;
224 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
225 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
227 lockcorner
= Corner_TopRight
;
228 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
229 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
230 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
231 lockcorner
= Corner_TopLeft
;
233 g_assert_not_reached();
237 } else if (e
->type
== KeyPress
) {
238 if (e
->xkey
.keycode
== button_escape
)
239 end_moveresize(TRUE
);
240 else if (e
->xkey
.keycode
== button_return
)
241 end_moveresize(FALSE
);
243 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
244 if (e
->xkey
.keycode
== button_right
)
245 cur_x
+= MAX(4, client
->size_inc
.width
);
246 else if (e
->xkey
.keycode
== button_left
)
247 cur_x
-= MAX(4, client
->size_inc
.width
);
248 else if (e
->xkey
.keycode
== button_down
)
249 cur_y
+= MAX(4, client
->size_inc
.height
);
250 else if (e
->xkey
.keycode
== button_up
)
251 cur_y
-= MAX(4, client
->size_inc
.height
);
255 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
256 if (e
->xkey
.keycode
== button_right
)
258 else if (e
->xkey
.keycode
== button_left
)
260 else if (e
->xkey
.keycode
== button_down
)
262 else if (e
->xkey
.keycode
== button_up
)