RedBearAK / toshy

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

[BUG] not_win_type_rgx breaks custom keyboard map #25

Closed squk closed 1 year ago

squk commented 1 year ago
Bare metal or virtual machine: 
(If in VM, which VM software): None

(Try running 'toshy-env' in a terminal.)

        DISTRO_NAME      = 'debian'
        DISTRO_VER       = 'rodete'
        SESSION_TYPE     = 'x11'
        DESKTOP_ENV      = 'gnome'

Keyboard type (IBM, Chromebook, Windows, Apple):  Apple
Keyboard device name (try 'toshy-devices'): 'LAZYDESIGNERS Bolt'

These terminal commands may provide helpful info:

Problem observed:


not_win_type_rgx causes custom keyboard types to always be marked as windows if a Windows modmap is found before the custom type. Effectively rendering the keyboards_UserCustom_dct useless.

Additionally, the following check in isKbType :

        and "magic" in kb_dev_name
        and "keyboard" in kb_dev_name

Will not allow non-magic keyboards to be treated as an Apple keyboard. This should be removed and seems to be cruft left over from before the keyboard type lists were made.

RedBearAK commented 1 year ago

@squk

I know that's not a perfect check for the Magic Keyboards, but I've been having a lot of trouble with the regex stuff, as always. I put that in because the regex that should have been matching on the literal name was not working for that user.

If you're any good with regex maybe you can help troubleshoot that part of things. The auto keyboard type matching is one of the main goals I had when doing this, and it's pretty frustrating that I can't seem to get it working perfectly.

When I get the rest of it working I can remove the heavy-handed matching on 'magic' and 'keyboard', which I know was not a great solution. (But who is actually going to risk being sued by Apple for calling their keyboard "Magic" something?)

RedBearAK commented 1 year ago

@squk

Thanks to what you said I think I found one of the main problems, which was letting things "fall through" past the custom keyboard check even when there is a custom entry given for the device, in which case the correct action if there is no match to the keyboard type being tested for is to return False immediately and not let it get anywhere near the "defaulting to Windows" option. The custom check is supposed to be an override after all. But these checks must only happen when there is actually a value returned for the device name key retrieval attempt. Otherwise it would be False all the time. So I think I've got all that taken care of now.

This should work a heck of a lot better. Still not sure about the regex stuff though. And I also put back a check on "all keyboards" below that, before it allows the 'Windows' type to be true. But the function is still very imperfect and I'm not that happy with it.

    def _isKBtype(ctx: KeyContext):
        logging_enabled = True
        kb_dev_name = ctx.device_name.casefold()

        custom_kbtype = str(kbds_UserCustom_lower_dct.get(kb_dev_name, '')).casefold()
        # check for type match/mismatch only if custom type is truthy
        if custom_kbtype and custom_kbtype == kbtype_cf:
            if logging_enabled:
                debug(f"KB_TYPE: '{kbtype}' | Type override given for device: '{ctx.device_name}'")
            return True
        elif custom_kbtype and custom_kbtype != kbtype_cf:
            return False

I've committed this change to the dev_alpha branch, so if you feel like testing it you can switch to that branch on the main page, download the zip and run the new version of the installer. Which should not damage any customizations you may have between the "marks" in your existing config file. 🤞🏽 That's been working in testing for a couple of days at least, and is already in main.

RedBearAK commented 1 year ago

Updates to the keyboard type function are integrated in main at this point.

RedBearAK commented 1 year ago

This should be resolved at this point.