plugins/trackmouse: listen to mouse events when active

Previously TrackMouseEffect only listens to mouse events if there are
modifiers configured. So when it was activated by shortcut, the effect
doesn't follow mouse movements.

Instead, listen to mouse events when the effect has been activated, or
if any modifier is configured.

BUG: 487820
This commit is contained in:
Yifan Zhu 2024-08-07 10:30:48 -07:00
parent f86f7eba32
commit 8d5f46a719
2 changed files with 19 additions and 4 deletions

View file

@ -82,7 +82,7 @@ TrackMouseEffect::~TrackMouseEffect()
void TrackMouseEffect::reconfigure(ReconfigureFlags)
{
const bool active = bool(m_modifiers);
const bool needMouseEventsOld = needMouseEvents();
m_modifiers = Qt::KeyboardModifiers();
TrackMouseConfig::self()->read();
if (TrackMouseConfig::shift()) {
@ -97,10 +97,10 @@ void TrackMouseEffect::reconfigure(ReconfigureFlags)
if (TrackMouseConfig::meta()) {
m_modifiers |= Qt::MetaModifier;
}
const bool newActive = bool(m_modifiers);
if (newActive && !active) {
const bool needMouseEventsNew = needMouseEvents();
if (needMouseEventsNew && !needMouseEventsOld) {
connect(effects, &EffectsHandler::mouseChanged, this, &TrackMouseEffect::slotMouseChanged);
} else if (!newActive && active) {
} else if (!needMouseEventsNew && needMouseEventsOld) {
disconnect(effects, &EffectsHandler::mouseChanged, this, &TrackMouseEffect::slotMouseChanged);
}
}
@ -116,6 +116,7 @@ void TrackMouseEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mil
void TrackMouseEffect::toggle()
{
const bool needMouseEventsOld = needMouseEvents();
switch (m_state) {
case State::ActivatedByModifiers:
m_state = State::ActivatedByShortcut;
@ -134,6 +135,12 @@ void TrackMouseEffect::toggle()
break;
}
const bool needMouseEventsNew = needMouseEvents();
if (needMouseEventsNew && !needMouseEventsOld) {
connect(effects, &EffectsHandler::mouseChanged, this, &TrackMouseEffect::slotMouseChanged);
} else if (!needMouseEventsNew && needMouseEventsOld) {
disconnect(effects, &EffectsHandler::mouseChanged, this, &TrackMouseEffect::slotMouseChanged);
}
if (m_state == State::Inactive) {
m_rotatingArcsItem.reset();
} else {
@ -184,6 +191,11 @@ bool TrackMouseEffect::isActive() const
return m_state != State::Inactive;
}
bool TrackMouseEffect::needMouseEvents() const
{
return m_state != State::Inactive || m_modifiers;
}
} // namespace
#include "moc_trackmouse.cpp"

View file

@ -62,6 +62,9 @@ private:
ActivatedByShortcut,
Inactive
};
bool needMouseEvents() const;
State m_state = State::Inactive;
float m_angle = 0;
Qt::KeyboardModifiers m_modifiers;