From 89eea0921db94fddbd1b8c20102be9350e2ec1c3 Mon Sep 17 00:00:00 2001 From: nikitar020 <42252263+nikitar020@users.noreply.github.com> Date: Fri, 11 Jan 2019 01:58:30 +0700 Subject: [PATCH] Bug: mouse cursors leaks (#136) --- gui/gui.go | 2 ++ gui/mouse.go | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gui/gui.go b/gui/gui.go index 9debe84..995dded 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -36,6 +36,8 @@ type GUI struct { showDebugInfo bool keyboardShortcuts map[config.UserAction]*config.KeyCombination resizeLock *sync.Mutex + handCursor *glfw.Cursor + arrowCursor *glfw.Cursor } func Min(x, y int) int { diff --git a/gui/mouse.go b/gui/mouse.go index 4996781..dcd4e1b 100644 --- a/gui/mouse.go +++ b/gui/mouse.go @@ -17,6 +17,22 @@ func (gui *GUI) glfwScrollCallback(w *glfw.Window, xoff float64, yoff float64) { } } +func (gui *GUI) getHandCursor() *glfw.Cursor { + if gui.handCursor == nil { + gui.handCursor = glfw.CreateStandardCursor(glfw.HandCursor) + } + + return gui.handCursor +} + +func (gui *GUI) getArrowCursor() *glfw.Cursor { + if gui.arrowCursor == nil { + gui.arrowCursor = glfw.CreateStandardCursor(glfw.ArrowCursor) + } + + return gui.arrowCursor +} + func (gui *GUI) mouseMoveCallback(w *glfw.Window, px float64, py float64) { scale := gui.scale() @@ -40,9 +56,9 @@ func (gui *GUI) mouseMoveCallback(w *glfw.Window, px float64, py float64) { } if url := gui.terminal.ActiveBuffer().GetURLAtPosition(x, y); url != "" { - w.SetCursor(glfw.CreateStandardCursor(glfw.HandCursor)) + w.SetCursor(gui.getHandCursor()) } else { - w.SetCursor(glfw.CreateStandardCursor(glfw.ArrowCursor)) + w.SetCursor(gui.getArrowCursor()) } }