aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/bar.c115
-rw-r--r--sway/commands/bar/hidden_state.c34
-rw-r--r--sway/commands/bar/id.c2
-rw-r--r--sway/commands/bar/mode.c34
-rw-r--r--sway/commands/bar/status_command.c2
-rw-r--r--sway/commands/border.c2
-rw-r--r--sway/commands/gaps.c50
-rw-r--r--sway/commands/move.c8
-rw-r--r--sway/commands/sticky.c5
-rw-r--r--sway/commands/swap.c19
-rw-r--r--sway/commands/workspace.c22
11 files changed, 154 insertions, 139 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
index 03f4c557..c808aef2 100644
--- a/sway/commands/bar.c
+++ b/sway/commands/bar.c
@@ -17,7 +17,6 @@ static struct cmd_handler bar_handlers[] = {
{ "height", bar_cmd_height },
{ "hidden_state", bar_cmd_hidden_state },
{ "icon_theme", bar_cmd_icon_theme },
- { "id", bar_cmd_id },
{ "mode", bar_cmd_mode },
{ "modifier", bar_cmd_modifier },
{ "output", bar_cmd_output },
@@ -27,7 +26,6 @@ static struct cmd_handler bar_handlers[] = {
{ "separator_symbol", bar_cmd_separator_symbol },
{ "status_command", bar_cmd_status_command },
{ "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
- { "swaybar_command", bar_cmd_swaybar_command },
{ "tray_output", bar_cmd_tray_output },
{ "tray_padding", bar_cmd_tray_padding },
{ "workspace_buttons", bar_cmd_workspace_buttons },
@@ -36,54 +34,49 @@ static struct cmd_handler bar_handlers[] = {
// Must be in alphabetical order for bsearch
static struct cmd_handler bar_config_handlers[] = {
- { "hidden_state", bar_cmd_hidden_state },
- { "mode", bar_cmd_mode }
+ { "id", bar_cmd_id },
+ { "swaybar_command", bar_cmd_swaybar_command },
};
+// Determines whether the subcommand is valid in any bar handler struct
+static bool is_subcommand(char *name) {
+ return find_handler(name, bar_handlers, sizeof(bar_handlers)) ||
+ find_handler(name, bar_config_handlers, sizeof(bar_config_handlers));
+}
+
struct cmd_results *cmd_bar(int argc, char **argv) {
struct cmd_results *error = NULL;
- if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) {
+ if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 2))) {
return error;
}
- if (find_handler(argv[0], bar_config_handlers,
- sizeof(bar_config_handlers))) {
- if (config->reading) {
- return config_subcommand(argv, argc, bar_config_handlers,
- sizeof(bar_config_handlers));
- }
- return cmd_results_new(CMD_FAILURE, "bar",
- "Can only be used in config file.");
- }
-
- if (argc > 1) {
- struct bar_config *bar = NULL;
- if (!find_handler(argv[0], bar_handlers, sizeof(bar_handlers))
- && find_handler(argv[1], bar_handlers, sizeof(bar_handlers))) {
- for (int i = 0; i < config->bars->length; ++i) {
- struct bar_config *item = config->bars->items[i];
- if (strcmp(item->id, argv[0]) == 0) {
- wlr_log(WLR_DEBUG, "Selecting bar: %s", argv[0]);
- bar = item;
- break;
- }
+ bool spawn = false;
+ struct bar_config *bar = NULL;
+ if (strcmp(argv[0], "id") != 0 && is_subcommand(argv[1])) {
+ for (int i = 0; i < config->bars->length; ++i) {
+ struct bar_config *item = config->bars->items[i];
+ if (strcmp(item->id, argv[0]) == 0) {
+ wlr_log(WLR_DEBUG, "Selecting bar: %s", argv[0]);
+ bar = item;
+ break;
}
+ }
+ if (!bar) {
+ spawn = !config->reading;
+ wlr_log(WLR_DEBUG, "Creating bar: %s", argv[0]);
+ bar = default_bar_config();
if (!bar) {
- wlr_log(WLR_DEBUG, "Creating bar: %s", argv[0]);
- bar = default_bar_config();
- if (!bar) {
- return cmd_results_new(CMD_FAILURE, "bar",
- "Unable to allocate bar state");
- }
-
- bar->id = strdup(argv[0]);
+ return cmd_results_new(CMD_FAILURE, "bar",
+ "Unable to allocate bar state");
}
- config->current_bar = bar;
- ++argv; --argc;
+
+ bar->id = strdup(argv[0]);
}
+ config->current_bar = bar;
+ ++argv; --argc;
}
- if (!config->current_bar) {
+ if (!config->current_bar && config->reading) {
// Create new bar with default values
struct bar_config *bar = default_bar_config();
if (!bar) {
@@ -92,18 +85,13 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
}
// set bar id
- for (int i = 0; i < config->bars->length; ++i) {
- if (bar == config->bars->items[i]) {
- const int len = 5 + numlen(i); // "bar-" + i + \0
- bar->id = malloc(len * sizeof(char));
- if (bar->id) {
- snprintf(bar->id, len, "bar-%d", i);
- } else {
- return cmd_results_new(CMD_FAILURE,
- "bar", "Unable to allocate bar ID");
- }
- break;
- }
+ const int len = 5 + numlen(config->bars->length - 1); // "bar-"+i+\0
+ bar->id = malloc(len * sizeof(char));
+ if (bar->id) {
+ snprintf(bar->id, len, "bar-%d", config->bars->length - 1);
+ } else {
+ return cmd_results_new(CMD_FAILURE,
+ "bar", "Unable to allocate bar ID");
}
// Set current bar
@@ -111,5 +99,32 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
wlr_log(WLR_DEBUG, "Creating bar %s", bar->id);
}
- return config_subcommand(argv, argc, bar_handlers, sizeof(bar_handlers));
+ if (find_handler(argv[0], bar_config_handlers,
+ sizeof(bar_config_handlers))) {
+ if (config->reading) {
+ return config_subcommand(argv, argc, bar_config_handlers,
+ sizeof(bar_config_handlers));
+ } else if (spawn) {
+ for (int i = config->bars->length - 1; i >= 0; i--) {
+ struct bar_config *bar = config->bars->items[i];
+ if (bar == config->current_bar) {
+ list_del(config->bars, i);
+ free_bar_config(bar);
+ break;
+ }
+ }
+ }
+ return cmd_results_new(CMD_INVALID, "bar",
+ "Can only be used in the config file.");
+ }
+
+ struct cmd_results *res =
+ config_subcommand(argv, argc, bar_handlers, sizeof(bar_handlers));
+ if (!config->reading) {
+ if (spawn) {
+ load_swaybar(config->current_bar);
+ }
+ config->current_bar = NULL;
+ }
+ return res;
}
diff --git a/sway/commands/bar/hidden_state.c b/sway/commands/bar/hidden_state.c
index 502ce2c4..28adf6c7 100644
--- a/sway/commands/bar/hidden_state.c
+++ b/sway/commands/bar/hidden_state.c
@@ -32,7 +32,7 @@ static struct cmd_results *bar_set_hidden_state(struct bar_config *bar,
}
// free old mode
free(old_state);
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ return NULL;
}
struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
@@ -50,24 +50,20 @@ struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
const char *state = argv[0];
if (config->reading) {
- return bar_set_hidden_state(config->current_bar, state);
- }
-
- const char *id = NULL;
- if (argc == 2) {
- id = argv[1];
- }
- struct bar_config *bar;
- for (int i = 0; i < config->bars->length; ++i) {
- bar = config->bars->items[i];
- if (id && strcmp(id, bar->id) == 0) {
- return bar_set_hidden_state(bar, state);
- }
-
- error = bar_set_hidden_state(bar, state);
- if (error) {
- return error;
+ error = bar_set_hidden_state(config->current_bar, state);
+ } else {
+ const char *id = argc == 2 ? argv[1] : NULL;
+ for (int i = 0; i < config->bars->length; ++i) {
+ struct bar_config *bar = config->bars->items[i];
+ if (id) {
+ if (strcmp(id, bar->id) == 0) {
+ error = bar_set_hidden_state(bar, state);
+ break;
+ }
+ } else if ((error = bar_set_hidden_state(bar, state))) {
+ break;
+ }
}
}
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/bar/id.c b/sway/commands/bar/id.c
index 65fa69fd..7690a852 100644
--- a/sway/commands/bar/id.c
+++ b/sway/commands/bar/id.c
@@ -13,6 +13,8 @@ struct cmd_results *bar_cmd_id(int argc, char **argv) {
const char *oldname = config->current_bar->id;
if (strcmp(name, oldname) == 0) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL); // NOP
+ } else if (strcmp(name, "id") == 0) {
+ return cmd_results_new(CMD_INVALID, "id", "id cannot be 'id'");
}
// check if id is used by a previously defined bar
for (int i = 0; i < config->bars->length; ++i) {
diff --git a/sway/commands/bar/mode.c b/sway/commands/bar/mode.c
index 28e2d77b..dbdd3897 100644
--- a/sway/commands/bar/mode.c
+++ b/sway/commands/bar/mode.c
@@ -33,7 +33,7 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode
// free old mode
free(old_mode);
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ return NULL;
}
struct cmd_results *bar_cmd_mode(int argc, char **argv) {
@@ -51,24 +51,20 @@ struct cmd_results *bar_cmd_mode(int argc, char **argv) {
const char *mode = argv[0];
if (config->reading) {
- return bar_set_mode(config->current_bar, mode);
- }
-
- const char *id = NULL;
- if (argc == 2) {
- id = argv[1];
- }
-
- struct bar_config *bar;
- for (int i = 0; i < config->bars->length; ++i) {
- bar = config->bars->items[i];
- if (id && strcmp(id, bar->id) == 0) {
- return bar_set_mode(bar, mode);
- }
- error = bar_set_mode(bar, mode);
- if (error) {
- return error;
+ error = bar_set_mode(config->current_bar, mode);
+ } else {
+ const char *id = argc == 2 ? argv[1] : NULL;
+ for (int i = 0; i < config->bars->length; ++i) {
+ struct bar_config *bar = config->bars->items[i];
+ if (id) {
+ if (strcmp(id, bar->id) == 0) {
+ error = bar_set_mode(bar, mode);
+ break;
+ }
+ } else if ((error = bar_set_mode(bar, mode))) {
+ break;
+ }
}
}
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/bar/status_command.c b/sway/commands/bar/status_command.c
index 5b4fdc87..490393f1 100644
--- a/sway/commands/bar/status_command.c
+++ b/sway/commands/bar/status_command.c
@@ -25,7 +25,7 @@ struct cmd_results *bar_cmd_status_command(int argc, char **argv) {
}
if (config->active && !config->validating) {
- load_swaybars();
+ load_swaybar(config->current_bar);
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
diff --git a/sway/commands/border.c b/sway/commands/border.c
index bfd3b9ed..cc0d635a 100644
--- a/sway/commands/border.c
+++ b/sway/commands/border.c
@@ -81,7 +81,7 @@ struct cmd_results *cmd_border(int argc, char **argv) {
border_toggle(view);
} else {
return cmd_results_new(CMD_INVALID, "border",
- "Expected 'border <none|normal|pixel|toggle>' "
+ "Expected 'border <none|normal|pixel|csd|toggle>' "
"or 'border pixel <px>'");
}
if (argc == 2) {
diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c
index 2e0876a9..042b415f 100644
--- a/sway/commands/gaps.c
+++ b/sway/commands/gaps.c
@@ -20,31 +20,6 @@ struct gaps_data {
int amount;
};
-// gaps edge_gaps on|off|toggle
-static struct cmd_results *gaps_edge_gaps(int argc, char **argv) {
- struct cmd_results *error;
- if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) {
- return error;
- }
-
- if (strcmp(argv[1], "on") == 0) {
- config->edge_gaps = true;
- } else if (strcmp(argv[1], "off") == 0) {
- config->edge_gaps = false;
- } else if (strcmp(argv[1], "toggle") == 0) {
- if (!config->active) {
- return cmd_results_new(CMD_INVALID, "gaps",
- "Cannot toggle gaps while not running.");
- }
- config->edge_gaps = !config->edge_gaps;
- } else {
- return cmd_results_new(CMD_INVALID, "gaps",
- "gaps edge_gaps on|off|toggle");
- }
- arrange_root();
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
-}
-
// gaps inner|outer <px>
static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2);
@@ -68,15 +43,17 @@ static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
return cmd_results_new(CMD_INVALID, "gaps",
"Expected 'gaps inner|outer <px>'");
}
- if (amount < 0) {
- amount = 0;
- }
-
if (inner) {
- config->gaps_inner = amount;
+ config->gaps_inner = (amount >= 0) ? amount : 0;
} else {
config->gaps_outer = amount;
}
+
+ // Prevent negative outer gaps from moving windows out of the workspace.
+ if (config->gaps_outer < -config->gaps_inner) {
+ config->gaps_outer = -config->gaps_inner;
+ }
+
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
@@ -95,8 +72,12 @@ static void configure_gaps(struct sway_workspace *ws, void *_data) {
*prop -= data->amount;
break;
}
- if (*prop < 0) {
- *prop = 0;
+ // Prevent invalid gaps configurations.
+ if (ws->gaps_inner < 0) {
+ ws->gaps_inner = 0;
+ }
+ if (ws->gaps_outer < -ws->gaps_inner) {
+ ws->gaps_outer = -ws->gaps_inner;
}
arrange_workspace(ws);
}
@@ -156,7 +137,6 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
-// gaps edge_gaps on|off|toggle
// gaps inner|outer <px> - sets defaults for workspaces
// gaps inner|outer current|all set|plus|minus <px> - runtime only
struct cmd_results *cmd_gaps(int argc, char **argv) {
@@ -165,10 +145,6 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
return error;
}
- if (strcmp(argv[0], "edge_gaps") == 0) {
- return gaps_edge_gaps(argc, argv);
- }
-
if (argc == 2) {
return gaps_set_defaults(argc, argv);
}
diff --git a/sway/commands/move.c b/sway/commands/move.c
index fc2f1cc1..24036f36 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -543,7 +543,7 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
if (new_output_last_ws && new_output_last_ws != new_workspace) {
struct sway_node *new_output_last_focus =
seat_get_focus_inactive(seat, &new_output_last_ws->node);
- seat_set_focus_warp(seat, new_output_last_focus, false, false);
+ seat_set_raw_focus(seat, new_output_last_focus);
}
// restore focus
@@ -556,7 +556,7 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
focus = seat_get_focus_inactive(seat, &old_ws->node);
}
}
- seat_set_focus_warp(seat, focus, true, false);
+ seat_set_focus(seat, focus);
// clean-up, destroying parents if the container was the last child
if (old_parent) {
@@ -593,7 +593,7 @@ static void workspace_move_to_output(struct sway_workspace *workspace,
char *ws_name = workspace_next_name(old_output->wlr_output->name);
struct sway_workspace *ws = workspace_create(old_output, ws_name);
free(ws_name);
- seat_set_focus_workspace(seat, ws);
+ seat_set_raw_focus(seat, &ws->node);
}
workspace_consider_destroy(new_output_old_ws);
@@ -704,7 +704,7 @@ static struct cmd_results *cmd_move_in_direction(
}
// Hack to re-focus container
- seat_set_focus_workspace(config->handler_context.seat, new_ws);
+ seat_set_raw_focus(config->handler_context.seat, &new_ws->node);
seat_set_focus_container(config->handler_context.seat, container);
if (old_ws != new_ws) {
diff --git a/sway/commands/sticky.c b/sway/commands/sticky.c
index 7995cdd6..f18322b7 100644
--- a/sway/commands/sticky.c
+++ b/sway/commands/sticky.c
@@ -16,6 +16,11 @@ struct cmd_results *cmd_sticky(int argc, char **argv) {
return error;
}
struct sway_container *container = config->handler_context.container;
+
+ if (container == NULL) {
+ return cmd_results_new(CMD_FAILURE, "sticky", "No current container");
+ };
+
if (!container_is_floating(container)) {
return cmd_results_new(CMD_FAILURE, "sticky",
"Can't set sticky on a tiled container");
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index e7f9cbea..9cc0d5c2 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -22,6 +22,7 @@ static void swap_places(struct sway_container *con1,
temp->width = con1->width;
temp->height = con1->height;
temp->parent = con1->parent;
+ temp->workspace = con1->workspace;
con1->x = con2->x;
con1->y = con2->y;
@@ -34,8 +35,18 @@ static void swap_places(struct sway_container *con1,
con2->height = temp->height;
int temp_index = container_sibling_index(con1);
- container_insert_child(con2->parent, con1, container_sibling_index(con2));
- container_insert_child(temp->parent, con2, temp_index);
+ if (con2->parent) {
+ container_insert_child(con2->parent, con1,
+ container_sibling_index(con2));
+ } else {
+ workspace_insert_tiling(con2->workspace, con1,
+ container_sibling_index(con2));
+ }
+ if (temp->parent) {
+ container_insert_child(temp->parent, con2, temp_index);
+ } else {
+ workspace_insert_tiling(temp->workspace, con2, temp_index);
+ }
free(temp);
}
@@ -50,13 +61,13 @@ static void swap_focus(struct sway_container *con1,
enum sway_container_layout layout2 = container_parent_layout(con2);
if (focus == con1 && (layout2 == L_TABBED || layout2 == L_STACKED)) {
if (workspace_is_visible(ws2)) {
- seat_set_focus_warp(seat, &con2->node, false, true);
+ seat_set_focus_warp(seat, &con2->node, false);
}
seat_set_focus_container(seat, ws1 != ws2 ? con2 : con1);
} else if (focus == con2 && (layout1 == L_TABBED
|| layout1 == L_STACKED)) {
if (workspace_is_visible(ws1)) {
- seat_set_focus_warp(seat, &con1->node, false, true);
+ seat_set_focus_warp(seat, &con1->node, false);
}
seat_set_focus_container(seat, ws1 != ws2 ? con1 : con2);
} else if (ws1 != ws2) {
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index 63f29641..58c2201d 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -1,5 +1,6 @@
#define _XOPEN_SOURCE 500
#include <ctype.h>
+#include <limits.h>
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
@@ -20,8 +21,8 @@ static struct workspace_config *workspace_config_find_or_create(char *ws_name) {
return NULL;
}
wsc->workspace = strdup(ws_name);
- wsc->gaps_inner = -1;
- wsc->gaps_outer = -1;
+ wsc->gaps_inner = INT_MIN;
+ wsc->gaps_outer = INT_MIN;
list_add(config->workspace_configs, wsc);
return wsc;
}
@@ -94,7 +95,16 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "workspace gaps",
"Expected 'workspace <ws> gaps inner|outer <px>'");
}
- *prop = val >= 0 ? val : 0;
+ *prop = val;
+
+ // Prevent invalid gaps configurations.
+ if (wsc->gaps_inner < 0) {
+ wsc->gaps_inner = 0;
+ }
+ if (wsc->gaps_outer < -wsc->gaps_inner) {
+ wsc->gaps_outer = -wsc->gaps_inner;
+ }
+
} else {
if (config->reading || !config->active) {
return cmd_results_new(CMD_DEFER, "workspace", NULL);
@@ -132,7 +142,11 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
strcasecmp(argv[0], "current") == 0) {
ws = workspace_by_name(argv[0]);
} else if (strcasecmp(argv[0], "back_and_forth") == 0) {
- if (!(ws = workspace_by_name(argv[0])) && prev_workspace_name) {
+ if (!prev_workspace_name) {
+ return cmd_results_new(CMD_INVALID, "workspace",
+ "There is no previous workspace");
+ }
+ if (!(ws = workspace_by_name(argv[0]))) {
ws = workspace_create(NULL, prev_workspace_name);
}
} else {