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

From: Eli Zaretskii <[email-masked]>
Date: Mon, 02 Nov 2020 17:38:22 +0200

> From: Arthur Miller <[email-masked]>
> Cc: Paul Pogonyshev <[email-masked]>,  [email-masked],
>   [email-masked]
> Date: Mon, 02 Nov 2020 05:41:06 +0100
> 
> > 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

That's what I was prfoposing to do, on the C level.

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

I don't think I understand what shortcuts you have in mind here.

> 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 think you are forgetting how many different methods are there on a
modern system to generate keyboard input.  There are system input
methods, there are virtual keyboards, etc. etc.  And I don't think we
can easily read keyboard on scancode level, either, even if we wanted
to.  But I'm not an expert.

> I don't know if it is possible to automatically detect keyboard layout
> change in all cases.

AFAIK, we only support that on MS-Windows.

> I know that Emacs automatically switches to different layout when I
> change keyboard with loadkeys or in vconsole.conf.

That's because we read characters, and those don't change.