Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better #56

Merged
merged 2 commits into from
Jan 19, 2022
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
9 changes: 9 additions & 0 deletions src/windy/platforms/macos/macdefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type
NSImage* = distinct NSObject
NSCursor* = distinct NSObject
NSTextInputContext* = distinct NSObject
NSTextInputClient* = distinct int

const
NSNotFound* = int.high
Expand Down Expand Up @@ -935,4 +936,12 @@ proc activate*(context: NSTextInputContext) =
s"activate",
)

proc insertText2*(client: NSTextInputClient, obj: ID, range: NSRange) =
discard objc_msgSend(
client.ID,
s"insertText:replacementRange:",
obj,
range
)

{.pop.}
10 changes: 4 additions & 6 deletions src/windy/platforms/macos/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ proc closeIme*(window: Window) =
return

if window.markedText.int != 0:
discard objc_msgSend(
window.inner.contentView.ID,
s"insertText:replacementRange:",
window.inner.contentView.NSTextInputClient.insertText2(
window.markedText.ID,
kEmptyRange
)
Expand Down Expand Up @@ -353,11 +351,11 @@ proc mouseMoved(self: ID, cmd: SEL, event: NSEvent): ID {.cdecl.} =

let
locationInWindow = event.locationInWindow
x = round(locationInWindow.x).int32
y = round(self.NSView.bounds.size.height - locationInWindow.y).int32
x = round(locationInWindow.x)
y = round(self.NSView.bounds.size.height - locationInWindow.y)

window.state.mousePrevPos = window.state.mousePos
window.state.mousePos = ivec2(x, y)
window.state.mousePos = (vec2(x, y) * window.contentScale).ivec2
window.state.perFrame.mouseDelta +=
window.state.mousePos - window.state.mousePrevPos

Expand Down