Skip to content

Commit

Permalink
Merge pull request #56 from guzba/master
Browse files Browse the repository at this point in the history
better
  • Loading branch information
treeform authored Jan 19, 2022
2 parents 93ffdf1 + 0938806 commit e57b819
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
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

0 comments on commit e57b819

Please sign in to comment.