i3keys icon indicating copy to clipboard operation
i3keys copied to clipboard

sway: i3keys web - Supporting symbol key names starting with a capital letter.

Open junaruga opened this issue 2 years ago • 3 comments

Hi, thanks for providing and maintaining this nice tool!

My environment

I am using sway on Fedora Linux 38.

$ sway --version
sway version 1.8.1

I am using the i3keys on the current latest master branch 99e368e4cbb4f82f4e9461c3fd43054add0c3c37.

The issue summary

In sway, it's possible to define symbol keys as the name starting with a capital letter first such as Return, Space, Semicolon, Comma, Period, Slash. I can see these keys are not shown as occupied (red color) on the page by the i3keys web.

I don't see the capital letter first names worked in i3 config except "Return". But it's nice if i3keys considers the capital letter first key names.

I am using this sway config. https://github.com/junaruga/framework-laptop-config/blob/main/home/.config/sway/config

set $mod Mod4
...
bindsym $mod+Return exec $term
...
bindsym $mod+Shift+Semicolon exec $term
...
# KEY_DELETE 111
bindsym $mod+Comma exec "sudo ydotool key 111:1 111:0"
# KEY_INSERT 110
bindsym $mod+Period exec "sudo ydotool key 110:1 110:0"
# KEY_ENTER 28
bindsym $mod+Slash exec "sudo ydotool key 28:1 28:0"
...
bindsym $mod+Semicolon mode "symbol"
bindsym $mod+Shift+Space mode "symbol"

I was able to see the following $mod+minus was shown as occupied.

bindsym $mod+minus scratchpad show

Here is the actual screenshot. You can see these capital letter first keys are not shown as occupied (red).

screenshot-i3keys-sway

junaruga avatar Oct 05 '23 21:10 junaruga

I confirm. Quick fix is normalizing case in https://github.com/RasmusLindroth/i3keys/blob/99e368e4cbb4f82f4e9461c3fd43054add0c3c37/keyboard/layouts.go#L101

if strings.ToLower(symbol) == strings.ToLower(key.Key)

There may be a better way but this seems to work.

On a side note, key symbols are always capitalized in https://github.com/RasmusLindroth/i3keys/blob/99e368e4cbb4f82f4e9461c3fd43054add0c3c37/helpers/parse.go#L52 but /usr/include/X11/keysymdef.h, which is parsed to generate https://github.com/RasmusLindroth/i3keys/blob/99e368e4cbb4f82f4e9461c3fd43054add0c3c37/xlib/keysyms.go#L4 uses inconsistent capitalization. That should explain why XK_space has the problem but XK_Return does not.

elder-n00b avatar Oct 05 '23 22:10 elder-n00b

I confirm. Quick fix is normalizing case in

https://github.com/RasmusLindroth/i3keys/blob/99e368e4cbb4f82f4e9461c3fd43054add0c3c37/keyboard/layouts.go#L101

if strings.ToLower(symbol) == strings.ToLower(key.Key)

There may be a better way but this seems to work.

Thank you for taking a look at this issue, and suggesting the fix!

On a side note, key symbols are always capitalized in

https://github.com/RasmusLindroth/i3keys/blob/99e368e4cbb4f82f4e9461c3fd43054add0c3c37/helpers/parse.go#L52

but /usr/include/X11/keysymdef.h, which is parsed to generate

https://github.com/RasmusLindroth/i3keys/blob/99e368e4cbb4f82f4e9461c3fd43054add0c3c37/xlib/keysyms.go#L4 uses inconsistent capitalization. That should explain why XK_space has the problem but XK_Return does not.

Oh, I see. Thank you for providing this info. Now I understood why there are inconsistent symbol names in i3 config. It had been a mystery in my mind for a long term.

junaruga avatar Oct 06 '23 19:10 junaruga

I sent the PR https://github.com/RasmusLindroth/i3keys/pull/40!

junaruga avatar Oct 16 '23 20:10 junaruga