2 #include "framerender.h"
12 #include "render/render.h"
13 #include "render/theme.h"
18 gboolean moveresize_in_progress
= FALSE
;
19 ObClient
*moveresize_client
= NULL
;
21 static gboolean moving
= FALSE
; /* TRUE - moving, FALSE - resizing */
23 static int start_x
, start_y
, start_cx
, start_cy
, start_cw
, start_ch
;
24 static int cur_x
, cur_y
;
26 static guint32 corner
;
27 static ObCorner lockcorner
;
29 static Popup
*popup
= NULL
;
34 void moveresize_startup()
36 XSetWindowAttributes attrib
;
38 popup
= popup_new(FALSE
);
39 popup_size_to_string(popup
, "W: 0000 W: 0000");
41 attrib
.save_under
= True
;
44 void moveresize_shutdown()
50 static void popup_coords(char *format
, int a
, int b
)
55 text
= g_strdup_printf(format
, a
, b
);
56 area
= screen_physical_area_monitor(0);
57 popup_position(popup
, NorthWestGravity
,
58 POPUP_X
+ area
->x
, POPUP_Y
+ area
->y
);
59 popup_show(popup
, text
, NULL
);
63 void moveresize_start(ObClient
*c
, int x
, int y
, guint b
, guint32 cnr
)
67 g_assert(!moveresize_in_progress
);
69 moveresize_client
= c
;
70 start_cx
= c
->frame
->area
.x
;
71 start_cy
= c
->frame
->area
.y
;
72 start_cw
= c
->area
.width
;
73 start_ch
= c
->area
.height
;
80 have to change start_cx and start_cy if going to do this..
81 if (corner == prop_atoms.net_wm_moveresize_move_keyboard ||
82 corner == prop_atoms.net_wm_moveresize_size_keyboard)
83 XWarpPointer(ob_display, None, c->window, 0, 0, 0, 0,
84 c->area.width / 2, c->area.height / 2);
87 if (corner
== prop_atoms
.net_wm_moveresize_move
||
88 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
98 moveresize_in_progress
= TRUE
;
100 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
)
101 cur
= OB_CURSOR_NORTHWEST
;
102 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
103 cur
= OB_CURSOR_NORTH
;
104 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
105 cur
= OB_CURSOR_NORTHEAST
;
106 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
107 cur
= OB_CURSOR_EAST
;
108 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
109 cur
= OB_CURSOR_SOUTHEAST
;
110 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
111 cur
= OB_CURSOR_SOUTH
;
112 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
113 cur
= OB_CURSOR_SOUTHWEST
;
114 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
115 cur
= OB_CURSOR_WEST
;
116 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
117 cur
= OB_CURSOR_SOUTHEAST
;
118 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
119 cur
= OB_CURSOR_MOVE
;
120 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
121 cur
= OB_CURSOR_MOVE
;
123 g_assert_not_reached();
125 grab_pointer(TRUE
, cur
);
129 void moveresize_end(gboolean cancel
)
131 grab_keyboard(FALSE
);
132 grab_pointer(FALSE
, None
);
137 client_configure(moveresize_client
, OB_CORNER_TOPLEFT
,
138 (cancel
? start_cx
: cur_x
),
139 (cancel
? start_cy
: cur_y
),
140 start_cw
, start_ch
, TRUE
, TRUE
);
142 client_configure(moveresize_client
, lockcorner
,
143 moveresize_client
->area
.x
,
144 moveresize_client
->area
.y
,
145 (cancel
? start_cw
: cur_x
),
146 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
149 moveresize_in_progress
= FALSE
;
150 moveresize_client
= NULL
;
153 static void do_move(gboolean resist
)
158 resist_move(moveresize_client
, &cur_x
, &cur_y
);
160 dispatch_move(moveresize_client
, &cur_x
, &cur_y
);
162 /* get where the client should be */
163 frame_frame_gravity(moveresize_client
->frame
, &cur_x
, &cur_y
);
164 client_configure(moveresize_client
, OB_CORNER_TOPLEFT
, cur_x
, cur_y
,
165 start_cw
, start_ch
, TRUE
, FALSE
);
167 /* this would be better with a fixed width font ... XXX can do it better
168 if there are 2 text boxes */
169 a
= screen_area(screen_desktop
);
170 popup_coords("X: %4d Y: %4d",
171 moveresize_client
->frame
->area
.x
- a
->x
,
172 moveresize_client
->frame
->area
.y
- a
->y
);
175 static void do_resize(gboolean resist
)
177 /* dispatch_resize needs the frame size */
178 cur_x
+= moveresize_client
->frame
->size
.left
+
179 moveresize_client
->frame
->size
.right
;
180 cur_y
+= moveresize_client
->frame
->size
.top
+
181 moveresize_client
->frame
->size
.bottom
;
184 resist_size(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
186 dispatch_resize(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
188 cur_x
-= moveresize_client
->frame
->size
.left
+
189 moveresize_client
->frame
->size
.right
;
190 cur_y
-= moveresize_client
->frame
->size
.top
+
191 moveresize_client
->frame
->size
.bottom
;
193 client_configure(moveresize_client
, lockcorner
,
194 moveresize_client
->area
.x
, moveresize_client
->area
.y
,
195 cur_x
, cur_y
, TRUE
, FALSE
);
197 /* this would be better with a fixed width font ... XXX can do it better
198 if there are 2 text boxes */
199 popup_coords("W: %4d H: %4d", moveresize_client
->logical_size
.width
,
200 moveresize_client
->logical_size
.height
);
203 void moveresize_event(XEvent
*e
)
205 g_assert(moveresize_in_progress
);
207 if (e
->type
== ButtonPress
) {
209 start_x
= e
->xbutton
.x_root
;
210 start_y
= e
->xbutton
.y_root
;
211 button
= e
->xbutton
.button
; /* this will end it now */
213 } else if (e
->type
== ButtonRelease
) {
214 if (!button
|| e
->xbutton
.button
== button
) {
215 moveresize_end(FALSE
);
217 } else if (e
->type
== MotionNotify
) {
219 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
220 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
223 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
224 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
225 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
226 lockcorner
= OB_CORNER_BOTTOMRIGHT
;
227 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
229 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
230 lockcorner
= OB_CORNER_BOTTOMRIGHT
;
231 } else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
) {
232 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
233 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
234 lockcorner
= OB_CORNER_BOTTOMLEFT
;
235 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
236 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
238 lockcorner
= OB_CORNER_BOTTOMLEFT
;
240 prop_atoms
.net_wm_moveresize_size_bottomright
) {
241 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
242 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
243 lockcorner
= OB_CORNER_TOPLEFT
;
244 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
246 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
247 lockcorner
= OB_CORNER_TOPLEFT
;
249 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
250 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
251 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
252 lockcorner
= OB_CORNER_TOPRIGHT
;
253 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
254 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
256 lockcorner
= OB_CORNER_TOPRIGHT
;
257 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
258 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
259 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
260 lockcorner
= OB_CORNER_TOPLEFT
;
262 g_assert_not_reached();
266 } else if (e
->type
== KeyPress
) {
267 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
))
268 moveresize_end(TRUE
);
269 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
))
270 moveresize_end(FALSE
);
272 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
275 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
276 dx
= MAX(4, moveresize_client
->size_inc
.width
);
277 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
278 dx
= -MAX(4, moveresize_client
->size_inc
.width
);
279 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
280 dy
= MAX(4, moveresize_client
->size_inc
.height
);
281 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))
282 dy
= -MAX(4, moveresize_client
->size_inc
.height
);
288 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);
291 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
294 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
296 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
298 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
300 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))
307 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);