RedBearAK / toshy

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

Is there a way to disable/ignore some devices? #323

Closed markopw closed 1 week ago

markopw commented 1 month ago

It would be nice if we could disable/ignore some keyboards or devices. I didn't find a way in the configuration file. I only found layout remap per device and excluding from Forced Numpad.

The problem: I have two keyboards, one is apple type and other is windows. I would like to ignore the windows keyboard by toshy completely.

Also toshy detects my mouse logitech mx master 3 as keyboard so any system settings for the mouse stops working like scrolling direction or pointer speed. I would like to add it to disable/ignore list. I tried adding --device / --devices but it didn't work.

Thank you for reading.

➜  ~/.config/toshy git:(main) ✗ toshy-config-start-verbose
Stopping Toshy systemd services...

Toshy systemd services stopped.

xwaykeyz v1.1.2
(DD) CONFIG: /home/user/.config/toshy/toshy_config.py
(DD) THROTTLES: Pre-key: 12ms, Post-key: 18ms
(DD) No Synergy log folder found. No log observer will be engaged.

(CG) Current settings:
        ------------------------------------------------------------------------------
        calling_module          = 'toshy_config.py'
        prefs_db_file_path      = '/home/user/.config/toshy/toshy_user_preferences.sqlite'
        ------------------------------------------------------------------------------
        autostart_tray_icon     = True
        gui_dark_theme          = True
        ------------------------------------------------------------------------------
        override_kbtype         = 'Auto-Adapt'
        ------------------------------------------------------------------------------
        optspec_layout          = 'Disabled'
        mru_layout              = ('us', 'default')
        ------------------------------------------------------------------------------
        forced_numpad           = True
        media_arrows_fix        = False
        multi_lang              = False
        Caps2Cmd                = False
        Caps2Esc_Cmd            = False
        Enter2Ent_Cmd           = False
        ST3_in_VSCode           = False
        ------------------------------------------------------------------------------

(CG) Toshy config sees this environment:
        DISTRO_ID        = 'arch'
        DISTRO_VER       = 'notfound'
        SESSION_TYPE     = 'wayland'
        DESKTOP_ENV      = 'kde'
        DE_MAJ_VER       = '6'

(DD) ENVIRON: Session type: 'wayland', Desktop env: 'kde'
(DD) Zenity command path: '/usr/bin/zenity'
(--) WATCH: Watching for new devices to hot-plug.
(--) Autodetecting all keyboards (--device not specified)
(+K) Grabbing 'Logitech MX Master 3' (/dev/input/event29)
(+K) Successfully grabbed 'Logitech MX Master 3' (/dev/input/event29)
(+K) Grabbing 'Keychron Keychron K2' (/dev/input/event28)
(+K) Successfully grabbed 'Keychron Keychron K2' (/dev/input/event28)
(+K) Grabbing 'Keychron Keychron K2' (/dev/input/event27)
(+K) Successfully grabbed 'Keychron Keychron K2' (/dev/input/event27)
(+K) Grabbing 'Wooting Wooting 60HE (ARM)' (/dev/input/event19)
(+K) Successfully grabbed 'Wooting Wooting 60HE (ARM)' (/dev/input/event19)
(--) Ready to process input.
RedBearAK commented 1 month ago

It should work if you use --devices, but I think you need to put all devices (either the path, or the string name in quotes) that you want it to grab. It should not grab other devices in that case.

There was talk of adding a type of ignore setting inside the keymapper, but I don't think anything ever happened with that.

To run a manual keymapper command, you have to first engage the Toshy Python virtual environment:

source toshy-venv

Then you should be able to run xwaykeyz, the current keymapper fork that gets installed, with your -c (config file) and then the added --devices option and arguments. Look inside the toshy-config-start script if you're not sure about the command. Maybe leave off the -w option.

less $(toshy-config-start)

I'll have to add to this later.

markopw commented 1 month ago

Ahhh, sorry for not looking a bit more into the code.

--devices should be changed in toshy-config-start as well as toshy-service-config - this is called when you restart from the tray menu, that is why it wasn't working for me.

If someone needs this: To make it work only for keychron I changed in .config/toshy/scripts/toshy-service-config.sh and .config/toshy/scripts/bin/toshy-config-start.sh: FROM:

xwaykeyz -w -c "$HOME/.config/toshy/toshy_config.py"

TO:

xwaykeyz -w -c "$HOME/.config/toshy/toshy_config.py" --devices "Keychron Keychron K2"

You can find device name with toshy-devices.

RedBearAK commented 1 month ago

Excellent work there. That would of course all be overwritten if you reinstall Toshy. There’s also the verbose script you may want to modify. In case you need to debug config changes.

I should look into having a way to save the devices the user wants to add and/or ignore to some kind of settings file that the launcher scripts can read into a variable. To make this customization of the command more maintainable. Shouldn’t be too hard, but I can’t get to it immediately.

RedBearAK commented 1 month ago

I’m not sure about this but the -w option may cause the keymapper to grab the mouse device if it gets disconnected and reconnected. Or it might just keep ignoring any device but the specified device.

You may need to check the behavior and remove that option if necessary.

markopw commented 1 month ago

It seems like --devices have grater priority than -w option, meaning -w only monitor for devices specified with --devices. I tried unpluging and powering off/on the mouse and windows keyboard and it didn't attach to toshy or should I say xwaykeyz.

RedBearAK commented 1 month ago

That is good news. Without the -w it probably wouldn’t even re-grab the designated device, which would be quite annoying.

Thanks for your support. Let me know if you have any other issues with Toshy. I’ll leave this open until I have a chance to add that enhancement.

RedBearAK commented 1 month ago

@markopw

FYI, I just added a new API function into the keymapper (xwaykeyz), that operates in exactly the same way as the --devices command-line arguments. Any new install of Toshy should have the 1.3.0 version of the keymapper (or later), and should be able to use this new API:

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

# Keymapper-specific config settings - REMOVE OR SET TO DEFAULTS FOR DISTRIBUTION
dump_diagnostics_key(Key.F15)   # default key: F15
emergency_eject_key(Key.F16)    # default key: F16

timeouts(
    multipurpose        = 1,        # default: 1 sec
    suspend             = 1,        # default: 1 sec, try 0.1 sec for touchpads/trackpads
)

# Delays often needed for Wayland and/or virtual machines or slow systems
throttle_delays(
    key_pre_delay_ms    = 12,      # default: 0 ms, range: 0-150 ms, suggested: 1-50 ms
    key_post_delay_ms   = 18,      # default: 0 ms, range: 0-150 ms, suggested: 1-100 ms
)

devices_api(
    # Only the specified devices will be "grabbed" and watched for during 
    # device connections/disconnections. 
    only_devices = [
        # 'Example Disconnected Keyboard',
        # 'Example Connected Keyboard',
    ]
)

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

If you place that new API in your tagged keymapper_api editable slice like shown here, and put the devices you want to grab in the only_devices list, you could save the config and reinstall Toshy from a new zip file. That should wipe out the changes you made to the launcher scripts, and take the same device argument from the API call inside the config file.

For your device name it could look like this:

devices_api(
    only_devices = [
        'Keychron Keychron K2',
    ]
)

The difference being that you could reinstall Toshy for any reason, possibly to upgrade and get new features or remaps every few months, and your "devices" argument will be preserved in the config file. Plus, you won't need to hack the launcher scripts again.

Let me know if you ever get a chance to try it out. The example as shown above will be in the default Toshy config file from now on.

Remember that, when using this or --devices, if you get another input device and want Toshy's remapping to apply to that device, you'd have to add its device name to the list, or it would get ignored like everything else.

A device on the list doesn't need to be connected, but at least one device has to be successfully grabbed as the keymapper starts, or it will just have an error.

If you reinstall from a new zip at this point, you should be able to use a simpler alias to see the verbose output for troubleshooting:

toshy-debug

That's the same as either of these:

toshy-config-start-verbose
toshy-config-verbose-start