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()
150 dispatch_move(moveresize_client
, &cur_x
, &cur_y
);
152 /* get where the client should be */
153 frame_frame_gravity(moveresize_client
->frame
, &cur_x
, &cur_y
);
154 client_configure(moveresize_client
, OB_CORNER_TOPLEFT
, cur_x
, cur_y
,
155 start_cw
, start_ch
, TRUE
, FALSE
);
157 /* this would be better with a fixed width font ... XXX can do it better
158 if there are 2 text boxes */
159 popup_coords("X: %4d Y: %4d", moveresize_client
->frame
->area
.x
,
160 moveresize_client
->frame
->area
.y
);
163 static void do_resize()
165 /* dispatch_resize needs the frame size */
166 cur_x
+= moveresize_client
->frame
->size
.left
+
167 moveresize_client
->frame
->size
.right
;
168 cur_y
+= moveresize_client
->frame
->size
.top
+
169 moveresize_client
->frame
->size
.bottom
;
171 dispatch_resize(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
173 cur_x
-= moveresize_client
->frame
->size
.left
+
174 moveresize_client
->frame
->size
.right
;
175 cur_y
-= moveresize_client
->frame
->size
.top
+
176 moveresize_client
->frame
->size
.bottom
;
178 client_configure(moveresize_client
, lockcorner
,
179 moveresize_client
->area
.x
, moveresize_client
->area
.y
,
180 cur_x
, cur_y
, TRUE
, FALSE
);
182 /* this would be better with a fixed width font ... XXX can do it better
183 if there are 2 text boxes */
184 popup_coords("W: %4d H: %4d", moveresize_client
->logical_size
.width
,
185 moveresize_client
->logical_size
.height
);
188 void moveresize_event(XEvent
*e
)
190 g_assert(moveresize_in_progress
);
192 if (e
->type
== ButtonPress
) {
194 start_x
= e
->xbutton
.x_root
;
195 start_y
= e
->xbutton
.y_root
;
196 button
= e
->xbutton
.button
; /* this will end it now */
198 } else if (e
->type
== ButtonRelease
) {
199 if (!button
|| e
->xbutton
.button
== button
) {
200 moveresize_end(FALSE
);
202 } else if (e
->type
== MotionNotify
) {
204 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
205 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
208 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
209 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
210 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
211 lockcorner
= OB_CORNER_BOTTOMRIGHT
;
212 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
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_topright
) {
217 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
218 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
219 lockcorner
= OB_CORNER_BOTTOMLEFT
;
220 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
221 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
223 lockcorner
= OB_CORNER_BOTTOMLEFT
;
225 prop_atoms
.net_wm_moveresize_size_bottomright
) {
226 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
227 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
228 lockcorner
= OB_CORNER_TOPLEFT
;
229 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
231 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
232 lockcorner
= OB_CORNER_TOPLEFT
;
234 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
235 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
236 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
237 lockcorner
= OB_CORNER_TOPRIGHT
;
238 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
239 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
241 lockcorner
= OB_CORNER_TOPRIGHT
;
242 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
243 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
244 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
245 lockcorner
= OB_CORNER_TOPLEFT
;
247 g_assert_not_reached();
251 } else if (e
->type
== KeyPress
) {
252 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
))
253 moveresize_end(TRUE
);
254 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
))
255 moveresize_end(FALSE
);
257 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
258 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
259 cur_x
+= MAX(4, moveresize_client
->size_inc
.width
);
260 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
261 cur_x
-= MAX(4, moveresize_client
->size_inc
.width
);
262 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
263 cur_y
+= MAX(4, moveresize_client
->size_inc
.height
);
264 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))
265 cur_y
-= MAX(4, moveresize_client
->size_inc
.height
);
269 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
270 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
272 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
274 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
276 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))