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");
52 popup_position(popup
, NorthWestGravity
, POPUP_X
, POPUP_Y
);
54 attrib
.save_under
= True
;
55 opaque_window
.win
= XCreateWindow(ob_display
, ob_root
, 0, 0, 1, 1, 0,
56 RrDepth(ob_rr_inst
), InputOutput
,
58 CWSaveUnder
, &attrib
);
59 stacking_add(INTERNAL_AS_WINDOW(&opaque_window
));
60 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window
));
62 /* a GC to invert stuff */
64 gcv
.line_width
= ob_rr_theme
->bwidth
;
65 gcv
.foreground
= (WhitePixel(ob_display
, ob_screen
) ^
66 BlackPixel(ob_display
, ob_screen
));
67 opaque_gc
= XCreateGC(ob_display
, opaque_window
.win
,
68 GCFunction
| GCForeground
| GCLineWidth
, &gcv
);
71 void moveresize_shutdown()
75 stacking_remove(&opaque_window
);
76 XFreeGC(ob_display
, opaque_gc
);
77 XDestroyWindow(ob_display
, opaque_window
.win
);
80 static void popup_coords(char *format
, int a
, int b
)
84 text
= g_strdup_printf(format
, a
, b
);
85 popup_show(popup
, text
, NULL
);
89 void moveresize_start(Client
*c
, int x
, int y
, guint b
, guint32 cnr
)
93 g_assert(!moveresize_in_progress
);
95 moveresize_client
= c
;
96 start_cx
= c
->frame
->area
.x
;
97 start_cy
= c
->frame
->area
.y
;
98 start_cw
= c
->area
.width
;
99 start_ch
= c
->area
.height
;
102 if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
||
103 corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
104 button
= 0; /* mouse can't end it without being pressed first */
109 if (corner
== prop_atoms
.net_wm_moveresize_move
||
110 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
120 moveresize_in_progress
= TRUE
;
122 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
)
124 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
126 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
128 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
130 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
132 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
134 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
136 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
138 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
140 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
141 cur
= ob_cursors
.move
;
142 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
143 cur
= ob_cursors
.move
;
145 g_assert_not_reached();
147 grab_pointer(TRUE
, cur
);
150 XResizeWindow(ob_display
, opaque_window
.win
, screen_physical_size
.width
,
151 screen_physical_size
.height
);
152 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window
));
153 if (corner
== prop_atoms
.net_wm_moveresize_move
||
154 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
155 if (!config_opaque_move
)
156 XMapWindow(ob_display
, opaque_window
.win
);
158 if (!config_opaque_resize
)
159 XMapWindow(ob_display
, opaque_window
.win
);
164 void moveresize_end(gboolean cancel
)
166 XUnmapWindow(ob_display
, opaque_window
.win
);
168 grab_keyboard(FALSE
);
169 grab_pointer(FALSE
, None
);
174 client_configure(moveresize_client
, Corner_TopLeft
,
175 (cancel
? start_cx
: cur_x
),
176 (cancel
? start_cy
: cur_y
),
177 start_cw
, start_ch
, TRUE
, TRUE
);
179 client_configure(moveresize_client
, lockcorner
,
180 moveresize_client
->area
.x
,
181 moveresize_client
->area
.y
,
182 (cancel
? start_cw
: cur_x
),
183 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
186 moveresize_in_progress
= FALSE
;
187 moveresize_client
= NULL
;
190 static void do_move()
192 int oldx
, oldy
, oldw
, oldh
;
194 dispatch_move(moveresize_client
, &cur_x
, &cur_y
);
196 oldx
= moveresize_client
->frame
->area
.x
;
197 oldy
= moveresize_client
->frame
->area
.y
;
198 oldw
= moveresize_client
->frame
->area
.width
;
199 oldh
= moveresize_client
->frame
->area
.height
;
200 /* get where the client should be */
201 frame_frame_gravity(moveresize_client
->frame
, &cur_x
, &cur_y
);
202 client_configure(moveresize_client
, Corner_TopLeft
, cur_x
, cur_y
,
203 start_cw
, start_ch
, TRUE
, FALSE
);
204 /* draw the new one */
205 if (moveresize_client
->frame
->area
.x
!= oldx
||
206 moveresize_client
->frame
->area
.y
!= oldy
||
207 moveresize_client
->frame
->area
.width
!= oldw
||
208 moveresize_client
->frame
->area
.height
!= oldh
) {
209 if (!config_opaque_move
)
210 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
211 moveresize_client
->frame
->area
.x
,
212 moveresize_client
->frame
->area
.y
,
213 moveresize_client
->frame
->area
.width
- 1,
214 moveresize_client
->frame
->area
.height
- 1);
215 /* erase the old one */
216 if (!config_opaque_move
&& !first_draw
)
217 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
218 oldx
, oldy
, oldw
- 1, oldh
- 1);
222 /* this would be better with a fixed width font ... XXX can do it better
223 if there are 2 text boxes */
224 popup_coords("X: %4d Y: %4d", moveresize_client
->frame
->area
.x
,
225 moveresize_client
->frame
->area
.y
);
228 static void do_resize()
230 int oldx
, oldy
, oldw
, oldh
;
232 /* dispatch_resize needs the frame size */
233 cur_x
+= moveresize_client
->frame
->size
.left
+
234 moveresize_client
->frame
->size
.right
;
235 cur_y
+= moveresize_client
->frame
->size
.top
+
236 moveresize_client
->frame
->size
.bottom
;
238 dispatch_resize(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
240 cur_x
-= moveresize_client
->frame
->size
.left
+
241 moveresize_client
->frame
->size
.right
;
242 cur_y
-= moveresize_client
->frame
->size
.top
+
243 moveresize_client
->frame
->size
.bottom
;
245 oldx
= moveresize_client
->frame
->area
.x
;
246 oldy
= moveresize_client
->frame
->area
.y
;
247 oldw
= moveresize_client
->frame
->area
.width
;
248 oldh
= moveresize_client
->frame
->area
.height
;
249 client_configure(moveresize_client
, lockcorner
,
250 moveresize_client
->area
.x
, moveresize_client
->area
.y
,
251 cur_x
, cur_y
, TRUE
, FALSE
);
252 /* draw the new one */
253 if (!config_opaque_resize
)
254 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
255 moveresize_client
->frame
->area
.x
,
256 moveresize_client
->frame
->area
.y
,
257 moveresize_client
->frame
->area
.width
- 1,
258 moveresize_client
->frame
->area
.height
- 1);
259 /* erase the old one */
260 if (!config_opaque_resize
&& !first_draw
)
261 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
262 oldx
, oldy
, oldw
- 1, oldh
- 1);
265 /* this would be better with a fixed width font ... XXX can do it better
266 if there are 2 text boxes */
267 popup_coords("W: %4d H: %4d", moveresize_client
->logical_size
.width
,
268 moveresize_client
->logical_size
.height
);
271 void moveresize_event(XEvent
*e
)
273 g_assert(moveresize_in_progress
);
275 if (e
->type
== ButtonPress
) {
277 start_x
= e
->xbutton
.x_root
;
278 start_y
= e
->xbutton
.y_root
;
279 button
= e
->xbutton
.button
; /* this will end it now */
281 } else if (e
->type
== ButtonRelease
) {
282 if (!button
|| e
->xbutton
.button
== button
) {
283 moveresize_end(FALSE
);
285 } else if (e
->type
== MotionNotify
) {
287 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
288 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
291 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
292 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
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_top
) {
297 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
298 lockcorner
= Corner_BottomRight
;
299 } else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
) {
300 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
301 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
302 lockcorner
= Corner_BottomLeft
;
303 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
304 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
306 lockcorner
= Corner_BottomLeft
;
308 prop_atoms
.net_wm_moveresize_size_bottomright
) {
309 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
310 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
311 lockcorner
= Corner_TopLeft
;
312 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
314 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
315 lockcorner
= Corner_TopLeft
;
317 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
318 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
319 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
320 lockcorner
= Corner_TopRight
;
321 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
322 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
324 lockcorner
= Corner_TopRight
;
325 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
326 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
327 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
328 lockcorner
= Corner_TopLeft
;
330 g_assert_not_reached();
334 } else if (e
->type
== KeyPress
) {
335 if (e
->xkey
.keycode
== button_escape
)
336 moveresize_end(TRUE
);
337 else if (e
->xkey
.keycode
== button_return
)
338 moveresize_end(FALSE
);
340 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
341 if (e
->xkey
.keycode
== button_right
)
342 cur_x
+= MAX(4, moveresize_client
->size_inc
.width
);
343 else if (e
->xkey
.keycode
== button_left
)
344 cur_x
-= MAX(4, moveresize_client
->size_inc
.width
);
345 else if (e
->xkey
.keycode
== button_down
)
346 cur_y
+= MAX(4, moveresize_client
->size_inc
.height
);
347 else if (e
->xkey
.keycode
== button_up
)
348 cur_y
-= MAX(4, moveresize_client
->size_inc
.height
);
352 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
353 if (e
->xkey
.keycode
== button_right
)
355 else if (e
->xkey
.keycode
== button_left
)
357 else if (e
->xkey
.keycode
== button_down
)
359 else if (e
->xkey
.keycode
== button_up
)