2 #include "framerender.h"
11 #include "render/render.h"
12 #include "render/theme.h"
17 gboolean moveresize_in_progress
= FALSE
;
18 ObClient
*moveresize_client
= NULL
;
20 static gboolean moving
= FALSE
; /* TRUE - moving, FALSE - resizing */
22 static int start_x
, start_y
, start_cx
, start_cy
, start_cw
, start_ch
;
23 static int cur_x
, cur_y
;
25 static guint32 corner
;
26 static ObCorner lockcorner
;
28 static Popup
*popup
= NULL
;
33 void moveresize_startup()
35 XSetWindowAttributes attrib
;
37 popup
= popup_new(FALSE
);
38 popup_size_to_string(popup
, "W: 0000 W: 0000");
40 attrib
.save_under
= True
;
43 void moveresize_shutdown()
49 static void popup_coords(char *format
, int a
, int b
)
54 text
= g_strdup_printf(format
, a
, b
);
55 area
= screen_physical_area_monitor(0);
56 popup_position(popup
, NorthWestGravity
,
57 POPUP_X
+ area
->x
, POPUP_Y
+ area
->y
);
58 popup_show(popup
, text
, NULL
);
62 void moveresize_start(ObClient
*c
, int x
, int y
, guint b
, guint32 cnr
)
66 g_assert(!moveresize_in_progress
);
68 moveresize_client
= c
;
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
)
96 cur
= OB_CURSOR_NORTHWEST
;
97 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
98 cur
= OB_CURSOR_NORTH
;
99 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
100 cur
= OB_CURSOR_NORTHEAST
;
101 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
102 cur
= OB_CURSOR_EAST
;
103 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
104 cur
= OB_CURSOR_SOUTHEAST
;
105 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
106 cur
= OB_CURSOR_SOUTH
;
107 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
108 cur
= OB_CURSOR_SOUTHWEST
;
109 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
110 cur
= OB_CURSOR_WEST
;
111 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
112 cur
= OB_CURSOR_SOUTHEAST
;
113 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
114 cur
= OB_CURSOR_MOVE
;
115 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
116 cur
= OB_CURSOR_MOVE
;
118 g_assert_not_reached();
120 grab_pointer(TRUE
, cur
);
124 void moveresize_end(gboolean cancel
)
126 grab_keyboard(FALSE
);
127 grab_pointer(FALSE
, None
);
132 client_configure(moveresize_client
, OB_CORNER_TOPLEFT
,
133 (cancel
? start_cx
: cur_x
),
134 (cancel
? start_cy
: cur_y
),
135 start_cw
, start_ch
, TRUE
, TRUE
);
137 client_configure(moveresize_client
, lockcorner
,
138 moveresize_client
->area
.x
,
139 moveresize_client
->area
.y
,
140 (cancel
? start_cw
: cur_x
),
141 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
144 moveresize_in_progress
= FALSE
;
145 moveresize_client
= NULL
;
148 static void do_move()
152 dispatch_move(moveresize_client
, &cur_x
, &cur_y
);
154 /* get where the client should be */
155 frame_frame_gravity(moveresize_client
->frame
, &cur_x
, &cur_y
);
156 client_configure(moveresize_client
, OB_CORNER_TOPLEFT
, cur_x
, cur_y
,
157 start_cw
, start_ch
, TRUE
, FALSE
);
159 /* this would be better with a fixed width font ... XXX can do it better
160 if there are 2 text boxes */
161 a
= screen_area(screen_desktop
);
162 popup_coords("X: %4d Y: %4d",
163 moveresize_client
->frame
->area
.x
- a
->x
,
164 moveresize_client
->frame
->area
.y
- a
->y
);
167 static void do_resize()
169 /* dispatch_resize needs the frame size */
170 cur_x
+= moveresize_client
->frame
->size
.left
+
171 moveresize_client
->frame
->size
.right
;
172 cur_y
+= moveresize_client
->frame
->size
.top
+
173 moveresize_client
->frame
->size
.bottom
;
175 dispatch_resize(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
177 cur_x
-= moveresize_client
->frame
->size
.left
+
178 moveresize_client
->frame
->size
.right
;
179 cur_y
-= moveresize_client
->frame
->size
.top
+
180 moveresize_client
->frame
->size
.bottom
;
182 client_configure(moveresize_client
, lockcorner
,
183 moveresize_client
->area
.x
, moveresize_client
->area
.y
,
184 cur_x
, cur_y
, TRUE
, FALSE
);
186 /* this would be better with a fixed width font ... XXX can do it better
187 if there are 2 text boxes */
188 popup_coords("W: %4d H: %4d", moveresize_client
->logical_size
.width
,
189 moveresize_client
->logical_size
.height
);
192 void moveresize_event(XEvent
*e
)
194 g_assert(moveresize_in_progress
);
196 if (e
->type
== ButtonPress
) {
198 start_x
= e
->xbutton
.x_root
;
199 start_y
= e
->xbutton
.y_root
;
200 button
= e
->xbutton
.button
; /* this will end it now */
202 } else if (e
->type
== ButtonRelease
) {
203 if (!button
|| e
->xbutton
.button
== button
) {
204 moveresize_end(FALSE
);
206 } else if (e
->type
== MotionNotify
) {
208 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
209 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
212 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
213 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
214 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
215 lockcorner
= OB_CORNER_BOTTOMRIGHT
;
216 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
218 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
219 lockcorner
= OB_CORNER_BOTTOMRIGHT
;
220 } else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
) {
221 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
222 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
223 lockcorner
= OB_CORNER_BOTTOMLEFT
;
224 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
225 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
227 lockcorner
= OB_CORNER_BOTTOMLEFT
;
229 prop_atoms
.net_wm_moveresize_size_bottomright
) {
230 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
231 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
232 lockcorner
= OB_CORNER_TOPLEFT
;
233 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
235 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
236 lockcorner
= OB_CORNER_TOPLEFT
;
238 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
239 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
240 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
241 lockcorner
= OB_CORNER_TOPRIGHT
;
242 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
243 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
245 lockcorner
= OB_CORNER_TOPRIGHT
;
246 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
247 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
248 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
249 lockcorner
= OB_CORNER_TOPLEFT
;
251 g_assert_not_reached();
255 } else if (e
->type
== KeyPress
) {
256 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
))
257 moveresize_end(TRUE
);
258 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
))
259 moveresize_end(FALSE
);
261 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
262 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
263 cur_x
+= MAX(4, moveresize_client
->size_inc
.width
);
264 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
265 cur_x
-= MAX(4, moveresize_client
->size_inc
.width
);
266 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
267 cur_y
+= MAX(4, moveresize_client
->size_inc
.height
);
268 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))
269 cur_y
-= MAX(4, moveresize_client
->size_inc
.height
);
273 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
274 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
276 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
278 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
280 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))