diff --git a/dulcepan.cfg b/dulcepan.cfg index 7afa8e0..c73e401 100644 --- a/dulcepan.cfg +++ b/dulcepan.cfg @@ -14,3 +14,7 @@ quick-select = false # PNG (zlib) compression level, 0-9 png-compression = 6 + +# Key bindings +quit-key = Escape +save-key = Space diff --git a/src/config.c b/src/config.c index 0470f4d..24042df 100644 --- a/src/config.c +++ b/src/config.c @@ -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); } diff --git a/src/dulcepan.h b/src/dulcepan.h index 089083d..64bb829 100644 --- a/src/dulcepan.h +++ b/src/dulcepan.h @@ -5,6 +5,7 @@ #include #include #include +#include // 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; diff --git a/src/seat.c b/src/seat.c index cdb76f1..456a1ae 100644 --- a/src/seat.c +++ b/src/seat.c @@ -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; } }