On Thu, Jan 23, 2014 at 08:57:43PM +0000, Miod Vallat wrote:
> [cc: tech@, reply-to set to tech@]
> 
> > After suspend or hibernate, I lose my designated console keyboard layout 
> > (sv) and it reverts to the default (us?)  wsconsctl shows that the 
> > encoding to still be sv,
> > 
> >     keyboard.encoding=sv
> > 
> > What setting(s) am I missing to preserve the designated layout across 
> > suspend/hibernate?
> 
> Well, the mux is supposed to be a bit smart and remember a forced
> keyboard layout (set with kbd(8) or wsconsctl keyboard.encoding), and
> force it on new keyboard attachments.
> 
> Except that this only works when the `set encoding' ioctl is issued on
> /dev/wskbd, not /dev/wskbd[0-9], which is what kbd(8) and wsconsctl(8)
> prefer.
> 
> Fear not, for I have a diff for you (which I have been sitting on for
> about two years, and only completed and debugged thanks to this
> discussion)!
> 
> This diff attempts to achieve the following:
> - keyboard drivers will now tell wskbd if the keyboard layout they ask
>   for is a default value, or a value they are 100% sure of (either
>   because your kernel has a XXXKBD_LAYOUT option, or because the
>   driver can tell the keyboard layout, e.g. by the country code on USB
>   keyboards which provide it, such as Sun's)
> - when attaching a keyboard with a non-default layout, the layout will
>   become the default layout of the mux for new keyboard attachments if
>   the mux doesn't have a layout set already.
> - when changing the keyboard layout of a particular keyboard with an
>   ioctl (i.e. using kbd(8) or wsconsctl(8)), the layout will become the
>   default layout of the mux for new keyboard attachments.
> 
> This actually allows special-casing of the WSKBDIO_SETENCODING ioctl in
> the mux code to be removed.
> 
> If the above is a bit too complicated, let me provide an example.
> 
> I am booting a GENERIC kernel with a PS/2 us keyboard. The keyboard
> is wskbd0, its layout is the default, ``us''.
> 
>   $ wsconsctl 2>/dev/null |grep encoding
>   keyboard.encoding=us
> 
> Now I am plugging an icelandic USB keyboard with no country information.
> It becomes wskbd1, and uses the default layout, ``us''.
> 
>   $ wsconsctl 2>/dev/null |grep encoding
>   keyboard.encoding=us
>   keyboard1.encoding=us
> 
> Now I run:
> 
>   $ wsconsctl keyboard1.encoding=is
>   keyboard1.encoding -> is
> 
> Now the PS/2 keyboard is still using the us layout, the USB keyboard is
> using the icelandic layout (and I can enter thorns and eths), and the
> default setting for new keyboards become icelandic:
> 
>   $ wsconsctl 2>/dev/null |grep encoding
>   keyboard.encoding=us
>   keyboard1.encoding=is
> 
> I unplug the USB keyboard. 
> 
>   $ wsconsctl 2>/dev/null |grep encoding
>   keyboard.encoding=us
> 
> I plug the USB keyboard again. It will reattach with an icelandic
> keyboard layout, whereas it would use the us layout without that diff:
> 
>   $ wsconsctl 2>/dev/null |grep encoding
>   keyboard.encoding=us
>   keyboard1.encoding=is
> 
> Now I plug a Sun USB keyboard with the uk layout (pound sign as shift-3,
> etc). Sun keyboards provide country information to the ukbd driver,
> which uses it to select the matching layout.
> 
>   $ wsconsctl 2>/dev/null |grep encoding
>   keyboard.encoding=us
>   keyboard1.encoding=is
>   keyboard2.encoding=uk
> 
> And the uk layout has become the default for new attachments. If I
> unplug, then replug, the icelandic keyboard, it will reattach as wskbd1,
> and it will pick the default mux layout, which is still icelandic.
> 
>   $ wsconsctl 2>/dev/null |grep encoding
>   keyboard.encoding=us
>   keyboard1.encoding=is
>   keyboard2.encoding=uk
> 
> Now I unplug both USB keyboards...
> 
>   $ wsconsctl 2>/dev/null |grep encoding
>   keyboard.encoding=us
> 
> ... and put the machine to sleep.
> 
>   $ zzz
> 
> I wake up the system, and connect back the icelandic keyboard:
> 
>   $ wsconsctl 2>/dev/null |grep encoding
>   keyboard.encoding=us
>   keyboard1.encoding=is
> 
> Is this the behaviour you would like to get?

Couple of questions:

1. What if starting from this state:
        $ wsconsctl 2>/dev/null |grep encoding
        keyboard.encoding=us
        keyboard1.encoding=is
        keyboard2.encoding=uk

you unplug the Icelandic and Sun UK keyboards. Next attach
first the Sun UK keyboard and next the Icelandic one?

2. What if starting from this state:
        $ wsconsctl 2>/dev/null |grep encoding
        keyboard.encoding=us
        keyboard1.encoding=is

you unplug the Icelandic keyboard, and plug in a US layout
keyboard with no country codes?


Btw, your examples/illustrations were very useful!

hmm...

I am interested in this patch because I use Sun USB
keyboards, with "proper" Control key position (:P) but,
say, on my laptops, I set keyboard.encoding=us.swapctrlcaps.
Where, if/when I plug in said Sun USB keyboard, the key
marked "Control" is swapped as CapsLock.

I wonder if your patch, or similar, could fix the situation
such that, plugging in a Sun USB keyboard (with "proper" Ctrl
key position), it could "know" not to treat the Control key
on the Sun keyboard as CapsLock?

Cheers,
--patrick

Reply via email to