-static bool button_press_stackwin(xcb_connection_t *conn, xcb_button_press_event_t *event) {
- struct Stack_Window *stack_win;
-
- /* If we find a corresponding stack window, we can handle the event */
- if ((stack_win = get_stack_window(event->event)) == NULL)
- return false;
-
- /* A stack window was clicked, we check if it was button4 or button5
- which are scroll up / scroll down. */
- if (event->detail == XCB_BUTTON_INDEX_4 || event->detail == XCB_BUTTON_INDEX_5) {
- direction_t direction = (event->detail == XCB_BUTTON_INDEX_4 ? D_UP : D_DOWN);
- focus_window_in_container(conn, CUR_CELL, direction);
- return true;
- }
-
- /* It was no scrolling, so we calculate the destination client by
- dividing the Y position of the event through the height of a window
- decoration and then set the focus to this client. */
- i3Font *font = load_font(conn, config.font);
- int decoration_height = (font->height + 2 + 2);
- int destination = (event->event_y / decoration_height),
- c = 0,
- num_clients = 0;
- Client *client;
- Container *container = stack_win->container;
-
- CIRCLEQ_FOREACH(client, &(container->clients), clients)
- num_clients++;
-
- /* If we don’t have any clients in this container, we cannot do
- * anything useful anyways. */
- if (num_clients == 0)
- return true;
-
- if (container->mode == MODE_TABBED)
- destination = (event->event_x / (container->width / num_clients));
- else if (container->mode == MODE_STACK &&
- container->stack_limit != STACK_LIMIT_NONE) {
- if (container->stack_limit == STACK_LIMIT_COLS) {
- int wrap = ceil((float)num_clients / container->stack_limit_value);
- int clicked_column = (event->event_x / (stack_win->rect.width / container->stack_limit_value));
- int clicked_row = (event->event_y / decoration_height);
- DLOG("clicked on column %d, row %d\n", clicked_column, clicked_row);
- destination = (wrap * clicked_column) + clicked_row;
- } else {
- int width = (stack_win->rect.width / ceil((float)num_clients / container->stack_limit_value));
- int clicked_column = (event->event_x / width);
- int clicked_row = (event->event_y / decoration_height);
- DLOG("clicked on column %d, row %d\n", clicked_column, clicked_row);
- destination = (container->stack_limit_value * clicked_column) + clicked_row;
- }
- }
-
- DLOG("Click on stack_win for client %d\n", destination);
- CIRCLEQ_FOREACH(client, &(stack_win->container->clients), clients)
- if (c++ == destination) {
- set_focus(conn, client, true);
- return true;
- }
-
- return true;
+static bool floating_mod_on_tiled_client(Con *con, xcb_button_press_event_t *event) {
+ /* 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 */
+ int to_right = con->rect.width - event->event_x,
+ to_left = event->event_x,
+ to_top = event->event_y,
+ to_bottom = con->rect.height - event->event_y;
+
+ DLOG("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)
+ return tiling_resize_for_border(con, BORDER_RIGHT, event);
+
+ if (to_left < to_right &&
+ to_left < to_top &&
+ to_left < to_bottom)
+ return tiling_resize_for_border(con, BORDER_LEFT, event);
+
+ if (to_top < to_right &&
+ to_top < to_left &&
+ to_top < to_bottom)
+ return tiling_resize_for_border(con, BORDER_TOP, event);
+
+ if (to_bottom < to_right &&
+ to_bottom < to_left &&
+ to_bottom < to_top)
+ return tiling_resize_for_border(con, BORDER_BOTTOM, event);
+
+ return false;