config cleanup

master
Tony Crisci 7 years ago
parent 163edc5a90
commit 538903bc5a

@ -9,9 +9,11 @@ struct cmd_results *input_cmd_accel_profile(int argc, char **argv) {
return error; return error;
} }
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "accel_profile", "No input device defined."); return cmd_results_new(CMD_FAILURE, "accel_profile",
"No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
if (strcasecmp(argv[0], "adaptive") == 0) { if (strcasecmp(argv[0], "adaptive") == 0) {
new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;

@ -5,15 +5,18 @@
#include "log.h" #include "log.h"
struct cmd_results *input_cmd_click_method(int argc, char **argv) { struct cmd_results *input_cmd_click_method(int argc, char **argv) {
sway_log(L_DEBUG, "click_method for device: %d %s", current_input_config==NULL, current_input_config->identifier); sway_log(L_DEBUG, "click_method for device: %d %s",
current_input_config==NULL, current_input_config->identifier);
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) { if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) {
return error; return error;
} }
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "click_method", "No input device defined."); return cmd_results_new(CMD_FAILURE, "click_method",
"No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
if (strcasecmp(argv[0], "none") == 0) { if (strcasecmp(argv[0], "none") == 0) {
new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
@ -22,7 +25,8 @@ 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) {
new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
} else { } else {
return cmd_results_new(CMD_INVALID, "click_method", "Expected 'click_method <none|button_areas|clickfinger'"); return cmd_results_new(CMD_INVALID, "click_method",
"Expected 'click_method <none|button_areas|clickfinger'");
} }
input_cmd_apply(new_config); input_cmd_apply(new_config);

@ -9,16 +9,19 @@ struct cmd_results *input_cmd_drag_lock(int argc, char **argv) {
return error; return error;
} }
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "drag_lock", "No input device defined."); return cmd_results_new(CMD_FAILURE,
"drag_lock", "No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
if (strcasecmp(argv[0], "enabled") == 0) { if (strcasecmp(argv[0], "enabled") == 0) {
new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED;
} else if (strcasecmp(argv[0], "disabled") == 0) { } else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
} else { } else {
return cmd_results_new(CMD_INVALID, "drag_lock", "Expected 'drag_lock <enabled|disabled>'"); return cmd_results_new(CMD_INVALID, "drag_lock",
"Expected 'drag_lock <enabled|disabled>'");
} }
input_cmd_apply(new_config); input_cmd_apply(new_config);

@ -11,14 +11,16 @@ struct cmd_results *input_cmd_dwt(int argc, char **argv) {
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined."); return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
if (strcasecmp(argv[0], "enabled") == 0) { if (strcasecmp(argv[0], "enabled") == 0) {
new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED; new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED;
} else if (strcasecmp(argv[0], "disabled") == 0) { } else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED;
} else { } else {
return cmd_results_new(CMD_INVALID, "dwt", "Expected 'dwt <enabled|disabled>'"); return cmd_results_new(CMD_INVALID, "dwt",
"Expected 'dwt <enabled|disabled>'");
} }
input_cmd_apply(new_config); input_cmd_apply(new_config);

@ -5,24 +5,29 @@
#include "log.h" #include "log.h"
struct cmd_results *input_cmd_events(int argc, char **argv) { struct cmd_results *input_cmd_events(int argc, char **argv) {
sway_log(L_DEBUG, "events for device: %s", current_input_config->identifier); sway_log(L_DEBUG, "events for device: %s",
current_input_config->identifier);
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) { if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) {
return error; return error;
} }
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "events", "No input device defined."); return cmd_results_new(CMD_FAILURE, "events",
"No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
if (strcasecmp(argv[0], "enabled") == 0) { if (strcasecmp(argv[0], "enabled") == 0) {
new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
} else if (strcasecmp(argv[0], "disabled") == 0) { } else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
} else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) { } else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) {
new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; new_config->send_events =
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
} else { } else {
return cmd_results_new(CMD_INVALID, "events", "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); return cmd_results_new(CMD_INVALID, "events",
"Expected 'events <enabled|disabled|disabled_on_external_mouse>'");
} }
input_cmd_apply(new_config); input_cmd_apply(new_config);

@ -9,16 +9,19 @@ struct cmd_results *input_cmd_left_handed(int argc, char **argv) {
return error; return error;
} }
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "left_handed", "No input device defined."); return cmd_results_new(CMD_FAILURE, "left_handed",
"No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
if (strcasecmp(argv[0], "enabled") == 0) { if (strcasecmp(argv[0], "enabled") == 0) {
new_config->left_handed = 1; new_config->left_handed = 1;
} else if (strcasecmp(argv[0], "disabled") == 0) { } else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->left_handed = 0; new_config->left_handed = 0;
} else { } else {
return cmd_results_new(CMD_INVALID, "left_handed", "Expected 'left_handed <enabled|disabled>'"); return cmd_results_new(CMD_INVALID, "left_handed",
"Expected 'left_handed <enabled|disabled>'");
} }
input_cmd_apply(new_config); input_cmd_apply(new_config);

@ -9,16 +9,20 @@ struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) {
return error; return error;
} }
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "middle_emulation", "No input device defined."); return cmd_results_new(CMD_FAILURE, "middle_emulation",
"No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
if (strcasecmp(argv[0], "enabled") == 0) { if (strcasecmp(argv[0], "enabled") == 0) {
new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED;
} else if (strcasecmp(argv[0], "disabled") == 0) { } else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; new_config->middle_emulation =
LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
} else { } else {
return cmd_results_new(CMD_INVALID, "middle_emulation", "Expected 'middle_emulation <enabled|disabled>'"); return cmd_results_new(CMD_INVALID, "middle_emulation",
"Expected 'middle_emulation <enabled|disabled>'");
} }
input_cmd_apply(new_config); input_cmd_apply(new_config);

@ -9,16 +9,19 @@ struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) {
return error; return error;
} }
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "natural_scoll", "No input device defined."); return cmd_results_new(CMD_FAILURE, "natural_scoll",
"No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
if (strcasecmp(argv[0], "enabled") == 0) { if (strcasecmp(argv[0], "enabled") == 0) {
new_config->natural_scroll = 1; new_config->natural_scroll = 1;
} else if (strcasecmp(argv[0], "disabled") == 0) { } else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->natural_scroll = 0; new_config->natural_scroll = 0;
} else { } else {
return cmd_results_new(CMD_INVALID, "natural_scroll", "Expected 'natural_scroll <enabled|disabled>'"); return cmd_results_new(CMD_INVALID, "natural_scroll",
"Expected 'natural_scroll <enabled|disabled>'");
} }
input_cmd_apply(new_config); input_cmd_apply(new_config);

@ -9,13 +9,16 @@ struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) {
return error; return error;
} }
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "pointer_accel", "No input device defined."); return cmd_results_new(CMD_FAILURE,
"pointer_accel", "No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
float pointer_accel = atof(argv[0]); float pointer_accel = atof(argv[0]);
if (pointer_accel < -1 || pointer_accel > 1) { if (pointer_accel < -1 || pointer_accel > 1) {
return cmd_results_new(CMD_INVALID, "pointer_accel", "Input out of range [-1, 1]"); return cmd_results_new(CMD_INVALID, "pointer_accel",
"Input out of range [-1, 1]");
} }
new_config->pointer_accel = pointer_accel; new_config->pointer_accel = pointer_accel;

@ -9,9 +9,11 @@ struct cmd_results *input_cmd_scroll_method(int argc, char **argv) {
return error; return error;
} }
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "scroll_method", "No input device defined."); return cmd_results_new(CMD_FAILURE, "scroll_method",
"No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
if (strcasecmp(argv[0], "none") == 0) { if (strcasecmp(argv[0], "none") == 0) {
new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
@ -22,7 +24,8 @@ 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) {
new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
} else { } else {
return cmd_results_new(CMD_INVALID, "scroll_method", "Expected 'scroll_method <none|two_finger|edge|on_button_down>'"); return cmd_results_new(CMD_INVALID, "scroll_method",
"Expected 'scroll_method <none|two_finger|edge|on_button_down>'");
} }
input_cmd_apply(new_config); input_cmd_apply(new_config);

@ -13,17 +13,20 @@ struct cmd_results *input_cmd_tap(int argc, char **argv) {
if (!current_input_config) { if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "tap", "No input device defined."); return cmd_results_new(CMD_FAILURE, "tap", "No input device defined.");
} }
struct input_config *new_config = new_input_config(current_input_config->identifier); struct input_config *new_config =
new_input_config(current_input_config->identifier);
if (strcasecmp(argv[0], "enabled") == 0) { if (strcasecmp(argv[0], "enabled") == 0) {
new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED; new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED;
} else if (strcasecmp(argv[0], "disabled") == 0) { } else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED;
} else { } else {
return cmd_results_new(CMD_INVALID, "tap", "Expected 'tap <enabled|disabled>'"); return cmd_results_new(CMD_INVALID, "tap",
"Expected 'tap <enabled|disabled>'");
} }
sway_log(L_DEBUG, "apply-tap for device: %s", current_input_config->identifier); sway_log(L_DEBUG, "apply-tap for device: %s",
current_input_config->identifier);
input_cmd_apply(new_config); input_cmd_apply(new_config);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

@ -21,6 +21,7 @@
#include <dev/evdev/input-event-codes.h> #include <dev/evdev/input-event-codes.h>
#endif #endif
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include "sway/input/input-manager.h"
#include "sway/commands.h" #include "sway/commands.h"
#include "sway/config.h" #include "sway/config.h"
#include "sway/layout.h" #include "sway/layout.h"
@ -48,7 +49,8 @@ static void config_defaults(struct sway_config *config) {
if (!(config->cmd_queue = create_list())) goto cleanup; if (!(config->cmd_queue = create_list())) goto cleanup;
if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) goto cleanup; if (!(config->current_mode = malloc(sizeof(struct sway_mode))))
goto cleanup;
if (!(config->current_mode->name = malloc(sizeof("default")))) goto cleanup; if (!(config->current_mode->name = malloc(sizeof("default")))) goto cleanup;
strcpy(config->current_mode->name, "default"); strcpy(config->current_mode->name, "default");
if (!(config->current_mode->bindings = create_list())) goto cleanup; if (!(config->current_mode->bindings = create_list())) goto cleanup;
@ -337,8 +339,9 @@ bool load_main_config(const char *file, bool is_active) {
bool success = true; bool success = true;
DIR *dir = opendir(SYSCONFDIR "/sway/security.d"); DIR *dir = opendir(SYSCONFDIR "/sway/security.d");
if (!dir) { if (!dir) {
sway_log(L_ERROR, "%s does not exist, sway will have no security configuration" sway_log(L_ERROR,
" and will probably be broken", SYSCONFDIR "/sway/security.d"); "%s does not exist, sway will have no security configuration"
" and will probably be broken", SYSCONFDIR "/sway/security.d");
} else { } else {
list_t *secconfigs = create_list(); list_t *secconfigs = create_list();
char *base = SYSCONFDIR "/sway/security.d/"; char *base = SYSCONFDIR "/sway/security.d/";
@ -362,8 +365,12 @@ bool load_main_config(const char *file, bool is_active) {
list_qsort(secconfigs, qstrcmp); list_qsort(secconfigs, qstrcmp);
for (int i = 0; i < secconfigs->length; ++i) { for (int i = 0; i < secconfigs->length; ++i) {
char *_path = secconfigs->items[i]; char *_path = secconfigs->items[i];
if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || (((s.st_mode & 0777) != 0644) && (s.st_mode & 0777) != 0444)) { if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 ||
sway_log(L_ERROR, "Refusing to load %s - it must be owned by root and mode 644 or 444", _path); (((s.st_mode & 0777) != 0644) &&
(s.st_mode & 0777) != 0444)) {
sway_log(L_ERROR,
"Refusing to load %s - it must be owned by root "
"and mode 644 or 444", _path);
success = false; success = false;
} else { } else {
success = success && load_config(_path, config); success = success && load_config(_path, config);
@ -392,7 +399,8 @@ bool load_main_config(const char *file, bool is_active) {
return success; return success;
} }
static bool load_include_config(const char *path, const char *parent_dir, struct sway_config *config) { static bool load_include_config(const char *path, const char *parent_dir,
struct sway_config *config) {
// save parent config // save parent config
const char *parent_config = config->current_config; const char *parent_config = config->current_config;
@ -402,7 +410,8 @@ static bool load_include_config(const char *path, const char *parent_dir, struct
len = len + strlen(parent_dir) + 2; len = len + strlen(parent_dir) + 2;
full_path = malloc(len * sizeof(char)); full_path = malloc(len * sizeof(char));
if (!full_path) { if (!full_path) {
sway_log(L_ERROR, "Unable to allocate full path to included config"); sway_log(L_ERROR,
"Unable to allocate full path to included config");
return false; return false;
} }
snprintf(full_path, len, "%s/%s", parent_dir, path); snprintf(full_path, len, "%s/%s", parent_dir, path);
@ -421,7 +430,9 @@ static bool load_include_config(const char *path, const char *parent_dir, struct
for (j = 0; j < config->config_chain->length; ++j) { for (j = 0; j < config->config_chain->length; ++j) {
char *old_path = config->config_chain->items[j]; char *old_path = config->config_chain->items[j];
if (strcmp(real_path, old_path) == 0) { if (strcmp(real_path, old_path) == 0) {
sway_log(L_DEBUG, "%s already included once, won't be included again.", real_path); sway_log(L_DEBUG,
"%s already included once, won't be included again.",
real_path);
free(real_path); free(real_path);
return false; return false;
} }
@ -509,8 +520,8 @@ bool read_config(FILE *file, struct sway_config *config) {
switch(res->status) { switch(res->status) {
case CMD_FAILURE: case CMD_FAILURE:
case CMD_INVALID: case CMD_INVALID:
sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number, line, sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number,
res->error, config->current_config); line, res->error, config->current_config);
success = false; success = false;
break; break;
@ -585,8 +596,7 @@ bool read_config(FILE *file, struct sway_config *config) {
case CMD_BLOCK_INPUT: case CMD_BLOCK_INPUT:
sway_log(L_DEBUG, "End of input block"); sway_log(L_DEBUG, "End of input block");
// TODO: input current_input_config = NULL;
//current_input_config = NULL;
block = CMD_BLOCK_END; block = CMD_BLOCK_END;
break; break;
@ -651,7 +661,8 @@ char *do_var_replacement(char *str) {
char *newstr = malloc(strlen(str) - vnlen + vvlen + 1); char *newstr = malloc(strlen(str) - vnlen + vvlen + 1);
if (!newstr) { if (!newstr) {
sway_log(L_ERROR, sway_log(L_ERROR,
"Unable to allocate replacement during variable expansion"); "Unable to allocate replacement "
"during variable expansion");
break; break;
} }
char *newptr = newstr; char *newptr = newstr;

Loading…
Cancel
Save