diff --git a/effects/trackmouse/trackmouse.cpp b/effects/trackmouse/trackmouse.cpp index c9fa60f3e5..f923421049 100644 --- a/effects/trackmouse/trackmouse.cpp +++ b/effects/trackmouse/trackmouse.cpp @@ -4,6 +4,7 @@ Copyright (C) 2006 Lubos Lunak Copyright (C) 2010 Jorge Mata +Copyright (C) 2018 Vlad Zagorodniy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -42,8 +43,7 @@ namespace KWin { TrackMouseEffect::TrackMouseEffect() - : m_active(false) - , m_angle(0) + : m_angle(0) { initConfig(); m_texture[0] = m_texture[1] = 0; @@ -107,21 +107,18 @@ void TrackMouseEffect::reconfigure(ReconfigureFlags) void TrackMouseEffect::prePaintScreen(ScreenPrePaintData& data, int time) { - if (m_active) { - QTime t = QTime::currentTime(); - m_angle = ((t.second() % 4) * m_angleBase) + (t.msec() / 1000.0 * m_angleBase); - m_lastRect[0].moveCenter(cursorPos()); - m_lastRect[1].moveCenter(cursorPos()); - data.paint |= m_lastRect[0].adjusted(-1,-1,1,1); - } + QTime t = QTime::currentTime(); + m_angle = ((t.second() % 4) * m_angleBase) + (t.msec() / 1000.0 * m_angleBase); + m_lastRect[0].moveCenter(cursorPos()); + m_lastRect[1].moveCenter(cursorPos()); + data.paint |= m_lastRect[0].adjusted(-1,-1,1,1); + effects->prePaintScreen(data, time); } void TrackMouseEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data) { effects->paintScreen(mask, region, data); // paint normal screen - if (!m_active) - return; if ( effects->isOpenGLCompositing() && m_texture[0] && m_texture[1]) { ShaderBinder binder(ShaderTrait::MapTexture); @@ -191,9 +188,7 @@ void TrackMouseEffect::paintScreen(int mask, QRegion region, ScreenPaintData& da void TrackMouseEffect::postPaintScreen() { - if (m_active) { - effects->addRepaint(m_lastRect[0].adjusted(-1,-1,1,1)); - } + effects->addRepaint(m_lastRect[0].adjusted(-1,-1,1,1)); effects->postPaintScreen(); } @@ -215,39 +210,71 @@ bool TrackMouseEffect::init() #endif m_lastRect[0].moveCenter(cursorPos()); m_lastRect[1].moveCenter(cursorPos()); - m_active = true; m_angle = 0; return true; } void TrackMouseEffect::toggle() { - if (m_mousePolling) - return; + switch (m_state) { + case State::ActivatedByModifiers: + m_state = State::ActivatedByShortcut; + break; - if (m_active) { - m_active = false; - } else if (!init()) { - return; + case State::ActivatedByShortcut: + m_state = State::Inactive; + break; + + case State::Inactive: + if (!init()) { + return; + } + m_state = State::ActivatedByShortcut; + break; + + default: + Q_UNREACHABLE(); + break; } - effects->addRepaint(m_lastRect[0].adjusted(-1,-1,1,1)); + + effects->addRepaint(m_lastRect[0].adjusted(-1, -1, 1, 1)); } void TrackMouseEffect::slotMouseChanged(const QPoint&, const QPoint&, Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers) { - if (!m_mousePolling) // we didn't ask for it but maybe someone else did... + if (!m_mousePolling) { // we didn't ask for it but maybe someone else did... return; - if (m_modifiers && modifiers == m_modifiers) { - if (!m_active && !init()) { + } + + switch (m_state) { + case State::ActivatedByModifiers: + if (modifiers == m_modifiers) { return; } - effects->addRepaint(m_lastRect[0].adjusted(-1,-1,1,1)); - } else if (m_active) { - m_active = false; - effects->addRepaint(m_lastRect[0].adjusted(-1,-1,1,1)); + m_state = State::Inactive; + break; + + case State::ActivatedByShortcut: + return; + + case State::Inactive: + if (modifiers != m_modifiers) { + return; + } + if (!init()) { + return; + } + m_state = State::ActivatedByModifiers; + break; + + default: + Q_UNREACHABLE(); + break; } + + effects->addRepaint(m_lastRect[0].adjusted(-1, -1, 1, 1)); } void TrackMouseEffect::loadTexture() @@ -280,7 +307,7 @@ void TrackMouseEffect::loadTexture() bool TrackMouseEffect::isActive() const { - return m_active; + return m_state != State::Inactive; } } // namespace diff --git a/effects/trackmouse/trackmouse.h b/effects/trackmouse/trackmouse.h index fabf360b71..f2eb602ca4 100644 --- a/effects/trackmouse/trackmouse.h +++ b/effects/trackmouse/trackmouse.h @@ -4,6 +4,7 @@ Copyright (C) 2006 Lubos Lunak Copyright (C) 2010 Jorge Mata +Copyright (C) 2018 Vlad Zagorodniy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -61,7 +62,7 @@ private: bool init(); void loadTexture(); QRect m_lastRect[2]; - bool m_active, m_mousePolling; + bool m_mousePolling; float m_angle; float m_angleBase; GLTexture* m_texture[2]; @@ -72,6 +73,13 @@ private: QAction* m_action; QImage m_image[2]; Qt::KeyboardModifiers m_modifiers; + + enum class State { + ActivatedByModifiers, + ActivatedByShortcut, + Inactive + }; + State m_state = State::Inactive; }; } // namespace diff --git a/effects/trackmouse/trackmouse_config.cpp b/effects/trackmouse/trackmouse_config.cpp index 51da99f47f..94d3211932 100644 --- a/effects/trackmouse/trackmouse_config.cpp +++ b/effects/trackmouse/trackmouse_config.cpp @@ -44,6 +44,8 @@ K_PLUGIN_FACTORY_WITH_JSON(TrackMouseEffectConfigFactory, namespace KWin { +static const QString s_toggleTrackMouseActionName = QStringLiteral("TrackMouse"); + TrackMouseEffectConfigForm::TrackMouseEffectConfigForm(QWidget* parent) : QWidget(parent) { setupUi(this); @@ -64,7 +66,7 @@ TrackMouseEffectConfig::TrackMouseEffectConfig(QWidget* parent, const QVariantLi m_actionCollection->setConfigGroup(QStringLiteral("TrackMouse")); m_actionCollection->setConfigGlobal(true); - QAction *a = m_actionCollection->addAction(QStringLiteral("TrackMouse")); + QAction *a = m_actionCollection->addAction(s_toggleTrackMouseActionName); a->setText(i18n("Track mouse")); a->setProperty("isConfigurationAction", true); @@ -81,20 +83,16 @@ TrackMouseEffectConfig::~TrackMouseEffectConfig() { } -void TrackMouseEffectConfig::checkModifiers() -{ - const bool modifiers = m_ui->kcfg_Shift->isChecked() || m_ui->kcfg_Alt->isChecked() || - m_ui->kcfg_Control->isChecked() || m_ui->kcfg_Meta->isChecked(); - m_ui->modifierRadio->setChecked(modifiers); - m_ui->shortcutRadio->setChecked(!modifiers); -} - void TrackMouseEffectConfig::load() { KCModule::load(); - checkModifiers(); - emit changed(false); + if (QAction *a = m_actionCollection->action(s_toggleTrackMouseActionName)) { + auto shortcuts = KGlobalAccel::self()->shortcut(a); + if (!shortcuts.isEmpty()) { + m_ui->shortcut->setKeySequence(shortcuts.first()); + } + } } void TrackMouseEffectConfig::save() @@ -111,7 +109,6 @@ void TrackMouseEffectConfig::defaults() { KCModule::defaults(); m_ui->shortcut->clearKeySequence(); - checkModifiers(); } void TrackMouseEffectConfig::shortcutChanged(const QKeySequence &seq) @@ -119,7 +116,6 @@ void TrackMouseEffectConfig::shortcutChanged(const QKeySequence &seq) if (QAction *a = m_actionCollection->action(QStringLiteral("TrackMouse"))) { KGlobalAccel::self()->setShortcut(a, QList() << seq, KGlobalAccel::NoAutoloading); } -// m_actionCollection->writeSettings(); emit changed(true); } diff --git a/effects/trackmouse/trackmouse_config.h b/effects/trackmouse/trackmouse_config.h index 211990d2b4..56f9a60db9 100644 --- a/effects/trackmouse/trackmouse_config.h +++ b/effects/trackmouse/trackmouse_config.h @@ -52,7 +52,6 @@ public Q_SLOTS: private Q_SLOTS: void shortcutChanged(const QKeySequence &seq); private: - void checkModifiers(); TrackMouseEffectConfigForm* m_ui; KActionCollection* m_actionCollection; }; diff --git a/effects/trackmouse/trackmouse_config.ui b/effects/trackmouse/trackmouse_config.ui index 1c87ffa32e..dff595d26e 100644 --- a/effects/trackmouse/trackmouse_config.ui +++ b/effects/trackmouse/trackmouse_config.ui @@ -6,8 +6,8 @@ 0 0 - 327 - 104 + 345 + 112 @@ -15,26 +15,48 @@ QFormLayout::FieldsStayAtSizeHint - + + + + 75 + true + + - Trigger on + Trigger effect with: - + - Modifiers + Keyboard shortcut: - - - false + + + + + + Modifier keys: + + + + - + + 0 + + + 0 + + + 0 + + 0 @@ -68,20 +90,6 @@ - - - - Shortcut - - - - - - - false - - - @@ -90,45 +98,7 @@ QWidget
kkeysequencewidget.h
- - KTitleWidget - QWidget -
ktitlewidget.h
-
- - - shortcutRadio - toggled(bool) - shortcut - setEnabled(bool) - - - 107 - 75 - - - 183 - 75 - - - - - modifierRadio - toggled(bool) - widget - setEnabled(bool) - - - 99 - 44 - - - 309 - 52 - - - - +