mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-30 00:15:58 +01:00
rootston: prefix config structs and functions
This commit is contained in:
parent
18079e234a
commit
1db3b55128
8 changed files with 51 additions and 45 deletions
|
@ -3,7 +3,7 @@
|
|||
#include <wlr/types/wlr_output_layout.h>
|
||||
#include <wlr/types/wlr_input_device.h>
|
||||
|
||||
struct output_config {
|
||||
struct roots_output_config {
|
||||
char *name;
|
||||
enum wl_output_transform transform;
|
||||
int x, y;
|
||||
|
@ -15,7 +15,7 @@ struct output_config {
|
|||
} mode;
|
||||
};
|
||||
|
||||
struct device_config {
|
||||
struct roots_device_config {
|
||||
char *name;
|
||||
char *mapped_output;
|
||||
struct wlr_box *mapped_box;
|
||||
|
@ -23,7 +23,7 @@ struct device_config {
|
|||
struct wl_list link;
|
||||
};
|
||||
|
||||
struct binding_config {
|
||||
struct roots_binding_config {
|
||||
uint32_t modifiers;
|
||||
xkb_keysym_t *keysyms;
|
||||
size_t keysyms_len;
|
||||
|
@ -31,7 +31,7 @@ struct binding_config {
|
|||
struct wl_list link;
|
||||
};
|
||||
|
||||
struct keyboard_config {
|
||||
struct roots_keyboard_config {
|
||||
char *name;
|
||||
uint32_t meta_key;
|
||||
char *rules;
|
||||
|
@ -63,7 +63,7 @@ struct roots_config {
|
|||
* arguments can specify the location of the config file. If it is not
|
||||
* specified, the default location will be used.
|
||||
*/
|
||||
struct roots_config *parse_args(int argc, char *argv[]);
|
||||
struct roots_config *roots_config_create_from_args(int argc, char *argv[]);
|
||||
|
||||
/**
|
||||
* Destroy the config and free its resources.
|
||||
|
@ -74,21 +74,21 @@ void roots_config_destroy(struct roots_config *config);
|
|||
* Get configuration for the output. If the output is not configured, returns
|
||||
* NULL.
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Get configuration for the device. If the device is not configured, returns
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Get configuration for the keyboard. If the keyboard is not configured,
|
||||
* returns NULL. A NULL device returns the default config for keyboards.
|
||||
*/
|
||||
struct keyboard_config *config_get_keyboard(struct roots_config *config,
|
||||
struct wlr_input_device *device);
|
||||
struct roots_keyboard_config *roots_config_get_keyboard(
|
||||
struct roots_config *config, struct wlr_input_device *device);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,7 +10,7 @@ struct roots_keyboard {
|
|||
struct roots_input *input;
|
||||
struct roots_seat *seat;
|
||||
struct wlr_input_device *device;
|
||||
struct keyboard_config *config;
|
||||
struct roots_keyboard_config *config;
|
||||
struct wl_list link;
|
||||
|
||||
struct wl_listener keyboard_key;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -207,7 +208,7 @@ static int config_ini_handler(void *user, const char *section, const char *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);
|
||||
|
@ -323,7 +324,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 +371,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 +388,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 +403,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 +414,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 +427,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 +439,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 +451,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)) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue