mpv icon indicating copy to clipboard operation
mpv copied to clipboard

Keyboard shortcuts work correctly only when using English layout

Open MadFishTheOne opened this issue 13 years ago • 78 comments

Shortcuts should not depend on current layout.

Layout-independent key codes can be obtained from:

  1. event.xkey.keycode on X11.
  2. [event keyCode] on Cocoa.
  3. wParam on Windows.

MadFishTheOne avatar Nov 20 '13 19:11 MadFishTheOne

Wouldn't that be confusing? Also, I generally use US layout even on i.e. Italian keyboards at work (because companies buy PCs for the masses), wouldn't this feature troll me in that scenario?

pigoz avatar Nov 20 '13 19:11 pigoz

In most GUI software keyboard shortcuts do not depend on layout, switching layout for using player is annoying. Please add this feature.

Nikoli avatar Nov 20 '13 20:11 Nikoli

This was already discussed here: https://github.com/mpv-player/mpv/issues/45

ghost avatar Nov 20 '13 20:11 ghost

This is mostly for non-latin layouts. Specifically Russian in my case. With such layouts, necessary letters are nowhere to be found. This is unlike Italian, that uses the same letters (maybe just in different places). Since guessing whether layout is latin or not is not practical, I would suggest a user option for this.

Also on Cocoa layout switching for some reason does not work when keyboard focus is in mpv. So it is triple-pain: switch away, switch layout, switch back.

MadFishTheOne avatar Nov 20 '13 20:11 MadFishTheOne

This was already discussed here: #45

I've read through discussion, but I don't agree with the conclusion:

it's not generally possible to be independent of keyboard layout, no matter what you do it will always cuse inconveniences in one way or another.

It is definitely possible, as SDL (or any other similar library) does that exact thing for games. In fact it provides both layout-independent code and layout-dependent one AFAIK. I would recommend checking the code there for specifics.

For mpv, I would recommend a user option switch. So that both latin keyboard users with non-English-weird-key-positions, and non-latin users (I am only aware of Cyrillic) can be happy.

MadFishTheOne avatar Nov 20 '13 20:11 MadFishTheOne

As an obviously highly biased Neo user I agree. I’m always pleased when games and programs manage to cope with my layout.

But: In (well written) games and other applications you generally assign actions to positions on the keyboard, what would be a non confusing way to do this in a config file? Letter → position of it on the US layout → letter on the corresponding position of your layout is kinda dumb. And really confusing. Not nearly as confusing as having to type scancodes though. Some kind of layout switching script could work though, convert all hotkeys to the active layout or something. I’m pretty sure some program (a tiling WM?) does this, I just can’t remember which one…

Zehkul avatar Nov 20 '13 20:11 Zehkul

For mpv, I would recommend a user option switch. So that both latin keyboard users with non-English-weird-key-positions, and non-latin users (I am only aware of Cyrillic) can be happy.

It already does: --input-conf=yourcyrillicinput.conf

ghost avatar Nov 20 '13 20:11 ghost

Some kind of layout switching script could work though, convert all hotkeys to the active layout or something. I’m pretty sure some program (a tiling WM?) does this, I just can’t remember which one…

There are programs that can switch your keyboard layout depending on what application's window is focused.

ghost avatar Nov 20 '13 20:11 ghost

It already does: --input-conf=yourcyrillicinput.conf

You miss (entirely) the point of this issue. Imagine the situation: two keyboard layouts on the system - English and Russian, and user switches between them. In current situation no matter what bindings you specify, one of the layouts won't work. And that is frustrating.

MadFishTheOne avatar Nov 20 '13 20:11 MadFishTheOne

Then use a keyboard layout switcher.

These scancodes are not portable and you'd need huge lookup tables. And in the end you'd bother everyone with weird crap like the 'Z' binding actually mapping to the 'Y' key on German keyboard. Everyone would have trouble finding the correct symbol to bind. I don't see how that's an advantage.

ghost avatar Nov 20 '13 20:11 ghost

These scancodes are not portable and you'd need huge lookup tables.

They are portable to the extent we should care about (they will work on any PC with a keyboard). For implementation specifics, check SDL (or others) - they should have figured portability already, and SDL is widely used.

And in the end you'd bother everyone with weird crap like the 'Z' binding actually mapping to the 'Y' key on German keyboard. Everyone would have trouble finding the correct symbol to bind.

That's why I recommended it to be a user option. To not bother people with weird crap.

I don't see how that's an advantage.

Advantage is for multi-layout users, that would like the same key to trigger shortcut regardless of what layout was current at the moment.

MadFishTheOne avatar Nov 20 '13 20:11 MadFishTheOne

For implementation specifics, check SDL (or others) - they should have figured portability already

Yes, and I've seen a very big bunch of dirty hacks.

That's why I recommended it to be a user option.

Making it an option would require even more code. (You'd have to keep the code for old method and the new one.)

Advantage is for multi-layout users, that would like the same key to trigger shortcut regardless of what layout was current at the moment.

Just use a program that switches the keyboard layout based on the currently focused application window. This is much simpler, saves us a lot of trouble, and avoids bloat in mpv.

ghost avatar Nov 20 '13 21:11 ghost

Few more points for completeness:

  1. Getting layout-independent mappings is only a potential problem on X11 ("mechanism, not policy" yay! where the most common case is handled as the special case). Both OS X and Windows are more defined in that regard and getting it to work there is rather trivial.
  2. Most other software has layout-independent bindings. Ctrl+C Ctrl+V works everywhere regardless of layout.
  3. Useful (for some people) feature is not necessarily bloat.

Besides, this:

Just use a program that switches the keyboard layout based on the currently focused application window.

forces user to a specific workflow (per-window layout) which might not necessarily be what the user wants (in fact I prefer global layout).

MadFishTheOne avatar Nov 21 '13 15:11 MadFishTheOne

If someone wants to implement it (in a non-intrusive enough way) I wouldn't be opposed to it. But personally I don't want to work on this. Probably nothing will happen into this direction, so I'm closing this for now.

forces user to a specific workflow (per-window layout) which might not necessarily be what the user wants (in fact I prefer global layout).

You could configure it to switch the layout for mpv, but not any other application.

ghost avatar Nov 22 '13 11:11 ghost

Checkout xkb-switch !

otommod avatar Nov 22 '13 12:11 otommod

I would suggest leaving the issue open, so that people can find it. Closing an issue means "this user story is resolved" (fixed, or would-not-fixed). However, that is not really the case here.

MadFishTheOne avatar Nov 22 '13 17:11 MadFishTheOne

Having too many issues open is a problem for me, because I can't see which things need work and for which are resolved.

ghost avatar Nov 22 '13 17:11 ghost

I can reopen it, if you take offense.

I won't work on this, though.

ghost avatar Nov 22 '13 17:11 ghost

There are three issues if we made the controls scancode-aware:

  1. mpv also runs on a terminal, e.g. when playing music. And we cannot get scan codes there.
  2. Documentation - we simply cannot describe such a mapping with text. A picture of a keyboard with is assignments would work, but can not be put on a manpage.
  3. input.conf becomes a mess.

divVerent avatar Nov 22 '13 19:11 divVerent

2 and 3 do not exist: input.conf will still use english letters.

Nikoli avatar Nov 22 '13 20:11 Nikoli