Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Tapped being triggered after Drag #2248

Merged
merged 4 commits into from May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/driver/glfw/window.go
Expand Up @@ -628,7 +628,7 @@ func (w *window) mouseMoved(viewport *glfw.Window, xpos float64, ypos float64) {
}
}

if mouseButton != 0 && !mouseDragStarted {
if mouseButton != 0 && mouseButton != desktop.MouseButtonSecondary && !mouseDragStarted {
obj, pos, _ := w.findObjectAtPositionMatching(w.canvas, previousPos, func(object fyne.CanvasObject) bool {
_, ok := object.(fyne.Draggable)
return ok
Expand Down Expand Up @@ -687,7 +687,7 @@ func (w *window) mouseMoved(viewport *glfw.Window, xpos float64, ypos float64) {
mouseDraggedOffset := w.mouseDraggedOffset
mouseDragPos := w.mouseDragPos
w.mouseLock.RUnlock()
if mouseDragged != nil && mouseButton > 0 {
if mouseDragged != nil && mouseButton > 0 && mouseButton != desktop.MouseButtonSecondary {
draggedObjDelta := mouseDraggedObjStart.Subtract(mouseDragged.(fyne.CanvasObject).Position())
ev := new(fyne.DragEvent)
ev.AbsolutePosition = mousePos
Expand Down Expand Up @@ -828,7 +828,7 @@ func (w *window) mouseClicked(_ *glfw.Window, btn glfw.MouseButton, action glfw.
}

// Check for double click/tap on left mouse button
if action == glfw.Release && button == desktop.MouseButtonPrimary {
if action == glfw.Release && button == desktop.MouseButtonPrimary && !mouseDragStarted {
w.mouseClickedHandleTapDoubleTap(co, ev)
}
}
Expand Down
49 changes: 49 additions & 0 deletions internal/driver/glfw/window_test.go
Expand Up @@ -325,6 +325,30 @@ func TestWindow_HandleDragging(t *testing.T) {
assert.Nil(t, d1.popDragEvent())
assert.Nil(t, d2.popDragEvent())

// no drag event on secondary mouseDown
w.mouseClicked(w.viewport, glfw.MouseButton2, glfw.Press, 0)
w.WaitForEvents()
assert.Nil(t, d1.popDragEvent())
assert.Nil(t, d2.popDragEvent())

// no drag start and no drag event with pressed secondary mouse button
w.mouseMoved(w.viewport, 8, 8)
w.WaitForEvents()
assert.Nil(t, d1.popDragEvent())
assert.Nil(t, d2.popDragEvent())

// no drag end event on secondary mouseUp
w.mouseClicked(w.viewport, glfw.MouseButton2, glfw.Release, 0)
w.WaitForEvents()
assert.Nil(t, d1.popDragEndEvent())
assert.Nil(t, d2.popDragEndEvent())

// no drag event in simple move
w.mouseMoved(w.viewport, 9, 9)
w.WaitForEvents()
assert.Nil(t, d1.popDragEvent())
assert.Nil(t, d2.popDragEvent())

// no drag event on mouseDown
w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Press, 0)
w.WaitForEvents()
Expand Down Expand Up @@ -575,6 +599,25 @@ func TestWindow_HoverableOnDragging(t *testing.T) {
assert.NotNil(t, dh.popMouseOutEvent())
}

func TestWindow_DragEndWithoutTappedEvent(t *testing.T) {
w := createWindow("Test").(*window)
do := &draggableTappableObject{Rectangle: canvas.NewRectangle(color.White)}
do.SetMinSize(fyne.NewSize(10, 10))
w.SetContent(do)

repaintWindow(w)
require.Equal(t, fyne.NewPos(4, 4), do.Position())

w.mouseMoved(w.viewport, 9, 9)
w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Press, 0)
w.mouseMoved(w.viewport, 8, 8)
w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Release, 0)

w.WaitForEvents()

assert.Nil(t, do.popTapEvent())
}

func TestWindow_Scrolled(t *testing.T) {
w := createWindow("Test").(*window)
o := &scrollable{Rectangle: canvas.NewRectangle(color.White)}
Expand Down Expand Up @@ -1328,6 +1371,12 @@ func (t *tappable) popSecondaryTapEvent() (e interface{}) {
return
}

type draggableTappableObject struct {
*canvas.Rectangle
draggable
tappable
}

var _ fyne.Focusable = (*focusable)(nil)
var _ fyne.Disableable = (*focusable)(nil)

Expand Down