[keyboard] Factor out lambdas to regular slots
- Long and complicated, nested, lambdas are not convenient for reasoning. - The debug messages from the innermost lambda have a totally useless function name, which makes debugging harder.
This commit is contained in:
parent
d6825c4986
commit
f38b518e86
@ -168,54 +168,64 @@ Config::Config( QObject* parent )
|
|||||||
emit prettyStatusChanged();
|
emit prettyStatusChanged();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
connect( m_keyboardVariantsModel, &KeyboardVariantsModel::currentIndexChanged, [&]( int index ) {
|
connect( m_keyboardVariantsModel, &KeyboardVariantsModel::currentIndexChanged, this, &Config::xkbChanged );
|
||||||
// Set Xorg keyboard layout + variant
|
|
||||||
m_selectedVariant = m_keyboardVariantsModel->key( index );
|
|
||||||
|
|
||||||
if ( m_setxkbmapTimer.isActive() )
|
|
||||||
{
|
|
||||||
m_setxkbmapTimer.stop();
|
|
||||||
m_setxkbmapTimer.disconnect( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
connect( &m_setxkbmapTimer, &QTimer::timeout, this, [=] {
|
|
||||||
m_additionalLayoutInfo = getAdditionalLayoutInfo( m_selectedLayout );
|
|
||||||
|
|
||||||
if ( !m_additionalLayoutInfo.additionalLayout.isEmpty() )
|
|
||||||
{
|
|
||||||
m_additionalLayoutInfo.groupSwitcher = xkbmap_query_grp_option();
|
|
||||||
|
|
||||||
if ( m_additionalLayoutInfo.groupSwitcher.isEmpty() )
|
|
||||||
{
|
|
||||||
m_additionalLayoutInfo.groupSwitcher = "grp:alt_shift_toggle";
|
|
||||||
}
|
|
||||||
|
|
||||||
QProcess::execute( "setxkbmap",
|
|
||||||
xkbmap_layout_args( { m_additionalLayoutInfo.additionalLayout, m_selectedLayout },
|
|
||||||
{ m_additionalLayoutInfo.additionalVariant, m_selectedVariant },
|
|
||||||
m_additionalLayoutInfo.groupSwitcher ) );
|
|
||||||
|
|
||||||
|
|
||||||
cDebug() << "xkbmap selection changed to: " << m_selectedLayout << '-' << m_selectedVariant << "(added "
|
|
||||||
<< m_additionalLayoutInfo.additionalLayout << "-" << m_additionalLayoutInfo.additionalVariant
|
|
||||||
<< " since current layout is not ASCII-capable)";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QProcess::execute( "setxkbmap", xkbmap_layout_args( m_selectedLayout, m_selectedVariant ) );
|
|
||||||
cDebug() << "xkbmap selection changed to: " << m_selectedLayout << '-' << m_selectedVariant;
|
|
||||||
}
|
|
||||||
m_setxkbmapTimer.disconnect( this );
|
|
||||||
} );
|
|
||||||
m_setxkbmapTimer.start( QApplication::keyboardInputInterval() );
|
|
||||||
emit prettyStatusChanged();
|
|
||||||
} );
|
|
||||||
|
|
||||||
m_selectedModel = m_keyboardModelsModel->key( m_keyboardModelsModel->currentIndex() );
|
m_selectedModel = m_keyboardModelsModel->key( m_keyboardModelsModel->currentIndex() );
|
||||||
m_selectedLayout = m_keyboardLayoutsModel->item( m_keyboardLayoutsModel->currentIndex() ).first;
|
m_selectedLayout = m_keyboardLayoutsModel->item( m_keyboardLayoutsModel->currentIndex() ).first;
|
||||||
m_selectedVariant = m_keyboardVariantsModel->key( m_keyboardVariantsModel->currentIndex() );
|
m_selectedVariant = m_keyboardVariantsModel->key( m_keyboardVariantsModel->currentIndex() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::xkbChanged( int index )
|
||||||
|
{
|
||||||
|
// Set Xorg keyboard layout + variant
|
||||||
|
m_selectedVariant = m_keyboardVariantsModel->key( index );
|
||||||
|
|
||||||
|
if ( m_setxkbmapTimer.isActive() )
|
||||||
|
{
|
||||||
|
m_setxkbmapTimer.stop();
|
||||||
|
m_setxkbmapTimer.disconnect( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
connect( &m_setxkbmapTimer, &QTimer::timeout, this, &Config::xkbApply );
|
||||||
|
|
||||||
|
m_setxkbmapTimer.start( QApplication::keyboardInputInterval() );
|
||||||
|
emit prettyStatusChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::xkbApply()
|
||||||
|
{
|
||||||
|
m_additionalLayoutInfo = getAdditionalLayoutInfo( m_selectedLayout );
|
||||||
|
|
||||||
|
if ( !m_additionalLayoutInfo.additionalLayout.isEmpty() )
|
||||||
|
{
|
||||||
|
m_additionalLayoutInfo.groupSwitcher = xkbmap_query_grp_option();
|
||||||
|
|
||||||
|
if ( m_additionalLayoutInfo.groupSwitcher.isEmpty() )
|
||||||
|
{
|
||||||
|
m_additionalLayoutInfo.groupSwitcher = "grp:alt_shift_toggle";
|
||||||
|
}
|
||||||
|
|
||||||
|
QProcess::execute( "setxkbmap",
|
||||||
|
xkbmap_layout_args( { m_additionalLayoutInfo.additionalLayout, m_selectedLayout },
|
||||||
|
{ m_additionalLayoutInfo.additionalVariant, m_selectedVariant },
|
||||||
|
m_additionalLayoutInfo.groupSwitcher ) );
|
||||||
|
|
||||||
|
|
||||||
|
cDebug() << "xkbmap selection changed to: " << m_selectedLayout << '-' << m_selectedVariant << "(added "
|
||||||
|
<< m_additionalLayoutInfo.additionalLayout << "-" << m_additionalLayoutInfo.additionalVariant
|
||||||
|
<< " since current layout is not ASCII-capable)";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QProcess::execute( "setxkbmap", xkbmap_layout_args( m_selectedLayout, m_selectedVariant ) );
|
||||||
|
cDebug() << "xkbmap selection changed to: " << m_selectedLayout << '-' << m_selectedVariant;
|
||||||
|
}
|
||||||
|
m_setxkbmapTimer.disconnect( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
KeyboardModelsModel*
|
KeyboardModelsModel*
|
||||||
Config::keyboardModels() const
|
Config::keyboardModels() const
|
||||||
{
|
{
|
||||||
|
@ -76,6 +76,18 @@ private:
|
|||||||
void guessLayout( const QStringList& langParts );
|
void guessLayout( const QStringList& langParts );
|
||||||
void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() );
|
void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() );
|
||||||
|
|
||||||
|
/* These two methods are used in tandem to apply changes to the
|
||||||
|
* keyboard layout. This introduces a slight delay between selecting
|
||||||
|
* a keyboard, and applying it to the system -- so that if you
|
||||||
|
* scroll through or down-arrow through the list of keyboards,
|
||||||
|
* you don't get buried under xkbset processes.
|
||||||
|
*
|
||||||
|
* xkbChanged() is called when the selection changes, and triggers
|
||||||
|
* a delayed call to xkbApply() which does the actual work.
|
||||||
|
*/
|
||||||
|
void xkbChanged( int index );
|
||||||
|
void xkbApply();
|
||||||
|
|
||||||
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