Commit c30c6f42 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Implement a hack for right- and middle-buttons on weird tablet devices

If should fix the following cases:

1) Wintab drivers that do not generate tablet events for right-click and
   middle-click.

2) WinInk mode. With the patch both right- and middle-clicks should be
   available with the stylus buttons.

To activate a workaround just add the following to your 'kritarc':

rightMiddleTabletButtonWorkaround=true

This hack just ignores tablet events for right- and middle-click and
starts to use mouse events for them. Please be careful, the hack will
make right- and middle-strokes less precise. And it also can just break
the tablet support completely.

CCBUG:399585
CCBUG:368849
parent 714c9aae
......@@ -288,9 +288,6 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick: {
d->debugEvent<QMouseEvent, true>(event);
//Block mouse press events on Genius tablets
if (d->tabletActive) break;
if (d->ignoringQtCursorEvents()) break;
if (d->touchHasBlockedPressEvents) break;
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
......@@ -309,7 +306,6 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
}
case QEvent::MouseButtonRelease: {
d->debugEvent<QMouseEvent, true>(event);
if (d->ignoringQtCursorEvents()) break;
if (d->touchHasBlockedPressEvents) break;
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
......@@ -352,7 +348,6 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
}
case QEvent::MouseMove: {
d->debugEvent<QMouseEvent, true>(event);
if (d->ignoringQtCursorEvents()) break;
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
retval = compressMoveEventCommon(mouseEvent);
......
......@@ -69,6 +69,12 @@ static bool isMouseEventType(QEvent::Type t)
t == QEvent::MouseButtonDblClick);
}
KisInputManager::Private::EventEater::EventEater()
{
KisConfig cfg(true);
activateSecondaryButtonsWorkaround = cfg.readEntry("rightMiddleTabletButtonWorkaround", false);
}
bool KisInputManager::Private::EventEater::eventFilter(QObject* target, QEvent* event )
{
Q_UNUSED(target)
......@@ -81,6 +87,14 @@ bool KisInputManager::Private::EventEater::eventFilter(QObject* target, QEvent*
}
};
auto debugTabletEvent = [&](int i) {
if (KisTabletDebugger::instance()->debugEnabled()) {
QString pre = QString("[BLOCKED %1:]").arg(i);
QTabletEvent *ev = static_cast<QTabletEvent*>(event);
dbgTablet << KisTabletDebugger::instance()->eventToString(*ev, pre);
}
};
if (peckish && event->type() == QEvent::MouseButtonPress
// Drop one mouse press following tabletPress or touchBegin
&& (static_cast<QMouseEvent*>(event)->button() == Qt::LeftButton)) {
......@@ -88,7 +102,28 @@ bool KisInputManager::Private::EventEater::eventFilter(QObject* target, QEvent*
debugEvent(1);
return true;
}
else if (isMouseEventType(event->type()) &&
if (activateSecondaryButtonsWorkaround) {
if (event->type() == QEvent::TabletPress ||
event->type() == QEvent::TabletRelease) {
QTabletEvent *te = static_cast<QTabletEvent*>(event);
if (te->button() != Qt::LeftButton) {
debugTabletEvent(3);
return true;
}
} else if (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease ||
event->type() == QEvent::MouseButtonDblClick) {
QMouseEvent *me = static_cast<QMouseEvent*>(event);
if (me->button() != Qt::LeftButton) {
return false;
}
}
}
if (isMouseEventType(event->type()) &&
(hungry
// On Mac, we need mouse events when the tablet is in proximity, but not pressed down
// since tablet move events are not generated until after tablet press.
......@@ -136,11 +171,6 @@ void KisInputManager::Private::setMaskSyntheticEvents(bool value)
eventEater.eatSyntheticEvents = value;
}
void KisInputManager::Private::setTabletActive(bool value)
{
tabletActive = value;
}
KisInputManager::Private::Private(KisInputManager *qq)
: q(qq)
, moveEventCompressor(10 /* ms */, KisSignalCompressor::FIRST_ACTIVE)
......
......@@ -73,7 +73,6 @@ public:
QScopedPointer<QEvent> compressedMoveEvent;
bool testingAcceptCompressedTabletEvents = false;
bool testingCompressBrushEvents = false;
bool tabletActive = false; // Indicates whether or not tablet is in proximity
typedef QPair<int, QPointer<QObject> > PriorityPair;
typedef QList<PriorityPair> PriorityList;
......@@ -84,7 +83,6 @@ public:
void allowMouseEvents();
void eatOneMousePress();
void setMaskSyntheticEvents(bool value);
void setTabletActive(bool value);
void resetCompressor();
template <class Event, bool useBlocking>
......@@ -128,6 +126,8 @@ public:
struct EventEater
{
EventEater();
bool eventFilter(QObject* target, QEvent* event);
// This should be called after we're certain a tablet stroke has started.
......@@ -141,6 +141,7 @@ public:
bool hungry{false}; // Continue eating mouse strokes
bool peckish{false}; // Eat a single mouse press event
bool eatSyntheticEvents{false}; // Mask all synthetic events
bool activateSecondaryButtonsWorkaround{false}; // Use mouse events for right- and middle-clicks
};
EventEater eventEater;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment