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
;
75 if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
||
76 corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
77 button
= 0; /* mouse can't end it without being pressed first */
82 if (corner
== prop_atoms
.net_wm_moveresize_move
||
83 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
93 moveresize_in_progress
= TRUE
;
95 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
)
97 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
99 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
101 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
103 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
105 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
107 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
109 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
111 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
113 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
114 cur
= ob_cursors
.move
;
115 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
116 cur
= ob_cursors
.move
;
118 g_assert_not_reached();
120 grab_pointer(TRUE
, cur
);
124 static void end_moveresize(gboolean cancel
)
126 grab_keyboard(FALSE
);
127 grab_pointer(FALSE
, None
);
129 XDestroyWindow(ob_display
, coords
);
132 moveresize_in_progress
= FALSE
;
135 client_configure(client
, Corner_TopLeft
, (cancel
? start_cx
: cur_x
),
136 (cancel
? start_cy
: cur_y
),
137 start_cw
, start_ch
, TRUE
, TRUE
);
139 client_configure(client
, lockcorner
, client
->area
.x
,
140 client
->area
.y
, (cancel
? start_cw
: cur_x
),
141 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
145 static void do_move()
147 dispatch_move(client
, &cur_x
, &cur_y
);
149 popup_coords("X: %d Y: %d", cur_x
, cur_y
);
151 /* get where the client should be */
152 frame_frame_gravity(client
->frame
, &cur_x
, &cur_y
);
153 client_configure(client
, Corner_TopLeft
, cur_x
, cur_y
,
154 start_cw
, start_ch
, TRUE
, FALSE
);
157 static void do_resize()
159 /* dispatch_resize needs the frame size */
160 cur_x
+= client
->frame
->size
.left
+ client
->frame
->size
.right
;
161 cur_y
+= client
->frame
->size
.top
+ client
->frame
->size
.bottom
;
163 dispatch_resize(client
, &cur_x
, &cur_y
, lockcorner
);
165 cur_x
-= client
->frame
->size
.left
+ client
->frame
->size
.right
;
166 cur_y
-= client
->frame
->size
.top
+ client
->frame
->size
.bottom
;
168 client_configure(client
, lockcorner
, client
->area
.x
,
169 client
->area
.y
, cur_x
, cur_y
, TRUE
, FALSE
);
171 popup_coords("W: %d H: %d", client
->logical_size
.width
,
172 client
->logical_size
.height
);
175 void moveresize_event(XEvent
*e
)
177 g_assert(moveresize_in_progress
);
179 if (e
->type
== ButtonPress
) {
181 start_x
= e
->xbutton
.x_root
;
182 start_y
= e
->xbutton
.y_root
;
183 button
= e
->xbutton
.button
; /* this will end it now */
185 } else if (e
->type
== ButtonRelease
) {
186 if (e
->xbutton
.button
== button
) {
187 end_moveresize(FALSE
);
189 } else if (e
->type
== MotionNotify
) {
191 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
192 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
195 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
196 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
197 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
198 lockcorner
= Corner_BottomRight
;
199 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
201 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
202 lockcorner
= Corner_BottomRight
;
203 } else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
) {
204 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
205 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
206 lockcorner
= Corner_BottomLeft
;
207 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
208 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
210 lockcorner
= Corner_BottomLeft
;
212 prop_atoms
.net_wm_moveresize_size_bottomright
) {
213 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
214 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
215 lockcorner
= Corner_TopLeft
;
216 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
218 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
219 lockcorner
= Corner_TopLeft
;
221 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
222 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
223 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
224 lockcorner
= Corner_TopRight
;
225 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
226 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
228 lockcorner
= Corner_TopRight
;
229 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
230 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
231 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
232 lockcorner
= Corner_TopLeft
;
234 g_assert_not_reached();
238 } else if (e
->type
== KeyPress
) {
239 if (e
->xkey
.keycode
== button_escape
)
240 end_moveresize(TRUE
);
241 else if (e
->xkey
.keycode
== button_return
)
242 end_moveresize(FALSE
);
244 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
245 if (e
->xkey
.keycode
== button_right
)
246 cur_x
+= MAX(4, client
->size_inc
.width
);
247 else if (e
->xkey
.keycode
== button_left
)
248 cur_x
-= MAX(4, client
->size_inc
.width
);
249 else if (e
->xkey
.keycode
== button_down
)
250 cur_y
+= MAX(4, client
->size_inc
.height
);
251 else if (e
->xkey
.keycode
== button_up
)
252 cur_y
-= MAX(4, client
->size_inc
.height
);
256 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
257 if (e
->xkey
.keycode
== button_right
)
259 else if (e
->xkey
.keycode
== button_left
)
261 else if (e
->xkey
.keycode
== button_down
)
263 else if (e
->xkey
.keycode
== button_up
)