[libgnomekbd/wip/rtcm/cleanups: 1/6] gkbd-keyboard-drawing: Handle XkbGetKeyboard() failing



commit 0d714a1ed7735bb375a9a7c81009108053ad8d1f
Author: Rui Matos <tiagomatos gmail com>
Date:   Tue Sep 13 16:46:57 2016 +0200

    gkbd-keyboard-drawing: Handle XkbGetKeyboard() failing
    
    XkbGetKeyboard() might fail but we might still be able to work with a
    XkbGetKeyboardByName() later in gkbd_keyboard_drawing_set_keyboard()
    so don't abort the initialization if it fails.

 libgnomekbd/gkbd-keyboard-drawing.c |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)
---
diff --git a/libgnomekbd/gkbd-keyboard-drawing.c b/libgnomekbd/gkbd-keyboard-drawing.c
index 6894f47..64e62ea 100644
--- a/libgnomekbd/gkbd-keyboard-drawing.c
+++ b/libgnomekbd/gkbd-keyboard-drawing.c
@@ -1895,6 +1895,9 @@ free_cdik (                       /*colors doodads indicators keys */
 static void
 alloc_cdik (GkbdKeyboardDrawing * drawing)
 {
+       if (!drawing->xkb)
+               return;
+
        drawing->physical_indicators_size =
            drawing->xkb->indicators->phys_indicators + 1;
        drawing->physical_indicators =
@@ -2047,13 +2050,14 @@ gkbd_keyboard_drawing_init (GkbdKeyboardDrawing * drawing)
                                       XkbGBN_SymbolsMask |
                                       XkbGBN_IndicatorMapMask,
                                       XkbUseCoreKbd);
-       if (drawing->xkb == NULL) {
-               g_critical
-                   ("XkbGetKeyboard failed to get keyboard from the server!");
-               return;
+       if (drawing->xkb) {
+               XkbGetNames (drawing->display, XkbAllNamesMask, drawing->xkb);
+               XkbSelectEventDetails (drawing->display, XkbUseCoreKbd,
+                                      XkbIndicatorStateNotify,
+                                      drawing->xkb->indicators->phys_indicators,
+                                      drawing->xkb->indicators->phys_indicators);
        }
 
-       XkbGetNames (drawing->display, XkbAllNamesMask, drawing->xkb);
        drawing->l3mod = XkbKeysymToModifiers (drawing->display,
                                               GDK_KEY_ISO_Level3_Shift);
 
@@ -2061,11 +2065,6 @@ gkbd_keyboard_drawing_init (GkbdKeyboardDrawing * drawing)
 
        alloc_cdik (drawing);
 
-       XkbSelectEventDetails (drawing->display, XkbUseCoreKbd,
-                              XkbIndicatorStateNotify,
-                              drawing->xkb->indicators->phys_indicators,
-                              drawing->xkb->indicators->phys_indicators);
-
        mask =
            (XkbStateNotifyMask | XkbNamesNotifyMask |
             XkbControlsNotifyMask | XkbIndicatorMapNotifyMask |
@@ -2312,8 +2311,12 @@ gkbd_keyboard_drawing_set_keyboard (GkbdKeyboardDrawing * drawing,
                drawing->xkbOnDisplay = TRUE;
        }
 
-       if (drawing->xkb == NULL)
-               return FALSE;
+       if (drawing->xkb) {
+               XkbSelectEventDetails (drawing->display, XkbUseCoreKbd,
+                                      XkbIndicatorStateNotify,
+                                      drawing->xkb->indicators->phys_indicators,
+                                      drawing->xkb->indicators->phys_indicators);
+       }
 
        alloc_cdik (drawing);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]