floating: re-implement floating_modifier + left/right mouse button to drag/resize
This commit is contained in:
parent
84e78c6dba
commit
c33d352fd2
@ -78,7 +78,6 @@ int floating_border_click(xcb_connection_t *conn, Client *client,
|
||||
*
|
||||
*/
|
||||
void floating_drag_window(Con *con, xcb_button_press_event_t *event);
|
||||
#if 0
|
||||
|
||||
/**
|
||||
* Called when the user clicked on a floating window while holding the
|
||||
@ -86,9 +85,9 @@ void floating_drag_window(Con *con, xcb_button_press_event_t *event);
|
||||
* Calls the drag_pointer function with the resize_window callback
|
||||
*
|
||||
*/
|
||||
void floating_resize_window(xcb_connection_t *conn, Client *client,
|
||||
bool proportional, xcb_button_press_event_t *event);
|
||||
void floating_resize_window(Con *con, bool proportional, xcb_button_press_event_t *event);
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Changes focus in the given direction for floating clients.
|
||||
*
|
||||
|
29
src/click.c
29
src/click.c
@ -238,7 +238,7 @@ static bool floating_mod_on_tiled_client(xcb_connection_t *conn, Client *client,
|
||||
|
||||
int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_event_t *event) {
|
||||
Con *con;
|
||||
LOG("Button %d pressed\n", event->state);
|
||||
LOG("Button %d pressed on window 0x%08x\n", event->state, event->event);
|
||||
|
||||
con = con_by_window_id(event->event);
|
||||
bool border_click = false;
|
||||
@ -246,50 +246,61 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_
|
||||
con = con_by_frame_id(event->event);
|
||||
border_click = true;
|
||||
}
|
||||
LOG("border_click = %d\n", border_click);
|
||||
//if (con && con->type == CT_FLOATING_CON)
|
||||
//con = TAILQ_FIRST(&(con->nodes_head));
|
||||
|
||||
/* See if this was a click with the configured modifier. If so, we need
|
||||
* to move around the client if it was floating. if not, we just process
|
||||
* as usual. */
|
||||
//if (config.floating_modifier != 0 &&
|
||||
//(event->state & config.floating_modifier) == config.floating_modifier) {
|
||||
LOG("state = %d, floating_modifier = %d\n", event->state, config.floating_modifier);
|
||||
if (border_click ||
|
||||
(config.floating_modifier != 0 &&
|
||||
(event->state & config.floating_modifier) == config.floating_modifier)) {
|
||||
if (con == NULL) {
|
||||
LOG("Not handling, floating_modifier was pressed and no client found\n");
|
||||
return 1;
|
||||
}
|
||||
LOG("handling\n");
|
||||
#if 0
|
||||
if (con->fullscreen) {
|
||||
LOG("Not handling, client is in fullscreen mode\n");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
if (con->type == CT_FLOATING_CON) {
|
||||
if ((border_click && con->type == CT_FLOATING_CON) ||
|
||||
(!border_click && con_is_floating(con))) {
|
||||
/* floating operations are always on the container around
|
||||
* the "payload container", so make sure we use the right one */
|
||||
Con *floatingcon = (border_click ? con : con->parent);
|
||||
LOG("button %d pressed\n", event->detail);
|
||||
if (event->detail == 1) {
|
||||
LOG("left mouse button, dragging\n");
|
||||
floating_drag_window(con, event);
|
||||
floating_drag_window(floatingcon, event);
|
||||
}
|
||||
#if 0
|
||||
else if (event->detail == 3) {
|
||||
bool proportional = (event->state & BIND_SHIFT);
|
||||
DLOG("right mouse button\n");
|
||||
floating_resize_window(conn, client, proportional, event);
|
||||
floating_resize_window(floatingcon, proportional, event);
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (!floating_mod_on_tiled_client(conn, client, event)) {
|
||||
#endif
|
||||
xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
|
||||
xcb_flush(conn);
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
//}
|
||||
}
|
||||
|
||||
xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
|
||||
xcb_flush(conn);
|
||||
return 0;
|
||||
#if 0
|
||||
if (client == NULL) {
|
||||
/* The client was neither on a client’s titlebar nor on a client itself, maybe on a stack_window? */
|
||||
|
107
src/floating.c
107
src/floating.c
@ -340,7 +340,6 @@ void floating_drag_window(Con *con, xcb_button_press_event_t *event) {
|
||||
tree_render();
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* This is an ugly data structure which we need because there is no standard
|
||||
* way of having nested functions (only available as a gcc extension at the
|
||||
@ -349,55 +348,60 @@ void floating_drag_window(Con *con, xcb_button_press_event_t *event) {
|
||||
*
|
||||
*/
|
||||
struct resize_window_callback_params {
|
||||
border_t corner;
|
||||
bool proportional;
|
||||
xcb_button_press_event_t *event;
|
||||
border_t corner;
|
||||
bool proportional;
|
||||
xcb_button_press_event_t *event;
|
||||
};
|
||||
|
||||
DRAGGING_CB(resize_window_callback) {
|
||||
struct resize_window_callback_params *params = extra;
|
||||
xcb_button_press_event_t *event = params->event;
|
||||
border_t corner = params->corner;
|
||||
struct resize_window_callback_params *params = extra;
|
||||
xcb_button_press_event_t *event = params->event;
|
||||
border_t corner = params->corner;
|
||||
|
||||
int32_t dest_x = client->rect.x;
|
||||
int32_t dest_y = client->rect.y;
|
||||
uint32_t dest_width;
|
||||
uint32_t dest_height;
|
||||
int32_t dest_x = con->rect.x;
|
||||
int32_t dest_y = con->rect.y;
|
||||
uint32_t dest_width;
|
||||
uint32_t dest_height;
|
||||
|
||||
double ratio = (double) old_rect->width / old_rect->height;
|
||||
double ratio = (double) old_rect->width / old_rect->height;
|
||||
|
||||
/* First guess: We resize by exactly the amount the mouse moved,
|
||||
* taking into account in which corner the client was grabbed */
|
||||
if (corner & BORDER_LEFT)
|
||||
dest_width = old_rect->width - (new_x - event->root_x);
|
||||
else dest_width = old_rect->width + (new_x - event->root_x);
|
||||
/* First guess: We resize by exactly the amount the mouse moved,
|
||||
* taking into account in which corner the client was grabbed */
|
||||
if (corner & BORDER_LEFT)
|
||||
dest_width = old_rect->width - (new_x - event->root_x);
|
||||
else dest_width = old_rect->width + (new_x - event->root_x);
|
||||
|
||||
if (corner & BORDER_TOP)
|
||||
dest_height = old_rect->height - (new_y - event->root_y);
|
||||
else dest_height = old_rect->height + (new_y - event->root_y);
|
||||
if (corner & BORDER_TOP)
|
||||
dest_height = old_rect->height - (new_y - event->root_y);
|
||||
else dest_height = old_rect->height + (new_y - event->root_y);
|
||||
|
||||
/* Obey minimum window size */
|
||||
dest_width = max(dest_width, client_min_width(client));
|
||||
dest_height = max(dest_height, client_min_height(client));
|
||||
/* TODO: minimum window size */
|
||||
#if 0
|
||||
/* Obey minimum window size */
|
||||
dest_width = max(dest_width, client_min_width(client));
|
||||
dest_height = max(dest_height, client_min_height(client));
|
||||
#endif
|
||||
|
||||
/* User wants to keep proportions, so we may have to adjust our values */
|
||||
if (params->proportional) {
|
||||
dest_width = max(dest_width, (int) (dest_height * ratio));
|
||||
dest_height = max(dest_height, (int) (dest_width / ratio));
|
||||
}
|
||||
/* User wants to keep proportions, so we may have to adjust our values */
|
||||
if (params->proportional) {
|
||||
dest_width = max(dest_width, (int) (dest_height * ratio));
|
||||
dest_height = max(dest_height, (int) (dest_width / ratio));
|
||||
}
|
||||
|
||||
/* If not the lower right corner is grabbed, we must also reposition
|
||||
* the client by exactly the amount we resized it */
|
||||
if (corner & BORDER_LEFT)
|
||||
dest_x = old_rect->x + (old_rect->width - dest_width);
|
||||
/* If not the lower right corner is grabbed, we must also reposition
|
||||
* the client by exactly the amount we resized it */
|
||||
if (corner & BORDER_LEFT)
|
||||
dest_x = old_rect->x + (old_rect->width - dest_width);
|
||||
|
||||
if (corner & BORDER_TOP)
|
||||
dest_y = old_rect->y + (old_rect->height - dest_height);
|
||||
if (corner & BORDER_TOP)
|
||||
dest_y = old_rect->y + (old_rect->height - dest_height);
|
||||
|
||||
client->rect = (Rect) { dest_x, dest_y, dest_width, dest_height };
|
||||
con->rect = (Rect) { dest_x, dest_y, dest_width, dest_height };
|
||||
|
||||
/* resize_client flushes */
|
||||
resize_client(conn, client);
|
||||
/* TODO: don’t re-render the whole tree just because we change
|
||||
* coordinates of a floating window */
|
||||
tree_render();
|
||||
x_push_changes(croot);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -406,28 +410,27 @@ DRAGGING_CB(resize_window_callback) {
|
||||
* Calls the drag_pointer function with the resize_window callback
|
||||
*
|
||||
*/
|
||||
void floating_resize_window(xcb_connection_t *conn, Client *client,
|
||||
bool proportional, xcb_button_press_event_t *event) {
|
||||
DLOG("floating_resize_window\n");
|
||||
void floating_resize_window(Con *con, bool proportional,
|
||||
xcb_button_press_event_t *event) {
|
||||
DLOG("floating_resize_window\n");
|
||||
|
||||
/* corner saves the nearest corner to the original click. It contains
|
||||
* a bitmask of the nearest borders (BORDER_LEFT, BORDER_RIGHT, …) */
|
||||
border_t corner = 0;
|
||||
/* corner saves the nearest corner to the original click. It contains
|
||||
* a bitmask of the nearest borders (BORDER_LEFT, BORDER_RIGHT, …) */
|
||||
border_t corner = 0;
|
||||
|
||||
if (event->event_x <= (client->rect.width / 2))
|
||||
corner |= BORDER_LEFT;
|
||||
else corner |= BORDER_RIGHT;
|
||||
if (event->event_x <= (con->rect.width / 2))
|
||||
corner |= BORDER_LEFT;
|
||||
else corner |= BORDER_RIGHT;
|
||||
|
||||
if (event->event_y <= (client->rect.height / 2))
|
||||
corner |= BORDER_TOP;
|
||||
else corner |= BORDER_RIGHT;
|
||||
if (event->event_y <= (con->rect.height / 2))
|
||||
corner |= BORDER_TOP;
|
||||
else corner |= BORDER_RIGHT;
|
||||
|
||||
struct resize_window_callback_params params = { corner, proportional, event };
|
||||
struct resize_window_callback_params params = { corner, proportional, event };
|
||||
|
||||
drag_pointer(conn, client, event, XCB_NONE, BORDER_TOP /* irrelevant */, resize_window_callback, ¶ms);
|
||||
drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, resize_window_callback, ¶ms);
|
||||
}
|
||||
|
||||
#endif
|
||||
/*
|
||||
* This function grabs your pointer and lets you drag stuff around (borders).
|
||||
* Every time you move your mouse, an XCB_MOTION_NOTIFY event will be received
|
||||
|
12
src/manage.c
12
src/manage.c
@ -128,6 +128,18 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
|
||||
i3Window *cwindow = scalloc(sizeof(i3Window));
|
||||
cwindow->id = window;
|
||||
|
||||
/* We need to grab the mouse buttons for click to focus */
|
||||
xcb_grab_button(conn, false, window, XCB_EVENT_MASK_BUTTON_PRESS,
|
||||
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, root, XCB_NONE,
|
||||
1 /* left mouse button */,
|
||||
XCB_BUTTON_MASK_ANY /* don’t filter for any modifiers */);
|
||||
|
||||
xcb_grab_button(conn, false, window, XCB_EVENT_MASK_BUTTON_PRESS,
|
||||
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, root, XCB_NONE,
|
||||
3 /* right mouse button */,
|
||||
XCB_BUTTON_MASK_ANY /* don’t filter for any modifiers */);
|
||||
|
||||
|
||||
/* update as much information as possible so far (some replies may be NULL) */
|
||||
window_update_class(cwindow, xcb_get_property_reply(conn, class_cookie, NULL));
|
||||
window_update_name_legacy(cwindow, xcb_get_property_reply(conn, title_cookie, NULL));
|
||||
|
Loading…
Reference in New Issue
Block a user