Use parse_boolean where possible.
This commit is contained in:
parent
7fa7f4f48d
commit
b865dabeba
|
@ -2,6 +2,7 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) {
|
struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
@ -13,17 +14,14 @@ struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_FAILURE,
|
return cmd_results_new(CMD_FAILURE,
|
||||||
"binding_mode_indicator", "No bar defined.");
|
"binding_mode_indicator", "No bar defined.");
|
||||||
}
|
}
|
||||||
if (strcasecmp("yes", argv[0]) == 0) {
|
config->current_bar->binding_mode_indicator =
|
||||||
config->current_bar->binding_mode_indicator = true;
|
parse_boolean(argv[0], config->current_bar->binding_mode_indicator);
|
||||||
|
if (config->current_bar->binding_mode_indicator) {
|
||||||
wlr_log(WLR_DEBUG, "Enabling binding mode indicator on bar: %s",
|
wlr_log(WLR_DEBUG, "Enabling binding mode indicator on bar: %s",
|
||||||
config->current_bar->id);
|
config->current_bar->id);
|
||||||
} else if (strcasecmp("no", argv[0]) == 0) {
|
} else {
|
||||||
config->current_bar->binding_mode_indicator = false;
|
|
||||||
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);
|
||||||
} else {
|
|
||||||
return cmd_results_new(CMD_INVALID, "binding_mode_indicator",
|
|
||||||
"Invalid value %s", argv[0]);
|
|
||||||
}
|
}
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) {
|
struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
@ -11,18 +12,14 @@ struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) {
|
||||||
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, "pango_markup", "No bar defined.");
|
||||||
}
|
}
|
||||||
if (strcasecmp("enabled", argv[0]) == 0) {
|
config->current_bar->pango_markup
|
||||||
config->current_bar->pango_markup = true;
|
= parse_boolean(argv[0], config->current_bar->pango_markup);
|
||||||
|
if (config->current_bar->pango_markup) {
|
||||||
wlr_log(WLR_DEBUG, "Enabling pango markup for bar: %s",
|
wlr_log(WLR_DEBUG, "Enabling pango markup for bar: %s",
|
||||||
config->current_bar->id);
|
config->current_bar->id);
|
||||||
} else if (strcasecmp("disabled", argv[0]) == 0) {
|
} else {
|
||||||
config->current_bar->pango_markup = false;
|
|
||||||
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);
|
||||||
} else {
|
|
||||||
error = cmd_results_new(CMD_INVALID, "pango_markup",
|
|
||||||
"Invalid value %s", argv[0]);
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
|
struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
@ -12,17 +13,14 @@ struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_FAILURE,
|
return cmd_results_new(CMD_FAILURE,
|
||||||
"workspace_buttons", "No bar defined.");
|
"workspace_buttons", "No bar defined.");
|
||||||
}
|
}
|
||||||
if (strcasecmp("yes", argv[0]) == 0) {
|
config->current_bar->workspace_buttons =
|
||||||
config->current_bar->workspace_buttons = true;
|
parse_boolean(argv[0], config->current_bar->workspace_buttons);
|
||||||
|
if (config->current_bar->workspace_buttons) {
|
||||||
wlr_log(WLR_DEBUG, "Enabling workspace buttons on bar: %s",
|
wlr_log(WLR_DEBUG, "Enabling workspace buttons on bar: %s",
|
||||||
config->current_bar->id);
|
config->current_bar->id);
|
||||||
} else if (strcasecmp("no", argv[0]) == 0) {
|
} else {
|
||||||
config->current_bar->workspace_buttons = false;
|
|
||||||
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);
|
||||||
} else {
|
|
||||||
return cmd_results_new(CMD_INVALID, "workspace_buttons",
|
|
||||||
"Invalid value %s", argv[0]);
|
|
||||||
}
|
}
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) {
|
struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
@ -11,17 +12,14 @@ struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) {
|
||||||
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, "wrap_scroll", "No bar defined.");
|
||||||
}
|
}
|
||||||
if (strcasecmp("yes", argv[0]) == 0) {
|
config->current_bar->wrap_scroll =
|
||||||
config->current_bar->wrap_scroll = true;
|
parse_boolean(argv[0], config->current_bar->wrap_scroll);
|
||||||
|
if (config->current_bar->wrap_scroll) {
|
||||||
wlr_log(WLR_DEBUG, "Enabling wrap scroll on bar: %s",
|
wlr_log(WLR_DEBUG, "Enabling wrap scroll on bar: %s",
|
||||||
config->current_bar->id);
|
config->current_bar->id);
|
||||||
} else if (strcasecmp("no", argv[0]) == 0) {
|
} else {
|
||||||
config->current_bar->wrap_scroll = false;
|
|
||||||
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);
|
||||||
} else {
|
|
||||||
return cmd_results_new(CMD_INVALID,
|
|
||||||
"wrap_scroll", "Invalid value %s", argv[0]);
|
|
||||||
}
|
}
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "sway/tree/view.h"
|
#include "sway/tree/view.h"
|
||||||
#include "sway/tree/workspace.h"
|
#include "sway/tree/workspace.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *cmd_floating(int argc, char **argv) {
|
struct cmd_results *cmd_floating(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
@ -40,17 +41,8 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wants_floating;
|
bool wants_floating =
|
||||||
if (strcasecmp(argv[0], "enable") == 0) {
|
parse_boolean(argv[0], container_is_floating(container));
|
||||||
wants_floating = true;
|
|
||||||
} else if (strcasecmp(argv[0], "disable") == 0) {
|
|
||||||
wants_floating = false;
|
|
||||||
} else if (strcasecmp(argv[0], "toggle") == 0) {
|
|
||||||
wants_floating = !container_is_floating(container);
|
|
||||||
} else {
|
|
||||||
return cmd_results_new(CMD_FAILURE, "floating",
|
|
||||||
"Expected 'floating <enable|disable|toggle>'");
|
|
||||||
}
|
|
||||||
|
|
||||||
container_set_floating(container, wants_floating);
|
container_set_floating(container, wants_floating);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "sway/input/input-manager.h"
|
#include "sway/input/input-manager.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *input_cmd_xkb_capslock(int argc, char **argv) {
|
struct cmd_results *input_cmd_xkb_capslock(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
@ -15,14 +16,7 @@ struct cmd_results *input_cmd_xkb_capslock(int argc, char **argv) {
|
||||||
"No input device defined.");
|
"No input device defined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(argv[0], "enabled") == 0) {
|
ic->xkb_capslock = parse_boolean(argv[0], false);
|
||||||
ic->xkb_capslock = 1;
|
|
||||||
} else if (strcasecmp(argv[0], "disabled") == 0) {
|
|
||||||
ic->xkb_capslock = 0;
|
|
||||||
} else {
|
|
||||||
return cmd_results_new(CMD_INVALID, "xkb_capslock",
|
|
||||||
"Expected 'xkb_capslock <enabled|disabled>'");
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "sway/input/input-manager.h"
|
#include "sway/input/input-manager.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *input_cmd_xkb_numlock(int argc, char **argv) {
|
struct cmd_results *input_cmd_xkb_numlock(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
@ -15,14 +16,7 @@ struct cmd_results *input_cmd_xkb_numlock(int argc, char **argv) {
|
||||||
"No input device defined.");
|
"No input device defined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(argv[0], "enabled") == 0) {
|
ic->xkb_numlock = parse_boolean(argv[0], false);
|
||||||
ic->xkb_numlock = 1;
|
|
||||||
} else if (strcasecmp(argv[0], "disabled") == 0) {
|
|
||||||
ic->xkb_numlock = 0;
|
|
||||||
} else {
|
|
||||||
return cmd_results_new(CMD_INVALID, "xkb_numlock",
|
|
||||||
"Expected 'xkb_numlock <enabled|disabled>'");
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "sway/input/input-manager.h"
|
#include "sway/input/input-manager.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *seat_cmd_fallback(int argc, char **argv) {
|
struct cmd_results *seat_cmd_fallback(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
@ -17,15 +18,7 @@ struct cmd_results *seat_cmd_fallback(int argc, char **argv) {
|
||||||
struct seat_config *new_config =
|
struct seat_config *new_config =
|
||||||
new_seat_config(current_seat_config->name);
|
new_seat_config(current_seat_config->name);
|
||||||
|
|
||||||
if (strcasecmp(argv[0], "true") == 0) {
|
new_config->fallback = parse_boolean(argv[0], false);
|
||||||
new_config->fallback = 1;
|
|
||||||
} else if (strcasecmp(argv[0], "false") == 0) {
|
|
||||||
new_config->fallback = 0;
|
|
||||||
} else {
|
|
||||||
free_seat_config(new_config);
|
|
||||||
return cmd_results_new(CMD_INVALID, "fallback",
|
|
||||||
"Expected 'fallback <true|false>'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config->validating) {
|
if (!config->validating) {
|
||||||
apply_seat_config(new_config);
|
apply_seat_config(new_config);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "sway/tree/container.h"
|
#include "sway/tree/container.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *cmd_smart_gaps(int argc, char **argv) {
|
struct cmd_results *cmd_smart_gaps(int argc, char **argv) {
|
||||||
struct cmd_results *error = checkarg(argc, "smart_gaps", EXPECTED_AT_LEAST, 1);
|
struct cmd_results *error = checkarg(argc, "smart_gaps", EXPECTED_AT_LEAST, 1);
|
||||||
|
@ -14,14 +15,7 @@ struct cmd_results *cmd_smart_gaps(int argc, char **argv) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(argv[0], "on") == 0) {
|
config->smart_gaps = parse_boolean(argv[0], config->smart_gaps);
|
||||||
config->smart_gaps = true;
|
|
||||||
} else if (strcmp(argv[0], "off") == 0) {
|
|
||||||
config->smart_gaps = false;
|
|
||||||
} else {
|
|
||||||
return cmd_results_new(CMD_INVALID, "smart_gaps",
|
|
||||||
"Expected 'smart_gaps <on|off>' ");
|
|
||||||
}
|
|
||||||
|
|
||||||
arrange_root();
|
arrange_root();
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "sway/tree/view.h"
|
#include "sway/tree/view.h"
|
||||||
#include "sway/tree/workspace.h"
|
#include "sway/tree/workspace.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *cmd_sticky(int argc, char **argv) {
|
struct cmd_results *cmd_sticky(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
@ -26,21 +27,9 @@ struct cmd_results *cmd_sticky(int argc, char **argv) {
|
||||||
"Can't set sticky on a tiled container");
|
"Can't set sticky on a tiled container");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wants_sticky;
|
container->is_sticky = parse_boolean(argv[0], container->is_sticky);
|
||||||
if (strcasecmp(argv[0], "enable") == 0) {
|
|
||||||
wants_sticky = true;
|
|
||||||
} else if (strcasecmp(argv[0], "disable") == 0) {
|
|
||||||
wants_sticky = false;
|
|
||||||
} else if (strcasecmp(argv[0], "toggle") == 0) {
|
|
||||||
wants_sticky = !container->is_sticky;
|
|
||||||
} else {
|
|
||||||
return cmd_results_new(CMD_FAILURE, "sticky",
|
|
||||||
"Expected 'sticky <enable|disable|toggle>'");
|
|
||||||
}
|
|
||||||
|
|
||||||
container->is_sticky = wants_sticky;
|
if (container->is_sticky) {
|
||||||
|
|
||||||
if (wants_sticky) {
|
|
||||||
// move container to active workspace
|
// move container to active workspace
|
||||||
struct sway_workspace *active_workspace =
|
struct sway_workspace *active_workspace =
|
||||||
output_get_active_workspace(container->workspace->output);
|
output_get_active_workspace(container->workspace->output);
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *cmd_ws_auto_back_and_forth(int argc, char **argv) {
|
struct cmd_results *cmd_ws_auto_back_and_forth(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if ((error = checkarg(argc, "workspace_auto_back_and_forth", EXPECTED_EQUAL_TO, 1))) {
|
if ((error = checkarg(argc, "workspace_auto_back_and_forth", EXPECTED_EQUAL_TO, 1))) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
config->auto_back_and_forth = !strcasecmp(argv[0], "yes");
|
config->auto_back_and_forth =
|
||||||
|
!parse_boolean(argv[0], config->auto_back_and_forth);
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue