Skip to content

Commit

Permalink
GLMakie: ignore mouse buttons beyond the first three (#3144)
Browse files Browse the repository at this point in the history
* GLMakie: ignore mouse buttons beyond the first three

Prevents an error message from being thrown. Allowing those buttons to
be used would require additions to mousestatemachine.

* filter out buttons beyond first three inside mouse state machine
  • Loading branch information
jwahlstrand authored Aug 14, 2023
1 parent d551d3c commit f1fb6c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/interaction/iodevices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ module Mouse
middle = 2
right = 1 # Conform to GLFW
none = -1 # for convenience
button_4 = 3
button_5 = 4
button_6 = 5
button_7 = 6
button_8 = 7
end

"""
Expand Down
9 changes: 6 additions & 3 deletions src/makielayout/mousestatemachine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ function addmouseevents!(scene, bbox::Observables.AbstractObservable{<: Rect2};
end


# don't react to buttons beyond the first three
_isstandardmousebutton(b) = (b == Mouse.left || b == Mouse.middle || b == Mouse.right)

function _addmouseevents!(scene, is_mouse_over_relevant_area, priority)
Mouse = Makie.Mouse
dblclick_max_interval = 0.2
Expand Down Expand Up @@ -156,7 +159,7 @@ function _addmouseevents!(scene, is_mouse_over_relevant_area, priority)
# this can mean a new drag started, or a drag continues if it is ongoing.
# it can also mean that a drag that started outside and isn't related to this
# object is going across it and should be ignored here
if last_mouseevent[] == Mouse.press
if last_mouseevent[] == Mouse.press && _isstandardmousebutton(mouse_downed_button[])

if drag_ongoing[]
# continue the drag
Expand Down Expand Up @@ -241,7 +244,7 @@ function _addmouseevents!(scene, is_mouse_over_relevant_area, priority)

# mouse went down, this can either happen inside or outside the objects of interest
# we also only react if one button is pressed, because otherwise things go crazy (pressed left button plus clicks from other buttons in between are not allowed, e.g.)
if event.action == Mouse.press
if event.action == Mouse.press && _isstandardmousebutton(first(pressed_buttons))
if length(pressed_buttons) == 1
button = first(pressed_buttons)
mouse_downed_button[] = button
Expand All @@ -267,7 +270,7 @@ function _addmouseevents!(scene, is_mouse_over_relevant_area, priority)
end
end
last_mouseevent[] = Mouse.press
elseif event.action == Mouse.release
elseif event.action == Mouse.release && _isstandardmousebutton(mouse_downed_button[])
# only register up events and clicks if the upped button matches
# the recorded downed one
# and it can't be nothing (if the first up event comes from outside)
Expand Down

0 comments on commit f1fb6c0

Please sign in to comment.