mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-23 05:15:58 +01:00
Per-keyboard configuration
This commit is contained in:
parent
92b41bb51f
commit
4e5d23daa9
5 changed files with 118 additions and 20 deletions
|
@ -26,6 +26,17 @@ struct binding_config {
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct keyboard_config {
|
||||||
|
char *name;
|
||||||
|
uint32_t meta_key;
|
||||||
|
char *rules;
|
||||||
|
char *model;
|
||||||
|
char *layout;
|
||||||
|
char *variant;
|
||||||
|
char *options;
|
||||||
|
struct wl_list link;
|
||||||
|
};
|
||||||
|
|
||||||
struct roots_config {
|
struct roots_config {
|
||||||
bool xwayland;
|
bool xwayland;
|
||||||
// TODO: Multiple cursors, multiseat
|
// TODO: Multiple cursors, multiseat
|
||||||
|
@ -34,13 +45,10 @@ struct roots_config {
|
||||||
struct wlr_box *mapped_box;
|
struct wlr_box *mapped_box;
|
||||||
} cursor;
|
} cursor;
|
||||||
|
|
||||||
struct {
|
|
||||||
uint32_t meta_key;
|
|
||||||
} keyboard;
|
|
||||||
|
|
||||||
struct wl_list outputs;
|
struct wl_list outputs;
|
||||||
struct wl_list devices;
|
struct wl_list devices;
|
||||||
struct wl_list bindings;
|
struct wl_list bindings;
|
||||||
|
struct wl_list keyboards;
|
||||||
char *config_path;
|
char *config_path;
|
||||||
char *startup_cmd;
|
char *startup_cmd;
|
||||||
};
|
};
|
||||||
|
@ -63,4 +71,11 @@ struct output_config *config_get_output(struct roots_config *config,
|
||||||
struct device_config *config_get_device(struct roots_config *config,
|
struct device_config *config_get_device(struct roots_config *config,
|
||||||
struct wlr_input_device *device);
|
struct wlr_input_device *device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configuration for the keyboard. If the keyboard is not configured,
|
||||||
|
* returns NULL.
|
||||||
|
*/
|
||||||
|
struct keyboard_config *config_get_keyboard(struct roots_config *config,
|
||||||
|
struct wlr_input_device *device);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -149,6 +149,7 @@ void add_binding_config(struct wl_list *bindings, const char* combination,
|
||||||
|
|
||||||
static const char *output_prefix = "output:";
|
static const char *output_prefix = "output:";
|
||||||
static const char *device_prefix = "device:";
|
static const char *device_prefix = "device:";
|
||||||
|
static const char *keyboard_prefix = "keyboard:";
|
||||||
|
|
||||||
static int config_ini_handler(void *user, const char *section, const char *name,
|
static int config_ini_handler(void *user, const char *section, const char *name,
|
||||||
const char *value) {
|
const char *value) {
|
||||||
|
@ -219,9 +220,9 @@ static int config_ini_handler(void *user, const char *section, const char *name,
|
||||||
}
|
}
|
||||||
} else if (strncmp(device_prefix, section, strlen(device_prefix)) == 0) {
|
} else if (strncmp(device_prefix, section, strlen(device_prefix)) == 0) {
|
||||||
const char *device_name = section + strlen(device_prefix);
|
const char *device_name = section + strlen(device_prefix);
|
||||||
|
|
||||||
struct device_config *dc;
|
struct device_config *dc;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
wl_list_for_each(dc, &config->devices, link) {
|
wl_list_for_each(dc, &config->devices, link) {
|
||||||
if (strcmp(dc->name, device_name) == 0) {
|
if (strcmp(dc->name, device_name) == 0) {
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -244,12 +245,39 @@ static int config_ini_handler(void *user, const char *section, const char *name,
|
||||||
} else {
|
} else {
|
||||||
wlr_log(L_ERROR, "got unknown device config: %s", name);
|
wlr_log(L_ERROR, "got unknown device config: %s", name);
|
||||||
}
|
}
|
||||||
} else if (strcmp(section, "keyboard") == 0) {
|
} else if (strncmp(keyboard_prefix, section, strlen(keyboard_prefix)) == 0) {
|
||||||
|
const char *device_name = section + strlen(keyboard_prefix);
|
||||||
|
|
||||||
|
struct keyboard_config *kc;
|
||||||
|
bool found = false;
|
||||||
|
wl_list_for_each(kc, &config->keyboards, link) {
|
||||||
|
if (strcmp(kc->name, device_name) == 0) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
kc = calloc(1, sizeof(struct keyboard_config));
|
||||||
|
kc->name = strdup(device_name);
|
||||||
|
wl_list_insert(&config->keyboards, &kc->link);
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(name, "meta-key") == 0) {
|
if (strcmp(name, "meta-key") == 0) {
|
||||||
config->keyboard.meta_key = parse_modifier(value);
|
kc->meta_key = parse_modifier(value);
|
||||||
if (config->keyboard.meta_key == 0) {
|
if (kc->meta_key == 0) {
|
||||||
wlr_log(L_ERROR, "got unknown meta key: %s", name);
|
wlr_log(L_ERROR, "got unknown meta key: %s", name);
|
||||||
}
|
}
|
||||||
|
} else if (strcmp(name, "rules") == 0) {
|
||||||
|
kc->rules = strdup(value);
|
||||||
|
} else if (strcmp(name, "model") == 0) {
|
||||||
|
kc->model = strdup(value);
|
||||||
|
} else if (strcmp(name, "layout") == 0) {
|
||||||
|
kc->layout = strdup(value);
|
||||||
|
} else if (strcmp(name, "variant") == 0) {
|
||||||
|
kc->variant = strdup(value);
|
||||||
|
} else if (strcmp(name, "options") == 0) {
|
||||||
|
kc->options = strdup(value);
|
||||||
} else {
|
} else {
|
||||||
wlr_log(L_ERROR, "got unknown keyboard config: %s", name);
|
wlr_log(L_ERROR, "got unknown keyboard config: %s", name);
|
||||||
}
|
}
|
||||||
|
@ -271,6 +299,7 @@ struct roots_config *parse_args(int argc, char *argv[]) {
|
||||||
config->xwayland = true;
|
config->xwayland = true;
|
||||||
wl_list_init(&config->outputs);
|
wl_list_init(&config->outputs);
|
||||||
wl_list_init(&config->devices);
|
wl_list_init(&config->devices);
|
||||||
|
wl_list_init(&config->keyboards);
|
||||||
wl_list_init(&config->bindings);
|
wl_list_init(&config->bindings);
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
|
@ -305,10 +334,12 @@ struct roots_config *parse_args(int argc, char *argv[]) {
|
||||||
|
|
||||||
if (result == -1) {
|
if (result == -1) {
|
||||||
wlr_log(L_DEBUG, "No config file found. Using sensible defaults.");
|
wlr_log(L_DEBUG, "No config file found. Using sensible defaults.");
|
||||||
config->keyboard.meta_key = WLR_MODIFIER_LOGO;
|
|
||||||
add_binding_config(&config->bindings, "Logo+Shift+E", "exit");
|
add_binding_config(&config->bindings, "Logo+Shift+E", "exit");
|
||||||
add_binding_config(&config->bindings, "Ctrl+q", "close");
|
add_binding_config(&config->bindings, "Ctrl+q", "close");
|
||||||
add_binding_config(&config->bindings, "Alt+Tab", "next_window");
|
add_binding_config(&config->bindings, "Alt+Tab", "next_window");
|
||||||
|
struct keyboard_config *kc = calloc(1, sizeof(struct keyboard_config));
|
||||||
|
kc->meta_key = WLR_MODIFIER_LOGO;
|
||||||
|
wl_list_insert(&config->keyboards, &kc->link);
|
||||||
} else if (result == -2) {
|
} else if (result == -2) {
|
||||||
wlr_log(L_ERROR, "Could not allocate memory to parse config file");
|
wlr_log(L_ERROR, "Could not allocate memory to parse config file");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -335,6 +366,17 @@ void roots_config_destroy(struct roots_config *config) {
|
||||||
free(dc);
|
free(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct keyboard_config *kc, *ktmp = NULL;
|
||||||
|
wl_list_for_each_safe(kc, ktmp, &config->bindings, link) {
|
||||||
|
free(kc->name);
|
||||||
|
free(kc->rules);
|
||||||
|
free(kc->model);
|
||||||
|
free(kc->layout);
|
||||||
|
free(kc->variant);
|
||||||
|
free(kc->options);
|
||||||
|
free(kc);
|
||||||
|
}
|
||||||
|
|
||||||
struct binding_config *bc, *btmp = NULL;
|
struct binding_config *bc, *btmp = NULL;
|
||||||
wl_list_for_each_safe(bc, btmp, &config->bindings, link) {
|
wl_list_for_each_safe(bc, btmp, &config->bindings, link) {
|
||||||
free(bc->keysyms);
|
free(bc->keysyms);
|
||||||
|
@ -371,3 +413,18 @@ struct device_config *config_get_device(struct roots_config *config,
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct keyboard_config *config_get_keyboard(struct roots_config *config,
|
||||||
|
struct wlr_input_device *device) {
|
||||||
|
struct keyboard_config *kc;
|
||||||
|
struct keyboard_config *default_kc = NULL;
|
||||||
|
wl_list_for_each(kc, &config->keyboards, link) {
|
||||||
|
if (strcmp(kc->name, "*") == 0) {
|
||||||
|
default_kc = kc;
|
||||||
|
} else if (strcmp(kc->name, device->name) == 0) {
|
||||||
|
return kc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return default_kc;
|
||||||
|
}
|
||||||
|
|
|
@ -215,8 +215,14 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) {
|
||||||
event->orientation, event->delta);
|
event->orientation, event->delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_meta_pressed(struct roots_input *input) {
|
static bool is_meta_pressed(struct roots_input *input,
|
||||||
uint32_t meta_key = input->server->config->keyboard.meta_key;
|
struct wlr_input_device *device) {
|
||||||
|
struct keyboard_config *config = config_get_keyboard(input->server->config,
|
||||||
|
device);
|
||||||
|
uint32_t meta_key = 0;
|
||||||
|
if (config != NULL) {
|
||||||
|
meta_key = config->meta_key;
|
||||||
|
}
|
||||||
if (meta_key == 0) {
|
if (meta_key == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -241,7 +247,7 @@ static void do_cursor_button_press(struct roots_input *input,
|
||||||
struct roots_view *view = view_at(desktop,
|
struct roots_view *view = view_at(desktop,
|
||||||
input->cursor->x, input->cursor->y, &surface, &sx, &sy);
|
input->cursor->x, input->cursor->y, &surface, &sx, &sy);
|
||||||
|
|
||||||
if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input)) {
|
if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input, device)) {
|
||||||
set_view_focus(input, desktop, view);
|
set_view_focus(input, desktop, view);
|
||||||
|
|
||||||
switch (button) {
|
switch (button) {
|
||||||
|
|
|
@ -137,13 +137,33 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
|
||||||
wl_signal_add(&device->keyboard->events.key, &keyboard->key);
|
wl_signal_add(&device->keyboard->events.key, &keyboard->key);
|
||||||
wl_list_insert(&input->keyboards, &keyboard->link);
|
wl_list_insert(&input->keyboards, &keyboard->link);
|
||||||
|
|
||||||
|
struct keyboard_config *config = config_get_keyboard(input->config,
|
||||||
|
device);
|
||||||
|
|
||||||
struct xkb_rule_names rules;
|
struct xkb_rule_names rules;
|
||||||
memset(&rules, 0, sizeof(rules));
|
memset(&rules, 0, sizeof(rules));
|
||||||
|
if (config != NULL) {
|
||||||
|
rules.rules = config->rules;
|
||||||
|
rules.model = config->model;
|
||||||
|
rules.layout = config->layout;
|
||||||
|
rules.variant = config->variant;
|
||||||
|
rules.options = config->options;
|
||||||
|
}
|
||||||
|
if (rules.rules == NULL) {
|
||||||
rules.rules = getenv("XKB_DEFAULT_RULES");
|
rules.rules = getenv("XKB_DEFAULT_RULES");
|
||||||
|
}
|
||||||
|
if (rules.model == NULL) {
|
||||||
rules.model = getenv("XKB_DEFAULT_MODEL");
|
rules.model = getenv("XKB_DEFAULT_MODEL");
|
||||||
|
}
|
||||||
|
if (rules.layout == NULL) {
|
||||||
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
|
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
|
||||||
|
}
|
||||||
|
if (rules.variant == NULL) {
|
||||||
rules.variant = getenv("XKB_DEFAULT_VARIANT");
|
rules.variant = getenv("XKB_DEFAULT_VARIANT");
|
||||||
|
}
|
||||||
|
if (rules.options == NULL) {
|
||||||
rules.options = getenv("XKB_DEFAULT_OPTIONS");
|
rules.options = getenv("XKB_DEFAULT_OPTIONS");
|
||||||
|
}
|
||||||
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||||
if (context == NULL) {
|
if (context == NULL) {
|
||||||
wlr_log(L_ERROR, "Cannot create XKB context");
|
wlr_log(L_ERROR, "Cannot create XKB context");
|
||||||
|
|
|
@ -29,7 +29,7 @@ map-to-output = VGA-1
|
||||||
# Restrict cursor movements for this mouse to concrete rectangle
|
# Restrict cursor movements for this mouse to concrete rectangle
|
||||||
geometry = 2500x800
|
geometry = 2500x800
|
||||||
|
|
||||||
[keyboard]
|
[keyboard:*]
|
||||||
meta-key = Logo
|
meta-key = Logo
|
||||||
|
|
||||||
# Keybindings
|
# Keybindings
|
||||||
|
|
Loading…
Reference in a new issue