Merge pull request #2136 from ivan1986/fix-non-ascii-keyboard

Write layout information for non-ASCII keyboard to X11 and console settnigs.

FIXES #2135
This commit is contained in:
Adriaan de Groot 2023-08-29 14:48:12 +02:00 committed by GitHub
commit 55a2d71e3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 32 deletions

View File

@ -177,6 +177,13 @@ SetKeyboardLayoutJob::findLegacyKeymap() const
return ::findLegacyKeymap( m_layout, m_model, m_variant );
}
QStringList
SetKeyboardLayoutJob::removeEmpty(QStringList& list) const
{
list.removeAll(QString());
return list;
}
bool
SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, const QString& convertedKeymapPath ) const
@ -268,32 +275,12 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
" MatchIsKeyboard \"on\"\n";
if ( m_additionalLayoutInfo.additionalLayout.isEmpty() )
QStringList layouts({m_additionalLayoutInfo.additionalLayout, m_layout});
QStringList variants({m_additionalLayoutInfo.additionalVariant, m_variant});
stream << " Option \"XkbLayout\" \"" << removeEmpty(layouts).join(",") << "\"\n";
stream << " Option \"XkbVariant\" \"" << removeEmpty(variants).join(",") << "\"\n";
if ( !m_additionalLayoutInfo.additionalLayout.isEmpty() )
{
if ( !m_layout.isEmpty() )
{
stream << " Option \"XkbLayout\" \"" << m_layout << "\"\n";
}
if ( !m_variant.isEmpty() )
{
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_additionalLayoutInfo.additionalVariant << "," << m_variant
<< "\"\n";
}
stream << " Option \"XkbOptions\" \"" << m_additionalLayoutInfo.groupSwitcher << "\"\n";
}
@ -302,8 +289,8 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
file.close();
cDebug() << Logger::SubEntry << "Written XkbLayout" << m_layout << "; XkbModel" << m_model << "; XkbVariant"
<< m_variant << "to X.org file" << keyboardConfPath << stream.status();
cDebug() << Logger::SubEntry << "Written XkbLayout" << layouts.join(",") << "; XkbModel" << m_model << "; XkbVariant"
<< variants.join(",") << "to X.org file" << keyboardConfPath << stream.status();
return ( stream.status() == QTextStream::Ok );
}
@ -322,20 +309,25 @@ SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPa
}
QTextStream stream( &file );
QStringList layouts({m_additionalLayoutInfo.additionalLayout, m_layout});
QStringList variants({m_additionalLayoutInfo.additionalVariant, m_variant});
stream << "# KEYBOARD CONFIGURATION FILE\n\n"
"# Consult the keyboard(5) manual page.\n\n";
stream << "XKBMODEL=\"" << m_model << "\"\n";
stream << "XKBLAYOUT=\"" << m_layout << "\"\n";
stream << "XKBVARIANT=\"" << m_variant << "\"\n";
stream << "XKBOPTIONS=\"\"\n\n";
stream << "XKBLAYOUT=\"" << removeEmpty(layouts).join(",") << "\"\n";
stream << "XKBVARIANT=\"" << removeEmpty(variants).join(",") << "\"\n";
if ( !m_additionalLayoutInfo.additionalLayout.isEmpty() )
{
stream << "XKBOPTIONS=\"" << m_additionalLayoutInfo.groupSwitcher << "\"\n";
}
stream << "BACKSPACE=\"guess\"\n";
stream.flush();
file.close();
cDebug() << Logger::SubEntry << "Written XKBMODEL" << m_model << "; XKBLAYOUT" << m_layout << "; XKBVARIANT"
<< m_variant << "to /etc/default/keyboard file" << defaultKeyboardPath << stream.status();
cDebug() << Logger::SubEntry << "Written XKBMODEL" << m_model << "; XKBLAYOUT" << layouts.join(",") << "; XKBVARIANT"
<< variants.join(",") << "to /etc/default/keyboard file" << defaultKeyboardPath << stream.status();
return ( stream.status() == QTextStream::Ok );
}

View File

@ -37,6 +37,7 @@ private:
bool writeVConsoleData( const QString& vconsoleConfPath, const QString& convertedKeymapPath ) const;
bool writeX11Data( const QString& keyboardConfPath ) const;
bool writeDefaultKeyboardData( const QString& defaultKeyboardPath ) const;
QStringList removeEmpty(QStringList& list) const;
QString m_model;
QString m_layout;