rvaiya / keyd

A key remapping daemon for linux.
MIT License
2.79k stars 167 forks source link

"meta+click" does not work: "space = timeout(overload(meta, space), 1000, space)" #162

Closed funcrab closed 2 years ago

funcrab commented 2 years ago

It seems that space+click is not meta+click when space+click is used in the following configuration. I noticed this because I tried to move (meta+leftclick) and resize (meta+rightclick) the swaywm window and could not.

$ keyd --version
keyd v2.3.0-rc (6581f36)
$
space = timeout(overload(meta, space), 1000, space)
keyd virtual device     xxxx:xxxx       space down
keyd virtual device     xxxx:xxxx       space up

Due to a glitch in the AUR, I have not been able to update to the latest version. https://aur.archlinux.org/packages/keyd-git Sorry if this has been resolved.

rvaiya commented 2 years ago

Unfortunately this is unsupported. keyd is completely ignorant of your mouse, so it can't resolve the timeout on click.

On Wed, Mar 23, 2022 at 7:41 AM Naoki Takahashi @.***> wrote:

It seems that space+click is not meta+click when space+click is used in the following configuration. I noticed this because I tried to move (meta+leftclick) and resize ( meta+rightclick) the swaywm window and could not.

$ keyd --version keyd v2.3.0-rc (6581f36) $

space = timeout(overload(meta, space), 1000, space)

keyd virtual device xxxx:xxxx space down keyd virtual device xxxx:xxxx space up

Due to a glitch in the AUR, I have not been able to update to the latest version. https://aur.archlinux.org/packages/keyd-git Sorry if this has been resolved.

— Reply to this email directly, view it on GitHub https://github.com/rvaiya/keyd/issues/162, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOP7GPOMYM6NJYMKA7FRNDVBL7O3ANCNFSM5RNYG3HA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

funcrab commented 2 years ago

I understand. Thanks. I just wanted the key repeat for the Pagedown and Pageup one-shot keys, set up with two keys to the left and right of the space, as in the configuration below, and I am fine without the key repeat for the space. (I expressed this in the form of meta,space when I requested the key repeat feature because it was easier to explain)

leftalt          = timeout(overload( alt,     pageup),   1000, pageup)
muhenkan         = timeout(overload( control, pagedown), 1000, pagedown)

space            = overload(meta,space)

henkan           = timeout(overload( alt,     pageup),   1000, pageup)
katakanahiragana = timeout(overload( shift,   pagedown), 1000, pagedown)

You may close it.

rvaiya commented 2 years ago

I've added support for this in the latest commit. Let me know if it solves your problem.

funcrab commented 2 years ago

Great. Thank you.

It may be difficult to understand, but it is as follows keyd v2.3.1-rc (013f1e5) space = timeout(overload(meta, space), 1000, space)

space+single click

Kensington      Kensington Expert Mouse 047d:1020       leftmouse down
keyd virtual device     0fac:0ade       leftmeta down
Kensington      Kensington Expert Mouse 047d:1020       leftmouse up

-> It won't be meta+click.

space+double click

Kensington      Kensington Expert Mouse 047d:1020       leftmouse down
keyd virtual device     0fac:0ade       leftmeta down
Kensington      Kensington Expert Mouse 047d:1020       leftmouse up
Kensington      Kensington Expert Mouse 047d:1020       leftmouse down

-> result in meta+click behavior.

https://user-images.githubusercontent.com/55499652/160245966-eb51b00a-74c9-4d5c-89b4-eb3aa70654ac.mp4

rvaiya commented 2 years ago

Ah, yes. The problem is that keyd is only passively monitoring your mouse, so it can't transpose the event order. This is not an issue in the case of oneshot keys, but won't properly break overload ties since the click event propagates independently from the meta event.

The only solution to this is to have keyd actually manage the mouse, but this potentially has other implications (e.g breaking common userspace tools/mouse specific config and potentially interfering with vendor specific libinput logic, etc). It might be possible to make something like this opt-in, but then we are going down the rabbit hole of turning keyd into moused.

funcrab commented 2 years ago

I personally have little need for the timeout+overload+click functionality as I can currently fulfill my expectations without using the timeout (key repeat), but apart from that, you have the (I still don't understand) high scalability and consistency of this timeout functionality I imagine you are thinking about 🤔

rvaiya commented 2 years ago

At the moment I'm treating this as out of scope, since it involves multi-device coordination and would require keyd to get into the business of mouse management. I may revisit it at a later point if there is greater demand or I have some spare time. If you feel strongly about this, feel free to open another issue.

rvaiya commented 2 years ago

This should work now, though you will need to explicitly add the mouse to your config.

funcrab commented 2 years ago

I added the relevant mouse in this way. I can't seem to do it yet in the form of using timeout. Am I doing something wrong?

# paru -Q keyd
keyd-git 2.4.0.r32.6064708-1
# 
[ids]
04fe:0022 #HHKB-Hybrid_1 Keyboard
04fe:000d #PFU Limited  HHKB Professional JP
047d:8019 #Expert Wireless TB Mouse
047d:1020 #Kensington Expert Mouse

[main]

#OK
#space = overload(meta, space)

#NG?
space = timeout(overload(meta, space), 1000, space)

https://user-images.githubusercontent.com/55499652/172599123-61683e4c-8066-47f8-b9ba-3b6711952a56.mp4

rvaiya commented 2 years ago

From what I can see from that video, keyd is outputting the correct sequence, but click+drag fails in your window manger intermittently. Is this correct?

funcrab commented 2 years ago

Certainly the output looks the same.

#1: space = overload(meta, space)
keyd virtual device     0fac:0ade       leftmeta down
keyd virtual pointer    0fac:1ade       leftmouse down
#2: space  = timeout(overload(meta, space), 1000, space)
keyd virtual device     0fac:0ade       leftmeta down
keyd virtual pointer    0fac:1ade       leftmouse down

Sorry if I am wrong. Just a naive guess, but could it be that #2 has a shorter interval after the leftmeta is pressed?

rvaiya commented 2 years ago

My guess would be that your window manager is processing the button event before the key event. I've changed the behaviour to route both through the same virtual device to avoid the issue. Can you try the latest commit?

funcrab commented 2 years ago

Unfortunately, it still doesn't seem to work.

https://user-images.githubusercontent.com/55499652/172851097-e8865889-206e-47a6-b80a-7d0234477bcd.mp4

rvaiya commented 2 years ago

What window manager are you using? Moving forward it might be better to omit KEYD_DEBUG since the motion events makes the output harder to follow.

funcrab commented 2 years ago

The window manager I use is sway. The settings that might be relevant are below, but I don't think they have been changed from their defaults.

~/.config/sway/config

    # Resize them with right mouse button + $mod.
    # Despite the name, also works for non-floating windows.
    # Change normal to inverse to use left mouse button for resizing and right
    # mouse button for dragging.
    floating_modifier $mod normal

It may be more likely to occur in the terminal. I have had this problem with foot and kitty, but not with code (oss version of vscode).

https://user-images.githubusercontent.com/55499652/173048280-1b4060e5-c348-4893-a4bc-419c8aa25e9c.mp4

For me, the need to repeat the space key (using timeout) is not serious, because I have little need for it. If I want to repeat a key, I can work around it by doing it on a different key layer. However, I will test if you feel the need.

rvaiya commented 2 years ago

Thanks for the second demo, I would appreciate your assistance in tracking down the bug. Oddly I can't seem to reproduce this. Your demo would suggest keyd is outputting the correct sequences even in the failure case. Can you post the output of libinput debug-events alongside keyd -m when reproducing the issue?

funcrab commented 2 years ago

I would appreciate your assistance in tracking down the bug.

OK with pleasure👍

# space = timeout(overload(meta, space), 1000, space)

keyd virtual device     0fac:0ade       leftmeta down
keyd virtual device     0fac:0ade       leftmouse down

-event26  KEYBOARD_KEY            +242.686s     KEY_LEFTMETA (125) pressed
 event26  POINTER_BUTTON          +242.686s     BTN_LEFT (272) pressed, seat count: 1

-> meta and click timing are simultaneous

# space = overload(meta, space)

keyd virtual device     0fac:0ade       leftmeta down
keyd virtual device     0fac:0ade       leftmouse down

 event26  KEYBOARD_KEY            +7.513s       KEY_LEFTMETA (125) pressed
 event26  POINTER_BUTTON          +8.550s       BTN_LEFT (272) pressed, seat count: 1

-> Click after meta

https://user-images.githubusercontent.com/55499652/173173032-14b4136d-59b4-4f8a-9ab2-0960c17242cc.mp4

rvaiya commented 2 years ago

Hmm, that only leaves sway itself. Can you see if a more direct binding like grave = M-leftmouse produces the same problem? What version of sway are you running?

tkna91 commented 2 years ago

Occurred in the following

# tab = M-leftmouse

 event26  KEYBOARD_KEY            +137.664s     KEY_LEFTMETA (125) pressed
 event26  POINTER_BUTTON          +137.664s     BTN_LEFT (272) pressed, seat count: 1

version

$ paru -Q sway cairo gdk-pixbuf2 libevdev.so=2-64 libinput libjson-c.so=5-64 libudev.so=1-64 libwayland-server.so=0-64 libwlroots.so=10-64 libxcb libxkbcommon.so=0-64 pango pcre ttf-font
sway 1:1.7-9
cairo 1.17.6-2
gdk-pixbuf2 2.42.8-1
libevdev 1.12.1-1
libinput 1.20.1-1
json-c 0.16-1
systemd-libs 251.2-1
wayland 1.20.0-2
wlroots 0.15.1-5
libxcb 1.15-1
libxkbcommon 1.4.1-1
pango 1:1.50.7-1
pcre 8.45-1
gnu-free-fonts 20120503-8
$

https://user-images.githubusercontent.com/102382754/173209751-6f392714-0ce4-47f1-bd55-f42c7bed4c10.mp4

Note: I am the same person as @funcrab

funcrab commented 2 years ago

I think there was a problem with my sway settings. I did the following and was able to move windows with the tab key. Sorry to bother you.

cd ~/.config/sway
mv config config.bk
reboot

https://user-images.githubusercontent.com/55499652/173217107-1945122a-239c-4b1f-9264-417a95e251e5.mp4

rvaiya commented 2 years ago

No worries. I'm curious to know what the offending setting was. I assume the timeout() binding also works now.

tkna91 commented 2 years ago

Sorry, I'm kind of having trouble reproducing the above. I will do some research.

tkna91 commented 2 years ago

I did a lot of research. I think I got the point, but I am guessing so sorry if I am off. It seems to be a problem in my environment, and it is not possible if the following settings are included.

/etc/enviroment

GTK2_RC_FILES=/usr/share/themes/base16-tomorrow-night/gtk-2.0/gtkrc

https://user-images.githubusercontent.com/102382754/173229146-fc842294-26af-4562-afff-336cd2bb665c.mp4

I think the problem may have been that Wayland could not use GTK2 but was forced to use it. https://wiki.archlinux.org/title/GTK#Wayland_backend

This problem occurred with foot and kitty, which are wayland compatible, and not with alacritty, which is an X11 app.

https://user-images.githubusercontent.com/102382754/173229139-bd6bbe07-e6af-4244-99ac-74c967d92c9f.mp4

tkna91 commented 2 years ago

Sorry, my guess was off. It seems that the behavior just changes every time swaymsg reload.

https://user-images.githubusercontent.com/102382754/173231546-05406bd0-b72b-4139-aabb-1609667a3629.mp4

rvaiya commented 2 years ago

I still can't seem to reproduce this. Can you post your sway config?

tkna91 commented 2 years ago

I renamed the ~/.config/sway directory and rebooted the machine and it still occurred, so I don't think it has anything to do with that.

https://user-images.githubusercontent.com/102382754/173308960-49e2a14c-aa01-4bf5-a89f-9350a3f1bcdc.mp4

If it has anything to do with it, it might be environment variables, etc. I'm running the following sway-run with greetd-tuigreet-bin I don't think it would make any difference if I started it directly from agetty

I can't take the time right now, but I'll take a look in a few days.

$ cat /usr/local/bin/sway-run

#!/bin/sh

#Xwayland disable

# Session
export XDG_SESSION_TYPE=wayland
export XDG_SESSION_DESKTOP=sway
export XDG_CURRENT_DESKTOP=sway
export XDG_CURRENT_SESSION=sway #https://zenn.dev/haxibami/articles/wayland-sway-install

source /usr/local/bin/wayland_enablement.sh

# wayvnc
WLR_BACKENDS=headless
WLR_LIBINPUT_NO_DEVICES=1

systemd-cat --identifier=sway sway $@
$ cat /usr/local/bin/wayland_enablement.sh
#!/bin/sh
export MOZ_ENABLE_WAYLAND=1
export CLUTTER_BACKEND=wayland
#export QT_QPA_PLATFORM=wayland-egl
#export QT_QPA_PLATFORM=wayland
export QT_QPA_PLATFORM="wayland;xcb"
export ECORE_EVAS_ENGINE=wayland-egl
export ELM_ENGINE=wayland_egl
export SDL_VIDEODRIVER=wayland
export _JAVA_AWT_WM_NONREPARENTING=1
export NO_AT_BRIDGE=1
export WINIT_UNIX_BACKEND=x11
$ cat /etc/environment
#
# This file is parsed by pam_env module
#
# Syntax: simple "KEY=VAL" pairs on separate lines

#####
# uim
#####
#export GTK_IM_MODULE='uim'
#export QT_IM_MODULE='uim'
#uim-xim &
#export XMODIFIERS='@im=uim'

#######
# fcitx
#######
# To use kitty
GLFW_IM_MODULE=ibus
# Arch Wiki EN.
GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
SDL_IM_MODULE=fcitx

# GTK
#GTK2_RC_FILES=/usr/share/themes/base16-tomorrow-night/gtk-2.0/gtkrc
$
tkna91 commented 2 years ago

To reduce the impact as much as I could think of, I did the following and checked again. Unfortunately, the operation did not seem to change.

Rename files and directories that may be related to this event

$ cat tmp/rename-20220617.txt | while read i ; do ls -ld $i ; done
ls: cannot access '/etc/environment': No such file or directory
ls: cannot access '/etc/locale.gen': No such file or directory
-rw-r--r-- 1 root root 75 Jun  3 03:32 /etc/locale.conf
ls: cannot access '/etc/profile.d': No such file or directory
ls: cannot access '/etc/bash.bashrc': No such file or directory
ls: cannot access '/usr/share/themes': No such file or directory
ls: cannot access '~/.profile': No such file or directory
ls: cannot access '~/.config/sway': No such file or directory
ls: cannot access '~/.zshrc': No such file or directory
ls: cannot access '~/.config/user-dirs.locale': No such file or directory
ls: cannot access '~/.config/foot': No such file or directory
ls: cannot access '~/.config/kitty': No such file or directory
ls: cannot access '~/.config/gtk-2.0': No such file or directory
ls: cannot access '~/.config/gtk-3.0': No such file or directory
gb1% cat /etc/locale.conf
# This is the fallback locale configuration provided by systemd.

LANG="C"
$

After rebooting the machine, login to agetty as a normal user (a) and perform the following

sway

User environment variables (printenv)

SHELL=/usr/bin/zsh
CLUTTER_BACKEND=wayland
I3SOCK=/run/user/1000/sway-ipc.1000.1445.sock
XDG_CURRENT_SESSION=sway
NO_AT_BRIDGE=1
XCURSOR_SIZE=24
XDG_SEAT=seat0
PWD=/home/a
XDG_SESSION_DESKTOP=sway
LOGNAME=a
XDG_SESSION_TYPE=wayland
ECORE_EVAS_ENGINE=wayland-egl
_=/usr/bin/printenv
MOTD_SHOWN=pam
HOME=/home/a
_JAVA_AWT_WM_NONREPARENTING=1
XDG_CURRENT_DESKTOP=sway
SWAYSOCK=/run/user/1000/sway-ipc.1000.1445.sock
WAYLAND_DISPLAY=wayland-1
WINIT_UNIX_BACKEND=x11
QT_QPA_PLATFORM=wayland;xcb
XDG_SESSION_CLASS=user
TERM=foot
USER=a
SDL_VIDEODRIVER=wayland
DISPLAY=:0
SHLVL=3
MOZ_ENABLE_WAYLAND=1
XDG_VTNR=2
XDG_SESSION_ID=3
XDG_RUNTIME_DIR=/run/user/1000
GREETD_SOCK=/run/greetd-1128.sock
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
ELM_ENGINE=wayland_egl
MAIL=/var/spool/mail/a
OLDPWD=/home/a
COLORTERM=truecolor

Environment variable for root (printenv)

SHELL=/bin/bash
PWD=/root
LOGNAME=root
HOME=/root
TERM=foot
USER=root
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin
_=/usr/bin/printenv

https://user-images.githubusercontent.com/102382754/174333479-55accf69-1e38-4ecc-a69d-371494a3721d.mp4

rvaiya commented 2 years ago

I still can't reproduce this. Can you see if the test branch makes a difference? I've added an artificial delay between the modifier and button press.

E.G

git fetch origin
git checkout origin/test
make

and compare it to the tip of master?

The best way to ensure it isn't a config issue it to create a new user on your machine and run sway with no config.

tkna91 commented 2 years ago

/etc/keyd/test.conf

[ids]

*

[main]

space = timeout(overload(meta, space), 1000, space)

Setting up a test version

$ paru -R keyd-git
$ mkdir ~/.cache/paru/clone/keyd-git_test
$ cp -p ~/.cache/paru/clone/keyd-git/PKGBUILD ~/.cache/paru/clone/keyd-git_test/
$ cd ~/.cache/paru/clone/keyd-git_test
$ $EDITOR PKGBUILD
$ grep "^\(source\|pkgver\)=" PKGBUILD
pkgver=2.4.1.r10.9fb7a1d
source=('git+https://github.com/rvaiya/keyd#branch=test')
$ makepkg -is
$ paru -Q keyd-git
keyd-git 2.4.1.r10.9fb7a1d-1
$ pgrep keyd
$ keyd --version
keyd v2.4.1 (9fb7a1d)
$ sudo systemctl start keyd

Add user, logout

sudo useradd -m newuser1
sudo passwd newuser1
swaymsg exit

I then logged into agetty as newuser1 and ran the sway command.

Then run the usual operations. failure😿

https://user-images.githubusercontent.com/102382754/175353553-686862a2-7c0e-45c3-ac2d-df7ea58258d0.mp4

Shall I check with a new OS installation on a virtual machine such as gnome-boxes?

rvaiya commented 2 years ago

Shall I check with a new OS installation on a virtual machine such as gnome-boxes?

This shouldn't be necessary for now, but thanks for offering.

Would you mind compiling directly from the git repo? I'm not really sure what magic paru is doing, but it seems to be creating its own commit hash.

If you are worried about polluting your system, you don't need to run make install. You can do something like this:

git clone https://github.com/rvaiya/keyd
cd keyd
git checkout origin/test
make && sudo systemctl stop keyd && sudo ./bin/keyd

# Run tests..
# <C-c>

git checkout origin/master && make && sudo ./bin/keyd

# Run tests..
# <C-c>

# Restart your local version
sudo systemctl restart keyd

and test/post the output while it is running.

tkna91 commented 2 years ago

Thank you.

$ ./bin/keyd --version
keyd v2.4.1 (9fb7a1d)
$

OK with test version

https://user-images.githubusercontent.com/102382754/175763001-0f7255b4-1e6b-4315-b5c5-1a377fca36a9.mp4

NG with origin/master

https://user-images.githubusercontent.com/102382754/175762962-2d2aaf75-b87a-4dc8-8a16-a7579952e218.mp4

tkna91 commented 2 years ago

@rvaiya Sorry if you have already noticed this. Presumably this issue appears to have been resolved as well as the status. https://github.com/rvaiya/keyd/commit/9fb7a1da6db9d4b2ab28c1ba711bb1bac3bc7ebb

rvaiya commented 2 years ago

Apologies for letting this languish. I haven't been able to reproduce the issue, but the fact that adding a delay solves the problem and that libinput seems to be seeing the correct output in both cases, would suggest it is a race condition higher up the input stack (i.e sway) potentially affected by something in your environment.

I am loath to add an artificial delay until I am convinced it is strictly necessary. Once I have some free time I will make another attempt, but if you can isolate the components necessary to reproduce it in the meantime, that would greatly help.

tkna91 commented 2 years ago

I understand. I will try a few things at the right time.

rvaiya commented 2 years ago

Can you try a40e3a489 (git fetch origin && git checkout a40e3a489) and compare it to e749310df?

tkna91 commented 2 years ago

I tried it. The behavior seems to be the same for both. https://github.com/rvaiya/keyd/commit/e749310df486f00b97e97d5571ee142058a2a0be

https://user-images.githubusercontent.com/102382754/183242233-564a010b-fb73-43ab-9f91-d322e7e65ffa.mp4

https://github.com/rvaiya/keyd/commit/a40e3a489c0b362e6ad982cae7e6afe2a54acd0b

https://user-images.githubusercontent.com/102382754/183242237-7f09fa39-6f69-413a-a189-f89c8f18b619.mp4

rvaiya commented 2 years ago

It looks like you haven't added your mouse id to your config file. I took a closer look at your earlier videos and looks like many of them have the same problem.

tkna91 commented 2 years ago

Sorry, I added the relevant mouse ID and checked again. The behavior does not seem to change. https://github.com/rvaiya/keyd/commit/e749310df486f00b97e97d5571ee142058a2a0be

https://user-images.githubusercontent.com/102382754/183294210-567f3711-84d1-4d9f-8a30-1565192ecc58.mp4

https://github.com/rvaiya/keyd/commit/a40e3a489c0b362e6ad982cae7e6afe2a54acd0b

https://user-images.githubusercontent.com/102382754/183294225-da35224a-0723-4c4e-af60-c68bd5dba1bd.mp4

rvaiya commented 2 years ago

Thanks. Can you also include the libinput output?

tkna91 commented 2 years ago

KEY_LEFTMETA and BTN_LEFT appear to be entered simultaneously.

# e749310
-event31  KEYBOARD_KEY            +3.549s       KEY_LEFTMETA (125) pressed
-event256  POINTER_BUTTON          +3.549s      BTN_LEFT (272) pressed, seat count: 1

# a40e3a4
-event31  KEYBOARD_KEY            +281.056s     KEY_LEFTMETA (125) pressed
 event31  POINTER_BUTTON          +281.056s     BTN_LEFT (272) pressed, seat count: 1

I uploaded my screencast to an external site because it seems that if the video file size is over 10 MB, it cannot be uploaded. https://github.com/rvaiya/keyd/commit/e749310df486f00b97e97d5571ee142058a2a0be https://streamable.com/s22x9l

https://github.com/rvaiya/keyd/commit/a40e3a489c0b362e6ad982cae7e6afe2a54acd0b https://streamable.com/r7ahdm