NSEvent.odin 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. package objc_Foundation
  2. @(objc_class="NSEvent")
  3. Event :: struct {using _: Object}
  4. EventMask :: distinct bit_set[EventType; UInteger]
  5. EventMaskAny :: transmute(EventMask)(max(UInteger))
  6. when size_of(UInteger) == 4 {
  7. // We don't support a 32-bit darwin system but this is mostly to shut up the type checker for the time being
  8. EventType :: enum UInteger {
  9. LeftMouseDown = 1,
  10. LeftMouseUp = 2,
  11. RightMouseDown = 3,
  12. RightMouseUp = 4,
  13. MouseMoved = 5,
  14. LeftMouseDragged = 6,
  15. RightMouseDragged = 7,
  16. MouseEntered = 8,
  17. MouseExited = 9,
  18. KeyDown = 10,
  19. KeyUp = 11,
  20. FlagsChanged = 12,
  21. AppKitDefined = 13,
  22. SystemDefined = 14,
  23. ApplicationDefined = 15,
  24. Periodic = 16,
  25. CursorUpdate = 17,
  26. Rotate = 18,
  27. BeginGesture = 19,
  28. EndGesture = 20,
  29. ScrollWheel = 22,
  30. TabletPoint = 23,
  31. TabletProximity = 24,
  32. OtherMouseDown = 25,
  33. OtherMouseUp = 26,
  34. OtherMouseDragged = 27,
  35. Gesture = 29,
  36. Magnify = 30,
  37. Swipe = 31,
  38. }
  39. } else {
  40. EventType :: enum UInteger {
  41. LeftMouseDown = 1,
  42. LeftMouseUp = 2,
  43. RightMouseDown = 3,
  44. RightMouseUp = 4,
  45. MouseMoved = 5,
  46. LeftMouseDragged = 6,
  47. RightMouseDragged = 7,
  48. MouseEntered = 8,
  49. MouseExited = 9,
  50. KeyDown = 10,
  51. KeyUp = 11,
  52. FlagsChanged = 12,
  53. AppKitDefined = 13,
  54. SystemDefined = 14,
  55. ApplicationDefined = 15,
  56. Periodic = 16,
  57. CursorUpdate = 17,
  58. Rotate = 18,
  59. BeginGesture = 19,
  60. EndGesture = 20,
  61. ScrollWheel = 22,
  62. TabletPoint = 23,
  63. TabletProximity = 24,
  64. OtherMouseDown = 25,
  65. OtherMouseUp = 26,
  66. OtherMouseDragged = 27,
  67. Gesture = 29,
  68. Magnify = 30,
  69. Swipe = 31,
  70. SmartMagnify = 32,
  71. QuickLook = 33,
  72. Pressure = 34,
  73. DirectTouch = 37,
  74. ChangeMode = 38,
  75. }
  76. }
  77. EventPhase :: distinct bit_set[EventPhaseFlag; UInteger]
  78. EventPhaseFlag :: enum UInteger {
  79. Began = 0,
  80. Stationary = 1,
  81. Changed = 2,
  82. Ended = 3,
  83. Cancelled = 4,
  84. MayBegin = 5,
  85. }
  86. EventPhaseNone :: EventPhase{}
  87. EventPhaseBegan :: EventPhase{.Began}
  88. EventPhaseStationary :: EventPhase{.Stationary}
  89. EventPhaseChanged :: EventPhase{.Changed}
  90. EventPhaseEnded :: EventPhase{.Ended}
  91. EventPhaseCancelled :: EventPhase{.Cancelled}
  92. EventPhaseMayBegin :: EventPhase{.MayBegin}
  93. /* pointer types for NSTabletProximity events or mouse events with subtype NSTabletProximityEventSubtype*/
  94. PointingDeviceType :: enum UInteger {
  95. Unknown = 0,
  96. Pen = 1,
  97. Cursor = 2,
  98. Eraser = 3,
  99. }
  100. EventModifierFlag :: enum UInteger {
  101. CapsLock = 16,
  102. Shift = 17,
  103. Control = 18,
  104. Option = 19,
  105. Command = 20,
  106. NumericPad = 21,
  107. Help = 22,
  108. Function = 23,
  109. }
  110. EventModifierFlags :: distinct bit_set[EventModifierFlag; UInteger]
  111. EventModifierFlagCapsLock :: EventModifierFlags{.CapsLock}
  112. EventModifierFlagShift :: EventModifierFlags{.Shift}
  113. EventModifierFlagControl :: EventModifierFlags{.Control}
  114. EventModifierFlagOption :: EventModifierFlags{.Option}
  115. EventModifierFlagCommand :: EventModifierFlags{.Command}
  116. EventModifierFlagNumericPad :: EventModifierFlags{.NumericPad}
  117. EventModifierFlagHelp :: EventModifierFlags{.Help}
  118. EventModifierFlagFunction :: EventModifierFlags{.Function}
  119. EventModifierFlagDeviceIndependentFlagsMask : UInteger : 0xffff0000
  120. // Defined in Carbon.framework Events.h
  121. kVK :: enum {
  122. ANSI_A = 0x00,
  123. ANSI_S = 0x01,
  124. ANSI_D = 0x02,
  125. ANSI_F = 0x03,
  126. ANSI_H = 0x04,
  127. ANSI_G = 0x05,
  128. ANSI_Z = 0x06,
  129. ANSI_X = 0x07,
  130. ANSI_C = 0x08,
  131. ANSI_V = 0x09,
  132. ANSI_B = 0x0B,
  133. ANSI_Q = 0x0C,
  134. ANSI_W = 0x0D,
  135. ANSI_E = 0x0E,
  136. ANSI_R = 0x0F,
  137. ANSI_Y = 0x10,
  138. ANSI_T = 0x11,
  139. ANSI_1 = 0x12,
  140. ANSI_2 = 0x13,
  141. ANSI_3 = 0x14,
  142. ANSI_4 = 0x15,
  143. ANSI_6 = 0x16,
  144. ANSI_5 = 0x17,
  145. ANSI_Equal = 0x18,
  146. ANSI_9 = 0x19,
  147. ANSI_7 = 0x1A,
  148. ANSI_Minus = 0x1B,
  149. ANSI_8 = 0x1C,
  150. ANSI_0 = 0x1D,
  151. ANSI_RightBracket = 0x1E,
  152. ANSI_O = 0x1F,
  153. ANSI_U = 0x20,
  154. ANSI_LeftBracket = 0x21,
  155. ANSI_I = 0x22,
  156. ANSI_P = 0x23,
  157. ANSI_L = 0x25,
  158. ANSI_J = 0x26,
  159. ANSI_Quote = 0x27,
  160. ANSI_K = 0x28,
  161. ANSI_Semicolon = 0x29,
  162. ANSI_Backslash = 0x2A,
  163. ANSI_Comma = 0x2B,
  164. ANSI_Slash = 0x2C,
  165. ANSI_N = 0x2D,
  166. ANSI_M = 0x2E,
  167. ANSI_Period = 0x2F,
  168. ANSI_Grave = 0x32,
  169. ANSI_KeypadDecimal = 0x41,
  170. ANSI_KeypadMultiply = 0x43,
  171. ANSI_KeypadPlus = 0x45,
  172. ANSI_KeypadClear = 0x47,
  173. ANSI_KeypadDivide = 0x4B,
  174. ANSI_KeypadEnter = 0x4C,
  175. ANSI_KeypadMinus = 0x4E,
  176. ANSI_KeypadEquals = 0x51,
  177. ANSI_Keypad0 = 0x52,
  178. ANSI_Keypad1 = 0x53,
  179. ANSI_Keypad2 = 0x54,
  180. ANSI_Keypad3 = 0x55,
  181. ANSI_Keypad4 = 0x56,
  182. ANSI_Keypad5 = 0x57,
  183. ANSI_Keypad6 = 0x58,
  184. ANSI_Keypad7 = 0x59,
  185. ANSI_Keypad8 = 0x5B,
  186. ANSI_Keypad9 = 0x5C,
  187. Return = 0x24,
  188. Tab = 0x30,
  189. Space = 0x31,
  190. Delete = 0x33,
  191. Escape = 0x35,
  192. Command = 0x37,
  193. Shift = 0x38,
  194. CapsLock = 0x39,
  195. Option = 0x3A,
  196. Control = 0x3B,
  197. RightCommand = 0x36,
  198. RightShift = 0x3C,
  199. RightOption = 0x3D,
  200. RightControl = 0x3E,
  201. Function = 0x3F,
  202. F17 = 0x40,
  203. VolumeUp = 0x48,
  204. VolumeDown = 0x49,
  205. Mute = 0x4A,
  206. F18 = 0x4F,
  207. F19 = 0x50,
  208. F20 = 0x5A,
  209. F5 = 0x60,
  210. F6 = 0x61,
  211. F7 = 0x62,
  212. F3 = 0x63,
  213. F8 = 0x64,
  214. F9 = 0x65,
  215. F11 = 0x67,
  216. F13 = 0x69,
  217. F16 = 0x6A,
  218. F14 = 0x6B,
  219. F10 = 0x6D,
  220. F12 = 0x6F,
  221. F15 = 0x71,
  222. Help = 0x72,
  223. Home = 0x73,
  224. PageUp = 0x74,
  225. ForwardDelete = 0x75,
  226. F4 = 0x76,
  227. End = 0x77,
  228. F2 = 0x78,
  229. PageDown = 0x79,
  230. F1 = 0x7A,
  231. LeftArrow = 0x7B,
  232. RightArrow = 0x7C,
  233. DownArrow = 0x7D,
  234. UpArrow = 0x7E,
  235. JIS_Yen = 0x5D,
  236. JIS_Underscore = 0x5E,
  237. JIS_KeypadComma = 0x5F,
  238. JIS_Eisu = 0x66,
  239. JIS_Kana = 0x68,
  240. ISO_Section = 0x0A,
  241. }
  242. /* these messages are valid for all events */
  243. @(objc_type=Event, objc_name="type")
  244. Event_type :: proc "c" (self: ^Event) -> EventType {
  245. return msgSend(EventType, self, "type")
  246. }
  247. @(objc_type=Event, objc_name="modifierFlags")
  248. Event_modifierFlags :: proc "c" (self: ^Event) -> EventModifierFlags {
  249. return msgSend(EventModifierFlags, self, "modifierFlags")
  250. }
  251. @(objc_type=Event, objc_name="timestamp")
  252. Event_timestamp :: proc "c" (self: ^Event) -> TimeInterval {
  253. return msgSend(TimeInterval, self, "timestamp")
  254. }
  255. @(objc_type=Event, objc_name="window")
  256. Event_window :: proc "c" (self: ^Event) -> ^Window {
  257. return msgSend(^Window, self, "window")
  258. }
  259. @(objc_type=Event, objc_name="windowNumber")
  260. Event_windowNumber :: proc "c" (self: ^Event) -> UInteger {
  261. return msgSend(UInteger, self, "windowNumber")
  262. }
  263. /* these messages are valid for all mouse down/up/drag events */
  264. @(objc_type=Event, objc_name="clickCount")
  265. Event_clickCount :: proc "c" (self: ^Event) -> Integer {
  266. return msgSend(Integer, self, "clickCount")
  267. }
  268. // for NSOtherMouse events, but will return valid constants for NSLeftMouse and NSRightMouse
  269. @(objc_type=Event, objc_name="buttonNumber")
  270. Event_buttonNumber :: proc "c" (self: ^Event) -> Integer {
  271. return msgSend(Integer, self, "buttonNumber")
  272. }
  273. /* these messages are valid for all mouse down/up/drag and enter/exit events */
  274. @(objc_type=Event, objc_name="eventNumber")
  275. Event_eventNumber :: proc "c" (self: ^Event) -> Integer {
  276. return msgSend(Integer, self, "eventNumber")
  277. }
  278. /* -pressure is valid for all mouse down/up/drag events, and is also valid for NSTabletPoint events on 10.4 or later */
  279. @(objc_type=Event, objc_name="pressure")
  280. Event_pressure :: proc "c" (self: ^Event) -> f32 {
  281. return msgSend(f32, self, "pressure")
  282. }
  283. /* -locationInWindow is valid for all mouse-related events */
  284. @(objc_type=Event, objc_name="locationInWindow")
  285. Event_locationInWindow :: proc "c" (self: ^Event) -> Point {
  286. return msgSend(Point, self, "locationInWindow")
  287. }
  288. @(objc_type=Event, objc_name="deltaX")
  289. Event_deltaX :: proc "c" (self: ^Event) -> Float {
  290. return msgSend(Float, self, "deltaX")
  291. }
  292. @(objc_type=Event, objc_name="deltaY")
  293. Event_deltaY :: proc "c" (self: ^Event) -> Float {
  294. return msgSend(Float, self, "deltaY")
  295. }
  296. @(objc_type=Event, objc_name="deltaZ")
  297. Event_deltaZ :: proc "c" (self: ^Event) -> Float {
  298. return msgSend(Float, self, "deltaZ")
  299. }
  300. @(objc_type=Event, objc_name="delta")
  301. Event_delta :: proc "c" (self: ^Event) -> (x, y, z: Float) {
  302. x = self->deltaX()
  303. y = self->deltaY()
  304. z = self->deltaZ()
  305. return
  306. }
  307. @(objc_type=Event, objc_name="hasPreciseScrollingDeltas")
  308. Event_hasPreciseScrollingDeltas :: proc "c" (self: ^Event) -> BOOL {
  309. return msgSend(BOOL, self, "hasPreciseScrollingDeltas")
  310. }
  311. @(objc_type=Event, objc_name="scrollingDeltaX")
  312. Event_scrollingDeltaX :: proc "c" (self: ^Event) -> Float {
  313. return msgSend(Float, self, "scrollingDeltaX")
  314. }
  315. @(objc_type=Event, objc_name="scrollingDeltaY")
  316. Event_scrollingDeltaY :: proc "c" (self: ^Event) -> Float {
  317. return msgSend(Float, self, "scrollingDeltaY")
  318. }
  319. @(objc_type=Event, objc_name="scrollingDelta")
  320. Event_scrollingDelta :: proc "c" (self: ^Event) -> (x, y: Float) {
  321. x = self->scrollingDeltaX()
  322. y = self->scrollingDeltaY()
  323. return
  324. }
  325. @(objc_type=Event, objc_name="momentumPhase")
  326. Event_momentumPhase :: proc "c" (self: ^Event) -> EventPhase {
  327. return msgSend(EventPhase, self, "momentumPhase")
  328. }
  329. @(objc_type=Event, objc_name="phase")
  330. Event_phase :: proc "c" (self: ^Event) -> EventPhase {
  331. return msgSend(EventPhase, self, "phase")
  332. }
  333. @(objc_type=Event, objc_name="isDirectionInvertedFromDevice")
  334. Event_isDirectionInvertedFromDevice :: proc "c" (self: ^Event) -> BOOL {
  335. return msgSend(BOOL, self, "isDirectionInvertedFromDevice")
  336. }
  337. @(objc_type=Event, objc_name="characters")
  338. Event_characters :: proc "c" (self: ^Event) -> ^String {
  339. return msgSend(^String, self, "characters")
  340. }
  341. @(objc_type=Event, objc_name="charactersIgnoringModifiers")
  342. Event_charactersIgnoringModifiers :: proc "c" (self: ^Event) -> ^String {
  343. return msgSend(^String, self, "charactersIgnoringModifiers")
  344. }
  345. @(objc_type=Event, objc_name="isARepeat")
  346. Event_isARepeat :: proc "c" (self: ^Event) -> BOOL {
  347. return msgSend(BOOL, self, "isARepeat")
  348. }
  349. @(objc_type=Event, objc_name="keyCode")
  350. Event_keyCode :: proc "c" (self: ^Event) -> u16 {
  351. return msgSend(u16, self, "keyCode")
  352. }
  353. @(objc_type=Event, objc_name="subtype")
  354. Event_subtype :: proc "c" (self: ^Event) -> i16 {
  355. return msgSend(i16, self, "subtype")
  356. }
  357. @(objc_type=Event, objc_name="data1")
  358. Event_data1 :: proc "c" (self: ^Event) -> Integer {
  359. return msgSend(Integer, self, "data1")
  360. }
  361. @(objc_type=Event, objc_name="data2")
  362. Event_data2 :: proc "c" (self: ^Event) -> Integer {
  363. return msgSend(Integer, self, "data2")
  364. }
  365. @(objc_type=Event, objc_name="absoluteX")
  366. Event_absoluteX :: proc "c" (self: ^Event) -> Integer {
  367. return msgSend(Integer, self, "absoluteX")
  368. }
  369. @(objc_type=Event, objc_name="absoluteY")
  370. Event_absoluteY :: proc "c" (self: ^Event) -> Integer {
  371. return msgSend(Integer, self, "absoluteY")
  372. }
  373. @(objc_type=Event, objc_name="absoluteZ")
  374. Event_absoluteZ :: proc "c" (self: ^Event) -> Integer {
  375. return msgSend(Integer, self, "absoluteZ")
  376. }
  377. @(objc_type=Event, objc_name="absolute")
  378. Event_absolute :: proc "c" (self: ^Event) -> (x, y, z: Integer) {
  379. x = self->absoluteX()
  380. y = self->absoluteY()
  381. z = self->absoluteZ()
  382. return
  383. }
  384. @(objc_type=Event, objc_name="buttonMask")
  385. Event_buttonMask :: proc "c" (self: ^Event) -> UInteger {
  386. return msgSend(UInteger, self, "buttonMask")
  387. }
  388. @(objc_type=Event, objc_name="tilt")
  389. tilt :: proc "c" (self: ^Event) -> Point {
  390. return msgSend(Point, self, "tilt")
  391. }
  392. @(objc_type=Event, objc_name="tangentialPressure")
  393. Event_tangentialPressure :: proc "c" (self: ^Event) -> f32 {
  394. return msgSend(f32, self, "tangentialPressure")
  395. }
  396. @(objc_type=Event, objc_name="vendorDefined")
  397. Event_vendorDefined :: proc "c" (self: ^Event) -> id {
  398. return msgSend(id, self, "vendorDefined")
  399. }
  400. @(objc_type=Event, objc_name="vendorID")
  401. Event_vendorID :: proc "c" (self: ^Event) -> UInteger {
  402. return msgSend(UInteger, self, "vendorID")
  403. }
  404. @(objc_type=Event, objc_name="tabletID")
  405. Event_tabletID :: proc "c" (self: ^Event) -> UInteger {
  406. return msgSend(UInteger, self, "tabletID")
  407. }
  408. @(objc_type=Event, objc_name="pointingDeviceID")
  409. Event_pointingDeviceID :: proc "c" (self: ^Event) -> UInteger {
  410. return msgSend(UInteger, self, "pointingDeviceID")
  411. }
  412. @(objc_type=Event, objc_name="systemTabletID")
  413. Event_systemTabletID :: proc "c" (self: ^Event) -> UInteger {
  414. return msgSend(UInteger, self, "systemTabletID")
  415. }
  416. @(objc_type=Event, objc_name="vendorPointingDeviceType")
  417. Event_vendorPointingDeviceType :: proc "c" (self: ^Event) -> UInteger {
  418. return msgSend(UInteger, self, "vendorPointingDeviceType")
  419. }
  420. @(objc_type=Event, objc_name="pointingDeviceSerialNumber")
  421. Event_pointingDeviceSerialNumber :: proc "c" (self: ^Event) -> UInteger {
  422. return msgSend(UInteger, self, "pointingDeviceSerialNumber")
  423. }
  424. @(objc_type=Event, objc_name="uniqueID")
  425. Event_uniqueID :: proc "c" (self: ^Event) -> u64 {
  426. return msgSend(u64, self, "uniqueID")
  427. }
  428. @(objc_type=Event, objc_name="capabilityMask")
  429. Event_capabilityMask :: proc "c" (self: ^Event) -> UInteger {
  430. return msgSend(UInteger, self, "capabilityMask")
  431. }
  432. @(objc_type=Event, objc_name="pointingDeviceType")
  433. Event_pointingDeviceType :: proc "c" (self: ^Event) -> PointingDeviceType {
  434. return msgSend(PointingDeviceType, self, "pointingDeviceType")
  435. }
  436. @(objc_type=Event, objc_name="isEnteringProximity")
  437. Event_isEnteringProximity :: proc "c" (self: ^Event) -> BOOL {
  438. return msgSend(BOOL, self, "isEnteringProximity")
  439. }
  440. @(objc_type=Event, objc_name="isSwipeTrackingFromScrollEventsEnabled")
  441. Event_isSwipeTrackingFromScrollEventsEnabled :: proc "c" (self: ^Event) -> BOOL {
  442. return msgSend(BOOL, self, "isSwipeTrackingFromScrollEventsEnabled")
  443. }