2003-04-17 05:28:35 +00:00
|
|
|
#include "grab.h"
|
|
|
|
#include "framerender.h"
|
2003-05-11 23:31:43 +00:00
|
|
|
#include "screen.h"
|
2003-04-17 05:28:35 +00:00
|
|
|
#include "prop.h"
|
|
|
|
#include "client.h"
|
2003-07-10 17:03:05 +00:00
|
|
|
#include "frame.h"
|
2003-04-17 05:28:35 +00:00
|
|
|
#include "openbox.h"
|
2003-08-12 19:57:04 +00:00
|
|
|
#include "resist.h"
|
2003-05-09 16:57:17 +00:00
|
|
|
#include "popup.h"
|
2003-09-01 02:02:40 +00:00
|
|
|
#include "moveresize.h"
|
2003-05-11 23:57:56 +00:00
|
|
|
#include "config.h"
|
2003-05-11 23:31:43 +00:00
|
|
|
#include "render/render.h"
|
|
|
|
#include "render/theme.h"
|
2003-04-17 05:28:35 +00:00
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
gboolean moveresize_in_progress = FALSE;
|
2003-07-10 06:38:42 +00:00
|
|
|
ObClient *moveresize_client = NULL;
|
2003-04-18 01:51:41 +00:00
|
|
|
|
2003-04-17 05:28:35 +00:00
|
|
|
static gboolean moving = FALSE; /* TRUE - moving, FALSE - resizing */
|
|
|
|
|
|
|
|
static int start_x, start_y, start_cx, start_cy, start_cw, start_ch;
|
|
|
|
static int cur_x, cur_y;
|
|
|
|
static guint button;
|
|
|
|
static guint32 corner;
|
2003-07-10 06:18:47 +00:00
|
|
|
static ObCorner lockcorner;
|
2003-04-17 06:17:06 +00:00
|
|
|
|
2003-05-09 16:57:17 +00:00
|
|
|
static Popup *popup = NULL;
|
|
|
|
|
2003-04-17 05:28:35 +00:00
|
|
|
#define POPUP_X (10)
|
|
|
|
#define POPUP_Y (10)
|
|
|
|
|
2003-08-30 17:46:23 +00:00
|
|
|
static void client_dest(ObClient *c)
|
|
|
|
{
|
|
|
|
if (moveresize_client == c)
|
|
|
|
moveresize_end(TRUE);
|
|
|
|
}
|
|
|
|
|
2003-04-17 06:17:06 +00:00
|
|
|
void moveresize_startup()
|
|
|
|
{
|
2003-05-11 23:31:43 +00:00
|
|
|
XSetWindowAttributes attrib;
|
|
|
|
|
2003-05-09 16:57:17 +00:00
|
|
|
popup = popup_new(FALSE);
|
|
|
|
popup_size_to_string(popup, "W: 0000 W: 0000");
|
2003-05-11 23:31:43 +00:00
|
|
|
|
|
|
|
attrib.save_under = True;
|
2003-08-30 17:46:23 +00:00
|
|
|
|
|
|
|
client_add_destructor(client_dest);
|
2003-05-09 16:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void moveresize_shutdown()
|
|
|
|
{
|
2003-08-30 17:46:23 +00:00
|
|
|
client_remove_destructor(client_dest);
|
|
|
|
|
2003-05-09 16:57:17 +00:00
|
|
|
popup_free(popup);
|
|
|
|
popup = NULL;
|
2003-04-17 06:17:06 +00:00
|
|
|
}
|
|
|
|
|
2003-04-17 05:28:35 +00:00
|
|
|
static void popup_coords(char *format, int a, int b)
|
|
|
|
{
|
|
|
|
char *text;
|
2003-06-27 04:20:30 +00:00
|
|
|
Rect *area;
|
2003-04-17 05:28:35 +00:00
|
|
|
|
|
|
|
text = g_strdup_printf(format, a, b);
|
2003-07-10 05:44:23 +00:00
|
|
|
area = screen_physical_area_monitor(0);
|
2003-06-27 04:20:30 +00:00
|
|
|
popup_position(popup, NorthWestGravity,
|
|
|
|
POPUP_X + area->x, POPUP_Y + area->y);
|
2003-05-09 16:57:17 +00:00
|
|
|
popup_show(popup, text, NULL);
|
2003-04-17 05:28:35 +00:00
|
|
|
g_free(text);
|
|
|
|
}
|
|
|
|
|
2003-07-10 06:38:42 +00:00
|
|
|
void moveresize_start(ObClient *c, int x, int y, guint b, guint32 cnr)
|
2003-04-17 05:28:35 +00:00
|
|
|
{
|
2003-07-10 06:18:47 +00:00
|
|
|
ObCursor cur;
|
2003-04-17 05:28:35 +00:00
|
|
|
|
|
|
|
g_assert(!moveresize_in_progress);
|
|
|
|
|
2003-04-18 01:51:41 +00:00
|
|
|
moveresize_client = c;
|
2003-04-17 05:28:35 +00:00
|
|
|
start_cx = c->frame->area.x;
|
|
|
|
start_cy = c->frame->area.y;
|
2003-09-02 07:50:52 +00:00
|
|
|
start_cw = c->area.width + (c->size_inc.width + 1) / 2;
|
|
|
|
start_ch = c->area.height + (c->size_inc.height + 1) / 2;
|
2003-04-17 06:21:19 +00:00
|
|
|
start_x = x;
|
|
|
|
start_y = y;
|
2003-04-17 05:28:35 +00:00
|
|
|
corner = cnr;
|
2003-08-12 19:57:04 +00:00
|
|
|
button = b;
|
2003-04-17 05:28:35 +00:00
|
|
|
|
2003-08-20 04:45:55 +00:00
|
|
|
/*
|
|
|
|
have to change start_cx and start_cy if going to do this..
|
|
|
|
if (corner == prop_atoms.net_wm_moveresize_move_keyboard ||
|
|
|
|
corner == prop_atoms.net_wm_moveresize_size_keyboard)
|
|
|
|
XWarpPointer(ob_display, None, c->window, 0, 0, 0, 0,
|
|
|
|
c->area.width / 2, c->area.height / 2);
|
|
|
|
*/
|
|
|
|
|
2003-04-17 06:17:06 +00:00
|
|
|
if (corner == prop_atoms.net_wm_moveresize_move ||
|
|
|
|
corner == prop_atoms.net_wm_moveresize_move_keyboard) {
|
|
|
|
cur_x = start_cx;
|
|
|
|
cur_y = start_cy;
|
|
|
|
moving = TRUE;
|
|
|
|
} else {
|
|
|
|
cur_x = start_cw;
|
|
|
|
cur_y = start_ch;
|
|
|
|
moving = FALSE;
|
|
|
|
}
|
|
|
|
|
2003-04-17 05:28:35 +00:00
|
|
|
moveresize_in_progress = TRUE;
|
|
|
|
|
|
|
|
if (corner == prop_atoms.net_wm_moveresize_size_topleft)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_NORTHWEST;
|
2003-04-17 05:28:35 +00:00
|
|
|
else if (corner == prop_atoms.net_wm_moveresize_size_top)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_NORTH;
|
2003-04-17 05:28:35 +00:00
|
|
|
else if (corner == prop_atoms.net_wm_moveresize_size_topright)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_NORTHEAST;
|
2003-04-17 05:28:35 +00:00
|
|
|
else if (corner == prop_atoms.net_wm_moveresize_size_right)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_EAST;
|
2003-04-17 05:28:35 +00:00
|
|
|
else if (corner == prop_atoms.net_wm_moveresize_size_bottomright)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_SOUTHEAST;
|
2003-04-17 05:28:35 +00:00
|
|
|
else if (corner == prop_atoms.net_wm_moveresize_size_bottom)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_SOUTH;
|
2003-04-17 05:28:35 +00:00
|
|
|
else if (corner == prop_atoms.net_wm_moveresize_size_bottomleft)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_SOUTHWEST;
|
2003-04-17 05:28:35 +00:00
|
|
|
else if (corner == prop_atoms.net_wm_moveresize_size_left)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_WEST;
|
2003-04-17 05:28:35 +00:00
|
|
|
else if (corner == prop_atoms.net_wm_moveresize_size_keyboard)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_SOUTHEAST;
|
2003-04-17 05:28:35 +00:00
|
|
|
else if (corner == prop_atoms.net_wm_moveresize_move)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_MOVE;
|
2003-04-17 05:28:35 +00:00
|
|
|
else if (corner == prop_atoms.net_wm_moveresize_move_keyboard)
|
2003-07-10 06:18:47 +00:00
|
|
|
cur = OB_CURSOR_MOVE;
|
2003-04-17 05:28:35 +00:00
|
|
|
else
|
|
|
|
g_assert_not_reached();
|
|
|
|
|
|
|
|
grab_pointer(TRUE, cur);
|
2003-04-17 07:00:13 +00:00
|
|
|
grab_keyboard(TRUE);
|
2003-04-17 05:28:35 +00:00
|
|
|
}
|
|
|
|
|
2003-04-18 01:51:41 +00:00
|
|
|
void moveresize_end(gboolean cancel)
|
2003-04-17 06:17:06 +00:00
|
|
|
{
|
|
|
|
grab_keyboard(FALSE);
|
|
|
|
grab_pointer(FALSE, None);
|
|
|
|
|
2003-05-09 16:57:17 +00:00
|
|
|
popup_hide(popup);
|
2003-04-17 06:17:06 +00:00
|
|
|
|
|
|
|
if (moving) {
|
2003-09-01 02:02:40 +00:00
|
|
|
client_move(moveresize_client,
|
|
|
|
(cancel ? start_cx : cur_x),
|
|
|
|
(cancel ? start_cy : cur_y));
|
2003-04-17 06:17:06 +00:00
|
|
|
} else {
|
2003-04-18 01:51:41 +00:00
|
|
|
client_configure(moveresize_client, lockcorner,
|
|
|
|
moveresize_client->area.x,
|
|
|
|
moveresize_client->area.y,
|
|
|
|
(cancel ? start_cw : cur_x),
|
2003-04-17 06:17:06 +00:00
|
|
|
(cancel ? start_ch : cur_y), TRUE, TRUE);
|
|
|
|
}
|
2003-04-18 06:29:28 +00:00
|
|
|
|
|
|
|
moveresize_in_progress = FALSE;
|
|
|
|
moveresize_client = NULL;
|
2003-04-17 06:17:06 +00:00
|
|
|
}
|
|
|
|
|
2003-08-12 19:57:04 +00:00
|
|
|
static void do_move(gboolean resist)
|
2003-04-17 06:17:06 +00:00
|
|
|
{
|
2003-08-05 07:25:22 +00:00
|
|
|
Rect *a;
|
|
|
|
|
2003-08-12 19:57:04 +00:00
|
|
|
if (resist)
|
2003-09-02 07:50:52 +00:00
|
|
|
resist_move_windows(moveresize_client, &cur_x, &cur_y);
|
|
|
|
resist_move_monitors(moveresize_client, &cur_x, &cur_y);
|
2003-08-12 19:57:04 +00:00
|
|
|
|
2003-04-17 06:17:06 +00:00
|
|
|
/* get where the client should be */
|
2003-04-18 01:51:41 +00:00
|
|
|
frame_frame_gravity(moveresize_client->frame, &cur_x, &cur_y);
|
2003-09-01 16:14:13 +00:00
|
|
|
client_configure(moveresize_client, OB_CORNER_TOPLEFT, cur_x, cur_y,
|
|
|
|
start_cw, start_ch, TRUE, FALSE);
|
2003-04-26 21:11:50 +00:00
|
|
|
|
2003-05-09 16:57:17 +00:00
|
|
|
/* this would be better with a fixed width font ... XXX can do it better
|
|
|
|
if there are 2 text boxes */
|
2003-08-05 07:25:22 +00:00
|
|
|
a = screen_area(screen_desktop);
|
|
|
|
popup_coords("X: %4d Y: %4d",
|
|
|
|
moveresize_client->frame->area.x - a->x,
|
|
|
|
moveresize_client->frame->area.y - a->y);
|
2003-04-17 06:17:06 +00:00
|
|
|
}
|
|
|
|
|
2003-08-12 19:57:04 +00:00
|
|
|
static void do_resize(gboolean resist)
|
2003-04-17 06:17:06 +00:00
|
|
|
{
|
2003-09-02 07:50:52 +00:00
|
|
|
/* resist_size_* needs the frame size */
|
|
|
|
cur_x += moveresize_client->frame->size.left +
|
|
|
|
moveresize_client->frame->size.right;
|
|
|
|
cur_y += moveresize_client->frame->size.top +
|
|
|
|
moveresize_client->frame->size.bottom;
|
|
|
|
|
|
|
|
if (resist)
|
|
|
|
resist_size_windows(moveresize_client, &cur_x, &cur_y, lockcorner);
|
|
|
|
resist_size_monitors(moveresize_client, &cur_x, &cur_y, lockcorner);
|
|
|
|
|
|
|
|
cur_x -= moveresize_client->frame->size.left +
|
|
|
|
moveresize_client->frame->size.right;
|
|
|
|
cur_y -= moveresize_client->frame->size.top +
|
|
|
|
moveresize_client->frame->size.bottom;
|
2003-04-17 06:17:06 +00:00
|
|
|
|
2003-05-11 23:31:43 +00:00
|
|
|
client_configure(moveresize_client, lockcorner,
|
|
|
|
moveresize_client->area.x, moveresize_client->area.y,
|
|
|
|
cur_x, cur_y, TRUE, FALSE);
|
2003-04-17 06:17:06 +00:00
|
|
|
|
2003-05-09 16:57:17 +00:00
|
|
|
/* this would be better with a fixed width font ... XXX can do it better
|
|
|
|
if there are 2 text boxes */
|
|
|
|
popup_coords("W: %4d H: %4d", moveresize_client->logical_size.width,
|
2003-04-18 01:51:41 +00:00
|
|
|
moveresize_client->logical_size.height);
|
2003-04-17 06:17:06 +00:00
|
|
|
}
|
|
|
|
|
2003-04-17 05:28:35 +00:00
|
|
|
void moveresize_event(XEvent *e)
|
|
|
|
{
|
|
|
|
g_assert(moveresize_in_progress);
|
|
|
|
|
2003-04-17 06:17:06 +00:00
|
|
|
if (e->type == ButtonPress) {
|
|
|
|
if (!button) {
|
|
|
|
start_x = e->xbutton.x_root;
|
|
|
|
start_y = e->xbutton.y_root;
|
|
|
|
button = e->xbutton.button; /* this will end it now */
|
|
|
|
}
|
|
|
|
} else if (e->type == ButtonRelease) {
|
2003-04-17 16:18:34 +00:00
|
|
|
if (!button || e->xbutton.button == button) {
|
2003-04-18 01:51:41 +00:00
|
|
|
moveresize_end(FALSE);
|
2003-04-17 06:17:06 +00:00
|
|
|
}
|
|
|
|
} else if (e->type == MotionNotify) {
|
2003-04-17 05:28:35 +00:00
|
|
|
if (moving) {
|
|
|
|
cur_x = start_cx + e->xmotion.x_root - start_x;
|
|
|
|
cur_y = start_cy + e->xmotion.y_root - start_y;
|
2003-08-12 19:57:04 +00:00
|
|
|
do_move(TRUE);
|
2003-04-17 05:28:35 +00:00
|
|
|
} else {
|
|
|
|
if (corner == prop_atoms.net_wm_moveresize_size_topleft) {
|
|
|
|
cur_x = start_cw - (e->xmotion.x_root - start_x);
|
|
|
|
cur_y = start_ch - (e->xmotion.y_root - start_y);
|
2003-07-10 06:18:47 +00:00
|
|
|
lockcorner = OB_CORNER_BOTTOMRIGHT;
|
2003-04-17 05:28:35 +00:00
|
|
|
} else if (corner == prop_atoms.net_wm_moveresize_size_top) {
|
|
|
|
cur_x = start_cw;
|
|
|
|
cur_y = start_ch - (e->xmotion.y_root - start_y);
|
2003-07-10 06:18:47 +00:00
|
|
|
lockcorner = OB_CORNER_BOTTOMRIGHT;
|
2003-04-17 05:28:35 +00:00
|
|
|
} else if (corner == prop_atoms.net_wm_moveresize_size_topright) {
|
|
|
|
cur_x = start_cw + (e->xmotion.x_root - start_x);
|
|
|
|
cur_y = start_ch - (e->xmotion.y_root - start_y);
|
2003-07-10 06:18:47 +00:00
|
|
|
lockcorner = OB_CORNER_BOTTOMLEFT;
|
2003-04-17 05:28:35 +00:00
|
|
|
} else if (corner == prop_atoms.net_wm_moveresize_size_right) {
|
|
|
|
cur_x = start_cw + (e->xmotion.x_root - start_x);
|
|
|
|
cur_y = start_ch;
|
2003-07-10 06:18:47 +00:00
|
|
|
lockcorner = OB_CORNER_BOTTOMLEFT;
|
2003-04-17 05:28:35 +00:00
|
|
|
} else if (corner ==
|
|
|
|
prop_atoms.net_wm_moveresize_size_bottomright) {
|
|
|
|
cur_x = start_cw + (e->xmotion.x_root - start_x);
|
|
|
|
cur_y = start_ch + (e->xmotion.y_root - start_y);
|
2003-07-10 06:18:47 +00:00
|
|
|
lockcorner = OB_CORNER_TOPLEFT;
|
2003-04-17 05:28:35 +00:00
|
|
|
} else if (corner == prop_atoms.net_wm_moveresize_size_bottom) {
|
|
|
|
cur_x = start_cw;
|
|
|
|
cur_y = start_ch + (e->xmotion.y_root - start_y);
|
2003-07-10 06:18:47 +00:00
|
|
|
lockcorner = OB_CORNER_TOPLEFT;
|
2003-04-17 05:28:35 +00:00
|
|
|
} else if (corner ==
|
|
|
|
prop_atoms.net_wm_moveresize_size_bottomleft) {
|
|
|
|
cur_x = start_cw - (e->xmotion.x_root - start_x);
|
|
|
|
cur_y = start_ch + (e->xmotion.y_root - start_y);
|
2003-07-10 06:18:47 +00:00
|
|
|
lockcorner = OB_CORNER_TOPRIGHT;
|
2003-04-17 05:28:35 +00:00
|
|
|
} else if (corner == prop_atoms.net_wm_moveresize_size_left) {
|
|
|
|
cur_x = start_cw - (e->xmotion.x_root - start_x);
|
|
|
|
cur_y = start_ch;
|
2003-07-10 06:18:47 +00:00
|
|
|
lockcorner = OB_CORNER_TOPRIGHT;
|
2003-04-17 05:28:35 +00:00
|
|
|
} else if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
|
|
|
|
cur_x = start_cw + (e->xmotion.x_root - start_x);
|
|
|
|
cur_y = start_ch + (e->xmotion.y_root - start_y);
|
2003-07-10 06:18:47 +00:00
|
|
|
lockcorner = OB_CORNER_TOPLEFT;
|
2003-04-17 05:28:35 +00:00
|
|
|
} else
|
|
|
|
g_assert_not_reached();
|
|
|
|
|
2003-08-12 19:57:04 +00:00
|
|
|
do_resize(TRUE);
|
2003-04-17 05:28:35 +00:00
|
|
|
}
|
2003-04-17 06:17:06 +00:00
|
|
|
} else if (e->type == KeyPress) {
|
2003-07-10 06:18:47 +00:00
|
|
|
if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE))
|
2003-04-18 01:51:41 +00:00
|
|
|
moveresize_end(TRUE);
|
2003-07-10 06:18:47 +00:00
|
|
|
else if (e->xkey.keycode == ob_keycode(OB_KEY_RETURN))
|
2003-04-18 01:51:41 +00:00
|
|
|
moveresize_end(FALSE);
|
2003-04-17 06:17:06 +00:00
|
|
|
else {
|
|
|
|
if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
|
2003-08-20 04:45:55 +00:00
|
|
|
int dx = 0, dy = 0;
|
|
|
|
|
2003-07-10 06:18:47 +00:00
|
|
|
if (e->xkey.keycode == ob_keycode(OB_KEY_RIGHT))
|
2003-08-20 04:45:55 +00:00
|
|
|
dx = MAX(4, moveresize_client->size_inc.width);
|
2003-07-10 06:18:47 +00:00
|
|
|
else if (e->xkey.keycode == ob_keycode(OB_KEY_LEFT))
|
2003-08-20 04:45:55 +00:00
|
|
|
dx = -MAX(4, moveresize_client->size_inc.width);
|
2003-07-10 06:18:47 +00:00
|
|
|
else if (e->xkey.keycode == ob_keycode(OB_KEY_DOWN))
|
2003-08-20 04:45:55 +00:00
|
|
|
dy = MAX(4, moveresize_client->size_inc.height);
|
2003-07-10 06:18:47 +00:00
|
|
|
else if (e->xkey.keycode == ob_keycode(OB_KEY_UP))
|
2003-08-20 04:45:55 +00:00
|
|
|
dy = -MAX(4, moveresize_client->size_inc.height);
|
2003-04-17 06:17:06 +00:00
|
|
|
else
|
|
|
|
return;
|
2003-08-20 04:45:55 +00:00
|
|
|
|
|
|
|
cur_x += dx;
|
|
|
|
cur_y += dy;
|
|
|
|
XWarpPointer(ob_display, None, None, 0, 0, 0, 0, dx, dy);
|
|
|
|
|
2003-08-12 19:57:04 +00:00
|
|
|
do_resize(FALSE);
|
2003-04-17 06:17:06 +00:00
|
|
|
} else if (corner == prop_atoms.net_wm_moveresize_move_keyboard) {
|
2003-08-20 04:45:55 +00:00
|
|
|
int dx = 0, dy = 0;
|
|
|
|
|
2003-07-10 06:18:47 +00:00
|
|
|
if (e->xkey.keycode == ob_keycode(OB_KEY_RIGHT))
|
2003-08-20 04:45:55 +00:00
|
|
|
dx = 4;
|
2003-07-10 06:18:47 +00:00
|
|
|
else if (e->xkey.keycode == ob_keycode(OB_KEY_LEFT))
|
2003-08-20 04:45:55 +00:00
|
|
|
dx = -4;
|
2003-07-10 06:18:47 +00:00
|
|
|
else if (e->xkey.keycode == ob_keycode(OB_KEY_DOWN))
|
2003-08-20 04:45:55 +00:00
|
|
|
dy = 4;
|
2003-07-10 06:18:47 +00:00
|
|
|
else if (e->xkey.keycode == ob_keycode(OB_KEY_UP))
|
2003-08-20 04:45:55 +00:00
|
|
|
dy = -4;
|
2003-04-17 06:17:06 +00:00
|
|
|
else
|
|
|
|
return;
|
2003-08-20 04:45:55 +00:00
|
|
|
|
|
|
|
cur_x += dx;
|
|
|
|
cur_y += dy;
|
|
|
|
XWarpPointer(ob_display, None, None, 0, 0, 0, 0, dx, dy);
|
|
|
|
|
2003-08-12 19:57:04 +00:00
|
|
|
do_move(FALSE);
|
2003-04-17 05:28:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|