cyber-sushi / makima

Linux daemon to remap and create macros for keyboards, mice and controllers
GNU General Public License v3.0
145 stars 1 forks source link

App-specific binding isn't working on KDE Plasma #13

Closed pintassilgo closed 5 months ago

pintassilgo commented 5 months ago

I'm probably doing something wrong, maybe you can please help me.

So to test this new feature of v0.9.0 I first downloaded kdotool tarball then extracted the binary to ~/.local/bin.

I confirmed print $XDG_CURRENT_DESKTOP returns KDE.

To run a simple test, I duplicated my keyboard toml file appending window class. I don't know if there's a easier way to get window class, so I used "Detect Window Properties" from Window Rules (Kwin). The app I chose to test was Kate, which is Plasma default editor. I'm not sure if its window class is kate or org.kde.kate, but I tried both separately and none worked. So, for me, filename was Usb KeyBoard Usb KeyBoard::kate.toml or Usb KeyBoard Usb KeyBoard::org.kde.kate.toml.

Content was simple this:

[remap]
KEY_A = ["KEY_B"]

So that pressing A key should print b.

Restarted systemd service but... it doesn't work.

Maybe kdotool needs to be available as root, so I placed the file in /usr/bin and restarted the service, but it still doesn't work.

Am I missing something?

Thanks.

cyber-sushi commented 5 months ago

Hello, thanks for your report!

I've only tested it on a Debian KDE live USB with the following conditions and it works:

There are two things that I can think of:

pintassilgo commented 5 months ago

Thanks for your reply.

Does kdotool getactivewindow getwindowclassname work in your terminal? It should just print konsole

Yes. It prints org.kde.konsole. It's not a Flatpak, it's from package manager. I use openSUSE Tumbleweed.

So I just tried again with Usb KeyBoard Usb KeyBoard::org.kde.konsole.toml instead of Kate, but A is still a, not b as expected...

Are you running Makima as a systemd service?

Yes.

Also, just to make sure, can you post your systemd unit?

[Unit]
Description=Makima remapping daemon

[Service]
Type=simple
Restart=always
RestartSec=3
ExecStart=/home/user/pr/makima/makima
User=user
Group=input
Environment="MAKIMA_CONFIG=/home/user/pr/makima/"

[Install]
WantedBy=default.target

I use makima to remap some things, it works. It's just this new app-specific feature that isn't working.

cyber-sushi commented 5 months ago

Hello, I've done a couple of changes in v0.9.1 to correctly intercept stdout from kdotool and redirect stderr to null when running as a systemd service

I can't test if this works because in my Debian KDE live ISO I don't seem to be able to access uinput when running Makima as a systemd service (I should actually do some research on this one in case it affects other systems and not just that live ISO), but I'm pretty confident that active window retrieval should work now on Plasma

Let me know if this solves the issue, and again, thanks for the detailed info

Edit: tested it on Tumbleweed KDE and it works, let me know if it works on your end as well

pintassilgo commented 5 months ago

Thanks! I confirm it's working now.

I suggest linking to kdotool repo in docs to make easier for users to know where to download it.

And just adding, having kdotool in ~/.local/bin - which is in PATH - wasn't enough, it doesn't work. It only worked when I placed it in /usr/bin. I guess this is because makima runs as root (remembering it starts from a systemd service), so... Maybe it's worth a word about that in docs too.

cyber-sushi commented 5 months ago

I suggest linking to kdotool repo in docs

Will do

makima runs as root

Not exactly, if you run it as a systemd service with User=your_user and Group=input (like you're doing), then Makima runs as your user and not with elevated permissions. However, it doesn't inherit your shell's environment, it inherits your systemd user environment (which you can see by calling systemctl --user show-environment) so if you set PATH from .bashrc or .zshrc, it won't be available to Makima. In case you need to pass a different PATH to Makima, you can either import it directly into systemd (systemctl --user import-environment PATH, or whatever other variable), or you can add it into the systemd unit by adding Environment=PATH=...)

But anyway, thank you for the feedback! I'll mention this in the docs as well

pintassilgo commented 5 months ago

Thanks for the explanation.

it inherits your systemd user environment (which you can see by calling systemctl --user show-environment)

The printed PATH from this command includes /home/user/.local/bin, so I don't know why it doesn't work.

cyber-sushi commented 5 months ago

Oh, interesting, I'll see if I can do something about that