xkeysnail icon indicating copy to clipboard operation
xkeysnail copied to clipboard

Feature: Add support for wm_name property when passing conditionals.

Open rbreaves opened this issue 3 years ago • 7 comments

Can we expand the conditions to not only check against wm_class, but to also optionally use wm_name? I think this change would allow for even more flexibility of allowing for varying keymaps based on where you are in an application and not only THE application you are in.

Examples where this could be useful would be Virtual Machines or Remote Desktops, you might want the wm_name instead of the class as that gives you additional context. Are you editing within the app or are you on a remote machine and want to completely exclude remaps - or do you want specific keymaps when accessing that device?

I believe this function, on_event, inside of transform.py will need some extensive changing and testing to allow for a second parameter to go along with wm_class and from reviewing the code wm_name appears to possibly act as a back up to wm_class? In either case I'd like to see its inclusion as a separate and valid parameter. I might get around to working on this in the future but for now I am just going to leave my thoughts here to get input from others or if someone thinks they'd like to tackle it then please do and I will happily try it out.

def on_event(event, device_name, quiet):

rbreaves avatar Feb 17 '21 03:02 rbreaves

Almost, a year ago, I did a quick hack to support wm_name. As you said, it is very useful. For me, especially with some terminals in web browser like butterfly.

Here is the patch: https://github.com/yoshinari-nomura/xkeysnail/commit/2a74e002a5c43fd757b91fee753d02b38782df36

Concatenate window name into WM_CLASS

If you visit https://github.com/mooz/xkeysnail on Google Chrome, xkeysnail will report WM_CLASS as follows: WM_CLASS 'Google-chrome' | active keymaps = ...

After applying this patch, it will be: WM_CLASS 'Google-chrome' (mooz/xkeysnail: Yet another keyboard remapping tool for X environment - Google Chrome)' | active keymaps = ...

This means we can change the keymaps according to the window title. This is especially useful when you want to change the keymap for each tab of the browser.

This patch, however, forces changes to the user's config.py

If possible, I wanted to add the window title as the second parameter of the lambda function given to "define_keymap", but the current xkeysnail doesn't support it.

It looks like there's a change that adds a device name to the second parameter, but It doesn't seem to be working well.

yoshinari-nomura avatar Feb 18 '21 16:02 yoshinari-nomura

@yoshinari-nomura, @rbreaves Give #129 a try and see if it works for you.

Lenbok avatar Apr 09 '21 04:04 Lenbok

@Lenbok This is awesome, I'll try and test it soon. I need to revise my fork a bit with the latest changes already. I think there are some old issues out there where I need to work on back porting some of my changes again but break it out into a different function so that it doesn't trip up some users existing keybinds. I need held key modifiers to be a thing on modifiers versus simply triggering a combo and immediately releasing the modifier even when it it is held, hence I need to create a KH() function and not just the default K(). That or add a paramter to K that would allow for held modifiers.

rbreaves avatar Apr 09 '21 04:04 rbreaves

@Lenbok Great! I have tried your hack. It works for me perfectly. Thank you!

By the way, why don't you show the device_name as well? something like in transform.py:

print("WM_CLASS '{}' WM_NAME '{}' DEVICE_NAME '{}' | active keymaps = [{}]".format(wm_class, wm_name, device_name, ", ".join(keymap_names)))

yoshinari-nomura avatar Apr 09 '21 05:04 yoshinari-nomura

Yes, that's a good idea. I was a little worried things would be getting too verbose but really it would be useful for debugging. I will update the PR.

On Fri, 9 Apr 2021, 17:52 Yoshinari Nomura, @.***> wrote:

@Lenbok https://github.com/Lenbok Great! I have tried your hack. It works for me perfectly. Thank you!

By the way, why don't you show the device_name as well? something like in transform.py:

print("WM_CLASS '{}' WM_NAME '{}' DEVICE_NAME '{}' | active keymaps = [{}]".format(wm_class, wm_name, device_name, ", ".join(keymap_names)))

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mooz/xkeysnail/issues/122#issuecomment-816427517, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACE34X75JRKUAOOFUAJ6RTTH2IYJANCNFSM4XXTAWAQ .

Lenbok avatar Apr 09 '21 07:04 Lenbok

@Lenbok Thank you again!

yoshinari-nomura avatar Apr 09 '21 09:04 yoshinari-nomura

I've opened an issue against my fork to support WM_NAME in the context object passed to all conditionals. https://github.com/joshgoebel/xkeysnail/issues/2 I've already done the backend work of making the whole conditional system more flexible (so we aren't just adding "yet another param" to a lambda). Adding this support (to keymap, modmap, and multi-modmap) should be trivial now. If anyone is comfortable running beta software and would like to contribute, get in touch! I still have a lot of balls in the air but things should hopefully be pretty stable in the next few days.

joshgoebel avatar Jun 05 '22 17:06 joshgoebel