From 59605d552ef3a72d0c44eadea2945b4dfc984d6b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 19 Jun 2017 10:41:56 -0400 Subject: [PATCH 1/3] Keyboard: simplify execution of setxkbmap. Use QProcess::execute() with the 'safer' argument-list, rather than escaping and de-escaping strings. Also reduce noise by only passing a variant if there is one. --- src/modules/keyboard/KeyboardPage.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/modules/keyboard/KeyboardPage.cpp b/src/modules/keyboard/KeyboardPage.cpp index 117530a88..76eecc85c 100644 --- a/src/modules/keyboard/KeyboardPage.cpp +++ b/src/modules/keyboard/KeyboardPage.cpp @@ -67,8 +67,8 @@ KeyboardPage::KeyboardPage( QWidget* parent ) QString model = m_models.value( text, "pc105" ); // Set Xorg keyboard model - QProcess::execute( QString( "setxkbmap -model \"%1\"" ) - .arg( model ).toUtf8() ); + QProcess::execute( QLatin1Literal( "setxkbmap" ), + QStringList() << "-model" << model ); }); CALAMARES_RETRANSLATE( ui->retranslateUi( this ); ) @@ -292,6 +292,13 @@ KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current, updateVariants( QPersistentModelIndex( current ) ); } +static inline QStringList xkbmap_args( QStringList&& r, const QString& layout, const QString& variant) +{ + r << "-layout" << layout; + if ( !variant.isEmpty() ) + r << "-variant" << variant; + return r; +} void KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous ) @@ -320,8 +327,8 @@ KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWi connect( &m_setxkbmapTimer, &QTimer::timeout, this, [=] { - QProcess::execute( QString( "setxkbmap -layout \"%1\" -variant \"%2\"" ) - .arg( layout, variant ).toUtf8() ); + QProcess::execute( QLatin1Literal( "setxkbmap" ), + xkbmap_args( QStringList(), layout, variant ) ); cDebug() << "xkbmap selection changed to: " << layout << "-" << variant; m_setxkbmapTimer.disconnect( this ); } ); From 6ef2f5d769a6c9fbc2bb661e9487db282f42015b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 19 Jun 2017 10:46:30 -0400 Subject: [PATCH 2/3] Keyboard: code-docs, copyright --- src/modules/keyboard/KeyboardPage.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/keyboard/KeyboardPage.cpp b/src/modules/keyboard/KeyboardPage.cpp index 76eecc85c..e8a938629 100644 --- a/src/modules/keyboard/KeyboardPage.cpp +++ b/src/modules/keyboard/KeyboardPage.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2016, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Portions from the Manjaro Installation Framework * by Roland Singer @@ -292,6 +293,9 @@ KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current, updateVariants( QPersistentModelIndex( current ) ); } +/* Returns stringlist with suitable setxkbmap command-line arguments + * to set the given @p layout and @p variant. + */ static inline QStringList xkbmap_args( QStringList&& r, const QString& layout, const QString& variant) { r << "-layout" << layout; From e9ab78cd52e7e7bc87b0c8408c099d2f11ac5c1f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 19 Jun 2017 11:11:08 -0400 Subject: [PATCH 3/3] Keyboard: special-case, pc+latin interpreted as us, instead of as unknown which selects the first layout in the list. --- src/modules/keyboard/KeyboardPage.cpp | 29 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/modules/keyboard/KeyboardPage.cpp b/src/modules/keyboard/KeyboardPage.cpp index e8a938629..3f1b7b2c3 100644 --- a/src/modules/keyboard/KeyboardPage.cpp +++ b/src/modules/keyboard/KeyboardPage.cpp @@ -37,6 +37,21 @@ #include #include +static QPersistentModelIndex +findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout ) +{ + QPersistentModelIndex currentLayoutItem; + + for ( int i = 0; i < klm->rowCount(); ++i ) + { + QModelIndex idx = klm->index( i ); + if ( idx.isValid() && + idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout ) + currentLayoutItem = idx; + } + + return currentLayoutItem; +} KeyboardPage::KeyboardPage( QWidget* parent ) : QWidget() @@ -160,14 +175,13 @@ KeyboardPage::init() // Block signals ui->listLayout->blockSignals( true ); - QPersistentModelIndex currentLayoutItem; - - for ( int i = 0; i < klm->rowCount(); ++i ) + QPersistentModelIndex currentLayoutItem = findLayout( klm, currentLayout ); + if ( !currentLayoutItem.isValid() && ( + ( currentLayout == "latin" ) + || ( currentLayout == "pc" ) ) ) { - QModelIndex idx = klm->index( i ); - if ( idx.isValid() && - idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout ) - currentLayoutItem = idx; + currentLayout = "us"; + currentLayoutItem = findLayout( klm, currentLayout ); } // Set current layout and variant @@ -341,4 +355,3 @@ KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWi m_selectedLayout = layout; m_selectedVariant = variant; } -