mirror of
https://codeberg.org/vyivel/dulcepan/
synced 2025-03-13 19:29:17 +02:00
Add customizable keybinds
This commit is contained in:
parent
8e8cdf1f32
commit
eba288479e
@ -14,3 +14,7 @@ quick-select = false
|
|||||||
|
|
||||||
# PNG (zlib) compression level, 0-9
|
# PNG (zlib) compression level, 0-9
|
||||||
png-compression = 6
|
png-compression = 6
|
||||||
|
|
||||||
|
# Key bindings
|
||||||
|
quit-key = Escape
|
||||||
|
save-key = Space
|
||||||
|
13
src/config.c
13
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) {
|
void dp_config_load(struct dp_config *config, const char *user_path) {
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
|
|
||||||
*config = (struct dp_config){
|
*config = (struct dp_config){
|
||||||
|
.quit_key = XKB_KEY_Escape,
|
||||||
|
.save_key = XKB_KEY_space,
|
||||||
.border_size = 2,
|
.border_size = 2,
|
||||||
.png_compression = 6,
|
.png_compression = 6,
|
||||||
.quick_select = false,
|
.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) {
|
} else if (strcmp(key, "quick-select") == 0) {
|
||||||
load_bool(value, line_idx, &config->quick_select);
|
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 {
|
} else {
|
||||||
dp_log_fatal("Config: unknown key %s on line %d", key, line_idx);
|
dp_log_fatal("Config: unknown key %s on line %d", key, line_idx);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <wayland-util.h>
|
#include <wayland-util.h>
|
||||||
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
|
||||||
// Per-output
|
// Per-output
|
||||||
#define DP_SWAPCHAIN_LEN 2
|
#define DP_SWAPCHAIN_LEN 2
|
||||||
@ -125,6 +126,8 @@ struct dp_config {
|
|||||||
pixman_color_t unselected_color;
|
pixman_color_t unselected_color;
|
||||||
pixman_color_t selected_color;
|
pixman_color_t selected_color;
|
||||||
pixman_color_t border_color;
|
pixman_color_t border_color;
|
||||||
|
xkb_keysym_t quit_key;
|
||||||
|
xkb_keysym_t save_key;
|
||||||
int border_size; // 0 if disabled
|
int border_size; // 0 if disabled
|
||||||
int png_compression;
|
int png_compression;
|
||||||
bool quick_select;
|
bool quick_select;
|
||||||
|
16
src/seat.c
16
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);
|
xkb_keysym_t keysym = xkb_state_key_get_one_sym(seat->xkb_state, keycode + 8);
|
||||||
|
|
||||||
// TODO: configurable
|
struct dp_state *state = seat->state;
|
||||||
// TODO: more actions
|
struct dp_config *config = &state->config;
|
||||||
switch (keysym) {
|
|
||||||
case XKB_KEY_q:
|
if (keysym == config->quit_key) {
|
||||||
seat->state->status = DP_STATUS_QUIT;
|
state->status = DP_STATUS_QUIT;
|
||||||
break;
|
} else if (keysym == config->save_key) {
|
||||||
case XKB_KEY_s:
|
state->status = DP_STATUS_SAVED;
|
||||||
seat->state->status = DP_STATUS_SAVED;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user