diff --git a/src/modules/keyboard/Config.cpp b/src/modules/keyboard/Config.cpp index c2f27982c..3450a7c1e 100644 --- a/src/modules/keyboard/Config.cpp +++ b/src/modules/keyboard/Config.cpp @@ -331,21 +331,10 @@ findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout ) } void -Config::detectCurrentKeyboardLayout() +Config::getCurrentKeyboardLayoutXkb( QString& currentLayout, QString& currentVariant ) { - if ( m_state != State::Initial ) - { - return; - } - cScopedAssignment returnToIntial( &m_state, State::Initial ); - m_state = State::Guessing; - - //### Detect current keyboard layout and variant - QString currentLayout; - QString currentVariant; QProcess process; process.start( "setxkbmap", QStringList() << "-print" ); - if ( process.waitForFinished() ) { const QStringList list = QString( process.readAll() ).split( "\n", SplitSkipEmptyParts ); @@ -385,6 +374,47 @@ Config::detectCurrentKeyboardLayout() } } } +} + +void +Config::getCurrentKeyboardLayoutLocale1( QString& currentLayout, QString& currentVariant ) +{ + QDBusInterface locale1( "org.freedesktop.locale1", + "/org/freedesktop/locale1", + "org.freedesktop.locale1", + QDBusConnection::systemBus() ); + if ( !locale1.isValid() ) + { + cWarning() << "Interface" << locale1.interface() << "is not valid."; + return; + } + + currentLayout = locale1.property( "X11Layout" ).toString().split( "," ).last(); + currentVariant = locale1.property( "X11Variant" ).toString().split( "," ).last(); +} + +void +Config::detectCurrentKeyboardLayout() +{ + if ( m_state != State::Initial ) + { + return; + } + cScopedAssignment returnToIntial( &m_state, State::Initial ); + m_state = State::Guessing; + + //### Detect current keyboard layout and variant + QString currentLayout; + QString currentVariant; + + if ( m_useLocale1 ) + { + getCurrentKeyboardLayoutLocale1( currentLayout, currentVariant ); + } + else + { + getCurrentKeyboardLayoutXkb( currentLayout, currentVariant ); + } //### Layouts and Variants QPersistentModelIndex currentLayoutItem = findLayout( m_keyboardLayoutsModel, currentLayout ); diff --git a/src/modules/keyboard/Config.h b/src/modules/keyboard/Config.h index e5bd7cb8b..02edee291 100644 --- a/src/modules/keyboard/Config.h +++ b/src/modules/keyboard/Config.h @@ -91,6 +91,9 @@ private: void xkbApply(); void locale1Apply(); + void getCurrentKeyboardLayoutXkb( QString& currentLayout, QString& currentVariant ); + void getCurrentKeyboardLayoutLocale1( QString& currentLayout, QString& currentVariant ); + KeyboardModelsModel* m_keyboardModelsModel; KeyboardLayoutModel* m_keyboardLayoutsModel; KeyboardVariantsModel* m_keyboardVariantsModel;