feat: support keybind mode

This commit is contained in:
DreamMaoMao
2025-10-07 11:57:48 +08:00
parent 0622ab463b
commit 572fe6ae27
6 changed files with 64 additions and 3 deletions

View File

@@ -195,6 +195,11 @@ typedef struct {
const Arg arg;
} Button; // 鼠标按键
typedef struct {
char mode[28];
bool isdefault;
} KeyMode;
typedef struct {
unsigned int mod;
unsigned int dir;
@@ -786,7 +791,10 @@ struct dvec2 *baked_points_close;
static struct wl_event_source *hide_source;
static bool cursor_hidden = false;
static bool tag_combo = false;
static KeyMode keymode = {
.mode = {'d', 'e', 'f', 'a', 'u', 'l', 't', '\0'},
.isdefault = true,
};
static struct {
enum wp_cursor_shape_device_v1_shape shape;
struct wlr_surface *surface;
@@ -3265,7 +3273,9 @@ keybinding(unsigned int mods, xkb_keysym_t sym, unsigned int keycode) {
if (config.key_bindings_count < 1)
break;
k = &config.key_bindings[ji];
if (CLEANMASK(mods) == CLEANMASK(k->mod) &&
if ((k->iscommonmode || (k->isdefaultmode && keymode.isdefault) ||
(strcmp(keymode.mode, k->mode) == 0)) &&
CLEANMASK(mods) == CLEANMASK(k->mod) &&
((k->keysymcode.type == KEY_TYPE_SYM &&
normalize_keysym(sym) ==
normalize_keysym(k->keysymcode.keysym)) ||
@@ -3274,6 +3284,7 @@ keybinding(unsigned int mods, xkb_keysym_t sym, unsigned int keycode) {
k->func) {
k->func(&k->arg);
handled = 1;
break;
}
}
return handled;