1
0
mirror of https://codeberg.org/vyivel/dulcepan/ synced 2025-03-12 10:49:15 +02:00

Add customizable keybinds

This commit is contained in:
Kirill Primak 2024-06-20 19:26:38 +03:00
parent 8e8cdf1f32
commit eba288479e
4 changed files with 27 additions and 9 deletions

View File

@ -14,3 +14,7 @@ quick-select = false
# PNG (zlib) compression level, 0-9
png-compression = 6
# Key bindings
quit-key = Escape
save-key = Space

View File

@ -71,10 +71,19 @@ static void load_bool(const char *value, int line_idx, bool *out) {
}
}
static void load_key(const char *value, int line_idx, xkb_keysym_t *out) {
*out = xkb_keysym_from_name(value, XKB_KEYSYM_CASE_INSENSITIVE);
if (*out == XKB_KEY_NoSymbol) {
dp_log_fatal("Config: unknown key %s on line %d", value, line_idx);
}
}
void dp_config_load(struct dp_config *config, const char *user_path) {
FILE *fp = NULL;
*config = (struct dp_config){
.quit_key = XKB_KEY_Escape,
.save_key = XKB_KEY_space,
.border_size = 2,
.png_compression = 6,
.quick_select = false,
@ -177,6 +186,10 @@ void dp_config_load(struct dp_config *config, const char *user_path) {
}
} else if (strcmp(key, "quick-select") == 0) {
load_bool(value, line_idx, &config->quick_select);
} else if (strcmp(key, "quit-key") == 0) {
load_key(value, line_idx, &config->quit_key);
} else if (strcmp(key, "save-key") == 0) {
load_key(value, line_idx, &config->save_key);
} else {
dp_log_fatal("Config: unknown key %s on line %d", key, line_idx);
}

View File

@ -5,6 +5,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <wayland-util.h>
#include <xkbcommon/xkbcommon.h>
// Per-output
#define DP_SWAPCHAIN_LEN 2
@ -125,6 +126,8 @@ struct dp_config {
pixman_color_t unselected_color;
pixman_color_t selected_color;
pixman_color_t border_color;
xkb_keysym_t quit_key;
xkb_keysym_t save_key;
int border_size; // 0 if disabled
int png_compression;
bool quick_select;

View File

@ -59,15 +59,13 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, uin
xkb_keysym_t keysym = xkb_state_key_get_one_sym(seat->xkb_state, keycode + 8);
// TODO: configurable
// TODO: more actions
switch (keysym) {
case XKB_KEY_q:
seat->state->status = DP_STATUS_QUIT;
break;
case XKB_KEY_s:
seat->state->status = DP_STATUS_SAVED;
break;
struct dp_state *state = seat->state;
struct dp_config *config = &state->config;
if (keysym == config->quit_key) {
state->status = DP_STATUS_QUIT;
} else if (keysym == config->save_key) {
state->status = DP_STATUS_SAVED;
}
}