Skip to content

Commit

Permalink
Allow ignoring mouse events for freehand tool
Browse files Browse the repository at this point in the history
An attempted hack around XP Pen problems when it is in relative mode. It
seems to send mouse events first and then doesn't send tablet events
when those are accepted, so this is a hack around that which will ignore
those mouse events altogether when the freehand tool is active to test
that theory. This isn't ideal like this though, since it will also
ignore mouse inputs when using canvas shortcuts and doesn't update the
outline position while the tool is active. It may get reverted or
adjusted further from here.
  • Loading branch information
askmeaboutlo0m committed Dec 15, 2024
1 parent df88cc0 commit 4a5e3c9
Show file tree
Hide file tree
Showing 26 changed files with 77 additions and 32 deletions.
5 changes: 5 additions & 0 deletions src/desktop/dialogs/settingsdialog/tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ void Tablet::initTablet(
settings.bindTabletEvents(pressure);
form->addRow(tr("Pen pressure:"), pressure);

auto *ignoreMouse =
new QCheckBox(tr("Ignore mouse when using freehand tool"));
settings.bindIgnoreMouse(ignoreMouse);
form->addRow(nullptr, ignoreMouse);

auto *smoothing = new KisSliderSpinBox;
smoothing->setMaximum(libclient::settings::maxSmoothing);
smoothing->setPrefix(tr("Global smoothing: "));
Expand Down
1 change: 1 addition & 0 deletions src/desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,7 @@ void MainWindow::toggleTabletEventLog()
DP_event_log_write_meta("Input: %s", tabletinput::current());
const desktop::settings::Settings &settings = dpApp().settings();
DP_event_log_write_meta("Tablet enabled: %d", settings.tabletEvents());
DP_event_log_write_meta("Ignore mouse: %d", settings.ignoreMouse());
DP_event_log_write_meta("Tablet eraser action: %d", settings.tabletEraserAction());
DP_event_log_write_meta("One-finger touch action: %d", settings.oneFingerTouch());
DP_event_log_write_meta("Two-finger pinch action: %d", settings.twoFingerPinch());
Expand Down
10 changes: 6 additions & 4 deletions src/desktop/scene/canvasview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ CanvasView::CanvasView(QWidget *parent)
settings.bindTabletEvents(this, &widgets::CanvasView::setTabletEnabled);
settings.bindTouchGestures(
this, &widgets::CanvasView::setTouchUseGestureEvents);
settings.bindIgnoreMouse(this, &widgets::CanvasView::setIgnoreMouse);
settings.bindRenderSmooth(this, &widgets::CanvasView::setRenderSmooth);
settings.bindRenderUpdateFull(
this, &widgets::CanvasView::setRenderUpdateFull);
Expand Down Expand Up @@ -854,12 +855,13 @@ void CanvasView::setToolCursor(const QCursor &cursor)

void CanvasView::setToolCapabilities(
bool allowColorPick, bool allowToolAdjust, bool toolHandlesRightClick,
bool fractionalTool)
bool fractionalTool, bool toolSupportsPressure)
{
m_allowColorPick = allowColorPick;
m_allowToolAdjust = allowToolAdjust;
m_toolHandlesRightClick = toolHandlesRightClick;
m_fractionalTool = fractionalTool;
m_toolSupportsPressure = toolSupportsPressure;
m_touch->setAllowColorPick(allowColorPick);
}

Expand Down Expand Up @@ -1367,7 +1369,7 @@ void CanvasView::mousePressEvent(QMouseEvent *event)
updateCursorPos(mousePos);

if((m_enableTablet && isSynthetic(event)) || isSyntheticTouch(event) ||
touching || !m_tabletEventTimer.hasExpired()) {
touching || shouldIgnoreMouse() || !m_tabletEventTimer.hasExpired()) {
return;
}

Expand Down Expand Up @@ -1443,7 +1445,7 @@ void CanvasView::mouseMoveEvent(QMouseEvent *event)
updateCursorPos(mousePos);

if((m_enableTablet && isSynthetic(event)) || isSyntheticTouch(event) ||
m_pendown == TABLETDOWN || touching ||
m_pendown == TABLETDOWN || touching || shouldIgnoreMouse() ||
(m_pendown && !m_tabletEventTimer.hasExpired())) {
return;
}
Expand Down Expand Up @@ -1603,7 +1605,7 @@ void CanvasView::mouseReleaseEvent(QMouseEvent *event)
updateCursorPos(mousePos);

if((m_enableTablet && isSynthetic(event)) || isSyntheticTouch(event) ||
touching || !m_tabletEventTimer.hasExpired()) {
touching || shouldIgnoreMouse() || !m_tabletEventTimer.hasExpired()) {
return;
}

Expand Down
10 changes: 9 additions & 1 deletion src/desktop/scene/canvasview.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class CanvasView final : public QGraphicsView {

//! Enable/disable tablet event handling
void setTabletEnabled(bool enable) { m_enableTablet = enable; }
void setIgnoreMouse(bool ignoreMouse) { m_ignoreMouse = ignoreMouse; }

//! Enable/disable touch gestures
void setTouchUseGestureEvents(bool touchUseGestureEvents);
Expand Down Expand Up @@ -228,7 +229,7 @@ public slots:
void setToolCursor(const QCursor &cursor);
void setToolCapabilities(
bool allowColorPick, bool allowToolAdjust, bool toolHandlesRightClick,
bool fractionalTool);
bool fractionalTool, bool toolSupportsPressure);

void setBrushCursorStyle(int style);
void setEraseCursorStyle(int style);
Expand Down Expand Up @@ -360,6 +361,11 @@ private slots:
void showTransformNotice(const QString &text);
void updateLockNotice();

bool shouldIgnoreMouse() const
{
return m_ignoreMouse && m_toolSupportsPressure;
}

Qt::KeyboardModifiers getKeyboardModifiers(const QKeyEvent *keyev) const;
Qt::KeyboardModifiers getMouseModifiers(const QMouseEvent *mouseev) const;
Qt::KeyboardModifiers getTabletModifiers(const QTabletEvent *tabev) const;
Expand Down Expand Up @@ -387,6 +393,7 @@ private slots:
bool m_allowToolAdjust;
bool m_toolHandlesRightClick;
bool m_fractionalTool;
bool m_toolSupportsPressure = false;
PenMode m_penmode;
QDeadlineTimer m_tabletEventTimer;
int m_tabletEventTimerDelay;
Expand Down Expand Up @@ -430,6 +437,7 @@ private slots:

bool m_useGestureEvents = false;
bool m_enableTablet;
bool m_ignoreMouse = false;
bool m_locked;
QString m_lockDescription;
int m_toolState;
Expand Down
7 changes: 4 additions & 3 deletions src/desktop/scene/scenewrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "libclient/tools/toolcontroller.h"
#include <functional>

using std::placeholders::_5;
using std::placeholders::_6;

namespace drawingboard {

Expand Down Expand Up @@ -346,7 +346,7 @@ void SceneWrapper::connectDocument(Document *doc)
connect(
toolCtrl, &tools::ToolController::toolCapabilitiesChanged, m_scene,
std::bind(
&drawingboard::CanvasScene::setSelectionIgnored, m_scene, _5));
&drawingboard::CanvasScene::setSelectionIgnored, m_scene, _6));
m_scene->setSelectionIgnored(toolCtrl->activeToolIgnoresSelections());

connect(
Expand All @@ -361,7 +361,8 @@ void SceneWrapper::connectDocument(Document *doc)
toolCtrl->activeToolAllowColorPick(),
toolCtrl->activeToolAllowToolAdjust(),
toolCtrl->activeToolHandlesRightClick(),
toolCtrl->activeToolIsFractional());
toolCtrl->activeToolIsFractional(),
toolCtrl->activeToolSupportsPressure());

connect(
m_view, &CanvasView::penDown, toolCtrl,
Expand Down
1 change: 1 addition & 0 deletions src/desktop/settings_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ SETTING(fontSize , FontSize , "settings/fontSi
SETTING(globalPressureCurve , GlobalPressureCurve , "settings/input/globalcurve" , GLOBAL_PRESSURE_CURVE_DEFAULT)
SETTING(hostEnableAdvanced , HostEnableAdvanced , "history/hostenableadvanced" , false)
SETTING(ignoreCarrierGradeNat , IgnoreCarrierGradeNat , "history/cgnalert" , false)
SETTING(ignoreMouse , IgnoreMouse , "settings/input/ignoremouse" , false)
SETTING(inputPresets , InputPresets , "inputpresets" , QVector<QVariantMap>())
SETTING(insecurePasswordStorage , InsecurePasswordStorage , "settings/insecurepasswordstorage" , false)
SETTING_GETSET_V(
Expand Down
14 changes: 11 additions & 3 deletions src/desktop/view/canvascontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ CanvasController::CanvasController(CanvasScene *scene, QWidget *parent)
this, &CanvasController::setClearColor);
settings.bindRenderSmooth(this, &CanvasController::setRenderSmooth);
settings.bindTabletEvents(this, &CanvasController::setTabletEnabled);
settings.bindIgnoreMouse(this, &CanvasController::setIgnoreMouse);
settings.bindBrushOutlineWidth(this, &CanvasController::setOutlineWidth);
settings.bindGlobalPressureCurve(
this, &CanvasController::setSerializedPressureCurve);
Expand Down Expand Up @@ -609,6 +610,7 @@ void CanvasController::handleMouseMove(QMouseEvent *event)

if((!m_tabletEnabled || !isSynthetic(event)) && !isSyntheticTouch(event) &&
m_penState != PenState::TabletDown && !touching &&
!shouldIgnoreMouse() &&
(m_penState == PenState::Up || m_tabletEventTimer.hasExpired())) {
if(m_penState != PenState::Up && buttons == Qt::NoButton) {
handleMouseRelease(event);
Expand All @@ -633,7 +635,7 @@ void CanvasController::handleMousePress(QMouseEvent *event)
int(m_penState), int(touching), qulonglong(event->timestamp()));

if(((!m_tabletEnabled || !isSynthetic(event))) &&
!isSyntheticTouch(event) && !touching &&
!isSyntheticTouch(event) && !touching && !shouldIgnoreMouse() &&
m_tabletEventTimer.hasExpired()) {
event->accept();
penPressEvent(
Expand All @@ -655,7 +657,7 @@ void CanvasController::handleMouseRelease(QMouseEvent *event)
int(m_penState), int(touching), qulonglong(event->timestamp()));

if((!m_tabletEnabled || !isSynthetic(event)) && !isSyntheticTouch(event) &&
!touching) {
!touching && !shouldIgnoreMouse()) {
event->accept();
penReleaseEvent(
QDateTime::currentMSecsSinceEpoch(), posf, event->button(),
Expand Down Expand Up @@ -1175,6 +1177,11 @@ void CanvasController::setTabletEnabled(bool tabletEnabled)
m_tabletEnabled = tabletEnabled;
}

void CanvasController::setIgnoreMouse(bool ignoreMouse)
{
m_ignoreMouse = ignoreMouse;
}

void CanvasController::setSerializedPressureCurve(
const QString &serializedPressureCurve)
{
Expand Down Expand Up @@ -1276,12 +1283,13 @@ void CanvasController::setPointerTracking(bool pointerTracking)

void CanvasController::setToolCapabilities(
bool allowColorPick, bool allowToolAdjust, bool toolHandlesRightClick,
bool fractionalTool)
bool fractionalTool, bool toolSupportsPressure)
{
m_allowColorPick = allowColorPick;
m_allowToolAdjust = allowToolAdjust;
m_toolHandlesRightClick = toolHandlesRightClick;
m_fractionalTool = fractionalTool;
m_toolSupportsPressure = toolSupportsPressure;
m_touch->setAllowColorPick(allowColorPick);
}

Expand Down
10 changes: 9 additions & 1 deletion src/desktop/view/canvascontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class CanvasController : public QObject {
void setPointerTracking(bool pointerTracking);
void setToolCapabilities(
bool allowColorPick, bool allowToolAdjust, bool toolHandlesRightClick,
bool fractionalTool);
bool fractionalTool, bool toolSupportsPressure);
void setToolCursor(const QCursor &toolCursor);
void setBrushBlendMode(int brushBlendMode);

Expand Down Expand Up @@ -210,6 +210,7 @@ class CanvasController : public QObject {
void setClearColor(const QColor clearColor);
void setRenderSmooth(bool renderSmooth);
void setTabletEnabled(bool tabletEnabled);
void setIgnoreMouse(bool ignoreMouse);
void setSerializedPressureCurve(const QString &serializedPressureCurve);
void setOutlineWidth(qreal outlineWidth);
void setCanvasShortcuts(QVariantMap canvasShortcuts);
Expand Down Expand Up @@ -266,6 +267,11 @@ class CanvasController : public QObject {
static bool isSynthetic(QMouseEvent *event);
static bool isSyntheticTouch(QMouseEvent *event);

bool shouldIgnoreMouse() const
{
return m_ignoreMouse && m_toolSupportsPressure;
}

Qt::KeyboardModifiers getKeyboardModifiers(const QKeyEvent *event) const;
Qt::KeyboardModifiers getMouseModifiers(const QMouseEvent *event) const;
Qt::KeyboardModifiers getTabletModifiers(const QTabletEvent *event) const;
Expand Down Expand Up @@ -338,6 +344,7 @@ class CanvasController : public QObject {
QColor m_clearColor;
bool m_renderSmooth = false;
bool m_tabletEnabled = true;
bool m_ignoreMouse = false;
KisCubicCurve m_pressureCurve;
bool m_pixelGrid = true;
bool m_pointerTracking = false;
Expand Down Expand Up @@ -387,6 +394,7 @@ class CanvasController : public QObject {
bool m_allowToolAdjust = false;
bool m_toolHandlesRightClick = false;
bool m_fractionalTool = false;
bool m_toolSupportsPressure = false;

#ifdef __EMSCRIPTEN__
bool m_enableEraserOverride = false;
Expand Down
7 changes: 4 additions & 3 deletions src/desktop/view/viewwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "libclient/tools/toolcontroller.h"
#include <functional>

using std::placeholders::_5;
using std::placeholders::_6;

namespace view {

Expand Down Expand Up @@ -333,7 +333,7 @@ void ViewWrapper::connectDocument(Document *doc)
&tools::ToolController::offsetActiveTool);
connect(
toolCtrl, &tools::ToolController::toolCapabilitiesChanged, m_scene,
std::bind(&view::CanvasScene::setSelectionIgnored, m_scene, _5));
std::bind(&view::CanvasScene::setSelectionIgnored, m_scene, _6));
m_scene->setSelectionIgnored(toolCtrl->activeToolIgnoresSelections());

connect(
Expand All @@ -348,7 +348,8 @@ void ViewWrapper::connectDocument(Document *doc)
toolCtrl->activeToolAllowColorPick(),
toolCtrl->activeToolAllowToolAdjust(),
toolCtrl->activeToolHandlesRightClick(),
toolCtrl->activeToolIsFractional());
toolCtrl->activeToolIsFractional(),
toolCtrl->activeToolSupportsPressure());

connect(
m_controller, &CanvasController::penDown, toolCtrl,
Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace tools {
Annotation::Annotation(ToolController &owner)
: Tool(
owner, ANNOTATION, QCursor(QPixmap(":cursors/text.png"), 2, 2), false,
false, true, false, true)
false, true, false, false, true)
, m_selectedId{0}
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/beziertool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using canvas::Point;
static constexpr long long DELTA_MSEC = 10;

BezierTool::BezierTool(ToolController &owner)
: Tool(owner, BEZIER, QCursor(QPixmap(":cursors/curve.png"), 2, 2), true, true, false, true, true)
: Tool(owner, BEZIER, QCursor(QPixmap(":cursors/curve.png"), 2, 2), true, true, false, true, false, true)
, m_brushEngine{}
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/colorpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace tools {
ColorPicker::ColorPicker(ToolController &owner)
: Tool(
owner, PICKER, QCursor(QPixmap(":/cursors/colorpicker.png"), 2, 29),
false, true, false, true, false)
false, true, false, true, false, false)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/floodfill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ FloodFill::FloodFill(ToolController &owner)
: Tool(
owner, FLOODFILL,
QCursor(QPixmap(QStringLiteral(":cursors/bucket.png")), 2, 29), true,
true, false, false, false)
true, false, false, false, false)
, m_kernel(int(DP_FLOOD_FILL_KERNEL_ROUND))
, m_blendMode(DP_BLEND_MODE_NORMAL)
, m_originalBlendMode(m_blendMode)
Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/freehand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace tools {
Freehand::Freehand(ToolController &owner, bool isEraser)
: Tool(
owner, isEraser ? ERASER : FREEHAND, Qt::CrossCursor, true, true,
false, false, true)
false, false, true, true)
, m_pollTimer{}
, m_brushEngine{std::bind(&Freehand::pollControl, this, _1)}
, m_drawing(false)
Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace tools {
Inspector::Inspector(ToolController &owner)
: Tool(
owner, INSPECTOR, QCursor(Qt::WhatsThisCursor), false, false, false,
true, false)
true, false, false)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/laser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace tools {
LaserPointer::LaserPointer(ToolController &owner)
: Tool(
owner, LASERPOINTER, QCursor(QPixmap(":cursors/arrow.png"), 0, 0),
false, true, false, false, false)
false, true, false, false, false, false)
, m_persistence(1)
, m_drawing(false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/magicwand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MagicWandTool::Task final : public ToolController::Task {
MagicWandTool::MagicWandTool(ToolController &owner)
: Tool(
owner, MAGICWAND, QCursor(QPixmap(":cursors/magicwand.png"), 2, 2),
true, false, false, false, false)
true, false, false, false, false, false)
, m_wandCursor(cursor())
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/pan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace tools {
PanTool::PanTool(ToolController &owner)
: Tool(
owner, PAN, QCursor(Qt::OpenHandCursor), true, false, false, true,
false)
false, false)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace tools {

SelectionTool::SelectionTool(ToolController &owner, Type type, QCursor cursor)
: Tool(owner, type, cursor, true, false, false, true, false)
: Tool(owner, type, cursor, true, false, false, true, false, false)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/shapetools.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace tools {
class ShapeTool : public Tool {
public:
ShapeTool(ToolController &owner, Type type, QCursor cursor)
: Tool(owner, type, cursor, true, true, false, true, true)
: Tool(owner, type, cursor, true, true, false, true, false, true)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/libclient/tools/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Tool::setHandlesRightClick(bool handlesRightClick)
if(isActiveTool()) {
emit m_owner.toolCapabilitiesChanged(
m_allowColorPick, m_allowToolAdjust, m_handlesRightClick,
m_fractional, m_ignoresSelections);
m_fractional, m_supportsPressure, m_ignoresSelections);
}
}
}
Expand Down
Loading

0 comments on commit 4a5e3c9

Please sign in to comment.