aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-04 13:39:10 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-04 14:08:54 -0500
commit515150229847c9ebdfd0cabb6f0026fca9d57a23 (patch)
tree8a50ce0ac8ce4dc2ec973c63c68dc45378c50737 /sway/tree
parentImplement workspaces (diff)
downloadsway-515150229847c9ebdfd0cabb6f0026fca9d57a23.tar.gz
sway-515150229847c9ebdfd0cabb6f0026fca9d57a23.tar.zst
sway-515150229847c9ebdfd0cabb6f0026fca9d57a23.zip
basic focus overhaul
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/container.c33
-rw-r--r--sway/tree/layout.c30
-rw-r--r--sway/tree/workspace.c17
3 files changed, 69 insertions, 11 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 48aabd86..67fac5ee 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -158,12 +158,13 @@ swayc_t *new_output(struct sway_output *sway_output) {
158 // struct instead of trying to do focus semantics like this 158 // struct instead of trying to do focus semantics like this
159 struct sway_seat *seat = NULL; 159 struct sway_seat *seat = NULL;
160 wl_list_for_each(seat, &input_manager->seats, link) { 160 wl_list_for_each(seat, &input_manager->seats, link) {
161 if (!seat->focus) { 161 if (!seat->has_focus) {
162 seat->focus = ws; 162 sway_seat_set_focus(seat, ws);
163 } 163 }
164 } 164 }
165 165
166 free(ws_name); 166 free(ws_name);
167 wl_signal_emit(&root_container.sway_root->events.new_container, output);
167 return output; 168 return output;
168} 169}
169 170
@@ -185,6 +186,7 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
185 186
186 add_child(output, workspace); 187 add_child(output, workspace);
187 sort_workspaces(output); 188 sort_workspaces(output);
189 wl_signal_emit(&root_container.sway_root->events.new_container, workspace);
188 return workspace; 190 return workspace;
189} 191}
190 192
@@ -207,9 +209,9 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) {
207 add_child(sibling, swayc); 209 add_child(sibling, swayc);
208 } else { 210 } else {
209 // Regular case, create as sibling of current container 211 // Regular case, create as sibling of current container
210 // TODO WLR 212 add_sibling(sibling, swayc);
211 //add_sibling(sibling, swayc);
212 } 213 }
214 wl_signal_emit(&root_container.sway_root->events.new_container, swayc);
213 return swayc; 215 return swayc;
214} 216}
215 217
@@ -378,3 +380,26 @@ void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), voi
378 f(container, data); 380 f(container, data);
379 } 381 }
380} 382}
383
384/**
385 * Get a list of containers that are descendents of the container in rendering
386 * order
387 */
388list_t *container_list_children(swayc_t *con) {
389 list_t *list = create_list();
390 list_t *queue = create_list();
391
392 list_add(queue, con);
393
394 swayc_t *current = NULL;
395 while (queue->length) {
396 current = queue->items[0];
397 list_del(queue, 0);
398 list_add(list, current);
399 // TODO floating containers
400 list_cat(queue, current->children);
401 }
402
403 list_free(queue);
404 return list;
405}
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 41ff81b2..45f8c3ae 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -48,10 +48,12 @@ void init_layout(void) {
48 root_container.layout = L_NONE; 48 root_container.layout = L_NONE;
49 root_container.name = strdup("root"); 49 root_container.name = strdup("root");
50 root_container.children = create_list(); 50 root_container.children = create_list();
51 wl_signal_init(&root_container.events.destroy);
51 52
52 root_container.sway_root = calloc(1, sizeof(*root_container.sway_root)); 53 root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
53 root_container.sway_root->output_layout = wlr_output_layout_create(); 54 root_container.sway_root->output_layout = wlr_output_layout_create();
54 wl_list_init(&root_container.sway_root->unmanaged_views); 55 wl_list_init(&root_container.sway_root->unmanaged_views);
56 wl_signal_init(&root_container.sway_root->events.new_container);
55 57
56 root_container.sway_root->output_layout_change.notify = 58 root_container.sway_root->output_layout_change.notify =
57 output_layout_change_notify; 59 output_layout_change_notify;
@@ -59,6 +61,34 @@ void init_layout(void) {
59 &root_container.sway_root->output_layout_change); 61 &root_container.sway_root->output_layout_change);
60} 62}
61 63
64int index_child(const swayc_t *child) {
65 // TODO handle floating
66 swayc_t *parent = child->parent;
67 int i, len;
68 len = parent->children->length;
69 for (i = 0; i < len; ++i) {
70 if (parent->children->items[i] == child) {
71 break;
72 }
73 }
74
75 if (!sway_assert(i < len, "Stray container")) {
76 return -1;
77 }
78 return i;
79}
80
81swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) {
82 // TODO handle floating
83 swayc_t *parent = fixed->parent;
84 int i = index_child(fixed);
85 list_insert(parent->children, i + 1, active);
86 active->parent = parent;
87 // focus new child
88 parent->focused = active;
89 return active->parent;
90}
91
62void add_child(swayc_t *parent, swayc_t *child) { 92void add_child(swayc_t *parent, swayc_t *child) {
63 wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", 93 wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)",
64 child, child->type, child->width, child->height, 94 child, child->type, child->width, child->height,
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 23c630b6..ce5b425c 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -63,9 +63,10 @@ static bool _workspace_by_name(swayc_t *view, void *data) {
63swayc_t *workspace_by_name(const char *name) { 63swayc_t *workspace_by_name(const char *name) {
64 struct sway_seat *seat = input_manager_current_seat(input_manager); 64 struct sway_seat *seat = input_manager_current_seat(input_manager);
65 swayc_t *current_workspace = NULL, *current_output = NULL; 65 swayc_t *current_workspace = NULL, *current_output = NULL;
66 if (seat->focus) { 66 if (seat->has_focus) {
67 current_workspace = swayc_parent_by_type(seat->focus, C_WORKSPACE); 67 swayc_t *focus = sway_seat_get_focus(seat, &root_container);
68 current_output = swayc_parent_by_type(seat->focus, C_OUTPUT); 68 current_workspace = swayc_parent_by_type(focus, C_WORKSPACE);
69 current_output = swayc_parent_by_type(focus, C_OUTPUT);
69 } 70 }
70 if (strcmp(name, "prev") == 0) { 71 if (strcmp(name, "prev") == 0) {
71 return workspace_prev(current_workspace); 72 return workspace_prev(current_workspace);
@@ -102,7 +103,8 @@ swayc_t *workspace_create(const char *name) {
102 } 103 }
103 // Otherwise create a new one 104 // Otherwise create a new one
104 struct sway_seat *seat = input_manager_current_seat(input_manager); 105 struct sway_seat *seat = input_manager_current_seat(input_manager);
105 parent = seat->focus; 106 swayc_t *focus = sway_seat_get_focus(seat, &root_container);
107 parent = focus;
106 parent = swayc_parent_by_type(parent, C_OUTPUT); 108 parent = swayc_parent_by_type(parent, C_OUTPUT);
107 return new_workspace(parent, name); 109 return new_workspace(parent, name);
108} 110}
@@ -193,12 +195,13 @@ bool workspace_switch(swayc_t *workspace) {
193 return false; 195 return false;
194 } 196 }
195 struct sway_seat *seat = input_manager_current_seat(input_manager); 197 struct sway_seat *seat = input_manager_current_seat(input_manager);
196 if (!seat || !seat->focus) { 198 swayc_t *focus = sway_seat_get_focus(seat, &root_container);
199 if (!seat || !focus) {
197 return false; 200 return false;
198 } 201 }
199 swayc_t *active_ws = seat->focus; 202 swayc_t *active_ws = focus;
200 if (active_ws->type != C_WORKSPACE) { 203 if (active_ws->type != C_WORKSPACE) {
201 swayc_parent_by_type(seat->focus, C_WORKSPACE); 204 swayc_parent_by_type(focus, C_WORKSPACE);
202 } 205 }
203 206
204 if (config->auto_back_and_forth 207 if (config->auto_back_and_forth