From e541ba3d876de8ce2812482fc6bfa13b236c6a58 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Tue, 18 Aug 2015 01:33:15 -0500 Subject: [PATCH 1/5] Added in basic, but semi-broken moving/resizing functionality to floating windows --- include/config.h | 2 + include/handlers.h | 2 +- sway/commands.c | 13 +++++ sway/handlers.c | 130 ++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 134 insertions(+), 13 deletions(-) diff --git a/include/config.h b/include/config.h index 38e93eb87..b9511aac2 100644 --- a/include/config.h +++ b/include/config.h @@ -3,6 +3,7 @@ #include #include +#include #include "list.h" struct sway_variable { @@ -32,6 +33,7 @@ struct sway_config { list_t *cmd_queue; list_t *workspace_outputs; struct sway_mode *current_mode; + uint32_t floating_mod; // Flags bool focus_follows_mouse; diff --git a/include/handlers.h b/include/handlers.h index d1742cce4..c954ce61c 100644 --- a/include/handlers.h +++ b/include/handlers.h @@ -5,7 +5,7 @@ #include extern struct wlc_interface interface; - +extern uint32_t keys_pressed[32]; //set focus to current pointer location and return focused container swayc_t *focus_pointer(void); diff --git a/sway/commands.c b/sway/commands.c index 444e61597..f47edd2f3 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -171,6 +171,10 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) { } static bool cmd_floating(struct sway_config *config, int argc, char **argv) { + if (!checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1)) { + return false; + } + if (strcasecmp(argv[0], "toggle") == 0) { swayc_t *view = get_focused_container(&root_container); // Prevent running floating commands on things like workspaces @@ -241,6 +245,14 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { return true; } +static bool cmd_floating_mod(struct sway_config *config, int argc, char **argv) { + if (!checkarg(argc, "floating_modifier", EXPECTED_EQUAL_TO, 1)) { + return false; + } + config->floating_mod = xkb_keysym_from_name(argv[0], XKB_KEYSYM_CASE_INSENSITIVE); + return true; +} + static bool cmd_focus(struct sway_config *config, int argc, char **argv) { if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { return false; @@ -465,6 +477,7 @@ static struct cmd_handler handlers[] = { { "exec_always", cmd_exec_always }, { "exit", cmd_exit }, { "floating", cmd_floating }, + { "floating_modifier", cmd_floating_mod }, { "focus", cmd_focus }, { "focus_follows_mouse", cmd_focus_follows_mouse }, { "fullscreen", cmd_fullscreen }, diff --git a/sway/handlers.c b/sway/handlers.c index e17aefee4..c39c16289 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -12,10 +12,15 @@ #include "workspace.h" #include "container.h" +uint32_t keys_pressed[32]; + static struct wlc_origin mouse_origin; //Keyboard input is being overrided by window (dmenu) static bool override_redirect = false; +static bool m1_held = false; +static bool m2_held = false; + static bool pointer_test(swayc_t *view, void *_origin) { const struct wlc_origin *origin = _origin; //Determine the output that the view is under @@ -186,7 +191,7 @@ static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geo view->x = geometry->origin.x; view->y = geometry->origin.y; arrange_windows(view->parent, -1, -1); - } + } } } @@ -230,7 +235,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier return false; } static uint8_t head = 0; - static uint32_t array[QSIZE]; bool cmd_success = false; struct sway_mode *mode = config->current_mode; @@ -239,13 +243,13 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier //Find key, if it has been pressed int mid = 0; - while (mid < head && array[mid] != sym) { + while (mid < head && keys_pressed[mid] != sym) { ++mid; } if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) { - array[head++] = sym; + keys_pressed[head++] = sym; } else if (state == WLC_KEY_STATE_RELEASED && mid < head) { - memmove(array + mid, array + mid + 1, sizeof*array * (--head - mid)); + memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--head - mid)); } // TODO: reminder to check conflicts with mod+q+a versus mod+q int i; @@ -260,7 +264,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier xkb_keysym_t *key = binding->keys->items[j]; uint8_t k; for (k = 0; k < head; ++k) { - if (array[k] == *key) { + if (keys_pressed[k] == *key) { match = true; break; } @@ -271,12 +275,12 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier } if (match) { - //Remove matched keys from array + //Remove matched keys from keys_pressed int j; for (j = 0; j < binding->keys->length; ++j) { uint8_t k; for (k = 0; k < head; ++k) { - memmove(array + k, array + k + 1, sizeof*array * (--head - k)); + memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--head - k)); break; } } @@ -291,13 +295,100 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier return cmd_success; } -static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_origin *origin) { - static wlc_handle prev_view = 0; +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; - if (config->focus_follows_mouse && prev_view != view) { + bool changed_floating = false; + int i = 0; + // Do checks to determine if proper keys are being held + swayc_t *view = active_workspace->focused; + if (m1_held) { + if (view->is_floating) { + while (keys_pressed[i++]) { + if (keys_pressed[i] == config->floating_mod) { + int dx = mouse_origin.x - prev_pos.x; + int dy = mouse_origin.y - prev_pos.y; + sway_log(L_DEBUG, "Moving from px: %d to cx: %d and from py: %d to cy: %d", prev_pos.x, mouse_origin.x, prev_pos.y, mouse_origin.y); + sway_log(L_DEBUG, "Moving: dx: %d, dy: %d", dx, dy); + + view->x += dx; + view->y += dy; + changed_floating = true; + break; + } + } + } + } else if (m2_held) { + if (view->is_floating) { + while (keys_pressed[i++]) { + if (keys_pressed[i] == config->floating_mod) { + int dx = mouse_origin.x - prev_pos.x; + int dy = mouse_origin.y - prev_pos.y; + sway_log(L_DEBUG, "Moving from px: %d to cx: %d and from py: %d to cy: %d", prev_pos.x, mouse_origin.x, prev_pos.y, mouse_origin.y); + sway_log(L_INFO, "Moving: dx: %d, dy: %d", dx, dy); + + // 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) { + changed_floating = true; + if (mouse_origin.x > midway_x) { + sway_log(L_INFO, "Downsizing view to the left"); + view->width += dx; + } else { + sway_log(L_INFO, "Upsizing view to the left"); + view->x += dx; + view->width -= dx; + } + } else if (dx > 0){ + changed_floating = true; + if (mouse_origin.x > midway_x) { + sway_log(L_INFO, "Upsizing to the right"); + view->width += dx; + } else { + sway_log(L_INFO, "Downsizing to the right"); + view->x += dx; + view->width -= dx; + } + } + + if (dy < 0) { + changed_floating = true; + if (mouse_origin.y > midway_y) { + sway_log(L_INFO, "Downsizing view to the top"); + view->height += dy; + } else { + sway_log(L_INFO, "Upsizing the view to the top"); + view->y += dy; + view->height -= dy; + } + } else if (dy > 0) { + changed_floating = true; + if (mouse_origin.y > midway_y) { + sway_log(L_INFO, "Upsizing to the bottom"); + view->height += dy; + } else { + sway_log(L_INFO, "Downsizing to the bottom"); + view->y += dy; + view->height -= dy; + } + } + break; + } + } + } + } + if (config->focus_follows_mouse && prev_handle != handle) { focus_pointer(); } - prev_view = view; + prev_handle = handle; + prev_pos = mouse_origin; + if (changed_floating) { + arrange_windows(view, -1, -1); + return true; + } return false; } @@ -305,8 +396,23 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w uint32_t button, enum wlc_button_state state) { swayc_t *focused = get_focused_container(&root_container); if (state == WLC_BUTTON_STATE_PRESSED) { + sway_log(L_DEBUG, "Mouse button %u pressed", button); + if (button == 272) { + m1_held = true; + } + if (button == 273) { + m2_held = true; + } swayc_t *pointer = focus_pointer(); return (pointer && pointer != focused); + } else { + sway_log(L_DEBUG, "Mouse button %u released", button); + if (button == 272) { + m1_held = false; + } + if (button == 273) { + m2_held = false; + } } return false; } From 11321ca2dd355be82175213795d88dcbfd0540ee Mon Sep 17 00:00:00 2001 From: taiyu Date: Tue, 18 Aug 2015 00:28:44 -0700 Subject: [PATCH 2/5] changed handling of focus, handling of view by type --- include/container.h | 2 + include/focus.h | 36 +++++++ include/handlers.h | 5 +- include/movement.h | 17 ---- sway/commands.c | 9 +- sway/container.c | 36 ++++--- sway/focus.c | 186 ++++++++++++++++++++++++++++++++++ sway/handlers.c | 237 ++++++++++++++++++++++++-------------------- sway/layout.c | 66 +----------- sway/log.c | 2 +- sway/movement.c | 70 ------------- sway/workspace.c | 50 ++-------- 12 files changed, 392 insertions(+), 324 deletions(-) create mode 100644 include/focus.h delete mode 100644 include/movement.h create mode 100644 sway/focus.c delete mode 100644 sway/movement.c diff --git a/include/container.h b/include/container.h index e395a55b3..5f386368b 100644 --- a/include/container.h +++ b/include/container.h @@ -45,6 +45,8 @@ struct sway_container { bool is_floating; + bool is_focused; + int weight; char *name; diff --git a/include/focus.h b/include/focus.h new file mode 100644 index 000000000..185910f34 --- /dev/null +++ b/include/focus.h @@ -0,0 +1,36 @@ +#ifndef _SWAY_FOCUS_H +#define _SWAY_FOCUS_H +#include "container.h" + +enum movement_direction { + MOVE_LEFT, + MOVE_RIGHT, + MOVE_UP, + MOVE_DOWN, + MOVE_PARENT +}; + +//focused_container - the container found by following the `focused` pointer +//from a given container to a container with `is_focused` boolean set +//--- +//focused_view - the container found by following the `focused` pointer from a +//given container to a view. +//--- + +swayc_t *get_focused_container(swayc_t *parent); +swayc_t *get_focused_view(swayc_t *parent); + +void set_focused_container(swayc_t *container); +void set_focused_container_for(swayc_t *ancestor, swayc_t *container); + +//lock focused container/view. locked by windows with OVERRIDE attribute +//and unlocked when they are destroyed + +extern bool locked_container_focus; +extern bool locked_view_focus; + + +bool move_focus(enum movement_direction direction); + +#endif + diff --git a/include/handlers.h b/include/handlers.h index d1742cce4..6ea4bbf1e 100644 --- a/include/handlers.h +++ b/include/handlers.h @@ -1,12 +1,11 @@ #ifndef _SWAY_HANDLERS_H #define _SWAY_HANDLERS_H - +#include "container.h" #include #include extern struct wlc_interface interface; -//set focus to current pointer location and return focused container -swayc_t *focus_pointer(void); +swayc_t *container_under_pointer(void); #endif diff --git a/include/movement.h b/include/movement.h deleted file mode 100644 index dd7018770..000000000 --- a/include/movement.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _SWAY_MOVEMENT_H -#define _SWAY_MOVEMENT_H - -#include -#include "list.h" - -enum movement_direction { - MOVE_LEFT, - MOVE_RIGHT, - MOVE_UP, - MOVE_DOWN, - MOVE_PARENT -}; - -bool move_focus(enum movement_direction direction); - -#endif diff --git a/sway/commands.c b/sway/commands.c index 444e61597..134593c70 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -8,7 +8,7 @@ #include #include "stringop.h" #include "layout.h" -#include "movement.h" +#include "focus.h" #include "log.h" #include "workspace.h" #include "commands.h" @@ -215,11 +215,12 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { view->is_floating = false; active_workspace->focused = NULL; // Get the properly focused container, and add in the view there - swayc_t *focused = focus_pointer(); + swayc_t *focused = container_under_pointer(); // If focused is null, it's because the currently focused container is a workspace if (focused == NULL) { focused = active_workspace; } + set_focused_container(focused); sway_log(L_DEBUG, "Non-floating focused container is %p", focused); @@ -232,7 +233,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { add_sibling(focused, view); } // Refocus on the view once its been put back into the layout - focus_view(view); + set_focused_container(view); arrange_windows(active_workspace, -1, -1); return true; } @@ -345,7 +346,7 @@ static bool _do_split(struct sway_config *config, int argc, char **argv, int lay else { sway_log(L_DEBUG, "Adding new container around current focused container"); swayc_t *parent = new_container(focused, layout); - focus_view(focused); + set_focused_container(focused); arrange_windows(parent, -1, -1); } diff --git a/sway/container.c b/sway/container.c index 3534721dc..67132a487 100644 --- a/sway/container.c +++ b/sway/container.c @@ -39,17 +39,11 @@ static void free_swayc(swayc_t *c) { } /* New containers */ -static void add_output_widths(swayc_t *container, void *_width) { - int *width = _width; - if (container->type == C_OUTPUT) { - *width += container->width; - } -} swayc_t *new_output(wlc_handle handle) { const struct wlc_size* size = wlc_output_get_resolution(handle); const char *name = wlc_output_get_name(handle); - sway_log(L_DEBUG, "Added output %u %s", (unsigned int)handle, name); + sway_log(L_DEBUG, "Added output %lu:%s", handle, name); swayc_t *output = new_swayc(C_OUTPUT); output->width = size->w; @@ -59,9 +53,12 @@ swayc_t *new_output(wlc_handle handle) { add_child(&root_container, output); - //TODO something with this - int total_width = 0; - container_map(&root_container, add_output_widths, &total_width); +//TODO still dont know why this is here? +// int total_width = 0; +// int i; +// for (i = 0; i < root_container.children->length; ++i) { +// total_width += ((swayc_t*)root_container.children->items[i])->width; +// } //Create workspace char *ws_name = NULL; @@ -79,7 +76,10 @@ swayc_t *new_output(wlc_handle handle) { if (!ws_name) { ws_name = workspace_next_name(); } - new_workspace(output, ws_name); + //create and initilize default workspace + swayc_t *ws = new_workspace(output, ws_name); + ws->is_focused = true; + free(ws_name); return output; @@ -139,14 +139,15 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { } swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { - const char *title = wlc_view_get_title(handle); + const char *title = wlc_view_get_title(handle); swayc_t *view = new_swayc(C_VIEW); - sway_log(L_DEBUG, "Adding new view %u:%s to container %p %d", - (unsigned int)handle, title, sibling, sibling?sibling->type:0); + sway_log(L_DEBUG, "Adding new view %lu:%s to container %p %d", + handle, title, sibling, sibling ? sibling->type : 0); //Setup values view->handle = handle; view->name = title ? strdup(title) : NULL; view->visible = true; + view->is_focused = true; view->desired_width = -1; view->desired_height = -1; @@ -168,8 +169,8 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { swayc_t *new_floating_view(wlc_handle handle) { const char *title = wlc_view_get_title(handle); swayc_t *view = new_swayc(C_VIEW); - sway_log(L_DEBUG, "Adding new view %u:%s as a floating view", - (unsigned int)handle, title); + sway_log(L_DEBUG, "Adding new view %lu:%x:%s as a floating view", + handle, wlc_view_get_type(handle), title); //Setup values view->handle = handle; view->name = title ? strdup(title) : NULL; @@ -197,6 +198,7 @@ swayc_t *new_floating_view(wlc_handle handle) { return view; } +/* Destroy container */ swayc_t *destroy_output(swayc_t *output) { if (output->children->length == 0) { @@ -300,3 +302,5 @@ void set_view_visibility(swayc_t *view, void *data) { } view->visible = (*p == 2); } + + diff --git a/sway/focus.c b/sway/focus.c new file mode 100644 index 000000000..2999c6d0c --- /dev/null +++ b/sway/focus.c @@ -0,0 +1,186 @@ +#include + +#include "focus.h" +#include "log.h" +#include "workspace.h" + +bool locked_container_focus = false; +bool locked_view_focus = false; + +//switches parent focus to c. will switch it accordingly +//TODO, everything needs a handle, so we can set front/back position properly +static void update_focus(swayc_t *c) { + //Handle if focus switches + swayc_t *parent = c->parent; + if (parent->focused != c) { + switch (c->type) { + case C_ROOT: return; + case C_OUTPUT: + wlc_output_focus(c->parent->handle); + break; + //switching workspaces + case C_WORKSPACE: + if (parent->focused) { + swayc_t *ws = parent->focused; + //hide visibility of old workspace + uint32_t mask = 1; + container_map(ws, set_view_visibility, &mask); + //set visibility of new workspace + mask = 2; + container_map(c, set_view_visibility, &mask); + wlc_output_set_mask(parent->handle, 2); + destroy_workspace(ws); + } + active_workspace = c; + break; + case C_VIEW: + case C_CONTAINER: + //TODO whatever to do when container changes + //for example, stacked and tabbing change whatever. + break; + } + } + c->parent->focused = c; +} + +bool move_focus(enum movement_direction direction) { + if (locked_container_focus) { + return false; + } + swayc_t *current = get_focused_container(&root_container); + swayc_t *parent = current->parent; + + if (direction == MOVE_PARENT) { + if (parent->type == C_OUTPUT) { + sway_log(L_DEBUG, "Focus cannot move to parent"); + return false; + } else { + sway_log(L_DEBUG, "Moving focus from %p:%ld to %p:%ld", + current, current->handle, parent, parent->handle); + set_focused_container(parent); + return true; + } + } + + while (true) { + sway_log(L_DEBUG, "Moving focus away from %p", current); + + // Test if we can even make a difference here + bool can_move = false; + int diff = 0; + if (direction == MOVE_LEFT || direction == MOVE_RIGHT) { + if (parent->layout == L_HORIZ || parent->type == C_ROOT) { + can_move = true; + diff = direction == MOVE_LEFT ? -1 : 1; + } + } else { + if (parent->layout == L_VERT) { + can_move = true; + diff = direction == MOVE_UP ? -1 : 1; + } + } + sway_log(L_DEBUG, "Can move? %s", can_move ? "yes" : "no"); + if (can_move) { + int i; + for (i = 0; i < parent->children->length; ++i) { + swayc_t *child = parent->children->items[i]; + if (child == current) { + break; + } + } + int desired = i + diff; + sway_log(L_DEBUG, "Moving from %d to %d", i, desired); + if (desired < 0 || desired >= parent->children->length) { + can_move = false; + } else { + swayc_t *newview = parent->children->items[desired]; + set_focused_container(get_focused_view(newview)); + return true; + } + } + if (!can_move) { + sway_log(L_DEBUG, "Can't move at current level, moving up tree"); + current = parent; + parent = parent->parent; + if (!parent) { + // Nothing we can do + return false; + } + } + } +} + +swayc_t *get_focused_container(swayc_t *parent) { + while (parent && !parent->is_focused) { + parent = parent->focused; + } + return parent; +} + +void set_focused_container(swayc_t *c) { + if (locked_container_focus || !c) { + return; + } + sway_log(L_DEBUG, "Setting focus to %p:%ld", c, c->handle); + if (c->type != C_ROOT && c->type != C_OUTPUT) { + c->is_focused = true; + } + swayc_t *prev_view = get_focused_view(&root_container); + swayc_t *p = c; + while (p != &root_container) { + update_focus(p); + p = p->parent; + p->is_focused = false; + } + if (!locked_view_focus) { + p = get_focused_view(c); + //Set focus to p + if (p && p != prev_view && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { + if (prev_view) { + wlc_view_set_state(prev_view->handle, WLC_BIT_ACTIVATED, false); + } + wlc_view_focus(p->handle); + wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true); + } + } +} + +void set_focused_container_for(swayc_t *a, swayc_t *c) { + if (locked_container_focus || !c) { + return; + } + swayc_t *find = c; + //Ensure that a is an ancestor of c + while (find != a && (find = find->parent)) { + if (find == &root_container) { + return; + } + } + + sway_log(L_DEBUG, "Setting focus for %p:%ld to %p:%ld", + a, a->handle, c, c->handle); + + c->is_focused = true; + swayc_t *p = c; + while (p != a) { + update_focus(p); + p = p->parent; + p->is_focused = false; + } + if (!locked_view_focus) { + p = get_focused_view(c); + //Set focus to p + if (p) { + wlc_view_focus(p->handle); + wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true); + } + } +} + +swayc_t *get_focused_view(swayc_t *parent) { + while (parent && parent->type != C_VIEW) { + parent = parent->focused; + } + return parent; +} + diff --git a/sway/handlers.c b/sway/handlers.c index e17aefee4..99f597af9 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -3,18 +3,18 @@ #include #include #include -#include "layout.h" + +#include "handlers.h" #include "log.h" +#include "layout.h" #include "config.h" #include "commands.h" -#include "handlers.h" #include "stringop.h" #include "workspace.h" #include "container.h" +#include "focus.h" static struct wlc_origin mouse_origin; -//Keyboard input is being overrided by window (dmenu) -static bool override_redirect = false; static bool pointer_test(swayc_t *view, void *_origin) { const struct wlc_origin *origin = _origin; @@ -23,27 +23,57 @@ static bool pointer_test(swayc_t *view, void *_origin) { while (parent->type != C_OUTPUT) { parent = parent->parent; } - if (view->type == C_VIEW && origin->x >= view->x && origin->y >= view->y - && origin->x < view->x + view->width && origin->y < view->y + view->height - && view->visible && parent == root_container.focused) { + if (origin->x >= view->x && origin->y >= view->y + && origin->x < view->x + view->width && origin->y < view->y + view->height + && view->visible && parent == root_container.focused) { return true; } return false; } -swayc_t *focus_pointer(void) { - swayc_t *focused = get_focused_container(&root_container); - if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) { - swayc_t *pointer = find_container(&root_container, pointer_test, &mouse_origin); - if (pointer && focused != pointer) { - unfocus_all(&root_container); - focus_view(pointer); - } else if (!focused) { - focus_view(active_workspace); - } - focused = pointer; +swayc_t *container_under_pointer(void) { + //root.output->workspace + swayc_t *lookup = root_container.focused->focused; + //Case of empty workspace + if (lookup->children == 0) { + return NULL; } - return focused; + while (lookup->type != C_VIEW) { + int i; + int len; + //if tabbed/stacked go directly to focused container, otherwise search + //children + if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) { + lookup = lookup->focused; + continue; + } + //if workspace, search floating + if (lookup->type == C_WORKSPACE) { + len = lookup->floating->length; + for (i = 0; i < len; ++i) { + if (pointer_test(lookup->floating->items[i], &mouse_origin)) { + lookup = lookup->floating->items[i]; + break; + } + } + if (i < len) { + continue; + } + } + //search children + len = lookup->children->length; + for (i = 0; i < len; ++i) { + if (pointer_test(lookup->children->items[i], &mouse_origin)) { + lookup = lookup->children->items[i]; + break; + } + } + //when border and titles are done, this could happen + if (i == len) { + break; + } + } + return lookup; } static bool handle_output_created(wlc_handle output) { @@ -81,90 +111,79 @@ static void handle_output_resolution_change(wlc_handle output, const struct wlc_ static void handle_output_focused(wlc_handle output, bool focus) { swayc_t *c = get_swayc_for_handle(output, &root_container); - if (!c) return; + //if for some reason this output doesnt exist, create it. + if (!c) { + handle_output_created(output); + } if (focus) { - unfocus_all(&root_container); - focus_view(c); + set_focused_container(c); } } static bool handle_view_created(wlc_handle handle) { swayc_t *focused = get_focused_container(&root_container); - uint32_t type = wlc_view_get_type(handle); - // If override_redirect/unmanaged/popup/modal/splach - if (type) { - sway_log(L_DEBUG,"Unmanaged window of type %x left alone", type); - wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); - if (type & WLC_BIT_UNMANAGED) { - return true; - } - // For things like Dmenu - if (type & WLC_BIT_OVERRIDE_REDIRECT) { - override_redirect = true; - wlc_view_focus(handle); - } - - // Float popups - if (type & WLC_BIT_POPUP) { - swayc_t *view = new_floating_view(handle); - wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, false); - focus_view(view); - arrange_windows(active_workspace, -1, -1); - } - } else { - swayc_t *view = new_view(focused, handle); - //Set maximize flag for windows. - //TODO: floating windows have this unset + swayc_t *newview = NULL; + switch (wlc_view_get_type(handle)) { + //regular view created regularly + case 0: + newview = new_view(focused, handle); wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true); - unfocus_all(&root_container); - focus_view(view); - arrange_windows(view->parent, -1, -1); + break; + //takes keyboard focus + case WLC_BIT_OVERRIDE_REDIRECT: + sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT", handle); + locked_view_focus = true; + wlc_view_focus(handle); + wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); + wlc_view_bring_to_front(handle); + break; + //Takes container focus + case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: + sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT|WLC_BIT_MANAGED", handle); + wlc_view_bring_to_front(handle); + locked_container_focus = true; + break; + //set modals as floating containers + case WLC_BIT_POPUP: + case WLC_BIT_MODAL: + wlc_view_bring_to_front(handle); + newview = new_floating_view(handle); + break; } - if (wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) { - unfocus_all(&root_container); - focus_view(focused); - arrange_windows(focused, -1, -1); + if (newview) { + set_focused_container(newview); + arrange_windows(newview->parent, -1, -1); } return true; } static void handle_view_destroyed(wlc_handle handle) { - sway_log(L_DEBUG, "Destroying window %u", (unsigned int)handle); - - // Properly handle unmanaged views - uint32_t type = wlc_view_get_type(handle); - if (type) { - wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); - sway_log(L_DEBUG,"Unmanaged window of type %x was destroyed", type); - if (type & WLC_BIT_UNMANAGED) { - // We need to call focus_view() on focus_pointer because unmanaged windows - // do not alter the focus structure of the container tree. This makes focus_pointer() - // think that it doesn't need to do anything, so we manually focus the result. - focus_view(focus_pointer()); - return; - } - - if (type & WLC_BIT_OVERRIDE_REDIRECT) { - override_redirect = false; - focus_view(focus_pointer()); - return; - } - - // WLC_BIT_POPUP doesn't need to be dealt with since it's - // treated as a floating view. - } - + sway_log(L_DEBUG, "Destroying window %lu", handle); swayc_t *view = get_swayc_for_handle(handle, &root_container); - swayc_t *parent; swayc_t *focused = get_focused_container(&root_container); - if (view) { - parent = destroy_view(view); - arrange_windows(parent, -1, -1); - } - if (!focused || focused == view) { - focus_pointer(); + switch (wlc_view_get_type(handle)) { + //regular view created regularly + case 0: + case WLC_BIT_MODAL: + case WLC_BIT_POPUP: + if (view) { + arrange_windows(destroy_view(view), -1, -1); + if (!focused || focused == view) { + set_focused_container(container_under_pointer()); + } + } + break; + //takes keyboard focus + case WLC_BIT_OVERRIDE_REDIRECT: + locked_view_focus = false; + break; + //Takes container focus + case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: + locked_container_focus = false; + break; } + set_focused_container(get_focused_view(&root_container)); } static void handle_view_focus(wlc_handle view, bool focus) { @@ -172,6 +191,8 @@ static void handle_view_focus(wlc_handle view, bool focus) { } static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geometry* geometry) { + sway_log(L_DEBUG, "geometry request %d x %d : %d x %d", + geometry->origin.x, geometry->origin.y, geometry->size.w, geometry->size.h); // If the view is floating, then apply the geometry. // Otherwise save the desired width/height for the view. // This will not do anything for the time being as WLC improperly sends geometry requests @@ -186,33 +207,32 @@ static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geo view->x = geometry->origin.x; view->y = geometry->origin.y; arrange_windows(view->parent, -1, -1); - } + } } } static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) { - switch(state) { + swayc_t *c = NULL; + switch (state) { case WLC_BIT_FULLSCREEN: - { - //I3 just lets it become fullscreen - wlc_view_set_state(view,state,toggle); - swayc_t *c = get_swayc_for_handle(view, &root_container); - sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d",view,c->name,toggle); - if (c) { - arrange_windows(c->parent, -1, -1); - //Set it as focused window for that workspace if its going - //fullscreen - if (toggle) { - swayc_t *ws = c; - while (ws->type != C_WORKSPACE) { - ws = ws->parent; - } - //Set ws focus to c - focus_view_for(ws, c); + //I3 just lets it become fullscreen + wlc_view_set_state(view, state, toggle); + c = get_swayc_for_handle(view, &root_container); + sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d", view, c->name, toggle); + if (c) { + arrange_windows(c->parent, -1, -1); + //Set it as focused window for that workspace if its going + //fullscreen + if (toggle) { + swayc_t *ws = c; + while (ws->type != C_WORKSPACE) { + ws = ws->parent; } + //Set ws focus to c + set_focused_container_for(ws, c); } - break; } + break; case WLC_BIT_MAXIMIZED: case WLC_BIT_RESIZING: case WLC_BIT_MOVING: @@ -226,7 +246,7 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { enum { QSIZE = 32 }; - if (override_redirect) { + if (locked_view_focus) { return false; } static uint8_t head = 0; @@ -295,7 +315,7 @@ static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct w static wlc_handle prev_view = 0; mouse_origin = *origin; if (config->focus_follows_mouse && prev_view != view) { - focus_pointer(); + set_focused_container(container_under_pointer()); } prev_view = view; return false; @@ -305,7 +325,8 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w uint32_t button, enum wlc_button_state state) { swayc_t *focused = get_focused_container(&root_container); if (state == WLC_BUTTON_STATE_PRESSED) { - swayc_t *pointer = focus_pointer(); + swayc_t *pointer = container_under_pointer(); + set_focused_container(pointer); return (pointer && pointer != focused); } return false; diff --git a/sway/layout.c b/sway/layout.c index f4079d4b5..de7ef3701 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -31,9 +31,6 @@ void add_child(swayc_t *parent, swayc_t *child) { child->width, child->height, parent, parent->type, parent->width, parent->height); list_add(parent->children, child); child->parent = parent; - if (parent->focused == NULL) { - parent->focused = child; - } } swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) { @@ -206,7 +203,7 @@ void arrange_windows(swayc_t *container, int width, int height) { // Arrage floating layouts for workspaces last if (container->type == C_WORKSPACE) { for (i = 0; i < container->floating->length; ++i) { - swayc_t *view = ((swayc_t *)container->floating->items[i]); + swayc_t *view = container->floating->items[i]; // Set the geometry struct wlc_geometry geometry = { .origin = { @@ -262,64 +259,3 @@ swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) { return NULL; } -swayc_t *get_focused_container(swayc_t *parent) { - if (parent->focused == NULL) { - return parent; - } - return get_focused_container(parent->focused); -} - -void unfocus_all(swayc_t *container) { - if (container->children == NULL) { - return; - } - int i; - for (i = 0; i < container->children->length; ++i) { - swayc_t *view = container->children->items[i]; - if (view->type == C_VIEW) { - wlc_view_set_state(view->handle, WLC_BIT_ACTIVATED, false); - } else { - unfocus_all(view); - } - } -} - -void focus_view(swayc_t *view) { - if (!view) { - return; - } - sway_log(L_DEBUG, "Setting focus for %p:%ld", view, view->handle); - swayc_t *c = view; - //Set focus from root to view - while (c != &root_container) { - c->parent->focused = c; - c = c->parent; - } - //Set output - wlc_output_focus(c->focused->handle); - //get focus for views focused window - while (view && view->type != C_VIEW) { - view = view->focused; - } - if (view) { - wlc_view_set_state(view->handle, WLC_BIT_ACTIVATED, true); - wlc_view_focus(view->handle); - } -} - -void focus_view_for(swayc_t *top, swayc_t *view) { - swayc_t *find = view; - //Make sure top is a ancestor of view - while (find != top) { - if (find == &root_container) { - return; - } - find = find->parent; - } - //Set focus for top to go to view - while (view != top) { - view->parent->focused = view; - view = view->parent; - } -} - diff --git a/sway/log.c b/sway/log.c index b9048b34d..03639ae42 100644 --- a/sway/log.c +++ b/sway/log.c @@ -8,7 +8,7 @@ int colored = 1; int v = 0; -const char *verbosity_colors[] = { +static const char *verbosity_colors[] = { "", // L_SILENT "\x1B[1;31m", // L_ERROR "\x1B[1;34m", // L_INFO diff --git a/sway/movement.c b/sway/movement.c deleted file mode 100644 index 127263923..000000000 --- a/sway/movement.c +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include "list.h" -#include "log.h" -#include "layout.h" -#include "movement.h" - -bool move_focus(enum movement_direction direction) { - swayc_t *current = get_focused_container(&root_container); - swayc_t *parent = current->parent; - - if (direction == MOVE_PARENT) { - if (parent->type == C_OUTPUT) { - sway_log(L_DEBUG, "Focus cannot move to parent"); - return false; - } else { - sway_log(L_DEBUG, "Moving focus away from %p to %p", current, parent); - unfocus_all(parent->parent); - focus_view(parent); - return true; - } - } - - while (true) { - sway_log(L_DEBUG, "Moving focus away from %p", current); - - // Test if we can even make a difference here - bool can_move = false; - int diff = 0; - if (direction == MOVE_LEFT || direction == MOVE_RIGHT) { - if (parent->layout == L_HORIZ || parent->type == C_ROOT) { - can_move = true; - diff = direction == MOVE_LEFT ? -1 : 1; - } - } else { - if (parent->layout == L_VERT) { - can_move = true; - diff = direction == MOVE_UP ? -1 : 1; - } - } - sway_log(L_DEBUG, "Can move? %s", can_move ? "yes" : "no"); - if (can_move) { - int i; - for (i = 0; i < parent->children->length; ++i) { - swayc_t *child = parent->children->items[i]; - if (child == current) { - break; - } - } - int desired = i + diff; - sway_log(L_DEBUG, "Moving from %d to %d", i, desired); - if (desired < 0 || desired >= parent->children->length) { - can_move = false; - } else { - unfocus_all(&root_container); - focus_view(parent->children->items[desired]); - return true; - } - } - if (!can_move) { - sway_log(L_DEBUG, "Can't move at current level, moving up tree"); - current = parent; - parent = parent->parent; - if (!parent) { - // Nothing we can do - return false; - } - } - } -} diff --git a/sway/workspace.c b/sway/workspace.c index df6464457..bc0fa2c8d 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -9,6 +9,7 @@ #include "handlers.h" #include "config.h" #include "stringop.h" +#include "focus.h" swayc_t *active_workspace = NULL; @@ -173,64 +174,33 @@ void workspace_prev() { } void workspace_switch(swayc_t *workspace) { - swayc_t *ws_output = workspace->parent; - while (ws_output->type != C_OUTPUT) { - ws_output = ws_output->parent; - } - // The current workspace of the output our target workspace is in - swayc_t *focused_workspace = ws_output->focused; - if (workspace != focused_workspace && focused_workspace) { - sway_log(L_DEBUG, "workspace: changing from '%s' to '%s'", focused_workspace->name, workspace->name); - uint32_t mask = 1; - - // set all c_views in the old workspace to the invisible mask if the workspace - // is in the same output & c_views in the new workspace to the visible mask - container_map(focused_workspace, set_view_visibility, &mask); - mask = 2; - container_map(workspace, set_view_visibility, &mask); - wlc_output_set_mask(ws_output->handle, 2); - - destroy_workspace(focused_workspace); - } - unfocus_all(&root_container); - focus_view(workspace); - - // focus the output this workspace is on - swayc_t *output = workspace->parent; - sway_log(L_DEBUG, "Switching focus to output %p (%d)", output, output->type); - while (output && output->type != C_OUTPUT) { - output = output->parent; - } - if (output) { - sway_log(L_DEBUG, "Switching focus to output %p (%d)", output, output->type); - wlc_output_focus(output->handle); - } + set_focused_container(workspace); active_workspace = workspace; } /* XXX:DEBUG:XXX */ static void container_log(const swayc_t *c) { fprintf(stderr, "focus:%c|", - c == get_focused_container(&root_container) ? 'F' : //Focused + c->is_focused ? 'F' : //Focused c == active_workspace ? 'W' : //active workspace c == &root_container ? 'R' : //root 'X');//not any others fprintf(stderr,"(%p)",c); fprintf(stderr,"(p:%p)",c->parent); fprintf(stderr,"(f:%p)",c->focused); + fprintf(stderr,"(h:%ld)",c->handle); fprintf(stderr,"Type:"); fprintf(stderr, - c->type == C_ROOT ? "Root|" : - c->type == C_OUTPUT ? "Output|" : + c->type == C_ROOT ? "Root|" : + c->type == C_OUTPUT ? "Output|" : c->type == C_WORKSPACE ? "Workspace|" : c->type == C_CONTAINER ? "Container|" : - c->type == C_VIEW ? "View|" : - "Unknown|"); + c->type == C_VIEW ? "View|" : "Unknown|"); fprintf(stderr,"layout:"); fprintf(stderr, - c->layout == L_NONE ? "NONE|" : - c->layout == L_HORIZ ? "Horiz|": - c->layout == L_VERT ? "Vert|": + c->layout == L_NONE ? "NONE|" : + c->layout == L_HORIZ ? "Horiz|": + c->layout == L_VERT ? "Vert|": c->layout == L_STACKED ? "Stacked|": c->layout == L_FLOATING ? "Floating|": "Unknown|"); From f0fe4a346d46b2033d8ceff9b06b558d82f51f6d Mon Sep 17 00:00:00 2001 From: taiyu Date: Tue, 18 Aug 2015 00:58:25 -0700 Subject: [PATCH 3/5] style --- sway/handlers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sway/handlers.c b/sway/handlers.c index 99f597af9..d18be253a 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -192,7 +192,7 @@ static void handle_view_focus(wlc_handle view, bool focus) { static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geometry* geometry) { sway_log(L_DEBUG, "geometry request %d x %d : %d x %d", - geometry->origin.x, geometry->origin.y, geometry->size.w, geometry->size.h); + geometry->origin.x, geometry->origin.y, geometry->size.w,geometry->size.h); // If the view is floating, then apply the geometry. // Otherwise save the desired width/height for the view. // This will not do anything for the time being as WLC improperly sends geometry requests @@ -213,12 +213,12 @@ static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geo static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) { swayc_t *c = NULL; - switch (state) { + switch(state) { case WLC_BIT_FULLSCREEN: //I3 just lets it become fullscreen wlc_view_set_state(view, state, toggle); c = get_swayc_for_handle(view, &root_container); - sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d", view, c->name, toggle); + sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d",view,c->name,toggle); if (c) { arrange_windows(c->parent, -1, -1); //Set it as focused window for that workspace if its going From 63bc0d3b5451f4668186c98a1f283f3e0a104cfe Mon Sep 17 00:00:00 2001 From: taiyu Date: Tue, 18 Aug 2015 02:46:14 -0700 Subject: [PATCH 4/5] more changes --- include/layout.h | 2 +- sway/container.c | 13 +++++++------ sway/focus.c | 2 +- sway/handlers.c | 6 +++--- sway/layout.c | 9 +++++++-- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/layout.h b/include/layout.h index a7f43fda3..26d00ce44 100644 --- a/include/layout.h +++ b/include/layout.h @@ -13,7 +13,7 @@ void add_child(swayc_t *parent, swayc_t *child); //Returns parent container which needs to be rearranged. 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 *parent, swayc_t *child); +swayc_t *remove_child(swayc_t *child); //Layout void arrange_windows(swayc_t *container, int width, int height); diff --git a/sway/container.c b/sway/container.c index 67132a487..2b9f7554d 100644 --- a/sway/container.c +++ b/sway/container.c @@ -27,10 +27,7 @@ static void free_swayc(swayc_t *c) { list_free(c->children); } if (c->parent) { - if (c->parent->focused == c) { - c->parent->focused = NULL; - } - remove_child(c->parent, c); + remove_child(c); } if (c->name) { free(c->name); @@ -118,6 +115,11 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { //reorder focus cont->focused = workspace->focused; workspace->focused = cont; + //set all children focu to container + int i; + for (i = 0; i < workspace->children->length; ++i) { + ((swayc_t *)workspace->children->items[i])->parent = cont; + } //Swap children list_t *tmp_list = workspace->children; workspace->children = cont->children; @@ -204,7 +206,7 @@ swayc_t *destroy_output(swayc_t *output) { if (output->children->length == 0) { //TODO move workspaces to other outputs } - sway_log(L_DEBUG, "OUTPUT: Destroying output '%u'", (unsigned int)output->handle); + sway_log(L_DEBUG, "OUTPUT: Destroying output '%lu'", output->handle); free_swayc(output); return &root_container; } @@ -246,7 +248,6 @@ swayc_t *destroy_view(swayc_t *view) { if (parent->type == C_CONTAINER) { return destroy_container(parent); } - return parent; } diff --git a/sway/focus.c b/sway/focus.c index 2999c6d0c..4f57f252e 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -135,7 +135,7 @@ void set_focused_container(swayc_t *c) { if (!locked_view_focus) { p = get_focused_view(c); //Set focus to p - if (p && p != prev_view && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { + if (p && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { if (prev_view) { wlc_view_set_state(prev_view->handle, WLC_BIT_ACTIVATED, false); } diff --git a/sway/handlers.c b/sway/handlers.c index 2a5113ccb..24e8e0149 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -38,6 +38,9 @@ static bool pointer_test(swayc_t *view, void *_origin) { swayc_t *container_under_pointer(void) { //root.output->workspace + if (!root_container.focused || !root_container.focused->focused) { + return NULL; + } swayc_t *lookup = root_container.focused->focused; //Case of empty workspace if (lookup->children == 0) { @@ -174,9 +177,6 @@ static void handle_view_destroyed(wlc_handle handle) { if (view) { swayc_t *parent = destroy_view(view); arrange_windows(parent, -1, -1); - if (!focused || focused == view) { - set_focused_container(container_under_pointer()); - } } break; //takes keyboard focus diff --git a/sway/layout.c b/sway/layout.c index de7ef3701..8ff5c4b72 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -60,8 +60,9 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) { return parent; } -swayc_t *remove_child(swayc_t *parent, swayc_t *child) { +swayc_t *remove_child(swayc_t *child) { int i; + swayc_t *parent = child->parent; // Special case for floating views if (child->is_floating) { for (i = 0; i < parent->floating->length; ++i) { @@ -79,7 +80,11 @@ swayc_t *remove_child(swayc_t *parent, swayc_t *child) { } } if (parent->focused == child) { - parent->focused = NULL; + if (parent->children->length > 0) { + parent->focused = parent->children->items[i?i-1:0]; + } else { + parent->focused = NULL; + } } return parent; } From b132f67e7bb5017c73658cec8d297060033890e8 Mon Sep 17 00:00:00 2001 From: taiyu Date: Tue, 18 Aug 2015 03:48:41 -0700 Subject: [PATCH 5/5] minor fixes --- include/config.h | 8 ++++---- sway/config.c | 2 +- sway/focus.c | 8 +++++++- sway/handlers.c | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/config.h b/include/config.h index b9511aac2..9243bf351 100644 --- a/include/config.h +++ b/include/config.h @@ -33,17 +33,17 @@ struct sway_config { list_t *cmd_queue; list_t *workspace_outputs; struct sway_mode *current_mode; - uint32_t floating_mod; + uint32_t floating_mod; // Flags bool focus_follows_mouse; bool mouse_warping; - bool active; - bool failed; + bool active; + bool failed; bool reloading; }; -bool load_config(); +bool load_config(void); bool read_config(FILE *file, bool is_active); char *do_var_replacement(struct sway_config *config, char *str); diff --git a/sway/config.c b/sway/config.c index f06d55f8a..4125f4cde 100644 --- a/sway/config.c +++ b/sway/config.c @@ -126,7 +126,7 @@ static char* get_config_path() { return NULL; } -bool load_config() { +bool load_config(void) { sway_log(L_INFO, "Loading config"); char *path = get_config_path(); diff --git a/sway/focus.c b/sway/focus.c index 4f57f252e..14d271846 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -33,10 +33,11 @@ static void update_focus(swayc_t *c) { } active_workspace = c; break; + default: case C_VIEW: case C_CONTAINER: //TODO whatever to do when container changes - //for example, stacked and tabbing change whatever. + //for example, stacked and tabbing change stuff. break; } } @@ -114,6 +115,11 @@ swayc_t *get_focused_container(swayc_t *parent) { while (parent && !parent->is_focused) { parent = parent->focused; } + //just incase + if (parent == NULL) { + sway_log(L_DEBUG, "get_focused_container unable to find container"); + return active_workspace; + } return parent; } diff --git a/sway/handlers.c b/sway/handlers.c index 24e8e0149..0157d466f 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -252,7 +252,7 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { enum { QSIZE = 32 }; - if (locked_view_focus) { + if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { return false; } static uint8_t head = 0;