From e139de0857a1ba015fa324dcc662a39eca88761b Mon Sep 17 00:00:00 2001 From: taiyu Date: Sat, 22 Aug 2015 18:01:38 -0700 Subject: [PATCH 1/8] floating/tiling move + floating resize cleaned and fixed --- include/input_state.h | 46 ++++++++- include/layout.h | 2 + sway/handlers.c | 190 ++++++++++++++++++------------------ sway/input_state.c | 219 ++++++++++++++++++++++++++++++++++++++++++ sway/layout.c | 109 +++++++++++++++------ sway/resize.c | 24 ++--- 6 files changed, 454 insertions(+), 136 deletions(-) diff --git a/include/input_state.h b/include/input_state.h index 04fde42d..3a246e0c 100644 --- a/include/input_state.h +++ b/include/input_state.h @@ -17,6 +17,7 @@ void press_key(keycode key); // unsets a key as pressed void release_key(keycode key); + /* Pointer state */ enum pointer_values { @@ -27,9 +28,40 @@ enum pointer_values { M_SCROLL_DOWN = 276, }; +enum pointer_mode { + // Target + M_FLOATING = 1 << 0, + M_TILING = 1 << 1, + // Action + M_DRAGGING = 1 << 2, + M_RESIZING = 1 << 3, +}; + extern struct pointer_state { - bool l_held; - bool r_held; + // mouse clicks + bool l_held : 1; + bool r_held : 1; + + // scroll wheel + bool s_held : 1; + bool s_up : 1; + bool s_down :1; + + // pointer position + struct mouse_origin{ + int x, y; + } origin; + struct { + int x, y; + } delta; + + // view pointer is over + swayc_t *view; + + // Pointer mode + int mode; + + // OLD struct pointer_floating { bool drag; bool resize; @@ -53,6 +85,16 @@ extern struct pointer_state { } lock; } pointer_state; +// on button release unset mode depending on the button. +// on button press set mode conditionally depending on the button +void pointer_mode_set(uint32_t button, bool condition); + +// Update mode in mouse motion +void pointer_mode_update(void); + +// Reset mode on any keypress; +void pointer_mode_reset(void); + void start_floating(swayc_t *view); void reset_floating(swayc_t *view); void input_init(void); diff --git a/include/layout.h b/include/layout.h index f8aebe0a..8f269607 100644 --- a/include/layout.h +++ b/include/layout.h @@ -19,10 +19,12 @@ void add_floating(swayc_t *ws, swayc_t *child); swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); swayc_t *replace_child(swayc_t *child, swayc_t *new_child); swayc_t *remove_child(swayc_t *child); +void swap_container(swayc_t *a, swayc_t *b); void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction); // Layout +void update_geometry(swayc_t *view); void arrange_windows(swayc_t *container, double width, double height); swayc_t *get_focused_container(swayc_t *parent); diff --git a/sway/handlers.c b/sway/handlers.c index cb42196f..7d1e4cde 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -17,10 +17,8 @@ #include "input_state.h" #include "resize.h" -struct wlc_origin mouse_origin; - static bool pointer_test(swayc_t *view, void *_origin) { - const struct wlc_origin *origin = _origin; + const struct mouse_origin *origin = _origin; // Determine the output that the view is under swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); if (origin->x >= view->x && origin->y >= view->y @@ -55,7 +53,7 @@ swayc_t *container_under_pointer(void) { i = len = lookup->floating->length; bool got_floating = false; while (--i > -1) { - if (pointer_test(lookup->floating->items[i], &mouse_origin)) { + if (pointer_test(lookup->floating->items[i], &pointer_state.origin)) { lookup = lookup->floating->items[i]; got_floating = true; break; @@ -68,7 +66,7 @@ swayc_t *container_under_pointer(void) { // search children len = lookup->children->length; for (i = 0; i < len; ++i) { - if (pointer_test(lookup->children->items[i], &mouse_origin)) { + if (pointer_test(lookup->children->items[i], &pointer_state.origin)) { lookup = lookup->children->items[i]; break; } @@ -281,10 +279,9 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier return false; } - // Revert floating container back to original position on keypress - if (state == WLC_KEY_STATE_PRESSED && - (pointer_state.floating.drag || pointer_state.floating.resize)) { - reset_floating(get_focused_view(&root_container)); + // reset pointer mode on keypress + if (state == WLC_KEY_STATE_PRESSED && pointer_state.mode) { + pointer_mode_reset(); } struct sway_mode *mode = config->current_mode; @@ -334,83 +331,25 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier } static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) { - static struct wlc_origin prev_pos; - static wlc_handle prev_handle = 0; - mouse_origin = *origin; - bool changed_floating = false; - bool changed_tiling = false; - if (!swayc_active_workspace()) { - return false; + // Update pointer origin + pointer_state.delta.x = origin->x - pointer_state.origin.x; + pointer_state.delta.y = origin->y - pointer_state.origin.y; + pointer_state.origin.x = origin->x; + pointer_state.origin.y = origin->y; + + // Update view under pointer + swayc_t *prev_view = pointer_state.view; + pointer_state.view = container_under_pointer(); + + // If pointer is in a mode, update it + if (pointer_state.mode) { + pointer_mode_update(); } - // Do checks to determine if proper keys are being held - swayc_t *view = container_under_pointer(); - if (pointer_state.floating.drag && view) { - if (view->is_floating) { - int dx = mouse_origin.x - prev_pos.x; - int dy = mouse_origin.y - prev_pos.y; - view->x += dx; - view->y += dy; - struct wlc_geometry geometry = { - .origin = { - .x = view->x, - .y = view->y - }, - .size = { - .w = view->width, - .h = view->height - } - }; - wlc_view_set_geometry(view->handle, 0, &geometry); - changed_floating = true; - } else { - swayc_t *init_view = pointer_state.tiling.init_view; - if (view != init_view && view->type == C_VIEW) { - changed_tiling = true; - int i, j; - for (i = 0; i < view->parent->children->length; i++) { - if (view->parent->children->items[i] == view) { - for (j = 0; j < init_view->parent->children->length; j++) { - if (init_view->parent->children->items[j] == init_view) { - double temp_w = view->width; - double temp_h = view->height; - view->width = init_view->width; - view->height = init_view->height; - init_view->width = temp_w; - init_view->height = temp_h; - - init_view->parent->children->items[j] = view; - view->parent->children->items[i] = init_view; - - swayc_t *temp = view->parent; - view->parent = init_view->parent; - init_view->parent = temp; - - arrange_windows(&root_container, -1, -1); - break; - } - } - break; - } - } - } + // Otherwise change focus if config is set an + else if (prev_view != pointer_state.view && config->focus_follows_mouse) { + if (pointer_state.view && pointer_state.view->type == C_VIEW) { + set_focused_container(pointer_state.view); } - } else if (pointer_state.floating.resize && view) { - changed_floating = resize_floating(prev_pos); - } else if (pointer_state.tiling.resize && view) { - changed_tiling = mouse_resize_tiled(prev_pos); - } - if (config->focus_follows_mouse && prev_handle != handle) { - // Dont change focus if fullscreen - swayc_t *focused = get_focused_view(view); - if (!swayc_is_fullscreen(focused) - && !(pointer_state.l_held || pointer_state.r_held)) { - set_focused_container(container_under_pointer()); - } - } - prev_handle = handle; - prev_pos = mouse_origin; - if (changed_tiling || changed_floating) { - return true; } return false; } @@ -418,11 +357,82 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { + enum { DONT_SEND_CLICK = true, SEND_CLICK = false }; + + // Update pointer_state + switch (button) { + case M_LEFT_CLICK: + pointer_state.l_held = state == WLC_BUTTON_STATE_PRESSED; + break; + + case M_RIGHT_CLICK: + pointer_state.r_held = state == WLC_BUTTON_STATE_PRESSED; + break; + + case M_SCROLL_CLICK: + pointer_state.s_held = state == WLC_BUTTON_STATE_PRESSED; + break; + + case M_SCROLL_UP: + pointer_state.s_up = state == WLC_BUTTON_STATE_PRESSED; + break; + + case M_SCROLL_DOWN: + pointer_state.s_down = state == WLC_BUTTON_STATE_PRESSED; + break; + } + + // Update pointer origin + pointer_state.origin.x = origin->x; + pointer_state.origin.y = origin->y; + + // Update view pointer is on + pointer_state.view = container_under_pointer(); + + // set pointer mode + pointer_mode_set(button, + (modifiers->mods & config->floating_mod) == config->floating_mod); + + // Return if mode has been set + if (pointer_state.mode) { + return DONT_SEND_CLICK; + } + + // Always send mouse release + if (state == WLC_BUTTON_STATE_RELEASED) { + return SEND_CLICK; + } + + // get focused window and check if to change focus on mouse click swayc_t *focused = get_focused_container(&root_container); + + // Check whether to change focus + swayc_t *pointer = pointer_state.view; + if (pointer && focused != pointer) { + set_focused_container(pointer_state.view); + // Send to front if floating + if (pointer->is_floating) { + int i; + for (i = 0; i < pointer->parent->floating->length; i++) { + if (pointer->parent->floating->items[i] == pointer) { + list_del(pointer->parent->floating, i); + list_add(pointer->parent->floating, pointer); + break; + } + } + wlc_view_bring_to_front(view); + } + } + // dont change focus if fullscreen if (swayc_is_fullscreen(focused)) { - return false; + return SEND_CLICK; } + + // Finally send click + return SEND_CLICK; + + /* OLD */ if (state == WLC_BUTTON_STATE_PRESSED) { sway_log(L_DEBUG, "Mouse button %u pressed", button); if (button == M_LEFT_CLICK) { @@ -443,15 +453,6 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w } if (pointer->is_floating) { - int i; - for (i = 0; i < pointer->parent->floating->length; i++) { - if (pointer->parent->floating->items[i] == pointer) { - list_del(pointer->parent->floating, i); - list_add(pointer->parent->floating, pointer); - break; - } - } - arrange_windows(pointer->parent, -1, -1); if (modifiers->mods & config->floating_mod) { pointer_state.floating.drag = pointer_state.l_held; pointer_state.floating.resize = pointer_state.r_held; @@ -484,6 +485,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w pointer_state.lock = (struct pointer_lock){false ,false ,false ,false, false, false, false, false}; } } + /* OLD */ return false; } diff --git a/sway/input_state.c b/sway/input_state.c index e2f3c754..3db78167 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -50,6 +50,224 @@ void release_key(keycode key) { struct pointer_state pointer_state; +// Pointer mode values +static struct mode_state { + // Initial view state + struct { + double x, y, w, h; + swayc_t *ptr; + } view; + // Initial pointer state + struct { + int x, y; + } coor; +} initial; + +static struct { + enum { LEFT=1, RIGHT=0 } lr; + enum { TOP=1, BOTTOM=0 } tb; +} lock; + +// Floating set/unset + +static void pointer_mode_set_floating(void) { + initial.view.x = initial.view.ptr->x; + initial.view.y = initial.view.ptr->y; + initial.view.w = initial.view.ptr->width; + initial.view.h = initial.view.ptr->height; + // setup initial cooridinates + initial.coor.x = pointer_state.origin.x; + initial.coor.y = pointer_state.origin.y; +} + +static void pointer_mode_reset_floating(void) { + initial.view.ptr->x = initial.view.x; + initial.view.ptr->y = initial.view.y; + initial.view.ptr->width = initial.view.w; + initial.view.ptr->height = initial.view.h; + arrange_windows(initial.view.ptr, -1, -1); + pointer_state.mode = 0; +} + +// Mode set left/right click + +static void pointer_mode_set_left(void) { + swayc_t *view = pointer_state.view; + initial.view.ptr = view; + if (view->is_floating) { + pointer_state.mode = M_DRAGGING | M_FLOATING; + pointer_mode_set_floating(); + } else { + pointer_state.mode = M_DRAGGING | M_TILING; + } +} + +static void pointer_mode_set_right(void) { + swayc_t *view = pointer_state.view; + initial.view.ptr = view; + // Setup locking information + int midway_x = view->x + view->width/2; + int midway_y = view->y + view->height/2; + + lock.lr = pointer_state.origin.x > midway_x; + lock.tb = pointer_state.origin.y > midway_y; + + if (view->is_floating) { + pointer_state.mode = M_RESIZING | M_FLOATING; + pointer_mode_set_floating(); + } else { + pointer_state.mode = M_RESIZING | M_TILING; + } +} + +// Mode set/update/reset + +void pointer_mode_set(uint32_t button, bool condition) { + // switch on drag/resize mode + switch (pointer_state.mode & (M_DRAGGING | M_RESIZING)) { + case M_DRAGGING: + // end drag mode when left click is unpressed + if (!pointer_state.l_held) { + pointer_state.mode = 0; + } + break; + + case M_RESIZING: + // end resize mode when right click is unpressed + if (!pointer_state.r_held) { + pointer_state.mode = 0; + } + break; + + // No mode case + default: + // return if failed condition, or no view + if (!condition || !pointer_state.view) { + break; + } + // Set mode depending on current button press + switch (button) { + // Start dragging mode + case M_LEFT_CLICK: + // if button release dont do anything + if (pointer_state.l_held) { + pointer_mode_set_left(); + } + break; + + // Start resize mode + case M_RIGHT_CLICK: + // if button release dont do anyhting + if (pointer_state.r_held) { + pointer_mode_set_right(); + } + break; + + case M_SCROLL_UP: + case M_SCROLL_DOWN: + //TODO add scrolling behavior here + ; + } + } +} + +void pointer_mode_update(void) { + swayc_t *view = initial.view.ptr; + if (view->type != C_VIEW) { + pointer_state.mode = 0; + return; + } + int dx = pointer_state.origin.x - initial.coor.x; + int dy = pointer_state.origin.y - initial.coor.y; + bool changed = false; + + switch (pointer_state.mode) { + case M_FLOATING | M_DRAGGING: + // Update position + if (initial.view.x + dx != view->x) { + view->x = initial.view.x + dx; + changed = true; + } + if (initial.view.y + dy != view->y) { + view->y = initial.view.y + dy; + changed = true; + } + break; + + case M_FLOATING | M_RESIZING: + if (lock.lr) { + if (initial.view.w + dx > min_sane_w) { + if (initial.view.w + dx != view->width) { + view->width = initial.view.w + dx; + changed = true; + } + } + } else { //lock.right + if (initial.view.w - dx > min_sane_w) { + if (initial.view.w - dx != view->width) { + view->width = initial.view.w - dx; + view->x = initial.view.x + dx; + changed = true; + } + } + } + if (lock.tb) { + if (initial.view.h + dy > min_sane_h) { + if (initial.view.y - dy != view->height) { + view->height = initial.view.h + dy; + changed = true; + } + } + } else { //lock.bottom + if (initial.view.h - dy > min_sane_h) { + if (initial.view.h - dy != view->height) { + view->height = initial.view.h - dy; + view->y = initial.view.y + dy; + changed = true; + } + } + } + break; + + case M_TILING | M_DRAGGING: + // swap current view under pointer with dragged view + if (pointer_state.view && pointer_state.view != initial.view.ptr) { + // Swap them around + swap_container(pointer_state.view, initial.view.ptr); + update_geometry(pointer_state.view); + update_geometry(initial.view.ptr); + // Set focus back to initial view + set_focused_container(initial.view.ptr); + } + break; + + case M_TILING | M_RESIZING: + + + + default: + return; + } + if (changed) { + update_geometry(view); + } +} + +void pointer_mode_reset(void) { + switch (pointer_state.mode) { + case M_FLOATING | M_DRAGGING: + case M_FLOATING | M_RESIZING: + pointer_mode_reset_floating(); + break; + + case M_TILING | M_DRAGGING: + case M_TILING | M_RESIZING: + default: + return; + } +} + + static struct wlc_geometry saved_floating; void start_floating(swayc_t *view) { @@ -72,3 +290,4 @@ void reset_floating(swayc_t *view) { pointer_state.floating = (struct pointer_floating){0, 0}; pointer_state.lock = (struct pointer_lock){0, 0, 0, 0, 0, 0, 0, 0}; } + diff --git a/sway/layout.c b/sway/layout.c index 18ecb1e7..fd2e80fe 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -20,7 +20,8 @@ void init_layout(void) { root_container.handle = -1; } -static int index_child(swayc_t *parent, swayc_t *child) { +static int index_child(swayc_t *child) { + swayc_t *parent = child->parent; int i; for (i = 0; i < parent->children->length; ++i) { if (parent->children->items[i] == child) { @@ -54,7 +55,7 @@ void add_floating(swayc_t *ws, swayc_t *child) { swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) { swayc_t *parent = sibling->parent; - int i = index_child(parent, sibling); + int i = index_child(sibling); if (i == parent->children->length) { --i; } @@ -68,17 +69,65 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) { if (parent == NULL) { return NULL; } - int i = index_child(parent, child); + int i = index_child(child); parent->children->items[i] = new_child; new_child->parent = child->parent; + // Set parent for new child if (child->parent->focused == child) { child->parent->focused = new_child; } child->parent = NULL; + // Set geometry for new child + new_child->x = child->x; + new_child->y = child->y; + new_child->width = child->width; + new_child->height = child->height; + // set child geometry to 0 + child->x = 0; + child->y = 0; + child->width = 0; + child->height = 0; return parent; } +void swap_container(swayc_t *a, swayc_t *b) { + //TODO doesnt handle floating <-> tiling swap + if (!sway_assert(a&&b, "%s: parameters must be non null",__func__) || + !sway_assert(a->parent && b->parent, "%s: containers must have parents",__func__)) { + return; + } + size_t a_index = index_child(a); + size_t b_index = index_child(b); + swayc_t *a_parent = a->parent; + swayc_t *b_parent = b->parent; + // Swap the pointers + a_parent->children->items[a_index] = b; + b_parent->children->items[b_index] = a; + a->parent = b_parent; + b->parent = a_parent; + if (a_parent->focused == a) { + a_parent->focused = b; + } + // dont want to double switch + if (b_parent->focused == b && a_parent != b_parent) { + b_parent->focused = a; + } + // and their geometry + double x = a->x; + double y = a->y; + double w = a->width; + double h = a->height; + a->x = b->x; + a->y = b->y; + a->width = b->width; + a->height = b->height; + b->x = x; + b->y = y; + b->width = w; + b->height = h; +} + swayc_t *remove_child(swayc_t *child) { int i; swayc_t *parent = child->parent; @@ -154,6 +203,30 @@ void move_container(swayc_t *container,swayc_t* root,enum movement_direction dir } +void update_geometry(swayc_t *container) { + if (container->type != C_VIEW) { + return; + } + struct wlc_geometry geometry = { + .origin = { + .x = container->x + container->gaps / 2, + .y = container->y + container->gaps / 2 + }, + .size = { + .w = container->width - container->gaps, + .h = container->height - container->gaps + } + }; + if (swayc_is_fullscreen(container)) { + swayc_t *parent = swayc_parent_by_type(container, C_OUTPUT); + geometry.origin.x = 0; + geometry.origin.y = 0; + geometry.size.w = parent->width; + geometry.size.h = parent->height; + } + wlc_view_set_geometry(container->handle, 0, &geometry); + return; +} void arrange_windows(swayc_t *container, double width, double height) { int i; @@ -196,31 +269,11 @@ void arrange_windows(swayc_t *container, double width, double height) { return; case C_VIEW: { - struct wlc_geometry geometry = { - .origin = { - .x = container->x + container->gaps / 2, - .y = container->y + container->gaps / 2 - }, - .size = { - .w = width - container->gaps, - .h = height - container->gaps - } - }; - if (swayc_is_fullscreen(container)) { - swayc_t *parent = swayc_parent_by_type(container, C_OUTPUT); - geometry.origin.x = 0; - geometry.origin.y = 0; - geometry.size.w = parent->width; - geometry.size.h = parent->height; - wlc_view_set_geometry(container->handle, 0, &geometry); - wlc_view_bring_to_front(container->handle); - } else { - wlc_view_set_geometry(container->handle, 0, &geometry); - container->width = width; - container->height = height; - } - sway_log(L_DEBUG, "Set view to %d x %d @ %d, %d", geometry.size.w, geometry.size.h, - geometry.origin.x, geometry.origin.y); + container->width = width; + container->height = height; + update_geometry(container); + sway_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f", container->width, + container->height, container->x, container->y); } return; default: diff --git a/sway/resize.c b/sway/resize.c index a08ef4a1..31cd66e8 100644 --- a/sway/resize.c +++ b/sway/resize.c @@ -10,8 +10,8 @@ bool mouse_resize_tiled(struct wlc_origin prev_pos) { swayc_t *view = container_under_pointer(); bool valid = true; bool changed_tiling = false; - double dx = mouse_origin.x - prev_pos.x; - double dy = mouse_origin.y - prev_pos.y; + double dx = pointer_state.origin.x - prev_pos.x; + double dy = pointer_state.origin.y - prev_pos.y; if (view != pointer_state.tiling.init_view) { changed_tiling = true; valid = false; @@ -32,7 +32,7 @@ bool mouse_resize_tiled(struct wlc_origin prev_pos) { } } - if ((dx < 0 || mouse_origin.x < pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_left) { + if ((dx < 0 || pointer_state.origin.x < pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_left) { changed_tiling = true; valid = false; } else if (dx > 0 && pointer_state.lock.temp_left) { @@ -40,7 +40,7 @@ bool mouse_resize_tiled(struct wlc_origin prev_pos) { pointer_state.tiling.lock_pos.x = 0; } - if ((dx > 0 || mouse_origin.x > pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_right) { + if ((dx > 0 || pointer_state.origin.x > pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_right) { changed_tiling = true; valid = false; } else if (dx < 0 && pointer_state.lock.temp_right) { @@ -48,7 +48,7 @@ bool mouse_resize_tiled(struct wlc_origin prev_pos) { pointer_state.tiling.lock_pos.x = 0; } - if ((dy < 0 || mouse_origin.y < pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_up) { + if ((dy < 0 || pointer_state.origin.y < pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_up) { changed_tiling = true; valid = false; } else if (dy > 0 && pointer_state.lock.temp_up) { @@ -56,7 +56,7 @@ bool mouse_resize_tiled(struct wlc_origin prev_pos) { pointer_state.tiling.lock_pos.y = 0; } - if ((dy > 0 || mouse_origin.y > pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_down) { + if ((dy > 0 || pointer_state.origin.y > pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_down) { changed_tiling = true; valid = false; } else if (dy < 0 && pointer_state.lock.temp_down) { @@ -190,8 +190,8 @@ bool resize_floating(struct wlc_origin prev_pos) { bool changed = false; swayc_t *view = container_under_pointer(); uint32_t edge = 0; - int dx = mouse_origin.x - prev_pos.x; - int dy = mouse_origin.y - prev_pos.y; + int dx = pointer_state.origin.x - prev_pos.x; + int dy = pointer_state.origin.y - prev_pos.y; // Move and resize the view based on the dx/dy and mouse position int midway_x = view->x + view->width/2; @@ -203,14 +203,14 @@ bool resize_floating(struct wlc_origin prev_pos) { view->width += dx; edge += WLC_RESIZE_EDGE_RIGHT; } - } else if (mouse_origin.x < midway_x && !pointer_state.lock.left) { + } else if (pointer_state.origin.x < midway_x && !pointer_state.lock.left) { changed = true; view->x += dx; view->width -= dx; edge += WLC_RESIZE_EDGE_LEFT; } } else if (dx > 0) { - if (mouse_origin.x > midway_x && !pointer_state.lock.right) { + if (pointer_state.origin.x > midway_x && !pointer_state.lock.right) { changed = true; view->width += dx; edge += WLC_RESIZE_EDGE_RIGHT; @@ -231,14 +231,14 @@ bool resize_floating(struct wlc_origin prev_pos) { view->height += dy; edge += WLC_RESIZE_EDGE_BOTTOM; } - } else if (mouse_origin.y < midway_y && !pointer_state.lock.top) { + } else if (pointer_state.origin.y < midway_y && !pointer_state.lock.top) { changed = true; view->y += dy; view->height -= dy; edge += WLC_RESIZE_EDGE_TOP; } } else if (dy > 0) { - if (mouse_origin.y > midway_y && !pointer_state.lock.bottom) { + if (pointer_state.origin.y > midway_y && !pointer_state.lock.bottom) { changed = true; view->height += dy; edge += WLC_RESIZE_EDGE_BOTTOM; From 42d5d9a17779710e83f4ebb2d7e8c893ad91dfe6 Mon Sep 17 00:00:00 2001 From: taiyu Date: Sat, 22 Aug 2015 21:03:45 -0700 Subject: [PATCH 2/8] mouse tile resize mode done --- include/input_state.h | 46 +++----- include/resize.h | 2 +- sway/handlers.c | 102 ++++++----------- sway/input_state.c | 230 +++++++++++++++++++------------------ sway/resize.c | 261 ------------------------------------------ 5 files changed, 165 insertions(+), 476 deletions(-) diff --git a/include/input_state.h b/include/input_state.h index 3a246e0c..747a3563 100644 --- a/include/input_state.h +++ b/include/input_state.h @@ -37,52 +37,34 @@ enum pointer_mode { M_RESIZING = 1 << 3, }; +struct pointer_button_state { + bool held; + // state at the point it was pressed + int x, y; + swayc_t *view; +}; + extern struct pointer_state { // mouse clicks - bool l_held : 1; - bool r_held : 1; - - // scroll wheel - bool s_held : 1; - bool s_up : 1; - bool s_down :1; + struct pointer_button_state left; + struct pointer_button_state right; + struct pointer_button_state scroll; // pointer position struct mouse_origin{ int x, y; } origin; + + // change in pointer position struct { int x, y; } delta; - // view pointer is over + // view pointer is currently over swayc_t *view; // Pointer mode int mode; - - // OLD - struct pointer_floating { - bool drag; - bool resize; - } floating; - struct pointer_tiling { - bool resize; - swayc_t *init_view; - struct wlc_origin lock_pos; - } tiling; - struct pointer_lock { - // Lock movement for certain edges - bool left; - bool right; - bool top; - bool bottom; - // Lock movement in certain directions - bool temp_left; - bool temp_right; - bool temp_up; - bool temp_down; - } lock; } pointer_state; // on button release unset mode depending on the button. @@ -95,8 +77,6 @@ void pointer_mode_update(void); // Reset mode on any keypress; void pointer_mode_reset(void); -void start_floating(swayc_t *view); -void reset_floating(swayc_t *view); void input_init(void); #endif diff --git a/include/resize.h b/include/resize.h index 4ace1815..04209983 100644 --- a/include/resize.h +++ b/include/resize.h @@ -1,8 +1,8 @@ #ifndef _SWAY_RESIZE_H #define _SWAY_RESIZE_H +#include bool mouse_resize_tiled(struct wlc_origin prev_pos); -bool resize_floating(struct wlc_origin prev_pos); bool resize_tiled(int amount, bool use_width); #endif diff --git a/sway/handlers.c b/sway/handlers.c index 7d1e4cde..896caa10 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -359,36 +359,54 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { enum { DONT_SEND_CLICK = true, SEND_CLICK = false }; + // Update view pointer is on + pointer_state.view = container_under_pointer(); + + // Update pointer origin + pointer_state.origin.x = origin->x; + pointer_state.origin.y = origin->y; + // Update pointer_state switch (button) { case M_LEFT_CLICK: - pointer_state.l_held = state == WLC_BUTTON_STATE_PRESSED; + if (state == WLC_BUTTON_STATE_PRESSED) { + pointer_state.left.held = true; + pointer_state.left.x = origin->x; + pointer_state.left.y = origin->y; + pointer_state.left.view = pointer_state.view; + } else { + pointer_state.left.held = false; + } break; case M_RIGHT_CLICK: - pointer_state.r_held = state == WLC_BUTTON_STATE_PRESSED; + if (state == WLC_BUTTON_STATE_PRESSED) { + pointer_state.right.held = true; + pointer_state.right.x = origin->x; + pointer_state.right.y = origin->y; + pointer_state.right.view = pointer_state.view; + } else { + pointer_state.right.held = false; + } break; case M_SCROLL_CLICK: - pointer_state.s_held = state == WLC_BUTTON_STATE_PRESSED; + if (state == WLC_BUTTON_STATE_PRESSED) { + pointer_state.scroll.held = true; + pointer_state.scroll.x = origin->x; + pointer_state.scroll.y = origin->y; + pointer_state.scroll.view = pointer_state.view; + } else { + pointer_state.scroll.held = false; + } break; + //TODO scrolling behavior case M_SCROLL_UP: - pointer_state.s_up = state == WLC_BUTTON_STATE_PRESSED; - break; - case M_SCROLL_DOWN: - pointer_state.s_down = state == WLC_BUTTON_STATE_PRESSED; break; } - // Update pointer origin - pointer_state.origin.x = origin->x; - pointer_state.origin.y = origin->y; - - // Update view pointer is on - pointer_state.view = container_under_pointer(); - // set pointer mode pointer_mode_set(button, (modifiers->mods & config->floating_mod) == config->floating_mod); @@ -431,62 +449,6 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w // Finally send click return SEND_CLICK; - - /* OLD */ - if (state == WLC_BUTTON_STATE_PRESSED) { - sway_log(L_DEBUG, "Mouse button %u pressed", button); - if (button == M_LEFT_CLICK) { - pointer_state.l_held = true; - } - if (button == M_RIGHT_CLICK) { - pointer_state.r_held = true; - } - swayc_t *pointer = container_under_pointer(); - if (pointer) { - set_focused_container(pointer); - int midway_x = pointer->x + pointer->width/2; - int midway_y = pointer->y + pointer->height/2; - pointer_state.lock.bottom = origin->y < midway_y; - pointer_state.lock.top = !pointer_state.lock.bottom; - pointer_state.lock.right = origin->x < midway_x; - pointer_state.lock.left = !pointer_state.lock.right; - } - - if (pointer->is_floating) { - if (modifiers->mods & config->floating_mod) { - pointer_state.floating.drag = pointer_state.l_held; - pointer_state.floating.resize = pointer_state.r_held; - start_floating(pointer); - } - // Dont want pointer sent to window while dragging or resizing - return (pointer_state.floating.drag || pointer_state.floating.resize); - } else { - if (modifiers->mods & config->floating_mod) { - pointer_state.floating.drag = pointer_state.l_held; - pointer_state.tiling.resize = pointer_state.r_held; - pointer_state.tiling.init_view = pointer; - // Dont want pointer sent when resizing - return (pointer_state.tiling.resize); - } - } - return (pointer && pointer != focused); - } else { - sway_log(L_DEBUG, "Mouse button %u released", button); - if (button == M_LEFT_CLICK) { - pointer_state.l_held = false; - pointer_state.floating.drag = false; - pointer_state.tiling.init_view = NULL; - } - if (button == M_RIGHT_CLICK) { - pointer_state.r_held = false; - pointer_state.floating.resize = false; - pointer_state.tiling.resize = false; - pointer_state.tiling.init_view = NULL; - pointer_state.lock = (struct pointer_lock){false ,false ,false ,false, false, false, false, false}; - } - } - /* OLD */ - return false; } static void handle_wlc_ready(void) { diff --git a/sway/input_state.c b/sway/input_state.c index 3db78167..a63fc01c 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -48,75 +48,81 @@ void release_key(keycode key) { } } +// Pointer state and mode + struct pointer_state pointer_state; -// Pointer mode values static struct mode_state { - // Initial view state + // initial view state + double x, y, w, h; + swayc_t *ptr; + // containers resized with tiling resize struct { - double x, y, w, h; + double x, w; swayc_t *ptr; - } view; - // Initial pointer state + } lr; struct { - int x, y; - } coor; + double y, h; + swayc_t *ptr; + } tb; } initial; static struct { - enum { LEFT=1, RIGHT=0 } lr; - enum { TOP=1, BOTTOM=0 } tb; + bool left; + bool top; } lock; // Floating set/unset -static void pointer_mode_set_floating(void) { - initial.view.x = initial.view.ptr->x; - initial.view.y = initial.view.ptr->y; - initial.view.w = initial.view.ptr->width; - initial.view.h = initial.view.ptr->height; - // setup initial cooridinates - initial.coor.x = pointer_state.origin.x; - initial.coor.y = pointer_state.origin.y; +static void set_initial_view(swayc_t *view) { + initial.ptr = view; + initial.x = view->x; + initial.y = view->y; + initial.w = view->width; + initial.h = view->height; } -static void pointer_mode_reset_floating(void) { - initial.view.ptr->x = initial.view.x; - initial.view.ptr->y = initial.view.y; - initial.view.ptr->width = initial.view.w; - initial.view.ptr->height = initial.view.h; - arrange_windows(initial.view.ptr, -1, -1); +static void reset_initial_view(void) { + initial.ptr->x = initial.x; + initial.ptr->y = initial.y; + initial.ptr->width = initial.w; + initial.ptr->height = initial.h; + arrange_windows(initial.ptr, -1, -1); pointer_state.mode = 0; } // Mode set left/right click static void pointer_mode_set_left(void) { - swayc_t *view = pointer_state.view; - initial.view.ptr = view; - if (view->is_floating) { + set_initial_view(pointer_state.left.view); + if (initial.ptr->is_floating) { pointer_state.mode = M_DRAGGING | M_FLOATING; - pointer_mode_set_floating(); } else { pointer_state.mode = M_DRAGGING | M_TILING; } } static void pointer_mode_set_right(void) { - swayc_t *view = pointer_state.view; - initial.view.ptr = view; + set_initial_view(pointer_state.right.view); // Setup locking information - int midway_x = view->x + view->width/2; - int midway_y = view->y + view->height/2; + int midway_x = initial.ptr->x + initial.ptr->width/2; + int midway_y = initial.ptr->y + initial.ptr->height/2; - lock.lr = pointer_state.origin.x > midway_x; - lock.tb = pointer_state.origin.y > midway_y; + lock.left = pointer_state.origin.x > midway_x; + lock.top = pointer_state.origin.y > midway_y; - if (view->is_floating) { + if (initial.ptr->is_floating) { pointer_state.mode = M_RESIZING | M_FLOATING; - pointer_mode_set_floating(); } else { pointer_state.mode = M_RESIZING | M_TILING; + if ((initial.lr.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) { + initial.lr.x = initial.lr.ptr->x; + initial.lr.w = initial.lr.ptr->width; + } + if ((initial.tb.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) { + initial.tb.y = initial.tb.ptr->y; + initial.tb.h = initial.tb.ptr->height; + } } } @@ -127,14 +133,14 @@ void pointer_mode_set(uint32_t button, bool condition) { switch (pointer_state.mode & (M_DRAGGING | M_RESIZING)) { case M_DRAGGING: // end drag mode when left click is unpressed - if (!pointer_state.l_held) { + if (!pointer_state.left.held) { pointer_state.mode = 0; } break; case M_RESIZING: // end resize mode when right click is unpressed - if (!pointer_state.r_held) { + if (!pointer_state.right.held) { pointer_state.mode = 0; } break; @@ -145,12 +151,13 @@ void pointer_mode_set(uint32_t button, bool condition) { if (!condition || !pointer_state.view) { break; } + // Set mode depending on current button press switch (button) { // Start dragging mode case M_LEFT_CLICK: // if button release dont do anything - if (pointer_state.l_held) { + if (pointer_state.left.held) { pointer_mode_set_left(); } break; @@ -158,106 +165,131 @@ void pointer_mode_set(uint32_t button, bool condition) { // Start resize mode case M_RIGHT_CLICK: // if button release dont do anyhting - if (pointer_state.r_held) { + if (pointer_state.right.held) { pointer_mode_set_right(); } break; - - case M_SCROLL_UP: - case M_SCROLL_DOWN: - //TODO add scrolling behavior here - ; } } } void pointer_mode_update(void) { - swayc_t *view = initial.view.ptr; - if (view->type != C_VIEW) { + if (initial.ptr->type != C_VIEW) { pointer_state.mode = 0; return; } - int dx = pointer_state.origin.x - initial.coor.x; - int dy = pointer_state.origin.y - initial.coor.y; + int dx = pointer_state.origin.x; + int dy = pointer_state.origin.y; bool changed = false; switch (pointer_state.mode) { case M_FLOATING | M_DRAGGING: // Update position - if (initial.view.x + dx != view->x) { - view->x = initial.view.x + dx; + dx -= pointer_state.left.x; + dy -= pointer_state.left.y; + if (initial.x + dx != initial.ptr->x) { + initial.ptr->x = initial.x + dx; changed = true; } - if (initial.view.y + dy != view->y) { - view->y = initial.view.y + dy; + if (initial.y + dy != initial.ptr->y) { + initial.ptr->y = initial.y + dy; changed = true; } + update_geometry(initial.ptr); break; case M_FLOATING | M_RESIZING: - if (lock.lr) { - if (initial.view.w + dx > min_sane_w) { - if (initial.view.w + dx != view->width) { - view->width = initial.view.w + dx; - changed = true; - } + dx -= pointer_state.right.x; + dy -= pointer_state.right.y; + initial.ptr = pointer_state.right.view; + if (lock.left) { + if (initial.w + dx > min_sane_w) { + initial.ptr->width = initial.w + dx; } } else { //lock.right - if (initial.view.w - dx > min_sane_w) { - if (initial.view.w - dx != view->width) { - view->width = initial.view.w - dx; - view->x = initial.view.x + dx; - changed = true; - } + if (initial.w - dx > min_sane_w) { + initial.ptr->width = initial.w - dx; + initial.ptr->x = initial.x + dx; } } - if (lock.tb) { - if (initial.view.h + dy > min_sane_h) { - if (initial.view.y - dy != view->height) { - view->height = initial.view.h + dy; - changed = true; - } + if (lock.top) { + if (initial.h + dy > min_sane_h) { + initial.ptr->height = initial.h + dy; } } else { //lock.bottom - if (initial.view.h - dy > min_sane_h) { - if (initial.view.h - dy != view->height) { - view->height = initial.view.h - dy; - view->y = initial.view.y + dy; - changed = true; - } + if (initial.h - dy > min_sane_h) { + initial.ptr->height = initial.h - dy; + initial.ptr->y = initial.y + dy; } } + update_geometry(initial.ptr); break; case M_TILING | M_DRAGGING: // swap current view under pointer with dragged view - if (pointer_state.view && pointer_state.view != initial.view.ptr) { + if (pointer_state.view && pointer_state.view != initial.ptr) { // Swap them around - swap_container(pointer_state.view, initial.view.ptr); + swap_container(pointer_state.view, initial.ptr); update_geometry(pointer_state.view); - update_geometry(initial.view.ptr); + update_geometry(initial.ptr); // Set focus back to initial view - set_focused_container(initial.view.ptr); + set_focused_container(initial.ptr); } break; case M_TILING | M_RESIZING: - - - + dx -= pointer_state.right.x; + dy -= pointer_state.right.y; + // resize if we can + if (initial.lr.ptr) { + if (lock.left) { + // Check whether its fine to resize + if (initial.w + dx > min_sane_w && initial.lr.w - dx > min_sane_w) { + initial.ptr->width = initial.w + dx; + initial.lr.ptr->width = initial.lr.w - dx; + initial.lr.ptr->x = initial.lr.x + dx; + } + } else { //lock.right + if (initial.w - dx > min_sane_w && initial.lr.w + dx > min_sane_w) { + initial.ptr->width = initial.w - dx; + initial.ptr->x = initial.x + dx; + initial.lr.ptr->width = initial.lr.w + dx; + } + changed = true; + } + arrange_windows(initial.lr.ptr->parent, -1, -1); + } + if (initial.tb.ptr) { + if (lock.top) { + if (initial.h + dy > min_sane_h && initial.tb.h - dy > min_sane_h) { + initial.ptr->height = initial.h + dy; + initial.tb.ptr->height = initial.tb.h - dy; + initial.tb.ptr->y = initial.tb.y + dy; + } + } else { //lock.bottom + if (initial.h - dy > min_sane_h && initial.tb.h + dy > min_sane_h) { + initial.ptr->height = initial.h - dy; + initial.ptr->y = initial.y + dy; + initial.tb.ptr->height = initial.tb.h + dy; + } + changed = true; + } + arrange_windows(initial.tb.ptr->parent, -1, -1); + } + if (changed) { + arrange_windows(initial.ptr->parent, -1, -1); + } + changed = false; default: return; } - if (changed) { - update_geometry(view); - } } void pointer_mode_reset(void) { switch (pointer_state.mode) { case M_FLOATING | M_DRAGGING: case M_FLOATING | M_RESIZING: - pointer_mode_reset_floating(); + reset_initial_view(); break; case M_TILING | M_DRAGGING: @@ -267,27 +299,3 @@ void pointer_mode_reset(void) { } } - -static struct wlc_geometry saved_floating; - -void start_floating(swayc_t *view) { - if (view->is_floating) { - saved_floating.origin.x = view->x; - saved_floating.origin.y = view->y; - saved_floating.size.w = view->width; - saved_floating.size.h = view->height; - } -} - -void reset_floating(swayc_t *view) { - if (view->is_floating) { - view->x = saved_floating.origin.x; - view->y = saved_floating.origin.y; - view->width = saved_floating.size.w; - view->height = saved_floating.size.h; - arrange_windows(view->parent, -1, -1); - } - pointer_state.floating = (struct pointer_floating){0, 0}; - pointer_state.lock = (struct pointer_lock){0, 0, 0, 0, 0, 0, 0, 0}; -} - diff --git a/sway/resize.c b/sway/resize.c index 31cd66e8..22d520af 100644 --- a/sway/resize.c +++ b/sway/resize.c @@ -6,267 +6,6 @@ #include "input_state.h" #include "handlers.h" -bool mouse_resize_tiled(struct wlc_origin prev_pos) { - swayc_t *view = container_under_pointer(); - bool valid = true; - bool changed_tiling = false; - double dx = pointer_state.origin.x - prev_pos.x; - double dy = pointer_state.origin.y - prev_pos.y; - if (view != pointer_state.tiling.init_view) { - changed_tiling = true; - valid = false; - if (view->type != C_WORKSPACE) { - if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_LEFT) == view) { - pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + 20; - pointer_state.lock.temp_left = true; - } else if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_RIGHT) == view) { - pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + pointer_state.tiling.init_view->width - 20; - pointer_state.lock.temp_right = true; - } else if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_UP) == view) { - pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20; - pointer_state.lock.temp_up = true; - } else if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_DOWN) == view) { - pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20; - pointer_state.lock.temp_down = true; - } - } - } - - if ((dx < 0 || pointer_state.origin.x < pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_left) { - changed_tiling = true; - valid = false; - } else if (dx > 0 && pointer_state.lock.temp_left) { - pointer_state.lock.temp_left = false; - pointer_state.tiling.lock_pos.x = 0; - } - - if ((dx > 0 || pointer_state.origin.x > pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_right) { - changed_tiling = true; - valid = false; - } else if (dx < 0 && pointer_state.lock.temp_right) { - pointer_state.lock.temp_right = false; - pointer_state.tiling.lock_pos.x = 0; - } - - if ((dy < 0 || pointer_state.origin.y < pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_up) { - changed_tiling = true; - valid = false; - } else if (dy > 0 && pointer_state.lock.temp_up) { - pointer_state.lock.temp_up = false; - pointer_state.tiling.lock_pos.y = 0; - } - - if ((dy > 0 || pointer_state.origin.y > pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_down) { - changed_tiling = true; - valid = false; - } else if (dy < 0 && pointer_state.lock.temp_down) { - pointer_state.lock.temp_down = false; - pointer_state.tiling.lock_pos.y = 0; - } - - if (!view->is_floating && valid) { - // Handle layout resizes -- Find the biggest parent container then apply resizes to that - // and its bordering siblings - swayc_t *parent = view; - if (!pointer_state.lock.bottom) { - while (parent->type != C_WORKSPACE) { - // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better - // way of doing this. - if (fabs(parent->parent->y + parent->parent->height - (view->y + view->height)) <= 1) { - parent = parent->parent; - } else { - break; - } - } - if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { - swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN); - if (sibling) { - if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) { - recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM); - recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP); - changed_tiling = true; - } else { - if (parent->height < min_sane_h) { - //pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20; - pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20; - pointer_state.lock.temp_up = true; - } else if (sibling->height < min_sane_h) { - pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20; - pointer_state.lock.temp_down = true; - } - } - } - } - } else if (!pointer_state.lock.top) { - while (parent->type != C_WORKSPACE) { - if (fabs(parent->parent->y - view->y) <= 1) { - parent = parent->parent; - } else { - break; - } - } - if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { - swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP); - if (sibling) { - if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) { - recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP); - recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM); - changed_tiling = true; - } else { - if (parent->height < min_sane_h) { - //pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20; - pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20; - pointer_state.lock.temp_down = true; - } else if (sibling->height < min_sane_h) { - pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20; - pointer_state.lock.temp_up = true; - } - } - } - } - } - - parent = view; - if (!pointer_state.lock.right) { - while (parent->type != C_WORKSPACE) { - if (fabs(parent->parent->x + parent->parent->width - (view->x + view->width)) <= 1) { - parent = parent->parent; - } else { - sway_log(L_DEBUG, "view: %f vs parent: %f", view->x + view->width, parent->parent->x + parent->parent->width); - break; - } - } - if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { - swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT); - if (sibling) { - if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) { - recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT); - recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT); - changed_tiling = true; - } else { - if (parent->width < min_sane_w) { - pointer_state.lock.temp_left = true; - pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + pointer_state.tiling.init_view->width - 20; - } else if (sibling->width < min_sane_w) { - pointer_state.lock.temp_right = true; - pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + pointer_state.tiling.init_view->width - 20; - } - } - } - } - } else if (!pointer_state.lock.left) { - while (parent->type != C_WORKSPACE) { - if (fabs(parent->parent->x - view->x) <= 1 && parent->parent) { - parent = parent->parent; - } else { - break; - } - } - if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { - swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT); - if (sibling) { - if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) { - recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT); - recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT); - changed_tiling = true; - } else { - if (parent->width < min_sane_w) { - pointer_state.lock.temp_right = true; - pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + 20; - } else if (sibling->width < min_sane_w) { - pointer_state.lock.temp_left = true; - pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + 20; - } - } - } - } - } - arrange_windows(swayc_active_workspace(), -1, -1); - } - return changed_tiling; -} - -bool resize_floating(struct wlc_origin prev_pos) { - bool changed = false; - swayc_t *view = container_under_pointer(); - uint32_t edge = 0; - int dx = pointer_state.origin.x - prev_pos.x; - int dy = pointer_state.origin.y - prev_pos.y; - - // Move and resize the view based on the dx/dy and mouse position - int midway_x = view->x + view->width/2; - int midway_y = view->y + view->height/2; - if (dx < 0) { - if (!pointer_state.lock.right) { - if (view->width > min_sane_w) { - changed = true; - view->width += dx; - edge += WLC_RESIZE_EDGE_RIGHT; - } - } else if (pointer_state.origin.x < midway_x && !pointer_state.lock.left) { - changed = true; - view->x += dx; - view->width -= dx; - edge += WLC_RESIZE_EDGE_LEFT; - } - } else if (dx > 0) { - if (pointer_state.origin.x > midway_x && !pointer_state.lock.right) { - changed = true; - view->width += dx; - edge += WLC_RESIZE_EDGE_RIGHT; - } else if (!pointer_state.lock.left) { - if (view->width > min_sane_w) { - changed = true; - view->x += dx; - view->width -= dx; - edge += WLC_RESIZE_EDGE_LEFT; - } - } - } - - if (dy < 0) { - if (!pointer_state.lock.bottom) { - if (view->height > min_sane_h) { - changed = true; - view->height += dy; - edge += WLC_RESIZE_EDGE_BOTTOM; - } - } else if (pointer_state.origin.y < midway_y && !pointer_state.lock.top) { - changed = true; - view->y += dy; - view->height -= dy; - edge += WLC_RESIZE_EDGE_TOP; - } - } else if (dy > 0) { - if (pointer_state.origin.y > midway_y && !pointer_state.lock.bottom) { - changed = true; - view->height += dy; - edge += WLC_RESIZE_EDGE_BOTTOM; - } else if (!pointer_state.lock.top) { - if (view->height > min_sane_h) { - changed = true; - view->y += dy; - view->height -= dy; - edge += WLC_RESIZE_EDGE_TOP; - } - } - } - if (changed) { - struct wlc_geometry geometry = { - .origin = { - .x = view->x, - .y = view->y - }, - .size = { - .w = view->width, - .h = view->height - } - }; - wlc_view_set_geometry(view->handle, edge, &geometry); - } - return changed; -} - bool resize_tiled(int amount, bool use_width) { swayc_t *parent = get_focused_view(swayc_active_workspace()); swayc_t *focused = parent; From f1e38be09f00688b90751a45e9365cfd906f8d39 Mon Sep 17 00:00:00 2001 From: taiyu Date: Sat, 22 Aug 2015 21:16:46 -0700 Subject: [PATCH 3/8] no mode for fullscreen --- sway/handlers.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sway/handlers.c b/sway/handlers.c index 896caa10..d26ce5f3 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -407,6 +407,14 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w break; } + // get focused window and check if to change focus on mouse click + swayc_t *focused = get_focused_container(&root_container); + + // dont change focus or mode if fullscreen + if (swayc_is_fullscreen(focused)) { + return SEND_CLICK; + } + // set pointer mode pointer_mode_set(button, (modifiers->mods & config->floating_mod) == config->floating_mod); @@ -421,9 +429,6 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w return SEND_CLICK; } - // get focused window and check if to change focus on mouse click - swayc_t *focused = get_focused_container(&root_container); - // Check whether to change focus swayc_t *pointer = pointer_state.view; if (pointer && focused != pointer) { @@ -442,11 +447,6 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w } } - // dont change focus if fullscreen - if (swayc_is_fullscreen(focused)) { - return SEND_CLICK; - } - // Finally send click return SEND_CLICK; } From a4ded14991cf84ba7069e4e6748a218f8a5f1be6 Mon Sep 17 00:00:00 2001 From: taiyu Date: Sat, 22 Aug 2015 21:23:22 -0700 Subject: [PATCH 4/8] small change --- sway/input_state.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sway/input_state.c b/sway/input_state.c index a63fc01c..03904322 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -114,14 +114,21 @@ static void pointer_mode_set_right(void) { if (initial.ptr->is_floating) { pointer_state.mode = M_RESIZING | M_FLOATING; } else { + bool reset = true; pointer_state.mode = M_RESIZING | M_TILING; if ((initial.lr.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) { initial.lr.x = initial.lr.ptr->x; initial.lr.w = initial.lr.ptr->width; + reset = false; } if ((initial.tb.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) { initial.tb.y = initial.tb.ptr->y; initial.tb.h = initial.tb.ptr->height; + reset = false; + } + // If nothing changes just undo the mode + if (reset) { + pointer_state.mode = 0; } } } From f24b78898a7a7fc98f896f6d1d374c602ee30952 Mon Sep 17 00:00:00 2001 From: taiyu Date: Sat, 22 Aug 2015 21:54:39 -0700 Subject: [PATCH 5/8] dont swap view with workspace... --- include/resize.h | 1 - sway/input_state.c | 7 ++----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/include/resize.h b/include/resize.h index 04209983..8d205d3b 100644 --- a/include/resize.h +++ b/include/resize.h @@ -2,7 +2,6 @@ #define _SWAY_RESIZE_H #include -bool mouse_resize_tiled(struct wlc_origin prev_pos); bool resize_tiled(int amount, bool use_width); #endif diff --git a/sway/input_state.c b/sway/input_state.c index 03904322..cb8632de 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -234,7 +234,8 @@ void pointer_mode_update(void) { case M_TILING | M_DRAGGING: // swap current view under pointer with dragged view - if (pointer_state.view && pointer_state.view != initial.ptr) { + if (pointer_state.view && pointer_state.view->type == C_VIEW + && pointer_state.view != initial.ptr) { // Swap them around swap_container(pointer_state.view, initial.ptr); update_geometry(pointer_state.view); @@ -254,12 +255,10 @@ void pointer_mode_update(void) { if (initial.w + dx > min_sane_w && initial.lr.w - dx > min_sane_w) { initial.ptr->width = initial.w + dx; initial.lr.ptr->width = initial.lr.w - dx; - initial.lr.ptr->x = initial.lr.x + dx; } } else { //lock.right if (initial.w - dx > min_sane_w && initial.lr.w + dx > min_sane_w) { initial.ptr->width = initial.w - dx; - initial.ptr->x = initial.x + dx; initial.lr.ptr->width = initial.lr.w + dx; } changed = true; @@ -271,12 +270,10 @@ void pointer_mode_update(void) { if (initial.h + dy > min_sane_h && initial.tb.h - dy > min_sane_h) { initial.ptr->height = initial.h + dy; initial.tb.ptr->height = initial.tb.h - dy; - initial.tb.ptr->y = initial.tb.y + dy; } } else { //lock.bottom if (initial.h - dy > min_sane_h && initial.tb.h + dy > min_sane_h) { initial.ptr->height = initial.h - dy; - initial.ptr->y = initial.y + dy; initial.tb.ptr->height = initial.tb.h + dy; } changed = true; From f53ce887e854dba1db327ae8e18b12dd385e2743 Mon Sep 17 00:00:00 2001 From: taiyu Date: Sat, 22 Aug 2015 22:14:59 -0700 Subject: [PATCH 6/8] fixed container resize oddity --- sway/input_state.c | 57 +++++++++++++++++++++++----------------------- sway/layout.c | 39 +++++++------------------------ 2 files changed, 36 insertions(+), 60 deletions(-) diff --git a/sway/input_state.c b/sway/input_state.c index cb8632de..ece75bf4 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -60,10 +60,12 @@ static struct mode_state { struct { double x, w; swayc_t *ptr; + swayc_t *sib; } lr; struct { double y, h; swayc_t *ptr; + swayc_t *sib; } tb; } initial; @@ -72,7 +74,7 @@ static struct { bool top; } lock; -// Floating set/unset +// initial set/unset static void set_initial_view(swayc_t *view) { initial.ptr = view; @@ -82,6 +84,26 @@ static void set_initial_view(swayc_t *view) { initial.h = view->height; } +static void set_initial_sibling(void) { + bool reset = true; + if ((initial.lr.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) { + initial.lr.sib = get_swayc_in_direction(initial.lr.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT); + initial.lr.x = initial.lr.ptr->x; + initial.lr.w = initial.lr.ptr->width; + reset = false; + } + if ((initial.tb.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) { + initial.tb.sib = get_swayc_in_direction(initial.tb.ptr, lock.top ? MOVE_UP : MOVE_DOWN); + initial.tb.y = initial.tb.ptr->y; + initial.tb.h = initial.tb.ptr->height; + reset = false; + } + // If nothing changes just undo the mode + if (reset) { + pointer_state.mode = 0; + } +} + static void reset_initial_view(void) { initial.ptr->x = initial.x; initial.ptr->y = initial.y; @@ -114,22 +136,8 @@ static void pointer_mode_set_right(void) { if (initial.ptr->is_floating) { pointer_state.mode = M_RESIZING | M_FLOATING; } else { - bool reset = true; pointer_state.mode = M_RESIZING | M_TILING; - if ((initial.lr.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) { - initial.lr.x = initial.lr.ptr->x; - initial.lr.w = initial.lr.ptr->width; - reset = false; - } - if ((initial.tb.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) { - initial.tb.y = initial.tb.ptr->y; - initial.tb.h = initial.tb.ptr->height; - reset = false; - } - // If nothing changes just undo the mode - if (reset) { - pointer_state.mode = 0; - } + set_initial_sibling(); } } @@ -187,7 +195,6 @@ void pointer_mode_update(void) { } int dx = pointer_state.origin.x; int dy = pointer_state.origin.y; - bool changed = false; switch (pointer_state.mode) { case M_FLOATING | M_DRAGGING: @@ -196,11 +203,9 @@ void pointer_mode_update(void) { dy -= pointer_state.left.y; if (initial.x + dx != initial.ptr->x) { initial.ptr->x = initial.x + dx; - changed = true; } if (initial.y + dy != initial.ptr->y) { initial.ptr->y = initial.y + dy; - changed = true; } update_geometry(initial.ptr); break; @@ -253,37 +258,31 @@ void pointer_mode_update(void) { if (lock.left) { // Check whether its fine to resize if (initial.w + dx > min_sane_w && initial.lr.w - dx > min_sane_w) { - initial.ptr->width = initial.w + dx; + initial.lr.sib->width = initial.w + dx; initial.lr.ptr->width = initial.lr.w - dx; } } else { //lock.right if (initial.w - dx > min_sane_w && initial.lr.w + dx > min_sane_w) { - initial.ptr->width = initial.w - dx; + initial.lr.sib->width = initial.w - dx; initial.lr.ptr->width = initial.lr.w + dx; } - changed = true; } arrange_windows(initial.lr.ptr->parent, -1, -1); } if (initial.tb.ptr) { if (lock.top) { if (initial.h + dy > min_sane_h && initial.tb.h - dy > min_sane_h) { - initial.ptr->height = initial.h + dy; + initial.tb.sib->height = initial.h + dy; initial.tb.ptr->height = initial.tb.h - dy; } } else { //lock.bottom if (initial.h - dy > min_sane_h && initial.tb.h + dy > min_sane_h) { - initial.ptr->height = initial.h - dy; + initial.tb.sib->height = initial.h - dy; initial.tb.ptr->height = initial.tb.h + dy; } - changed = true; } arrange_windows(initial.tb.ptr->parent, -1, -1); } - if (changed) { - arrange_windows(initial.ptr->parent, -1, -1); - } - changed = false; default: return; } diff --git a/sway/layout.c b/sway/layout.c index fd2e80fe..4d738433 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -209,12 +209,12 @@ void update_geometry(swayc_t *container) { } struct wlc_geometry geometry = { .origin = { - .x = container->x + container->gaps / 2, - .y = container->y + container->gaps / 2 + .x = container->x + (container->is_floating ? 0 : container->gaps / 2), + .y = container->y + (container->is_floating ? 0 : container->gaps / 2) }, .size = { - .w = container->width - container->gaps, - .h = container->height - container->gaps + .w = container->width - (container->is_floating ? 0 : container->gaps), + .h = container->height - (container->is_floating ? 0 : container->gaps) } }; if (swayc_is_fullscreen(container)) { @@ -347,35 +347,12 @@ void arrange_windows(swayc_t *container, double width, double height) { for (i = 0; i < container->floating->length; ++i) { swayc_t *view = container->floating->items[i]; if (view->type == C_VIEW) { - // Set the geometry - struct wlc_geometry geometry = { - .origin = { - .x = view->x, - .y = view->y - }, - .size = { - .w = view->width, - .h = view->height - } - }; + update_geometry(view); if (swayc_is_fullscreen(view)) { - swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); - geometry.origin.x = 0; - geometry.origin.y = 0; - geometry.size.w = parent->width; - geometry.size.h = parent->height; - wlc_view_set_geometry(view->handle, 0, &geometry); wlc_view_bring_to_front(view->handle); - } else { - wlc_view_set_geometry(view->handle, 0, &geometry); - // Bring the views to the front in order of the list, the list - // will be kept up to date so that more recently focused views - // have higher indexes - // This is conditional on there not being a fullscreen view in the workspace - if (!container->focused - || !swayc_is_fullscreen(container->focused)) { - wlc_view_bring_to_front(view->handle); - } + } else if (!container->focused + || !swayc_is_fullscreen(container->focused)) { + wlc_view_bring_to_front(view->handle); } } } From 299406a048e8db3342987a9cfb2ce8b61df6bd82 Mon Sep 17 00:00:00 2001 From: taiyu Date: Sat, 22 Aug 2015 22:32:41 -0700 Subject: [PATCH 7/8] slight fix --- sway/input_state.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/sway/input_state.c b/sway/input_state.c index ece75bf4..8450fe7a 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -60,12 +60,18 @@ static struct mode_state { struct { double x, w; swayc_t *ptr; - swayc_t *sib; + struct { + double x, w; + swayc_t *ptr; + } sib; } lr; struct { double y, h; swayc_t *ptr; - swayc_t *sib; + struct { + double y, h; + swayc_t *ptr; + } sib; } tb; } initial; @@ -87,15 +93,19 @@ static void set_initial_view(swayc_t *view) { static void set_initial_sibling(void) { bool reset = true; if ((initial.lr.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) { - initial.lr.sib = get_swayc_in_direction(initial.lr.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT); initial.lr.x = initial.lr.ptr->x; initial.lr.w = initial.lr.ptr->width; + initial.lr.sib.ptr = get_swayc_in_direction(initial.lr.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT); + initial.lr.sib.x = initial.lr.sib.ptr->x; + initial.lr.sib.w = initial.lr.sib.ptr->width; reset = false; } if ((initial.tb.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) { - initial.tb.sib = get_swayc_in_direction(initial.tb.ptr, lock.top ? MOVE_UP : MOVE_DOWN); initial.tb.y = initial.tb.ptr->y; initial.tb.h = initial.tb.ptr->height; + initial.tb.sib.ptr = get_swayc_in_direction(initial.tb.ptr, lock.top ? MOVE_UP : MOVE_DOWN); + initial.tb.sib.y = initial.tb.sib.ptr->y; + initial.tb.sib.h = initial.tb.sib.ptr->height; reset = false; } // If nothing changes just undo the mode @@ -258,13 +268,13 @@ void pointer_mode_update(void) { if (lock.left) { // Check whether its fine to resize if (initial.w + dx > min_sane_w && initial.lr.w - dx > min_sane_w) { - initial.lr.sib->width = initial.w + dx; initial.lr.ptr->width = initial.lr.w - dx; + initial.lr.sib.ptr->width = initial.lr.sib.w + dx; } } else { //lock.right if (initial.w - dx > min_sane_w && initial.lr.w + dx > min_sane_w) { - initial.lr.sib->width = initial.w - dx; initial.lr.ptr->width = initial.lr.w + dx; + initial.lr.sib.ptr->width = initial.lr.sib.w - dx; } } arrange_windows(initial.lr.ptr->parent, -1, -1); @@ -272,13 +282,13 @@ void pointer_mode_update(void) { if (initial.tb.ptr) { if (lock.top) { if (initial.h + dy > min_sane_h && initial.tb.h - dy > min_sane_h) { - initial.tb.sib->height = initial.h + dy; initial.tb.ptr->height = initial.tb.h - dy; + initial.tb.sib.ptr->height = initial.tb.sib.h + dy; } } else { //lock.bottom if (initial.h - dy > min_sane_h && initial.tb.h + dy > min_sane_h) { - initial.tb.sib->height = initial.h - dy; initial.tb.ptr->height = initial.tb.h + dy; + initial.tb.sib.ptr->height = initial.tb.sib.h - dy; } } arrange_windows(initial.tb.ptr->parent, -1, -1); From d72cc925416847adaf2636cea0773ef6d9a46461 Mon Sep 17 00:00:00 2001 From: taiyu Date: Sun, 23 Aug 2015 07:59:18 -0700 Subject: [PATCH 8/8] style --- include/input_state.h | 8 ++-- sway/handlers.c | 25 ++++++----- sway/input_state.c | 101 +++++++++++++++++++++++------------------- 3 files changed, 74 insertions(+), 60 deletions(-) diff --git a/include/input_state.h b/include/input_state.h index 747a3563..4ab93cd6 100644 --- a/include/input_state.h +++ b/include/input_state.h @@ -30,11 +30,11 @@ enum pointer_values { enum pointer_mode { // Target - M_FLOATING = 1 << 0, - M_TILING = 1 << 1, + M_FLOATING = 1, + M_TILING = 2, // Action - M_DRAGGING = 1 << 2, - M_RESIZING = 1 << 3, + M_DRAGGING = 4, + M_RESIZING = 8, }; struct pointer_button_state { diff --git a/sway/handlers.c b/sway/handlers.c index d26ce5f3..0bb4f613 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -17,6 +17,12 @@ #include "input_state.h" #include "resize.h" +// Event should be sent to client +#define EVENT_PASSTHROUGH false + +// Event handled by sway and should not be sent to client +#define EVENT_HANDLED true + static bool pointer_test(swayc_t *view, void *_origin) { const struct mouse_origin *origin = _origin; // Determine the output that the view is under @@ -276,7 +282,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier uint32_t key, uint32_t sym, enum wlc_key_state state) { if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { - return false; + return EVENT_PASSTHROUGH; } // reset pointer mode on keypress @@ -289,7 +295,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier if (sym < 70000 /* bullshit made up number */) { if (!isalnum(sym) && sym != ' ' && sym != XKB_KEY_Escape && sym != XKB_KEY_Tab) { // God fucking dammit - return false; + return EVENT_PASSTHROUGH; } } @@ -320,14 +326,14 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier if (match) { if (state == WLC_KEY_STATE_PRESSED) { handle_command(config, binding->command); - return true; + return EVENT_HANDLED; } else if (state == WLC_KEY_STATE_RELEASED) { // TODO: --released } } } } - return false; + return EVENT_PASSTHROUGH; } static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) { @@ -351,13 +357,12 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct set_focused_container(pointer_state.view); } } - return false; + return EVENT_PASSTHROUGH; } static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { - enum { DONT_SEND_CLICK = true, SEND_CLICK = false }; // Update view pointer is on pointer_state.view = container_under_pointer(); @@ -412,7 +417,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w // dont change focus or mode if fullscreen if (swayc_is_fullscreen(focused)) { - return SEND_CLICK; + return EVENT_PASSTHROUGH; } // set pointer mode @@ -421,12 +426,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w // Return if mode has been set if (pointer_state.mode) { - return DONT_SEND_CLICK; + return EVENT_HANDLED; } // Always send mouse release if (state == WLC_BUTTON_STATE_RELEASED) { - return SEND_CLICK; + return EVENT_PASSTHROUGH; } // Check whether to change focus @@ -448,7 +453,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w } // Finally send click - return SEND_CLICK; + return EVENT_PASSTHROUGH; } static void handle_wlc_ready(void) { diff --git a/sway/input_state.c b/sway/input_state.c index 8450fe7a..acf90d75 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -56,23 +56,24 @@ static struct mode_state { // initial view state double x, y, w, h; swayc_t *ptr; - // containers resized with tiling resize + // Containers used for resizing horizontally struct { - double x, w; + double w; swayc_t *ptr; struct { - double x, w; + double w; swayc_t *ptr; - } sib; - } lr; + } parent; + } horiz; + // Containers used for resizing vertically struct { - double y, h; + double h; swayc_t *ptr; struct { - double y, h; + double h; swayc_t *ptr; - } sib; - } tb; + } parent; + } vert; } initial; static struct { @@ -92,23 +93,19 @@ static void set_initial_view(swayc_t *view) { static void set_initial_sibling(void) { bool reset = true; - if ((initial.lr.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) { - initial.lr.x = initial.lr.ptr->x; - initial.lr.w = initial.lr.ptr->width; - initial.lr.sib.ptr = get_swayc_in_direction(initial.lr.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT); - initial.lr.sib.x = initial.lr.sib.ptr->x; - initial.lr.sib.w = initial.lr.sib.ptr->width; + if ((initial.horiz.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) { + initial.horiz.w = initial.horiz.ptr->width; + initial.horiz.parent.ptr = get_swayc_in_direction(initial.horiz.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT); + initial.horiz.parent.w = initial.horiz.parent.ptr->width; reset = false; } - if ((initial.tb.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) { - initial.tb.y = initial.tb.ptr->y; - initial.tb.h = initial.tb.ptr->height; - initial.tb.sib.ptr = get_swayc_in_direction(initial.tb.ptr, lock.top ? MOVE_UP : MOVE_DOWN); - initial.tb.sib.y = initial.tb.sib.ptr->y; - initial.tb.sib.h = initial.tb.sib.ptr->height; + if ((initial.vert.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) { + initial.vert.h = initial.vert.ptr->height; + initial.vert.parent.ptr = get_swayc_in_direction(initial.vert.ptr, lock.top ? MOVE_UP : MOVE_DOWN); + initial.vert.parent.h = initial.vert.parent.ptr->height; reset = false; } - // If nothing changes just undo the mode + // If nothing will change just undo the mode if (reset) { pointer_state.mode = 0; } @@ -123,6 +120,16 @@ static void reset_initial_view(void) { pointer_state.mode = 0; } +static void reset_initial_sibling(void) { + initial.horiz.ptr->width = initial.horiz.w; + initial.horiz.parent.ptr->width = initial.horiz.parent.w; + initial.vert.ptr->height = initial.vert.h; + initial.vert.parent.ptr->height = initial.vert.parent.h; + arrange_windows(initial.horiz.ptr->parent, -1, -1); + arrange_windows(initial.vert.ptr->parent, -1, -1); + pointer_state.mode = 0; +} + // Mode set left/right click static void pointer_mode_set_left(void) { @@ -228,7 +235,7 @@ void pointer_mode_update(void) { if (initial.w + dx > min_sane_w) { initial.ptr->width = initial.w + dx; } - } else { //lock.right + } else { // lock.right if (initial.w - dx > min_sane_w) { initial.ptr->width = initial.w - dx; initial.ptr->x = initial.x + dx; @@ -238,7 +245,7 @@ void pointer_mode_update(void) { if (initial.h + dy > min_sane_h) { initial.ptr->height = initial.h + dy; } - } else { //lock.bottom + } else { // lock.bottom if (initial.h - dy > min_sane_h) { initial.ptr->height = initial.h - dy; initial.ptr->y = initial.y + dy; @@ -264,34 +271,34 @@ void pointer_mode_update(void) { dx -= pointer_state.right.x; dy -= pointer_state.right.y; // resize if we can - if (initial.lr.ptr) { + if (initial.horiz.ptr) { if (lock.left) { // Check whether its fine to resize - if (initial.w + dx > min_sane_w && initial.lr.w - dx > min_sane_w) { - initial.lr.ptr->width = initial.lr.w - dx; - initial.lr.sib.ptr->width = initial.lr.sib.w + dx; + if (initial.w + dx > min_sane_w && initial.horiz.w - dx > min_sane_w) { + initial.horiz.ptr->width = initial.horiz.w - dx; + initial.horiz.parent.ptr->width = initial.horiz.parent.w + dx; } - } else { //lock.right - if (initial.w - dx > min_sane_w && initial.lr.w + dx > min_sane_w) { - initial.lr.ptr->width = initial.lr.w + dx; - initial.lr.sib.ptr->width = initial.lr.sib.w - dx; + } else { // lock.right + if (initial.w - dx > min_sane_w && initial.horiz.w + dx > min_sane_w) { + initial.horiz.ptr->width = initial.horiz.w + dx; + initial.horiz.parent.ptr->width = initial.horiz.parent.w - dx; } } - arrange_windows(initial.lr.ptr->parent, -1, -1); + arrange_windows(initial.horiz.ptr->parent, -1, -1); } - if (initial.tb.ptr) { + if (initial.vert.ptr) { if (lock.top) { - if (initial.h + dy > min_sane_h && initial.tb.h - dy > min_sane_h) { - initial.tb.ptr->height = initial.tb.h - dy; - initial.tb.sib.ptr->height = initial.tb.sib.h + dy; + if (initial.h + dy > min_sane_h && initial.vert.h - dy > min_sane_h) { + initial.vert.ptr->height = initial.vert.h - dy; + initial.vert.parent.ptr->height = initial.vert.parent.h + dy; } - } else { //lock.bottom - if (initial.h - dy > min_sane_h && initial.tb.h + dy > min_sane_h) { - initial.tb.ptr->height = initial.tb.h + dy; - initial.tb.sib.ptr->height = initial.tb.sib.h - dy; + } else { // lock.bottom + if (initial.h - dy > min_sane_h && initial.vert.h + dy > min_sane_h) { + initial.vert.ptr->height = initial.vert.h + dy; + initial.vert.parent.ptr->height = initial.vert.parent.h - dy; } } - arrange_windows(initial.tb.ptr->parent, -1, -1); + arrange_windows(initial.vert.ptr->parent, -1, -1); } default: return; @@ -300,15 +307,17 @@ void pointer_mode_update(void) { void pointer_mode_reset(void) { switch (pointer_state.mode) { - case M_FLOATING | M_DRAGGING: case M_FLOATING | M_RESIZING: + case M_FLOATING | M_DRAGGING: reset_initial_view(); break; - case M_TILING | M_DRAGGING: case M_TILING | M_RESIZING: + (void) reset_initial_sibling; + break; + + case M_TILING | M_DRAGGING: default: - return; + break; } } -