Remove now-unused "input" argument of cmd_results_new

Patch tested by compiling with `__attribute__ ((format (printf, 2, 3)))`
applied to `cmd_results_new`.

String usage constants have been converted from pointers to arrays when
encountered. General handler format strings were sometimes modified to
include the old input string, especially for unknown command errors.
This commit is contained in:
M Stoeckl 2019-01-10 18:27:21 -05:00
parent 6d392150a7
commit 2a684cad5f
131 changed files with 503 additions and 601 deletions

View file

@ -75,7 +75,7 @@ struct cmd_results *config_commands_command(char *exec);
/** /**
* Allocates a cmd_results object. * Allocates a cmd_results object.
*/ */
struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *error, ...); struct cmd_results *cmd_results_new(enum cmd_status status, const char *error, ...);
/** /**
* Frees a cmd_results object. * Frees a cmd_results object.
*/ */
@ -87,8 +87,7 @@ void free_cmd_results(struct cmd_results *results);
*/ */
char *cmd_results_to_json(list_t *res_list); char *cmd_results_to_json(list_t *res_list);
struct cmd_results *add_color(const char *name, struct cmd_results *add_color(char *buffer, const char *color);
char *buffer, const char *color);
/** /**
* TODO: Move this function and its dependent functions to container.c. * TODO: Move this function and its dependent functions to container.c.

View file

@ -36,7 +36,7 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type
} }
} }
return error_name ? return error_name ?
cmd_results_new(CMD_INVALID, name, "Invalid %s command " cmd_results_new(CMD_INVALID, "Invalid %s command "
"(expected %s%d argument%s, got %d)", "(expected %s%d argument%s, got %d)",
name, error_name, val, val != 1 ? "s" : "", argc) name, error_name, val, val != 1 ? "s" : "", argc)
: NULL; : NULL;
@ -228,8 +228,7 @@ list_t *execute_command(char *_exec, struct sway_seat *seat,
char *error = NULL; char *error = NULL;
struct criteria *criteria = criteria_parse(head, &error); struct criteria *criteria = criteria_parse(head, &error);
if (!criteria) { if (!criteria) {
list_add(res_list, cmd_results_new(CMD_INVALID, head, list_add(res_list, cmd_results_new(CMD_INVALID, "%s", error));
"%s", error));
free(error); free(error);
goto cleanup; goto cleanup;
} }
@ -265,8 +264,8 @@ list_t *execute_command(char *_exec, struct sway_seat *seat,
} }
struct cmd_handler *handler = find_handler(argv[0], NULL, 0); struct cmd_handler *handler = find_handler(argv[0], NULL, 0);
if (!handler) { if (!handler) {
list_add(res_list, cmd_results_new(CMD_INVALID, cmd, list_add(res_list, cmd_results_new(CMD_INVALID,
"Unknown/invalid command")); "Unknown/invalid command '%s'", argv[0]));
free_argv(argc, argv); free_argv(argc, argv);
goto cleanup; goto cleanup;
} }
@ -323,20 +322,20 @@ struct cmd_results *config_command(char *exec, char **new_block) {
// Check for empty lines // Check for empty lines
if (!argc) { if (!argc) {
results = cmd_results_new(CMD_SUCCESS, NULL, NULL); results = cmd_results_new(CMD_SUCCESS, NULL);
goto cleanup; goto cleanup;
} }
// Check for the start of a block // Check for the start of a block
if (argc > 1 && strcmp(argv[argc - 1], "{") == 0) { if (argc > 1 && strcmp(argv[argc - 1], "{") == 0) {
*new_block = join_args(argv, argc - 1); *new_block = join_args(argv, argc - 1);
results = cmd_results_new(CMD_BLOCK, NULL, NULL); results = cmd_results_new(CMD_BLOCK, NULL);
goto cleanup; goto cleanup;
} }
// Check for the end of a block // Check for the end of a block
if (strcmp(argv[argc - 1], "}") == 0) { if (strcmp(argv[argc - 1], "}") == 0) {
results = cmd_results_new(CMD_BLOCK_END, NULL, NULL); results = cmd_results_new(CMD_BLOCK_END, NULL);
goto cleanup; goto cleanup;
} }
@ -348,7 +347,7 @@ struct cmd_results *config_command(char *exec, char **new_block) {
argv = split_args(temp, &argc); argv = split_args(temp, &argc);
free(temp); free(temp);
if (!argc) { if (!argc) {
results = cmd_results_new(CMD_SUCCESS, NULL, NULL); results = cmd_results_new(CMD_SUCCESS, NULL);
goto cleanup; goto cleanup;
} }
} }
@ -357,11 +356,10 @@ struct cmd_results *config_command(char *exec, char **new_block) {
wlr_log(WLR_INFO, "Config command: %s", exec); wlr_log(WLR_INFO, "Config command: %s", exec);
struct cmd_handler *handler = find_handler(argv[0], NULL, 0); struct cmd_handler *handler = find_handler(argv[0], NULL, 0);
if (!handler || !handler->handle) { if (!handler || !handler->handle) {
char *input = argv[0] ? argv[0] : "(empty)"; const char *error = handler
char *error = handler ? "Command '%s' is shimmed, but unimplemented"
? "This command is shimmed, but unimplemented" : "Unknown/invalid command '%s'";
: "Unknown/invalid command"; results = cmd_results_new(CMD_INVALID, error, argv[0]);
results = cmd_results_new(CMD_INVALID, input, error);
goto cleanup; goto cleanup;
} }
@ -410,14 +408,14 @@ struct cmd_results *config_subcommand(char **argv, int argc,
struct cmd_handler *handler = find_handler(argv[0], handlers, struct cmd_handler *handler = find_handler(argv[0], handlers,
handlers_size); handlers_size);
if (!handler) { if (!handler) {
char *input = argv[0] ? argv[0] : "(empty)"; return cmd_results_new(CMD_INVALID,
return cmd_results_new(CMD_INVALID, input, "Unknown/invalid command"); "Unknown/invalid command '%s'", argv[0]);
} }
if (handler->handle) { if (handler->handle) {
return handler->handle(argc - 1, argv + 1); return handler->handle(argc - 1, argv + 1);
} }
return cmd_results_new(CMD_INVALID, argv[0], return cmd_results_new(CMD_INVALID,
"This command is shimmed, but unimplemented"); "The command '%s' is shimmed, but unimplemented", argv[0]);
} }
struct cmd_results *config_commands_command(char *exec) { struct cmd_results *config_commands_command(char *exec) {
@ -425,7 +423,7 @@ struct cmd_results *config_commands_command(char *exec) {
int argc; int argc;
char **argv = split_args(exec, &argc); char **argv = split_args(exec, &argc);
if (!argc) { if (!argc) {
results = cmd_results_new(CMD_SUCCESS, NULL, NULL); results = cmd_results_new(CMD_SUCCESS, NULL);
goto cleanup; goto cleanup;
} }
@ -433,13 +431,14 @@ struct cmd_results *config_commands_command(char *exec) {
char *cmd = argv[0]; char *cmd = argv[0];
if (strcmp(cmd, "}") == 0) { if (strcmp(cmd, "}") == 0) {
results = cmd_results_new(CMD_BLOCK_END, NULL, NULL); results = cmd_results_new(CMD_BLOCK_END, NULL);
goto cleanup; goto cleanup;
} }
struct cmd_handler *handler = find_handler(cmd, NULL, 0); struct cmd_handler *handler = find_handler(cmd, NULL, 0);
if (!handler && strcmp(cmd, "*") != 0) { if (!handler && strcmp(cmd, "*") != 0) {
results = cmd_results_new(CMD_INVALID, cmd, "Unknown/invalid command"); results = cmd_results_new(CMD_INVALID,
"Unknown/invalid command '%s'", cmd);
goto cleanup; goto cleanup;
} }
@ -464,7 +463,7 @@ struct cmd_results *config_commands_command(char *exec) {
} }
} }
if (j == sizeof(context_names) / sizeof(context_names[0])) { if (j == sizeof(context_names) / sizeof(context_names[0])) {
results = cmd_results_new(CMD_INVALID, cmd, results = cmd_results_new(CMD_INVALID,
"Invalid command context %s", argv[i]); "Invalid command context %s", argv[i]);
goto cleanup; goto cleanup;
} }
@ -482,7 +481,7 @@ struct cmd_results *config_commands_command(char *exec) {
if (!policy) { if (!policy) {
policy = alloc_command_policy(cmd); policy = alloc_command_policy(cmd);
if (!sway_assert(policy, "Unable to allocate security policy")) { if (!sway_assert(policy, "Unable to allocate security policy")) {
results = cmd_results_new(CMD_INVALID, cmd, results = cmd_results_new(CMD_INVALID,
"Unable to allocate memory"); "Unable to allocate memory");
goto cleanup; goto cleanup;
} }
@ -493,7 +492,7 @@ struct cmd_results *config_commands_command(char *exec) {
wlr_log(WLR_INFO, "Set command policy for %s to %d", wlr_log(WLR_INFO, "Set command policy for %s to %d",
policy->command, policy->context); policy->command, policy->context);
results = cmd_results_new(CMD_SUCCESS, NULL, NULL); results = cmd_results_new(CMD_SUCCESS, NULL);
cleanup: cleanup:
free_argv(argc, argv); free_argv(argc, argv);
@ -501,14 +500,13 @@ cleanup:
} }
struct cmd_results *cmd_results_new(enum cmd_status status, struct cmd_results *cmd_results_new(enum cmd_status status,
const char *input, const char *format, ...) { const char *format, ...) {
struct cmd_results *results = malloc(sizeof(struct cmd_results)); struct cmd_results *results = malloc(sizeof(struct cmd_results));
if (!results) { if (!results) {
wlr_log(WLR_ERROR, "Unable to allocate command results"); wlr_log(WLR_ERROR, "Unable to allocate command results");
return NULL; return NULL;
} }
results->status = status; results->status = status;
// NOTE: `input` argument is unused, remove
if (format) { if (format) {
char *error = malloc(256); char *error = malloc(256);
va_list args; va_list args;
@ -557,20 +555,19 @@ char *cmd_results_to_json(list_t *res_list) {
* *
* return error object, or NULL if color is valid. * return error object, or NULL if color is valid.
*/ */
struct cmd_results *add_color(const char *name, struct cmd_results *add_color(char *buffer, const char *color) {
char *buffer, const char *color) {
int len = strlen(color); int len = strlen(color);
if (len != 7 && len != 9) { if (len != 7 && len != 9) {
return cmd_results_new(CMD_INVALID, name, return cmd_results_new(CMD_INVALID,
"Invalid color definition %s", color); "Invalid color definition %s", color);
} }
if (color[0] != '#') { if (color[0] != '#') {
return cmd_results_new(CMD_INVALID, name, return cmd_results_new(CMD_INVALID,
"Invalid color definition %s", color); "Invalid color definition %s", color);
} }
for (int i = 1; i < len; ++i) { for (int i = 1; i < len; ++i) {
if (!isxdigit(color[i])) { if (!isxdigit(color[i])) {
return cmd_results_new(CMD_INVALID, name, return cmd_results_new(CMD_INVALID,
"Invalid color definition %s", color); "Invalid color definition %s", color);
} }
} }

View file

@ -17,7 +17,7 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
char *err_str = NULL; char *err_str = NULL;
struct criteria *criteria = criteria_parse(argv[0], &err_str); struct criteria *criteria = criteria_parse(argv[0], &err_str);
if (!criteria) { if (!criteria) {
error = cmd_results_new(CMD_INVALID, "assign", err_str); error = cmd_results_new(CMD_INVALID, err_str);
free(err_str); free(err_str);
return error; return error;
} }
@ -27,7 +27,7 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
if (strncmp(*argv, "", strlen("")) == 0) { if (strncmp(*argv, "", strlen("")) == 0) {
if (argc < 2) { if (argc < 2) {
free(criteria); free(criteria);
return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); return cmd_results_new(CMD_INVALID, "Missing workspace");
} }
--argc; --argc;
++argv; ++argv;
@ -44,7 +44,7 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
--argc; ++argv; --argc; ++argv;
if (argv[0][0] < '0' || argv[0][0] > '9') { if (argv[0][0] < '0' || argv[0][0] > '9') {
free(criteria); free(criteria);
return cmd_results_new(CMD_INVALID, "assign", return cmd_results_new(CMD_INVALID,
"Invalid workspace number '%s'", argv[0]); "Invalid workspace number '%s'", argv[0]);
} }
criteria->type = CT_ASSIGN_WORKSPACE_NUMBER; criteria->type = CT_ASSIGN_WORKSPACE_NUMBER;
@ -59,5 +59,5 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
wlr_log(WLR_DEBUG, "assign: '%s' -> '%s' added", criteria->raw, wlr_log(WLR_DEBUG, "assign: '%s' -> '%s' added", criteria->raw,
criteria->target); criteria->target);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -69,7 +69,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
wlr_log(WLR_DEBUG, "Creating bar: %s", argv[0]); wlr_log(WLR_DEBUG, "Creating bar: %s", argv[0]);
bar = default_bar_config(); bar = default_bar_config();
if (!bar) { if (!bar) {
return cmd_results_new(CMD_FAILURE, "bar", return cmd_results_new(CMD_FAILURE,
"Unable to allocate bar state"); "Unable to allocate bar state");
} }
@ -83,7 +83,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
// Create new bar with default values // Create new bar with default values
struct bar_config *bar = default_bar_config(); struct bar_config *bar = default_bar_config();
if (!bar) { if (!bar) {
return cmd_results_new(CMD_FAILURE, "bar", return cmd_results_new(CMD_FAILURE,
"Unable to allocate bar state"); "Unable to allocate bar state");
} }
@ -93,8 +93,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
if (bar->id) { if (bar->id) {
snprintf(bar->id, len, "bar-%d", config->bars->length - 1); snprintf(bar->id, len, "bar-%d", config->bars->length - 1);
} else { } else {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "Unable to allocate bar ID");
"bar", "Unable to allocate bar ID");
} }
// Set current bar // Set current bar
@ -117,7 +116,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
} }
} }
} }
return cmd_results_new(CMD_INVALID, "bar", return cmd_results_new(CMD_INVALID,
"Can only be used in the config file."); "Can only be used in the config file.");
} }

View file

@ -16,13 +16,12 @@ static struct cmd_results *bar_cmd_bind(int argc, char **argv, bool code) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, command, "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
struct bar_binding *binding = calloc(1, sizeof(struct bar_binding)); struct bar_binding *binding = calloc(1, sizeof(struct bar_binding));
if (!binding) { if (!binding) {
return cmd_results_new(CMD_FAILURE, command, return cmd_results_new(CMD_FAILURE, "Unable to allocate bar binding");
"Unable to allocate bar binding");
} }
binding->release = false; binding->release = false;
@ -40,13 +39,12 @@ static struct cmd_results *bar_cmd_bind(int argc, char **argv, bool code) {
} }
if (message) { if (message) {
free_bar_binding(binding); free_bar_binding(binding);
error = cmd_results_new(CMD_INVALID, command, message); error = cmd_results_new(CMD_INVALID, message);
free(message); free(message);
return error; return error;
} else if (!binding->button) { } else if (!binding->button) {
free_bar_binding(binding); free_bar_binding(binding);
return cmd_results_new(CMD_INVALID, command, return cmd_results_new(CMD_INVALID, "Unknown button %s", argv[0]);
"Unknown button %s", argv[0]);
} }
const char *name = libevdev_event_code_get_name(EV_KEY, binding->button); const char *name = libevdev_event_code_get_name(EV_KEY, binding->button);
@ -94,7 +92,7 @@ static struct cmd_results *bar_cmd_bind(int argc, char **argv, bool code) {
binding->release ? " - release" : ""); binding->release ? " - release" : "");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct cmd_results *bar_cmd_bindcode(int argc, char **argv) { struct cmd_results *bar_cmd_bindcode(int argc, char **argv) {

View file

@ -11,8 +11,7 @@ struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No bar defined.");
"binding_mode_indicator", "No bar defined.");
} }
config->current_bar->binding_mode_indicator = config->current_bar->binding_mode_indicator =
parse_boolean(argv[0], config->current_bar->binding_mode_indicator); parse_boolean(argv[0], config->current_bar->binding_mode_indicator);
@ -23,5 +22,5 @@ struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) {
wlr_log(WLR_DEBUG, "Disabling binding mode indicator on bar: %s", wlr_log(WLR_DEBUG, "Disabling binding mode indicator on bar: %s",
config->current_bar->id); config->current_bar->id);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -25,11 +25,11 @@ static struct cmd_results *parse_single_color(char **color,
if (!*color && !(*color = malloc(10))) { if (!*color && !(*color = malloc(10))) {
return NULL; return NULL;
} }
error = add_color(cmd_name, *color, argv[0]); error = add_color(*color, argv[0]);
if (error) { if (error) {
return error; return error;
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
static struct cmd_results *parse_three_colors(char ***colors, static struct cmd_results *parse_three_colors(char ***colors,
@ -37,18 +37,18 @@ static struct cmd_results *parse_three_colors(char ***colors,
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
if (argc != 3) { if (argc != 3) {
return cmd_results_new(CMD_INVALID, return cmd_results_new(CMD_INVALID,
cmd_name, "Requires exactly three color values"); "Command '%s' requires exactly three color values", cmd_name);
} }
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
if (!*colors[i] && !(*(colors[i]) = malloc(10))) { if (!*colors[i] && !(*(colors[i]) = malloc(10))) {
return NULL; return NULL;
} }
error = add_color(cmd_name, *(colors[i]), argv[i]); error = add_color(*(colors[i]), argv[i]);
if (error) { if (error) {
return error; return error;
} }
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct cmd_results *bar_cmd_colors(int argc, char **argv) { struct cmd_results *bar_cmd_colors(int argc, char **argv) {

View file

@ -10,12 +10,12 @@ struct cmd_results *bar_cmd_font(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "font", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
char *font = join_args(argv, argc); char *font = join_args(argv, argc);
free(config->current_bar->font); free(config->current_bar->font);
config->current_bar->font = font; config->current_bar->font = font;
wlr_log(WLR_DEBUG, "Settings font '%s' for bar: %s", wlr_log(WLR_DEBUG, "Settings font '%s' for bar: %s",
config->current_bar->font, config->current_bar->id); config->current_bar->font, config->current_bar->id);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -14,7 +14,7 @@ struct cmd_results *bar_cmd_gaps(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "bar gaps", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
int top = 0, right = 0, bottom = 0, left = 0; int top = 0, right = 0, bottom = 0, left = 0;
@ -23,7 +23,7 @@ struct cmd_results *bar_cmd_gaps(int argc, char **argv) {
char *end; char *end;
int amount = strtol(argv[i], &end, 10); int amount = strtol(argv[i], &end, 10);
if (strlen(end) && strcasecmp(end, "px") != 0) { if (strlen(end) && strcasecmp(end, "px") != 0) {
return cmd_results_new(CMD_INVALID, "bar gaps", return cmd_results_new(CMD_INVALID,
"Expected 'bar [<bar-id>] gaps <all> | <horizonal> " "Expected 'bar [<bar-id>] gaps <all> | <horizonal> "
"<vertical> | <top> <right> <bottom> <left>'"); "<vertical> | <top> <right> <bottom> <left>'");
} }
@ -56,5 +56,5 @@ struct cmd_results *bar_cmd_gaps(int argc, char **argv) {
ipc_event_barconfig_update(config->current_bar); ipc_event_barconfig_update(config->current_bar);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -10,11 +10,11 @@ struct cmd_results *bar_cmd_height(int argc, char **argv) {
} }
int height = atoi(argv[0]); int height = atoi(argv[0]);
if (height < 0) { if (height < 0) {
return cmd_results_new(CMD_INVALID, "height", return cmd_results_new(CMD_INVALID,
"Invalid height value: %s", argv[0]); "Invalid height value: %s", argv[0]);
} }
config->current_bar->height = height; config->current_bar->height = height;
wlr_log(WLR_DEBUG, "Setting bar height to %d on bar: %s", wlr_log(WLR_DEBUG, "Setting bar height to %d on bar: %s",
height, config->current_bar->id); height, config->current_bar->id);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -20,8 +20,7 @@ static struct cmd_results *bar_set_hidden_state(struct bar_config *bar,
} else if (strcasecmp("show", hidden_state) == 0) { } else if (strcasecmp("show", hidden_state) == 0) {
bar->hidden_state = strdup("show"); bar->hidden_state = strdup("show");
} else { } else {
return cmd_results_new(CMD_INVALID, "hidden_state", return cmd_results_new(CMD_INVALID, "Invalid value %s", hidden_state);
"Invalid value %s", hidden_state);
} }
if (strcmp(old_state, bar->hidden_state) != 0) { if (strcmp(old_state, bar->hidden_state) != 0) {
if (!config->reading) { if (!config->reading) {
@ -44,7 +43,7 @@ struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
return error; return error;
} }
if (config->reading && argc > 1) { if (config->reading && argc > 1) {
return cmd_results_new(CMD_INVALID, "hidden_state", return cmd_results_new(CMD_INVALID,
"Unexpected value %s in config mode", argv[1]); "Unexpected value %s in config mode", argv[1]);
} }
@ -65,5 +64,5 @@ struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
} }
} }
} }
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); return error ? error : cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -13,16 +13,16 @@ struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) {
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "tray_padding", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
wlr_log(WLR_DEBUG, "[Bar %s] Setting icon theme to %s", wlr_log(WLR_DEBUG, "[Bar %s] Setting icon theme to %s",
config->current_bar->id, argv[0]); config->current_bar->id, argv[0]);
free(config->current_bar->icon_theme); free(config->current_bar->icon_theme);
config->current_bar->icon_theme = strdup(argv[0]); config->current_bar->icon_theme = strdup(argv[0]);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
#else #else
return cmd_results_new(CMD_INVALID, "icon_theme", return cmd_results_new(CMD_INVALID,
"Sway has been compiled without tray support"); "Sway has been compiled without tray support");
#endif #endif
} }

View file

@ -12,15 +12,15 @@ struct cmd_results *bar_cmd_id(int argc, char **argv) {
const char *name = argv[0]; const char *name = argv[0];
const char *oldname = config->current_bar->id; const char *oldname = config->current_bar->id;
if (strcmp(name, oldname) == 0) { if (strcmp(name, oldname) == 0) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL); // NOP return cmd_results_new(CMD_SUCCESS, NULL); // NOP
} else if (strcmp(name, "id") == 0) { } else if (strcmp(name, "id") == 0) {
return cmd_results_new(CMD_INVALID, "id", "id cannot be 'id'"); return cmd_results_new(CMD_INVALID, "id cannot be 'id'");
} }
// check if id is used by a previously defined bar // check if id is used by a previously defined bar
for (int i = 0; i < config->bars->length; ++i) { for (int i = 0; i < config->bars->length; ++i) {
struct bar_config *find = config->bars->items[i]; struct bar_config *find = config->bars->items[i];
if (strcmp(name, find->id) == 0 && config->current_bar != find) { if (strcmp(name, find->id) == 0 && config->current_bar != find) {
return cmd_results_new(CMD_FAILURE, "id", return cmd_results_new(CMD_FAILURE,
"Id '%s' already defined for another bar. Id unchanged (%s).", "Id '%s' already defined for another bar. Id unchanged (%s).",
name, oldname); name, oldname);
} }
@ -31,5 +31,5 @@ struct cmd_results *bar_cmd_id(int argc, char **argv) {
// free old bar id // free old bar id
free(config->current_bar->id); free(config->current_bar->id);
config->current_bar->id = strdup(name); config->current_bar->id = strdup(name);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -21,7 +21,7 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode
} else if (strcasecmp("invisible", mode) == 0) { } else if (strcasecmp("invisible", mode) == 0) {
bar->mode = strdup("invisible"); bar->mode = strdup("invisible");
} else { } else {
return cmd_results_new(CMD_INVALID, "mode", "Invalid value %s", mode); return cmd_results_new(CMD_INVALID, "Invalid value %s", mode);
} }
if (strcmp(old_mode, bar->mode) != 0) { if (strcmp(old_mode, bar->mode) != 0) {
@ -46,7 +46,7 @@ struct cmd_results *bar_cmd_mode(int argc, char **argv) {
} }
if (config->reading && argc > 1) { if (config->reading && argc > 1) {
return cmd_results_new(CMD_INVALID, return cmd_results_new(CMD_INVALID,
"mode", "Unexpected value %s in config mode", argv[1]); "Unexpected value %s in config mode", argv[1]);
} }
const char *mode = argv[0]; const char *mode = argv[0];
@ -66,5 +66,5 @@ struct cmd_results *bar_cmd_mode(int argc, char **argv) {
} }
} }
} }
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); return error ? error : cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,7 +11,7 @@ struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "modifier", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
uint32_t mod = 0; uint32_t mod = 0;
@ -21,8 +21,8 @@ struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) { if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) {
mod |= tmp_mod; mod |= tmp_mod;
} else { } else {
error = cmd_results_new(CMD_INVALID, "modifier", error = cmd_results_new(CMD_INVALID,
"Unknown modifier '%s'", split->items[i]); "Unknown modifier '%s'", (char *)split->items[i]);
list_free_items_and_destroy(split); list_free_items_and_destroy(split);
return error; return error;
} }
@ -31,5 +31,5 @@ struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
config->current_bar->modifier = mod; config->current_bar->modifier = mod;
wlr_log(WLR_DEBUG, wlr_log(WLR_DEBUG,
"Show/Hide the bar when pressing '%s' in hide mode.", argv[0]); "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,7 +11,7 @@ struct cmd_results *bar_cmd_output(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "output", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
const char *output = argv[0]; const char *output = argv[0];
@ -45,5 +45,5 @@ struct cmd_results *bar_cmd_output(int argc, char **argv) {
wlr_log(WLR_DEBUG, "Adding bar: '%s' to output '%s'", wlr_log(WLR_DEBUG, "Adding bar: '%s' to output '%s'",
config->current_bar->id, output); config->current_bar->id, output);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -10,7 +10,7 @@ struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "pango_markup", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
config->current_bar->pango_markup config->current_bar->pango_markup
= parse_boolean(argv[0], config->current_bar->pango_markup); = parse_boolean(argv[0], config->current_bar->pango_markup);
@ -21,5 +21,5 @@ struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) {
wlr_log(WLR_DEBUG, "Disabling pango markup for bar: %s", wlr_log(WLR_DEBUG, "Disabling pango markup for bar: %s",
config->current_bar->id); config->current_bar->id);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -10,7 +10,7 @@ struct cmd_results *bar_cmd_position(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "position", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
char *valid[] = { "top", "bottom" }; char *valid[] = { "top", "bottom" };
for (size_t i = 0; i < sizeof(valid) / sizeof(valid[0]); ++i) { for (size_t i = 0; i < sizeof(valid) / sizeof(valid[0]); ++i) {
@ -19,9 +19,8 @@ struct cmd_results *bar_cmd_position(int argc, char **argv) {
argv[0], config->current_bar->id); argv[0], config->current_bar->id);
free(config->current_bar->position); free(config->current_bar->position);
config->current_bar->position = strdup(argv[0]); config->current_bar->position = strdup(argv[0]);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
} }
return cmd_results_new(CMD_INVALID, return cmd_results_new(CMD_INVALID, "Invalid value %s", argv[0]);
"position", "Invalid value %s", argv[0]);
} }

View file

@ -9,12 +9,11 @@ struct cmd_results *bar_cmd_separator_symbol(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No bar defined.");
"separator_symbol", "No bar defined.");
} }
free(config->current_bar->separator_symbol); free(config->current_bar->separator_symbol);
config->current_bar->separator_symbol = strdup(argv[0]); config->current_bar->separator_symbol = strdup(argv[0]);
wlr_log(WLR_DEBUG, "Settings separator_symbol '%s' for bar: %s", wlr_log(WLR_DEBUG, "Settings separator_symbol '%s' for bar: %s",
config->current_bar->separator_symbol, config->current_bar->id); config->current_bar->separator_symbol, config->current_bar->id);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -9,8 +9,7 @@ struct cmd_results *bar_cmd_status_command(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No bar defined.");
"status_command", "No bar defined.");
} }
free(config->current_bar->status_command); free(config->current_bar->status_command);
config->current_bar->status_command = NULL; config->current_bar->status_command = NULL;
@ -28,5 +27,5 @@ struct cmd_results *bar_cmd_status_command(int argc, char **argv) {
load_swaybar(config->current_bar); load_swaybar(config->current_bar);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,11 +11,11 @@ struct cmd_results *bar_cmd_status_edge_padding(int argc, char **argv) {
char *end; char *end;
int padding = strtol(argv[0], &end, 10); int padding = strtol(argv[0], &end, 10);
if (strlen(end) || padding < 0) { if (strlen(end) || padding < 0) {
return cmd_results_new(CMD_INVALID, "status_edge_padding", return cmd_results_new(CMD_INVALID,
"Padding must be a positive integer"); "Padding must be a positive integer");
} }
config->current_bar->status_edge_padding = padding; config->current_bar->status_edge_padding = padding;
wlr_log(WLR_DEBUG, "Status edge padding on bar %s: %d", wlr_log(WLR_DEBUG, "Status edge padding on bar %s: %d",
config->current_bar->id, config->current_bar->status_edge_padding); config->current_bar->id, config->current_bar->status_edge_padding);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,11 +11,11 @@ struct cmd_results *bar_cmd_status_padding(int argc, char **argv) {
char *end; char *end;
int padding = strtol(argv[0], &end, 10); int padding = strtol(argv[0], &end, 10);
if (strlen(end) || padding < 0) { if (strlen(end) || padding < 0) {
return cmd_results_new(CMD_INVALID, "status_padding", return cmd_results_new(CMD_INVALID,
"Padding must be a positive integer"); "Padding must be a positive integer");
} }
config->current_bar->status_padding = padding; config->current_bar->status_padding = padding;
wlr_log(WLR_DEBUG, "Status padding on bar %s: %d", wlr_log(WLR_DEBUG, "Status padding on bar %s: %d",
config->current_bar->id, config->current_bar->status_padding); config->current_bar->id, config->current_bar->status_padding);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,8 +11,7 @@ struct cmd_results *bar_cmd_strip_workspace_name(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No bar defined.");
"strip_workspace_name", "No bar defined.");
} }
config->current_bar->strip_workspace_name = config->current_bar->strip_workspace_name =
@ -28,5 +27,5 @@ struct cmd_results *bar_cmd_strip_workspace_name(int argc, char **argv) {
config->current_bar->id); config->current_bar->id);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,8 +11,7 @@ struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No bar defined.");
"strip_workspace_numbers", "No bar defined.");
} }
config->current_bar->strip_workspace_numbers = config->current_bar->strip_workspace_numbers =
@ -28,5 +27,5 @@ struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) {
config->current_bar->id); config->current_bar->id);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -9,12 +9,11 @@ struct cmd_results *bar_cmd_swaybar_command(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No bar defined.");
"swaybar_command", "No bar defined.");
} }
free(config->current_bar->swaybar_command); free(config->current_bar->swaybar_command);
config->current_bar->swaybar_command = join_args(argv, argc); config->current_bar->swaybar_command = join_args(argv, argc);
wlr_log(WLR_DEBUG, "Using custom swaybar command: %s", wlr_log(WLR_DEBUG, "Using custom swaybar command: %s",
config->current_bar->swaybar_command); config->current_bar->swaybar_command);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,7 +12,7 @@ struct cmd_results *bar_cmd_tray_bindsym(int argc, char **argv) {
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "tray_bindsym", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
int button = 0; int button = 0;
@ -21,7 +21,7 @@ struct cmd_results *bar_cmd_tray_bindsym(int argc, char **argv) {
button = argv[0][strlen("button")] - '0'; button = argv[0][strlen("button")] - '0';
} }
if (button < 1 || button > 9) { if (button < 1 || button > 9) {
return cmd_results_new(CMD_FAILURE, "tray_bindsym", return cmd_results_new(CMD_FAILURE,
"[Bar %s] Only buttons 1 to 9 are supported", "[Bar %s] Only buttons 1 to 9 are supported",
config->current_bar->id); config->current_bar->id);
} }
@ -42,14 +42,14 @@ struct cmd_results *bar_cmd_tray_bindsym(int argc, char **argv) {
wlr_log(WLR_DEBUG, "[Bar %s] Binding button %d to %s", wlr_log(WLR_DEBUG, "[Bar %s] Binding button %d to %s",
config->current_bar->id, button, commands[i]); config->current_bar->id, button, commands[i]);
config->current_bar->tray_bindings[button] = commands[i]; config->current_bar->tray_bindings[button] = commands[i];
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
} }
return cmd_results_new(CMD_INVALID, "tray_bindsym", return cmd_results_new(CMD_INVALID,
"[Bar %s] Invalid command %s", config->current_bar->id, argv[1]); "[Bar %s] Invalid command %s", config->current_bar->id, argv[1]);
#else #else
return cmd_results_new(CMD_INVALID, "tray_bindsym", return cmd_results_new(CMD_INVALID,
"Sway has been compiled without tray support"); "Sway has been compiled without tray support");
#endif #endif
} }

View file

@ -14,7 +14,7 @@ struct cmd_results *bar_cmd_tray_output(int argc, char **argv) {
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "tray_output", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
list_t *outputs = config->current_bar->tray_outputs; list_t *outputs = config->current_bar->tray_outputs;
@ -34,9 +34,9 @@ struct cmd_results *bar_cmd_tray_output(int argc, char **argv) {
} }
list_add(outputs, strdup(argv[0])); list_add(outputs, strdup(argv[0]));
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
#else #else
return cmd_results_new(CMD_INVALID, "tray_output", return cmd_results_new(CMD_INVALID,
"Sway has been compiled without tray support"); "Sway has been compiled without tray support");
#endif #endif
} }

View file

@ -16,27 +16,27 @@ struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "tray_padding", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
struct bar_config *bar = config->current_bar; struct bar_config *bar = config->current_bar;
char *end; char *end;
int padding = strtol(argv[0], &end, 10); int padding = strtol(argv[0], &end, 10);
if (padding < 0 || (*end != '\0' && strcasecmp(end, "px") != 0)) { if (padding < 0 || (*end != '\0' && strcasecmp(end, "px") != 0)) {
return cmd_results_new(CMD_INVALID, "tray_padding", return cmd_results_new(CMD_INVALID,
"[Bar %s] Invalid tray padding value: %s", bar->id, argv[0]); "[Bar %s] Invalid tray padding value: %s", bar->id, argv[0]);
} }
if (argc == 2 && strcasecmp(argv[1], "px") != 0) { if (argc == 2 && strcasecmp(argv[1], "px") != 0) {
return cmd_results_new(CMD_INVALID, "tray_padding", return cmd_results_new(CMD_INVALID,
"Expected 'tray_padding <px> [px]'"); "Expected 'tray_padding <px> [px]'");
} }
wlr_log(WLR_DEBUG, "[Bar %s] Setting tray padding to %d", bar->id, padding); wlr_log(WLR_DEBUG, "[Bar %s] Setting tray padding to %d", bar->id, padding);
config->current_bar->tray_padding = padding; config->current_bar->tray_padding = padding;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
#else #else
return cmd_results_new(CMD_INVALID, "tray_padding", return cmd_results_new(CMD_INVALID,
"Sway has been compiled without tray support"); "Sway has been compiled without tray support");
#endif #endif
} }

View file

@ -10,8 +10,7 @@ struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No bar defined.");
"workspace_buttons", "No bar defined.");
} }
config->current_bar->workspace_buttons = config->current_bar->workspace_buttons =
parse_boolean(argv[0], config->current_bar->workspace_buttons); parse_boolean(argv[0], config->current_bar->workspace_buttons);
@ -22,5 +21,5 @@ struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
wlr_log(WLR_DEBUG, "Disabling workspace buttons on bar: %s", wlr_log(WLR_DEBUG, "Disabling workspace buttons on bar: %s",
config->current_bar->id); config->current_bar->id);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -10,7 +10,7 @@ struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) {
return error; return error;
} }
if (!config->current_bar) { if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "wrap_scroll", "No bar defined."); return cmd_results_new(CMD_FAILURE, "No bar defined.");
} }
config->current_bar->wrap_scroll = config->current_bar->wrap_scroll =
parse_boolean(argv[0], config->current_bar->wrap_scroll); parse_boolean(argv[0], config->current_bar->wrap_scroll);
@ -21,5 +21,5 @@ struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) {
wlr_log(WLR_DEBUG, "Disabling wrap scroll on bar: %s", wlr_log(WLR_DEBUG, "Disabling wrap scroll on bar: %s",
config->current_bar->id); config->current_bar->id);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -92,11 +92,11 @@ static struct cmd_results *identify_key(const char* name, bool first_key,
if (!button) { if (!button) {
if (message) { if (message) {
struct cmd_results *error = struct cmd_results *error =
cmd_results_new(CMD_INVALID, "bindcode", message); cmd_results_new(CMD_INVALID, message);
free(message); free(message);
return error; return error;
} else { } else {
return cmd_results_new(CMD_INVALID, "bindcode", return cmd_results_new(CMD_INVALID,
"Unknown button code %s", name); "Unknown button code %s", name);
} }
} }
@ -108,12 +108,11 @@ static struct cmd_results *identify_key(const char* name, bool first_key,
if (!button) { if (!button) {
if (message) { if (message) {
struct cmd_results *error = struct cmd_results *error =
cmd_results_new(CMD_INVALID, "bindsym", message); cmd_results_new(CMD_INVALID, message);
free(message); free(message);
return error; return error;
} else if (!button) { } else if (!button) {
return cmd_results_new(CMD_INVALID, "bindsym", return cmd_results_new(CMD_INVALID, "Unknown button %s", name);
"Unknown button %s", name);
} }
} }
*key_val = button; *key_val = button;
@ -133,10 +132,10 @@ static struct cmd_results *identify_key(const char* name, bool first_key,
xkb_keycode_t keycode = strtol(name, NULL, 10); xkb_keycode_t keycode = strtol(name, NULL, 10);
if (!xkb_keycode_is_legal_ext(keycode)) { if (!xkb_keycode_is_legal_ext(keycode)) {
if (first_key) { if (first_key) {
return cmd_results_new(CMD_INVALID, "bindcode", return cmd_results_new(CMD_INVALID,
"Invalid keycode or button code '%s'", name); "Invalid keycode or button code '%s'", name);
} else { } else {
return cmd_results_new(CMD_INVALID, "bindcode", return cmd_results_new(CMD_INVALID,
"Invalid keycode '%s'", name); "Invalid keycode '%s'", name);
} }
} }
@ -148,7 +147,7 @@ static struct cmd_results *identify_key(const char* name, bool first_key,
uint32_t button = get_mouse_bindsym(name, &message); uint32_t button = get_mouse_bindsym(name, &message);
if (message) { if (message) {
struct cmd_results *error = struct cmd_results *error =
cmd_results_new(CMD_INVALID, "bindsym", message); cmd_results_new(CMD_INVALID, message);
free(message); free(message);
return error; return error;
} else if (button) { } else if (button) {
@ -162,11 +161,10 @@ static struct cmd_results *identify_key(const char* name, bool first_key,
XKB_KEYSYM_CASE_INSENSITIVE); XKB_KEYSYM_CASE_INSENSITIVE);
if (!keysym) { if (!keysym) {
if (first_key) { if (first_key) {
return cmd_results_new(CMD_INVALID, "bindsym", return cmd_results_new(CMD_INVALID,
"Unknown key or button '%s'", name); "Unknown key or button '%s'", name);
} else { } else {
return cmd_results_new(CMD_INVALID, "bindsym", return cmd_results_new(CMD_INVALID, "Unknown key '%s'", name);
"Unknown key '%s'", name);
} }
} }
*key_val = keysym; *key_val = keysym;
@ -185,8 +183,7 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
struct sway_binding *binding = calloc(1, sizeof(struct sway_binding)); struct sway_binding *binding = calloc(1, sizeof(struct sway_binding));
if (!binding) { if (!binding) {
return cmd_results_new(CMD_FAILURE, bindtype, return cmd_results_new(CMD_FAILURE, "Unable to allocate binding");
"Unable to allocate binding");
} }
binding->input = strdup("*"); binding->input = strdup("*");
binding->keys = create_list(); binding->keys = create_list();
@ -229,7 +226,7 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
if (argc < 2) { if (argc < 2) {
free_sway_binding(binding); free_sway_binding(binding);
return cmd_results_new(CMD_FAILURE, bindtype, return cmd_results_new(CMD_FAILURE,
"Invalid %s command " "Invalid %s command "
"(expected at least 2 non-option arguments, got %d)", bindtype, argc); "(expected at least 2 non-option arguments, got %d)", bindtype, argc);
} }
@ -259,7 +256,7 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
if (!key) { if (!key) {
free_sway_binding(binding); free_sway_binding(binding);
list_free_items_and_destroy(split); list_free_items_and_destroy(split);
return cmd_results_new(CMD_FAILURE, bindtype, return cmd_results_new(CMD_FAILURE,
"Unable to allocate binding key"); "Unable to allocate binding key");
} }
*key = key_val; *key = key_val;
@ -315,7 +312,7 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
wlr_log(WLR_DEBUG, "%s - Bound %s to command `%s` for device '%s'", wlr_log(WLR_DEBUG, "%s - Bound %s to command `%s` for device '%s'",
bindtype, argv[0], binding->command, binding->input); bindtype, argv[0], binding->command, binding->input);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct cmd_results *cmd_bindsym(int argc, char **argv) { struct cmd_results *cmd_bindsym(int argc, char **argv) {

View file

@ -64,8 +64,7 @@ struct cmd_results *cmd_border(int argc, char **argv) {
struct sway_container *container = config->handler_context.container; struct sway_container *container = config->handler_context.container;
if (!container || !container->view) { if (!container || !container->view) {
return cmd_results_new(CMD_INVALID, "border", return cmd_results_new(CMD_INVALID, "Only views can have borders");
"Only views can have borders");
} }
struct sway_view *view = container->view; struct sway_view *view = container->view;
@ -77,14 +76,14 @@ struct cmd_results *cmd_border(int argc, char **argv) {
set_border(container, B_PIXEL); set_border(container, B_PIXEL);
} else if (strcmp(argv[0], "csd") == 0) { } else if (strcmp(argv[0], "csd") == 0) {
if (!view || !view->xdg_decoration) { if (!view || !view->xdg_decoration) {
return cmd_results_new(CMD_INVALID, "border", return cmd_results_new(CMD_INVALID,
"This window doesn't support client side decorations"); "This window doesn't support client side decorations");
} }
set_border(container, B_CSD); set_border(container, B_CSD);
} else if (strcmp(argv[0], "toggle") == 0) { } else if (strcmp(argv[0], "toggle") == 0) {
border_toggle(container); border_toggle(container);
} else { } else {
return cmd_results_new(CMD_INVALID, "border", return cmd_results_new(CMD_INVALID,
"Expected 'border <none|normal|pixel|csd|toggle>' " "Expected 'border <none|normal|pixel|csd|toggle>' "
"or 'border pixel <px>'"); "or 'border pixel <px>'");
} }
@ -98,5 +97,5 @@ struct cmd_results *cmd_border(int argc, char **argv) {
arrange_container(container); arrange_container(container);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -61,27 +61,27 @@ static struct cmd_results *handle_command(int argc, char **argv,
} }
if (!parse_color_float(argv[0], class->border)) { if (!parse_color_float(argv[0], class->border)) {
return cmd_results_new(CMD_INVALID, cmd_name, return cmd_results_new(CMD_INVALID,
"Unable to parse border color '%s'", argv[0]); "Unable to parse border color '%s'", argv[0]);
} }
if (!parse_color_float(argv[1], class->background)) { if (!parse_color_float(argv[1], class->background)) {
return cmd_results_new(CMD_INVALID, cmd_name, return cmd_results_new(CMD_INVALID,
"Unable to parse background color '%s'", argv[1]); "Unable to parse background color '%s'", argv[1]);
} }
if (!parse_color_float(argv[2], class->text)) { if (!parse_color_float(argv[2], class->text)) {
return cmd_results_new(CMD_INVALID, cmd_name, return cmd_results_new(CMD_INVALID,
"Unable to parse text color '%s'", argv[2]); "Unable to parse text color '%s'", argv[2]);
} }
if (!parse_color_float(argv[3], class->indicator)) { if (!parse_color_float(argv[3], class->indicator)) {
return cmd_results_new(CMD_INVALID, cmd_name, return cmd_results_new(CMD_INVALID,
"Unable to parse indicator color '%s'", argv[3]); "Unable to parse indicator color '%s'", argv[3]);
} }
if (!parse_color_float(argv[4], class->child_border)) { if (!parse_color_float(argv[4], class->child_border)) {
return cmd_results_new(CMD_INVALID, cmd_name, return cmd_results_new(CMD_INVALID,
"Unable to parse child border color '%s'", argv[4]); "Unable to parse child border color '%s'", argv[4]);
} }
@ -94,7 +94,7 @@ static struct cmd_results *handle_command(int argc, char **argv,
} }
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct cmd_results *cmd_client_focused(int argc, char **argv) { struct cmd_results *cmd_client_focused(int argc, char **argv) {
@ -115,5 +115,5 @@ struct cmd_results *cmd_client_urgent(int argc, char **argv) {
struct cmd_results *cmd_client_noop(int argc, char **argv) { struct cmd_results *cmd_client_noop(int argc, char **argv) {
wlr_log(WLR_INFO, "Warning: %s is ignored by sway", argv[-1]); wlr_log(WLR_INFO, "Warning: %s is ignored by sway", argv[-1]);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -37,9 +37,9 @@ struct cmd_results *cmd_create_output(int argc, char **argv) {
wlr_multi_for_each_backend(server.backend, create_output, &done); wlr_multi_for_each_backend(server.backend, create_output, &done);
if (!done) { if (!done) {
return cmd_results_new(CMD_INVALID, "create_output", return cmd_results_new(CMD_INVALID,
"Can only create outputs for Wayland or X11 backends"); "Can only create outputs for Wayland or X11 backends");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -16,12 +16,12 @@ struct cmd_results *cmd_default_border(int argc, char **argv) {
} else if (strcmp(argv[0], "pixel") == 0) { } else if (strcmp(argv[0], "pixel") == 0) {
config->border = B_PIXEL; config->border = B_PIXEL;
} else { } else {
return cmd_results_new(CMD_INVALID, "default_border", return cmd_results_new(CMD_INVALID,
"Expected 'default_border <none|normal|pixel>' or 'default_border <normal|pixel> <px>'"); "Expected 'default_border <none|normal|pixel>' or 'default_border <normal|pixel> <px>'");
} }
if (argc == 2) { if (argc == 2) {
config->border_thickness = atoi(argv[1]); config->border_thickness = atoi(argv[1]);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -17,7 +17,7 @@ struct cmd_results *cmd_default_floating_border(int argc, char **argv) {
} else if (strcmp(argv[0], "pixel") == 0) { } else if (strcmp(argv[0], "pixel") == 0) {
config->floating_border = B_PIXEL; config->floating_border = B_PIXEL;
} else { } else {
return cmd_results_new(CMD_INVALID, "default_floating_border", return cmd_results_new(CMD_INVALID,
"Expected 'default_floating_border <none|normal|pixel>' " "Expected 'default_floating_border <none|normal|pixel>' "
"or 'default_floating_border <normal|pixel> <px>'"); "or 'default_floating_border <normal|pixel> <px>'");
} }
@ -25,5 +25,5 @@ struct cmd_results *cmd_default_floating_border(int argc, char **argv) {
config->floating_border_thickness = atoi(argv[1]); config->floating_border_thickness = atoi(argv[1]);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -14,8 +14,8 @@ struct cmd_results *cmd_default_orientation(int argc, char **argv) {
} else if (strcasecmp(argv[0], "auto") == 0) { } else if (strcasecmp(argv[0], "auto") == 0) {
// Do nothing // Do nothing
} else { } else {
return cmd_results_new(CMD_INVALID, "default_orientation", return cmd_results_new(CMD_INVALID,
"Expected 'orientation <horizontal|vertical|auto>'"); "Expected 'orientation <horizontal|vertical|auto>'");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -5,12 +5,12 @@
#include "stringop.h" #include "stringop.h"
struct cmd_results *cmd_exec(int argc, char **argv) { struct cmd_results *cmd_exec(int argc, char **argv) {
if (!config->active) return cmd_results_new(CMD_DEFER, "exec", NULL); if (!config->active) return cmd_results_new(CMD_DEFER, NULL);
if (config->reloading) { if (config->reloading) {
char *args = join_args(argv, argc); char *args = join_args(argv, argc);
wlr_log(WLR_DEBUG, "Ignoring 'exec %s' due to reload", args); wlr_log(WLR_DEBUG, "Ignoring 'exec %s' due to reload", args);
free(args); free(args);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
return cmd_exec_always(argc, argv); return cmd_exec_always(argc, argv);
} }

View file

@ -15,7 +15,9 @@
struct cmd_results *cmd_exec_always(int argc, char **argv) { struct cmd_results *cmd_exec_always(int argc, char **argv) {
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
if (!config->active || config->validating) return cmd_results_new(CMD_DEFER, NULL, NULL); if (!config->active || config->validating) {
return cmd_results_new(CMD_DEFER, NULL);
}
if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) { if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) {
return error; return error;
} }
@ -71,7 +73,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) {
} else if (pid < 0) { } else if (pid < 0) {
close(fd[0]); close(fd[0]);
close(fd[1]); close(fd[1]);
return cmd_results_new(CMD_FAILURE, argv[-1], "fork() failed"); return cmd_results_new(CMD_FAILURE, "fork() failed");
} }
close(fd[1]); // close write close(fd[1]); // close write
ssize_t s = 0; ssize_t s = 0;
@ -85,9 +87,8 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) {
wlr_log(WLR_DEBUG, "Child process created with pid %d", child); wlr_log(WLR_DEBUG, "Child process created with pid %d", child);
root_record_workspace_pid(child); root_record_workspace_pid(child);
} else { } else {
return cmd_results_new(CMD_FAILURE, argv[-1], return cmd_results_new(CMD_FAILURE, "Second fork() failed");
"Second fork() failed");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -10,5 +10,5 @@ struct cmd_results *cmd_exit(int argc, char **argv) {
return error; return error;
} }
sway_terminate(0); sway_terminate(0);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -17,14 +17,13 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
return error; return error;
} }
if (!root->outputs->length) { if (!root->outputs->length) {
return cmd_results_new(CMD_INVALID, "floating", return cmd_results_new(CMD_INVALID,
"Can't run this command while there's no outputs connected."); "Can't run this command while there's no outputs connected.");
} }
struct sway_container *container = config->handler_context.container; struct sway_container *container = config->handler_context.container;
struct sway_workspace *workspace = config->handler_context.workspace; struct sway_workspace *workspace = config->handler_context.workspace;
if (!container && workspace->tiling->length == 0) { if (!container && workspace->tiling->length == 0) {
return cmd_results_new(CMD_INVALID, "floating", return cmd_results_new(CMD_INVALID, "Can't float an empty workspace");
"Can't float an empty workspace");
} }
if (!container) { if (!container) {
// Wrap the workspace's children in a container so we can float it // Wrap the workspace's children in a container so we can float it
@ -48,5 +47,5 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
arrange_workspace(container->workspace); arrange_workspace(container->workspace);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -8,10 +8,10 @@
#include "sway/commands.h" #include "sway/commands.h"
#include "log.h" #include "log.h"
static const char* min_usage = static const char min_usage[] =
"Expected 'floating_minimum_size <width> x <height>'"; "Expected 'floating_minimum_size <width> x <height>'";
static const char* max_usage = static const char max_usage[] =
"Expected 'floating_maximum_size <width> x <height>'"; "Expected 'floating_maximum_size <width> x <height>'";
static struct cmd_results *handle_command(int argc, char **argv, char *cmd_name, static struct cmd_results *handle_command(int argc, char **argv, char *cmd_name,
@ -39,7 +39,7 @@ static struct cmd_results *handle_command(int argc, char **argv, char *cmd_name,
*config_width = width; *config_width = width;
*config_height = height; *config_height = height;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct cmd_results *cmd_floating_minimum_size(int argc, char **argv) { struct cmd_results *cmd_floating_minimum_size(int argc, char **argv) {

View file

@ -11,8 +11,7 @@ struct cmd_results *cmd_floating_modifier(int argc, char **argv) {
uint32_t mod = get_modifier_mask_by_name(argv[0]); uint32_t mod = get_modifier_mask_by_name(argv[0]);
if (!mod) { if (!mod) {
return cmd_results_new(CMD_INVALID, "floating_modifier", return cmd_results_new(CMD_INVALID, "Invalid modifier");
"Invalid modifier");
} }
if (argc == 1 || strcasecmp(argv[1], "normal") == 0) { if (argc == 1 || strcasecmp(argv[1], "normal") == 0) {
@ -20,11 +19,11 @@ struct cmd_results *cmd_floating_modifier(int argc, char **argv) {
} else if (strcasecmp(argv[1], "inverse") == 0) { } else if (strcasecmp(argv[1], "inverse") == 0) {
config->floating_mod_inverse = true; config->floating_mod_inverse = true;
} else { } else {
return cmd_results_new(CMD_INVALID, "floating_modifier", return cmd_results_new(CMD_INVALID,
"Usage: floating_modifier <mod> [inverse|normal]"); "Usage: floating_modifier <mod> [inverse|normal]");
} }
config->floating_mod = mod; config->floating_mod = mod;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -179,17 +179,17 @@ static struct cmd_results *focus_mode(struct sway_workspace *ws,
seat_set_focus_container(seat, new_focus); seat_set_focus_container(seat, new_focus);
seat_consider_warp_to_focus(seat); seat_consider_warp_to_focus(seat);
} else { } else {
return cmd_results_new(CMD_FAILURE, "focus", return cmd_results_new(CMD_FAILURE,
"Failed to find a %s container in workspace", "Failed to find a %s container in workspace",
floating ? "floating" : "tiling"); floating ? "floating" : "tiling");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
static struct cmd_results *focus_output(struct sway_seat *seat, static struct cmd_results *focus_output(struct sway_seat *seat,
int argc, char **argv) { int argc, char **argv) {
if (!argc) { if (!argc) {
return cmd_results_new(CMD_INVALID, "focus", return cmd_results_new(CMD_INVALID,
"Expected 'focus output <direction|name>'"); "Expected 'focus output <direction|name>'");
} }
char *identifier = join_args(argv, argc); char *identifier = join_args(argv, argc);
@ -199,7 +199,7 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
enum wlr_direction direction; enum wlr_direction direction;
if (!parse_direction(identifier, &direction)) { if (!parse_direction(identifier, &direction)) {
free(identifier); free(identifier);
return cmd_results_new(CMD_INVALID, "focus", return cmd_results_new(CMD_INVALID,
"There is no output with that name"); "There is no output with that name");
} }
struct sway_workspace *ws = seat_get_focused_workspace(seat); struct sway_workspace *ws = seat_get_focused_workspace(seat);
@ -223,21 +223,21 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
seat_consider_warp_to_focus(seat); seat_consider_warp_to_focus(seat);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
static struct cmd_results *focus_parent(void) { static struct cmd_results *focus_parent(void) {
struct sway_seat *seat = config->handler_context.seat; struct sway_seat *seat = config->handler_context.seat;
struct sway_container *con = config->handler_context.container; struct sway_container *con = config->handler_context.container;
if (!con || con->is_fullscreen) { if (!con || con->is_fullscreen) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct sway_node *parent = node_get_parent(&con->node); struct sway_node *parent = node_get_parent(&con->node);
if (parent) { if (parent) {
seat_set_focus(seat, parent); seat_set_focus(seat, parent);
seat_consider_warp_to_focus(seat); seat_consider_warp_to_focus(seat);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
static struct cmd_results *focus_child(void) { static struct cmd_results *focus_child(void) {
@ -248,15 +248,15 @@ static struct cmd_results *focus_child(void) {
seat_set_focus(seat, focus); seat_set_focus(seat, focus);
seat_consider_warp_to_focus(seat); seat_consider_warp_to_focus(seat);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct cmd_results *cmd_focus(int argc, char **argv) { struct cmd_results *cmd_focus(int argc, char **argv) {
if (config->reading || !config->active) { if (config->reading || !config->active) {
return cmd_results_new(CMD_DEFER, NULL, NULL); return cmd_results_new(CMD_DEFER, NULL);
} }
if (!root->outputs->length) { if (!root->outputs->length) {
return cmd_results_new(CMD_INVALID, "focus", return cmd_results_new(CMD_INVALID,
"Can't run this command while there's no outputs connected."); "Can't run this command while there's no outputs connected.");
} }
struct sway_node *node = config->handler_context.node; struct sway_node *node = config->handler_context.node;
@ -264,7 +264,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
struct sway_workspace *workspace = config->handler_context.workspace; struct sway_workspace *workspace = config->handler_context.workspace;
struct sway_seat *seat = config->handler_context.seat; struct sway_seat *seat = config->handler_context.seat;
if (node->type < N_WORKSPACE) { if (node->type < N_WORKSPACE) {
return cmd_results_new(CMD_FAILURE, "focus", return cmd_results_new(CMD_FAILURE,
"Command 'focus' cannot be used above the workspace level"); "Command 'focus' cannot be used above the workspace level");
} }
@ -274,7 +274,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
} }
seat_set_focus_container(seat, container); seat_set_focus_container(seat, container);
seat_consider_warp_to_focus(seat); seat_consider_warp_to_focus(seat);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
if (strcmp(argv[0], "floating") == 0) { if (strcmp(argv[0], "floating") == 0) {
@ -300,7 +300,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
enum wlr_direction direction = 0; enum wlr_direction direction = 0;
if (!parse_direction(argv[0], &direction)) { if (!parse_direction(argv[0], &direction)) {
return cmd_results_new(CMD_INVALID, "focus", return cmd_results_new(CMD_INVALID,
"Expected 'focus <direction|parent|child|mode_toggle|floating|tiling>' " "Expected 'focus <direction|parent|child|mode_toggle|floating|tiling>' "
"or 'focus output <direction|name>'"); "or 'focus output <direction|name>'");
} }
@ -310,14 +310,14 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
struct sway_output *new_output = struct sway_output *new_output =
output_get_in_direction(workspace->output, direction); output_get_in_direction(workspace->output, direction);
if (!new_output) { if (!new_output) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct sway_node *node = struct sway_node *node =
get_node_in_output_direction(new_output, direction); get_node_in_output_direction(new_output, direction);
seat_set_focus(seat, node); seat_set_focus(seat, node);
seat_consider_warp_to_focus(seat); seat_consider_warp_to_focus(seat);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct sway_node *next_focus = struct sway_node *next_focus =
@ -327,5 +327,5 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
seat_consider_warp_to_focus(seat); seat_consider_warp_to_focus(seat);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -14,8 +14,8 @@ struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) {
} else if(strcmp(argv[0], "always") == 0) { } else if(strcmp(argv[0], "always") == 0) {
config->focus_follows_mouse = FOLLOWS_ALWAYS; config->focus_follows_mouse = FOLLOWS_ALWAYS;
} else { } else {
return cmd_results_new(CMD_FAILURE, "focus_follows_mouse", return cmd_results_new(CMD_FAILURE,
"Expected 'focus_follows_mouse no|yes|always'"); "Expected 'focus_follows_mouse no|yes|always'");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -16,10 +16,10 @@ struct cmd_results *cmd_focus_on_window_activation(int argc, char **argv) {
} else if (strcmp(argv[0], "none") == 0) { } else if (strcmp(argv[0], "none") == 0) {
config->focus_on_window_activation = FOWA_NONE; config->focus_on_window_activation = FOWA_NONE;
} else { } else {
return cmd_results_new(CMD_INVALID, "focus_on_window_activation", return cmd_results_new(CMD_INVALID,
"Expected " "Expected "
"'focus_on_window_activation smart|urgent|focus|none'"); "'focus_on_window_activation smart|urgent|focus|none'");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -17,5 +17,5 @@ struct cmd_results *cmd_focus_wrapping(int argc, char **argv) {
config->focus_wrapping = WRAP_NO; config->focus_wrapping = WRAP_NO;
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -23,5 +23,5 @@ struct cmd_results *cmd_font(int argc, char **argv) {
free(font); free(font);
config_update_font_height(true); config_update_font_height(true);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -14,7 +14,7 @@ struct cmd_results *cmd_for_window(int argc, char **argv) {
char *err_str = NULL; char *err_str = NULL;
struct criteria *criteria = criteria_parse(argv[0], &err_str); struct criteria *criteria = criteria_parse(argv[0], &err_str);
if (!criteria) { if (!criteria) {
error = cmd_results_new(CMD_INVALID, "for_window", err_str); error = cmd_results_new(CMD_INVALID, err_str);
free(err_str); free(err_str);
return error; return error;
} }
@ -25,5 +25,5 @@ struct cmd_results *cmd_for_window(int argc, char **argv) {
list_add(config->criteria, criteria); list_add(config->criteria, criteria);
wlr_log(WLR_DEBUG, "for_window: '%s' -> '%s' added", criteria->raw, criteria->cmdlist); wlr_log(WLR_DEBUG, "for_window: '%s' -> '%s' added", criteria->raw, criteria->cmdlist);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,12 +12,12 @@ struct cmd_results *cmd_force_display_urgency_hint(int argc, char **argv) {
int timeout = (int)strtol(argv[0], &err, 10); int timeout = (int)strtol(argv[0], &err, 10);
if (*err) { if (*err) {
if (strcmp(err, "ms") != 0) { if (strcmp(err, "ms") != 0) {
return cmd_results_new(CMD_INVALID, "force_display_urgency_hint", return cmd_results_new(CMD_INVALID,
"Expected 'force_display_urgency_hint <timeout> ms'"); "Expected 'force_display_urgency_hint <timeout> ms'");
} }
} }
config->urgent_timeout = timeout > 0 ? timeout : 0; config->urgent_timeout = timeout > 0 ? timeout : 0;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -16,5 +16,5 @@ struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) {
config->focus_wrapping = WRAP_YES; config->focus_wrapping = WRAP_YES;
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -13,14 +13,14 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) {
return error; return error;
} }
if (!root->outputs->length) { if (!root->outputs->length) {
return cmd_results_new(CMD_FAILURE, "fullscreen", return cmd_results_new(CMD_FAILURE,
"Can't run this command while there's no outputs connected."); "Can't run this command while there's no outputs connected.");
} }
struct sway_node *node = config->handler_context.node; struct sway_node *node = config->handler_context.node;
struct sway_container *container = config->handler_context.container; struct sway_container *container = config->handler_context.container;
struct sway_workspace *workspace = config->handler_context.workspace; struct sway_workspace *workspace = config->handler_context.workspace;
if (node->type == N_WORKSPACE && workspace->tiling->length == 0) { if (node->type == N_WORKSPACE && workspace->tiling->length == 0) {
return cmd_results_new(CMD_FAILURE, "fullscreen", return cmd_results_new(CMD_FAILURE,
"Can't fullscreen an empty workspace"); "Can't fullscreen an empty workspace");
} }
if (node->type == N_WORKSPACE) { if (node->type == N_WORKSPACE) {
@ -38,5 +38,5 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) {
container_set_fullscreen(container, enable); container_set_fullscreen(container, enable);
arrange_workspace(workspace); arrange_workspace(workspace);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -43,7 +43,7 @@ static void prevent_invalid_outer_gaps(void) {
} }
// gaps inner|outer|horizontal|vertical|top|right|bottom|left <px> // gaps inner|outer|horizontal|vertical|top|right|bottom|left <px>
static const char *expected_defaults = static const char expected_defaults[] =
"'gaps inner|outer|horizontal|vertical|top|right|bottom|left <px>'"; "'gaps inner|outer|horizontal|vertical|top|right|bottom|left <px>'";
static struct cmd_results *gaps_set_defaults(int argc, char **argv) { static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2); struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2);
@ -54,8 +54,7 @@ static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
char *end; char *end;
int amount = strtol(argv[1], &end, 10); int amount = strtol(argv[1], &end, 10);
if (strlen(end) && strcasecmp(end, "px") != 0) { if (strlen(end) && strcasecmp(end, "px") != 0) {
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID, "Expected %s", expected_defaults);
"Expected %s", expected_defaults);
} }
bool valid = false; bool valid = false;
@ -85,12 +84,11 @@ static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
} }
} }
if (!valid) { if (!valid) {
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID, "Expected %s", expected_defaults);
"Expected %s", expected_defaults);
} }
prevent_invalid_outer_gaps(); prevent_invalid_outer_gaps();
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
static void apply_gaps_op(int *prop, enum gaps_op op, int amount) { static void apply_gaps_op(int *prop, enum gaps_op op, int amount) {
@ -136,7 +134,7 @@ static void configure_gaps(struct sway_workspace *ws, void *_data) {
// gaps inner|outer|horizontal|vertical|top|right|bottom|left current|all // gaps inner|outer|horizontal|vertical|top|right|bottom|left current|all
// set|plus|minus <px> // set|plus|minus <px>
static const char *expected_runtime = "'gaps inner|outer|horizontal|vertical|" static const char expected_runtime[] = "'gaps inner|outer|horizontal|vertical|"
"top|right|bottom|left current|all set|plus|minus <px>'"; "top|right|bottom|left current|all set|plus|minus <px>'";
static struct cmd_results *gaps_set_runtime(int argc, char **argv) { static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4); struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4);
@ -144,7 +142,7 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
return error; return error;
} }
if (!root->outputs->length) { if (!root->outputs->length) {
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID,
"Can't run this command while there's no outputs connected."); "Can't run this command while there's no outputs connected.");
} }
@ -164,8 +162,7 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
} }
if (!data.inner && !data.outer.top && !data.outer.right && if (!data.inner && !data.outer.top && !data.outer.right &&
!data.outer.bottom && !data.outer.left) { !data.outer.bottom && !data.outer.left) {
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID, "Expected %s", expected_runtime);
"Expected %s", expected_runtime);
} }
bool all; bool all;
@ -174,8 +171,7 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
} else if (strcasecmp(argv[1], "all") == 0) { } else if (strcasecmp(argv[1], "all") == 0) {
all = true; all = true;
} else { } else {
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID, "Expected %s", expected_runtime);
"Expected %s", expected_runtime);
} }
if (strcasecmp(argv[2], "set") == 0) { if (strcasecmp(argv[2], "set") == 0) {
@ -185,15 +181,13 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
} else if (strcasecmp(argv[2], "minus") == 0) { } else if (strcasecmp(argv[2], "minus") == 0) {
data.operation = GAPS_OP_SUBTRACT; data.operation = GAPS_OP_SUBTRACT;
} else { } else {
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID, "Expected %s", expected_runtime);
"Expected %s", expected_runtime);
} }
char *end; char *end;
data.amount = strtol(argv[3], &end, 10); data.amount = strtol(argv[3], &end, 10);
if (strlen(end) && strcasecmp(end, "px") != 0) { if (strlen(end) && strcasecmp(end, "px") != 0) {
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID, "Expected %s", expected_runtime);
"Expected %s", expected_runtime);
} }
if (all) { if (all) {
@ -202,7 +196,7 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
configure_gaps(config->handler_context.workspace, &data); configure_gaps(config->handler_context.workspace, &data);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
// gaps inner|outer|<dir>|<side> <px> - sets defaults for workspaces // gaps inner|outer|<dir>|<side> <px> - sets defaults for workspaces
@ -224,9 +218,8 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
return gaps_set_runtime(argc, argv); return gaps_set_runtime(argc, argv);
} }
if (config_loading) { if (config_loading) {
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID, "Expected %s", expected_defaults);
"Expected %s", expected_defaults);
} }
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID, "Expected %s or %s",
"Expected %s or %s", expected_runtime, expected_defaults); expected_runtime, expected_defaults);
} }

View file

@ -22,13 +22,12 @@ struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) {
} else if (strcmp(argv[0], "smart_no_gaps") == 0) { } else if (strcmp(argv[0], "smart_no_gaps") == 0) {
config->hide_edge_borders = E_SMART_NO_GAPS; config->hide_edge_borders = E_SMART_NO_GAPS;
} else { } else {
return cmd_results_new(CMD_INVALID, "hide_edge_borders", return cmd_results_new(CMD_INVALID, "Expected 'hide_edge_borders "
"Expected 'hide_edge_borders "
"<none|vertical|horizontal|both|smart|smart_no_gaps>'"); "<none|vertical|horizontal|both|smart|smart_no_gaps>'");
} }
config->saved_edge_borders = config->hide_edge_borders; config->saved_edge_borders = config->hide_edge_borders;
arrange_root(); arrange_root();
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -9,9 +9,9 @@ struct cmd_results *cmd_include(int argc, char **argv) {
if (!load_include_configs(argv[0], config, if (!load_include_configs(argv[0], config,
&config->swaynag_config_errors)) { &config->swaynag_config_errors)) {
return cmd_results_new(CMD_INVALID, "include", return cmd_results_new(CMD_INVALID,
"Failed to include sub configuration file: %s", argv[0]); "Failed to include sub configuration file: %s", argv[0]);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -49,7 +49,7 @@ struct cmd_results *cmd_input(int argc, char **argv) {
config->handler_context.input_config = new_input_config(argv[0]); config->handler_context.input_config = new_input_config(argv[0]);
if (!config->handler_context.input_config) { if (!config->handler_context.input_config) {
return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config"); return cmd_results_new(CMD_FAILURE, "Couldn't allocate config");
} }
struct cmd_results *res; struct cmd_results *res;
@ -60,7 +60,7 @@ struct cmd_results *cmd_input(int argc, char **argv) {
res = config_subcommand(argv + 1, argc - 1, res = config_subcommand(argv + 1, argc - 1,
input_config_handlers, sizeof(input_config_handlers)); input_config_handlers, sizeof(input_config_handlers));
} else { } else {
res = cmd_results_new(CMD_FAILURE, "input", res = cmd_results_new(CMD_FAILURE,
"Can only be used in config file."); "Can only be used in config file.");
} }
} else { } else {

View file

@ -11,8 +11,7 @@ struct cmd_results *input_cmd_accel_profile(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "accel_profile", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
if (strcasecmp(argv[0], "adaptive") == 0) { if (strcasecmp(argv[0], "adaptive") == 0) {
@ -20,9 +19,9 @@ struct cmd_results *input_cmd_accel_profile(int argc, char **argv) {
} else if (strcasecmp(argv[0], "flat") == 0) { } else if (strcasecmp(argv[0], "flat") == 0) {
ic->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; ic->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
} else { } else {
return cmd_results_new(CMD_INVALID, "accel_profile", return cmd_results_new(CMD_INVALID,
"Expected 'accel_profile <adaptive|flat>'"); "Expected 'accel_profile <adaptive|flat>'");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,8 +12,7 @@ struct cmd_results *input_cmd_click_method(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "click_method", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
if (strcasecmp(argv[0], "none") == 0) { if (strcasecmp(argv[0], "none") == 0) {
@ -23,9 +22,9 @@ struct cmd_results *input_cmd_click_method(int argc, char **argv) {
} else if (strcasecmp(argv[0], "clickfinger") == 0) { } else if (strcasecmp(argv[0], "clickfinger") == 0) {
ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
} else { } else {
return cmd_results_new(CMD_INVALID, "click_method", return cmd_results_new(CMD_INVALID,
"Expected 'click_method <none|button_areas|clickfinger'>"); "Expected 'click_method <none|button_areas|clickfinger'>");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,8 +12,7 @@ struct cmd_results *input_cmd_drag(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No input device defined.");
"drag", "No input device defined.");
} }
if (parse_boolean(argv[0], true)) { if (parse_boolean(argv[0], true)) {
@ -22,5 +21,5 @@ struct cmd_results *input_cmd_drag(int argc, char **argv) {
ic->drag = LIBINPUT_CONFIG_DRAG_DISABLED; ic->drag = LIBINPUT_CONFIG_DRAG_DISABLED;
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,8 +12,7 @@ struct cmd_results *input_cmd_drag_lock(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No input device defined.");
"drag_lock", "No input device defined.");
} }
if (parse_boolean(argv[0], true)) { if (parse_boolean(argv[0], true)) {
@ -22,5 +21,5 @@ struct cmd_results *input_cmd_drag_lock(int argc, char **argv) {
ic->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; ic->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,7 +12,7 @@ struct cmd_results *input_cmd_dwt(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined."); return cmd_results_new(CMD_FAILURE, "No input device defined.");
} }
if (parse_boolean(argv[0], true)) { if (parse_boolean(argv[0], true)) {
@ -21,5 +21,5 @@ struct cmd_results *input_cmd_dwt(int argc, char **argv) {
ic->dwt = LIBINPUT_CONFIG_DWT_DISABLED; ic->dwt = LIBINPUT_CONFIG_DWT_DISABLED;
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -71,8 +71,7 @@ struct cmd_results *input_cmd_events(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "events", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
if (strcasecmp(argv[0], "enabled") == 0) { if (strcasecmp(argv[0], "enabled") == 0) {
@ -83,7 +82,7 @@ struct cmd_results *input_cmd_events(int argc, char **argv) {
ic->send_events = ic->send_events =
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
} else if (config->reading) { } else if (config->reading) {
return cmd_results_new(CMD_INVALID, "events", return cmd_results_new(CMD_INVALID,
"Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); "Expected 'events <enabled|disabled|disabled_on_external_mouse>'");
} else if (strcasecmp(argv[0], "toggle") == 0) { } else if (strcasecmp(argv[0], "toggle") == 0) {
if (strcmp(ic->identifier, "*") == 0) { if (strcmp(ic->identifier, "*") == 0) {
@ -97,10 +96,10 @@ struct cmd_results *input_cmd_events(int argc, char **argv) {
toggle_send_events(ic); toggle_send_events(ic);
} }
} else { } else {
return cmd_results_new(CMD_INVALID, "events", return cmd_results_new(CMD_INVALID,
"Expected 'events <enabled|disabled|disabled_on_external_mouse|" "Expected 'events <enabled|disabled|disabled_on_external_mouse|"
"toggle>'"); "toggle>'");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,11 +12,10 @@ struct cmd_results *input_cmd_left_handed(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "left_handed", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
ic->left_handed = parse_boolean(argv[0], true); ic->left_handed = parse_boolean(argv[0], true);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -40,8 +40,7 @@ struct cmd_results *input_cmd_map_from_region(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "map_from_region", return cmd_results_new(CMD_FAILURE, "No input device defined");
"No input device defined");
} }
ic->mapped_from_region = ic->mapped_from_region =
@ -52,30 +51,27 @@ struct cmd_results *input_cmd_map_from_region(int argc, char **argv) {
&ic->mapped_from_region->y1, &mm1)) { &ic->mapped_from_region->y1, &mm1)) {
free(ic->mapped_from_region); free(ic->mapped_from_region);
ic->mapped_from_region = NULL; ic->mapped_from_region = NULL;
return cmd_results_new(CMD_FAILURE, "map_from_region", return cmd_results_new(CMD_FAILURE, "Invalid top-left coordinates");
"Invalid top-left coordinates");
} }
if (!parse_coords(argv[1], &ic->mapped_from_region->x2, if (!parse_coords(argv[1], &ic->mapped_from_region->x2,
&ic->mapped_from_region->y2, &mm2)) { &ic->mapped_from_region->y2, &mm2)) {
free(ic->mapped_from_region); free(ic->mapped_from_region);
ic->mapped_from_region = NULL; ic->mapped_from_region = NULL;
return cmd_results_new(CMD_FAILURE, "map_from_region", return cmd_results_new(CMD_FAILURE, "Invalid bottom-right coordinates");
"Invalid bottom-right coordinates");
} }
if (ic->mapped_from_region->x1 > ic->mapped_from_region->x2 || if (ic->mapped_from_region->x1 > ic->mapped_from_region->x2 ||
ic->mapped_from_region->y1 > ic->mapped_from_region->y2) { ic->mapped_from_region->y1 > ic->mapped_from_region->y2) {
free(ic->mapped_from_region); free(ic->mapped_from_region);
ic->mapped_from_region = NULL; ic->mapped_from_region = NULL;
return cmd_results_new(CMD_FAILURE, "map_from_region", return cmd_results_new(CMD_FAILURE, "Invalid rectangle");
"Invalid rectangle");
} }
if (mm1 != mm2) { if (mm1 != mm2) {
free(ic->mapped_from_region); free(ic->mapped_from_region);
ic->mapped_from_region = NULL; ic->mapped_from_region = NULL;
return cmd_results_new(CMD_FAILURE, "map_from_region", return cmd_results_new(CMD_FAILURE,
"Both coordinates must be in the same unit"); "Both coordinates must be in the same unit");
} }
ic->mapped_from_region->mm = mm1; ic->mapped_from_region->mm = mm1;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -13,11 +13,10 @@ struct cmd_results *input_cmd_map_to_output(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "map_to_output", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
ic->mapped_to_output = strdup(argv[0]); ic->mapped_to_output = strdup(argv[0]);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,8 +12,7 @@ struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "middle_emulation", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
if (parse_boolean(argv[0], true)) { if (parse_boolean(argv[0], true)) {
@ -22,5 +21,5 @@ struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) {
ic->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; ic->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,11 +12,10 @@ struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "natural_scoll", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
ic->natural_scroll = parse_boolean(argv[0], true); ic->natural_scroll = parse_boolean(argv[0], true);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -13,19 +13,17 @@ struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No input device defined.");
"pointer_accel", "No input device defined.");
} }
float pointer_accel = parse_float(argv[0]); float pointer_accel = parse_float(argv[0]);
if (isnan(pointer_accel)) { if (isnan(pointer_accel)) {
return cmd_results_new(CMD_INVALID, "pointer_accel", return cmd_results_new(CMD_INVALID,
"Invalid pointer accel; expected float."); "Invalid pointer accel; expected float.");
} if (pointer_accel < -1 || pointer_accel > 1) { } if (pointer_accel < -1 || pointer_accel > 1) {
return cmd_results_new(CMD_INVALID, "pointer_accel", return cmd_results_new(CMD_INVALID, "Input out of range [-1, 1]");
"Input out of range [-1, 1]");
} }
ic->pointer_accel = pointer_accel; ic->pointer_accel = pointer_accel;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,16 +11,14 @@ struct cmd_results *input_cmd_repeat_delay(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No input device defined.");
"repeat_delay", "No input device defined.");
} }
int repeat_delay = atoi(argv[0]); int repeat_delay = atoi(argv[0]);
if (repeat_delay < 0) { if (repeat_delay < 0) {
return cmd_results_new(CMD_INVALID, "repeat_delay", return cmd_results_new(CMD_INVALID, "Repeat delay cannot be negative");
"Repeat delay cannot be negative");
} }
ic->repeat_delay = repeat_delay; ic->repeat_delay = repeat_delay;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,16 +11,14 @@ struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No input device defined.");
"repeat_rate", "No input device defined.");
} }
int repeat_rate = atoi(argv[0]); int repeat_rate = atoi(argv[0]);
if (repeat_rate < 0) { if (repeat_rate < 0) {
return cmd_results_new(CMD_INVALID, "repeat_rate", return cmd_results_new(CMD_INVALID, "Repeat rate cannot be negative");
"Repeat rate cannot be negative");
} }
ic->repeat_rate = repeat_rate; ic->repeat_rate = repeat_rate;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -10,30 +10,28 @@ struct cmd_results *input_cmd_scroll_button(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "scroll_button", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
if (strcmp(*argv, "disable") == 0) { if (strcmp(*argv, "disable") == 0) {
ic->scroll_button = 0; ic->scroll_button = 0;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
char *message = NULL; char *message = NULL;
uint32_t button = get_mouse_button(*argv, &message); uint32_t button = get_mouse_button(*argv, &message);
if (message) { if (message) {
error = cmd_results_new(CMD_INVALID, "scroll_button", message); error = cmd_results_new(CMD_INVALID, message);
free(message); free(message);
return error; return error;
} else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN } else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN
|| button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) { || button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) {
return cmd_results_new(CMD_INVALID, "scroll_button", return cmd_results_new(CMD_INVALID,
"X11 axis buttons are not supported for scroll_button"); "X11 axis buttons are not supported for scroll_button");
} else if (!button) { } else if (!button) {
return cmd_results_new(CMD_INVALID, "scroll_button", return cmd_results_new(CMD_INVALID, "Unknown button %s", *argv);
"Unknown button %s", *argv);
} }
ic->scroll_button = button; ic->scroll_button = button;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -14,19 +14,18 @@ struct cmd_results *input_cmd_scroll_factor(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "No input device defined.");
"scroll_factor", "No input device defined.");
} }
float scroll_factor = parse_float(argv[0]); float scroll_factor = parse_float(argv[0]);
if (isnan(scroll_factor)) { if (isnan(scroll_factor)) {
return cmd_results_new(CMD_INVALID, "scroll_factor", return cmd_results_new(CMD_INVALID,
"Invalid scroll factor; expected float."); "Invalid scroll factor; expected float.");
} else if (scroll_factor < 0) { } else if (scroll_factor < 0) {
return cmd_results_new(CMD_INVALID, "scroll_factor", return cmd_results_new(CMD_INVALID,
"Scroll factor cannot be negative."); "Scroll factor cannot be negative.");
} }
ic->scroll_factor = scroll_factor; ic->scroll_factor = scroll_factor;
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,8 +11,7 @@ struct cmd_results *input_cmd_scroll_method(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "scroll_method", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
if (strcasecmp(argv[0], "none") == 0) { if (strcasecmp(argv[0], "none") == 0) {
@ -24,9 +23,9 @@ struct cmd_results *input_cmd_scroll_method(int argc, char **argv) {
} else if (strcasecmp(argv[0], "on_button_down") == 0) { } else if (strcasecmp(argv[0], "on_button_down") == 0) {
ic->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; ic->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
} else { } else {
return cmd_results_new(CMD_INVALID, "scroll_method", return cmd_results_new(CMD_INVALID,
"Expected 'scroll_method <none|two_finger|edge|on_button_down>'"); "Expected 'scroll_method <none|two_finger|edge|on_button_down>'");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -13,7 +13,7 @@ struct cmd_results *input_cmd_tap(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "tap", "No input device defined."); return cmd_results_new(CMD_FAILURE, "No input device defined.");
} }
if (parse_boolean(argv[0], true)) { if (parse_boolean(argv[0], true)) {
@ -22,5 +22,5 @@ struct cmd_results *input_cmd_tap(int argc, char **argv) {
ic->tap = LIBINPUT_CONFIG_TAP_DISABLED; ic->tap = LIBINPUT_CONFIG_TAP_DISABLED;
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,8 +11,7 @@ struct cmd_results *input_cmd_tap_button_map(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "tap_button_map", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
if (strcasecmp(argv[0], "lrm") == 0) { if (strcasecmp(argv[0], "lrm") == 0) {
@ -20,9 +19,9 @@ struct cmd_results *input_cmd_tap_button_map(int argc, char **argv) {
} else if (strcasecmp(argv[0], "lmr") == 0) { } else if (strcasecmp(argv[0], "lmr") == 0) {
ic->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LMR; ic->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LMR;
} else { } else {
return cmd_results_new(CMD_INVALID, "tap_button_map", return cmd_results_new(CMD_INVALID,
"Expected 'tap_button_map <lrm|lmr>'"); "Expected 'tap_button_map <lrm|lmr>'");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,11 +12,10 @@ struct cmd_results *input_cmd_xkb_capslock(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "xkb_capslock", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
ic->xkb_capslock = parse_boolean(argv[0], false); ic->xkb_capslock = parse_boolean(argv[0], false);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,13 +11,12 @@ struct cmd_results *input_cmd_xkb_layout(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "xkb_layout", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
ic->xkb_layout = strdup(argv[0]); ic->xkb_layout = strdup(argv[0]);
wlr_log(WLR_DEBUG, "set-xkb_layout for config: %s layout: %s", wlr_log(WLR_DEBUG, "set-xkb_layout for config: %s layout: %s",
ic->identifier, ic->xkb_layout); ic->identifier, ic->xkb_layout);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,13 +11,12 @@ struct cmd_results *input_cmd_xkb_model(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "xkb_model", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
ic->xkb_model = strdup(argv[0]); ic->xkb_model = strdup(argv[0]);
wlr_log(WLR_DEBUG, "set-xkb_model for config: %s model: %s", wlr_log(WLR_DEBUG, "set-xkb_model for config: %s model: %s",
ic->identifier, ic->xkb_model); ic->identifier, ic->xkb_model);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -12,11 +12,10 @@ struct cmd_results *input_cmd_xkb_numlock(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "xkb_numlock", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
ic->xkb_numlock = parse_boolean(argv[0], false); ic->xkb_numlock = parse_boolean(argv[0], false);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,13 +11,12 @@ struct cmd_results *input_cmd_xkb_options(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "xkb_options", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
ic->xkb_options = strdup(argv[0]); ic->xkb_options = strdup(argv[0]);
wlr_log(WLR_DEBUG, "set-xkb_options for config: %s options: %s", wlr_log(WLR_DEBUG, "set-xkb_options for config: %s options: %s",
ic->identifier, ic->xkb_options); ic->identifier, ic->xkb_options);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,13 +11,12 @@ struct cmd_results *input_cmd_xkb_rules(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "xkb_rules", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
ic->xkb_rules = strdup(argv[0]); ic->xkb_rules = strdup(argv[0]);
wlr_log(WLR_DEBUG, "set-xkb_rules for config: %s rules: %s", wlr_log(WLR_DEBUG, "set-xkb_rules for config: %s rules: %s",
ic->identifier, ic->xkb_rules); ic->identifier, ic->xkb_rules);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -11,13 +11,12 @@ struct cmd_results *input_cmd_xkb_variant(int argc, char **argv) {
} }
struct input_config *ic = config->handler_context.input_config; struct input_config *ic = config->handler_context.input_config;
if (!ic) { if (!ic) {
return cmd_results_new(CMD_FAILURE, "xkb_variant", return cmd_results_new(CMD_FAILURE, "No input device defined.");
"No input device defined.");
} }
ic->xkb_variant = strdup(argv[0]); ic->xkb_variant = strdup(argv[0]);
wlr_log(WLR_DEBUG, "set-xkb_variant for config: %s variant: %s", wlr_log(WLR_DEBUG, "set-xkb_variant for config: %s variant: %s",
ic->identifier, ic->xkb_variant); ic->identifier, ic->xkb_variant);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -15,7 +15,7 @@ static void close_container_iterator(struct sway_container *con, void *data) {
struct cmd_results *cmd_kill(int argc, char **argv) { struct cmd_results *cmd_kill(int argc, char **argv) {
if (!root->outputs->length) { if (!root->outputs->length) {
return cmd_results_new(CMD_INVALID, "kill", return cmd_results_new(CMD_INVALID,
"Can't run this command while there's no outputs connected."); "Can't run this command while there's no outputs connected.");
} }
struct sway_container *con = config->handler_context.container; struct sway_container *con = config->handler_context.container;
@ -28,5 +28,5 @@ struct cmd_results *cmd_kill(int argc, char **argv) {
workspace_for_each_container(ws, close_container_iterator, NULL); workspace_for_each_container(ws, close_container_iterator, NULL);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -20,7 +20,7 @@ static enum sway_container_layout parse_layout_string(char *s) {
return L_NONE; return L_NONE;
} }
static const char* expected_syntax = static const char expected_syntax[] =
"Expected 'layout default|tabbed|stacking|splitv|splith' or " "Expected 'layout default|tabbed|stacking|splitv|splith' or "
"'layout toggle [split|all]' or " "'layout toggle [split|all]' or "
"'layout toggle [split|tabbed|stacking|splitv|splith] [split|tabbed|stacking|splitv|splith]...'"; "'layout toggle [split|tabbed|stacking|splitv|splith] [split|tabbed|stacking|splitv|splith]...'";
@ -100,14 +100,14 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
return error; return error;
} }
if (!root->outputs->length) { if (!root->outputs->length) {
return cmd_results_new(CMD_INVALID, "layout", return cmd_results_new(CMD_INVALID,
"Can't run this command while there's no outputs connected."); "Can't run this command while there's no outputs connected.");
} }
struct sway_container *container = config->handler_context.container; struct sway_container *container = config->handler_context.container;
struct sway_workspace *workspace = config->handler_context.workspace; struct sway_workspace *workspace = config->handler_context.workspace;
if (container && container_is_floating(container)) { if (container && container_is_floating(container)) {
return cmd_results_new(CMD_FAILURE, "layout", return cmd_results_new(CMD_FAILURE,
"Unable to change layout of floating windows"); "Unable to change layout of floating windows");
} }
@ -133,7 +133,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
workspace->layout, workspace->prev_split_layout); workspace->layout, workspace->prev_split_layout);
} }
if (new_layout == L_NONE) { if (new_layout == L_NONE) {
return cmd_results_new(CMD_INVALID, "layout", expected_syntax); return cmd_results_new(CMD_INVALID, expected_syntax);
} }
if (new_layout != old_layout) { if (new_layout != old_layout) {
if (container) { if (container) {
@ -152,5 +152,5 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
arrange_workspace(workspace); arrange_workspace(workspace);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -20,8 +20,7 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
} }
struct sway_container *container = config->handler_context.container; struct sway_container *container = config->handler_context.container;
if (!container) { if (!container) {
return cmd_results_new(CMD_INVALID, "mark", return cmd_results_new(CMD_INVALID, "Only containers can have marks");
"Only containers can have marks");
} }
bool add = false, toggle = false; bool add = false, toggle = false;
@ -33,7 +32,7 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
} else if (strcmp(*argv, "--toggle") == 0) { } else if (strcmp(*argv, "--toggle") == 0) {
toggle = true; toggle = true;
} else { } else {
return cmd_results_new(CMD_INVALID, "mark", return cmd_results_new(CMD_INVALID,
"Unrecognized argument '%s'", *argv); "Unrecognized argument '%s'", *argv);
} }
++argv; ++argv;
@ -41,7 +40,7 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
} }
if (!argc) { if (!argc) {
return cmd_results_new(CMD_INVALID, "mark", return cmd_results_new(CMD_INVALID,
"Expected '[--add|--replace] [--toggle] <identifier>'"); "Expected '[--add|--replace] [--toggle] <identifier>'");
} }
@ -65,5 +64,5 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
view_execute_criteria(container->view); view_execute_criteria(container->view);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -22,16 +22,14 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
} }
if (argc > 1 && !config->reading) { if (argc > 1 && !config->reading) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "Can only be used in config file");
"mode", "Can only be used in config file.");
} }
bool pango = strcmp(*argv, "--pango_markup") == 0; bool pango = strcmp(*argv, "--pango_markup") == 0;
if (pango) { if (pango) {
argc--; argv++; argc--; argv++;
if (argc == 0) { if (argc == 0) {
return cmd_results_new(CMD_FAILURE, "mode", return cmd_results_new(CMD_FAILURE, "Mode name is missing");
"Mode name is missing");
} }
} }
@ -50,8 +48,7 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
if (!mode && argc > 1) { if (!mode && argc > 1) {
mode = calloc(1, sizeof(struct sway_mode)); mode = calloc(1, sizeof(struct sway_mode));
if (!mode) { if (!mode) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE, "Unable to allocate mode");
"mode", "Unable to allocate mode");
} }
mode->name = strdup(mode_name); mode->name = strdup(mode_name);
mode->keysym_bindings = create_list(); mode->keysym_bindings = create_list();
@ -61,8 +58,7 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
list_add(config->modes, mode); list_add(config->modes, mode);
} }
if (!mode) { if (!mode) {
error = cmd_results_new(CMD_INVALID, error = cmd_results_new(CMD_INVALID, "Unknown mode `%s'", mode_name);
"mode", "Unknown mode `%s'", mode_name);
return error; return error;
} }
if ((config->reading && argc > 1) || (!config->reading && argc == 1)) { if ((config->reading && argc > 1) || (!config->reading && argc == 1)) {
@ -75,7 +71,7 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
// trigger IPC mode event // trigger IPC mode event
ipc_event_mode(config->current_mode->name, ipc_event_mode(config->current_mode->name,
config->current_mode->pango); config->current_mode->pango);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
// Create binding // Create binding

View file

@ -13,9 +13,9 @@ struct cmd_results *cmd_mouse_warping(int argc, char **argv) {
} else if (strcasecmp(argv[0], "none") == 0) { } else if (strcasecmp(argv[0], "none") == 0) {
config->mouse_warping = WARP_NO; config->mouse_warping = WARP_NO;
} else { } else {
return cmd_results_new(CMD_FAILURE, "mouse_warping", return cmd_results_new(CMD_FAILURE,
"Expected 'mouse_warping output|container|none'"); "Expected 'mouse_warping output|container|none'");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -21,7 +21,7 @@
#include "log.h" #include "log.h"
#include "util.h" #include "util.h"
static const char *expected_syntax = static const char expected_syntax[] =
"Expected 'move <left|right|up|down> <[px] px>' or " "Expected 'move <left|right|up|down> <[px] px>' or "
"'move [--no-auto-back-and-forth] <container|window> [to] workspace <name>' or " "'move [--no-auto-back-and-forth] <container|window> [to] workspace <name>' or "
"'move <container|window|workspace> [to] output <name|direction>' or " "'move <container|window|workspace> [to] output <name|direction>' or "
@ -378,7 +378,7 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
struct sway_container *container = config->handler_context.container; struct sway_container *container = config->handler_context.container;
if (node->type == N_WORKSPACE) { if (node->type == N_WORKSPACE) {
if (workspace->tiling->length == 0) { if (workspace->tiling->length == 0) {
return cmd_results_new(CMD_FAILURE, "move", return cmd_results_new(CMD_FAILURE,
"Can't move an empty workspace"); "Can't move an empty workspace");
} }
container = workspace_wrap_children(workspace); container = workspace_wrap_children(workspace);
@ -388,21 +388,21 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
while (strcasecmp(argv[0], "--no-auto-back-and-forth") == 0) { while (strcasecmp(argv[0], "--no-auto-back-and-forth") == 0) {
no_auto_back_and_forth = true; no_auto_back_and_forth = true;
if (--argc < 3) { if (--argc < 3) {
return cmd_results_new(CMD_INVALID, "move", expected_syntax); return cmd_results_new(CMD_INVALID, expected_syntax);
} }
++argv; ++argv;
} }
while (strcasecmp(argv[1], "--no-auto-back-and-forth") == 0) { while (strcasecmp(argv[1], "--no-auto-back-and-forth") == 0) {
no_auto_back_and_forth = true; no_auto_back_and_forth = true;
if (--argc < 3) { if (--argc < 3) {
return cmd_results_new(CMD_INVALID, "move", expected_syntax); return cmd_results_new(CMD_INVALID, expected_syntax);
} }
argv++; argv++;
} }
while (strcasecmp(argv[1], "to") == 0) { while (strcasecmp(argv[1], "to") == 0) {
if (--argc < 3) { if (--argc < 3) {
return cmd_results_new(CMD_INVALID, "move", expected_syntax); return cmd_results_new(CMD_INVALID, expected_syntax);
} }
argv++; argv++;
} }
@ -429,7 +429,7 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
if (seat->prev_workspace_name) { if (seat->prev_workspace_name) {
ws_name = strdup(seat->prev_workspace_name); ws_name = strdup(seat->prev_workspace_name);
} else { } else {
return cmd_results_new(CMD_FAILURE, "move", return cmd_results_new(CMD_FAILURE,
"No workspace was previously active."); "No workspace was previously active.");
} }
} }
@ -437,11 +437,10 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
if (strcasecmp(argv[2], "number") == 0) { if (strcasecmp(argv[2], "number") == 0) {
// move "container to workspace number x" // move "container to workspace number x"
if (argc < 4) { if (argc < 4) {
return cmd_results_new(CMD_INVALID, "move", return cmd_results_new(CMD_INVALID, expected_syntax);
expected_syntax);
} }
if (!isdigit(argv[3][0])) { if (!isdigit(argv[3][0])) {
return cmd_results_new(CMD_INVALID, "move", return cmd_results_new(CMD_INVALID,
"Invalid workspace number '%s'", argv[3]); "Invalid workspace number '%s'", argv[3]);
} }
ws_name = join_args(argv + 3, argc - 3); ws_name = join_args(argv + 3, argc - 3);
@ -472,7 +471,7 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
workspace_get_initial_output(ws_name); workspace_get_initial_output(ws_name);
if (old_output == new_output) { if (old_output == new_output) {
free(ws_name); free(ws_name);
return cmd_results_new(CMD_FAILURE, "move", return cmd_results_new(CMD_FAILURE,
"Can't move sticky container to another workspace " "Can't move sticky container to another workspace "
"on the same output"); "on the same output");
} }
@ -486,24 +485,24 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
struct sway_output *new_output = output_in_direction(argv[2], struct sway_output *new_output = output_in_direction(argv[2],
old_output, container->x, container->y); old_output, container->x, container->y);
if (!new_output) { if (!new_output) {
return cmd_results_new(CMD_FAILURE, "move workspace", return cmd_results_new(CMD_FAILURE,
"Can't find output with name/direction '%s'", argv[2]); "Can't find output with name/direction '%s'", argv[2]);
} }
destination = seat_get_focus_inactive(seat, &new_output->node); destination = seat_get_focus_inactive(seat, &new_output->node);
} else if (strcasecmp(argv[1], "mark") == 0) { } else if (strcasecmp(argv[1], "mark") == 0) {
struct sway_container *dest_con = container_find_mark(argv[2]); struct sway_container *dest_con = container_find_mark(argv[2]);
if (dest_con == NULL) { if (dest_con == NULL) {
return cmd_results_new(CMD_FAILURE, "move", return cmd_results_new(CMD_FAILURE,
"Mark '%s' not found", argv[2]); "Mark '%s' not found", argv[2]);
} }
destination = &dest_con->node; destination = &dest_con->node;
} else { } else {
return cmd_results_new(CMD_INVALID, "move", expected_syntax); return cmd_results_new(CMD_INVALID, expected_syntax);
} }
if (container->is_sticky && old_output && if (container->is_sticky && old_output &&
node_has_ancestor(destination, &old_output->node)) { node_has_ancestor(destination, &old_output->node)) {
return cmd_results_new(CMD_FAILURE, "move", "Can't move sticky " return cmd_results_new(CMD_FAILURE, "Can't move sticky "
"container to another workspace on the same output"); "container to another workspace on the same output");
} }
@ -569,7 +568,7 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
} }
arrange_node(node_get_parent(destination)); arrange_node(node_get_parent(destination));
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
static void workspace_move_to_output(struct sway_workspace *workspace, static void workspace_move_to_output(struct sway_workspace *workspace,
@ -611,13 +610,13 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) {
while (strcasecmp(argv[1], "to") == 0) { while (strcasecmp(argv[1], "to") == 0) {
if (--argc < 3) { if (--argc < 3) {
return cmd_results_new(CMD_INVALID, "move", expected_syntax); return cmd_results_new(CMD_INVALID, expected_syntax);
} }
++argv; ++argv;
} }
if (strcasecmp(argv[1], "output") != 0) { if (strcasecmp(argv[1], "output") != 0) {
return cmd_results_new(CMD_INVALID, "move", expected_syntax); return cmd_results_new(CMD_INVALID, expected_syntax);
} }
struct sway_workspace *workspace = config->handler_context.workspace; struct sway_workspace *workspace = config->handler_context.workspace;
@ -627,7 +626,7 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) {
struct sway_output *new_output = output_in_direction(argv[2], struct sway_output *new_output = output_in_direction(argv[2],
old_output, center_x, center_y); old_output, center_x, center_y);
if (!new_output) { if (!new_output) {
return cmd_results_new(CMD_FAILURE, "move workspace", return cmd_results_new(CMD_FAILURE,
"Can't find output with name/direction '%s'", argv[2]); "Can't find output with name/direction '%s'", argv[2]);
} }
workspace_move_to_output(workspace, new_output); workspace_move_to_output(workspace, new_output);
@ -635,7 +634,7 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) {
arrange_output(old_output); arrange_output(old_output);
arrange_output(new_output); arrange_output(new_output);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
static struct cmd_results *cmd_move_in_direction( static struct cmd_results *cmd_move_in_direction(
@ -645,19 +644,18 @@ static struct cmd_results *cmd_move_in_direction(
char *inv; char *inv;
move_amt = (int)strtol(argv[1], &inv, 10); move_amt = (int)strtol(argv[1], &inv, 10);
if (*inv != '\0' && strcasecmp(inv, "px") != 0) { if (*inv != '\0' && strcasecmp(inv, "px") != 0) {
return cmd_results_new(CMD_FAILURE, "move", return cmd_results_new(CMD_FAILURE, "Invalid distance specified");
"Invalid distance specified");
} }
} }
struct sway_container *container = config->handler_context.container; struct sway_container *container = config->handler_context.container;
if (!container) { if (!container) {
return cmd_results_new(CMD_FAILURE, "move", return cmd_results_new(CMD_FAILURE,
"Cannot move workspaces in a direction"); "Cannot move workspaces in a direction");
} }
if (container_is_floating(container)) { if (container_is_floating(container)) {
if (container->is_fullscreen) { if (container->is_fullscreen) {
return cmd_results_new(CMD_FAILURE, "move", return cmd_results_new(CMD_FAILURE,
"Cannot move fullscreen floating container"); "Cannot move fullscreen floating container");
} }
double lx = container->x; double lx = container->x;
@ -677,13 +675,13 @@ static struct cmd_results *cmd_move_in_direction(
break; break;
} }
container_floating_move_to(container, lx, ly); container_floating_move_to(container, lx, ly);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct sway_workspace *old_ws = container->workspace; struct sway_workspace *old_ws = container->workspace;
if (!container_move_in_direction(container, direction)) { if (!container_move_in_direction(container, direction)) {
// Container didn't move // Container didn't move
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct sway_workspace *new_ws = container->workspace; struct sway_workspace *new_ws = container->workspace;
@ -708,10 +706,10 @@ static struct cmd_results *cmd_move_in_direction(
} }
container_end_mouse_operation(container); container_end_mouse_operation(container);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
static const char *expected_position_syntax = static const char expected_position_syntax[] =
"Expected 'move [absolute] position <x> [px] <y> [px]' or " "Expected 'move [absolute] position <x> [px] <y> [px]' or "
"'move [absolute] position center' or " "'move [absolute] position center' or "
"'move position cursor|mouse|pointer'"; "'move position cursor|mouse|pointer'";
@ -719,12 +717,11 @@ static const char *expected_position_syntax =
static struct cmd_results *cmd_move_to_position(int argc, char **argv) { static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
struct sway_container *container = config->handler_context.container; struct sway_container *container = config->handler_context.container;
if (!container || !container_is_floating(container)) { if (!container || !container_is_floating(container)) {
return cmd_results_new(CMD_FAILURE, "move", return cmd_results_new(CMD_FAILURE, "Only floating containers "
"Only floating containers "
"can be moved to an absolute position"); "can be moved to an absolute position");
} }
if (!argc) { if (!argc) {
return cmd_results_new(CMD_FAILURE, "move", expected_position_syntax); return cmd_results_new(CMD_FAILURE, expected_position_syntax);
} }
bool absolute = false; bool absolute = false;
@ -734,25 +731,25 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
++argv; ++argv;
} }
if (!argc) { if (!argc) {
return cmd_results_new(CMD_FAILURE, "move", expected_position_syntax); return cmd_results_new(CMD_FAILURE, expected_position_syntax);
} }
if (strcmp(argv[0], "position") == 0) { if (strcmp(argv[0], "position") == 0) {
--argc; --argc;
++argv; ++argv;
} }
if (!argc) { if (!argc) {
return cmd_results_new(CMD_FAILURE, "move", expected_position_syntax); return cmd_results_new(CMD_FAILURE, expected_position_syntax);
} }
if (strcmp(argv[0], "cursor") == 0 || strcmp(argv[0], "mouse") == 0 || if (strcmp(argv[0], "cursor") == 0 || strcmp(argv[0], "mouse") == 0 ||
strcmp(argv[0], "pointer") == 0) { strcmp(argv[0], "pointer") == 0) {
struct sway_seat *seat = config->handler_context.seat; struct sway_seat *seat = config->handler_context.seat;
if (!seat->cursor) { if (!seat->cursor) {
return cmd_results_new(CMD_FAILURE, "move", "No cursor device"); return cmd_results_new(CMD_FAILURE, "No cursor device");
} }
double lx = seat->cursor->cursor->x - container->width / 2; double lx = seat->cursor->cursor->x - container->width / 2;
double ly = seat->cursor->cursor->y - container->height / 2; double ly = seat->cursor->cursor->y - container->height / 2;
container_floating_move_to(container, lx, ly); container_floating_move_to(container, lx, ly);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} else if (strcmp(argv[0], "center") == 0) { } else if (strcmp(argv[0], "center") == 0) {
double lx, ly; double lx, ly;
if (absolute) { if (absolute) {
@ -764,19 +761,18 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
ly = ws->y + (ws->height - container->height) / 2; ly = ws->y + (ws->height - container->height) / 2;
} }
container_floating_move_to(container, lx, ly); container_floating_move_to(container, lx, ly);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
if (argc < 2) { if (argc < 2) {
return cmd_results_new(CMD_FAILURE, "move", expected_position_syntax); return cmd_results_new(CMD_FAILURE, expected_position_syntax);
} }
double lx, ly; double lx, ly;
char *inv; char *inv;
lx = (double)strtol(argv[0], &inv, 10); lx = (double)strtol(argv[0], &inv, 10);
if (*inv != '\0' && strcasecmp(inv, "px") != 0) { if (*inv != '\0' && strcasecmp(inv, "px") != 0) {
return cmd_results_new(CMD_FAILURE, "move", return cmd_results_new(CMD_FAILURE, "Invalid position specified");
"Invalid position specified");
} }
if (strcmp(argv[1], "px") == 0) { if (strcmp(argv[1], "px") == 0) {
--argc; --argc;
@ -784,14 +780,13 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
} }
if (argc > 3) { if (argc > 3) {
return cmd_results_new(CMD_FAILURE, "move", expected_position_syntax); return cmd_results_new(CMD_FAILURE, expected_position_syntax);
} }
ly = (double)strtol(argv[1], &inv, 10); ly = (double)strtol(argv[1], &inv, 10);
if ((*inv != '\0' && strcasecmp(inv, "px") != 0) || if ((*inv != '\0' && strcasecmp(inv, "px") != 0) ||
(argc == 3 && strcmp(argv[2], "px") != 0)) { (argc == 3 && strcmp(argv[2], "px") != 0)) {
return cmd_results_new(CMD_FAILURE, "move", return cmd_results_new(CMD_FAILURE, "Invalid position specified");
"Invalid position specified");
} }
if (!absolute) { if (!absolute) {
@ -799,7 +794,7 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
ly += container->workspace->y; ly += container->workspace->y;
} }
container_floating_move_to(container, lx, ly); container_floating_move_to(container, lx, ly);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
static struct cmd_results *cmd_move_to_scratchpad(void) { static struct cmd_results *cmd_move_to_scratchpad(void) {
@ -807,7 +802,7 @@ static struct cmd_results *cmd_move_to_scratchpad(void) {
struct sway_container *con = config->handler_context.container; struct sway_container *con = config->handler_context.container;
struct sway_workspace *ws = config->handler_context.workspace; struct sway_workspace *ws = config->handler_context.workspace;
if (node->type == N_WORKSPACE && ws->tiling->length == 0) { if (node->type == N_WORKSPACE && ws->tiling->length == 0) {
return cmd_results_new(CMD_INVALID, "move", return cmd_results_new(CMD_INVALID,
"Can't move an empty workspace to the scratchpad"); "Can't move an empty workspace to the scratchpad");
} }
if (node->type == N_WORKSPACE) { if (node->type == N_WORKSPACE) {
@ -825,11 +820,11 @@ static struct cmd_results *cmd_move_to_scratchpad(void) {
} }
if (con->scratchpad) { if (con->scratchpad) {
return cmd_results_new(CMD_INVALID, "move", return cmd_results_new(CMD_INVALID,
"Container is already in the scratchpad"); "Container is already in the scratchpad");
} }
root_scratchpad_add_container(con); root_scratchpad_add_container(con);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct cmd_results *cmd_move(int argc, char **argv) { struct cmd_results *cmd_move(int argc, char **argv) {
@ -838,7 +833,7 @@ struct cmd_results *cmd_move(int argc, char **argv) {
return error; return error;
} }
if (!root->outputs->length) { if (!root->outputs->length) {
return cmd_results_new(CMD_INVALID, "move", return cmd_results_new(CMD_INVALID,
"Can't run this command while there's no outputs connected."); "Can't run this command while there's no outputs connected.");
} }
@ -867,7 +862,7 @@ struct cmd_results *cmd_move(int argc, char **argv) {
} else if (strcasecmp(argv[0], "absolute") == 0) { } else if (strcasecmp(argv[0], "absolute") == 0) {
return cmd_move_to_position(argc, argv); return cmd_move_to_position(argc, argv);
} else { } else {
return cmd_results_new(CMD_INVALID, "move", expected_syntax); return cmd_results_new(CMD_INVALID, expected_syntax);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -13,7 +13,7 @@ struct cmd_results *cmd_no_focus(int argc, char **argv) {
char *err_str = NULL; char *err_str = NULL;
struct criteria *criteria = criteria_parse(argv[0], &err_str); struct criteria *criteria = criteria_parse(argv[0], &err_str);
if (!criteria) { if (!criteria) {
error = cmd_results_new(CMD_INVALID, "no_focus", err_str); error = cmd_results_new(CMD_INVALID, err_str);
free(err_str); free(err_str);
return error; return error;
} }
@ -21,5 +21,5 @@ struct cmd_results *cmd_no_focus(int argc, char **argv) {
criteria->type = CT_NO_FOCUS; criteria->type = CT_NO_FOCUS;
list_add(config->criteria, criteria); list_add(config->criteria, criteria);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -1,5 +1,5 @@
#include "sway/commands.h" #include "sway/commands.h"
struct cmd_results *cmd_nop(int argc, char **argv) { struct cmd_results *cmd_nop(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -22,18 +22,18 @@ struct cmd_results *cmd_opacity(int argc, char **argv) {
struct sway_container *con = config->handler_context.container; struct sway_container *con = config->handler_context.container;
if (con == NULL) { if (con == NULL) {
return cmd_results_new(CMD_FAILURE, "opacity", "No current container"); return cmd_results_new(CMD_FAILURE, "No current container");
} }
float opacity = 0.0f; float opacity = 0.0f;
if (!parse_opacity(argv[0], &opacity)) { if (!parse_opacity(argv[0], &opacity)) {
return cmd_results_new(CMD_INVALID, "opacity <value>", return cmd_results_new(CMD_INVALID,
"Invalid value (expected 0..1): %s", argv[0]); "Invalid value (expected 0..1): %s", argv[0]);
} }
con->alpha = opacity; con->alpha = opacity;
container_damage_whole(con); container_damage_whole(con);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }

View file

@ -43,7 +43,7 @@ struct cmd_results *cmd_output(int argc, char **argv) {
error = config_subcommand(argv, argc, output_handlers, error = config_subcommand(argv, argc, output_handlers,
sizeof(output_handlers)); sizeof(output_handlers));
} else { } else {
error = cmd_results_new(CMD_INVALID, "output", error = cmd_results_new(CMD_INVALID,
"Invalid output subcommand: %s.", *argv); "Invalid output subcommand: %s.", *argv);
} }
@ -68,7 +68,7 @@ struct cmd_results *cmd_output(int argc, char **argv) {
apply_output_config_to_outputs(output); apply_output_config_to_outputs(output);
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
fail: fail:
config->handler_context.output_config = NULL; config->handler_context.output_config = NULL;

View file

@ -20,14 +20,14 @@ static const char *bg_options[] = {
struct cmd_results *output_cmd_background(int argc, char **argv) { struct cmd_results *output_cmd_background(int argc, char **argv) {
if (!config->handler_context.output_config) { if (!config->handler_context.output_config) {
return cmd_results_new(CMD_FAILURE, "output", "Missing output config"); return cmd_results_new(CMD_FAILURE, "Missing output config");
} }
if (!argc) { if (!argc) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID,
"Missing background file or color specification."); "Missing background file or color specification.");
} }
if (argc < 2) { if (argc < 2) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID,
"Missing background scaling mode or `solid_color`."); "Missing background scaling mode or `solid_color`.");
} }
@ -57,7 +57,7 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
} }
} }
if (!valid) { if (!valid) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID,
"Missing background scaling mode."); "Missing background scaling mode.");
} }
@ -70,7 +70,7 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
*ptr = '\\'; *ptr = '\\';
} }
if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) {
struct cmd_results *cmd_res = cmd_results_new(CMD_INVALID, "output", struct cmd_results *cmd_res = cmd_results_new(CMD_INVALID,
"Invalid syntax (%s)", src); "Invalid syntax (%s)", src);
free(src); free(src);
wordfree(&p); wordfree(&p);
@ -81,8 +81,7 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
wordfree(&p); wordfree(&p);
if (!src) { if (!src) {
wlr_log(WLR_ERROR, "Failed to duplicate string"); wlr_log(WLR_ERROR, "Failed to duplicate string");
return cmd_results_new(CMD_FAILURE, "output", return cmd_results_new(CMD_FAILURE, "Unable to allocate resource");
"Unable to allocate resource");
} }
if (config->reading && *src != '/') { if (config->reading && *src != '/') {
@ -92,7 +91,7 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
if (!conf) { if (!conf) {
wlr_log(WLR_ERROR, "Failed to duplicate string"); wlr_log(WLR_ERROR, "Failed to duplicate string");
free(src); free(src);
return cmd_results_new(CMD_FAILURE, "output", return cmd_results_new(CMD_FAILURE,
"Unable to allocate resources"); "Unable to allocate resources");
} }
@ -103,7 +102,7 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
free(rel_path); free(rel_path);
free(conf); free(conf);
wlr_log(WLR_ERROR, "Unable to allocate memory"); wlr_log(WLR_ERROR, "Unable to allocate memory");
return cmd_results_new(CMD_FAILURE, "output", return cmd_results_new(CMD_FAILURE,
"Unable to allocate resources"); "Unable to allocate resources");
} }

View file

@ -3,7 +3,7 @@
struct cmd_results *output_cmd_disable(int argc, char **argv) { struct cmd_results *output_cmd_disable(int argc, char **argv) {
if (!config->handler_context.output_config) { if (!config->handler_context.output_config) {
return cmd_results_new(CMD_FAILURE, "output", "Missing output config"); return cmd_results_new(CMD_FAILURE, "Missing output config");
} }
config->handler_context.output_config->enabled = 0; config->handler_context.output_config->enabled = 0;

View file

@ -4,10 +4,10 @@
struct cmd_results *output_cmd_dpms(int argc, char **argv) { struct cmd_results *output_cmd_dpms(int argc, char **argv) {
if (!config->handler_context.output_config) { if (!config->handler_context.output_config) {
return cmd_results_new(CMD_FAILURE, "output", "Missing output config"); return cmd_results_new(CMD_FAILURE, "Missing output config");
} }
if (!argc) { if (!argc) {
return cmd_results_new(CMD_INVALID, "output", "Missing dpms argument."); return cmd_results_new(CMD_INVALID, "Missing dpms argument.");
} }
if (parse_boolean(argv[0], true)) { if (parse_boolean(argv[0], true)) {

View file

@ -3,7 +3,7 @@
struct cmd_results *output_cmd_enable(int argc, char **argv) { struct cmd_results *output_cmd_enable(int argc, char **argv) {
if (!config->handler_context.output_config) { if (!config->handler_context.output_config) {
return cmd_results_new(CMD_FAILURE, "output", "Missing output config"); return cmd_results_new(CMD_FAILURE, "Missing output config");
} }
config->handler_context.output_config->enabled = 1; config->handler_context.output_config->enabled = 1;

View file

@ -4,10 +4,10 @@
struct cmd_results *output_cmd_mode(int argc, char **argv) { struct cmd_results *output_cmd_mode(int argc, char **argv) {
if (!config->handler_context.output_config) { if (!config->handler_context.output_config) {
return cmd_results_new(CMD_FAILURE, "output", "Missing output config"); return cmd_results_new(CMD_FAILURE, "Missing output config");
} }
if (!argc) { if (!argc) {
return cmd_results_new(CMD_INVALID, "output", "Missing mode argument."); return cmd_results_new(CMD_INVALID, "Missing mode argument.");
} }
struct output_config *output = config->handler_context.output_config; struct output_config *output = config->handler_context.output_config;
@ -17,20 +17,18 @@ struct cmd_results *output_cmd_mode(int argc, char **argv) {
if (*end) { if (*end) {
// Format is 1234x4321 // Format is 1234x4321
if (*end != 'x') { if (*end != 'x') {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Invalid mode width.");
"Invalid mode width.");
} }
++end; ++end;
output->height = strtol(end, &end, 10); output->height = strtol(end, &end, 10);
if (*end) { if (*end) {
if (*end != '@') { if (*end != '@') {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Invalid mode height.");
"Invalid mode height.");
} }
++end; ++end;
output->refresh_rate = strtof(end, &end); output->refresh_rate = strtof(end, &end);
if (strcasecmp("Hz", end) != 0) { if (strcasecmp("Hz", end) != 0) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID,
"Invalid mode refresh rate."); "Invalid mode refresh rate.");
} }
} }
@ -38,13 +36,12 @@ struct cmd_results *output_cmd_mode(int argc, char **argv) {
// Format is 1234 4321 // Format is 1234 4321
argc--; argv++; argc--; argv++;
if (!argc) { if (!argc) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID,
"Missing mode argument (height)."); "Missing mode argument (height).");
} }
output->height = strtol(*argv, &end, 10); output->height = strtol(*argv, &end, 10);
if (*end) { if (*end) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Invalid mode height.");
"Invalid mode height.");
} }
} }

View file

@ -4,11 +4,10 @@
struct cmd_results *output_cmd_position(int argc, char **argv) { struct cmd_results *output_cmd_position(int argc, char **argv) {
if (!config->handler_context.output_config) { if (!config->handler_context.output_config) {
return cmd_results_new(CMD_FAILURE, "output", "Missing output config"); return cmd_results_new(CMD_FAILURE, "Missing output config");
} }
if (!argc) { if (!argc) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Missing position argument.");
"Missing position argument.");
} }
char *end; char *end;
@ -16,26 +15,22 @@ struct cmd_results *output_cmd_position(int argc, char **argv) {
if (*end) { if (*end) {
// Format is 1234,4321 // Format is 1234,4321
if (*end != ',') { if (*end != ',') {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Invalid position x.");
"Invalid position x.");
} }
++end; ++end;
config->handler_context.output_config->y = strtol(end, &end, 10); config->handler_context.output_config->y = strtol(end, &end, 10);
if (*end) { if (*end) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Invalid position y.");
"Invalid position y.");
} }
} else { } else {
// Format is 1234 4321 (legacy) // Format is 1234 4321 (legacy)
argc--; argv++; argc--; argv++;
if (!argc) { if (!argc) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Missing position argument (y).");
"Missing position argument (y).");
} }
config->handler_context.output_config->y = strtol(*argv, &end, 10); config->handler_context.output_config->y = strtol(*argv, &end, 10);
if (*end) { if (*end) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Invalid position y.");
"Invalid position y.");
} }
} }

View file

@ -4,17 +4,16 @@
struct cmd_results *output_cmd_scale(int argc, char **argv) { struct cmd_results *output_cmd_scale(int argc, char **argv) {
if (!config->handler_context.output_config) { if (!config->handler_context.output_config) {
return cmd_results_new(CMD_FAILURE, "output", "Missing output config"); return cmd_results_new(CMD_FAILURE, "Missing output config");
} }
if (!argc) { if (!argc) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Missing scale argument.");
"Missing scale argument.");
} }
char *end; char *end;
config->handler_context.output_config->scale = strtof(*argv, &end); config->handler_context.output_config->scale = strtof(*argv, &end);
if (*end) { if (*end) {
return cmd_results_new(CMD_INVALID, "output", "Invalid scale."); return cmd_results_new(CMD_INVALID, "Invalid scale.");
} }
config->handler_context.leftovers.argc = argc - 1; config->handler_context.leftovers.argc = argc - 1;

View file

@ -6,11 +6,10 @@
struct cmd_results *output_cmd_transform(int argc, char **argv) { struct cmd_results *output_cmd_transform(int argc, char **argv) {
if (!config->handler_context.output_config) { if (!config->handler_context.output_config) {
return cmd_results_new(CMD_FAILURE, "output", "Missing output config"); return cmd_results_new(CMD_FAILURE, "Missing output config");
} }
if (!argc) { if (!argc) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Missing transform argument.");
"Missing transform argument.");
} }
enum wl_output_transform transform; enum wl_output_transform transform;
if (strcmp(*argv, "normal") == 0) { if (strcmp(*argv, "normal") == 0) {
@ -30,8 +29,7 @@ struct cmd_results *output_cmd_transform(int argc, char **argv) {
} else if (strcmp(*argv, "flipped-270") == 0) { } else if (strcmp(*argv, "flipped-270") == 0) {
transform = WL_OUTPUT_TRANSFORM_FLIPPED_270; transform = WL_OUTPUT_TRANSFORM_FLIPPED_270;
} else { } else {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID, "Invalid output transform.");
"Invalid output transform.");
} }
struct output_config *output = config->handler_context.output_config; struct output_config *output = config->handler_context.output_config;
config->handler_context.leftovers.argc = argc - 1; config->handler_context.leftovers.argc = argc - 1;
@ -42,12 +40,12 @@ struct cmd_results *output_cmd_transform(int argc, char **argv) {
return NULL; return NULL;
} }
if (strcmp(output->name, "*") == 0) { if (strcmp(output->name, "*") == 0) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID,
"Cannot apply relative transform to all outputs."); "Cannot apply relative transform to all outputs.");
} }
struct sway_output *s_output = output_by_name_or_id(output->name); struct sway_output *s_output = output_by_name_or_id(output->name);
if (s_output == NULL) { if (s_output == NULL) {
return cmd_results_new(CMD_INVALID, "output", return cmd_results_new(CMD_INVALID,
"Cannot apply relative transform to unknown output %s", output->name); "Cannot apply relative transform to unknown output %s", output->name);
} }
if (strcmp(argv[1], "anticlockwise") == 0) { if (strcmp(argv[1], "anticlockwise") == 0) {

Some files were not shown because too many files have changed in this diff Show more