[effects/trackmouse] Allow to use both modifiers and shortcut

Summary:
The Track Mouse effect can be toggled either by pressing modifier keys
and moving mouse or by pressing a shortcut. It's not possible to use
the latter and then the former without changing config.

But there is one caveat, in order to use shortcut, you have to uncheck
all modifier keys. This seems to be not very intuitive.

In addition to that, the KCM allows to change shortcut even if there is
some checked modifier.

As the title says, this change makes possible to use both modifier keys
and shortcut to activate this effect without changing config.

KCM:
{F6237308, layout=center, size=full}

BUG: 398124
FIXED-IN: 5.14.0

Reviewers: #kwin, #plasma, #vdg, davidedmundson

Reviewed By: #kwin, #plasma, #vdg, davidedmundson

Subscribers: broulik, abetts, ngraham, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D15272
This commit is contained in:
Vlad Zagorodniy 2018-09-04 15:08:27 +03:00
parent cc1f30b43d
commit 74994a7fbd
5 changed files with 108 additions and 108 deletions

View file

@ -4,6 +4,7 @@
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
Copyright (C) 2010 Jorge Mata <matamax123@gmail.com>
Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com>
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<TrackMouseConfig>();
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

View file

@ -4,6 +4,7 @@
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
Copyright (C) 2010 Jorge Mata <matamax123@gmail.com>
Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com>
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

View file

@ -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<QKeySequence>() << seq, KGlobalAccel::NoAutoloading);
}
// m_actionCollection->writeSettings();
emit changed(true);
}

View file

@ -52,7 +52,6 @@ public Q_SLOTS:
private Q_SLOTS:
void shortcutChanged(const QKeySequence &seq);
private:
void checkModifiers();
TrackMouseEffectConfigForm* m_ui;
KActionCollection* m_actionCollection;
};

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>327</width>
<height>104</height>
<width>345</width>
<height>112</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
@ -15,26 +15,48 @@
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="KTitleWidget" name="ktitlewidget">
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Trigger on</string>
<string>Trigger effect with:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="modifierRadio">
<widget class="QLabel" name="label_KeyboardShortcut">
<property name="text">
<string>Modifiers</string>
<string>Keyboard shortcut:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QWidget" name="widget" native="true">
<property name="enabled">
<bool>false</bool>
<widget class="KKeySequenceWidget" name="shortcut" native="true"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_ModifierKeys">
<property name="text">
<string>Modifier keys:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -68,20 +90,6 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="shortcutRadio">
<property name="text">
<string>Shortcut</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KKeySequenceWidget" name="shortcut">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@ -90,45 +98,7 @@
<extends>QWidget</extends>
<header>kkeysequencewidget.h</header>
</customwidget>
<customwidget>
<class>KTitleWidget</class>
<extends>QWidget</extends>
<header>ktitlewidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>shortcutRadio</sender>
<signal>toggled(bool)</signal>
<receiver>shortcut</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>107</x>
<y>75</y>
</hint>
<hint type="destinationlabel">
<x>183</x>
<y>75</y>
</hint>
</hints>
</connection>
<connection>
<sender>modifierRadio</sender>
<signal>toggled(bool)</signal>
<receiver>widget</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>99</x>
<y>44</y>
</hint>
<hint type="destinationlabel">
<x>309</x>
<y>52</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>