diff options
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/container.c | 18 | ||||
-rw-r--r-- | sway/tree/layout.c | 58 | ||||
-rw-r--r-- | sway/tree/output.c | 11 |
3 files changed, 61 insertions, 26 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 746dbf1f..21fe3fb0 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -33,6 +33,23 @@ static list_t *get_bfs_queue() { | |||
33 | return bfs_queue; | 33 | return bfs_queue; |
34 | } | 34 | } |
35 | 35 | ||
36 | const char *container_type_to_str(enum sway_container_type type) { | ||
37 | switch (type) { | ||
38 | case C_ROOT: | ||
39 | return "C_ROOT"; | ||
40 | case C_OUTPUT: | ||
41 | return "C_OUTPUT"; | ||
42 | case C_WORKSPACE: | ||
43 | return "C_WORKSPACE"; | ||
44 | case C_CONTAINER: | ||
45 | return "C_CONTAINER"; | ||
46 | case C_VIEW: | ||
47 | return "C_VIEW"; | ||
48 | default: | ||
49 | return "C_UNKNOWN"; | ||
50 | } | ||
51 | } | ||
52 | |||
36 | static void notify_new_container(struct sway_container *container) { | 53 | static void notify_new_container(struct sway_container *container) { |
37 | wl_signal_emit(&root_container.sway_root->events.new_container, container); | 54 | wl_signal_emit(&root_container.sway_root->events.new_container, container); |
38 | ipc_event_window(container, "new"); | 55 | ipc_event_window(container, "new"); |
@@ -54,6 +71,7 @@ static struct sway_container *container_create(enum sway_container_type type) { | |||
54 | } | 71 | } |
55 | 72 | ||
56 | wl_signal_init(&c->events.destroy); | 73 | wl_signal_init(&c->events.destroy); |
74 | wl_signal_init(&c->events.reparent); | ||
57 | 75 | ||
58 | return c; | 76 | return c; |
59 | } | 77 | } |
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index ce0682dc..a8941a40 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -106,8 +106,10 @@ struct sway_container *container_reap_empty(struct sway_container *container) { | |||
106 | if (!sway_assert(container, "reaping null container")) { | 106 | if (!sway_assert(container, "reaping null container")) { |
107 | return NULL; | 107 | return NULL; |
108 | } | 108 | } |
109 | wlr_log(L_DEBUG, "reaping %p %s", container, container->name); | 109 | wlr_log(L_DEBUG, "Reaping %p %s '%s'", container, |
110 | while (container != &root_container && container->children->length == 0) { | 110 | container_type_to_str(container->type), container->name); |
111 | while (container->type != C_ROOT && container->type != C_OUTPUT | ||
112 | && container->children->length == 0) { | ||
111 | if (container->type == C_WORKSPACE) { | 113 | if (container->type == C_WORKSPACE) { |
112 | if (!workspace_is_visible(container)) { | 114 | if (!workspace_is_visible(container)) { |
113 | struct sway_container *parent = container->parent; | 115 | struct sway_container *parent = container->parent; |
@@ -138,22 +140,46 @@ struct sway_container *container_remove_child(struct sway_container *child) { | |||
138 | return container_reap_empty(parent); | 140 | return container_reap_empty(parent); |
139 | } | 141 | } |
140 | 142 | ||
141 | void container_move_to(struct sway_container* container, | 143 | void container_move_to(struct sway_container *container, |
142 | struct sway_container* destination) { | 144 | struct sway_container *destination) { |
143 | if (container == destination | 145 | if (container == destination |
144 | || container_has_anscestor(container, destination)) { | 146 | || container_has_anscestor(container, destination)) { |
145 | return; | 147 | return; |
146 | } | 148 | } |
147 | struct sway_container *old_parent = container_remove_child(container); | 149 | struct sway_container *old_parent = container_remove_child(container); |
148 | container->width = container->height = 0; | 150 | container->width = container->height = 0; |
149 | struct sway_container *new_parent = | 151 | struct sway_container *new_parent; |
150 | container_add_sibling(destination, container); | 152 | if (destination->type == C_VIEW) { |
153 | new_parent = container_add_sibling(destination, container); | ||
154 | } else { | ||
155 | new_parent = destination; | ||
156 | container_add_child(destination, container); | ||
157 | } | ||
158 | wl_signal_emit(&container->events.reparent, old_parent); | ||
159 | if (container->type == C_WORKSPACE) { | ||
160 | struct sway_seat *seat = sway_input_manager_get_default_seat( | ||
161 | input_manager); | ||
162 | if (old_parent->children->length == 0) { | ||
163 | char *ws_name = workspace_next_name(old_parent->name); | ||
164 | struct sway_container *ws = | ||
165 | container_workspace_create(old_parent, ws_name); | ||
166 | free(ws_name); | ||
167 | sway_seat_set_focus(seat, ws); | ||
168 | } | ||
169 | container_sort_workspaces(new_parent); | ||
170 | sway_seat_set_focus(seat, new_parent); | ||
171 | } | ||
151 | if (old_parent) { | 172 | if (old_parent) { |
152 | arrange_windows(old_parent, -1, -1); | 173 | arrange_windows(old_parent, -1, -1); |
153 | } | 174 | } |
154 | arrange_windows(new_parent, -1, -1); | 175 | arrange_windows(new_parent, -1, -1); |
155 | } | 176 | } |
156 | 177 | ||
178 | void container_move(struct sway_container *container, | ||
179 | enum movement_direction dir, int move_amt) { | ||
180 | // TODO | ||
181 | } | ||
182 | |||
157 | enum sway_container_layout container_get_default_layout( | 183 | enum sway_container_layout container_get_default_layout( |
158 | struct sway_container *output) { | 184 | struct sway_container *output) { |
159 | if (config->default_layout != L_NONE) { | 185 | if (config->default_layout != L_NONE) { |
@@ -521,26 +547,6 @@ static struct sway_container *get_swayc_in_direction_under( | |||
521 | } | 547 | } |
522 | } | 548 | } |
523 | 549 | ||
524 | if (dir == MOVE_PREV || dir == MOVE_NEXT) { | ||
525 | int focused_idx = index_child(container); | ||
526 | if (focused_idx == -1) { | ||
527 | return NULL; | ||
528 | } else { | ||
529 | int desired = (focused_idx + (dir == MOVE_NEXT ? 1 : -1)) % | ||
530 | parent->children->length; | ||
531 | if (desired < 0) { | ||
532 | desired += parent->children->length; | ||
533 | } | ||
534 | return parent->children->items[desired]; | ||
535 | } | ||
536 | } | ||
537 | |||
538 | // If moving to an adjacent output we need a starting position (since this | ||
539 | // output might border to multiple outputs). | ||
540 | //struct wlc_point abs_pos; | ||
541 | //get_layout_center_position(container, &abs_pos); | ||
542 | |||
543 | |||
544 | // TODO WLR fullscreen | 550 | // TODO WLR fullscreen |
545 | /* | 551 | /* |
546 | if (container->type == C_VIEW && swayc_is_fullscreen(container)) { | 552 | if (container->type == C_VIEW && swayc_is_fullscreen(container)) { |
diff --git a/sway/tree/output.c b/sway/tree/output.c index 7248fd00..2331dc2b 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <strings.h> | ||
1 | #include "sway/tree/container.h" | 2 | #include "sway/tree/container.h" |
2 | #include "sway/tree/layout.h" | 3 | #include "sway/tree/layout.h" |
3 | #include "sway/output.h" | 4 | #include "sway/output.h" |
@@ -37,3 +38,13 @@ struct sway_container *container_output_destroy(struct sway_container *output) { | |||
37 | container_destroy(output); | 38 | container_destroy(output); |
38 | return &root_container; | 39 | return &root_container; |
39 | } | 40 | } |
41 | |||
42 | struct sway_container *output_by_name(const char *name) { | ||
43 | for (int i = 0; i < root_container.children->length; ++i) { | ||
44 | struct sway_container *output = root_container.children->items[i]; | ||
45 | if (strcasecmp(output->name, name) == 0){ | ||
46 | return output; | ||
47 | } | ||
48 | } | ||
49 | return NULL; | ||
50 | } | ||