Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add support for wm_name property when passing conditionals. #122

Open
rbreaves opened this issue Feb 17, 2021 · 7 comments · May be fixed by #129
Open

Feature: Add support for wm_name property when passing conditionals. #122

rbreaves opened this issue Feb 17, 2021 · 7 comments · May be fixed by #129

Comments

@rbreaves
Copy link
Contributor

rbreaves commented Feb 17, 2021

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):
@yoshinari-nomura
Copy link

yoshinari-nomura commented Feb 18, 2021

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:
yoshinari-nomura@2a74e00

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.

@Lenbok Lenbok linked a pull request Apr 9, 2021 that will close this issue
@Lenbok
Copy link
Contributor

Lenbok commented Apr 9, 2021

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

@rbreaves
Copy link
Contributor Author

rbreaves commented Apr 9, 2021

@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.

@yoshinari-nomura
Copy link

@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)))

@Lenbok
Copy link
Contributor

Lenbok commented Apr 9, 2021 via email

@yoshinari-nomura
Copy link

@Lenbok Thank you again!

@joshgoebel
Copy link

I've opened an issue against my fork to support WM_NAME in the context object passed to all conditionals. joshgoebel/keyszer#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants