opt: normal num key match KP_ num key in keybind

This commit is contained in:
DreamMaoMao 2025-04-22 09:16:14 +08:00
parent bb381c3051
commit 2c2c99aa50
3 changed files with 60 additions and 42 deletions

View file

@ -157,7 +157,7 @@ tags=id:9,layout_name:tile
# monitorrule=HDMI-A-1,0.55,1,tile,0,1,1920,0 # monitorrule=HDMI-A-1,0.55,1,tile,0,1,1920,0
# Key Bindings # Key Bindings
# All keys is not case sensitive, # key name refer to `xev` command output,
# mod keys name: super,ctrl,alt,shift,none # mod keys name: super,ctrl,alt,shift,none
@ -225,51 +225,49 @@ bind=CTRL,Right,viewtoright_have_client,
bind=CTRL+SUPER,Left,tagtoleft, bind=CTRL+SUPER,Left,tagtoleft,
bind=CTRL+SUPER,Right,tagtoright, bind=CTRL+SUPER,Right,tagtoright,
# normal num key is (1-9) bind=Ctrl,1,view,1
# right-side keyboard num keys is (KP_1-KP_9) bind=Ctrl,2,view,2
bind=Ctrl,KP_1,view,1 bind=Ctrl,3,view,3
bind=Ctrl,KP_2,view,2 bind=Ctrl,4,view,4
bind=Ctrl,KP_3,view,3 bind=Ctrl,5,view,5
bind=Ctrl,KP_4,view,4 bind=Ctrl,6,view,6
bind=Ctrl,KP_5,view,5 bind=Ctrl,7,view,7
bind=Ctrl,KP_6,view,6 bind=Ctrl,8,view,8
bind=Ctrl,KP_7,view,7 bind=Ctrl,9,view,9
bind=Ctrl,KP_8,view,8
bind=Ctrl,KP_9,view,9
# tag: move client to the tag and focus it # tag: move client to the tag and focus it
# tagsilent: move client to the tag and not focus it # tagsilent: move client to the tag and not focus it
# bind=Alt,KP_1,tagsilent,1 # bind=Alt,1,tagsilent,1
bind=Alt,KP_1,tag,1 bind=Alt,1,tag,1
bind=Alt,KP_2,tag,2 bind=Alt,2,tag,2
bind=Alt,KP_3,tag,3 bind=Alt,3,tag,3
bind=Alt,KP_4,tag,4 bind=Alt,4,tag,4
bind=Alt,KP_5,tag,5 bind=Alt,5,tag,5
bind=Alt,KP_6,tag,6 bind=Alt,6,tag,6
bind=Alt,KP_7,tag,7 bind=Alt,7,tag,7
bind=Alt,KP_8,tag,8 bind=Alt,8,tag,8
bind=Alt,KP_9,tag,9 bind=Alt,9,tag,9
bind=Super,KP_1,toggletag,1 bind=Super,1,toggletag,1
bind=Super,KP_2,toggletag,2 bind=Super,2,toggletag,2
bind=Super,KP_3,toggletag,3 bind=Super,3,toggletag,3
bind=Super,KP_4,toggletag,4 bind=Super,4,toggletag,4
bind=Super,KP_5,toggletag,5 bind=Super,5,toggletag,5
bind=Super,KP_6,toggletag,6 bind=Super,6,toggletag,6
bind=Super,KP_7,toggletag,7 bind=Super,7,toggletag,7
bind=Super,KP_8,toggletag,8 bind=Super,8,toggletag,8
bind=Super,KP_9,toggletag,9 bind=Super,9,toggletag,9
bind=Super+alt,KP_1,toggleview,1 bind=Super+alt,1,toggleview,1
bind=Super+alt,KP_2,toggleview,2 bind=Super+alt,2,toggleview,2
bind=Super+alt,KP_3,toggleview,3 bind=Super+alt,3,toggleview,3
bind=Super+alt,KP_4,toggleview,4 bind=Super+alt,4,toggleview,4
bind=Super+alt,KP_5,toggleview,5 bind=Super+alt,5,toggleview,5
bind=Super+alt,KP_6,toggleview,6 bind=Super+alt,6,toggleview,6
bind=Super+alt,KP_7,toggleview,7 bind=Super+alt,7,toggleview,7
bind=Super+alt,KP_8,toggleview,8 bind=Super+alt,8,toggleview,8
bind=Super+alt,KP_9,toggleview,9 bind=Super+alt,9,toggleview,9
# monitor switch # monitor switch
bind=SUPER,bracketleft,focusmon,left bind=SUPER,bracketleft,focusmon,left

View file

@ -3690,7 +3690,7 @@ keybinding(uint32_t mods, xkb_keysym_t sym) {
break; break;
k = &config.key_bindings[ji]; k = &config.key_bindings[ji];
if (CLEANMASK(mods) == CLEANMASK(k->mod) && if (CLEANMASK(mods) == CLEANMASK(k->mod) &&
xkb_keysym_to_lower(sym) == k->keysym && k->func) { normalize_keysym(sym) == normalize_keysym(k->keysym) && k->func) {
k->func(&k->arg); k->func(&k->arg);
handled = 1; handled = 1;
} }

View file

@ -254,6 +254,26 @@ long int parse_color(const char *hex_str) {
return hex_num; return hex_num;
} }
xkb_keysym_t normalize_keysym(xkb_keysym_t sym) {
// 首先转换为小写
sym = xkb_keysym_to_lower(sym);
// 将数字小键盘键转换为普通数字键
switch (sym) {
case XKB_KEY_KP_0: return XKB_KEY_0;
case XKB_KEY_KP_1: return XKB_KEY_1;
case XKB_KEY_KP_2: return XKB_KEY_2;
case XKB_KEY_KP_3: return XKB_KEY_3;
case XKB_KEY_KP_4: return XKB_KEY_4;
case XKB_KEY_KP_5: return XKB_KEY_5;
case XKB_KEY_KP_6: return XKB_KEY_6;
case XKB_KEY_KP_7: return XKB_KEY_7;
case XKB_KEY_KP_8: return XKB_KEY_8;
case XKB_KEY_KP_9: return XKB_KEY_9;
default: return sym;
}
}
// 辅助函数:检查字符串是否以指定的前缀开头(忽略大小写) // 辅助函数:检查字符串是否以指定的前缀开头(忽略大小写)
static bool starts_with_ignore_case(const char *str, const char *prefix) { static bool starts_with_ignore_case(const char *str, const char *prefix) {
while (*prefix) { while (*prefix) {
@ -299,7 +319,7 @@ uint32_t parse_mod(const char *mod_str) {
} }
xkb_keysym_t parse_keysym(const char *keysym_str) { xkb_keysym_t parse_keysym(const char *keysym_str) {
return xkb_keysym_to_lower(xkb_keysym_from_name(keysym_str, XKB_KEYSYM_NO_FLAGS)); return xkb_keysym_from_name(keysym_str, XKB_KEYSYM_NO_FLAGS);
} }
int parse_button(const char *str) { int parse_button(const char *str) {