[keyboard] Add support for getting the layout via locale1
Getter counterpart to the previous commit, to support using locale1 to fetch the current keyboard config. Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
812d861307
commit
25bb41f549
@ -331,21 +331,10 @@ findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
QProcess process;
|
||||||
process.start( "setxkbmap", QStringList() << "-print" );
|
process.start( "setxkbmap", QStringList() << "-print" );
|
||||||
|
|
||||||
if ( process.waitForFinished() )
|
if ( process.waitForFinished() )
|
||||||
{
|
{
|
||||||
const QStringList list = QString( process.readAll() ).split( "\n", SplitSkipEmptyParts );
|
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
|
//### Layouts and Variants
|
||||||
QPersistentModelIndex currentLayoutItem = findLayout( m_keyboardLayoutsModel, currentLayout );
|
QPersistentModelIndex currentLayoutItem = findLayout( m_keyboardLayoutsModel, currentLayout );
|
||||||
|
@ -91,6 +91,9 @@ private:
|
|||||||
void xkbApply();
|
void xkbApply();
|
||||||
void locale1Apply();
|
void locale1Apply();
|
||||||
|
|
||||||
|
void getCurrentKeyboardLayoutXkb( QString& currentLayout, QString& currentVariant );
|
||||||
|
void getCurrentKeyboardLayoutLocale1( QString& currentLayout, QString& currentVariant );
|
||||||
|
|
||||||
KeyboardModelsModel* m_keyboardModelsModel;
|
KeyboardModelsModel* m_keyboardModelsModel;
|
||||||
KeyboardLayoutModel* m_keyboardLayoutsModel;
|
KeyboardLayoutModel* m_keyboardLayoutsModel;
|
||||||
KeyboardVariantsModel* m_keyboardVariantsModel;
|
KeyboardVariantsModel* m_keyboardVariantsModel;
|
||||||
|
Loading…
Reference in New Issue
Block a user