aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-11-11 11:04:36 -0500
committerGitHub <noreply@github.com>2017-11-11 11:04:36 -0500
commit2bee288090d930a09be5f9176a519c1ec02c63de (patch)
tree05e8baf4a40288189f746e55b15928caa2793b90 /rootston
parentc9916b998c90ea935c79f4fb93fd10f57e488a50 (diff)
parent7072ac87fd1f92cfe6e88a075ff0e8ac2901e870 (diff)
Merge pull request #411 from acrisci/refactor/config-cleanup
Refactor: cleanup config
Diffstat (limited to 'rootston')
-rw-r--r--rootston/config.c67
-rw-r--r--rootston/input.c3
-rw-r--r--rootston/keyboard.c15
-rw-r--r--rootston/main.c2
-rw-r--r--rootston/output.c6
-rw-r--r--rootston/seat.c8
6 files changed, 54 insertions, 47 deletions
diff --git a/rootston/config.c b/rootston/config.c
index 54f10fcd..7ffbb786 100644
--- a/rootston/config.c
+++ b/rootston/config.c
@@ -115,7 +115,8 @@ static uint32_t parse_modifier(const char *symname) {
void add_binding_config(struct wl_list *bindings, const char* combination,
const char* command) {
- struct binding_config *bc = calloc(1, sizeof(struct binding_config));
+ struct roots_binding_config *bc =
+ calloc(1, sizeof(struct roots_binding_config));
xkb_keysym_t keysyms[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP];
char *symnames = strdup(combination);
@@ -151,7 +152,7 @@ void add_binding_config(struct wl_list *bindings, const char* combination,
static void config_handle_keyboard(struct roots_config *config,
const char *device_name, const char *name, const char *value) {
- struct keyboard_config *kc;
+ struct roots_keyboard_config *kc;
bool found = false;
wl_list_for_each(kc, &config->keyboards, link) {
if (strcmp(kc->name, device_name) == 0) {
@@ -161,7 +162,7 @@ static void config_handle_keyboard(struct roots_config *config,
}
if (!found) {
- kc = calloc(1, sizeof(struct keyboard_config));
+ kc = calloc(1, sizeof(struct roots_keyboard_config));
kc->name = strdup(device_name);
wl_list_insert(&config->keyboards, &kc->link);
}
@@ -194,20 +195,20 @@ static int config_ini_handler(void *user, const char *section, const char *name,
const char *value) {
struct roots_config *config = user;
if (strcmp(section, "core") == 0) {
- if (strcmp(name, "xwayland") == 0) {
- if (strcasecmp(value, "true") == 0) {
- config->xwayland = true;
- } else if (strcasecmp(value, "false") == 0) {
- config->xwayland = false;
- } else {
- wlr_log(L_ERROR, "got unknown xwayland value: %s", value);
- }
- } else {
- wlr_log(L_ERROR, "got unknown core config: %s", name);
- }
+ if (strcmp(name, "xwayland") == 0) {
+ if (strcasecmp(value, "true") == 0) {
+ config->xwayland = true;
+ } else if (strcasecmp(value, "false") == 0) {
+ config->xwayland = false;
+ } else {
+ wlr_log(L_ERROR, "got unknown xwayland value: %s", value);
+ }
+ } else {
+ wlr_log(L_ERROR, "got unknown core config: %s", name);
+ }
} else if (strncmp(output_prefix, section, strlen(output_prefix)) == 0) {
const char *output_name = section + strlen(output_prefix);
- struct output_config *oc;
+ struct roots_output_config *oc;
bool found = false;
wl_list_for_each(oc, &config->outputs, link) {
@@ -218,7 +219,7 @@ static int config_ini_handler(void *user, const char *section, const char *name,
}
if (!found) {
- oc = calloc(1, sizeof(struct output_config));
+ oc = calloc(1, sizeof(struct roots_output_config));
oc->name = strdup(output_name);
oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
oc->scale = 1;
@@ -281,7 +282,7 @@ static int config_ini_handler(void *user, const char *section, const char *name,
} else if (strncmp(device_prefix, section, strlen(device_prefix)) == 0) {
const char *device_name = section + strlen(device_prefix);
- struct device_config *dc;
+ struct roots_device_config *dc;
bool found = false;
wl_list_for_each(dc, &config->devices, link) {
if (strcmp(dc->name, device_name) == 0) {
@@ -291,7 +292,7 @@ static int config_ini_handler(void *user, const char *section, const char *name,
}
if (!found) {
- dc = calloc(1, sizeof(struct device_config));
+ dc = calloc(1, sizeof(struct roots_device_config));
dc->name = strdup(device_name);
dc->seat = strdup("seat0");
wl_list_insert(&config->devices, &dc->link);
@@ -311,7 +312,8 @@ static int config_ini_handler(void *user, const char *section, const char *name,
}
} else if (strcmp(section, "keyboard") == 0) {
config_handle_keyboard(config, "", name, value);
- } else if (strncmp(keyboard_prefix, section, strlen(keyboard_prefix)) == 0) {
+ } else if (strncmp(keyboard_prefix,
+ section, strlen(keyboard_prefix)) == 0) {
const char *device_name = section + strlen(keyboard_prefix);
config_handle_keyboard(config, device_name, name, value);
} else if (strcmp(section, "bindings") == 0) {
@@ -323,7 +325,7 @@ static int config_ini_handler(void *user, const char *section, const char *name,
return 1;
}
-struct roots_config *parse_args(int argc, char *argv[]) {
+struct roots_config *roots_config_create_from_args(int argc, char *argv[]) {
struct roots_config *config = calloc(1, sizeof(struct roots_config));
if (config == NULL) {
return NULL;
@@ -370,7 +372,8 @@ struct roots_config *parse_args(int argc, char *argv[]) {
add_binding_config(&config->bindings, "Logo+Shift+E", "exit");
add_binding_config(&config->bindings, "Ctrl+q", "close");
add_binding_config(&config->bindings, "Alt+Tab", "next_window");
- struct keyboard_config *kc = calloc(1, sizeof(struct keyboard_config));
+ struct roots_keyboard_config *kc =
+ calloc(1, sizeof(struct roots_keyboard_config));
kc->meta_key = WLR_MODIFIER_LOGO;
kc->name = strdup("");
wl_list_insert(&config->keyboards, &kc->link);
@@ -386,13 +389,13 @@ struct roots_config *parse_args(int argc, char *argv[]) {
}
void roots_config_destroy(struct roots_config *config) {
- struct output_config *oc, *otmp = NULL;
+ struct roots_output_config *oc, *otmp = NULL;
wl_list_for_each_safe(oc, otmp, &config->outputs, link) {
free(oc->name);
free(oc);
}
- struct device_config *dc, *dtmp = NULL;
+ struct roots_device_config *dc, *dtmp = NULL;
wl_list_for_each_safe(dc, dtmp, &config->devices, link) {
free(dc->name);
free(dc->seat);
@@ -401,7 +404,7 @@ void roots_config_destroy(struct roots_config *config) {
free(dc);
}
- struct keyboard_config *kc, *ktmp = NULL;
+ struct roots_keyboard_config *kc, *ktmp = NULL;
wl_list_for_each_safe(kc, ktmp, &config->bindings, link) {
free(kc->name);
free(kc->rules);
@@ -412,7 +415,7 @@ void roots_config_destroy(struct roots_config *config) {
free(kc);
}
- struct binding_config *bc, *btmp = NULL;
+ struct roots_binding_config *bc, *btmp = NULL;
wl_list_for_each_safe(bc, btmp, &config->bindings, link) {
free(bc->keysyms);
free(bc->command);
@@ -425,9 +428,9 @@ void roots_config_destroy(struct roots_config *config) {
free(config);
}
-struct output_config *config_get_output(struct roots_config *config,
+struct roots_output_config *roots_config_get_output(struct roots_config *config,
struct wlr_output *output) {
- struct output_config *o_config;
+ struct roots_output_config *o_config;
wl_list_for_each(o_config, &config->outputs, link) {
if (strcmp(o_config->name, output->name) == 0) {
return o_config;
@@ -437,9 +440,9 @@ struct output_config *config_get_output(struct roots_config *config,
return NULL;
}
-struct device_config *config_get_device(struct roots_config *config,
+struct roots_device_config *roots_config_get_device(struct roots_config *config,
struct wlr_input_device *device) {
- struct device_config *d_config;
+ struct roots_device_config *d_config;
wl_list_for_each(d_config, &config->devices, link) {
if (strcmp(d_config->name, device->name) == 0) {
return d_config;
@@ -449,9 +452,9 @@ struct device_config *config_get_device(struct roots_config *config,
return NULL;
}
-struct keyboard_config *config_get_keyboard(struct roots_config *config,
- struct wlr_input_device *device) {
- struct keyboard_config *kc;
+struct roots_keyboard_config *roots_config_get_keyboard(
+ struct roots_config *config, struct wlr_input_device *device) {
+ struct roots_keyboard_config *kc;
wl_list_for_each(kc, &config->keyboards, link) {
if ((device != NULL && strcmp(kc->name, device->name) == 0) ||
(device == NULL && strcmp(kc->name, "") == 0)) {
diff --git a/rootston/input.c b/rootston/input.c
index e96565e0..35a5af97 100644
--- a/rootston/input.c
+++ b/rootston/input.c
@@ -44,7 +44,8 @@ static void input_add_notify(struct wl_listener *listener, void *data) {
struct roots_input *input = wl_container_of(listener, input, input_add);
char *seat_name = "seat0";
- struct device_config *dc = config_get_device(input->config, device);
+ struct roots_device_config *dc =
+ roots_config_get_device(input->config, device);
if (dc) {
seat_name = dc->seat;
}
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index bb748550..c118e55c 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -92,7 +92,7 @@ static bool keyboard_keysym_press(struct roots_keyboard *keyboard,
uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
struct wl_list *bindings = &keyboard->input->server->config->bindings;
- struct binding_config *bc;
+ struct roots_binding_config *bc;
wl_list_for_each(bc, bindings, link) {
if (modifiers ^ bc->modifiers) {
continue;
@@ -210,8 +210,8 @@ void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard) {
wlr_seat_keyboard_notify_modifiers(seat);
}
-static void keyboard_config_merge(struct keyboard_config *config,
- struct keyboard_config *fallback) {
+static void keyboard_config_merge(struct roots_keyboard_config *config,
+ struct roots_keyboard_config *fallback) {
if (fallback == NULL) {
return;
}
@@ -248,15 +248,16 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
keyboard->device = device;
keyboard->input = input;
- struct keyboard_config *config = calloc(1, sizeof(struct keyboard_config));
+ struct roots_keyboard_config *config =
+ calloc(1, sizeof(struct roots_keyboard_config));
if (config == NULL) {
free(keyboard);
return NULL;
}
- keyboard_config_merge(config, config_get_keyboard(input->config, device));
- keyboard_config_merge(config, config_get_keyboard(input->config, NULL));
+ keyboard_config_merge(config, roots_config_get_keyboard(input->config, device));
+ keyboard_config_merge(config, roots_config_get_keyboard(input->config, NULL));
- struct keyboard_config env_config = {
+ struct roots_keyboard_config env_config = {
.rules = getenv("XKB_DEFAULT_RULES"),
.model = getenv("XKB_DEFAULT_MODEL"),
.layout = getenv("XKB_DEFAULT_LAYOUT"),
diff --git a/rootston/main.c b/rootston/main.c
index 2a054e6c..d55bc682 100644
--- a/rootston/main.c
+++ b/rootston/main.c
@@ -13,7 +13,7 @@
struct roots_server server = { 0 };
int main(int argc, char **argv) {
- assert(server.config = parse_args(argc, argv));
+ assert(server.config = roots_config_create_from_args(argc, argv));
assert(server.wl_display = wl_display_create());
assert(server.wl_event_loop = wl_display_get_event_loop(server.wl_display));
diff --git a/rootston/output.c b/rootston/output.c
index f192cb48..d853c45f 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -181,7 +181,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
output->last_frame = desktop->last_frame = now;
}
-static void set_mode(struct wlr_output *output, struct output_config *oc) {
+static void set_mode(struct wlr_output *output,
+ struct roots_output_config *oc) {
struct wlr_output_mode *mode, *best = NULL;
int mhz = (int)(oc->mode.refresh_rate * 1000);
wl_list_for_each(mode, &output->modes, link) {
@@ -225,7 +226,8 @@ void output_add_notify(struct wl_listener *listener, void *data) {
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&desktop->outputs, &output->link);
- struct output_config *output_config = config_get_output(config, wlr_output);
+ struct roots_output_config *output_config =
+ roots_config_get_output(config, wlr_output);
if (output_config) {
if (output_config->mode.width) {
set_mode(wlr_output, output_config);
diff --git a/rootston/seat.c b/rootston/seat.c
index 3530fb75..4602aad5 100644
--- a/rootston/seat.c
+++ b/rootston/seat.c
@@ -117,8 +117,8 @@ static void seat_reset_device_mappings(struct roots_seat *seat, struct wlr_input
struct roots_config *config = seat->input->config;
wlr_cursor_map_input_to_output(cursor, device, NULL);
- struct device_config *dconfig;
- if ((dconfig = config_get_device(config, device))) {
+ struct roots_device_config *dconfig;
+ if ((dconfig = roots_config_get_device(config, device))) {
wlr_cursor_map_input_to_region(cursor, device, dconfig->mapped_box);
}
}
@@ -127,8 +127,8 @@ static void seat_set_device_output_mappings(struct roots_seat *seat,
struct wlr_input_device *device, struct wlr_output *output) {
struct wlr_cursor *cursor = seat->cursor->cursor;
struct roots_config *config = seat->input->config;
- struct device_config *dconfig;
- dconfig = config_get_device(config, device);
+ struct roots_device_config *dconfig;
+ dconfig = roots_config_get_device(config, device);
if (dconfig && dconfig->mapped_output &&
strcmp(dconfig->mapped_output, output->name) == 0) {
wlr_cursor_map_input_to_output(cursor, device, output);