RedBearAK / toshy

Keymapper config to make Linux work like a 'Tosh!
https://toshy.app
GNU General Public License v3.0
339 stars 16 forks source link

(Question) Logitech MX Keys Mini F7 function changes when Toshy is enabled #357

Closed irfanhakim-as closed 2 months ago

irfanhakim-as commented 2 months ago

I installed and have been using Toshy for a more macOS like experience on my Linux desktop using my MX Keys Mini keyboard and it does the job well - but I prefer to have my top row keys, esp F1 to F12 as is.

For example, previously F4 and F5 (without holding the fn key) decreases and increases the keyboard backlights respectively. The F7 key previously would launch KDE Plasma's Emoji Selector app. I'd like to have those functionalities back, preferably to let Toshy do whatever tweaks is necessary, but leaving these keys untweaked, if possible, so that their behaviour with or without Toshy remains the same.

Is it possible?

RedBearAK commented 2 months ago

@irfanhakim-as

I am entirely unsure why Toshy would be affecting what the function keys do. I've been using this keymapper and its ancestors for a few years now, and I can't recall anything like that ever happening.

I only have some remaps for function keys on my personal Acer laptop because I got annoyed by accidentally putting my computer to sleep with F1, and accidentally turning my WiFi off with F2. So I went into the BIOS and flipped the function keys row to being function keys first, then remapped the volume and brightness keys back from F3/F4 and F9/F10/F11 to doing the usual hardware functions. But if I hadn't done that, there aren't really any general remaps for function keys in the config file.

So a question is, what happens if you press Fn+Esc on your keyboard? That's supposed to flip it between function keys and media keys... And the mode the function keys are in should have nothing to do with the keymapper.

But I'm sure we can figure out what's going on.

I am unclear after some googling whether that keyboard is using the hid_apple driver, or can use the hid_apple driver, but if it does and the Fn+Esc doesn't seem to work, there is the command toshy-fnmode that you can try. It lets you change the function keys mode on keyboards that use the hid_apple driver in Linux, and that isn't just limited to Apple keyboards. Some PC keyboards with multimedia functions also use that driver. Maybe the MX Mini is one of them, or can be.

RedBearAK commented 2 months ago

@irfanhakim-as

Follow-up question, is there some sort of software you use with the keyboard? This may be the explanation, as instead of seeing the F-keys events coming from the MX Mini, that software may only be seeing F-keys events coming from the virtual keyboard device created by the keymapper, so it may not be applying special functions onto those F-keys events. That's kind of the only way this massive change in behavior might make sense.

I'm sure it's possible to come up with some remaps to make the F-keys do the usual media functions, if those media/hardware functions are known key events that the virtual keyboard can also send.

You'd want to test the original keyboard device with Toshy disabled, using the evtest terminal command. See what key code each function key is actually emitting.

And list what normally happens for each key, when Toshy is disabled.

RedBearAK commented 2 months ago

Here's how I might start to go about solving your problem. However I have never tried the keyboard illumination key names before, and the "toggle" key name doesn't appear to affect my Acer laptop keyboard. The backlight on this laptop appears to be controlled entirely by the BIOS. There are no keys on my keyboard for decreasing or increasing the keyboard backlight brightness. So I have no idea if this will work for you, for the keyboard backlight.

But the remap to open the Plasma Emoji Selector app should work. It's working for me on Fedora with Plasma 6.1.

The remap for the Emoji Selector shortcut is in a separate if block to make it only active in Plasma. It wouldn't make sense in other desktop environments or window managers.

It might be necessary to install a new version of Toshy for the when conditionals to make sense. I've recently done some adjustments to the config for the sake of squeezing out some additional decrease in CPU usage while typing.

####################################  USER APPS  #####################################
###                                                                                ###
###                                                                                ###
###      ██    ██ ███████ ███████ ██████       █████  ██████  ██████  ███████      ###
###      ██    ██ ██      ██      ██   ██     ██   ██ ██   ██ ██   ██ ██           ###
###      ██    ██ ███████ █████   ██████      ███████ ██████  ██████  ███████      ###
###      ██    ██      ██ ██      ██   ██     ██   ██ ██      ██           ██      ###
###       ██████  ███████ ███████ ██   ██     ██   ██ ██      ██      ███████      ###
###                                                                                ###
###                                                                                ###
######################################################################################
### This is a good location in the config file for adding new custom keymaps for 
### user applications and custom function keys. Watch out that you don't override 
### any "general" shortcuts like Cmd+Z/X/C/V that may be defined below this section. 
### Changes made between the "slice" marks will be retained by the Toshy installer 
### if you reinstall and it finds matching start/end markers for each section. 

###################################################################################################
###  SLICE_MARK_START: user_apps  ###  EDITS OUTSIDE THESE MARKS WILL BE LOST ON UPGRADE

keymap("User hardware keys", {
    # KBDILLUMTOGGLE
    C("F4"):               C("KBDILLUMDOWN"),               # Keyboard illumination down
    C("F5"):               C("KBDILLUMUP"),                 # Keyboard illumination up
}, when = matchProps(not_clas=remoteStr) )

if DESKTOP_ENV == 'kde':
    keymap("User overrides: KDE", {
        C("F7"):               C("Super-dot"),                  # Open emoji picker in Plasma
    }, when = matchProps(not_clas=remoteStr) )

###  SLICE_MARK_END: user_apps  ###  EDITS OUTSIDE THESE MARKS WILL BE LOST ON UPGRADE
###################################################################################################
irfanhakim-as commented 2 months ago

Hi, thanks for returning so quickly! I'm not home for a couple of days to test these all out but I'll return in ~1-2 days with more info and my findings. Thanks for this very neat tool!

irfanhakim-as commented 2 months ago

Sorry, I've checked again and it seems that the keyboard brightness keys weren't affected by Toshy at all and that they work fine (F4 and F5). So in my case, the only issue I'm noticing is with KDE's Emoji Selector.

When I stop the Toshy service, the F7 key would launch the Emoji Selector app. When I've the service started, the same key or the Fn + F7 combo would not do anything.

Before I created this issue, I've added this to my Toshy config (based on a Wiki entry I found on this repo):

###################################################################################################
###  SLICE_MARK_START: user_apps  ###  EDITS OUTSIDE THESE MARKS WILL BE LOST ON UPGRADE

keymap("User hardware keys", {
    # PUT UNIVERSAL REMAPS FOR HARDWARE KEYS HERE
    # KEYMAP WILL BE ACTIVE IN ALL DESKTOP ENVIRONMENTS/DISTROS

}, when = lambda ctx:
    cnfg.screen_has_focus and
    matchProps(not_clas=remoteStr)(ctx)
)

keymap("User overrides: KDE Plasma", {
    C("F7"): C("Super-Dot"),      # Custom remap for Fn to open Emoji Selector app in KDE Plasma
}, when = lambda ctx:
    matchProps(not_lst=remotes_lod)(ctx) and
    DESKTOP_ENV == 'kde'
)

###  SLICE_MARK_END: user_apps  ###  EDITS OUTSIDE THESE MARKS WILL BE LOST ON UPGRADE
###################################################################################################

This allows me to launch the Emoji Selector, though not with F7 alone (what I'd like, similar to stock) but with a Fn + F7 combo.

I'm not entirely sure how Toshy works, other than how amazing it is and how grateful I am that it exists, but I am curious why other F-keys, as far as I'm aware, seem unaffected by Toshy - except for the Emoji Selector key (F7) and if the "recommended" solution to returning its functionality as stock is to add the snippet* you provided to the config?

*Said snippet:

###################################################################################################
###  SLICE_MARK_START: user_apps  ###  EDITS OUTSIDE THESE MARKS WILL BE LOST ON UPGRADE

keymap("User hardware keys", {
    # PUT UNIVERSAL REMAPS FOR HARDWARE KEYS HERE
    # KEYMAP WILL BE ACTIVE IN ALL DESKTOP ENVIRONMENTS/DISTROS

}, when = lambda ctx:
    cnfg.screen_has_focus and
    matchProps(not_clas=remoteStr)(ctx)
)

if DESKTOP_ENV == 'kde':
    keymap("User overrides: KDE", {
        C("F7"):               C("Super-dot"),                  # Open emoji picker in Plasma
    }, when = matchProps(not_clas=remoteStr) )

###  SLICE_MARK_END: user_apps  ###  EDITS OUTSIDE THESE MARKS WILL BE LOST ON UPGRADE
###################################################################################################

Thank you!

UPDATE:

After updating my config slightly according to your provided snippet, I'm getting the same behaviour of it allowing me to launch Emoji Selector only with the Fn + F7 combo, not F7 alone.

If I toggle the F-key "lock" with Fn + Esc as you recommended, the Emoji Selector does launch with F7 alone, but, it does "break" the other F-keys i.e. pressing F11 actually sends an F11 input to the focused window, instead of muting my sound output (in this mode, to mute my sound output I'd need to press the Fn + F11 combo.

RedBearAK commented 2 months ago

So, if you have to use Fn+F7, to have the F7 key issue F7, that's an indication that the "mode" of the function keys row is (like a MacBook keyboard) in a "media/hardware functions first" mode. The Fn+Esc I mentioned earlier is supposed to flip that so that the keys are F-keys first, and media/hardware only when holding Fn. (That's not necessarily what you want to do.)

What you want to do is find out what that key sends when you press it without holding Fn. You can do that with evtest. (I think you need to stop Toshy for that.)

I see an emoji face on the key in photos. If you're not using something like Solaar to support the features of the keyboard, I'm not sure exactly how it was launching the Plasma Emoji Selector app by just pressing the F7 key. But I'll be interested in the results of the evtest run, when you press that key, and Fn+F7.

You should be able to just take what you see the key issuing without the Fn held down, and replace the F7 in the combo remap in the config.

RedBearAK commented 2 months ago

I'm not entirely sure how Toshy works

It's just a keymapper config, along with some scripts to help manage it, and a tray icon and GUI app (again, just to help manage the keymapper). The keymapper needs window context (app class, window title) in order to do the app-specific combo remaps.

Don't be fooled into thinking that I wrote the original config, or the keymapper. I've mainly just been tweaking pre-existing code, and I wrote a different installer script, with expanded distro support. And hacked some Wayland support into the keymapper. That's really been the hardest part.

The config has some general shortcuts that are active in all non-terminal apps, some overrides and additional remaps for terminals, web browsers, file managers, and then the keymaps get more specific to certain apps, like VSCode and its variants. So it's like layers of remaps from general to specific. Starting with moving the modifier key locations based on the keyboard type.

Again, I didn't come up with any of that myself.

You can fix any specific app shortcuts that still don't conform to what you'd expect from macOS, by just knowing the window info and making a new keymap. There's a shortcut to pop up a dialog that shows the context.

Shift+Option+Cmd+I,I (double-tap the "I" key, "I" for "info")
irfanhakim-as commented 2 months ago

Not sure if I'm doing it right but I ran:

sudo evtest

Not sure which event exactly to pick as I'm using the keyboard wirelessly with its one USB dongle (there are no other Logitech USB receiver on my system) but I picked event number 3 from the list of available devices:

/dev/input/event3:      Logitech USB Receiver
/dev/input/event5:      Logitech USB Receiver Mouse
/dev/input/event6:      Logitech USB Receiver Consumer Control
/dev/input/event9:      Logitech USB Receiver System Control
  1. This is the exact output I got when I press F7 once while having Toshy's service stopped (launches Emoji Selector):

    Event: time 1723046716.388709, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e3
    Event: time 1723046716.388709, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 1
    Event: time 1723046716.388709, -------------- SYN_REPORT ------------
    Event: time 1723046716.396728, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70037
    Event: time 1723046716.396728, type 1 (EV_KEY), code 52 (KEY_DOT), value 1
    Event: time 1723046716.396728, -------------- SYN_REPORT ------------
    Event: time 1723046716.471711, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70037
    Event: time 1723046716.471711, type 1 (EV_KEY), code 52 (KEY_DOT), value 0
    Event: time 1723046716.471711, -------------- SYN_REPORT ------------
    Event: time 1723046716.479705, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e3
    Event: time 1723046716.479705, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 0
    Event: time 1723046716.479705, -------------- SYN_REPORT ------------

    Not exactly sure why a single key press could return that many output, but that's what I got.

  2. Doing the same test with Toshy service started (using event, /dev/input/event20: XWayKeyz (virtual) Keyboard), with my specified config, pressing just F7 once (does not launch Emoji Selector):

    Event: time 1723047137.835906, type 1 (EV_KEY), code 56 (KEY_LEFTALT), value 1
    Event: time 1723047137.835906, -------------- SYN_REPORT ------------
    Event: time 1723047137.835984, type 1 (EV_KEY), code 52 (KEY_DOT), value 1
    Event: time 1723047137.835984, -------------- SYN_REPORT ------------
    ^[.Event: time 1723047137.917648, type 1 (EV_KEY), code 52 (KEY_DOT), value 0
    Event: time 1723047137.917648, -------------- SYN_REPORT ------------
    Event: time 1723047137.925424, type 1 (EV_KEY), code 56 (KEY_LEFTALT), value 0
    Event: time 1723047137.925424, -------------- SYN_REPORT ------------
  3. Pressing Fn + F7 (launches Emoji Selector):

    Event: time 1723047280.429473, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 1
    Event: time 1723047280.429473, -------------- SYN_REPORT ------------
    Event: time 1723047280.459693, type 1 (EV_KEY), code 52 (KEY_DOT), value 1
    Event: time 1723047280.459693, -------------- SYN_REPORT ------------
    Event: time 1723047280.465865, type 1 (EV_KEY), code 52 (KEY_DOT), value 0
    Event: time 1723047280.465865, -------------- SYN_REPORT ------------
    Event: time 1723047280.496051, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 0
    Event: time 1723047280.496051, -------------- SYN_REPORT ------------

Based on these results, not sure what should I update my config to in order to have it behave as stock, which launches the Emoji Selector with F7 alone, since besides the EV_MSC/MSC_SCAN lines, the shortcut combo output of No. 1 and No. 3 seems identical.

Also, just to address this:

I see an emoji face on the key in photos. If you're not using something like Solaar to support the features of the keyboard, I'm not sure exactly how it was launching the Plasma Emoji Selector app by just pressing the F7 key.

Just wanted to clarify that I have set all keybinds/shortcuts to the defaults on my KDE Plasma 6 desktop prior to installing Toshy, and I don't have anything installed that would change/set any shortcuts other than Toshy alone. The F7 key has just always worked OOTB in launching the Emoji Selector on this PC, my Steam Deck, and my Mac using this keyboard.

RedBearAK commented 2 months ago

OK, boy that's some confusing output.

The F7 key has just always worked OOTB in launching the Emoji Selector on this PC, my Steam Deck, and my Mac using this keyboard.

I assume you mean while running Linux and the KDE Plasma desktop on all of those. So somehow the keyboard itself (or its driver) knows to send out Super+Dot to invoke the Plasma Emoji Selector app when you are in Plasma. I'm suspecting the driver, if you aren't using extra software like Solaar. Pretty sure that shortcut isn't standard across other desktop environments in Linux. Or other operating systems. It's specific to Plasma.

Well, if you really had the Toshy services stopped and also the Toshy debug output stopped (and of course you picked what should be the right device, the actual keyboard), that should mean...

Alright, I think I know what's going on. When the artificial keystrokes the keyboard sends out as a macro after you press F7 are modmapped by the keymapper, it becomes LAlt+Dot, which of course does not invoke the Emoji Selector. So the problem is happening because the keyboard is literally sending out a shortcut combo when you press F7. And it's a switchable "universal" keyboard that's in the Windows mode (and should stay that way, or would need to be manually named in the config as an "Apple" type if you changed to Mac mode). So Toshy modmaps the Super and Alt keys to make it act like an Apple keyboard, just like any other PC keyboard. This changes the combo the F7 key sends out.

You can remap this Alt+Dot combo that your F7 is emitting back to being Super+Dot (the kernel/evdev events and Plasma call that key Meta, which used to be associated with Alt in the keymapper, which is why you need to use Super in the config file to avoid confusion with Alt). It's up to you if you also want to retain the F7 remap, so that the key would do the same thing while Toshy is enabled, regardless of which function keys mode the keyboard is in.


if DESKTOP_ENV == 'kde':
    keymap("User overrides: KDE", {
        C("Alt-dot"):               C("Super-dot"),                 # Open emoji picker in Plasma
        C("F7"):                    C("Super-dot"),                 # Open emoji picker in Plasma
    }, when = matchProps(not_clas=remoteStr) )

You could even apply the combo remap only if it is coming from that particular device, like this:


if DESKTOP_ENV == 'kde':
    keymap("User overrides: KDE", {
        C("F7"):                    C("Super-dot"),                 # Open emoji picker in Plasma
    }, when = matchProps(not_clas=remoteStr) )
    keymap("User overrides: KDE Logitech", {
        C("Alt-dot"):               C("Super-dot"),                 # Open emoji picker in Plasma
    }, when = matchProps(not_clas=remoteStr devn='Logitech USB Receiver') )

At least, I think that will work. I wrote the matchProps() custom function, but have rarely tried to use the device name argument with it.

Restricting the combo remap to the device would prevent the config from trying to do the same remap of the combo on other keyboard devices. If this doesn't seem important or useful, feel free to stick with the version of this without the device name argument.

RedBearAK commented 2 months ago

FYI, Toshy has the ability to do some tweaks of how task switching works on Plasma, installing a KWin script that groups applications like macOS, and making the task switcher settings make more sense to go along with the grouped task switching. That requires using the --fancy-pants option with the install command.

In case you didn't see that in the README and do it yourself during the initial install. You should be able to reinstall Toshy while keeping the customizations you've made in the config file, if everything you've changed is in one of the protected "slices".

I should probably ask about the task switcher tweaking during install on Plasma. I think most Plasma users don't read through the options enough to know about it.

Then again, not everyone has an issue with the way task switching works in most Linux desktop environments.

irfanhakim-as commented 2 months ago

I assume you mean while running Linux and the KDE Plasma desktop on all of those.

On all those, yes, except the Mac ofc running macOS.

the keyboard itself (or its driver) knows to send out Super+Dot to invoke the Plasma Emoji Selector app when you are in Plasma

I suspect, it may not be super far-fetched that the device itself sends that combo when being used on a generic PC? I can imagine this is the scenario since from my search, it seems that the shortcut to launch the Emoji picker on Windows is also Super + .. On a Mac, using the built-in Keyboard Viewer on macOS, it seems to be sending the right combo for the Emoji picker though which is Cmd + Control + Spacebar.


Just to better document the inputs, this is F7 alone with the Toshy service running and stock Toshy config (no user_apps customisation):

Event: time 1723077236.318006, type 1 (EV_KEY), code 56 (KEY_LEFTALT), value 1
Event: time 1723077236.318006, -------------- SYN_REPORT ------------
Event: time 1723077236.318021, type 1 (EV_KEY), code 52 (KEY_DOT), value 1
Event: time 1723077236.318021, -------------- SYN_REPORT ------------
^[.Event: time 1723077236.392611, type 1 (EV_KEY), code 52 (KEY_DOT), value 0
Event: time 1723077236.392611, -------------- SYN_REPORT ------------
Event: time 1723077236.400550, type 1 (EV_KEY), code 56 (KEY_LEFTALT), value 0
Event: time 1723077236.400550, -------------- SYN_REPORT ------------

Fn + F7 with the Toshy service running and stock Toshy config:

Event: time 1723077282.639619, type 1 (EV_KEY), code 65 (KEY_F7), value 1
Event: time 1723077282.639619, -------------- SYN_REPORT ------------
^[[18~Event: time 1723077282.729254, type 1 (EV_KEY), code 65 (KEY_F7), value 0
Event: time 1723077282.729254, -------------- SYN_REPORT ------------

F7 with the Toshy service running and my previously documented Toshy config:

Event: time 1723077415.701646, type 1 (EV_KEY), code 56 (KEY_LEFTALT), value 1
Event: time 1723077415.701646, -------------- SYN_REPORT ------------
Event: time 1723077415.701656, type 1 (EV_KEY), code 52 (KEY_DOT), value 1
Event: time 1723077415.701656, -------------- SYN_REPORT ------------
^[.Event: time 1723077415.769203, type 1 (EV_KEY), code 52 (KEY_DOT), value 0
Event: time 1723077415.769203, -------------- SYN_REPORT ------------
Event: time 1723077415.784067, type 1 (EV_KEY), code 56 (KEY_LEFTALT), value 0
Event: time 1723077415.784067, -------------- SYN_REPORT ------------

Fn + F7 with the Toshy service running and my previously documented Toshy config:

Event: time 1723077475.896222, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 1
Event: time 1723077475.896222, -------------- SYN_REPORT ------------
Event: time 1723077475.926386, type 1 (EV_KEY), code 52 (KEY_DOT), value 1
Event: time 1723077475.926386, -------------- SYN_REPORT ------------
Event: time 1723077475.932476, type 1 (EV_KEY), code 52 (KEY_DOT), value 0
Event: time 1723077475.932476, -------------- SYN_REPORT ------------
Event: time 1723077475.962651, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 0
Event: time 1723077475.962651, -------------- SYN_REPORT ------------

After updating my config as you have recommended (mapping out both Alt-dot and F7), here's the evtest output with just F7 - and it does launch the Emoji Selector app now:

Event: time 1723078077.552207, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 1
Event: time 1723078077.552207, -------------- SYN_REPORT ------------
Event: time 1723078077.582374, type 1 (EV_KEY), code 52 (KEY_DOT), value 1
Event: time 1723078077.582374, -------------- SYN_REPORT ------------
Event: time 1723078077.588461, type 1 (EV_KEY), code 52 (KEY_DOT), value 0
Event: time 1723078077.588461, -------------- SYN_REPORT ------------
Event: time 1723078077.618624, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 0
Event: time 1723078077.618624, -------------- SYN_REPORT ------------

If I map Alt-dot alone (Stock behaviour is F7 opens the Emoji Selector, Fn + F7 does not), seems to do the job too as expected:

Event: time 1723079205.968880, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 1
Event: time 1723079205.968880, -------------- SYN_REPORT ------------
Event: time 1723079205.999108, type 1 (EV_KEY), code 52 (KEY_DOT), value 1
Event: time 1723079205.999108, -------------- SYN_REPORT ------------
Event: time 1723079206.005242, type 1 (EV_KEY), code 52 (KEY_DOT), value 0
Event: time 1723079206.005242, -------------- SYN_REPORT ------------
Event: time 1723079206.035420, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 0
Event: time 1723079206.035420, -------------- SYN_REPORT ------------

With this config, Fn + F7 sends the F7 key as expected:

Event: time 1723079292.096253, type 1 (EV_KEY), code 65 (KEY_F7), value 1
Event: time 1723079292.096253, -------------- SYN_REPORT ------------
^[[18~Event: time 1723079292.178833, type 1 (EV_KEY), code 65 (KEY_F7), value 0
Event: time 1723079292.178833, -------------- SYN_REPORT ------------

One side effect of this though, checking KDE Plasma's stock Shortcuts in the System Settings app, Alt + . is the default shortcut combo for toggling hidden files/folders in Dolphin, alongside Ctrl + H. With this latest config update, I don't seem to be able to toggle hidden files/folders in Dolphin anymore since Alt + . triggers Super + . (which opens the Emoji Selector), and Ctrl + H, which in Toshy I assume means Cmd + H minimises the focused window instead, sort of like on a Mac.

I'm assuming that's expected behaviour, unless you know of a way to fix this?

irfanhakim-as commented 2 months ago

Also, does the devn arg which in your example is set to Logitech USB Receiver accept more than one value, if yes, may I know how?

Just in case in the future I switch away from using the wireless dongle and either use it with Bluetooth, or Wired via USB directly and the device name no longer applies.

RedBearAK commented 2 months ago

On all those, yes, except the Mac ofc running macOS.

I don't like to make assumptions. Intel Macs can run many Linux distros and Apple Silicon Macs can run Fedora Asahi Remix (I have at least a couple of users running that on M-series MacBooks).

on macOS, it seems to be sending the right combo for the Emoji picker though which is Cmd + Control + Spacebar.

I see. It may indeed just be down to which mode it's in, if there's that much consistency with Meta/Super/Win+Dot usage for that purpose. So probably just the firmware doing it as a key macro, and Plasma just happens to have the same shortcut set as one of the defaults (there are two default shortcuts).

One side effect of this though, checking KDE Plasma's stock Shortcuts in the System Settings app, Alt + . is the default shortcut combo for toggling hidden files/folders in Dolphin, alongside Ctrl + H. With this latest config update, I don't seem to be able to toggle hidden files/folders in Dolphin anymore since Alt + . triggers Super + . (which opens the Emoji Selector), and Ctrl + H, which in Toshy I assume means Cmd + H minimises the focused window instead, sort of like on a Mac.

That's the kind of thing I was worried about. But the macOS Finder shortcut for that is Shift+Cmd+Dot, which should be getting remapped onto Ctrl+H, so that should still work (actually it would still work if it was remapping onto Alt+Dot too). If you stick with that, you should be fine.

Cmd+H (which is actually RIGHT_CTRL+H internally) is of course for minimizing windows (the closest we can get to "Hide Window" in Linux) and if you try to use the physical Ctrl+H it will be Super+H in non-terminals and only Ctrl+H in terminals. In other words this is kind of a tricky shortcut nexus. Hide window and hide/show files. They clash a bit.

The user_apps slice is positioned before most other things purposefully, to allow easily overriding pretty much any problematic remap. So you could potentially have a copy of the "General File Managers" keymap (same conditional expression so it's active at the same time) and allow Alt+Dot to work the way it used to in file managers. This would of course block the F7 key's ability to bring up the Emoji Selector while in file managers, which unfortunately often extends to the shell (like the Overview or app launcher) depending on whether you were in a file manager when you opened them.

The keymapper really has very limited information to work with in Linux, it's amazing that it works as well as it does.

Also, does the devn arg which in your example is set to Logitech USB Receiver accept more than one value, if yes, may I know how? Just in case in the future I switch away from using the wireless dongle and either use it with Bluetooth, or Wired via USB directly and the device name no longer applies.

Yeah, that's good thinking, I was going to mention that. Should go something like this, similar to how you can have multiple app classes or window titles:

devn="^One Device Name$|^Alternate Device Name$"

And I probably should have put the ^$ in my example before. That limits it to matching the exact string (but without including the cse= argument, all matches are case-insensitive). I never found a good reason to have the matching be case-sensitive by default.

RedBearAK commented 2 months ago

I see the "hooray". All good now?

irfanhakim-as commented 2 months ago

I don't like to make assumptions

Yea, totally understandable - I used to on my Intel Mac but not yet so far on my M1 Mac since there are things I need that are currently not supported on it for now.

But the macOS Finder shortcut for that is Shift+Cmd+Dot, which should be getting remapped onto Ctrl+H, so that should still work

It does! I didn't even think to try that combo - actually, I know Toshy maps (as best it could) to macOS keybinds but I wish there's actually a list of those keybinds available in the Wiki or so, just so I and other users would know what exactly is possible now for us to use. Maybe a list of this already exists, and I might just have not found it.

That being said, yeah Shift + Cmd + . works perfectly for my needs and losing Alt + . is no longer a concern (at least for now).

devn="^One Device Name$|^Alternate Device Name$"

Thank you for the example! I'll figure out the possible device names and update my config accordingly.

Oh and I did have one more question to understand the config better:

The when condition that you provided (without the devn arg) was this:

when = matchProps(not_clas=remoteStr)

In the Wiki I referred to initially though, used something more like this:

when = matchProps(not_lst=remotes_lod)(ctx)

If it doesn't inconvenience you, may I know the difference between not_clas=remoteStr and not_lst=remotes_lod, and what (ctx) means just so I know better what exactly to use when updating my user_maps?

irfanhakim-as commented 2 months ago

Just in case people facing the same issue sees this, in the end, this is my final user_maps config:

###################################################################################################
###  SLICE_MARK_START: user_apps  ###  EDITS OUTSIDE THESE MARKS WILL BE LOST ON UPGRADE

keymap("User hardware keys", {
    # PUT UNIVERSAL REMAPS FOR HARDWARE KEYS HERE
    # KEYMAP WILL BE ACTIVE IN ALL DESKTOP ENVIRONMENTS/DISTROS

}, when = lambda ctx:
    cnfg.screen_has_focus and
    matchProps(not_clas=remoteStr)(ctx)
)

if DESKTOP_ENV == 'kde':
    keymap("User overrides: KDE Emoji Selector", {
        C("Alt-dot"):               C("Super-dot"),                 # Open emoji picker in Plasma
        # C("F7"):                    C("Super-dot"),                 # Open emoji picker in Plasma
    }, when = matchProps(not_clas=remoteStr, devn="^Logitech USB Receiver$")
    )

    keymap("User overrides: KDE Spectacle", {
        C("RC-Shift-Key_3"):        C("Shift-Print"),               # Take a screenshot immediately (kde)
        C("RC-Shift-Key_4"):        C("Super-Shift-Print"),         # Take a screenshot interactively (kde)
        C("RC-Shift-Key_5"):        C("Super-Print"),               # Take a screenshot of a window (kde)
    }, when = lambda ctx:
        cnfg.screen_has_focus and
        matchProps(not_clas=remoteStr)(ctx)
    )

###  SLICE_MARK_END: user_apps  ###  EDITS OUTSIDE THESE MARKS WILL BE LOST ON UPGRADE
###################################################################################################

Only the User overrides: KDE Emoji Selector part of this is needed.

The User overrides: KDE Spectacle part is just my preference and minor modification of the default Toshy behaviour based on how I normally use the Screenshot tool on macOS where:

RedBearAK commented 2 months ago

Maybe a list of this already exists, and I might just have not found it.

It would sort of make more sense to try whatever shortcuts you know from macOS, then raise an issue if something doesn't behave like you expect. The way the config works is sort of a "sparse" remapping. It does as little as it can, and many common shortcuts work simply because the modifier keys are moved (such as the virtualized Command key actually being RIGHT_CTRL, which is the basis of most Linux shortcuts). So many things won't be found in the config file directly.

Therefore a handy reference would in fact be a literal list of shortcuts for macOS.

when = matchProps(not_lst=remotes_lod)(ctx)

That is a good question, and I really need to clean the Wiki pages of most uses of lst= and not_lst=. I've been working hard to decrease the amount of CPU usage that happens when rapidly typing. This can make a big difference with really old CPUs, or virtual machines with limited resources.

One of the main things that was using a lot of CPU was using lst= and not_lst= in matchProps() in many of the conditional expressions. This is simply because they represent a recursive call back to matchProps() with sets of arguments disassembled from "lists of dicts". In a few cases, I still need to use those (the dialog fixes, mostly). But for everything else I've reverted back to an older way of doing things, from Kinto. Which is just to compile a whole list of app classes into a long concatenated string of regex patterns, basically like the devn= example I just gave you.

This ends up being quite a bit faster (fewer function calls). And so this:

when = matchProps(not_clas=remoteStr)

Is just a replacement for this:

when = matchProps(not_lst=remotes_lod)

But actually this:

when = matchProps(not_lst=remotes_lod)(ctx)

Would produce an error. A quirk of how the when works is that the function gets passed the "context object" automatically, so you only need that extra (ctx) if you have a multi-expression conditional like all the instances of when = lambda ctx: you'll find. Then the functions inside the lambda have to be explicitly passed the (ctx) from the lambda ctx:. (Which is just called ctx by convention, it could be called anything.)

Hope that was fairly clear. I've been trying to wrap my head around this stuff for at least 3 years, and still usually make a mistake the first time around.

irfanhakim-as commented 2 months ago

It would sort of make more sense to try whatever shortcuts you know from macOS, then raise an issue if something doesn't behave like you expect

That makes perfect sense and much easier to maintain, I reckon. Thank you!

Hope that was fairly clear

Yes, got you! So from my understanding, in my configs, I'll be sure to use:

when = matchProps(not_clas=remoteStr)

when I can, and only pass the context, (ctx), when needed such as when I'm using lambda. Similar to how the default sample in the Toshy config does it:

keymap("User hardware keys", {
    # PUT UNIVERSAL REMAPS FOR HARDWARE KEYS HERE
    # KEYMAP WILL BE ACTIVE IN ALL DESKTOP ENVIRONMENTS/DISTROS

}, when = lambda ctx:
    cnfg.screen_has_focus and
    matchProps(not_clas=remoteStr)(ctx)
)
RedBearAK commented 2 months ago

Your Shift+Cmd+3 is the same as the existing remap for KDE, but I see why you did the other two custom remaps. I may have to slightly redo the defaults.

when = matchProps(not_clas=remoteStr)

To be clear, this particular conditional makes it like the "General GUI" keymaps. In other words, it will be active in all application windows as long as you aren't in a remote desktop app or virtual machine. If you need a custom remap to work in terminals, take a cue from the "General Terminals" keymap conditional, and so on. Make sure you give each keymap a unique name.

only pass the context, (ctx), when needed such as when I'm using lambda. Similar to how the default sample in the Toshy config does it

Yep, and if you get it wrong you'll see some kind of error in the debugging output about "expected 1 argument and got 2" or something like that.

Let me know if you have any other questions. Or raise other issues. I'm always interested in fixing anything that's still missing or doesn't work quite right. If possible. It's not always possible, but usually something can be done.

irfanhakim-as commented 2 months ago

Your Shift+Cmd+3 is the same as the existing remap for KDE

Yea you're right, its current form is redundant but I thought to group them together anyway, especially if I later change it to only capture the currently active screen alone which was what I had done before using Toshy.

If you need a custom remap to work in terminals, take a cue from the "General Terminals" keymap conditional, and so on

Gotcha, I'll do just that.

Let me know if you have any other questions

Yes, will do! I'll be sure to do that when I come across any questions/issues. Thank you so much for actively responding to my questions, I've been wanting a project such as this for a long time and I'm really happy to have finally found it. Now that I've it configured, up and running perfectly on my main system, I'll be installing it on all my other machines as well. I'll leave closing the issue to you as you see fit, thanks again <3

RedBearAK commented 2 months ago

I'll leave closing the issue to you as you see fit, thanks again <3

I think we did a great job here, so... Bam! It's closed. Hope it works out as well on the other systems.

Any further comments on closed issues will need to "@" me, or I think it won't show up in my email notifications.

See you next time.