2 #include "framerender.h"
9 #include "render/render.h"
10 #include "render/theme.h"
15 gboolean moveresize_in_progress
= FALSE
;
16 Client
*moveresize_client
= NULL
;
18 static gboolean moving
= FALSE
; /* TRUE - moving, FALSE - resizing */
20 static int start_x
, start_y
, start_cx
, start_cy
, start_cw
, start_ch
;
21 static int cur_x
, cur_y
;
23 static guint32 corner
;
24 static Corner lockcorner
;
26 static guint button_return
, button_escape
, button_left
, button_right
,
27 button_up
, button_down
;
29 static Popup
*popup
= NULL
;
30 static InternalWindow opaque_window
= { { Window_Internal
}, None
};
31 static GC opaque_gc
= None
;
32 static gboolean first_draw
= FALSE
;
37 gboolean config_opaque_move
= FALSE
;
38 gboolean config_opaque_resize
= FALSE
;
40 void moveresize_startup()
42 XSetWindowAttributes attrib
;
45 button_return
= XKeysymToKeycode(ob_display
, XStringToKeysym("Return"));
46 button_escape
= XKeysymToKeycode(ob_display
, XStringToKeysym("Escape"));
47 button_left
= XKeysymToKeycode(ob_display
, XStringToKeysym("Left"));
48 button_right
= XKeysymToKeycode(ob_display
, XStringToKeysym("Right"));
49 button_up
= XKeysymToKeycode(ob_display
, XStringToKeysym("Up"));
50 button_down
= XKeysymToKeycode(ob_display
, XStringToKeysym("Down"));
52 popup
= popup_new(FALSE
);
53 popup_size_to_string(popup
, "W: 0000 W: 0000");
54 popup_position(popup
, NorthWestGravity
, POPUP_X
, POPUP_Y
);
56 attrib
.save_under
= True
;
57 opaque_window
.win
= XCreateWindow(ob_display
, ob_root
, 0, 0, 1, 1, 0,
58 render_depth
, InputOutput
, render_visual
,
59 CWSaveUnder
, &attrib
);
60 stacking_add(&opaque_window
);
61 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window
));
63 /* a GC to invert stuff */
65 gcv
.line_width
= theme_bwidth
;
66 gcv
.foreground
= (WhitePixel(ob_display
, ob_screen
) ^
67 BlackPixel(ob_display
, ob_screen
));
68 opaque_gc
= XCreateGC(ob_display
, opaque_window
.win
,
69 GCFunction
| GCForeground
| GCLineWidth
, &gcv
);
72 void moveresize_shutdown()
76 stacking_remove(&opaque_window
);
77 XFreeGC(ob_display
, opaque_gc
);
78 XDestroyWindow(ob_display
, opaque_window
.win
);
81 static void popup_coords(char *format
, int a
, int b
)
85 text
= g_strdup_printf(format
, a
, b
);
86 popup_show(popup
, text
, NULL
);
90 void moveresize_start(Client
*c
, int x
, int y
, guint b
, guint32 cnr
)
94 g_assert(!moveresize_in_progress
);
96 moveresize_client
= c
;
97 start_cx
= c
->frame
->area
.x
;
98 start_cy
= c
->frame
->area
.y
;
99 start_cw
= c
->area
.width
;
100 start_ch
= c
->area
.height
;
103 if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
||
104 corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
105 button
= 0; /* mouse can't end it without being pressed first */
110 if (corner
== prop_atoms
.net_wm_moveresize_move
||
111 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
121 moveresize_in_progress
= TRUE
;
123 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
)
125 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
127 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
129 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
131 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
133 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
135 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
137 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
139 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
141 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
142 cur
= ob_cursors
.move
;
143 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
144 cur
= ob_cursors
.move
;
146 g_assert_not_reached();
148 grab_pointer(TRUE
, cur
);
151 XResizeWindow(ob_display
, opaque_window
.win
, screen_physical_size
.width
,
152 screen_physical_size
.height
);
153 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window
));
154 if (corner
== prop_atoms
.net_wm_moveresize_move
||
155 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
156 if (!config_opaque_move
)
157 XMapWindow(ob_display
, opaque_window
.win
);
159 if (!config_opaque_resize
)
160 XMapWindow(ob_display
, opaque_window
.win
);
165 void moveresize_end(gboolean cancel
)
167 XUnmapWindow(ob_display
, opaque_window
.win
);
169 grab_keyboard(FALSE
);
170 grab_pointer(FALSE
, None
);
175 client_configure(moveresize_client
, Corner_TopLeft
,
176 (cancel
? start_cx
: cur_x
),
177 (cancel
? start_cy
: cur_y
),
178 start_cw
, start_ch
, TRUE
, TRUE
);
180 client_configure(moveresize_client
, lockcorner
,
181 moveresize_client
->area
.x
,
182 moveresize_client
->area
.y
,
183 (cancel
? start_cw
: cur_x
),
184 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
187 moveresize_in_progress
= FALSE
;
188 moveresize_client
= NULL
;
191 static void do_move()
193 int oldx
, oldy
, oldw
, oldh
;
195 dispatch_move(moveresize_client
, &cur_x
, &cur_y
);
197 oldx
= moveresize_client
->frame
->area
.x
;
198 oldy
= moveresize_client
->frame
->area
.y
;
199 oldw
= moveresize_client
->frame
->area
.width
;
200 oldh
= moveresize_client
->frame
->area
.height
;
201 /* get where the client should be */
202 frame_frame_gravity(moveresize_client
->frame
, &cur_x
, &cur_y
);
203 client_configure(moveresize_client
, Corner_TopLeft
, cur_x
, cur_y
,
204 start_cw
, start_ch
, TRUE
, FALSE
);
205 /* draw the new one */
206 if (!config_opaque_move
)
207 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
208 moveresize_client
->frame
->area
.x
,
209 moveresize_client
->frame
->area
.y
,
210 moveresize_client
->frame
->area
.width
- 1,
211 moveresize_client
->frame
->area
.height
- 1);
212 /* erase the old one */
213 if (!config_opaque_move
&& !first_draw
)
214 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
215 oldx
, oldy
, oldw
- 1, oldh
- 1);
218 /* this would be better with a fixed width font ... XXX can do it better
219 if there are 2 text boxes */
220 popup_coords("X: %4d Y: %4d", moveresize_client
->frame
->area
.x
,
221 moveresize_client
->frame
->area
.y
);
224 static void do_resize()
226 int oldx
, oldy
, oldw
, oldh
;
228 /* dispatch_resize needs the frame size */
229 cur_x
+= moveresize_client
->frame
->size
.left
+
230 moveresize_client
->frame
->size
.right
;
231 cur_y
+= moveresize_client
->frame
->size
.top
+
232 moveresize_client
->frame
->size
.bottom
;
234 dispatch_resize(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
236 cur_x
-= moveresize_client
->frame
->size
.left
+
237 moveresize_client
->frame
->size
.right
;
238 cur_y
-= moveresize_client
->frame
->size
.top
+
239 moveresize_client
->frame
->size
.bottom
;
241 oldx
= moveresize_client
->frame
->area
.x
;
242 oldy
= moveresize_client
->frame
->area
.y
;
243 oldw
= moveresize_client
->frame
->area
.width
;
244 oldh
= moveresize_client
->frame
->area
.height
;
245 client_configure(moveresize_client
, lockcorner
,
246 moveresize_client
->area
.x
, moveresize_client
->area
.y
,
247 cur_x
, cur_y
, TRUE
, FALSE
);
248 /* draw the new one */
249 if (!config_opaque_resize
)
250 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
251 moveresize_client
->frame
->area
.x
,
252 moveresize_client
->frame
->area
.y
,
253 moveresize_client
->frame
->area
.width
- 1,
254 moveresize_client
->frame
->area
.height
- 1);
255 /* erase the old one */
256 if (!config_opaque_resize
&& !first_draw
)
257 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
258 oldx
, oldy
, oldw
- 1, oldh
- 1);
261 /* this would be better with a fixed width font ... XXX can do it better
262 if there are 2 text boxes */
263 popup_coords("W: %4d H: %4d", moveresize_client
->logical_size
.width
,
264 moveresize_client
->logical_size
.height
);
267 void moveresize_event(XEvent
*e
)
269 g_assert(moveresize_in_progress
);
271 if (e
->type
== ButtonPress
) {
273 start_x
= e
->xbutton
.x_root
;
274 start_y
= e
->xbutton
.y_root
;
275 button
= e
->xbutton
.button
; /* this will end it now */
277 } else if (e
->type
== ButtonRelease
) {
278 if (!button
|| e
->xbutton
.button
== button
) {
279 moveresize_end(FALSE
);
281 } else if (e
->type
== MotionNotify
) {
283 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
284 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
287 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
288 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
289 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
290 lockcorner
= Corner_BottomRight
;
291 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
293 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
294 lockcorner
= Corner_BottomRight
;
295 } else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
) {
296 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
297 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
298 lockcorner
= Corner_BottomLeft
;
299 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
300 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
302 lockcorner
= Corner_BottomLeft
;
304 prop_atoms
.net_wm_moveresize_size_bottomright
) {
305 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
306 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
307 lockcorner
= Corner_TopLeft
;
308 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
310 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
311 lockcorner
= Corner_TopLeft
;
313 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
314 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
315 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
316 lockcorner
= Corner_TopRight
;
317 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
318 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
320 lockcorner
= Corner_TopRight
;
321 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
322 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
323 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
324 lockcorner
= Corner_TopLeft
;
326 g_assert_not_reached();
330 } else if (e
->type
== KeyPress
) {
331 if (e
->xkey
.keycode
== button_escape
)
332 moveresize_end(TRUE
);
333 else if (e
->xkey
.keycode
== button_return
)
334 moveresize_end(FALSE
);
336 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
337 if (e
->xkey
.keycode
== button_right
)
338 cur_x
+= MAX(4, moveresize_client
->size_inc
.width
);
339 else if (e
->xkey
.keycode
== button_left
)
340 cur_x
-= MAX(4, moveresize_client
->size_inc
.width
);
341 else if (e
->xkey
.keycode
== button_down
)
342 cur_y
+= MAX(4, moveresize_client
->size_inc
.height
);
343 else if (e
->xkey
.keycode
== button_up
)
344 cur_y
-= MAX(4, moveresize_client
->size_inc
.height
);
348 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
349 if (e
->xkey
.keycode
== button_right
)
351 else if (e
->xkey
.keycode
== button_left
)
353 else if (e
->xkey
.keycode
== button_down
)
355 else if (e
->xkey
.keycode
== button_up
)