Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/windy/internal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/windy/platforms/macos/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ proc windowDidMove(
if window != nil and window.onMove != nil:
window.onMove()


proc canBecomeKeyWindow(
self: ID,
cmd: SEL,
Expand All @@ -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)
Expand All @@ -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
Expand Down
19 changes: 10 additions & 9 deletions src/windy/platforms/win32/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ proc destroy(window: Window) =
window.onButtonRelease = nil
window.onRune = nil
window.onImeChange = nil

# Destroy graphics context
window.destoryGraphicsContext()

Expand Down Expand Up @@ -889,6 +889,7 @@ proc wndProc(
window.onFrame()
return 0
of WM_SETFOCUS, WM_KILLFOCUS:
clearButtonsTemplate()
if window.onFocusChange != nil:
window.onFocusChange()
return 0
Expand Down Expand Up @@ -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
) =
Expand Down Expand Up @@ -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
) =
Expand Down Expand Up @@ -1231,7 +1232,7 @@ proc newWindow*(

result.style = style
result.visible = visible


except WindyError as e:
destroy result
Expand Down
29 changes: 29 additions & 0 deletions tests/manual_alt_tab.nim
Original file line number Diff line number Diff line change
@@ -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()