diff --git a/src/windy/internal.nim b/src/windy/internal.nim index a5fdcb48..3d125239 100644 --- a/src/windy/internal.nim +++ b/src/windy/internal.nim @@ -151,6 +151,11 @@ template handleButtonReleaseTemplate*() = if window.onButtonRelease != nil: window.onButtonRelease(button) +template clearButtonsTemplate*() = + let buttons = window.state.buttonDown + for button in buttons: + window.handleButtonRelease(button) + template handleRuneTemplate*() = if not window.state.runeInputEnabled: return diff --git a/src/windy/platforms/macos/platform.nim b/src/windy/platforms/macos/platform.nim index 1b1557eb..87b7e3e3 100644 --- a/src/windy/platforms/macos/platform.nim +++ b/src/windy/platforms/macos/platform.nim @@ -326,6 +326,7 @@ proc windowDidMove( if window != nil and window.onMove != nil: window.onMove() + proc canBecomeKeyWindow( self: ID, cmd: SEL, @@ -341,6 +342,7 @@ proc windowDidBecomeKey( let window = windows.forNSWindow(self.NSWindow) if window == nil: return + clearButtonsTemplate() if window.onFocusChange != nil: window.onFocusChange() handleMouseMove(window, window.inner.mouseLocationOutsideOfEventStream) @@ -351,7 +353,10 @@ proc windowDidResignKey( notification: NSNotification ): ID {.cdecl.} = let window = windows.forNSWindow(self.NSWindow) - if window != nil and window.onFocusChange != nil: + if window == nil: + return + clearButtonsTemplate() + if window.onFocusChange != nil: window.onFocusChange() # When loosing focus, prev mouse position is not valid. window.state.hasPrevMouse = false diff --git a/src/windy/platforms/win32/platform.nim b/src/windy/platforms/win32/platform.nim index 64359b46..2769dc96 100644 --- a/src/windy/platforms/win32/platform.nim +++ b/src/windy/platforms/win32/platform.nim @@ -253,7 +253,7 @@ proc destroy(window: Window) = window.onButtonRelease = nil window.onRune = nil window.onImeChange = nil - + # Destroy graphics context window.destoryGraphicsContext() @@ -889,6 +889,7 @@ proc wndProc( window.onFrame() return 0 of WM_SETFOCUS, WM_KILLFOCUS: + clearButtonsTemplate() if window.onFocusChange != nil: window.onFocusChange() return 0 @@ -1068,10 +1069,10 @@ when Backend == OpenGLBackend: proc createGraphicsContext( - window: Window, - depthBits: int, + window: Window, + depthBits: int, stencilBits: int, - msaa: MSAA, + msaa: MSAA, vsync: bool, openglVersion: OpenGLVersion ) = @@ -1167,10 +1168,10 @@ elif Backend == DirectXBackend: discard proc createGraphicsContext( - window: Window, - depthBits: int, - stencilBits: int, - msaa: MSAA, + window: Window, + depthBits: int, + stencilBits: int, + msaa: MSAA, vsync: bool, openglVersion: OpenGLVersion ) = @@ -1231,7 +1232,7 @@ proc newWindow*( result.style = style result.visible = visible - + except WindyError as e: destroy result diff --git a/tests/manual_alt_tab.nim b/tests/manual_alt_tab.nim new file mode 100644 index 00000000..f9e0b308 --- /dev/null +++ b/tests/manual_alt_tab.nim @@ -0,0 +1,29 @@ +import opengl, os, windy + +let window = newWindow("Windy Callbacks", ivec2(1280, 800)) +window.runeInputEnabled = true + +window.makeContextCurrent() +loadExtensions() + +window.onFrame = proc() = + glClear(GL_COLOR_BUFFER_BIT) + + # Print if alt is down, when mouse is down: + if window.buttonDown[KeyLeftSuper] or + window.buttonDown[KeyRightSuper] or + window.buttonDown[KeyLeftAlt] or + window.buttonDown[KeyRightAlt] or + window.buttonDown[KeyLeftControl] or + window.buttonDown[KeyRightControl]: + glClearColor(1.0f, 0.0f, 0.0f, 1.0f) + else: + glClearColor(0.0f, 0.0f, 0.0f, 1.0f) + + window.swapBuffers() + +while not window.closeRequested: + + if window.minimized or not window.visible: + sleep(10) + pollEvents()