2 #include "framerender.h"
10 #include "render/render.h"
11 #include "render/theme.h"
16 gboolean moveresize_in_progress
= FALSE
;
17 Client
*moveresize_client
= NULL
;
19 static gboolean moving
= FALSE
; /* TRUE - moving, FALSE - resizing */
21 static int start_x
, start_y
, start_cx
, start_cy
, start_cw
, start_ch
;
22 static int cur_x
, cur_y
;
24 static guint32 corner
;
25 static Corner lockcorner
;
27 static guint button_return
, button_escape
, button_left
, button_right
,
28 button_up
, button_down
;
30 static Popup
*popup
= NULL
;
31 static InternalWindow opaque_window
= { { Window_Internal
}, None
};
32 static GC opaque_gc
= None
;
33 static gboolean first_draw
= FALSE
;
38 void moveresize_startup()
40 XSetWindowAttributes attrib
;
43 button_return
= XKeysymToKeycode(ob_display
, XStringToKeysym("Return"));
44 button_escape
= XKeysymToKeycode(ob_display
, XStringToKeysym("Escape"));
45 button_left
= XKeysymToKeycode(ob_display
, XStringToKeysym("Left"));
46 button_right
= XKeysymToKeycode(ob_display
, XStringToKeysym("Right"));
47 button_up
= XKeysymToKeycode(ob_display
, XStringToKeysym("Up"));
48 button_down
= XKeysymToKeycode(ob_display
, XStringToKeysym("Down"));
50 popup
= popup_new(FALSE
);
51 popup_size_to_string(popup
, "W: 0000 W: 0000");
53 attrib
.save_under
= True
;
54 opaque_window
.win
= XCreateWindow(ob_display
, ob_root
, 0, 0, 1, 1, 0,
55 RrDepth(ob_rr_inst
), InputOutput
,
57 CWSaveUnder
, &attrib
);
58 stacking_add(INTERNAL_AS_WINDOW(&opaque_window
));
59 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window
));
61 /* a GC to invert stuff */
63 gcv
.line_width
= ob_rr_theme
->bwidth
;
64 gcv
.foreground
= (WhitePixel(ob_display
, ob_screen
) ^
65 BlackPixel(ob_display
, ob_screen
));
66 opaque_gc
= XCreateGC(ob_display
, opaque_window
.win
,
67 GCFunction
| GCForeground
| GCLineWidth
, &gcv
);
70 void moveresize_shutdown()
74 stacking_remove(&opaque_window
);
75 XFreeGC(ob_display
, opaque_gc
);
76 XDestroyWindow(ob_display
, opaque_window
.win
);
79 static void popup_coords(char *format
, int a
, int b
)
84 text
= g_strdup_printf(format
, a
, b
);
85 area
= screen_physical_area_xinerama(0);
86 popup_position(popup
, NorthWestGravity
,
87 POPUP_X
+ area
->x
, POPUP_Y
+ area
->y
);
88 popup_show(popup
, text
, NULL
);
92 void moveresize_start(Client
*c
, int x
, int y
, guint b
, guint32 cnr
)
97 g_assert(!moveresize_in_progress
);
99 moveresize_client
= c
;
100 start_cx
= c
->frame
->area
.x
;
101 start_cy
= c
->frame
->area
.y
;
102 start_cw
= c
->area
.width
;
103 start_ch
= c
->area
.height
;
106 if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
||
107 corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
108 button
= 0; /* mouse can't end it without being pressed first */
113 if (corner
== prop_atoms
.net_wm_moveresize_move
||
114 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
124 moveresize_in_progress
= TRUE
;
126 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
)
128 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
130 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
132 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
134 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
136 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
138 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
140 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
142 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
144 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
145 cur
= ob_cursors
.move
;
146 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
147 cur
= ob_cursors
.move
;
149 g_assert_not_reached();
151 grab_pointer(TRUE
, cur
);
154 a
= screen_physical_area();
156 XMoveResizeWindow(ob_display
, opaque_window
.win
,
157 a
->x
, a
->y
, a
->width
, a
->height
);
158 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window
));
159 if (corner
== prop_atoms
.net_wm_moveresize_move
||
160 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
161 if (!config_opaque_move
)
162 XMapWindow(ob_display
, opaque_window
.win
);
164 if (!config_opaque_resize
)
165 XMapWindow(ob_display
, opaque_window
.win
);
170 void moveresize_end(gboolean cancel
)
172 XUnmapWindow(ob_display
, opaque_window
.win
);
174 grab_keyboard(FALSE
);
175 grab_pointer(FALSE
, None
);
180 client_configure(moveresize_client
, Corner_TopLeft
,
181 (cancel
? start_cx
: cur_x
),
182 (cancel
? start_cy
: cur_y
),
183 start_cw
, start_ch
, TRUE
, TRUE
);
185 client_configure(moveresize_client
, lockcorner
,
186 moveresize_client
->area
.x
,
187 moveresize_client
->area
.y
,
188 (cancel
? start_cw
: cur_x
),
189 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
192 moveresize_in_progress
= FALSE
;
193 moveresize_client
= NULL
;
196 static void do_move()
198 int oldx
, oldy
, oldw
, oldh
;
200 dispatch_move(moveresize_client
, &cur_x
, &cur_y
);
202 oldx
= moveresize_client
->frame
->area
.x
;
203 oldy
= moveresize_client
->frame
->area
.y
;
204 oldw
= moveresize_client
->frame
->area
.width
;
205 oldh
= moveresize_client
->frame
->area
.height
;
206 /* get where the client should be */
207 frame_frame_gravity(moveresize_client
->frame
, &cur_x
, &cur_y
);
208 client_configure(moveresize_client
, Corner_TopLeft
, cur_x
, cur_y
,
209 start_cw
, start_ch
, TRUE
, FALSE
);
210 /* draw the new one */
211 if (moveresize_client
->frame
->area
.x
!= oldx
||
212 moveresize_client
->frame
->area
.y
!= oldy
||
213 moveresize_client
->frame
->area
.width
!= oldw
||
214 moveresize_client
->frame
->area
.height
!= oldh
) {
215 if (!config_opaque_move
)
216 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
217 moveresize_client
->frame
->area
.x
,
218 moveresize_client
->frame
->area
.y
,
219 moveresize_client
->frame
->area
.width
- 1,
220 moveresize_client
->frame
->area
.height
- 1);
221 /* erase the old one */
222 if (!config_opaque_move
&& !first_draw
)
223 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
224 oldx
, oldy
, oldw
- 1, oldh
- 1);
228 /* this would be better with a fixed width font ... XXX can do it better
229 if there are 2 text boxes */
230 popup_coords("X: %4d Y: %4d", moveresize_client
->frame
->area
.x
,
231 moveresize_client
->frame
->area
.y
);
234 static void do_resize()
236 int oldx
, oldy
, oldw
, oldh
;
238 /* dispatch_resize needs the frame size */
239 cur_x
+= moveresize_client
->frame
->size
.left
+
240 moveresize_client
->frame
->size
.right
;
241 cur_y
+= moveresize_client
->frame
->size
.top
+
242 moveresize_client
->frame
->size
.bottom
;
244 dispatch_resize(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
246 cur_x
-= moveresize_client
->frame
->size
.left
+
247 moveresize_client
->frame
->size
.right
;
248 cur_y
-= moveresize_client
->frame
->size
.top
+
249 moveresize_client
->frame
->size
.bottom
;
251 oldx
= moveresize_client
->frame
->area
.x
;
252 oldy
= moveresize_client
->frame
->area
.y
;
253 oldw
= moveresize_client
->frame
->area
.width
;
254 oldh
= moveresize_client
->frame
->area
.height
;
255 client_configure(moveresize_client
, lockcorner
,
256 moveresize_client
->area
.x
, moveresize_client
->area
.y
,
257 cur_x
, cur_y
, TRUE
, FALSE
);
258 /* draw the new one */
259 if (!config_opaque_resize
)
260 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
261 moveresize_client
->frame
->area
.x
,
262 moveresize_client
->frame
->area
.y
,
263 moveresize_client
->frame
->area
.width
- 1,
264 moveresize_client
->frame
->area
.height
- 1);
265 /* erase the old one */
266 if (!config_opaque_resize
&& !first_draw
)
267 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
268 oldx
, oldy
, oldw
- 1, oldh
- 1);
271 /* this would be better with a fixed width font ... XXX can do it better
272 if there are 2 text boxes */
273 popup_coords("W: %4d H: %4d", moveresize_client
->logical_size
.width
,
274 moveresize_client
->logical_size
.height
);
277 void moveresize_event(XEvent
*e
)
279 g_assert(moveresize_in_progress
);
281 if (e
->type
== ButtonPress
) {
283 start_x
= e
->xbutton
.x_root
;
284 start_y
= e
->xbutton
.y_root
;
285 button
= e
->xbutton
.button
; /* this will end it now */
287 } else if (e
->type
== ButtonRelease
) {
288 if (!button
|| e
->xbutton
.button
== button
) {
289 moveresize_end(FALSE
);
291 } else if (e
->type
== MotionNotify
) {
293 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
294 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
297 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
298 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
299 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
300 lockcorner
= Corner_BottomRight
;
301 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
303 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
304 lockcorner
= Corner_BottomRight
;
305 } else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
) {
306 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
307 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
308 lockcorner
= Corner_BottomLeft
;
309 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
310 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
312 lockcorner
= Corner_BottomLeft
;
314 prop_atoms
.net_wm_moveresize_size_bottomright
) {
315 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
316 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
317 lockcorner
= Corner_TopLeft
;
318 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
320 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
321 lockcorner
= Corner_TopLeft
;
323 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
324 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
325 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
326 lockcorner
= Corner_TopRight
;
327 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
328 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
330 lockcorner
= Corner_TopRight
;
331 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
332 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
333 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
334 lockcorner
= Corner_TopLeft
;
336 g_assert_not_reached();
340 } else if (e
->type
== KeyPress
) {
341 if (e
->xkey
.keycode
== button_escape
)
342 moveresize_end(TRUE
);
343 else if (e
->xkey
.keycode
== button_return
)
344 moveresize_end(FALSE
);
346 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
347 if (e
->xkey
.keycode
== button_right
)
348 cur_x
+= MAX(4, moveresize_client
->size_inc
.width
);
349 else if (e
->xkey
.keycode
== button_left
)
350 cur_x
-= MAX(4, moveresize_client
->size_inc
.width
);
351 else if (e
->xkey
.keycode
== button_down
)
352 cur_y
+= MAX(4, moveresize_client
->size_inc
.height
);
353 else if (e
->xkey
.keycode
== button_up
)
354 cur_y
-= MAX(4, moveresize_client
->size_inc
.height
);
358 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
359 if (e
->xkey
.keycode
== button_right
)
361 else if (e
->xkey
.keycode
== button_left
)
363 else if (e
->xkey
.keycode
== button_down
)
365 else if (e
->xkey
.keycode
== button_up
)