aboutsummaryrefslogtreecommitdiff
path: root/sway/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c274
1 files changed, 261 insertions, 13 deletions
diff --git a/sway/config.c b/sway/config.c
index 61131845..4e34aa8c 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -21,6 +21,7 @@
#include <dev/evdev/input-event-codes.h>
#endif
#include <wlr/types/wlr_output.h>
+#include "sway/input/input-manager.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/layout.h"
@@ -44,11 +45,13 @@ static void config_defaults(struct sway_config *config) {
if (!(config->criteria = create_list())) goto cleanup;
if (!(config->no_focus = create_list())) goto cleanup;
if (!(config->input_configs = create_list())) goto cleanup;
+ if (!(config->seat_configs = create_list())) goto cleanup;
if (!(config->output_configs = 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;
strcpy(config->current_mode->name, "default");
if (!(config->current_mode->bindings = create_list())) goto cleanup;
@@ -226,6 +229,227 @@ static int qstrcmp(const void* a, const void* b) {
return strcmp(*((char**) a), *((char**) b));
}
+struct input_config *new_input_config(const char* identifier) {
+ struct input_config *input = calloc(1, sizeof(struct input_config));
+ if (!input) {
+ sway_log(L_DEBUG, "Unable to allocate input config");
+ return NULL;
+ }
+ sway_log(L_DEBUG, "new_input_config(%s)", identifier);
+ if (!(input->identifier = strdup(identifier))) {
+ free(input);
+ sway_log(L_DEBUG, "Unable to allocate input config");
+ return NULL;
+ }
+
+ input->tap = INT_MIN;
+ input->drag_lock = INT_MIN;
+ input->dwt = INT_MIN;
+ input->send_events = INT_MIN;
+ input->click_method = INT_MIN;
+ input->middle_emulation = INT_MIN;
+ input->natural_scroll = INT_MIN;
+ input->accel_profile = INT_MIN;
+ input->pointer_accel = FLT_MIN;
+ input->scroll_method = INT_MIN;
+ input->left_handed = INT_MIN;
+
+ return input;
+}
+
+void merge_input_config(struct input_config *dst, struct input_config *src) {
+ if (src->identifier) {
+ free(dst->identifier);
+ dst->identifier = strdup(src->identifier);
+ }
+ if (src->accel_profile != INT_MIN) {
+ dst->accel_profile = src->accel_profile;
+ }
+ if (src->click_method != INT_MIN) {
+ dst->click_method = src->click_method;
+ }
+ if (src->drag_lock != INT_MIN) {
+ dst->drag_lock = src->drag_lock;
+ }
+ if (src->dwt != INT_MIN) {
+ dst->dwt = src->dwt;
+ }
+ if (src->middle_emulation != INT_MIN) {
+ dst->middle_emulation = src->middle_emulation;
+ }
+ if (src->natural_scroll != INT_MIN) {
+ dst->natural_scroll = src->natural_scroll;
+ }
+ if (src->pointer_accel != FLT_MIN) {
+ dst->pointer_accel = src->pointer_accel;
+ }
+ if (src->scroll_method != INT_MIN) {
+ dst->scroll_method = src->scroll_method;
+ }
+ if (src->send_events != INT_MIN) {
+ dst->send_events = src->send_events;
+ }
+ if (src->tap != INT_MIN) {
+ dst->tap = src->tap;
+ }
+ if (src->xkb_layout) {
+ free(dst->xkb_layout);
+ dst->xkb_layout = strdup(src->xkb_layout);
+ }
+ if (src->xkb_model) {
+ free(dst->xkb_model);
+ dst->xkb_model = strdup(src->xkb_model);
+ }
+ if (src->xkb_options) {
+ free(dst->xkb_options);
+ dst->xkb_options = strdup(src->xkb_options);
+ }
+ if (src->xkb_rules) {
+ free(dst->xkb_rules);
+ dst->xkb_rules = strdup(src->xkb_rules);
+ }
+ if (src->xkb_variant) {
+ free(dst->xkb_variant);
+ dst->xkb_variant = strdup(src->xkb_variant);
+ }
+}
+
+void free_input_config(struct input_config *ic) {
+ if (!ic) {
+ return;
+ }
+ free(ic->identifier);
+ free(ic);
+}
+
+int input_identifier_cmp(const void *item, const void *data) {
+ const struct input_config *ic = item;
+ const char *identifier = data;
+ return strcmp(ic->identifier, identifier);
+}
+
+struct seat_config *new_seat_config(const char* name) {
+ struct seat_config *seat = calloc(1, sizeof(struct seat_config));
+ if (!seat) {
+ sway_log(L_DEBUG, "Unable to allocate seat config");
+ return NULL;
+ }
+
+ sway_log(L_DEBUG, "new_seat_config(%s)", name);
+ seat->name = strdup(name);
+ if (!sway_assert(seat->name, "could not allocate name for seat")) {
+ return NULL;
+ }
+
+ seat->attachments = create_list();
+ if (!sway_assert(seat->attachments,
+ "could not allocate seat attachments list")) {
+ return NULL;
+ }
+
+ return seat;
+}
+
+struct seat_attachment_config *seat_attachment_config_new() {
+ struct seat_attachment_config *attachment =
+ calloc(1, sizeof(struct seat_attachment_config));
+ if (!attachment) {
+ sway_log(L_DEBUG, "cannot allocate attachment config");
+ return NULL;
+ }
+ return attachment;
+}
+
+static void seat_attachment_config_free(
+ struct seat_attachment_config *attachment) {
+ free(attachment->identifier);
+ free(attachment);
+ return;
+}
+
+static struct seat_attachment_config *seat_attachment_config_copy(
+ struct seat_attachment_config *attachment) {
+ struct seat_attachment_config *copy = seat_attachment_config_new();
+ if (!copy) {
+ return NULL;
+ }
+
+ copy->identifier = strdup(attachment->identifier);
+
+ return copy;
+}
+
+static void merge_seat_attachment_config(struct seat_attachment_config *dest,
+ struct seat_attachment_config *source) {
+ // nothing to merge yet, but there will be some day
+}
+
+void merge_seat_config(struct seat_config *dest, struct seat_config *source) {
+ if (source->name) {
+ free(dest->name);
+ dest->name = strdup(source->name);
+ }
+
+ for (int i = 0; i < source->attachments->length; ++i) {
+ struct seat_attachment_config *source_attachment =
+ source->attachments->items[i];
+ bool found = false;
+ for (int j = 0; j < dest->attachments->length; ++j) {
+ struct seat_attachment_config *dest_attachment =
+ dest->attachments->items[j];
+ if (strcmp(source_attachment->identifier,
+ dest_attachment->identifier) == 0) {
+ merge_seat_attachment_config(dest_attachment,
+ source_attachment);
+ found = true;
+ }
+ }
+
+ if (!found) {
+ struct seat_attachment_config *copy =
+ seat_attachment_config_copy(source_attachment);
+ if (copy) {
+ list_add(dest->attachments, copy);
+ }
+ }
+ }
+}
+
+void free_seat_config(struct seat_config *seat) {
+ if (!seat) {
+ return;
+ }
+
+ free(seat->name);
+ for (int i = 0; i < seat->attachments->length; ++i) {
+ struct seat_attachment_config *attachment =
+ seat->attachments->items[i];
+ seat_attachment_config_free(attachment);
+ }
+
+ list_free(seat->attachments);
+ free(seat);
+}
+
+int seat_name_cmp(const void *item, const void *data) {
+ const struct seat_config *sc = item;
+ const char *name = data;
+ return strcmp(sc->name, name);
+}
+
+struct seat_attachment_config *seat_config_get_attachment(
+ struct seat_config *seat_config, char *identifier) {
+ for (int i = 0; i < seat_config->attachments->length; ++i) {
+ struct seat_attachment_config *attachment =
+ seat_config->attachments->items[i];
+ if (strcmp(attachment->identifier, identifier) == 0) {
+ return attachment;
+ }
+ }
+
+ return NULL;
+}
+
bool load_main_config(const char *file, bool is_active) {
char *path;
if (file != NULL) {
@@ -256,8 +480,9 @@ bool load_main_config(const char *file, bool is_active) {
bool success = true;
DIR *dir = opendir(SYSCONFDIR "/sway/security.d");
if (!dir) {
- sway_log(L_ERROR, "%s does not exist, sway will have no security configuration"
- " and will probably be broken", SYSCONFDIR "/sway/security.d");
+ sway_log(L_ERROR,
+ "%s does not exist, sway will have no security configuration"
+ " and will probably be broken", SYSCONFDIR "/sway/security.d");
} else {
list_t *secconfigs = create_list();
char *base = SYSCONFDIR "/sway/security.d/";
@@ -281,8 +506,12 @@ bool load_main_config(const char *file, bool is_active) {
list_qsort(secconfigs, qstrcmp);
for (int i = 0; i < secconfigs->length; ++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)) {
- sway_log(L_ERROR, "Refusing to load %s - it must be owned by root and mode 644 or 444", _path);
+ if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 ||
+ (((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;
} else {
success = success && load_config(_path, config);
@@ -311,7 +540,8 @@ bool load_main_config(const char *file, bool is_active) {
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
const char *parent_config = config->current_config;
@@ -321,7 +551,8 @@ static bool load_include_config(const char *path, const char *parent_dir, struct
len = len + strlen(parent_dir) + 2;
full_path = malloc(len * sizeof(char));
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;
}
snprintf(full_path, len, "%s/%s", parent_dir, path);
@@ -340,7 +571,9 @@ static bool load_include_config(const char *path, const char *parent_dir, struct
for (j = 0; j < config->config_chain->length; ++j) {
char *old_path = config->config_chain->items[j];
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);
return false;
}
@@ -400,6 +633,7 @@ bool load_include_configs(const char *path, struct sway_config *config) {
return true;
}
+
bool read_config(FILE *file, struct sway_config *config) {
bool success = true;
enum cmd_status block = CMD_BLOCK_END;
@@ -427,8 +661,8 @@ bool read_config(FILE *file, struct sway_config *config) {
switch(res->status) {
case CMD_FAILURE:
case CMD_INVALID:
- sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number, line,
- res->error, config->current_config);
+ sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number,
+ line, res->error, config->current_config);
success = false;
break;
@@ -453,6 +687,14 @@ bool read_config(FILE *file, struct sway_config *config) {
}
break;
+ case CMD_BLOCK_SEAT:
+ if (block == CMD_BLOCK_END) {
+ block = CMD_BLOCK_SEAT;
+ } else {
+ sway_log(L_ERROR, "Invalid block '%s'", line);
+ }
+ break;
+
case CMD_BLOCK_BAR:
if (block == CMD_BLOCK_END) {
block = CMD_BLOCK_BAR;
@@ -503,8 +745,13 @@ bool read_config(FILE *file, struct sway_config *config) {
case CMD_BLOCK_INPUT:
sway_log(L_DEBUG, "End of input block");
- // TODO: input
- //current_input_config = NULL;
+ current_input_config = NULL;
+ block = CMD_BLOCK_END;
+ break;
+
+ case CMD_BLOCK_SEAT:
+ sway_log(L_DEBUG, "End of seat block");
+ current_seat_config = NULL;
block = CMD_BLOCK_END;
break;
@@ -569,7 +816,8 @@ char *do_var_replacement(char *str) {
char *newstr = malloc(strlen(str) - vnlen + vvlen + 1);
if (!newstr) {
sway_log(L_ERROR,
- "Unable to allocate replacement during variable expansion");
+ "Unable to allocate replacement "
+ "during variable expansion");
break;
}
char *newptr = newstr;