-int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_event_t *event) {
- LOG("Button %d pressed\n", event->state);
- /* This was either a focus for a client’s parent (= titlebar)… */
- Client *client = table_get(&by_child, event->event);
- bool border_click = false;
- if (client == NULL) {
- client = table_get(&by_parent, event->event);
- border_click = true;
- }
- /* 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) != 0) {
- if (client == NULL) {
- LOG("Not handling, floating_modifier was pressed and no client found\n");
- return 1;
- }
- if (client_is_floating(client)) {
- LOG("button %d pressed\n", event->detail);
- if (event->detail == 1) {
- LOG("left mouse button, dragging\n");
- floating_drag_window(conn, client, event);
- } else if (event->detail == 3) {
- LOG("right mouse button\n");
- floating_resize_window(conn, client, event);
- }
- return 1;
- } else {
- /* The client is in tiling layout. We can still
- * initiate a resize with the right mouse button,
- * by chosing the border which is the most near one
- * to the position of the mouse pointer */
- if (event->detail == 3) {
- int to_right = client->rect.width - event->event_x,
- to_left = event->event_x,
- to_top = event->event_y,
- to_bottom = client->rect.height - event->event_y;
- resize_orientation_t orientation = O_VERTICAL;
- Container *con = client->container;
- int first = 0, second = 0;
-
- LOG("click was %d px to the right, %d px to the left, %d px to top, %d px to bottom\n",
- to_right, to_left, to_top, to_bottom);
-
- if (to_right < to_left &&
- to_right < to_top &&
- to_right < to_bottom) {
- /* …right border */
- first = con->col + (con->colspan - 1);
- LOG("column %d\n", first);
-
- if (!cell_exists(first, con->row) ||
- (first == (con->workspace->cols-1)))
- return 1;
-
- second = first + 1;
- } else if (to_left < to_right &&
- to_left < to_top &&
- to_left < to_bottom) {
- /* …left border */
- if (con->col == 0)
- return 1;
-
- first = con->col - 1;
- second = con->col;
- } else if (to_top < to_right &&
- to_top < to_left &&
- to_top < to_bottom) {
- /* This was a press on the top border */
- if (con->row == 0)
- return 1;
- first = con->row - 1;
- second = con->row;
- orientation = O_HORIZONTAL;
- } else if (to_bottom < to_right &&
- to_bottom < to_left &&
- to_bottom < to_top) {
- /* …bottom border */
- first = con->row + (con->rowspan - 1);
- if (!cell_exists(con->col, first) ||
- (first == (con->workspace->rows-1)))
- return 1;
-
- second = first + 1;
- orientation = O_HORIZONTAL;
- }
-
- return resize_graphical_handler(conn, con->workspace, first, second, orientation, event);
- }
- }
+/*
+ * Finds out which border was clicked on and calls tiling_resize_for_border().
+ *
+ */
+static bool tiling_resize(Con *con, xcb_button_press_event_t *event, const click_destination_t dest) {
+ /* check if this was a click on the window border (and on which one) */
+ Rect bsr = con_border_style_rect(con);
+ DLOG("BORDER x = %d, y = %d for con %p, window 0x%08x\n",
+ event->event_x, event->event_y, con, event->event);
+ DLOG("checks for right >= %d\n", con->window_rect.x + con->window_rect.width);
+ if (dest == CLICK_DECORATION) {
+ /* The user clicked on a window decoration. We ignore the following case:
+ * The container is a h-split, tabbed or stacked container with > 1
+ * window. Decorations will end up next to each other and the user
+ * expects to switch to a window by clicking on its decoration. */
+
+ /* Since the container might either be the child *or* already a split
+ * container (in the case of a nested split container), we need to make
+ * sure that we are dealing with the split container here. */
+ Con *check_con = con;
+ if (con_is_leaf(check_con) && check_con->parent->type == CT_CON)
+ check_con = check_con->parent;
+
+ if ((check_con->layout == L_STACKED ||
+ check_con->layout == L_TABBED ||
+ con_orientation(check_con) == HORIZ) &&
+ con_num_children(check_con) > 1) {
+ DLOG("Not handling this resize, this container has > 1 child.\n");
+ return false;