[2/2] xkb: if the keymap failed to compile, load the default keymap instead.

Submitted by Peter Hutterer on Feb. 10, 2011, 1:34 p.m.

Details

Message ID 1297316072-9804-2-git-send-email-peter.hutterer@who-t.net
State Deferred, archived
Headers show

Not browsing as part of any series.

Commit Message

Peter Hutterer Feb. 10, 2011, 1:34 p.m.
We really need symbols, compat and types for a sensible keymap.

Try this in your xorg.conf.d snippets for all keyboards:
        Option "XkbLayout" "us"
        Option "XkbVariant" "nodeadkeys"

us(nodeadkeys) doesn't exist so xkbcomp provides everything but the symbols
map. We say we want everything but don't _need_ anything, the server happily
gives us a keymap with every key mapped to NoSymbol. This in turn isn't what
we want after all.

So instead, require symbols, compat and types from the keymap and if that
fails, load the default keymap instead. If that fails too, all bets are off.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
---
 xkb/ddxLoad.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

Patch hide | download patch | download mbox

diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index b968c43..fea1847 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -470,13 +470,32 @@  XkbDescPtr
 XkbCompileKeymap(DeviceIntPtr dev, XkbRMLVOSet *rmlvo)
 {
     XkbDescPtr xkb;
+    unsigned int need;
 
     if (!dev || !rmlvo) {
         LogMessage(X_ERROR, "XKB: No device or RMLVO specified\n");
         return NULL;
     }
 
-    xkb = XkbCompileKeymapForDevice(dev, rmlvo, 0);
+    /* These are the components we really really need */
+    need = XkmSymbolsMask | XkmCompatMapMask | XkmTypesMask;
+
+    xkb = XkbCompileKeymapForDevice(dev, rmlvo, need);
+
+    if (!xkb) {
+        XkbRMLVOSet dflts;
+
+        /* we didn't get what we really needed. And that will likely leave
+         * us with a keyboard that doesn't work. Use the defaults instead */
+        LogMessage(X_ERROR, "XKB: Failed to load keymap. Loading default "
+                   "keymap instead.\n");
+
+        XkbGetRulesDflts(&dflts);
+
+        xkb = XkbCompileKeymapForDevice(dev, &dflts, 0);
+
+        XkbFreeRMLVOSet(&dflts, FALSE);
+    }
 
     return xkb;
 }

Comments

On Wed, Feb 9, 2011 at 9:34 PM, Peter Hutterer <peter.hutterer@who-t.net> wrote:
> We really need symbols, compat and types for a sensible keymap.
>
> Try this in your xorg.conf.d snippets for all keyboards:
>        Option "XkbLayout" "us"
>        Option "XkbVariant" "nodeadkeys"
>
> us(nodeadkeys) doesn't exist so xkbcomp provides everything but the symbols
> map. We say we want everything but don't _need_ anything, the server happily
> gives us a keymap with every key mapped to NoSymbol. This in turn isn't what
> we want after all.
>
> So instead, require symbols, compat and types from the keymap and if that
> fails, load the default keymap instead. If that fails too, all bets are off.
>
> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>

I'll take your word for it that symbols, compat and types are the
right things to require. This seems like a nice fix.

Reviewed-by: Dan Nicholson <dbn.lists@gmail.com>
On Thu, Feb 10, 2011 at 03:34:32PM +1000, Peter Hutterer wrote:
> We really need symbols, compat and types for a sensible keymap.
> 
> Try this in your xorg.conf.d snippets for all keyboards:
>         Option "XkbLayout" "us"
>         Option "XkbVariant" "nodeadkeys"
> 
> us(nodeadkeys) doesn't exist so xkbcomp provides everything but the symbols
> map. We say we want everything but don't _need_ anything, the server happily
> gives us a keymap with every key mapped to NoSymbol. This in turn isn't what
> we want after all.
> 
> So instead, require symbols, compat and types from the keymap and if that
> fails, load the default keymap instead. If that fails too, all bets are off.

I think you also need XkmKeyNamesMask and XkmVirtualModsMask to be
useful.

Cheers,
Daniel
On Thu, Feb 10, 2011 at 02:52:26PM +0000, Daniel Stone wrote:
> On Thu, Feb 10, 2011 at 03:34:32PM +1000, Peter Hutterer wrote:
> > We really need symbols, compat and types for a sensible keymap.
> > 
> > Try this in your xorg.conf.d snippets for all keyboards:
> >         Option "XkbLayout" "us"
> >         Option "XkbVariant" "nodeadkeys"
> > 
> > us(nodeadkeys) doesn't exist so xkbcomp provides everything but the symbols
> > map. We say we want everything but don't _need_ anything, the server happily
> > gives us a keymap with every key mapped to NoSymbol. This in turn isn't what
> > we want after all.
> > 
> > So instead, require symbols, compat and types from the keymap and if that
> > fails, load the default keymap instead. If that fails too, all bets are off.
> 
> I think you also need XkmKeyNamesMask and XkmVirtualModsMask to be
> useful.

amended, thanks.

Cheers,
  Peter