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
;
79 have to change start_cx and start_cy if going to do this..
80 if (corner == prop_atoms.net_wm_moveresize_move_keyboard ||
81 corner == prop_atoms.net_wm_moveresize_size_keyboard)
82 XWarpPointer(ob_display, None, c->window, 0, 0, 0, 0,
83 c->area.width / 2, c->area.height / 2);
86 if (corner
== prop_atoms
.net_wm_moveresize_move
||
87 corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
97 moveresize_in_progress
= TRUE
;
99 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
)
100 cur
= OB_CURSOR_NORTHWEST
;
101 else if (corner
== prop_atoms
.net_wm_moveresize_size_top
)
102 cur
= OB_CURSOR_NORTH
;
103 else if (corner
== prop_atoms
.net_wm_moveresize_size_topright
)
104 cur
= OB_CURSOR_NORTHEAST
;
105 else if (corner
== prop_atoms
.net_wm_moveresize_size_right
)
106 cur
= OB_CURSOR_EAST
;
107 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomright
)
108 cur
= OB_CURSOR_SOUTHEAST
;
109 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
)
110 cur
= OB_CURSOR_SOUTH
;
111 else if (corner
== prop_atoms
.net_wm_moveresize_size_bottomleft
)
112 cur
= OB_CURSOR_SOUTHWEST
;
113 else if (corner
== prop_atoms
.net_wm_moveresize_size_left
)
114 cur
= OB_CURSOR_WEST
;
115 else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
)
116 cur
= OB_CURSOR_SOUTHEAST
;
117 else if (corner
== prop_atoms
.net_wm_moveresize_move
)
118 cur
= OB_CURSOR_MOVE
;
119 else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
)
120 cur
= OB_CURSOR_MOVE
;
122 g_assert_not_reached();
124 grab_pointer(TRUE
, cur
);
128 void moveresize_end(gboolean cancel
)
130 grab_keyboard(FALSE
);
131 grab_pointer(FALSE
, None
);
136 client_configure(moveresize_client
, OB_CORNER_TOPLEFT
,
137 (cancel
? start_cx
: cur_x
),
138 (cancel
? start_cy
: cur_y
),
139 start_cw
, start_ch
, TRUE
, TRUE
);
141 client_configure(moveresize_client
, lockcorner
,
142 moveresize_client
->area
.x
,
143 moveresize_client
->area
.y
,
144 (cancel
? start_cw
: cur_x
),
145 (cancel
? start_ch
: cur_y
), TRUE
, TRUE
);
148 moveresize_in_progress
= FALSE
;
149 moveresize_client
= NULL
;
152 static void do_move(gboolean resist
)
157 resist_move(moveresize_client
, &cur_x
, &cur_y
);
159 /* get where the client should be */
160 frame_frame_gravity(moveresize_client
->frame
, &cur_x
, &cur_y
);
161 client_configure(moveresize_client
, OB_CORNER_TOPLEFT
, cur_x
, cur_y
,
162 start_cw
, start_ch
, TRUE
, FALSE
);
164 /* this would be better with a fixed width font ... XXX can do it better
165 if there are 2 text boxes */
166 a
= screen_area(screen_desktop
);
167 popup_coords("X: %4d Y: %4d",
168 moveresize_client
->frame
->area
.x
- a
->x
,
169 moveresize_client
->frame
->area
.y
- a
->y
);
172 static void do_resize(gboolean resist
)
175 /* resist_size needs the frame size */
176 cur_x
+= moveresize_client
->frame
->size
.left
+
177 moveresize_client
->frame
->size
.right
;
178 cur_y
+= moveresize_client
->frame
->size
.top
+
179 moveresize_client
->frame
->size
.bottom
;
181 resist_size(moveresize_client
, &cur_x
, &cur_y
, lockcorner
);
183 cur_x
-= moveresize_client
->frame
->size
.left
+
184 moveresize_client
->frame
->size
.right
;
185 cur_y
-= moveresize_client
->frame
->size
.top
+
186 moveresize_client
->frame
->size
.bottom
;
189 client_configure(moveresize_client
, lockcorner
,
190 moveresize_client
->area
.x
, moveresize_client
->area
.y
,
191 cur_x
, cur_y
, TRUE
, FALSE
);
193 /* this would be better with a fixed width font ... XXX can do it better
194 if there are 2 text boxes */
195 popup_coords("W: %4d H: %4d", moveresize_client
->logical_size
.width
,
196 moveresize_client
->logical_size
.height
);
199 void moveresize_event(XEvent
*e
)
201 g_assert(moveresize_in_progress
);
203 if (e
->type
== ButtonPress
) {
205 start_x
= e
->xbutton
.x_root
;
206 start_y
= e
->xbutton
.y_root
;
207 button
= e
->xbutton
.button
; /* this will end it now */
209 } else if (e
->type
== ButtonRelease
) {
210 if (!button
|| e
->xbutton
.button
== button
) {
211 moveresize_end(FALSE
);
213 } else if (e
->type
== MotionNotify
) {
215 cur_x
= start_cx
+ e
->xmotion
.x_root
- start_x
;
216 cur_y
= start_cy
+ e
->xmotion
.y_root
- start_y
;
219 if (corner
== prop_atoms
.net_wm_moveresize_size_topleft
) {
220 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
221 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
222 lockcorner
= OB_CORNER_BOTTOMRIGHT
;
223 } else if (corner
== prop_atoms
.net_wm_moveresize_size_top
) {
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_topright
) {
228 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
229 cur_y
= start_ch
- (e
->xmotion
.y_root
- start_y
);
230 lockcorner
= OB_CORNER_BOTTOMLEFT
;
231 } else if (corner
== prop_atoms
.net_wm_moveresize_size_right
) {
232 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
234 lockcorner
= OB_CORNER_BOTTOMLEFT
;
236 prop_atoms
.net_wm_moveresize_size_bottomright
) {
237 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
238 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
239 lockcorner
= OB_CORNER_TOPLEFT
;
240 } else if (corner
== prop_atoms
.net_wm_moveresize_size_bottom
) {
242 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
243 lockcorner
= OB_CORNER_TOPLEFT
;
245 prop_atoms
.net_wm_moveresize_size_bottomleft
) {
246 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
247 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
248 lockcorner
= OB_CORNER_TOPRIGHT
;
249 } else if (corner
== prop_atoms
.net_wm_moveresize_size_left
) {
250 cur_x
= start_cw
- (e
->xmotion
.x_root
- start_x
);
252 lockcorner
= OB_CORNER_TOPRIGHT
;
253 } else if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
254 cur_x
= start_cw
+ (e
->xmotion
.x_root
- start_x
);
255 cur_y
= start_ch
+ (e
->xmotion
.y_root
- start_y
);
256 lockcorner
= OB_CORNER_TOPLEFT
;
258 g_assert_not_reached();
262 } else if (e
->type
== KeyPress
) {
263 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
))
264 moveresize_end(TRUE
);
265 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
))
266 moveresize_end(FALSE
);
268 if (corner
== prop_atoms
.net_wm_moveresize_size_keyboard
) {
271 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
272 dx
= MAX(4, moveresize_client
->size_inc
.width
);
273 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
274 dx
= -MAX(4, moveresize_client
->size_inc
.width
);
275 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
276 dy
= MAX(4, moveresize_client
->size_inc
.height
);
277 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))
278 dy
= -MAX(4, moveresize_client
->size_inc
.height
);
284 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);
287 } else if (corner
== prop_atoms
.net_wm_moveresize_move_keyboard
) {
290 if (e
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
))
292 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
))
294 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
))
296 else if (e
->xkey
.keycode
== ob_keycode(OB_KEY_UP
))
303 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);