[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/D15272icc-effect-5.14.5
parent
cc1f30b43d
commit
74994a7fbd
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
||||||
Copyright (C) 2010 Jorge Mata <matamax123@gmail.com>
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -42,8 +43,7 @@ namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
TrackMouseEffect::TrackMouseEffect()
|
TrackMouseEffect::TrackMouseEffect()
|
||||||
: m_active(false)
|
: m_angle(0)
|
||||||
, m_angle(0)
|
|
||||||
{
|
{
|
||||||
initConfig<TrackMouseConfig>();
|
initConfig<TrackMouseConfig>();
|
||||||
m_texture[0] = m_texture[1] = 0;
|
m_texture[0] = m_texture[1] = 0;
|
||||||
|
@ -107,21 +107,18 @@ void TrackMouseEffect::reconfigure(ReconfigureFlags)
|
||||||
|
|
||||||
void TrackMouseEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
void TrackMouseEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
||||||
{
|
{
|
||||||
if (m_active) {
|
QTime t = QTime::currentTime();
|
||||||
QTime t = QTime::currentTime();
|
m_angle = ((t.second() % 4) * m_angleBase) + (t.msec() / 1000.0 * m_angleBase);
|
||||||
m_angle = ((t.second() % 4) * m_angleBase) + (t.msec() / 1000.0 * m_angleBase);
|
m_lastRect[0].moveCenter(cursorPos());
|
||||||
m_lastRect[0].moveCenter(cursorPos());
|
m_lastRect[1].moveCenter(cursorPos());
|
||||||
m_lastRect[1].moveCenter(cursorPos());
|
data.paint |= m_lastRect[0].adjusted(-1,-1,1,1);
|
||||||
data.paint |= m_lastRect[0].adjusted(-1,-1,1,1);
|
|
||||||
}
|
|
||||||
effects->prePaintScreen(data, time);
|
effects->prePaintScreen(data, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackMouseEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
|
void TrackMouseEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
|
||||||
{
|
{
|
||||||
effects->paintScreen(mask, region, data); // paint normal screen
|
effects->paintScreen(mask, region, data); // paint normal screen
|
||||||
if (!m_active)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( effects->isOpenGLCompositing() && m_texture[0] && m_texture[1]) {
|
if ( effects->isOpenGLCompositing() && m_texture[0] && m_texture[1]) {
|
||||||
ShaderBinder binder(ShaderTrait::MapTexture);
|
ShaderBinder binder(ShaderTrait::MapTexture);
|
||||||
|
@ -191,9 +188,7 @@ void TrackMouseEffect::paintScreen(int mask, QRegion region, ScreenPaintData& da
|
||||||
|
|
||||||
void TrackMouseEffect::postPaintScreen()
|
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();
|
effects->postPaintScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,39 +210,71 @@ bool TrackMouseEffect::init()
|
||||||
#endif
|
#endif
|
||||||
m_lastRect[0].moveCenter(cursorPos());
|
m_lastRect[0].moveCenter(cursorPos());
|
||||||
m_lastRect[1].moveCenter(cursorPos());
|
m_lastRect[1].moveCenter(cursorPos());
|
||||||
m_active = true;
|
|
||||||
m_angle = 0;
|
m_angle = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackMouseEffect::toggle()
|
void TrackMouseEffect::toggle()
|
||||||
{
|
{
|
||||||
if (m_mousePolling)
|
switch (m_state) {
|
||||||
return;
|
case State::ActivatedByModifiers:
|
||||||
|
m_state = State::ActivatedByShortcut;
|
||||||
|
break;
|
||||||
|
|
||||||
if (m_active) {
|
case State::ActivatedByShortcut:
|
||||||
m_active = false;
|
m_state = State::Inactive;
|
||||||
} else if (!init()) {
|
break;
|
||||||
return;
|
|
||||||
|
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&,
|
void TrackMouseEffect::slotMouseChanged(const QPoint&, const QPoint&,
|
||||||
Qt::MouseButtons, Qt::MouseButtons,
|
Qt::MouseButtons, Qt::MouseButtons,
|
||||||
Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers)
|
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;
|
return;
|
||||||
if (m_modifiers && modifiers == m_modifiers) {
|
}
|
||||||
if (!m_active && !init()) {
|
|
||||||
|
switch (m_state) {
|
||||||
|
case State::ActivatedByModifiers:
|
||||||
|
if (modifiers == m_modifiers) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
effects->addRepaint(m_lastRect[0].adjusted(-1,-1,1,1));
|
m_state = State::Inactive;
|
||||||
} else if (m_active) {
|
break;
|
||||||
m_active = false;
|
|
||||||
effects->addRepaint(m_lastRect[0].adjusted(-1,-1,1,1));
|
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()
|
void TrackMouseEffect::loadTexture()
|
||||||
|
@ -280,7 +307,7 @@ void TrackMouseEffect::loadTexture()
|
||||||
|
|
||||||
bool TrackMouseEffect::isActive() const
|
bool TrackMouseEffect::isActive() const
|
||||||
{
|
{
|
||||||
return m_active;
|
return m_state != State::Inactive;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
||||||
Copyright (C) 2010 Jorge Mata <matamax123@gmail.com>
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -61,7 +62,7 @@ private:
|
||||||
bool init();
|
bool init();
|
||||||
void loadTexture();
|
void loadTexture();
|
||||||
QRect m_lastRect[2];
|
QRect m_lastRect[2];
|
||||||
bool m_active, m_mousePolling;
|
bool m_mousePolling;
|
||||||
float m_angle;
|
float m_angle;
|
||||||
float m_angleBase;
|
float m_angleBase;
|
||||||
GLTexture* m_texture[2];
|
GLTexture* m_texture[2];
|
||||||
|
@ -72,6 +73,13 @@ private:
|
||||||
QAction* m_action;
|
QAction* m_action;
|
||||||
QImage m_image[2];
|
QImage m_image[2];
|
||||||
Qt::KeyboardModifiers m_modifiers;
|
Qt::KeyboardModifiers m_modifiers;
|
||||||
|
|
||||||
|
enum class State {
|
||||||
|
ActivatedByModifiers,
|
||||||
|
ActivatedByShortcut,
|
||||||
|
Inactive
|
||||||
|
};
|
||||||
|
State m_state = State::Inactive;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -44,6 +44,8 @@ K_PLUGIN_FACTORY_WITH_JSON(TrackMouseEffectConfigFactory,
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static const QString s_toggleTrackMouseActionName = QStringLiteral("TrackMouse");
|
||||||
|
|
||||||
TrackMouseEffectConfigForm::TrackMouseEffectConfigForm(QWidget* parent) : QWidget(parent)
|
TrackMouseEffectConfigForm::TrackMouseEffectConfigForm(QWidget* parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
@ -64,7 +66,7 @@ TrackMouseEffectConfig::TrackMouseEffectConfig(QWidget* parent, const QVariantLi
|
||||||
m_actionCollection->setConfigGroup(QStringLiteral("TrackMouse"));
|
m_actionCollection->setConfigGroup(QStringLiteral("TrackMouse"));
|
||||||
m_actionCollection->setConfigGlobal(true);
|
m_actionCollection->setConfigGlobal(true);
|
||||||
|
|
||||||
QAction *a = m_actionCollection->addAction(QStringLiteral("TrackMouse"));
|
QAction *a = m_actionCollection->addAction(s_toggleTrackMouseActionName);
|
||||||
a->setText(i18n("Track mouse"));
|
a->setText(i18n("Track mouse"));
|
||||||
a->setProperty("isConfigurationAction", true);
|
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()
|
void TrackMouseEffectConfig::load()
|
||||||
{
|
{
|
||||||
KCModule::load();
|
KCModule::load();
|
||||||
|
|
||||||
checkModifiers();
|
if (QAction *a = m_actionCollection->action(s_toggleTrackMouseActionName)) {
|
||||||
emit changed(false);
|
auto shortcuts = KGlobalAccel::self()->shortcut(a);
|
||||||
|
if (!shortcuts.isEmpty()) {
|
||||||
|
m_ui->shortcut->setKeySequence(shortcuts.first());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackMouseEffectConfig::save()
|
void TrackMouseEffectConfig::save()
|
||||||
|
@ -111,7 +109,6 @@ void TrackMouseEffectConfig::defaults()
|
||||||
{
|
{
|
||||||
KCModule::defaults();
|
KCModule::defaults();
|
||||||
m_ui->shortcut->clearKeySequence();
|
m_ui->shortcut->clearKeySequence();
|
||||||
checkModifiers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackMouseEffectConfig::shortcutChanged(const QKeySequence &seq)
|
void TrackMouseEffectConfig::shortcutChanged(const QKeySequence &seq)
|
||||||
|
@ -119,7 +116,6 @@ void TrackMouseEffectConfig::shortcutChanged(const QKeySequence &seq)
|
||||||
if (QAction *a = m_actionCollection->action(QStringLiteral("TrackMouse"))) {
|
if (QAction *a = m_actionCollection->action(QStringLiteral("TrackMouse"))) {
|
||||||
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << seq, KGlobalAccel::NoAutoloading);
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << seq, KGlobalAccel::NoAutoloading);
|
||||||
}
|
}
|
||||||
// m_actionCollection->writeSettings();
|
|
||||||
emit changed(true);
|
emit changed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@ public Q_SLOTS:
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void shortcutChanged(const QKeySequence &seq);
|
void shortcutChanged(const QKeySequence &seq);
|
||||||
private:
|
private:
|
||||||
void checkModifiers();
|
|
||||||
TrackMouseEffectConfigForm* m_ui;
|
TrackMouseEffectConfigForm* m_ui;
|
||||||
KActionCollection* m_actionCollection;
|
KActionCollection* m_actionCollection;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>327</width>
|
<width>345</width>
|
||||||
<height>104</height>
|
<height>112</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
@ -15,26 +15,48 @@
|
||||||
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
|
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0" colspan="2">
|
<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">
|
<property name="text">
|
||||||
<string>Trigger on</string>
|
<string>Trigger effect with:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QRadioButton" name="modifierRadio">
|
<widget class="QLabel" name="label_KeyboardShortcut">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Modifiers</string>
|
<string>Keyboard shortcut:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QWidget" name="widget" native="true">
|
<widget class="KKeySequenceWidget" name="shortcut" native="true"/>
|
||||||
<property name="enabled">
|
</item>
|
||||||
<bool>false</bool>
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_ModifierKeys">
|
||||||
|
<property name="text">
|
||||||
|
<string>Modifier keys:</string>
|
||||||
</property>
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QWidget" name="widget" native="true">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<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>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
|
@ -68,20 +90,6 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
@ -90,45 +98,7 @@
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>kkeysequencewidget.h</header>
|
<header>kkeysequencewidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>KTitleWidget</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>ktitlewidget.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<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>
|
|
||||||
</ui>
|
</ui>
|
||||||
|
|
Loading…
Reference in New Issue