opt: keybaord layout config support hotreload to apply

This commit is contained in:
DreamMaoMao 2025-06-11 10:03:53 +08:00
parent 5560623f40
commit 297356a1ef
3 changed files with 119 additions and 14 deletions

View file

@ -880,18 +880,26 @@ void parse_config_line(Config *config, const char *line) {
config->drag_tile_to_tile = atoi(value);
} else if (strcmp(key, "swipe_min_threshold") == 0) {
config->swipe_min_threshold = atoi(value);
} else if (!xkb_rules.rules && strcmp(key, "xkb_rules_rules") == 0) {
xkb_rules.rules = strdup(value);
} else if (!xkb_rules.model && strcmp(key, "xkb_rules_model") == 0) {
xkb_rules.model = strdup(value);
} else if (!xkb_rules.layout && strcmp(key, "xkb_rules_layout") == 0) {
char *new_layouts_str = malloc(256); // 不要释放,只赋值一次
strcpy(new_layouts_str, value);
xkb_rules.layout = new_layouts_str;
} else if (!xkb_rules.variant && strcmp(key, "xkb_rules_variant") == 0) {
xkb_rules.variant = strdup(value);
} else if (!xkb_rules.options && strcmp(key, "xkb_rules_options") == 0) {
xkb_rules.options = strdup(value);
} else if (strcmp(key, "xkb_rules_rules") == 0) {
strncpy(xkb_rules_rules, value, sizeof(xkb_rules_rules) - 1);
xkb_rules_rules[sizeof(xkb_rules_rules) - 1] =
'\0'; // 确保字符串以 null 结尾
} else if (strcmp(key, "xkb_rules_model") == 0) {
strncpy(xkb_rules_model, value, sizeof(xkb_rules_model) - 1);
xkb_rules_model[sizeof(xkb_rules_model) - 1] =
'\0'; // 确保字符串以 null 结尾
} else if (strcmp(key, "xkb_rules_layout") == 0) {
strncpy(xkb_rules_layout, value, sizeof(xkb_rules_layout) - 1);
xkb_rules_layout[sizeof(xkb_rules_layout) - 1] =
'\0'; // 确保字符串以 null 结尾
} else if (strcmp(key, "xkb_rules_variant") == 0) {
strncpy(xkb_rules_variant, value, sizeof(xkb_rules_variant) - 1);
xkb_rules_variant[sizeof(xkb_rules_variant) - 1] =
'\0'; // 确保字符串以 null 结尾
} else if (strcmp(key, "xkb_rules_options") == 0) {
strncpy(xkb_rules_options, value, sizeof(xkb_rules_options) - 1);
xkb_rules_options[sizeof(xkb_rules_options) - 1] =
'\0'; // 确保字符串以 null 结尾
} else if (strcmp(key, "scroller_proportion_preset") == 0) {
// 1. 统计 value 中有多少个逗号,确定需要解析的浮点数个数
int count = 0; // 初始化为 0
@ -2230,6 +2238,7 @@ void reload_config(const Arg *arg) {
parse_config();
init_baked_points();
handlecursoractivity();
reset_keyboard_layout();
run_exec();
// reset border width when config change

View file

@ -102,13 +102,25 @@ Layout layouts[] = {
};
/* keyboard */
/*
only layout can modify after fisrt init
other fields change will be ignored.
*/
char xkb_rules_rules[256];
char xkb_rules_model[256];
char xkb_rules_layout[256];
char xkb_rules_variant[256];
char xkb_rules_options[256];
struct xkb_rule_names xkb_rules = {
/* can specify fields: rules, model, layout, variant, options */
/* example:
.options = "ctrl:nocaps",
*/
.rules = NULL, .model = NULL, .layout = NULL,
.variant = NULL, .options = NULL,
.rules = xkb_rules_rules, .model = xkb_rules_model,
.layout = xkb_rules_layout, .variant = xkb_rules_variant,
.options = xkb_rules_options,
};
int repeat_rate = 25;