diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-04-02 14:06:04 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-04-02 14:06:04 -0400 |
commit | 2187684bd09928748f8b3a82c2e25e5ae82f5ae6 (patch) | |
tree | e70e2862280a410f8f0d617abc3539d6f0ae056e | |
parent | remove default from kill switch (diff) | |
parent | Merge pull request #1697 from RedSoxFan/back-and-forth (diff) | |
download | sway-2187684bd09928748f8b3a82c2e25e5ae82f5ae6.tar.gz sway-2187684bd09928748f8b3a82c2e25e5ae82f5ae6.tar.zst sway-2187684bd09928748f8b3a82c2e25e5ae82f5ae6.zip |
Merge branch 'wlroots' into split-containers
-rw-r--r-- | include/sway/output.h | 2 | ||||
-rw-r--r-- | include/sway/tree/container.h | 9 | ||||
-rw-r--r-- | include/sway/tree/layout.h | 12 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/focus.c | 7 | ||||
-rw-r--r-- | sway/commands/move.c | 184 | ||||
-rw-r--r-- | sway/desktop/output.c | 9 | ||||
-rw-r--r-- | sway/input/keyboard.c | 4 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/tree/container.c | 18 | ||||
-rw-r--r-- | sway/tree/layout.c | 58 | ||||
-rw-r--r-- | sway/tree/output.c | 11 | ||||
-rw-r--r-- | sway/tree/workspace.c | 2 |
13 files changed, 276 insertions, 42 deletions
diff --git a/include/sway/output.h b/include/sway/output.h index b4980cd8..b343ecff 100644 --- a/include/sway/output.h +++ b/include/sway/output.h | |||
@@ -36,4 +36,6 @@ void output_damage_whole(struct sway_output *output); | |||
36 | void output_damage_whole_view(struct sway_output *output, | 36 | void output_damage_whole_view(struct sway_output *output, |
37 | struct sway_view *view); | 37 | struct sway_view *view); |
38 | 38 | ||
39 | struct sway_container *output_by_name(const char *name); | ||
40 | |||
39 | #endif | 41 | #endif |
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index f0e87fb5..fa22ea75 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h | |||
@@ -84,12 +84,21 @@ struct sway_container { | |||
84 | 84 | ||
85 | struct { | 85 | struct { |
86 | struct wl_signal destroy; | 86 | struct wl_signal destroy; |
87 | // Raised after the tree updates, but before arrange_windows | ||
88 | // Passed the previous parent | ||
89 | struct wl_signal reparent; | ||
87 | } events; | 90 | } events; |
88 | }; | 91 | }; |
89 | 92 | ||
90 | // TODO make private and use the container-specific create functions | 93 | // TODO make private and use the container-specific create functions |
91 | struct sway_container *container_create(enum sway_container_type type); | 94 | struct sway_container *container_create(enum sway_container_type type); |
92 | 95 | ||
96 | const char *container_type_to_str(enum sway_container_type type); | ||
97 | |||
98 | // TODO only one container create function and pass the type? | ||
99 | struct sway_container *container_output_create( | ||
100 | struct sway_output *sway_output); | ||
101 | |||
93 | /** | 102 | /** |
94 | * Create a new container container. A container container can be a a child of | 103 | * Create a new container container. A container container can be a a child of |
95 | * a workspace container or another container container. | 104 | * a workspace container or another container container. |
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h index 53f72ec4..fbc3d6af 100644 --- a/include/sway/tree/layout.h +++ b/include/sway/tree/layout.h | |||
@@ -11,9 +11,6 @@ enum movement_direction { | |||
11 | MOVE_DOWN, | 11 | MOVE_DOWN, |
12 | MOVE_PARENT, | 12 | MOVE_PARENT, |
13 | MOVE_CHILD, | 13 | MOVE_CHILD, |
14 | MOVE_NEXT, | ||
15 | MOVE_PREV, | ||
16 | MOVE_FIRST | ||
17 | }; | 14 | }; |
18 | 15 | ||
19 | struct sway_container; | 16 | struct sway_container; |
@@ -33,7 +30,8 @@ struct sway_root { | |||
33 | void layout_init(void); | 30 | void layout_init(void); |
34 | 31 | ||
35 | // TODO move to tree.h | 32 | // TODO move to tree.h |
36 | void container_add_child(struct sway_container *parent, struct sway_container *child); | 33 | void container_add_child(struct sway_container *parent, |
34 | struct sway_container *child); | ||
37 | 35 | ||
38 | // TODO move to tree.h | 36 | // TODO move to tree.h |
39 | struct sway_container *container_add_sibling(struct sway_container *parent, | 37 | struct sway_container *container_add_sibling(struct sway_container *parent, |
@@ -49,8 +47,12 @@ struct sway_container *container_reap_empty(struct sway_container *container); | |||
49 | void container_move_to(struct sway_container* container, | 47 | void container_move_to(struct sway_container* container, |
50 | struct sway_container* destination); | 48 | struct sway_container* destination); |
51 | 49 | ||
50 | void container_move(struct sway_container *container, | ||
51 | enum movement_direction dir, int move_amt); | ||
52 | |||
52 | // TODO move to output.c | 53 | // TODO move to output.c |
53 | enum sway_container_layout container_get_default_layout(struct sway_container *output); | 54 | enum sway_container_layout container_get_default_layout( |
55 | struct sway_container *output); | ||
54 | 56 | ||
55 | // TODO move to output.c | 57 | // TODO move to output.c |
56 | void container_sort_workspaces(struct sway_container *output); | 58 | void container_sort_workspaces(struct sway_container *output); |
diff --git a/sway/commands.c b/sway/commands.c index c85ddf7a..90012c6d 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -162,6 +162,7 @@ static struct cmd_handler command_handlers[] = { | |||
162 | { "focus", cmd_focus }, | 162 | { "focus", cmd_focus }, |
163 | { "kill", cmd_kill }, | 163 | { "kill", cmd_kill }, |
164 | { "layout", cmd_layout }, | 164 | { "layout", cmd_layout }, |
165 | { "move", cmd_move }, | ||
165 | { "reload", cmd_reload }, | 166 | { "reload", cmd_reload }, |
166 | { "split", cmd_split }, | 167 | { "split", cmd_split }, |
167 | { "splith", cmd_splith }, | 168 | { "splith", cmd_splith }, |
diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 64f079f4..0a521b9e 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c | |||
@@ -20,10 +20,6 @@ static bool parse_movement_direction(const char *name, | |||
20 | *out = MOVE_PARENT; | 20 | *out = MOVE_PARENT; |
21 | } else if (strcasecmp(name, "child") == 0) { | 21 | } else if (strcasecmp(name, "child") == 0) { |
22 | *out = MOVE_CHILD; | 22 | *out = MOVE_CHILD; |
23 | } else if (strcasecmp(name, "next") == 0) { | ||
24 | *out = MOVE_NEXT; | ||
25 | } else if (strcasecmp(name, "prev") == 0) { | ||
26 | *out = MOVE_PREV; | ||
27 | } else { | 23 | } else { |
28 | return false; | 24 | return false; |
29 | } | 25 | } |
@@ -51,7 +47,8 @@ struct cmd_results *cmd_focus(int argc, char **argv) { | |||
51 | "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); | 47 | "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); |
52 | } | 48 | } |
53 | 49 | ||
54 | struct sway_container *next_focus = container_get_in_direction(con, seat, direction); | 50 | struct sway_container *next_focus = container_get_in_direction( |
51 | con, seat, direction); | ||
55 | if (next_focus) { | 52 | if (next_focus) { |
56 | sway_seat_set_focus(seat, next_focus); | 53 | sway_seat_set_focus(seat, next_focus); |
57 | } | 54 | } |
diff --git a/sway/commands/move.c b/sway/commands/move.c new file mode 100644 index 00000000..ab959b77 --- /dev/null +++ b/sway/commands/move.c | |||
@@ -0,0 +1,184 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include <wlr/types/wlr_output.h> | ||
4 | #include <wlr/types/wlr_output_layout.h> | ||
5 | #include <wlr/util/log.h> | ||
6 | #include "sway/commands.h" | ||
7 | #include "sway/input/seat.h" | ||
8 | #include "sway/output.h" | ||
9 | #include "sway/tree/container.h" | ||
10 | #include "sway/tree/layout.h" | ||
11 | #include "sway/tree/workspace.h" | ||
12 | #include "stringop.h" | ||
13 | #include "list.h" | ||
14 | |||
15 | static const char* expected_syntax = | ||
16 | "Expected 'move <left|right|up|down> <[px] px>' or " | ||
17 | "'move <container|window> to workspace <name>' or " | ||
18 | "'move <container|window|workspace> to output <name|direction>' or " | ||
19 | "'move position mouse'"; | ||
20 | |||
21 | static struct sway_container *output_in_direction(const char *direction, | ||
22 | struct wlr_output *reference, int ref_ox, int ref_oy) { | ||
23 | int ref_lx = ref_ox + reference->lx, | ||
24 | ref_ly = ref_oy + reference->ly; | ||
25 | struct { | ||
26 | char *name; | ||
27 | enum wlr_direction direction; | ||
28 | } names[] = { | ||
29 | { "up", WLR_DIRECTION_UP }, | ||
30 | { "down", WLR_DIRECTION_DOWN }, | ||
31 | { "left", WLR_DIRECTION_LEFT }, | ||
32 | { "right", WLR_DIRECTION_RIGHT }, | ||
33 | }; | ||
34 | for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); ++i) { | ||
35 | if (strcasecmp(names[i].name, direction) == 0) { | ||
36 | struct wlr_output *adjacent = wlr_output_layout_adjacent_output( | ||
37 | root_container.sway_root->output_layout, | ||
38 | names[i].direction, reference, ref_lx, ref_ly); | ||
39 | if (adjacent) { | ||
40 | struct sway_output *sway_output = adjacent->data; | ||
41 | return sway_output->swayc; | ||
42 | } | ||
43 | break; | ||
44 | } | ||
45 | } | ||
46 | return output_by_name(direction); | ||
47 | } | ||
48 | |||
49 | static struct cmd_results *cmd_move_container(struct sway_container *current, | ||
50 | int argc, char **argv) { | ||
51 | struct cmd_results *error = NULL; | ||
52 | if ((error = checkarg(argc, "move container/window", | ||
53 | EXPECTED_AT_LEAST, 4))) { | ||
54 | return error; | ||
55 | } else if (strcasecmp(argv[1], "to") == 0 | ||
56 | && strcasecmp(argv[2], "workspace") == 0) { | ||
57 | // move container to workspace x | ||
58 | if (current->type == C_WORKSPACE) { | ||
59 | // TODO: Wrap children in a container and move that | ||
60 | return cmd_results_new(CMD_FAILURE, "move", "Unimplemented"); | ||
61 | } else if (current->type != C_CONTAINER && current->type != C_VIEW) { | ||
62 | return cmd_results_new(CMD_FAILURE, "move", | ||
63 | "Can only move containers and views."); | ||
64 | } | ||
65 | struct sway_container *ws; | ||
66 | const char *num_name = NULL; | ||
67 | char *ws_name = NULL; | ||
68 | if (argc == 5 && strcasecmp(argv[3], "number") == 0) { | ||
69 | // move "container to workspace number x" | ||
70 | num_name = argv[4]; | ||
71 | ws = workspace_by_number(num_name); | ||
72 | } else { | ||
73 | ws_name = join_args(argv + 3, argc - 3); | ||
74 | ws = workspace_by_name(ws_name); | ||
75 | } | ||
76 | if (!ws) { | ||
77 | ws = workspace_create(ws_name ? ws_name : num_name); | ||
78 | } | ||
79 | free(ws_name); | ||
80 | struct sway_container *old_parent = current->parent; | ||
81 | struct sway_container *focus = sway_seat_get_focus_inactive( | ||
82 | config->handler_context.seat, ws); | ||
83 | container_move_to(current, focus); | ||
84 | sway_seat_set_focus(config->handler_context.seat, old_parent); | ||
85 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
86 | } else if (strcasecmp(argv[1], "to") == 0 | ||
87 | && strcasecmp(argv[2], "output") == 0) { | ||
88 | if (current->type == C_WORKSPACE) { | ||
89 | // TODO: Wrap children in a container and move that | ||
90 | return cmd_results_new(CMD_FAILURE, "move", "Unimplemented"); | ||
91 | } else if (current->type != C_CONTAINER | ||
92 | && current->type != C_VIEW) { | ||
93 | return cmd_results_new(CMD_FAILURE, "move", | ||
94 | "Can only move containers and views."); | ||
95 | } | ||
96 | struct sway_container *source = container_parent(current, C_OUTPUT); | ||
97 | struct sway_container *destination = output_in_direction(argv[3], | ||
98 | source->sway_output->wlr_output, current->x, current->y); | ||
99 | if (!destination) { | ||
100 | return cmd_results_new(CMD_FAILURE, "move workspace", | ||
101 | "Can't find output with name/direction '%s'", argv[3]); | ||
102 | } | ||
103 | struct sway_container *focus = sway_seat_get_focus_inactive( | ||
104 | config->handler_context.seat, destination); | ||
105 | if (!focus) { | ||
106 | // We've never been to this output before | ||
107 | focus = destination->children->items[0]; | ||
108 | } | ||
109 | struct sway_container *old_parent = current->parent; | ||
110 | container_move_to(current, focus); | ||
111 | sway_seat_set_focus(config->handler_context.seat, old_parent); | ||
112 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
113 | } | ||
114 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
115 | } | ||
116 | |||
117 | static struct cmd_results *cmd_move_workspace(struct sway_container *current, | ||
118 | int argc, char **argv) { | ||
119 | struct cmd_results *error = NULL; | ||
120 | if ((error = checkarg(argc, "move workspace", EXPECTED_EQUAL_TO, 4))) { | ||
121 | return error; | ||
122 | } else if (strcasecmp(argv[1], "to") != 0 | ||
123 | || strcasecmp(argv[2], "output") != 0) { | ||
124 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
125 | } | ||
126 | struct sway_container *source = container_parent(current, C_OUTPUT); | ||
127 | int center_x = current->width / 2 + current->x, | ||
128 | center_y = current->height / 2 + current->y; | ||
129 | struct sway_container *destination = output_in_direction(argv[3], | ||
130 | source->sway_output->wlr_output, center_x, center_y); | ||
131 | if (!destination) { | ||
132 | return cmd_results_new(CMD_FAILURE, "move workspace", | ||
133 | "Can't find output with name/direction '%s'", argv[3]); | ||
134 | } | ||
135 | if (current->type != C_WORKSPACE) { | ||
136 | current = container_parent(current, C_WORKSPACE); | ||
137 | } | ||
138 | container_move_to(current, destination); | ||
139 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
140 | } | ||
141 | |||
142 | struct cmd_results *cmd_move(int argc, char **argv) { | ||
143 | struct cmd_results *error = NULL; | ||
144 | int move_amt = 10; | ||
145 | if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { | ||
146 | return error; | ||
147 | } | ||
148 | struct sway_container *current = config->handler_context.current_container; | ||
149 | |||
150 | if (argc == 2 || (argc == 3 && strcasecmp(argv[2], "px") == 0)) { | ||
151 | char *inv; | ||
152 | move_amt = (int)strtol(argv[1], &inv, 10); | ||
153 | if (*inv != '\0' && strcasecmp(inv, "px") != 0) { | ||
154 | return cmd_results_new(CMD_FAILURE, "move", | ||
155 | "Invalid distance specified"); | ||
156 | } | ||
157 | } | ||
158 | |||
159 | if (strcasecmp(argv[0], "left") == 0) { | ||
160 | container_move(current, MOVE_LEFT, move_amt); | ||
161 | } else if (strcasecmp(argv[0], "right") == 0) { | ||
162 | container_move(current, MOVE_RIGHT, move_amt); | ||
163 | } else if (strcasecmp(argv[0], "up") == 0) { | ||
164 | container_move(current, MOVE_UP, move_amt); | ||
165 | } else if (strcasecmp(argv[0], "down") == 0) { | ||
166 | container_move(current, MOVE_DOWN, move_amt); | ||
167 | } else if (strcasecmp(argv[0], "container") == 0 | ||
168 | || strcasecmp(argv[0], "window") == 0) { | ||
169 | return cmd_move_container(current, argc, argv); | ||
170 | } else if (strcasecmp(argv[0], "workspace") == 0) { | ||
171 | return cmd_move_workspace(current, argc, argv); | ||
172 | } else if (strcasecmp(argv[0], "scratchpad") == 0 | ||
173 | || (strcasecmp(argv[0], "to") == 0 | ||
174 | && strcasecmp(argv[1], "scratchpad") == 0)) { | ||
175 | // TODO: scratchpad | ||
176 | return cmd_results_new(CMD_FAILURE, "move", "Unimplemented"); | ||
177 | } else if (strcasecmp(argv[0], "position") == 0) { | ||
178 | // TODO: floating | ||
179 | return cmd_results_new(CMD_FAILURE, "move", "Unimplemented"); | ||
180 | } else { | ||
181 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
182 | } | ||
183 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
184 | } | ||
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 0d706c52..c4265818 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -229,9 +229,12 @@ static void render_output(struct sway_output *output, struct timespec *when, | |||
229 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 229 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
230 | struct sway_container *focus = | 230 | struct sway_container *focus = |
231 | sway_seat_get_focus_inactive(seat, output->swayc); | 231 | sway_seat_get_focus_inactive(seat, output->swayc); |
232 | struct sway_container *workspace = (focus->type == C_WORKSPACE ? | 232 | if (!focus) { |
233 | focus : | 233 | // We've never been to this output before |
234 | container_parent(focus, C_WORKSPACE)); | 234 | focus = output->swayc->children->items[0]; |
235 | } | ||
236 | struct sway_container *workspace = focus->type == C_WORKSPACE ? | ||
237 | focus : container_parent(focus, C_WORKSPACE); | ||
235 | 238 | ||
236 | struct render_data rdata = { | 239 | struct render_data rdata = { |
237 | .output = output, | 240 | .output = output, |
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 99685052..8d22b684 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -97,8 +97,8 @@ static void keyboard_execute_command(struct sway_keyboard *keyboard, | |||
97 | config->handler_context.seat = keyboard->seat_device->sway_seat; | 97 | config->handler_context.seat = keyboard->seat_device->sway_seat; |
98 | struct cmd_results *results = execute_command(binding->command, NULL); | 98 | struct cmd_results *results = execute_command(binding->command, NULL); |
99 | if (results->status != CMD_SUCCESS) { | 99 | if (results->status != CMD_SUCCESS) { |
100 | wlr_log(L_DEBUG, "could not run command for binding: %s", | 100 | wlr_log(L_DEBUG, "could not run command for binding: %s (%s)", |
101 | binding->command); | 101 | binding->command, results->error); |
102 | } | 102 | } |
103 | free_cmd_results(results); | 103 | free_cmd_results(results); |
104 | } | 104 | } |
diff --git a/sway/meson.build b/sway/meson.build index b4775d58..a6a633a0 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -20,6 +20,7 @@ sway_sources = files( | |||
20 | 'commands/layout.c', | 20 | 'commands/layout.c', |
21 | 'commands/mode.c', | 21 | 'commands/mode.c', |
22 | 'commands/split.c', | 22 | 'commands/split.c', |
23 | 'commands/move.c', | ||
23 | 'commands/seat.c', | 24 | 'commands/seat.c', |
24 | 'commands/seat/attach.c', | 25 | 'commands/seat/attach.c', |
25 | 'commands/seat/fallback.c', | 26 | 'commands/seat/fallback.c', |
diff --git a/sway/tree/container.c b/sway/tree/container.c index f4c82abe..41ba973f 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 @@ 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 5098c8d1..83e4fe37 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -109,8 +109,10 @@ struct sway_container *container_reap_empty(struct sway_container *container) { | |||
109 | if (container == NULL) { | 109 | if (container == NULL) { |
110 | return NULL; | 110 | return NULL; |
111 | } | 111 | } |
112 | wlr_log(L_DEBUG, "reaping %p %s", container, container->name); | 112 | wlr_log(L_DEBUG, "Reaping %p %s '%s'", container, |
113 | while (container->type != C_VIEW && container != &root_container && container->children->length == 0) { | 113 | container_type_to_str(container->type), container->name); |
114 | while (container->type != C_ROOT && container->type != C_OUTPUT | ||
115 | && container->children->length == 0) { | ||
114 | if (container->type == C_WORKSPACE) { | 116 | if (container->type == C_WORKSPACE) { |
115 | if (!workspace_is_visible(container)) { | 117 | if (!workspace_is_visible(container)) { |
116 | struct sway_container *parent = container->parent; | 118 | struct sway_container *parent = container->parent; |
@@ -141,22 +143,46 @@ struct sway_container *container_remove_child(struct sway_container *child) { | |||
141 | return parent; | 143 | return parent; |
142 | } | 144 | } |
143 | 145 | ||
144 | void container_move_to(struct sway_container* container, | 146 | void container_move_to(struct sway_container *container, |
145 | struct sway_container* destination) { | 147 | struct sway_container *destination) { |
146 | if (container == destination | 148 | if (container == destination |
147 | || container_has_anscestor(container, destination)) { | 149 | || container_has_anscestor(container, destination)) { |
148 | return; | 150 | return; |
149 | } | 151 | } |
150 | struct sway_container *old_parent = container_remove_child(container); | 152 | struct sway_container *old_parent = container_remove_child(container); |
151 | container->width = container->height = 0; | 153 | container->width = container->height = 0; |
152 | struct sway_container *new_parent = | 154 | struct sway_container *new_parent; |
153 | container_add_sibling(destination, container); | 155 | if (destination->type == C_VIEW) { |
156 | new_parent = container_add_sibling(destination, container); | ||
157 | } else { | ||
158 | new_parent = destination; | ||
159 | container_add_child(destination, container); | ||
160 | } | ||
161 | wl_signal_emit(&container->events.reparent, old_parent); | ||
162 | if (container->type == C_WORKSPACE) { | ||
163 | struct sway_seat *seat = sway_input_manager_get_default_seat( | ||
164 | input_manager); | ||
165 | if (old_parent->children->length == 0) { | ||
166 | char *ws_name = workspace_next_name(old_parent->name); | ||
167 | struct sway_container *ws = | ||
168 | container_workspace_create(old_parent, ws_name); | ||
169 | free(ws_name); | ||
170 | sway_seat_set_focus(seat, ws); | ||
171 | } | ||
172 | container_sort_workspaces(new_parent); | ||
173 | sway_seat_set_focus(seat, new_parent); | ||
174 | } | ||
154 | if (old_parent) { | 175 | if (old_parent) { |
155 | arrange_windows(old_parent, -1, -1); | 176 | arrange_windows(old_parent, -1, -1); |
156 | } | 177 | } |
157 | arrange_windows(new_parent, -1, -1); | 178 | arrange_windows(new_parent, -1, -1); |
158 | } | 179 | } |
159 | 180 | ||
181 | void container_move(struct sway_container *container, | ||
182 | enum movement_direction dir, int move_amt) { | ||
183 | // TODO | ||
184 | } | ||
185 | |||
160 | enum sway_container_layout container_get_default_layout( | 186 | enum sway_container_layout container_get_default_layout( |
161 | struct sway_container *output) { | 187 | struct sway_container *output) { |
162 | if (config->default_layout != L_NONE) { | 188 | if (config->default_layout != L_NONE) { |
@@ -529,26 +555,6 @@ struct sway_container *container_get_in_direction( | |||
529 | } | 555 | } |
530 | } | 556 | } |
531 | 557 | ||
532 | if (dir == MOVE_PREV || dir == MOVE_NEXT) { | ||
533 | int focused_idx = index_child(container); | ||
534 | if (focused_idx == -1) { | ||
535 | return NULL; | ||
536 | } else { | ||
537 | int desired = (focused_idx + (dir == MOVE_NEXT ? 1 : -1)) % | ||
538 | parent->children->length; | ||
539 | if (desired < 0) { | ||
540 | desired += parent->children->length; | ||
541 | } | ||
542 | return parent->children->items[desired]; | ||
543 | } | ||
544 | } | ||
545 | |||
546 | // If moving to an adjacent output we need a starting position (since this | ||
547 | // output might border to multiple outputs). | ||
548 | //struct wlc_point abs_pos; | ||
549 | //get_layout_center_position(container, &abs_pos); | ||
550 | |||
551 | |||
552 | // TODO WLR fullscreen | 558 | // TODO WLR fullscreen |
553 | /* | 559 | /* |
554 | if (container->type == C_VIEW && swayc_is_fullscreen(container)) { | 560 | 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 | } | ||
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index c629f1f1..de1bf159 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -351,7 +351,7 @@ bool workspace_switch(struct sway_container *workspace) { | |||
351 | } | 351 | } |
352 | struct sway_container *active_ws = focus; | 352 | struct sway_container *active_ws = focus; |
353 | if (active_ws->type != C_WORKSPACE) { | 353 | if (active_ws->type != C_WORKSPACE) { |
354 | container_parent(focus, C_WORKSPACE); | 354 | active_ws = container_parent(focus, C_WORKSPACE); |
355 | } | 355 | } |
356 | 356 | ||
357 | if (config->auto_back_and_forth | 357 | if (config->auto_back_and_forth |