aboutsummaryrefslogtreecommitdiff
path: root/sway/layout.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2015-08-18 07:02:31 -0400
committerDrew DeVault <sir@cmpwn.com>2015-08-18 07:02:31 -0400
commit2f6dd0687bac748f414e5deb090f38d755f66d29 (patch)
tree098ea31107357e0ebedd5435d870f11fe4b60836 /sway/layout.c
parentdebb0d6bc198e13ef019b141029cdc62a7087532 (diff)
parentb132f67e7bb5017c73658cec8d297060033890e8 (diff)
Merge pull request #65 from taiyu-len/focus_v2
Focus v2
Diffstat (limited to 'sway/layout.c')
-rw-r--r--sway/layout.c75
1 files changed, 8 insertions, 67 deletions
diff --git a/sway/layout.c b/sway/layout.c
index f4079d4b..8ff5c4b7 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) {
@@ -63,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) {
@@ -82,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;
}
@@ -206,7 +208,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 +264,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;
- }
-}
-