diff options
-rw-r--r-- | include/sway/tree/workspace.h | 2 | ||||
-rw-r--r-- | sway/commands/move.c | 38 | ||||
-rw-r--r-- | sway/tree/workspace.c | 4 |
3 files changed, 35 insertions, 9 deletions
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index 239cbbdb..056f2329 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h | |||
@@ -16,6 +16,8 @@ struct sway_workspace { | |||
16 | 16 | ||
17 | extern char *prev_workspace_name; | 17 | extern char *prev_workspace_name; |
18 | 18 | ||
19 | struct sway_container *workspace_get_initial_output(const char *name); | ||
20 | |||
19 | char *workspace_next_name(const char *output_name); | 21 | char *workspace_next_name(const char *output_name); |
20 | 22 | ||
21 | bool workspace_switch(struct sway_container *workspace, | 23 | bool workspace_switch(struct sway_container *workspace, |
diff --git a/sway/commands/move.c b/sway/commands/move.c index 95dcb088..de6b1b0a 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -100,7 +100,8 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
100 | // determine destination | 100 | // determine destination |
101 | if (strcasecmp(argv[1], "workspace") == 0) { | 101 | if (strcasecmp(argv[1], "workspace") == 0) { |
102 | // move container to workspace x | 102 | // move container to workspace x |
103 | struct sway_container *ws; | 103 | struct sway_container *ws = NULL; |
104 | char *ws_name = NULL; | ||
104 | if (strcasecmp(argv[2], "next") == 0 || | 105 | if (strcasecmp(argv[2], "next") == 0 || |
105 | strcasecmp(argv[2], "prev") == 0 || | 106 | strcasecmp(argv[2], "prev") == 0 || |
106 | strcasecmp(argv[2], "next_on_output") == 0 || | 107 | strcasecmp(argv[2], "next_on_output") == 0 || |
@@ -110,14 +111,13 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
110 | } else if (strcasecmp(argv[2], "back_and_forth") == 0) { | 111 | } else if (strcasecmp(argv[2], "back_and_forth") == 0) { |
111 | if (!(ws = workspace_by_name(argv[2]))) { | 112 | if (!(ws = workspace_by_name(argv[2]))) { |
112 | if (prev_workspace_name) { | 113 | if (prev_workspace_name) { |
113 | ws = workspace_create(NULL, prev_workspace_name); | 114 | ws_name = strdup(prev_workspace_name); |
114 | } else { | 115 | } else { |
115 | return cmd_results_new(CMD_FAILURE, "move", | 116 | return cmd_results_new(CMD_FAILURE, "move", |
116 | "No workspace was previously active."); | 117 | "No workspace was previously active."); |
117 | } | 118 | } |
118 | } | 119 | } |
119 | } else { | 120 | } else { |
120 | char *ws_name = NULL; | ||
121 | if (strcasecmp(argv[2], "number") == 0) { | 121 | if (strcasecmp(argv[2], "number") == 0) { |
122 | // move "container to workspace number x" | 122 | // move "container to workspace number x" |
123 | if (argc < 4) { | 123 | if (argc < 4) { |
@@ -141,12 +141,26 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
141 | ws = workspace_by_name(ws_name); | 141 | ws = workspace_by_name(ws_name); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | } | |
145 | if (!ws) { | 145 | if (!ws) { |
146 | ws = workspace_create(NULL, ws_name); | 146 | // We have to create the workspace, but if the container is |
147 | // sticky and the workspace is going to be created on the same | ||
148 | // output, we'll bail out first. | ||
149 | if (container_is_floating(current) && current->is_sticky) { | ||
150 | struct sway_container *old_output = | ||
151 | container_parent(current, C_OUTPUT); | ||
152 | struct sway_container *new_output = | ||
153 | workspace_get_initial_output(ws_name); | ||
154 | if (old_output == new_output) { | ||
155 | free(ws_name); | ||
156 | return cmd_results_new(CMD_FAILURE, "move", | ||
157 | "Can't move sticky container to another workspace " | ||
158 | "on the same output"); | ||
159 | } | ||
147 | } | 160 | } |
148 | free(ws_name); | 161 | ws = workspace_create(NULL, ws_name); |
149 | } | 162 | } |
163 | free(ws_name); | ||
150 | destination = seat_get_focus_inactive(config->handler_context.seat, ws); | 164 | destination = seat_get_focus_inactive(config->handler_context.seat, ws); |
151 | } else if (strcasecmp(argv[1], "output") == 0) { | 165 | } else if (strcasecmp(argv[1], "output") == 0) { |
152 | struct sway_container *source = container_parent(current, C_OUTPUT); | 166 | struct sway_container *source = container_parent(current, C_OUTPUT); |
@@ -173,6 +187,16 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
173 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | 187 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); |
174 | } | 188 | } |
175 | 189 | ||
190 | if (container_is_floating(current) && current->is_sticky) { | ||
191 | struct sway_container *old_output = container_parent(current, C_OUTPUT); | ||
192 | struct sway_container *new_output = destination->type == C_OUTPUT ? | ||
193 | destination : container_parent(destination, C_OUTPUT); | ||
194 | if (old_output == new_output) { | ||
195 | return cmd_results_new(CMD_FAILURE, "move", "Can't move sticky " | ||
196 | "container to another workspace on the same output"); | ||
197 | } | ||
198 | } | ||
199 | |||
176 | // move container, arrange windows and return focus | 200 | // move container, arrange windows and return focus |
177 | container_move_to(current, destination); | 201 | container_move_to(current, destination); |
178 | struct sway_container *focus = | 202 | struct sway_container *focus = |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 395c6c10..b8bec044 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include "log.h" | 18 | #include "log.h" |
19 | #include "util.h" | 19 | #include "util.h" |
20 | 20 | ||
21 | static struct sway_container *get_workspace_initial_output(const char *name) { | 21 | struct sway_container *workspace_get_initial_output(const char *name) { |
22 | struct sway_container *parent; | 22 | struct sway_container *parent; |
23 | // Search for workspace<->output pair | 23 | // Search for workspace<->output pair |
24 | int e = config->workspace_outputs->length; | 24 | int e = config->workspace_outputs->length; |
@@ -48,7 +48,7 @@ static struct sway_container *get_workspace_initial_output(const char *name) { | |||
48 | struct sway_container *workspace_create(struct sway_container *output, | 48 | struct sway_container *workspace_create(struct sway_container *output, |
49 | const char *name) { | 49 | const char *name) { |
50 | if (output == NULL) { | 50 | if (output == NULL) { |
51 | output = get_workspace_initial_output(name); | 51 | output = workspace_get_initial_output(name); |
52 | } | 52 | } |
53 | 53 | ||
54 | wlr_log(WLR_DEBUG, "Added workspace %s for output %s", name, output->name); | 54 | wlr_log(WLR_DEBUG, "Added workspace %s for output %s", name, output->name); |