[keyboard] Implemented X11 config writing for additional layout

This commit is contained in:
Artem Grinev 2020-10-27 04:56:19 +03:00
parent 0dd027af90
commit bfc60ad2cf
7 changed files with 72 additions and 27 deletions

View File

@ -0,0 +1,24 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2020 Artem Grinev <agrinev@manjaro.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#ifndef KEYBOARD_ADDITIONAL_LAYOUT_INFO_H
#define KEYBOARD_ADDITIONAL_LAYOUT_INFO_H
#include <QString>
struct AdditionalLayoutInfo {
QString additionalLayout;
QString additionalVariant;
QString groupSwitcher;
QString vconsoleKeymap;
};
#endif

View File

@ -176,27 +176,33 @@ Config::Config( QObject* parent )
}
connect( &m_setxkbmapTimer, &QTimer::timeout, this, [=] {
AdditionalLayoutInfo info = getAdditionalLayoutInfo( m_selectedLayout);
m_selectedLayoutsAdditionalLayoutInfo = getAdditionalLayoutInfo( m_selectedLayout );
if(!info.additionalLayout.isEmpty())
if(!m_selectedLayoutsAdditionalLayoutInfo.additionalLayout.isEmpty())
{
m_selectedLayoutsAdditionalLayoutInfo = info;
QString switchOption = xkbmap_query_grp_option();
m_selectedLayoutsAdditionalLayoutInfo.groupSwitcher = xkbmap_query_grp_option();
QProcess::execute( "setxkbmap", xkbmap_layout_args(
{ info.additionalLayout, m_selectedLayout },
{ info.additionalVariant, m_selectedVariant },
switchOption.isEmpty()?"grp:alt_shift_toggle":QString() )
{ m_selectedLayoutsAdditionalLayoutInfo.additionalLayout, m_selectedLayout },
{ m_selectedLayoutsAdditionalLayoutInfo.additionalVariant, m_selectedVariant },
m_selectedLayoutsAdditionalLayoutInfo.groupSwitcher.isEmpty()?"grp:alt_shift_toggle":QString() )
);
if( m_selectedLayoutsAdditionalLayoutInfo.groupSwitcher.isEmpty() )
{
m_selectedLayoutsAdditionalLayoutInfo.groupSwitcher = "grp:alt_shift_toggle";
}
cDebug() << "xkbmap selection changed to: " << m_selectedLayout << '-' << m_selectedVariant
<< "(added " << info.additionalLayout << "-" << info.additionalVariant << " since current layout is not ASCII-capable)";
<< "(added " << m_selectedLayoutsAdditionalLayoutInfo.additionalLayout << "-"
<< m_selectedLayoutsAdditionalLayoutInfo.additionalVariant << " since current layout is not ASCII-capable)";
}
else
{
m_selectedLayoutsAdditionalLayoutInfo = AdditionalLayoutInfo();
QProcess::execute( "setxkbmap", xkbmap_layout_args( m_selectedLayout, m_selectedVariant ) );
cDebug() << "xkbеmap selection changed to: " << m_selectedLayout << '-' << m_selectedVariant;
cDebug() << "xkbmap selection changed to: " << m_selectedLayout << '-' << m_selectedVariant;
}
m_setxkbmapTimer.disconnect( this );
} );
@ -336,6 +342,7 @@ Config::createJobs()
Calamares::Job* j = new SetKeyboardLayoutJob( m_selectedModel,
m_selectedLayout,
m_selectedVariant,
m_selectedLayoutsAdditionalLayoutInfo,
m_xOrgConfFileName,
m_convertedKeymapPath,
m_writeEtcDefaultKeyboard );

View File

@ -13,6 +13,7 @@
#include "Job.h"
#include "KeyboardLayoutModel.h"
#include "AdditionalLayoutInfo.h"
#include <QAbstractListModel>
#include <QMap>
@ -20,13 +21,6 @@
#include <QTimer>
#include <QUrl>
struct AdditionalLayoutInfo {
QString additionalLayout;
QString additionalVariant;
QString vconsoleKeymap;
};
class Config : public QObject
{
Q_OBJECT

View File

@ -222,6 +222,7 @@ KeyboardPage::createJobs( const QString& xOrgConfFileName,
Calamares::Job* j = new SetKeyboardLayoutJob( selectedModel,
m_selectedLayout,
m_selectedVariant,
AdditionalLayoutInfo(),
xOrgConfFileName,
convertedKeymapPath,
writeEtcDefaultKeyboard );

View File

@ -32,7 +32,7 @@
SetKeyboardLayoutJob::SetKeyboardLayoutJob(const QString& model,
const QString& layout,
const QString& variant,
const QString& variant, const AdditionalLayoutInfo &additionaLayoutInfo,
const QString& xOrgConfFileName,
const QString& convertedKeymapPath,
bool writeEtcDefaultKeyboard )
@ -40,6 +40,7 @@ SetKeyboardLayoutJob::SetKeyboardLayoutJob( const QString& model,
, m_model( model )
, m_layout( layout )
, m_variant( variant )
, m_additionalLayoutInfo( additionaLayoutInfo )
, m_xOrgConfFileName( xOrgConfFileName )
, m_convertedKeymapPath( convertedKeymapPath )
, m_writeEtcDefaultKeyboard( writeEtcDefaultKeyboard )
@ -250,19 +251,32 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
" Identifier \"system-keyboard\"\n"
" MatchIsKeyboard \"on\"\n";
if ( m_additionalLayoutInfo.additionalLayout.isEmpty() )
{
if ( !m_layout.isEmpty() )
{
stream << " Option \"XkbLayout\" \"" << m_layout << "\"\n";
}
if ( !m_model.isEmpty() )
if ( !m_variant.isEmpty() )
{
stream << " Option \"XkbModel\" \"" << m_model << "\"\n";
stream << " Option \"XkbVariant\" \"" << m_variant << "\"\n";
}
}
else
{
if ( !m_layout.isEmpty() )
{
stream << " Option \"XkbLayout\" \"" << m_additionalLayoutInfo.additionalLayout << "," << m_layout << "\"\n";
}
if ( !m_variant.isEmpty() )
{
stream << " Option \"XkbVariant\" \"" << m_variant << "\"\n";
stream << " Option \"XkbVariant\" \"" << m_additionalLayoutInfo.additionalVariant << "," << m_variant << "\"\n";
}
stream << " Option \"XkbOptions\" \"" << m_additionalLayoutInfo.groupSwitcher << "\"\n";
}
stream << "EndSection\n";

View File

@ -12,6 +12,8 @@
#define SETKEYBOARDLAYOUTJOB_H
#include "Job.h"
#include "AdditionalLayoutInfo.h"
class SetKeyboardLayoutJob : public Calamares::Job
@ -21,6 +23,7 @@ public:
SetKeyboardLayoutJob( const QString& model,
const QString& layout,
const QString& variant,
const AdditionalLayoutInfo& additionaLayoutInfo,
const QString& xOrgConfFileName,
const QString& convertedKeymapPath,
bool writeEtcDefaultKeyboard );
@ -38,6 +41,7 @@ private:
QString m_model;
QString m_layout;
QString m_variant;
AdditionalLayoutInfo m_additionalLayoutInfo;
QString m_xOrgConfFileName;
QString m_convertedKeymapPath;
const bool m_writeEtcDefaultKeyboard;

View File

@ -3,5 +3,6 @@
<file alias="kbd-model-map">../keyboard/kbd-model-map</file>
<file alias="images/restore.png">../keyboard/images/restore.png</file>
<file>keyboardq.qml</file>
<file alias="non-ascii-layouts">../keyboard/non-ascii-layouts</file>
</qresource>
</RCC>