From 1d30e6b6e8063564d86e2de5eb15b03ba514b66b Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Mon, 17 May 2021 16:31:47 +0100 Subject: [PATCH 1/4] Fixed: Tapped being triggered after Drag --- internal/driver/glfw/window.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/driver/glfw/window.go b/internal/driver/glfw/window.go index 45151a8749..0c61b955d6 100644 --- a/internal/driver/glfw/window.go +++ b/internal/driver/glfw/window.go @@ -820,7 +820,7 @@ func (w *window) mouseClicked(_ *glfw.Window, btn glfw.MouseButton, action glfw. w.mouseLock.Unlock() } else if action == glfw.Release { if co == mousePressed { - if button == desktop.MouseButtonSecondary && altTap { + if button == desktop.MouseButtonSecondary && altTap && !mouseDragStarted { w.QueueEvent(func() { co.(fyne.SecondaryTappable).TappedSecondary(ev) }) } } @@ -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) } } From 91b82749d80b7811fcca31f65105013f9ecac977 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 19 May 2021 18:09:50 +0100 Subject: [PATCH 2/4] Prevent dragging with secondary mouse button --- internal/driver/glfw/window.go | 4 ++-- internal/driver/glfw/window_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/internal/driver/glfw/window.go b/internal/driver/glfw/window.go index 0c61b955d6..c40b2a679e 100644 --- a/internal/driver/glfw/window.go +++ b/internal/driver/glfw/window.go @@ -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 @@ -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 diff --git a/internal/driver/glfw/window_test.go b/internal/driver/glfw/window_test.go index 9b267e0ff5..c42c8548be 100644 --- a/internal/driver/glfw/window_test.go +++ b/internal/driver/glfw/window_test.go @@ -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() From 1b2fb10dcc4002def2f37a1d81043b0819f628c9 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 19 May 2021 18:31:13 +0100 Subject: [PATCH 3/4] Added Test: TestWindow_DragEndWithoutTappedEvent --- internal/driver/glfw/window_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/internal/driver/glfw/window_test.go b/internal/driver/glfw/window_test.go index c42c8548be..4c4f10affb 100644 --- a/internal/driver/glfw/window_test.go +++ b/internal/driver/glfw/window_test.go @@ -599,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)} @@ -1352,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) From 9ce2455814c59115db484e4c7e37ae21ceee67d1 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 19 May 2021 18:35:58 +0100 Subject: [PATCH 4/4] Removed an unnecessary condition: !mouseDragStarted is always true if button == desktop.MouseButtonSecondary --- internal/driver/glfw/window.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/driver/glfw/window.go b/internal/driver/glfw/window.go index c40b2a679e..4460840fe8 100644 --- a/internal/driver/glfw/window.go +++ b/internal/driver/glfw/window.go @@ -820,7 +820,7 @@ func (w *window) mouseClicked(_ *glfw.Window, btn glfw.MouseButton, action glfw. w.mouseLock.Unlock() } else if action == glfw.Release { if co == mousePressed { - if button == desktop.MouseButtonSecondary && altTap && !mouseDragStarted { + if button == desktop.MouseButtonSecondary && altTap { w.QueueEvent(func() { co.(fyne.SecondaryTappable).TappedSecondary(ev) }) } }