[keyboard] Use the current keyboard model as the default
If there is a valid keyboard model set in the system already, keep it. This allows distributors to preconfigure the correct model if known. Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
6678d95a5d
commit
8be65003ce
@ -331,7 +331,7 @@ findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Config::getCurrentKeyboardLayoutXkb( QString& currentLayout, QString& currentVariant )
|
Config::getCurrentKeyboardLayoutXkb( QString& currentLayout, QString& currentVariant, QString& currentModel )
|
||||||
{
|
{
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.start( "setxkbmap", QStringList() << "-print" );
|
process.start( "setxkbmap", QStringList() << "-print" );
|
||||||
@ -343,10 +343,13 @@ Config::getCurrentKeyboardLayoutXkb( QString& currentLayout, QString& currentVar
|
|||||||
// xkb_symbols { include "pc+latin+ru:2+inet(evdev)+group(alt_shift_toggle)+ctrl(swapcaps)" };
|
// xkb_symbols { include "pc+latin+ru:2+inet(evdev)+group(alt_shift_toggle)+ctrl(swapcaps)" };
|
||||||
for ( const auto& line : list )
|
for ( const auto& line : list )
|
||||||
{
|
{
|
||||||
if ( !line.trimmed().startsWith( "xkb_symbols" ) )
|
bool symbols = false;
|
||||||
|
if ( line.trimmed().startsWith( "xkb_symbols" ) )
|
||||||
{
|
{
|
||||||
continue;
|
symbols = true;
|
||||||
}
|
}
|
||||||
|
else if ( !line.trimmed().startsWith( "xkb_geometry" ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
int firstQuote = line.indexOf( '"' );
|
int firstQuote = line.indexOf( '"' );
|
||||||
int lastQuote = line.lastIndexOf( '"' );
|
int lastQuote = line.lastIndexOf( '"' );
|
||||||
@ -358,7 +361,7 @@ Config::getCurrentKeyboardLayoutXkb( QString& currentLayout, QString& currentVar
|
|||||||
|
|
||||||
QStringList split = line.mid( firstQuote + 1, lastQuote - firstQuote ).split( "+", SplitSkipEmptyParts );
|
QStringList split = line.mid( firstQuote + 1, lastQuote - firstQuote ).split( "+", SplitSkipEmptyParts );
|
||||||
cDebug() << split;
|
cDebug() << split;
|
||||||
if ( split.size() >= 2 )
|
if ( symbols && split.size() >= 2 )
|
||||||
{
|
{
|
||||||
currentLayout = split.at( 1 );
|
currentLayout = split.at( 1 );
|
||||||
|
|
||||||
@ -372,12 +375,22 @@ Config::getCurrentKeyboardLayoutXkb( QString& currentLayout, QString& currentVar
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if ( !symbols && split.size() >= 1 )
|
||||||
|
{
|
||||||
|
currentModel = split.at( 0 );
|
||||||
|
if ( currentModel.contains( "(" ) )
|
||||||
|
{
|
||||||
|
int parenthesisIndex = currentLayout.indexOf( "(" );
|
||||||
|
currentModel = currentModel.mid( parenthesisIndex + 1 ).trimmed();
|
||||||
|
currentModel.chop( 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Config::getCurrentKeyboardLayoutLocale1( QString& currentLayout, QString& currentVariant )
|
Config::getCurrentKeyboardLayoutLocale1( QString& currentLayout, QString& currentVariant, QString& currentModel )
|
||||||
{
|
{
|
||||||
QDBusInterface locale1( "org.freedesktop.locale1",
|
QDBusInterface locale1( "org.freedesktop.locale1",
|
||||||
"/org/freedesktop/locale1",
|
"/org/freedesktop/locale1",
|
||||||
@ -391,6 +404,7 @@ Config::getCurrentKeyboardLayoutLocale1( QString& currentLayout, QString& curren
|
|||||||
|
|
||||||
currentLayout = locale1.property( "X11Layout" ).toString().split( "," ).last();
|
currentLayout = locale1.property( "X11Layout" ).toString().split( "," ).last();
|
||||||
currentVariant = locale1.property( "X11Variant" ).toString().split( "," ).last();
|
currentVariant = locale1.property( "X11Variant" ).toString().split( "," ).last();
|
||||||
|
currentModel = locale1.property( "X11Model" ).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -403,17 +417,18 @@ Config::detectCurrentKeyboardLayout()
|
|||||||
cScopedAssignment returnToIntial( &m_state, State::Initial );
|
cScopedAssignment returnToIntial( &m_state, State::Initial );
|
||||||
m_state = State::Guessing;
|
m_state = State::Guessing;
|
||||||
|
|
||||||
//### Detect current keyboard layout and variant
|
//### Detect current keyboard layout, variant, and model
|
||||||
QString currentLayout;
|
QString currentLayout;
|
||||||
QString currentVariant;
|
QString currentVariant;
|
||||||
|
QString currentModel;
|
||||||
|
|
||||||
if ( m_useLocale1 )
|
if ( m_useLocale1 )
|
||||||
{
|
{
|
||||||
getCurrentKeyboardLayoutLocale1( currentLayout, currentVariant );
|
getCurrentKeyboardLayoutLocale1( currentLayout, currentVariant, currentModel );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
getCurrentKeyboardLayoutXkb( currentLayout, currentVariant );
|
getCurrentKeyboardLayoutXkb( currentLayout, currentVariant, currentModel );
|
||||||
}
|
}
|
||||||
|
|
||||||
//### Layouts and Variants
|
//### Layouts and Variants
|
||||||
@ -437,6 +452,17 @@ Config::detectCurrentKeyboardLayout()
|
|||||||
{
|
{
|
||||||
m_keyboardLayoutsModel->setCurrentIndex( m_keyboardLayoutsModel->index( 0 ).row() );
|
m_keyboardLayoutsModel->setCurrentIndex( m_keyboardLayoutsModel->index( 0 ).row() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//### Keyboard model
|
||||||
|
for ( int i = 0; i < m_keyboardModelsModel->rowCount(); ++i )
|
||||||
|
{
|
||||||
|
QModelIndex idx = m_keyboardModelsModel->index( i );
|
||||||
|
if ( idx.isValid() && idx.data( XKBListModel::KeyRole ).toString() == currentModel )
|
||||||
|
{
|
||||||
|
m_keyboardModelsModel->setCurrentIndex( idx.row() );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
|
@ -91,8 +91,8 @@ private:
|
|||||||
void xkbApply();
|
void xkbApply();
|
||||||
void locale1Apply();
|
void locale1Apply();
|
||||||
|
|
||||||
void getCurrentKeyboardLayoutXkb( QString& currentLayout, QString& currentVariant );
|
void getCurrentKeyboardLayoutXkb( QString& currentLayout, QString& currentVariant, QString& currentModel );
|
||||||
void getCurrentKeyboardLayoutLocale1( QString& currentLayout, QString& currentVariant );
|
void getCurrentKeyboardLayoutLocale1( QString& currentLayout, QString& currentVariant, QString& currentModel );
|
||||||
|
|
||||||
KeyboardModelsModel* m_keyboardModelsModel;
|
KeyboardModelsModel* m_keyboardModelsModel;
|
||||||
KeyboardLayoutModel* m_keyboardLayoutsModel;
|
KeyboardLayoutModel* m_keyboardLayoutsModel;
|
||||||
|
@ -86,6 +86,7 @@ public:
|
|||||||
|
|
||||||
/// @brief Set the index back to PC105 (the default physical model)
|
/// @brief Set the index back to PC105 (the default physical model)
|
||||||
void setCurrentIndex() { XKBListModel::setCurrentIndex( m_defaultPC105 ); }
|
void setCurrentIndex() { XKBListModel::setCurrentIndex( m_defaultPC105 ); }
|
||||||
|
using XKBListModel::setCurrentIndex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_defaultPC105 = -1; ///< The index of pc105, if there is one
|
int m_defaultPC105 = -1; ///< The index of pc105, if there is one
|
||||||
|
Loading…
Reference in New Issue
Block a user