Skip to content

Commit

Permalink
NSEvent.addLocalMonitorForEventsMatchingMask and `NSApplication.sen…
Browse files Browse the repository at this point in the history
…dAction` (#39)
  • Loading branch information
bung87 authored Oct 14, 2024
1 parent d398048 commit 647babd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions darwin/app_kit.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import app_kit / [nsscreen, nsview, nsevent, nscursor, nspasteboard, nswindow,
nsapplication, nsmenu, nsresponder, nstext, nstextview, nswindowcontroller,
nsdragoperation, nsdragginginfo, nsalert, nsimage, nscell, nscontrol,
nsfont, nstextfield, nscolor, nsimageview, nspanel, nssavepanel,
nsopenpanel, nsbutton]
nsopenpanel, nsbutton, nseventmask]
export foundation, nsscreen, nsview, nsevent, nscursor, nspasteboard, nswindow,
nsapplication, nsmenu, nsresponder, nstext, nstextview, nswindowcontroller,
nsdragoperation, nsdragginginfo, nsalert, nsimage, nscell, nscontrol,
nsfont, nstextfield, nscolor, nsimageview, nspanel, nssavepanel,
nsopenpanel, nsbutton
nsopenpanel, nsbutton, nseventmask

{.passL: "-framework AppKit".}
4 changes: 3 additions & 1 deletion darwin/app_kit/nsapplication.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ proc stopModal*(self: NSApplication) {.objc: "stopModal".}
# Abort a specific modal session
proc abortModal*(self: NSApplication) {.objc: "abortModal".}

proc setDelegate*(s: NSApplication, d: NSObject) {.objc: "setDelegate:".}
proc setDelegate*(s: NSApplication, d: NSObject) {.objc: "setDelegate:".}

proc sendAction*(s: NSApplication, a: SEL, to: ID, `from`: ID): BOOL {.objc: "sendAction:to:from:".}
4 changes: 3 additions & 1 deletion darwin/app_kit/nsevent.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ../objc/runtime
import ../objc/[runtime, blocks]
import ../core_graphics/cggeometry
import ../foundation/[nsgeometry, nsstring, nsdate]
import ./nseventmask

type
NSEvent* = ptr object of NSObject
Expand Down Expand Up @@ -86,3 +87,4 @@ proc mouseEventWithType*(self: typedesc[NSEvent], eventType: NSEventKind, locati
buttonNumber: NSInteger, clickCount: NSInteger, pressure: CGFloat): NSEvent {.objc: "mouseEventWithType:location:modifierFlags:timestamp:windowNumber:buttonNumber:clickCount:pressure:".}

proc charactersIgnoringModifiers*(self: NSEvent): NSString {.objc: "charactersIgnoringModifiers".}
proc addLocalMonitorForEventsMatchingMask*(self: typedesc[NSEvent], mask: NSEventMask, handler: Block[proc (e: NSEvent): NSEvent]):ID {.objc: "addLocalMonitorForEventsMatchingMask:handler:", discardable.}
18 changes: 18 additions & 0 deletions darwin/app_kit/nseventmask.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type
NSEventMask* {.size: sizeof(uint64).} = enum
LeftMouseDown = 1 shl 1,
LeftMouseUp = 1 shl 2,
RightMouseDown = 1 shl 3,
RightMouseUp = 1 shl 4,
MouseMoved = 1 shl 5,
LeftMouseDragged = 1 shl 6,
RightMouseDragged = 1 shl 7,
KeyDown = 1 shl 10,
KeyUp = 1 shl 11,
FlagsChanged = 1 shl 12,
ScrollWheel = 1 shl 22,
TabletPoint = 1 shl 23,
TabletProximity = 1 shl 24,
OtherMouseDown = 1 shl 25,
OtherMouseUp = 1 shl 26,
OtherMouseDragged = 1 shl 27

0 comments on commit 647babd

Please sign in to comment.