Subject: Re: bug#43830: keyboard layout handling incompatible with rest of the OS

From: Arthur Miller <[email-masked]>
Date: Mon, 02 Nov 2020 05:41:06 +0100

Eli Zaretskii <[email-masked]> writes:

>> From: Paul Pogonyshev <[email-masked]>
>> Date: Sun, 1 Nov 2020 19:56:09 +0100
>> Cc: Juri Linkov <[email-masked]>, [email-masked]
>> 
>> > read-event will figure out by itself whether it should return the
>> > ASCII character or a non-ASCII character, and return that.
>> 
>> I'm not sure that is possible, because it doesn't really know how it
>> is going to be processed.
>
> It knows the binding of the character, and it knows other things.
>
> Nothing else makes sense to me, because exposing this info to Lisp
> means every Lisp program which deals with input will have to decide
> what to do with such events.

Couldn't Emacs just pack scancodes into some event structure similar as
raw_input in windows does? But I don't think Elisp programs really would
have use of scancodes anyway.

Would it be possible to use scancodes for the shortcuts internally in
the interpreter itself?

Shortcuts could be specified by users and scripts as they are now
(as keys/characters); but when Emacs starts, it could populate a lookup
table based on the current layout with scancodes, and then translate
shortcuts from keys to scancodes for internal usage. If user chagnes
keyboard layout on the fly, new lookup table would be generated, because
virtual keys would change but scancodes would stay same; so it wouldn't
matter if some key jumps from one physical key to another. That wouldn't
require to expose scancodes to Lisp either. But that would mean that
routines for inserting text in buffers would have to work differently
from shortcut handling routines, with regard to input; I don't know if
that is case now or if it is possible.

Is something like that possible to implement in current Emacs? Woukd it
be too much work?

I don't know if it is possible to automatically detect keyboard layout
change in all cases. I know that Emacs automatically switches to
different layout when I change keyboard with loadkeys or in vconsole.conf.