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 render_depth
, InputOutput
, render_visual
,
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
= 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
)
83 text
= g_strdup_printf(format
, a
, b
);
84 popup_show(popup
, text
, NULL
);
88 void moveresize_start(Client
*c
, int x
, int y
, guint b
, guint32 cnr
)
92 g_assert(!moveresize_in_progress
);
94 moveresize_client
= c
;
95 start_cx
= c
->frame
->area
.x
;
96 start_cy
= c
->frame
->area
.y
;
97 start_cw
= c
->area
.width
;
98 start_ch
= c
->area
.height
;
101 if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
||
102 corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
103 button
= 0; /* mouse can't end it without being pressed first */
108 if (corner
== prop_atoms
.net_wm_moveresize_move
||
109 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
119 moveresize_in_progress
= TRUE
;
121 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
)
123 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
125 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
127 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
129 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
131 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
133 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
135 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
137 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
139 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
140 cur
= ob_cursors
.move
;
141 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
142 cur
= ob_cursors
.move
;
144 g_assert_not_reached();
146 grab_pointer(TRUE
, cur
);
149 XResizeWindow(ob_display
, opaque_window
.win
, screen_physical_size
.width
,
150 screen_physical_size
.height
);
151 stacking_raise(INTERNAL_AS_WINDOW(&opaque_window
));
152 if (corner
== prop_atoms
.net_wm_moveresize_move
||
153 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
154 if (!config_opaque_move
)
155 XMapWindow(ob_display
, opaque_window
.win
);
157 if (!config_opaque_resize
)
158 XMapWindow(ob_display
, opaque_window
.win
);
163 void moveresize_end(gboolean cancel
)
165 XUnmapWindow(ob_display
, opaque_window
.win
);
167 grab_keyboard(FALSE
);
168 grab_pointer(FALSE
, None
);
173 client_configure(moveresize_client
, Corner_TopLeft
,
174 (cancel
? start_cx
: cur_x
),
175 (cancel
? start_cy
: cur_y
),
176 start_cw
, start_ch
, TRUE
, TRUE
);
178 client_configure(moveresize_client
, lockcorner
,
179 moveresize_client
->area
.x
,
180 moveresize_client
->area
.y
,
181 (cancel
? start_cw
: cur_x
),
182 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
185 moveresize_in_progress
= FALSE
;
186 moveresize_client
= NULL
;
189 static void do_move()
191 int oldx
, oldy
, oldw
, oldh
;
193 dispatch_move(moveresize_client
, &cur_x
, &cur_y
);
195 oldx
= moveresize_client
->frame
->area
.x
;
196 oldy
= moveresize_client
->frame
->area
.y
;
197 oldw
= moveresize_client
->frame
->area
.width
;
198 oldh
= moveresize_client
->frame
->area
.height
;
199 /* get where the client should be */
200 frame_frame_gravity(moveresize_client
->frame
, &cur_x
, &cur_y
);
201 client_configure(moveresize_client
, Corner_TopLeft
, cur_x
, cur_y
,
202 start_cw
, start_ch
, TRUE
, FALSE
);
203 /* draw the new one */
204 if (moveresize_client
->frame
->area
.x
!= oldx
||
205 moveresize_client
->frame
->area
.y
!= oldy
||
206 moveresize_client
->frame
->area
.width
!= oldw
||
207 moveresize_client
->frame
->area
.height
!= oldh
) {
208 if (!config_opaque_move
)
209 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
210 moveresize_client
->frame
->area
.x
,
211 moveresize_client
->frame
->area
.y
,
212 moveresize_client
->frame
->area
.width
- 1,
213 moveresize_client
->frame
->area
.height
- 1);
214 /* erase the old one */
215 if (!config_opaque_move
&& !first_draw
)
216 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
217 oldx
, oldy
, oldw
- 1, oldh
- 1);
221 /* this would be better with a fixed width font ... XXX can do it better
222 if there are 2 text boxes */
223 popup_coords("X: %4d Y: %4d", moveresize_client
->frame
->area
.x
,
224 moveresize_client
->frame
->area
.y
);
227 static void do_resize()
229 int oldx
, oldy
, oldw
, oldh
;
231 /* dispatch_resize needs the frame size */
232 cur_x
+= moveresize_client
->frame
->size
.left
+
233 moveresize_client
->frame
->size
.right
;
234 cur_y
+= moveresize_client
->frame
->size
.top
+
235 moveresize_client
->frame
->size
.bottom
;
237 dispatch_resize(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
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 oldx
= moveresize_client
->frame
->area
.x
;
245 oldy
= moveresize_client
->frame
->area
.y
;
246 oldw
= moveresize_client
->frame
->area
.width
;
247 oldh
= moveresize_client
->frame
->area
.height
;
248 client_configure(moveresize_client
, lockcorner
,
249 moveresize_client
->area
.x
, moveresize_client
->area
.y
,
250 cur_x
, cur_y
, TRUE
, FALSE
);
251 /* draw the new one */
252 if (!config_opaque_resize
)
253 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
254 moveresize_client
->frame
->area
.x
,
255 moveresize_client
->frame
->area
.y
,
256 moveresize_client
->frame
->area
.width
- 1,
257 moveresize_client
->frame
->area
.height
- 1);
258 /* erase the old one */
259 if (!config_opaque_resize
&& !first_draw
)
260 XDrawRectangle(ob_display
, opaque_window
.win
, opaque_gc
,
261 oldx
, oldy
, oldw
- 1, oldh
- 1);
264 /* this would be better with a fixed width font ... XXX can do it better
265 if there are 2 text boxes */
266 popup_coords("W: %4d H: %4d", moveresize_client
->logical_size
.width
,
267 moveresize_client
->logical_size
.height
);
270 void moveresize_event(XEvent
*e
)
272 g_assert(moveresize_in_progress
);
274 if (e
->type
== ButtonPress
) {
276 start_x
= e
->xbutton
.x_root
;
277 start_y
= e
->xbutton
.y_root
;
278 button
= e
->xbutton
.button
; /* this will end it now */
280 } else if (e
->type
== ButtonRelease
) {
281 if (!button
|| e
->xbutton
.button
== button
) {
282 moveresize_end(FALSE
);
284 } else if (e
->type
== MotionNotify
) {
286 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
287 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
290 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
291 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
292 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
293 lockcorner
= Corner_BottomRight
;
294 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
296 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
297 lockcorner
= Corner_BottomRight
;
298 } else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
) {
299 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
300 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
301 lockcorner
= Corner_BottomLeft
;
302 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
303 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
305 lockcorner
= Corner_BottomLeft
;
307 prop_atoms
.net_wm_moveresize_size_bottomright
) {
308 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
309 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
310 lockcorner
= Corner_TopLeft
;
311 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
313 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
314 lockcorner
= Corner_TopLeft
;
316 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
317 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
318 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
319 lockcorner
= Corner_TopRight
;
320 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
321 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
323 lockcorner
= Corner_TopRight
;
324 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
325 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
326 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
327 lockcorner
= Corner_TopLeft
;
329 g_assert_not_reached();
333 } else if (e
->type
== KeyPress
) {
334 if (e
->xkey
.keycode
== button_escape
)
335 moveresize_end(TRUE
);
336 else if (e
->xkey
.keycode
== button_return
)
337 moveresize_end(FALSE
);
339 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
340 if (e
->xkey
.keycode
== button_right
)
341 cur_x
+= MAX(4, moveresize_client
->size_inc
.width
);
342 else if (e
->xkey
.keycode
== button_left
)
343 cur_x
-= MAX(4, moveresize_client
->size_inc
.width
);
344 else if (e
->xkey
.keycode
== button_down
)
345 cur_y
+= MAX(4, moveresize_client
->size_inc
.height
);
346 else if (e
->xkey
.keycode
== button_up
)
347 cur_y
-= MAX(4, moveresize_client
->size_inc
.height
);
351 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
352 if (e
->xkey
.keycode
== button_right
)
354 else if (e
->xkey
.keycode
== button_left
)
356 else if (e
->xkey
.keycode
== button_down
)
358 else if (e
->xkey
.keycode
== button_up
)