From 8b6c79e19cfabd9f343884ddd91a738720c94583 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Wed, 12 Mar 2014 17:20:17 +1000 Subject: xkb: add KeymapOrDefault MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Helper function to return a default map if the keymap compilation failed. Signed-off-by: Peter Hutterer Reviewed-by: Kristian Høgsberg --- xkb/ddxLoad.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c index 0361b9be5..76bf09ca7 100644 --- a/xkb/ddxLoad.c +++ b/xkb/ddxLoad.c @@ -444,6 +444,29 @@ XkbCompileKeymapForDevice(DeviceIntPtr dev, XkbRMLVOSet * rmlvo, int need) return xkb; } +static XkbDescPtr +KeymapOrDefaults(DeviceIntPtr dev, XkbDescPtr xkb) +{ + XkbRMLVOSet dflts; + + if (xkb) + return xkb; + + /* 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; +} + + XkbDescPtr XkbCompileKeymap(DeviceIntPtr dev, XkbRMLVOSet * rmlvo) { @@ -461,20 +484,5 @@ XkbCompileKeymap(DeviceIntPtr dev, XkbRMLVOSet * rmlvo) 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; + return KeymapOrDefaults(dev, xkb); } -- cgit v1.2.3