Skip to content

Commit

Permalink
Make MouseInputEvent only consider one pressed button - discard any B…
Browse files Browse the repository at this point in the history
…UTTON_PRESS while the first button is not released
  • Loading branch information
bhennion committed Oct 8, 2023
1 parent eea49ce commit 13b7f4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/core/gui/inputdevices/MouseInputHandler.cpp
Expand Up @@ -34,7 +34,12 @@ auto MouseInputHandler::handleImpl(InputEvent const& event) -> bool {
*/
// Trigger start of action when pen/mouse is pressed
if (event.type == BUTTON_PRESS_EVENT) {
this->actionStart(event);
if (pressedButton == BUTTON_NONE || !inputRunning) {
pressedButton = event.button;
this->actionStart(event);
} else if (event.button == pressedButton) {
g_warning("MouseInputHandler: Double BUTTON_PRESS_EVENT on button %u", event.button);
}
return true;
}

Expand Down Expand Up @@ -67,13 +72,17 @@ auto MouseInputHandler::handleImpl(InputEvent const& event) -> bool {

// Trigger end of action if mouse button is released
if (event.type == BUTTON_RELEASE_EVENT) {
this->actionEnd(event);
if (event.button == pressedButton) {
pressedButton = BUTTON_NONE;
this->actionEnd(event);
}
return true;
}

// If we loose our Grab on the device end the current action
if (event.type == GRAB_BROKEN_EVENT && this->deviceClassPressed) {
// TODO(fabian): We may need to update pressed state manually here
pressedButton = BUTTON_NONE;
this->actionEnd(event);
return true;
}
Expand Down
7 changes: 7 additions & 0 deletions src/core/gui/inputdevices/MouseInputHandler.h
Expand Up @@ -11,6 +11,8 @@

#pragma once

#include <glib.h> // for guint

#include "PenInputHandler.h" // for PenInputHandler

class InputContext;
Expand Down Expand Up @@ -41,4 +43,9 @@ class MouseInputHandler: public PenInputHandler {
*/
bool changeTool(InputEvent const& event) override;
void onBlock() override;

private:
// see button member in https://docs.gtk.org/gdk3/struct.EventButton.html
static constexpr guint BUTTON_NONE = 0;
guint pressedButton = BUTTON_NONE;
};

0 comments on commit 13b7f4c

Please sign in to comment.