diff options
Diffstat (limited to 'sway')
32 files changed, 644 insertions, 462 deletions
diff --git a/sway/commands.c b/sway/commands.c index bff230f7..72db8ab9 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -110,6 +110,7 @@ static struct cmd_handler handlers[] = { { "seat", cmd_seat }, { "set", cmd_set }, { "show_marks", cmd_show_marks }, + { "smart_borders", cmd_smart_borders }, { "smart_gaps", cmd_smart_gaps }, { "tiling_drag", cmd_tiling_drag }, { "workspace", cmd_workspace }, @@ -391,14 +392,16 @@ struct cmd_results *config_command(char *exec) { // Var replacement, for all but first argument of set // TODO commands for (i = handler->handle == cmd_set ? 2 : 1; i < argc; ++i) { + if (handler->handle != cmd_exec && handler->handle != cmd_exec_always + && handler->handle != cmd_bindsym + && handler->handle != cmd_bindcode + && handler->handle != cmd_set + && (*argv[i] == '\"' || *argv[i] == '\'')) { + strip_quotes(argv[i]); + } argv[i] = do_var_replacement(argv[i]); unescape_string(argv[i]); } - // Strip quotes for first argument. - // TODO This part needs to be handled much better - if (argc>1 && (*argv[1] == '\"' || *argv[1] == '\'')) { - strip_quotes(argv[1]); - } if (handler->handle) { results = handler->handle(argc-1, argv+1); } else { @@ -422,11 +425,6 @@ struct cmd_results *config_subcommand(char **argv, int argc, char *input = argv[0] ? argv[0] : "(empty)"; return cmd_results_new(CMD_INVALID, input, "Unknown/invalid command"); } - // Strip quotes for first argument. - // TODO This part needs to be handled much better - if (argc > 1 && (*argv[1] == '\"' || *argv[1] == '\'')) { - strip_quotes(argv[1]); - } if (handler->handle) { return handler->handle(argc - 1, argv + 1); } diff --git a/sway/commands/bar/binding_mode_indicator.c b/sway/commands/bar/binding_mode_indicator.c index 0c48bee9..f18b8d7c 100644 --- a/sway/commands/bar/binding_mode_indicator.c +++ b/sway/commands/bar/binding_mode_indicator.c @@ -21,7 +21,9 @@ struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) { config->current_bar->binding_mode_indicator = false; wlr_log(WLR_DEBUG, "Disabling binding mode indicator on bar: %s", config->current_bar->id); + } else { + return cmd_results_new(CMD_INVALID, "binding_mode_indicator", + "Invalid value %s", argv[0]); } - return cmd_results_new(CMD_INVALID, "binding_mode_indicator", - "Invalid value %s", argv[0]); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c index d676e475..2e0876a9 100644 --- a/sway/commands/gaps.c +++ b/sway/commands/gaps.c @@ -1,4 +1,5 @@ #include <string.h> +#include <strings.h> #include "sway/commands.h" #include "sway/config.h" #include "sway/tree/arrange.h" @@ -13,172 +14,173 @@ enum gaps_op { GAPS_OP_SUBTRACT }; -enum gaps_scope { - GAPS_SCOPE_ALL, - GAPS_SCOPE_WORKSPACE, - GAPS_SCOPE_CURRENT +struct gaps_data { + bool inner; + enum gaps_op operation; + int amount; }; -struct cmd_results *cmd_gaps(int argc, char **argv) { - struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1); - if (error) { +// 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[0], "edge_gaps") == 0) { - 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 { + 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", - "gaps edge_gaps on|off|toggle"); + "Cannot toggle gaps while not running."); } - arrange_root(); + config->edge_gaps = !config->edge_gaps; } else { - int amount_idx = 0; // the current index in argv - enum gaps_op op = GAPS_OP_SET; - enum gaps_scope scope = GAPS_SCOPE_ALL; - bool inner = true; - - if (strcmp(argv[0], "inner") == 0) { - amount_idx++; - inner = true; - } else if (strcmp(argv[0], "outer") == 0) { - amount_idx++; - inner = false; - } + return cmd_results_new(CMD_INVALID, "gaps", + "gaps edge_gaps on|off|toggle"); + } + arrange_root(); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} - // If one of the long variants of the gaps command is used - // (which starts with inner|outer) check the number of args - if (amount_idx > 0) { // if we've seen inner|outer - if (argc > 2) { // check the longest variant - error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4); - if (error) { - return error; - } - } else { // check the next longest format - error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2); - if (error) { - return error; - } - } - } else { - error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 1); - if (error) { - return error; - } - } +// 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); + if (error) { + return error; + } - if (argc == 4) { - // Long format: all|workspace|current. - if (strcmp(argv[amount_idx], "all") == 0) { - amount_idx++; - scope = GAPS_SCOPE_ALL; - } else if (strcmp(argv[amount_idx], "workspace") == 0) { - amount_idx++; - scope = GAPS_SCOPE_WORKSPACE; - } else if (strcmp(argv[amount_idx], "current") == 0) { - amount_idx++; - scope = GAPS_SCOPE_CURRENT; - } - - // Long format: set|plus|minus - if (strcmp(argv[amount_idx], "set") == 0) { - amount_idx++; - op = GAPS_OP_SET; - } else if (strcmp(argv[amount_idx], "plus") == 0) { - amount_idx++; - op = GAPS_OP_ADD; - } else if (strcmp(argv[amount_idx], "minus") == 0) { - amount_idx++; - op = GAPS_OP_SUBTRACT; - } - } + bool inner; + if (strcasecmp(argv[0], "inner") == 0) { + inner = true; + } else if (strcasecmp(argv[0], "outer") == 0) { + inner = false; + } else { + return cmd_results_new(CMD_INVALID, "gaps", + "Expected 'gaps inner|outer <px>'"); + } - char *end; - double val = strtod(argv[amount_idx], &end); - - if (strlen(end) && val == 0.0) { // invalid <amount> - // guess which variant of the command was attempted - if (argc == 1) { - return cmd_results_new(CMD_INVALID, "gaps", "gaps <amount>"); - } - if (argc == 2) { - return cmd_results_new(CMD_INVALID, "gaps", - "gaps inner|outer <amount>"); - } - return cmd_results_new(CMD_INVALID, "gaps", - "gaps inner|outer all|workspace|current set|plus|minus <amount>"); - } + char *end; + int amount = strtol(argv[1], &end, 10); + if (strlen(end) && strcasecmp(end, "px") != 0) { + return cmd_results_new(CMD_INVALID, "gaps", + "Expected 'gaps inner|outer <px>'"); + } + if (amount < 0) { + amount = 0; + } - if (amount_idx == 0) { // gaps <amount> - config->gaps_inner = val; - config->gaps_outer = val; - arrange_root(); - return cmd_results_new(CMD_SUCCESS, NULL, NULL); - } - // Other variants. The middle-length variant (gaps inner|outer <amount>) - // just defaults the scope to "all" and defaults the op to "set". - - double total; - switch (op) { - case GAPS_OP_SUBTRACT: { - total = (inner ? config->gaps_inner : config->gaps_outer) - val; - if (total < 0) { - total = 0; - } - break; - } - case GAPS_OP_ADD: { - total = (inner ? config->gaps_inner : config->gaps_outer) + val; - break; - } - case GAPS_OP_SET: { - total = val; - break; - } - } + if (inner) { + config->gaps_inner = amount; + } else { + config->gaps_outer = amount; + } + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} - if (scope == GAPS_SCOPE_ALL) { - if (inner) { - config->gaps_inner = total; - } else { - config->gaps_outer = total; - } - arrange_root(); - } else { - if (scope == GAPS_SCOPE_WORKSPACE) { - struct sway_workspace *ws = config->handler_context.workspace; - ws->has_gaps = true; - if (inner) { - ws->gaps_inner = total; - } else { - ws->gaps_outer = total; - } - arrange_workspace(ws); - } else { - struct sway_container *c = config->handler_context.container; - c->has_gaps = true; - if (inner) { - c->gaps_inner = total; - } else { - c->gaps_outer = total; - } - arrange_workspace(c->workspace); - } - } +static void configure_gaps(struct sway_workspace *ws, void *_data) { + struct gaps_data *data = _data; + int *prop = data->inner ? &ws->gaps_inner : &ws->gaps_outer; + + switch (data->operation) { + case GAPS_OP_SET: + *prop = data->amount; + break; + case GAPS_OP_ADD: + *prop += data->amount; + break; + case GAPS_OP_SUBTRACT: + *prop -= data->amount; + break; + } + if (*prop < 0) { + *prop = 0; + } + arrange_workspace(ws); +} + +// gaps inner|outer current|all set|plus|minus <px> +static struct cmd_results *gaps_set_runtime(int argc, char **argv) { + struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4); + if (error) { + return error; + } + + struct gaps_data data; + + if (strcasecmp(argv[0], "inner") == 0) { + data.inner = true; + } else if (strcasecmp(argv[0], "outer") == 0) { + data.inner = false; + } else { + return cmd_results_new(CMD_INVALID, "gaps", + "Expected 'gaps inner|outer current|all set|plus|minus <px>'"); + } + + bool all; + if (strcasecmp(argv[1], "current") == 0) { + all = false; + } else if (strcasecmp(argv[1], "all") == 0) { + all = true; + } else { + return cmd_results_new(CMD_INVALID, "gaps", + "Expected 'gaps inner|outer current|all set|plus|minus <px>'"); + } + + if (strcasecmp(argv[2], "set") == 0) { + data.operation = GAPS_OP_SET; + } else if (strcasecmp(argv[2], "plus") == 0) { + data.operation = GAPS_OP_ADD; + } else if (strcasecmp(argv[2], "minus") == 0) { + data.operation = GAPS_OP_SUBTRACT; + } else { + return cmd_results_new(CMD_INVALID, "gaps", + "Expected 'gaps inner|outer current|all set|plus|minus <px>'"); + } + + char *end; + data.amount = strtol(argv[3], &end, 10); + if (strlen(end) && strcasecmp(end, "px") != 0) { + return cmd_results_new(CMD_INVALID, "gaps", + "Expected 'gaps inner|outer current|all set|plus|minus <px>'"); + } + + if (all) { + root_for_each_workspace(configure_gaps, &data); + } else { + configure_gaps(config->handler_context.workspace, &data); } 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) { + struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2); + if (error) { + return error; + } + + if (strcmp(argv[0], "edge_gaps") == 0) { + return gaps_edge_gaps(argc, argv); + } + + if (argc == 2) { + return gaps_set_defaults(argc, argv); + } + if (argc == 4) { + if (config->active) { + return gaps_set_runtime(argc, argv); + } else { + return cmd_results_new(CMD_INVALID, "gaps", + "This syntax can only be used when sway is running"); + } + } + return cmd_results_new(CMD_INVALID, "gaps", + "Expected 'gaps inner|outer <px>' or " + "'gaps inner|outer current|all set|plus|minus <px>'"); +} diff --git a/sway/commands/hide_edge_borders.c b/sway/commands/hide_edge_borders.c index 0a5c7f28..ea261fb1 100644 --- a/sway/commands/hide_edge_borders.c +++ b/sway/commands/hide_edge_borders.c @@ -1,15 +1,8 @@ #include "sway/commands.h" #include "sway/config.h" -#include "sway/tree/container.h" -#include "sway/tree/root.h" +#include "sway/tree/arrange.h" #include "sway/tree/view.h" -static void _configure_view(struct sway_container *con, void *data) { - if (con->view) { - view_autoconfigure(con->view); - } -} - struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_EQUAL_TO, 1))) { @@ -26,13 +19,16 @@ struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { config->hide_edge_borders = E_BOTH; } else if (strcmp(argv[0], "smart") == 0) { config->hide_edge_borders = E_SMART; + } else if (strcmp(argv[0], "smart_no_gaps") == 0) { + config->hide_edge_borders = E_SMART_NO_GAPS; } else { return cmd_results_new(CMD_INVALID, "hide_edge_borders", "Expected 'hide_edge_borders " - "<none|vertical|horizontal|both|smart>'"); + "<none|vertical|horizontal|both|smart|smart_no_gaps>'"); } + config->saved_edge_borders = config->hide_edge_borders; - root_for_each_container(_configure_view, NULL); + arrange_root(); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/input.c b/sway/commands/input.c index 9091da2a..2889d47d 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -9,6 +9,7 @@ static struct cmd_handler input_handlers[] = { { "accel_profile", input_cmd_accel_profile }, { "click_method", input_cmd_click_method }, + { "drag", input_cmd_drag }, { "drag_lock", input_cmd_drag_lock }, { "dwt", input_cmd_dwt }, { "events", input_cmd_events }, diff --git a/sway/commands/input/drag.c b/sway/commands/input/drag.c new file mode 100644 index 00000000..e325df29 --- /dev/null +++ b/sway/commands/input/drag.c @@ -0,0 +1,26 @@ +#include <string.h> +#include <strings.h> +#include "sway/config.h" +#include "sway/commands.h" +#include "sway/input/input-manager.h" +#include "util.h" + +struct cmd_results *input_cmd_drag(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "drag", EXPECTED_AT_LEAST, 1))) { + return error; + } + struct input_config *ic = config->handler_context.input_config; + if (!ic) { + return cmd_results_new(CMD_FAILURE, + "drag", "No input device defined."); + } + + if (parse_boolean(argv[0], true)) { + ic->drag = LIBINPUT_CONFIG_DRAG_ENABLED; + } else { + ic->drag = LIBINPUT_CONFIG_DRAG_DISABLED; + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/layout.c b/sway/commands/layout.c index ef3ec1cb..c2ce2e78 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -138,15 +138,14 @@ struct cmd_results *cmd_layout(int argc, char **argv) { } container->layout = new_layout; container_update_representation(container); - arrange_container(container); } else { if (old_layout != L_TABBED && old_layout != L_STACKED) { workspace->prev_split_layout = old_layout; } workspace->layout = new_layout; workspace_update_representation(workspace); - arrange_workspace(workspace); } + arrange_workspace(workspace); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 9e370d43..30fb47c4 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c @@ -123,19 +123,13 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { } free(src); } else { - // Escape spaces and quotes in the final path for swaybg + // Escape double quotes in the final path for swaybg for (size_t i = 0; i < strlen(src); i++) { - switch (src[i]) { - case ' ': - case '\'': - case '\"': - src = realloc(src, strlen(src) + 2); - memmove(src + i + 1, src + i, strlen(src + i) + 1); - *(src + i) = '\\'; - i++; - break; - default: - break; + if (src[i] == '"') { + src = realloc(src, strlen(src) + 2); + memmove(src + i + 1, src + i, strlen(src + i) + 1); + *(src + i) = '\\'; + i++; } } diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 99e9dbda..1343b165 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -179,11 +179,11 @@ static void container_recursive_resize(struct sway_container *container, } } -static void resize_tiled(struct sway_container *parent, int amount, +static bool resize_tiled(struct sway_container *parent, int amount, enum resize_axis axis) { struct sway_container *focused = parent; if (!parent) { - return; + return false; } enum sway_container_layout parallel_layout = @@ -216,7 +216,7 @@ static void resize_tiled(struct sway_container *parent, int amount, } if (!parent) { // Can't resize in this direction - return; + return false; } // Implement up/down/left/right direction by zeroing one of the weights, @@ -248,22 +248,22 @@ static void resize_tiled(struct sway_container *parent, int amount, if (sibling_pos < parent_pos && minor_weight) { double pixels = -amount / minor_weight; if (major_weight && (sibling_size + pixels / 2) < min_sane) { - return; // Too small + return false; // Too small } else if (!major_weight && sibling_size + pixels < min_sane) { - return; // Too small + return false; // Too small } } else if (sibling_pos > parent_pos && major_weight) { double pixels = -amount / major_weight; if (minor_weight && (sibling_size + pixels / 2) < min_sane) { - return; // Too small + return false; // Too small } else if (!minor_weight && sibling_size + pixels < min_sane) { - return; // Too small + return false; // Too small } } } else { double pixels = amount; if (parent_size + pixels < min_sane) { - return; // Too small + return false; // Too small } } } @@ -317,9 +317,10 @@ static void resize_tiled(struct sway_container *parent, int amount, } else { arrange_workspace(parent->workspace); } + return true; } -void container_resize_tiled(struct sway_container *parent, +bool container_resize_tiled(struct sway_container *parent, enum wlr_edges edge, int amount) { enum resize_axis axis = RESIZE_AXIS_INVALID; switch (edge) { @@ -338,7 +339,7 @@ void container_resize_tiled(struct sway_container *parent, case WLR_EDGE_NONE: break; } - resize_tiled(parent, amount, axis); + return resize_tiled(parent, amount, axis); } /** @@ -395,6 +396,10 @@ static struct cmd_results *resize_adjust_floating(enum resize_axis axis, case RESIZE_AXIS_INVALID: return cmd_results_new(CMD_INVALID, "resize", "Invalid axis/direction"); } + if (grow_x == 0 && grow_y == 0) { + return cmd_results_new(CMD_INVALID, "resize", + "Cannot resize any further"); + } con->x += grow_x; con->y += grow_y; con->width += grow_width; @@ -442,7 +447,10 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis, } } - resize_tiled(current, amount->amount, axis); + if (!resize_tiled(current, amount->amount, axis)) { + return cmd_results_new(CMD_INVALID, "resize", + "Cannot resize any further"); + } return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/smart_borders.c b/sway/commands/smart_borders.c new file mode 100644 index 00000000..fcb4040e --- /dev/null +++ b/sway/commands/smart_borders.c @@ -0,0 +1,25 @@ +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/tree/arrange.h" +#include "sway/tree/view.h" +#include "util.h" + +struct cmd_results *cmd_smart_borders(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "smart_borders", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + enum edge_border_types saved = config->hide_edge_borders; + if (strcmp(argv[0], "no_gaps") == 0) { + config->hide_edge_borders = E_SMART_NO_GAPS; + } else { + config->hide_edge_borders = parse_boolean(argv[0], true) ? + E_SMART : config->saved_edge_borders; + } + config->saved_edge_borders = saved; + + arrange_root(); + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index f026a39d..63f29641 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c @@ -10,6 +10,28 @@ #include "log.h" #include "stringop.h" +static struct workspace_config *workspace_config_find_or_create(char *ws_name) { + struct workspace_config *wsc = workspace_find_config(ws_name); + if (wsc) { + return wsc; + } + wsc = calloc(1, sizeof(struct workspace_config)); + if (!wsc) { + return NULL; + } + wsc->workspace = strdup(ws_name); + wsc->gaps_inner = -1; + wsc->gaps_outer = -1; + list_add(config->workspace_configs, wsc); + return wsc; +} + +void free_workspace_config(struct workspace_config *wsc) { + free(wsc->workspace); + free(wsc->output); + free(wsc); +} + struct cmd_results *cmd_workspace(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { @@ -17,6 +39,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { } int output_location = -1; + int gaps_location = -1; for (int i = 0; i < argc; ++i) { if (strcasecmp(argv[i], "output") == 0) { @@ -24,25 +47,54 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { break; } } + for (int i = 0; i < argc; ++i) { + if (strcasecmp(argv[i], "gaps") == 0) { + gaps_location = i; + break; + } + } if (output_location >= 0) { if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { return error; } - struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); - if (!wso) { + char *ws_name = join_args(argv, argc - 2); + struct workspace_config *wsc = workspace_config_find_or_create(ws_name); + free(ws_name); + if (!wsc) { return cmd_results_new(CMD_FAILURE, "workspace output", "Unable to allocate workspace output"); } - wso->workspace = join_args(argv, argc - 2); - wso->output = strdup(argv[output_location + 1]); - int i = -1; - if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) { - struct workspace_output *old = config->workspace_outputs->items[i]; - free(old); // workspaces can only be assigned to a single output - list_del(config->workspace_outputs, i); + free(wsc->output); + wsc->output = strdup(argv[output_location + 1]); + } else if (gaps_location >= 0) { + if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, gaps_location + 3))) { + return error; + } + char *ws_name = join_args(argv, argc - 3); + struct workspace_config *wsc = workspace_config_find_or_create(ws_name); + free(ws_name); + if (!wsc) { + return cmd_results_new(CMD_FAILURE, "workspace gaps", + "Unable to allocate workspace output"); + } + int *prop = NULL; + if (strcasecmp(argv[gaps_location + 1], "inner") == 0) { + prop = &wsc->gaps_inner; + } else if (strcasecmp(argv[gaps_location + 1], "outer") == 0) { + prop = &wsc->gaps_outer; + } else { + return cmd_results_new(CMD_FAILURE, "workspace gaps", + "Expected 'workspace <ws> gaps inner|outer <px>'"); + } + char *end; + int val = strtol(argv[gaps_location + 2], &end, 10); + + if (strlen(end)) { + free(end); + return cmd_results_new(CMD_FAILURE, "workspace gaps", + "Expected 'workspace <ws> gaps inner|outer <px>'"); } - wlr_log(WLR_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); - list_add(config->workspace_outputs, wso); + *prop = val >= 0 ? val : 0; } else { if (config->reading || !config->active) { return cmd_results_new(CMD_DEFER, "workspace", NULL); diff --git a/sway/config.c b/sway/config.c index 830fb65f..048b57de 100644 --- a/sway/config.c +++ b/sway/config.c @@ -95,7 +95,12 @@ void free_config(struct sway_config *config) { list_free(config->bars); } list_free(config->cmd_queue); - list_free(config->workspace_outputs); + if (config->workspace_configs) { + for (int i = 0; i < config->workspace_configs->length; i++) { + free_workspace_config(config->workspace_configs->items[i]); + } + list_free(config->workspace_configs); + } if (config->output_configs) { for (int i = 0; i < config->output_configs->length; i++) { free_output_config(config->output_configs->items[i]); @@ -175,7 +180,7 @@ static void config_defaults(struct sway_config *config) { if (!(config->symbols = create_list())) goto cleanup; if (!(config->modes = create_list())) goto cleanup; if (!(config->bars = create_list())) goto cleanup; - if (!(config->workspace_outputs = create_list())) goto cleanup; + if (!(config->workspace_configs = create_list())) goto cleanup; if (!(config->criteria = create_list())) goto cleanup; if (!(config->no_focus = create_list())) goto cleanup; if (!(config->input_configs = create_list())) goto cleanup; @@ -244,6 +249,7 @@ static void config_defaults(struct sway_config *config) { config->border_thickness = 2; config->floating_border_thickness = 2; config->hide_edge_borders = E_NONE; + config->saved_edge_borders = E_NONE; // border colors set_color(config->border_colors.focused.border, 0x4C7899); @@ -804,7 +810,7 @@ char *do_var_replacement(char *str) { // would compare two structs in full, while this method only compares the // workspace. int workspace_output_cmp_workspace(const void *a, const void *b) { - const struct workspace_output *wsa = a, *wsb = b; + const struct workspace_config *wsa = a, *wsb = b; return lenient_strcmp(wsa->workspace, wsb->workspace); } diff --git a/sway/config/input.c b/sway/config/input.c index 6b43a5b9..794d5194 100644 --- a/sway/config/input.c +++ b/sway/config/input.c @@ -20,6 +20,7 @@ struct input_config *new_input_config(const char* identifier) { input->tap = INT_MIN; input->tap_button_map = INT_MIN; + input->drag = INT_MIN; input->drag_lock = INT_MIN; input->dwt = INT_MIN; input->send_events = INT_MIN; @@ -46,6 +47,9 @@ void merge_input_config(struct input_config *dst, struct input_config *src) { if (src->click_method != INT_MIN) { dst->click_method = src->click_method; } + if (src->drag != INT_MIN) { + dst->drag = src->drag; + } if (src->drag_lock != INT_MIN) { dst->drag_lock = src->drag_lock; } diff --git a/sway/config/output.c b/sway/config/output.c index 74d79130..6f337b66 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -237,7 +237,7 @@ void apply_output_config(struct output_config *oc, struct sway_output *output) { wlr_log(WLR_DEBUG, "Setting background for output %d to %s", output_i, oc->background); - size_t len = snprintf(NULL, 0, "%s %d %s %s %s", + size_t len = snprintf(NULL, 0, "%s %d \"%s\" %s %s", config->swaybg_command ? config->swaybg_command : "swaybg", output_i, oc->background, oc->background_option, oc->background_fallback ? oc->background_fallback : ""); @@ -246,7 +246,7 @@ void apply_output_config(struct output_config *oc, struct sway_output *output) { wlr_log(WLR_DEBUG, "Unable to allocate swaybg command"); return; } - snprintf(command, len + 1, "%s %d %s %s %s", + snprintf(command, len + 1, "%s %d \"%s\" %s %s", config->swaybg_command ? config->swaybg_command : "swaybg", output_i, oc->background, oc->background_option, oc->background_fallback ? oc->background_fallback : ""); diff --git a/sway/config/seat.c b/sway/config/seat.c index 83dac4c0..46456caf 100644 --- a/sway/config/seat.c +++ b/sway/config/seat.c @@ -30,7 +30,7 @@ struct seat_config *new_seat_config(const char* name) { return seat; } -struct seat_attachment_config *seat_attachment_config_new() { +struct seat_attachment_config *seat_attachment_config_new(void) { struct seat_attachment_config *attachment = calloc(1, sizeof(struct seat_attachment_config)); if (!attachment) { diff --git a/sway/criteria.c b/sway/criteria.c index 0193233e..575e8bcf 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -339,6 +339,10 @@ static enum criteria_token token_from_name(char *name) { return T_URGENT; } else if (strcmp(name, "workspace") == 0) { return T_WORKSPACE; + } else if (strcmp(name, "tiling") == 0) { + return T_TILING; + } else if (strcmp(name, "floating") == 0) { + return T_FLOATING; } return T_INVALID; } diff --git a/sway/debug-tree.c b/sway/debug-tree.c index 9644f4e5..16b479f9 100644 --- a/sway/debug-tree.c +++ b/sway/debug-tree.c @@ -120,7 +120,7 @@ static int draw_node(cairo_t *cairo, struct sway_node *node, return height; } -void update_debug_tree() { +void update_debug_tree(void) { if (!debug.render_tree) { return; } diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index 4624d824..e717ee35 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -31,14 +31,14 @@ struct sway_transaction_instruction { struct sway_transaction *transaction; struct sway_node *node; union { - struct sway_output_state *output_state; - struct sway_workspace_state *workspace_state; - struct sway_container_state *container_state; + struct sway_output_state output_state; + struct sway_workspace_state workspace_state; + struct sway_container_state container_state; }; uint32_t serial; }; -static struct sway_transaction *transaction_create() { +static struct sway_transaction *transaction_create(void) { struct sway_transaction *transaction = calloc(1, sizeof(struct sway_transaction)); if (!sway_assert(transaction, "Unable to allocate transaction")) { @@ -86,14 +86,7 @@ static void transaction_destroy(struct sway_transaction *transaction) { static void copy_output_state(struct sway_output *output, struct sway_transaction_instruction *instruction) { - struct sway_output_state *state = - calloc(1, sizeof(struct sway_output_state)); - if (!state) { - wlr_log(WLR_ERROR, "Could not allocate output state"); - return; - } - instruction->output_state = state; - + struct sway_output_state *state = &instruction->output_state; state->workspaces = create_list(); list_cat(state->workspaces, output->workspaces); @@ -102,13 +95,7 @@ static void copy_output_state(struct sway_output *output, static void copy_workspace_state(struct sway_workspace *ws, struct sway_transaction_instruction *instruction) { - struct sway_workspace_state *state = - calloc(1, sizeof(struct sway_workspace_state)); - if (!state) { - wlr_log(WLR_ERROR, "Could not allocate workspace state"); - return; - } - instruction->workspace_state = state; + struct sway_workspace_state *state = &instruction->workspace_state; state->fullscreen = ws->fullscreen; state->x = ws->x; @@ -138,13 +125,7 @@ static void copy_workspace_state(struct sway_workspace *ws, static void copy_container_state(struct sway_container *container, struct sway_transaction_instruction *instruction) { - struct sway_container_state *state = - calloc(1, sizeof(struct sway_container_state)); - if (!state) { - wlr_log(WLR_ERROR, "Could not allocate container state"); - return; - } - instruction->container_state = state; + struct sway_container_state *state = &instruction->container_state; state->layout = container->layout; state->con_x = container->x; @@ -300,15 +281,15 @@ static void transaction_apply(struct sway_transaction *transaction) { case N_ROOT: break; case N_OUTPUT: - apply_output_state(node->sway_output, instruction->output_state); + apply_output_state(node->sway_output, &instruction->output_state); break; case N_WORKSPACE: apply_workspace_state(node->sway_workspace, - instruction->workspace_state); + &instruction->workspace_state); break; case N_CONTAINER: apply_container_state(node->sway_container, - instruction->container_state); + &instruction->container_state); break; } @@ -334,7 +315,7 @@ static bool transaction_same_nodes(struct sway_transaction *a, return true; } -static void transaction_progress_queue() { +static void transaction_progress_queue(void) { if (!server.transactions->length) { return; } @@ -389,7 +370,7 @@ static bool should_configure(struct sway_node *node, return false; } struct sway_container_state *cstate = &node->sway_container->current; - struct sway_container_state *istate = instruction->container_state; + struct sway_container_state *istate = &instruction->container_state; #ifdef HAVE_XWAYLAND // Xwayland views are position-aware and need to be reconfigured // when their position changes. @@ -417,10 +398,10 @@ static void transaction_commit(struct sway_transaction *transaction) { struct sway_node *node = instruction->node; if (should_configure(node, instruction)) { instruction->serial = view_configure(node->sway_container->view, - instruction->container_state->view_x, - instruction->container_state->view_y, - instruction->container_state->view_width, - instruction->container_state->view_height); + instruction->container_state.view_x, + instruction->container_state.view_y, + instruction->container_state.view_width, + instruction->container_state.view_height); ++transaction->num_waiting; // From here on we are rendering a saved buffer of the view, which @@ -512,8 +493,8 @@ void transaction_notify_view_ready_by_size(struct sway_view *view, int width, int height) { struct sway_transaction_instruction *instruction = view->container->node.instruction; - if (instruction->container_state->view_width == width && - instruction->container_state->view_height == height) { + if (instruction->container_state.view_width == width && + instruction->container_state.view_height == height) { set_instruction_ready(instruction); } } diff --git a/sway/input/cursor.c b/sway/input/cursor.c index eab102fd..afad6f6f 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -30,7 +30,7 @@ // when dragging to the edge of a layout container. #define DROP_LAYOUT_BORDER 30 -static uint32_t get_current_time_msec() { +static uint32_t get_current_time_msec(void) { struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); return now.tv_nsec / 1000; @@ -1007,8 +1007,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { if (seat_is_input_allowed(seat, surface)) { wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec, event->touch_id, sx, sy); - cursor->image_client = NULL; - wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); + cursor_set_image(cursor, NULL, NULL); } } @@ -1176,11 +1175,13 @@ static void handle_request_set_cursor(struct wl_listener *listener, void cursor_set_image(struct sway_cursor *cursor, const char *image, struct wl_client *client) { - if (!cursor->image || strcmp(cursor->image, image) != 0) { + if (!image) { + wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); + } else if (!cursor->image || strcmp(cursor->image, image) != 0) { wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, image, cursor->cursor); - cursor->image = image; } + cursor->image = image; cursor->image_client = client; } diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index f39fe29c..32f0355e 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -120,6 +120,13 @@ static void input_manager_libinput_config_pointer( libinput_device_config_click_set_method(libinput_device, ic->click_method); } + if (ic->drag != INT_MIN) { + wlr_log(WLR_DEBUG, + "libinput_config_pointer(%s) tap_set_drag_enabled(%d)", + ic->identifier, ic->click_method); + libinput_device_config_tap_set_drag_enabled(libinput_device, + ic->drag); + } if (ic->drag_lock != INT_MIN) { wlr_log(WLR_DEBUG, "libinput_config_pointer(%s) tap_set_drag_lock_enabled(%d)", diff --git a/sway/input/seat.c b/sway/input/seat.c index a9c564e7..e10b6409 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -144,32 +144,43 @@ static void handle_seat_node_destroy(struct wl_listener *listener, void *data) { struct sway_node *parent = node_get_parent(node); struct sway_node *focus = seat_get_focus(seat); - bool set_focus = - focus != NULL && - (focus == node || node_has_ancestor(focus, node)) && - node->type == N_CONTAINER; + if (node->type == N_WORKSPACE) { + seat_node_destroy(seat_node); + return; + } + + // Even though the container being destroyed might be nowhere near the + // focused container, we still need to set focus_inactive on a sibling of + // the container being destroyed. + bool needs_new_focus = focus && + (focus == node || node_has_ancestor(focus, node)); seat_node_destroy(seat_node); - if (set_focus) { - struct sway_node *next_focus = NULL; - while (next_focus == NULL) { - struct sway_container *con = - seat_get_focus_inactive_view(seat, parent); - next_focus = con ? &con->node : NULL; + // Find new focus_inactive (ie. sibling, or workspace if no siblings left) + struct sway_node *next_focus = NULL; + while (next_focus == NULL) { + struct sway_container *con = + seat_get_focus_inactive_view(seat, parent); + next_focus = con ? &con->node : NULL; - if (next_focus == NULL && parent->type == N_WORKSPACE) { - next_focus = parent; - break; - } - - parent = node_get_parent(parent); + if (next_focus == NULL && parent->type == N_WORKSPACE) { + next_focus = parent; + break; } - // the structure change might have caused it to move up to the top of + parent = node_get_parent(parent); + } + + if (needs_new_focus) { + // The structure change might have caused it to move up to the top of // the focus stack without sending focus notifications to the view seat_send_focus(next_focus, seat); seat_set_focus(seat, next_focus); + } else { + // Setting focus_inactive + seat_set_focus_warp(seat, next_focus, false, false); + seat_set_focus_warp(seat, focus, false, false); } } @@ -368,11 +379,20 @@ static void seat_update_capabilities(struct sway_seat *seat) { caps |= WL_SEAT_CAPABILITY_TOUCH; break; case WLR_INPUT_DEVICE_TABLET_TOOL: + caps |= WL_SEAT_CAPABILITY_POINTER; + break; case WLR_INPUT_DEVICE_TABLET_PAD: break; } } wlr_seat_set_capabilities(seat->wlr_seat, caps); + + // Hide cursor if seat doesn't have pointer capability + if ((caps & WL_SEAT_CAPABILITY_POINTER) == 0) { + cursor_set_image(seat->cursor, NULL, NULL); + } else { + cursor_set_image(seat->cursor, "left_ptr", NULL); + } } static void seat_apply_input_config(struct sway_seat *seat, @@ -552,8 +572,7 @@ void seat_configure_xcursor(struct sway_seat *seat) { output->name, (double)output->scale); } - wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, - "left_ptr", seat->cursor->cursor); + cursor_set_image(seat->cursor, "left_ptr", NULL); wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, seat->cursor->cursor->y); } @@ -752,6 +771,12 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, seat->has_focus = true; + if (config->smart_gaps) { + // When smart gaps is on, gaps may change when the focus changes so + // the workspace needs to be arranged + arrange_workspace(new_workspace); + } + update_debug_tree(); } diff --git a/sway/ipc-json.c b/sway/ipc-json.c index df24b812..bc36f9b1 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -42,7 +42,7 @@ static const char *ipc_json_orientation_description(enum sway_container_layout l return "none"; } -json_object *ipc_json_get_version() { +json_object *ipc_json_get_version(void) { int major = 0, minor = 0, patch = 0; json_object *version = json_object_new_object(); diff --git a/sway/main.c b/sway/main.c index 990f5f3a..dea4a31c 100644 --- a/sway/main.c +++ b/sway/main.c @@ -12,10 +12,6 @@ #include <sys/wait.h> #include <sys/un.h> #include <unistd.h> -#ifdef __linux__ -#include <sys/capability.h> -#include <sys/prctl.h> -#endif #include <wlr/util/log.h> #include "sway/commands.h" #include "sway/config.h" @@ -45,7 +41,7 @@ void sig_handler(int signal) { sway_terminate(EXIT_SUCCESS); } -void detect_raspi() { +void detect_raspi(void) { bool raspi = false; FILE *f = fopen("/sys/firmware/devicetree/base/model", "r"); if (!f) { @@ -85,7 +81,7 @@ void detect_raspi() { } } -void detect_proprietary() { +void detect_proprietary(void) { FILE *f = fopen("/proc/modules", "r"); if (!f) { return; @@ -120,7 +116,7 @@ void run_as_ipc_client(char *command, char *socket_path) { close(socketfd); } -static void log_env() { +static void log_env(void) { const char *log_vars[] = { "PATH", "LD_LIBRARY_PATH", @@ -135,7 +131,7 @@ static void log_env() { } } -static void log_distro() { +static void log_distro(void) { const char *paths[] = { "/etc/lsb-release", "/etc/os-release", @@ -162,7 +158,7 @@ static void log_distro() { } } -static void log_kernel() { +static void log_kernel(void) { FILE *f = popen("uname -a", "r"); if (!f) { wlr_log(WLR_INFO, "Unable to determine kernel version"); @@ -181,28 +177,8 @@ static void log_kernel() { pclose(f); } -static void executable_sanity_check() { -#ifdef __linux__ - struct stat sb; - char *exe = realpath("/proc/self/exe", NULL); - stat(exe, &sb); - // We assume that cap_get_file returning NULL implies ENODATA - if (sb.st_mode & (S_ISUID|S_ISGID) && cap_get_file(exe)) { - wlr_log(WLR_ERROR, - "sway executable has both the s(g)uid bit AND file caps set."); - wlr_log(WLR_ERROR, - "This is strongly discouraged (and completely broken)."); - wlr_log(WLR_ERROR, - "Please clear one of them (either the suid bit, or the file caps)."); - wlr_log(WLR_ERROR, - "If unsure, strip the file caps."); - exit(EXIT_FAILURE); - } - free(exe); -#endif -} -static void drop_permissions(bool keep_caps) { +static void drop_permissions(void) { if (getuid() != geteuid() || getgid() != getegid()) { if (setgid(getgid()) != 0) { wlr_log(WLR_ERROR, "Unable to drop root"); @@ -217,20 +193,6 @@ static void drop_permissions(bool keep_caps) { wlr_log(WLR_ERROR, "Root privileges can be restored."); exit(EXIT_FAILURE); } -#ifdef __linux__ - if (keep_caps) { - // Drop every cap except CAP_SYS_PTRACE - cap_t caps = cap_init(); - cap_value_t keep = CAP_SYS_PTRACE; - wlr_log(WLR_INFO, "Dropping extra capabilities"); - if (cap_set_flag(caps, CAP_PERMITTED, 1, &keep, CAP_SET) || - cap_set_flag(caps, CAP_EFFECTIVE, 1, &keep, CAP_SET) || - cap_set_proc(caps)) { - wlr_log(WLR_ERROR, "Failed to drop extra capabilities"); - exit(EXIT_FAILURE); - } - } -#endif } void enable_debug_flag(const char *flag) { @@ -279,14 +241,6 @@ int main(int argc, char **argv) { " --get-socketpath Gets the IPC socket path and prints it, then exits.\n" "\n"; - // Security: - unsetenv("LD_PRELOAD"); -#ifdef _LD_LIBRARY_PATH - setenv("LD_LIBRARY_PATH", _LD_LIBRARY_PATH, 1); -#else - unsetenv("LD_LIBRARY_PATH"); -#endif - int c; while (1) { int option_index = 0; @@ -347,7 +301,7 @@ int main(int argc, char **argv) { wlr_log(WLR_ERROR, "Don't use options with the IPC client"); exit(EXIT_FAILURE); } - drop_permissions(false); + drop_permissions(); char *socket_path = getenv("SWAYSOCK"); if (!socket_path) { wlr_log(WLR_ERROR, "Unable to retrieve socket path"); @@ -358,34 +312,17 @@ int main(int argc, char **argv) { return 0; } - executable_sanity_check(); - bool suid = false; - if (!server_privileged_prepare(&server)) { return 1; } -#if defined(__linux__) || defined(__FreeBSD__) - if (getuid() != geteuid() || getgid() != getegid()) { -#ifdef __linux__ - // Retain capabilities after setuid() - if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) { - wlr_log(WLR_ERROR, "Cannot keep caps after setuid()"); - exit(EXIT_FAILURE); - } -#endif - suid = true; - } -#endif - log_kernel(); log_distro(); detect_proprietary(); detect_raspi(); -#if defined(__linux__) || defined(__FreeBSD__) - drop_permissions(suid); -#endif + drop_permissions(); + // handle SIGTERM signals signal(SIGTERM, sig_handler); diff --git a/sway/meson.build b/sway/meson.build index 2a3c5b5e..00ebcb40 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -79,6 +79,7 @@ sway_sources = files( 'commands/seat/fallback.c', 'commands/set.c', 'commands/show_marks.c', + 'commands/smart_borders.c', 'commands/smart_gaps.c', 'commands/split.c', 'commands/sticky.c', @@ -120,6 +121,7 @@ sway_sources = files( 'commands/input/accel_profile.c', 'commands/input/click_method.c', + 'commands/input/drag.c', 'commands/input/drag_lock.c', 'commands/input/dwt.c', 'commands/input/events.c', @@ -165,7 +167,6 @@ sway_deps = [ cairo, gdk_pixbuf, jsonc, - libcap, libinput, math, pango, @@ -188,5 +189,6 @@ executable( include_directories: [sway_inc], dependencies: sway_deps, link_with: [lib_sway_common], + install_rpath : rpathdir, install: true ) diff --git a/sway/sway-bar.5.scd b/sway/sway-bar.5.scd index a61e2829..00b9386e 100644 --- a/sway/sway-bar.5.scd +++ b/sway/sway-bar.5.scd @@ -6,8 +6,7 @@ sway-bar - bar configuration file and commands # DESCRIPTION -Sway allows configuring swaybar in the sway configuration file. Swaybar -commands must be used inside a _bar { }_ block in the config file. +Sway allows configuring swaybar in the sway configuration file. # COMMANDS diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index 707c36af..14f2a007 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd @@ -7,7 +7,6 @@ sway-input - input configuration file and commands # DESCRIPTION Sway allows for configuration of devices within the sway configuration file. -sway-input commands must be used inside an _input { }_ block in the config. To obtain a list of available device identifiers, run *swaymsg -t get\_inputs*. # INPUT COMMANDS @@ -68,6 +67,9 @@ The following commands may only be used in the configuration file. *input* <identifier> click\_method none|button\_areas|clickfinger Changes the click method for the specified device. +*input* <identifier> drag enabled|disabled + Enables or disables tap-and-drag for specified input device. + *input* <identifier> drag\_lock enabled|disabled Enables or disables drag lock for specified input device. @@ -116,8 +118,7 @@ The following commands may only be used in the configuration file. ## SEAT CONFIGURATION -Configure options for multiseat mode. sway-seat commands must be used inside a -_seat { }_ block in the config. +Configure options for multiseat mode. A *seat* is a collection of input devices that act independently of each other. Seats are identified by name and the default seat is _seat0_ if no seats are diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 927bf55c..3202d517 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -19,6 +19,24 @@ bindsym Shift+XF86AudioRaiseVolume exec \\ pactl set-sink-volume @DEFAULT_SINK@ -1% ``` +Commands can also be given as a block in the form *command { <subcommands...> +}*. Anything before the opening *{* will be prepended to the lines inside the +block. For example: + +``` +output eDP-1 { + background ~/wallpaper.png + resolution 1920x1080 +} +``` + +is identical to + +``` +output eDP-1 background ~/wallpaper.png +output eDP-1 resolution 1920x1080 +``` + These commands can be executed in your config file, via *swaymsg*(1), or via the bindsym command. @@ -37,10 +55,8 @@ which you may only select one. *[...]* is used for optional arguments, and The following commands may only be used in the configuration file. -*bar {* <commands...> *}* - _commands..._ after *{* will be interpreted as bar commands. For - details, see *sway-bar*(5). A newline is required between *{* and the - first command, and *}* must be alone on a line. +*bar* [<bar-id>] <bar-subcommands...> + For details on bar subcommands, see *sway-bar*(5). *default\_orientation* horizontal|vertical|auto Sets the default container layout for tiled containers. @@ -51,10 +67,6 @@ The following commands may only be used in the configuration file. *wordexp*(3) for details). The same include file can only be included once; subsequent attempts will be ignored. -*set* $<name> <value> - Sets variable $_name_ to _value_. You can use the new variable in the - arguments of future commands. - *swaybg\_command* <command> Executes custom background _command_. Default is _swaybg_. Refer to *output* below for more information. @@ -407,37 +419,30 @@ The default colors are: inner gap is nonzero. When _off_, gaps will only be added between views. _toggle_ cannot be used in the configuration file. -*gaps* <amount> - Sets _amount_ pixels of gap between windows and around each workspace. - *gaps* inner|outer <amount> - Sets default _amount_ pixels of _inner_ or _outer_ gap, where the former - affects spacing between views and the latter affects the space around each - workspace. + Sets default _amount_ pixels of _inner_ or _outer_ gap, where the inner + affects spacing around each view and outer affects the spacing around each + workspace. Outer gaps are in addition to inner gaps. -*gaps* inner|outer all|workspace|current set|plus|minus <amount> - Changes the gaps for the _inner_ or _outer_ gap. _all_ changes the gaps for - all views or workspace, _workspace_ changes gaps for all views in current - workspace (or current workspace), and _current_ changes gaps for the current - view or workspace. + This affects new workspaces only, and is used when the workspace doesn't + have its own gaps settings (see: workspace <ws> gaps inner|outer <amount>). -*hide\_edge\_borders* none|vertical|horizontal|both|smart +*gaps* inner|outer all|current set|plus|minus <amount> + Changes the _inner_ or _outer_ gaps for either _all_ workspaces or the + _current_ workspace. + +*hide\_edge\_borders* none|vertical|horizontal|both|smart|smart\_no\_gaps Hides window borders adjacent to the screen edges. Default is _none_. -*input* <input\_device> *{* <commands...> *}* - _commands..._ after *{* will be interpreted as input commands applying to - the specified input device. For details, see *sway-input*(5). A newline is - required between *{* and the first command, and *}* must be alone on a - line. +*input* <input\_device> <input-subcommands...> + For details on input subcommands, see *sway-input*(5). \* may be used in lieu of a specific device name to configure all input devices. A list of input device names may be obtained via *swaymsg -t get\_inputs*. -*seat* <seat> *{* <commands...> *}* - _commands..._ after *{* will be interpreted as seat commands applying to - the specified seat. For details, see *sway-input*(5). A newline is required - between *{* and the first command, and *}* must be alone on a line. +*seat* <seat> <seat-subcommands...> + For details on seat subcommands, see *sway-input*(5). *seat* <seat> cursor move|set <x> <y> Move specified seat's cursor relative to current position or wrap to @@ -451,6 +456,12 @@ The default colors are: *kill* Kills (closes) the currently focused container and all of its children. +*smart\_borders* on|no\_gaps|off + If smart\_borders are _on_, borders will only be enabled if the workspace + only has one visible child (identical to _hide\_edge\_borders_ smart). If + smart\_borders is set to _no\_gaps_, borders will only be enabled if the + workspace only has one visible child and gaps greater than zero. + *smart\_gaps* on|off If smart\_gaps are _on_ gaps will only be enabled if a workspace has more than one child. @@ -465,10 +476,8 @@ The default colors are: *mode* <mode> Switches to the specified mode. The default mode _default_. -*mode* [--pango\_markup] <mode> *{* <commands...> *}* - _commands..._ after *{* will be added to the specified mode. A newline is - required between *{* and the first command, and *}* must be alone on a - line. Only *bindsym* and *bindcode* commands are permitted in mode blocks. +*mode* [--pango\_markup] <mode> <mode-subcommands...> + The only two valid _mode-subcommands..._ are *bindsym* and *bindcode*. If _--pango\_markup_ is given, then _mode_ will be interpreted as pango markup. @@ -533,8 +542,15 @@ You may combine output commands into one, like so: output HDMI-A-1 mode 1920x1080 pos 1920,0 bg ~/wallpaper.png stretch You can get a list of output names with *swaymsg -t get\_outputs*. You may also -match any output by using the output name "\*". Be sure to add this output -config after the others, or it will be matched instead of the others. +match any output by using the output name "\*". + +*set* $<name> <value> + Sets variable $_name_ to _value_. You can use the new variable in the + arguments of future commands. When the variable is used, it can be escaped + with an additional $ (ie $$_name_) to have the replacement happen at run + time instead of when reading the config. However, it does not always make + sense for the variable to be replaced at run time since some arguments do + need to be known at config time. *show\_marks* yes|no If *show\_marks* is yes, marks will be displayed in the window borders. @@ -568,6 +584,10 @@ config after the others, or it will be matched instead of the others. *workspace* back_and_forth Switches to the previously focused workspace. +*workspace* <name> gaps inner|outer <amount> + Specifies that workspace _name_ should have the given gaps settings when it + is created. + *workspace* <name> output <output> Specifies that workspace _name_ should be shown on the specified _output_. diff --git a/sway/tree/container.c b/sway/tree/container.c index 9b671c1d..a069b177 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -593,7 +593,7 @@ void container_update_representation(struct sway_container *con) { } } -size_t container_titlebar_height() { +size_t container_titlebar_height(void) { return config->font_height + TITLEBAR_V_PADDING * 2; } @@ -829,9 +829,16 @@ void container_floating_move_to_center(struct sway_container *con) { return; } struct sway_workspace *ws = con->workspace; + bool full = con->is_fullscreen; + if (full) { + container_set_fullscreen(con, false); + } double new_lx = ws->x + (ws->width - con->width) / 2; double new_ly = ws->y + (ws->height - con->height) / 2; container_floating_translate(con, new_lx - con->x, new_ly - con->y); + if (full) { + container_set_fullscreen(con, true); + } } static bool find_urgent_iterator(struct sway_container *con, void *data) { @@ -1020,15 +1027,33 @@ void container_add_gaps(struct sway_container *c) { if (!c->view && c->layout != L_TABBED && c->layout != L_STACKED) { return; } - // Children of tabbed/stacked containers re-use the gaps of the container - enum sway_container_layout layout = container_parent_layout(c); - if (layout == L_TABBED || layout == L_STACKED) { - return; + // Descendants of tabbed/stacked containers re-use the gaps of the container + struct sway_container *temp = c; + while (temp) { + enum sway_container_layout layout = container_parent_layout(temp); + if (layout == L_TABBED || layout == L_STACKED) { + return; + } + temp = temp->parent; + } + // If smart gaps is on, don't add gaps if there is only one view visible + if (config->smart_gaps) { + struct sway_view *view = c->view; + if (!view) { + struct sway_seat *seat = + input_manager_get_default_seat(input_manager); + struct sway_container *focus = + seat_get_focus_inactive_view(seat, &c->node); + view = focus ? focus->view : NULL; + } + if (view && view_is_only_visible(view)) { + return; + } } struct sway_workspace *ws = c->workspace; - c->current_gaps = ws->has_gaps ? ws->gaps_inner : config->gaps_inner; + c->current_gaps = ws->gaps_inner; c->x += c->current_gaps; c->y += c->current_gaps; c->width -= 2 * c->current_gaps; diff --git a/sway/tree/output.c b/sway/tree/output.c index 06933dc4..c3176325 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -113,6 +113,20 @@ void output_enable(struct sway_output *output, struct output_config *oc) { arrange_root(); } +static void evacuate_sticky(struct sway_workspace *old_ws, + struct sway_output *new_output) { + struct sway_workspace *new_ws = output_get_active_workspace(new_output); + while (old_ws->floating->length) { + struct sway_container *sticky = old_ws->floating->items[0]; + container_detach(sticky); + workspace_add_floating(new_ws, sticky); + container_handle_fullscreen_reparent(sticky); + container_floating_move_to_center(sticky); + ipc_event_window(sticky, "move"); + } + workspace_detect_urgent(new_ws); +} + static void output_evacuate(struct sway_output *output) { if (!output->workspaces->length) { return; @@ -130,17 +144,21 @@ static void output_evacuate(struct sway_output *output) { workspace_detach(workspace); - if (workspace_is_empty(workspace)) { - workspace_begin_destroy(workspace); - continue; - } - struct sway_output *new_output = workspace_output_get_highest_available(workspace, output); if (!new_output) { new_output = fallback_output; } + if (workspace_is_empty(workspace)) { + // If floating is not empty, there are sticky containers to move + if (workspace->floating->length) { + evacuate_sticky(workspace, new_output); + } + workspace_begin_destroy(workspace); + continue; + } + if (new_output) { workspace_output_add_priority(workspace, new_output); output_add_workspace(new_output, workspace); diff --git a/sway/tree/root.c b/sway/tree/root.c index d6f67bd7..6748e9c9 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c @@ -273,6 +273,12 @@ void root_for_each_container(void (*f)(struct sway_container *con, void *data), container_for_each_child(container, f, data); } } + + // Saved workspaces + for (int i = 0; i < root->saved_workspaces->length; ++i) { + struct sway_workspace *ws = root->saved_workspaces->items[i]; + workspace_for_each_container(ws, f, data); + } } struct sway_output *root_find_output( @@ -320,6 +326,15 @@ struct sway_container *root_find_container( } } } + + // Saved workspaces + for (int i = 0; i < root->saved_workspaces->length; ++i) { + struct sway_workspace *ws = root->saved_workspaces->items[i]; + if ((result = workspace_find_container(ws, test, data))) { + return result; + } + } + return NULL; } diff --git a/sway/tree/view.c b/sway/tree/view.c index 9ffcf206..9c7c44e9 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -165,6 +165,34 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, return 0; } +bool view_is_only_visible(struct sway_view *view) { + bool only_view = true; + struct sway_container *con = view->container; + while (con) { + enum sway_container_layout layout = container_parent_layout(con); + if (layout != L_TABBED && layout != L_STACKED) { + list_t *siblings = container_get_siblings(con); + if (siblings && siblings->length > 1) { + only_view = false; + break; + } + } + con = con->parent; + } + return only_view; +} + +static bool gaps_to_edge(struct sway_view *view) { + struct sway_container *con = view->container; + while (con) { + if (con->current_gaps > 0) { + return true; + } + con = con->parent; + } + return view->container->workspace->current_gaps > 0; +} + void view_autoconfigure(struct sway_view *view) { if (!view->container->workspace) { // Hidden in the scratchpad @@ -181,39 +209,28 @@ void view_autoconfigure(struct sway_view *view) { } struct sway_workspace *ws = view->container->workspace; - - bool other_views = false; - if (config->hide_edge_borders == E_SMART) { - struct sway_container *con = view->container; - while (con) { - enum sway_container_layout layout = container_parent_layout(con); - if (layout != L_TABBED && layout != L_STACKED) { - list_t *siblings = container_get_siblings(con); - if (siblings && siblings->length > 1) { - other_views = true; - break; - } - } - con = con->parent; - } - } - struct sway_container *con = view->container; + bool smart = config->hide_edge_borders == E_SMART || + config->hide_edge_borders == E_SMART_NO_GAPS; + bool other_views = smart && !view_is_only_visible(view); + bool no_gaps = config->hide_edge_borders != E_SMART_NO_GAPS + || !gaps_to_edge(view); + view->border_top = view->border_bottom = true; view->border_left = view->border_right = true; if (config->hide_edge_borders == E_BOTH || config->hide_edge_borders == E_VERTICAL - || (config->hide_edge_borders == E_SMART && !other_views)) { - view->border_left = con->x != ws->x; - int right_x = con->x + con->width; + || (smart && !other_views && no_gaps)) { + view->border_left = con->x - con->current_gaps != ws->x; + int right_x = con->x + con->width + con->current_gaps; view->border_right = right_x != ws->x + ws->width; } if (config->hide_edge_borders == E_BOTH || config->hide_edge_borders == E_HORIZONTAL - || (config->hide_edge_borders == E_SMART && !other_views)) { - view->border_top = con->y != ws->y; - int bottom_y = con->y + con->height; + || (smart && !other_views && no_gaps)) { + view->border_top = con->y - con->current_gaps != ws->y; + int bottom_y = con->y + con->height + con->current_gaps; view->border_bottom = bottom_y != ws->y + ws->height; } @@ -1004,12 +1021,16 @@ bool view_is_visible(struct sway_view *view) { floater = floater->parent; } bool is_sticky = container_is_floating(floater) && floater->is_sticky; + if (!is_sticky && !workspace_is_visible(workspace)) { + return false; + } // Check view isn't in a tabbed or stacked container on an inactive tab struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *con = view->container; while (con) { enum sway_container_layout layout = container_parent_layout(con); - if (layout == L_TABBED || layout == L_STACKED) { + if ((layout == L_TABBED || layout == L_STACKED) + && !container_is_floating(con)) { struct sway_node *parent = con->parent ? &con->parent->node : &con->workspace->node; if (seat_get_active_tiling_child(seat, parent) != &con->node) { @@ -1023,10 +1044,6 @@ bool view_is_visible(struct sway_view *view) { !container_is_fullscreen_or_child(view->container)) { return false; } - // Check the workspace is visible - if (!is_sticky) { - return workspace_is_visible(workspace); - } return true; } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 16031e87..e9e5dfa2 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -20,17 +20,23 @@ #include "log.h" #include "util.h" +struct workspace_config *workspace_find_config(const char *ws_name) { + for (int i = 0; i < config->workspace_configs->length; ++i) { + struct workspace_config *wsc = config->workspace_configs->items[i]; + if (strcmp(wsc->workspace, ws_name) == 0) { + return wsc; + } + } + return NULL; +} + struct sway_output *workspace_get_initial_output(const char *name) { - // Search for workspace<->output pair - for (int i = 0; i < config->workspace_outputs->length; ++i) { - struct workspace_output *wso = config->workspace_outputs->items[i]; - if (strcasecmp(wso->workspace, name) == 0) { - // Find output to use if it exists - struct sway_output *output = output_by_name(wso->output); - if (output) { - return output; - } - break; + // Check workspace configs for a workspace<->output pair + struct workspace_config *wsc = workspace_find_config(name); + if (wsc && wsc->output) { + struct sway_output *output = output_by_name(wsc->output); + if (output) { + return output; } } // Otherwise put it on the focused output @@ -62,6 +68,20 @@ struct sway_workspace *workspace_create(struct sway_output *output, ws->output_priority = create_list(); workspace_output_add_priority(ws, output); + ws->gaps_outer = config->gaps_outer; + ws->gaps_inner = config->gaps_inner; + if (name) { + struct workspace_config *wsc = workspace_find_config(name); + if (wsc) { + if (wsc->gaps_outer != -1) { + ws->gaps_outer = wsc->gaps_outer; + } + if (wsc->gaps_inner != -1) { + ws->gaps_inner = wsc->gaps_inner; + } + } + } + output_add_workspace(output, ws); output_sort_workspaces(output); @@ -121,17 +141,8 @@ void next_name_map(struct sway_container *ws, void *data) { static bool workspace_valid_on_output(const char *output_name, const char *ws_name) { - int i; - for (i = 0; i < config->workspace_outputs->length; ++i) { - struct workspace_output *wso = config->workspace_outputs->items[i]; - if (strcasecmp(wso->workspace, ws_name) == 0) { - if (strcasecmp(wso->output, output_name) != 0) { - return false; - } - } - } - - return true; + struct workspace_config *wsc = workspace_find_config(ws_name); + return !wsc || !wsc->output || strcmp(wsc->output, output_name) == 0; } static void workspace_name_from_binding(const struct sway_binding * binding, @@ -231,13 +242,13 @@ char *workspace_next_name(const char *output_name) { workspace_name_from_binding(mode->keycode_bindings->items[i], output_name, &order, &target); } - for (int i = 0; i < config->workspace_outputs->length; ++i) { + for (int i = 0; i < config->workspace_configs->length; ++i) { // Unlike with bindings, this does not guarantee order - const struct workspace_output *wso = config->workspace_outputs->items[i]; - if (strcmp(wso->output, output_name) == 0 - && workspace_by_name(wso->workspace) == NULL) { + const struct workspace_config *wsc = config->workspace_configs->items[i]; + if (wsc->output && strcmp(wsc->output, output_name) == 0 + && workspace_by_name(wsc->workspace) == NULL) { free(target); - target = strdup(wso->workspace); + target = strdup(wsc->workspace); break; } } @@ -629,19 +640,25 @@ void workspace_add_gaps(struct sway_workspace *ws) { if (ws->current_gaps > 0) { return; } - bool should_apply = - config->edge_gaps || (config->smart_gaps && ws->tiling->length > 1); - if (!should_apply) { + if (!config->edge_gaps) { return; } + if (config->smart_gaps) { + struct sway_seat *seat = input_manager_get_default_seat(input_manager); + struct sway_container *focus = + seat_get_focus_inactive_view(seat, &ws->node); + if (focus && focus->view && view_is_only_visible(focus->view)) { + return; + } + } - ws->current_gaps = ws->has_gaps ? ws->gaps_outer : config->gaps_outer; + ws->current_gaps = ws->gaps_outer; if (ws->layout == L_TABBED || ws->layout == L_STACKED) { // We have to add inner gaps for this, because children of tabbed and // stacked containers don't apply their own gaps - they assume the // tabbed/stacked container is using gaps. - ws->current_gaps += ws->has_gaps ? ws->gaps_inner : config->gaps_inner; + ws->current_gaps += ws->gaps_inner; } ws->x += ws->current_gaps; |