From 9d73e45677b5dce6298da5755763b1b960ee3887 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 17 Sep 2023 15:43:38 +0900 Subject: [PATCH] Revert "internal/ui: bug fix: preserve cursor positions for toggling fullscreening for desktops" This reverts commit 7ed4db90be0dde428c44f041fe027b47a1652d3a. Reason: compile error on Windows --- internal/glfw/glfw_cglfw.go | 10 +++------- internal/glfw/glfw_goglfw.go | 19 ++++++------------- internal/ui/input_glfw.go | 32 +++++--------------------------- internal/ui/ui_glfw.go | 13 ++----------- 4 files changed, 16 insertions(+), 58 deletions(-) diff --git a/internal/glfw/glfw_cglfw.go b/internal/glfw/glfw_cglfw.go index 8c5d93ba8..ded09ab86 100644 --- a/internal/glfw/glfw_cglfw.go +++ b/internal/glfw/glfw_cglfw.go @@ -178,11 +178,6 @@ func (w *Window) SetCharModsCallback(cbfun CharModsCallback) (previous CharModsC return ToCharModsCallback(nil) // TODO } -func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback) { - w.w.SetCloseCallback(cbfun) - return ToCloseCallback(nil) // TODO -} - func (w *Window) SetCursor(cursor *Cursor) { var c *cglfw.Cursor if cursor != nil { @@ -191,8 +186,9 @@ func (w *Window) SetCursor(cursor *Cursor) { w.w.SetCursor(c) } -func (w *Window) SetCursorPos(xpos, ypos float64) { - w.w.SetCursorPos(xpos, ypos) +func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback) { + w.w.SetCloseCallback(cbfun) + return ToCloseCallback(nil) // TODO } func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback) { diff --git a/internal/glfw/glfw_goglfw.go b/internal/glfw/glfw_goglfw.go index 1cfee23d7..076237b54 100644 --- a/internal/glfw/glfw_goglfw.go +++ b/internal/glfw/glfw_goglfw.go @@ -194,19 +194,6 @@ func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback) return f } -func (w *Window) SetCursor(cursor *Cursor) { - if err := (*goglfw.Window)(w).SetCursor((*goglfw.Cursor)(cursor)); err != nil { - panic(err) - } -} - -func (w *Window) SetCursorPos(xpos, ypos float64) { - if err := (*goglfw.Window)(w).SetCursorPos(xpos, ypos); err != nil { - panic(err) - } - return x, y -} - func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback) { f, err := (*goglfw.Window)(w).SetDropCallback(cbfun) if err != nil { @@ -215,6 +202,12 @@ func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback) { return f } +func (w *Window) SetCursor(cursor *Cursor) { + if err := (*goglfw.Window)(w).SetCursor((*goglfw.Cursor)(cursor)); err != nil { + panic(err) + } +} + func (w *Window) SetFramebufferSizeCallback(cbfun FramebufferSizeCallback) (previous FramebufferSizeCallback) { f, err := (*goglfw.Window)(w).SetFramebufferSizeCallback(cbfun) if err != nil { diff --git a/internal/ui/input_glfw.go b/internal/ui/input_glfw.go index 88caccc02..256dd23ca 100644 --- a/internal/ui/input_glfw.go +++ b/internal/ui/input_glfw.go @@ -66,27 +66,13 @@ func (u *userInterfaceImpl) updateInputStateImpl() error { for gb, ub := range glfwMouseButtonToMouseButton { u.inputState.MouseButtonPressed[ub] = u.window.GetMouseButton(gb) == glfw.Press } - + cx, cy := u.window.GetCursorPos() + // TODO: This is tricky. Rename the function? m := u.currentMonitor() s := u.deviceScaleFactor(m) - - cx, cy := u.savedCursorX, u.savedCursorY - defer func() { - u.savedCursorX = math.NaN() - u.savedCursorY = math.NaN() - }() - - if !math.IsNaN(cx) && !math.IsNaN(cy) { - cx2, cy2 := u.context.logicalPositionToClientPosition(cx, cy, s) - cx2 = u.dipToGLFWPixel(cx2, m) - cy2 = u.dipToGLFWPixel(cy2, m) - u.window.SetCursorPos(cx2, cy2) - } else { - cx2, cy2 := u.window.GetCursorPos() - cx2 = u.dipFromGLFWPixel(cx2, m) - cy2 = u.dipFromGLFWPixel(cy2, m) - cx, cy = u.context.clientPositionToLogicalPosition(cx2, cy2, s) - } + cx = u.dipFromGLFWPixel(cx, m) + cy = u.dipFromGLFWPixel(cy, m) + cx, cy = u.context.clientPositionToLogicalPosition(cx, cy, s) // AdjustPosition can return NaN at the initialization. if !math.IsNaN(cx) && !math.IsNaN(cy) { @@ -122,11 +108,3 @@ func (u *userInterfaceImpl) keyName(key Key) string { }) return name } - -func (u *userInterfaceImpl) saveCursorPosition() { - u.m.Lock() - defer u.m.Unlock() - - u.savedCursorX = u.inputState.CursorX - u.savedCursorY = u.inputState.CursorY -} diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index d089ff9a7..f68371b2a 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "image" - "math" "os" "runtime" "sync" @@ -105,10 +104,8 @@ type userInterfaceImpl struct { fpsModeInited bool - inputState InputState - iwindow glfwWindow - savedCursorX float64 - savedCursorY float64 + inputState InputState + iwindow glfwWindow sizeCallback glfw.SizeCallback closeCallback glfw.CloseCallback @@ -148,8 +145,6 @@ func init() { fpsMode: FPSModeVsyncOn, origWindowPosX: invalidPos, origWindowPosY: invalidPos, - savedCursorX: math.NaN(), - savedCursorY: math.NaN(), } theUI.iwindow.ui = &theUI.userInterfaceImpl } @@ -1408,10 +1403,6 @@ func (u *userInterfaceImpl) setFullscreen(fullscreen bool) { return } - if u.window.GetInputMode(glfw.CursorMode) == glfw.CursorDisabled { - u.saveCursorPosition() - } - // Enter the fullscreen. if fullscreen { u.disableWindowSizeLimits()