floating: re-implement floating_modifier + left/right mouse button to drag/resize

This commit is contained in:
Michael Stapelberg 2010-06-28 22:23:32 +02:00
parent 84e78c6dba
commit c33d352fd2
4 changed files with 89 additions and 64 deletions

View File

@ -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); 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 * 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 * Calls the drag_pointer function with the resize_window callback
* *
*/ */
void floating_resize_window(xcb_connection_t *conn, Client *client, void floating_resize_window(Con *con, bool proportional, xcb_button_press_event_t *event);
bool proportional, xcb_button_press_event_t *event);
#if 0
/** /**
* Changes focus in the given direction for floating clients. * Changes focus in the given direction for floating clients.
* *

View File

@ -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) { int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_event_t *event) {
Con *con; 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); con = con_by_window_id(event->event);
bool border_click = false; 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); con = con_by_frame_id(event->event);
border_click = true; border_click = true;
} }
LOG("border_click = %d\n", border_click);
//if (con && con->type == CT_FLOATING_CON) //if (con && con->type == CT_FLOATING_CON)
//con = TAILQ_FIRST(&(con->nodes_head)); //con = TAILQ_FIRST(&(con->nodes_head));
/* See if this was a click with the configured modifier. If so, we need /* 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 * to move around the client if it was floating. if not, we just process
* as usual. */ * as usual. */
//if (config.floating_modifier != 0 && LOG("state = %d, floating_modifier = %d\n", event->state, config.floating_modifier);
//(event->state & config.floating_modifier) == config.floating_modifier) { if (border_click ||
(config.floating_modifier != 0 &&
(event->state & config.floating_modifier) == config.floating_modifier)) {
if (con == NULL) { if (con == NULL) {
LOG("Not handling, floating_modifier was pressed and no client found\n"); LOG("Not handling, floating_modifier was pressed and no client found\n");
return 1; return 1;
} }
LOG("handling\n");
#if 0 #if 0
if (con->fullscreen) { if (con->fullscreen) {
LOG("Not handling, client is in fullscreen mode\n"); LOG("Not handling, client is in fullscreen mode\n");
return 1; return 1;
} }
#endif #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); LOG("button %d pressed\n", event->detail);
if (event->detail == 1) { if (event->detail == 1) {
LOG("left mouse button, dragging\n"); LOG("left mouse button, dragging\n");
floating_drag_window(con, event); floating_drag_window(floatingcon, event);
} }
#if 0
else if (event->detail == 3) { else if (event->detail == 3) {
bool proportional = (event->state & BIND_SHIFT); bool proportional = (event->state & BIND_SHIFT);
DLOG("right mouse button\n"); DLOG("right mouse button\n");
floating_resize_window(conn, client, proportional, event); floating_resize_window(floatingcon, proportional, event);
} }
#endif
return 1; return 1;
} }
#if 0 #if 0
if (!floating_mod_on_tiled_client(conn, client, event)) { if (!floating_mod_on_tiled_client(conn, client, event)) {
#endif
xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time); xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
xcb_flush(conn); xcb_flush(conn);
#if 0
} }
#endif #endif
return 1; return 1;
//} }
xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
xcb_flush(conn);
return 0;
#if 0 #if 0
if (client == NULL) { if (client == NULL) {
/* The client was neither on a clients titlebar nor on a client itself, maybe on a stack_window? */ /* The client was neither on a clients titlebar nor on a client itself, maybe on a stack_window? */

View File

@ -340,7 +340,6 @@ void floating_drag_window(Con *con, xcb_button_press_event_t *event) {
tree_render(); tree_render();
} }
#if 0
/* /*
* This is an ugly data structure which we need because there is no standard * 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 * 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 { struct resize_window_callback_params {
border_t corner; border_t corner;
bool proportional; bool proportional;
xcb_button_press_event_t *event; xcb_button_press_event_t *event;
}; };
DRAGGING_CB(resize_window_callback) { DRAGGING_CB(resize_window_callback) {
struct resize_window_callback_params *params = extra; struct resize_window_callback_params *params = extra;
xcb_button_press_event_t *event = params->event; xcb_button_press_event_t *event = params->event;
border_t corner = params->corner; border_t corner = params->corner;
int32_t dest_x = client->rect.x; int32_t dest_x = con->rect.x;
int32_t dest_y = client->rect.y; int32_t dest_y = con->rect.y;
uint32_t dest_width; uint32_t dest_width;
uint32_t dest_height; 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, /* First guess: We resize by exactly the amount the mouse moved,
* taking into account in which corner the client was grabbed */ * taking into account in which corner the client was grabbed */
if (corner & BORDER_LEFT) if (corner & BORDER_LEFT)
dest_width = old_rect->width - (new_x - event->root_x); dest_width = old_rect->width - (new_x - event->root_x);
else 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) if (corner & BORDER_TOP)
dest_height = old_rect->height - (new_y - event->root_y); dest_height = old_rect->height - (new_y - event->root_y);
else 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 */ /* TODO: minimum window size */
dest_width = max(dest_width, client_min_width(client)); #if 0
dest_height = max(dest_height, client_min_height(client)); /* 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 */ /* User wants to keep proportions, so we may have to adjust our values */
if (params->proportional) { if (params->proportional) {
dest_width = max(dest_width, (int) (dest_height * ratio)); dest_width = max(dest_width, (int) (dest_height * ratio));
dest_height = max(dest_height, (int) (dest_width / ratio)); dest_height = max(dest_height, (int) (dest_width / ratio));
} }
/* If not the lower right corner is grabbed, we must also reposition /* If not the lower right corner is grabbed, we must also reposition
* the client by exactly the amount we resized it */ * the client by exactly the amount we resized it */
if (corner & BORDER_LEFT) if (corner & BORDER_LEFT)
dest_x = old_rect->x + (old_rect->width - dest_width); dest_x = old_rect->x + (old_rect->width - dest_width);
if (corner & BORDER_TOP) if (corner & BORDER_TOP)
dest_y = old_rect->y + (old_rect->height - dest_height); 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 */ /* TODO: dont re-render the whole tree just because we change
resize_client(conn, client); * 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 * Calls the drag_pointer function with the resize_window callback
* *
*/ */
void floating_resize_window(xcb_connection_t *conn, Client *client, void floating_resize_window(Con *con, bool proportional,
bool proportional, xcb_button_press_event_t *event) { xcb_button_press_event_t *event) {
DLOG("floating_resize_window\n"); DLOG("floating_resize_window\n");
/* corner saves the nearest corner to the original click. It contains /* corner saves the nearest corner to the original click. It contains
* a bitmask of the nearest borders (BORDER_LEFT, BORDER_RIGHT, ) */ * a bitmask of the nearest borders (BORDER_LEFT, BORDER_RIGHT, ) */
border_t corner = 0; border_t corner = 0;
if (event->event_x <= (client->rect.width / 2)) if (event->event_x <= (con->rect.width / 2))
corner |= BORDER_LEFT; corner |= BORDER_LEFT;
else corner |= BORDER_RIGHT; else corner |= BORDER_RIGHT;
if (event->event_y <= (client->rect.height / 2)) if (event->event_y <= (con->rect.height / 2))
corner |= BORDER_TOP; corner |= BORDER_TOP;
else corner |= BORDER_RIGHT; 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, &params); drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, resize_window_callback, &params);
} }
#endif
/* /*
* This function grabs your pointer and lets you drag stuff around (borders). * 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 * Every time you move your mouse, an XCB_MOTION_NOTIFY event will be received

View File

@ -128,6 +128,18 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
i3Window *cwindow = scalloc(sizeof(i3Window)); i3Window *cwindow = scalloc(sizeof(i3Window));
cwindow->id = window; 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 /* dont 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 /* dont filter for any modifiers */);
/* update as much information as possible so far (some replies may be NULL) */ /* 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_class(cwindow, xcb_get_property_reply(conn, class_cookie, NULL));
window_update_name_legacy(cwindow, xcb_get_property_reply(conn, title_cookie, NULL)); window_update_name_legacy(cwindow, xcb_get_property_reply(conn, title_cookie, NULL));