src/gui/inputmethod/qximinputcontext_x11.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   342         }
   342         }
   343     }
   343     }
   344     return (fontsetCache[i] == (XFontSet)-1) ? 0 : fontsetCache[i];
   344     return (fontsetCache[i] == (XFontSet)-1) ? 0 : fontsetCache[i];
   345 }
   345 }
   346 
   346 
   347 
   347 extern bool qt_use_rtl_extensions; // from qapplication_x11.cpp
       
   348 #ifndef QT_NO_XKB
       
   349 extern void q_getLocaleAndDirection(QLocale *locale,
       
   350                                   Qt::LayoutDirection *direction,
       
   351                                   const QByteArray &layoutName,
       
   352                                   const QByteArray &variantName);
       
   353 #endif
   348 
   354 
   349 QXIMInputContext::QXIMInputContext()
   355 QXIMInputContext::QXIMInputContext()
   350 {
   356 {
   351     if (!qt_xim_preferred_style) // no configured input style, use the default
   357     if (!qt_xim_preferred_style) // no configured input style, use the default
   352         qt_xim_preferred_style = xim_default_style;
   358         qt_xim_preferred_style = xim_default_style;
   373     else if (XSetLocaleModifiers ("") == 0)
   379     else if (XSetLocaleModifiers ("") == 0)
   374         qWarning("Qt: Cannot set locale modifiers");
   380         qWarning("Qt: Cannot set locale modifiers");
   375     else
   381     else
   376         QXIMInputContext::create_xim();
   382         QXIMInputContext::create_xim();
   377 #endif // USE_X11R6_XIM
   383 #endif // USE_X11R6_XIM
       
   384 
       
   385 #ifndef QT_NO_XKB
       
   386     if (X11->use_xkb) {
       
   387         QByteArray layoutName;
       
   388         QByteArray variantName;
       
   389 
       
   390         Atom type = XNone;
       
   391         int format = 0;
       
   392         ulong nitems = 0;
       
   393         ulong bytesAfter = 0;
       
   394         uchar *data = 0;
       
   395         if (XGetWindowProperty(X11->display, RootWindow(X11->display, 0), ATOM(_XKB_RULES_NAMES), 0, 1024,
       
   396                                false, XA_STRING, &type, &format, &nitems, &bytesAfter, &data) == Success
       
   397             && type == XA_STRING && format == 8 && nitems > 2) {
       
   398 
       
   399             char *names[5] = { 0, 0, 0, 0, 0 };
       
   400             char *p = reinterpret_cast<char *>(data), *end = p + nitems;
       
   401             int i = 0;
       
   402             do {
       
   403                 names[i++] = p;
       
   404                 p += qstrlen(p) + 1;
       
   405             } while (p < end);
       
   406 
       
   407             QList<QByteArray> layoutNames = QByteArray::fromRawData(names[2], qstrlen(names[2])).split(',');
       
   408             QList<QByteArray> variantNames = QByteArray::fromRawData(names[3], qstrlen(names[3])).split(',');
       
   409             for (int i = 0; i < qMin(layoutNames.count(), variantNames.count()); ++i  ) {
       
   410                 QLocale keyboardInputLocale;
       
   411                 Qt::LayoutDirection keyboardInputDirection;
       
   412                 QByteArray variantName = variantNames.at(i);
       
   413                 const int dashPos = variantName.indexOf("-");
       
   414                 if (dashPos >= 0)
       
   415                     variantName.truncate(dashPos);
       
   416                 q_getLocaleAndDirection(&keyboardInputLocale,
       
   417                                       &keyboardInputDirection,
       
   418                                       layoutNames.at(i),
       
   419                                       variantName);
       
   420                 if (keyboardInputDirection == Qt::RightToLeft)
       
   421                     qt_use_rtl_extensions = true;
       
   422             }
       
   423         }
       
   424 
       
   425         if (data)
       
   426             XFree(data);
       
   427     }
       
   428 #endif // QT_NO_XKB
       
   429 
   378 }
   430 }
   379 
   431 
   380 
   432 
   381 /*!\internal
   433 /*!\internal
   382   Creates the application input method.
   434   Creates the application input method.