NSEvent.odin 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. package objc_Foundation
  2. @(objc_class="NSEvent")
  3. Event :: struct {using _: Object}
  4. EventMask :: distinct bit_set[EventType; UInteger]
  5. EventMaskAny :: ~EventMask{}
  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. // Defined in Carbon.framework Events.h
  101. kVK :: enum {
  102. ANSI_A = 0x00,
  103. ANSI_S = 0x01,
  104. ANSI_D = 0x02,
  105. ANSI_F = 0x03,
  106. ANSI_H = 0x04,
  107. ANSI_G = 0x05,
  108. ANSI_Z = 0x06,
  109. ANSI_X = 0x07,
  110. ANSI_C = 0x08,
  111. ANSI_V = 0x09,
  112. ANSI_B = 0x0B,
  113. ANSI_Q = 0x0C,
  114. ANSI_W = 0x0D,
  115. ANSI_E = 0x0E,
  116. ANSI_R = 0x0F,
  117. ANSI_Y = 0x10,
  118. ANSI_T = 0x11,
  119. ANSI_1 = 0x12,
  120. ANSI_2 = 0x13,
  121. ANSI_3 = 0x14,
  122. ANSI_4 = 0x15,
  123. ANSI_6 = 0x16,
  124. ANSI_5 = 0x17,
  125. ANSI_Equal = 0x18,
  126. ANSI_9 = 0x19,
  127. ANSI_7 = 0x1A,
  128. ANSI_Minus = 0x1B,
  129. ANSI_8 = 0x1C,
  130. ANSI_0 = 0x1D,
  131. ANSI_RightBracket = 0x1E,
  132. ANSI_O = 0x1F,
  133. ANSI_U = 0x20,
  134. ANSI_LeftBracket = 0x21,
  135. ANSI_I = 0x22,
  136. ANSI_P = 0x23,
  137. ANSI_L = 0x25,
  138. ANSI_J = 0x26,
  139. ANSI_Quote = 0x27,
  140. ANSI_K = 0x28,
  141. ANSI_Semicolon = 0x29,
  142. ANSI_Backslash = 0x2A,
  143. ANSI_Comma = 0x2B,
  144. ANSI_Slash = 0x2C,
  145. ANSI_N = 0x2D,
  146. ANSI_M = 0x2E,
  147. ANSI_Period = 0x2F,
  148. ANSI_Grave = 0x32,
  149. ANSI_KeypadDecimal = 0x41,
  150. ANSI_KeypadMultiply = 0x43,
  151. ANSI_KeypadPlus = 0x45,
  152. ANSI_KeypadClear = 0x47,
  153. ANSI_KeypadDivide = 0x4B,
  154. ANSI_KeypadEnter = 0x4C,
  155. ANSI_KeypadMinus = 0x4E,
  156. ANSI_KeypadEquals = 0x51,
  157. ANSI_Keypad0 = 0x52,
  158. ANSI_Keypad1 = 0x53,
  159. ANSI_Keypad2 = 0x54,
  160. ANSI_Keypad3 = 0x55,
  161. ANSI_Keypad4 = 0x56,
  162. ANSI_Keypad5 = 0x57,
  163. ANSI_Keypad6 = 0x58,
  164. ANSI_Keypad7 = 0x59,
  165. ANSI_Keypad8 = 0x5B,
  166. ANSI_Keypad9 = 0x5C,
  167. Return = 0x24,
  168. Tab = 0x30,
  169. Space = 0x31,
  170. Delete = 0x33,
  171. Escape = 0x35,
  172. Command = 0x37,
  173. Shift = 0x38,
  174. CapsLock = 0x39,
  175. Option = 0x3A,
  176. Control = 0x3B,
  177. RightCommand = 0x36,
  178. RightShift = 0x3C,
  179. RightOption = 0x3D,
  180. RightControl = 0x3E,
  181. Function = 0x3F,
  182. F17 = 0x40,
  183. VolumeUp = 0x48,
  184. VolumeDown = 0x49,
  185. Mute = 0x4A,
  186. F18 = 0x4F,
  187. F19 = 0x50,
  188. F20 = 0x5A,
  189. F5 = 0x60,
  190. F6 = 0x61,
  191. F7 = 0x62,
  192. F3 = 0x63,
  193. F8 = 0x64,
  194. F9 = 0x65,
  195. F11 = 0x67,
  196. F13 = 0x69,
  197. F16 = 0x6A,
  198. F14 = 0x6B,
  199. F10 = 0x6D,
  200. F12 = 0x6F,
  201. F15 = 0x71,
  202. Help = 0x72,
  203. Home = 0x73,
  204. PageUp = 0x74,
  205. ForwardDelete = 0x75,
  206. F4 = 0x76,
  207. End = 0x77,
  208. F2 = 0x78,
  209. PageDown = 0x79,
  210. F1 = 0x7A,
  211. LeftArrow = 0x7B,
  212. RightArrow = 0x7C,
  213. DownArrow = 0x7D,
  214. UpArrow = 0x7E,
  215. JIS_Yen = 0x5D,
  216. JIS_Underscore = 0x5E,
  217. JIS_KeypadComma = 0x5F,
  218. JIS_Eisu = 0x66,
  219. JIS_Kana = 0x68,
  220. ISO_Section = 0x0A,
  221. }
  222. /* these messages are valid for all events */
  223. @(objc_type=Event, objc_name="type")
  224. Event_type :: proc "c" (self: ^Event) -> EventType {
  225. return msgSend(EventType, self, "type")
  226. }
  227. @(objc_type=Event, objc_name="modifierFlags")
  228. Event_modifierFlags :: proc "c" (self: ^Event) -> UInteger {
  229. return msgSend(UInteger, self, "modifierFlags")
  230. }
  231. @(objc_type=Event, objc_name="timestamp")
  232. Event_timestamp :: proc "c" (self: ^Event) -> TimeInterval {
  233. return msgSend(TimeInterval, self, "timestamp")
  234. }
  235. @(objc_type=Event, objc_name="window")
  236. Event_window :: proc "c" (self: ^Event) -> ^Window {
  237. return msgSend(^Window, self, "window")
  238. }
  239. @(objc_type=Event, objc_name="windowNumber")
  240. Event_windowNumber :: proc "c" (self: ^Event) -> UInteger {
  241. return msgSend(UInteger, self, "windowNumber")
  242. }
  243. /* these messages are valid for all mouse down/up/drag events */
  244. @(objc_type=Event, objc_name="clickCount")
  245. Event_clickCount :: proc "c" (self: ^Event) -> Integer {
  246. return msgSend(Integer, self, "clickCount")
  247. }
  248. // for NSOtherMouse events, but will return valid constants for NSLeftMouse and NSRightMouse
  249. @(objc_type=Event, objc_name="buttonNumber")
  250. Event_buttonNumber :: proc "c" (self: ^Event) -> Integer {
  251. return msgSend(Integer, self, "buttonNumber")
  252. }
  253. /* these messages are valid for all mouse down/up/drag and enter/exit events */
  254. @(objc_type=Event, objc_name="eventNumber")
  255. Event_eventNumber :: proc "c" (self: ^Event) -> Integer {
  256. return msgSend(Integer, self, "eventNumber")
  257. }
  258. /* -pressure is valid for all mouse down/up/drag events, and is also valid for NSTabletPoint events on 10.4 or later */
  259. @(objc_type=Event, objc_name="pressure")
  260. Event_pressure :: proc "c" (self: ^Event) -> f32 {
  261. return msgSend(f32, self, "pressure")
  262. }
  263. /* -locationInWindow is valid for all mouse-related events */
  264. @(objc_type=Event, objc_name="locationInWindow")
  265. Event_locationInWindow :: proc "c" (self: ^Event) -> Point {
  266. return msgSend(Point, self, "locationInWindow")
  267. }
  268. @(objc_type=Event, objc_name="deltaX")
  269. Event_deltaX :: proc "c" (self: ^Event) -> Float {
  270. return msgSend(Float, self, "deltaX")
  271. }
  272. @(objc_type=Event, objc_name="deltaY")
  273. Event_deltaY :: proc "c" (self: ^Event) -> Float {
  274. return msgSend(Float, self, "deltaY")
  275. }
  276. @(objc_type=Event, objc_name="deltaZ")
  277. Event_deltaZ :: proc "c" (self: ^Event) -> Float {
  278. return msgSend(Float, self, "deltaZ")
  279. }
  280. @(objc_type=Event, objc_name="delta")
  281. Event_delta :: proc "c" (self: ^Event) -> (x, y, z: Float) {
  282. x = self->deltaX()
  283. y = self->deltaY()
  284. z = self->deltaZ()
  285. return
  286. }
  287. @(objc_type=Event, objc_name="hasPreciseScrollingDeltas")
  288. Event_hasPreciseScrollingDeltas :: proc "c" (self: ^Event) -> BOOL {
  289. return msgSend(BOOL, self, "hasPreciseScrollingDeltas")
  290. }
  291. @(objc_type=Event, objc_name="scrollingDeltaX")
  292. Event_scrollingDeltaX :: proc "c" (self: ^Event) -> Float {
  293. return msgSend(Float, self, "scrollingDeltaX")
  294. }
  295. @(objc_type=Event, objc_name="scrollingDeltaY")
  296. Event_scrollingDeltaY :: proc "c" (self: ^Event) -> Float {
  297. return msgSend(Float, self, "scrollingDeltaY")
  298. }
  299. @(objc_type=Event, objc_name="scrollingDelta")
  300. Event_scrollingDelta :: proc "c" (self: ^Event) -> (x, y: Float) {
  301. x = self->scrollingDeltaX()
  302. y = self->scrollingDeltaY()
  303. return
  304. }
  305. @(objc_type=Event, objc_name="momentumPhase")
  306. Event_momentumPhase :: proc "c" (self: ^Event) -> EventPhase {
  307. return msgSend(EventPhase, self, "momentumPhase")
  308. }
  309. @(objc_type=Event, objc_name="phase")
  310. Event_phase :: proc "c" (self: ^Event) -> EventPhase {
  311. return msgSend(EventPhase, self, "phase")
  312. }
  313. @(objc_type=Event, objc_name="isDirectionInvertedFromDevice")
  314. Event_isDirectionInvertedFromDevice :: proc "c" (self: ^Event) -> BOOL {
  315. return msgSend(BOOL, self, "isDirectionInvertedFromDevice")
  316. }
  317. @(objc_type=Event, objc_name="characters")
  318. Event_characters :: proc "c" (self: ^Event) -> ^String {
  319. return msgSend(^String, self, "characters")
  320. }
  321. @(objc_type=Event, objc_name="charactersIgnoringModifiers")
  322. Event_charactersIgnoringModifiers :: proc "c" (self: ^Event) -> ^String {
  323. return msgSend(^String, self, "charactersIgnoringModifiers")
  324. }
  325. @(objc_type=Event, objc_name="isARepeat")
  326. Event_isARepeat :: proc "c" (self: ^Event) -> BOOL {
  327. return msgSend(BOOL, self, "isARepeat")
  328. }
  329. @(objc_type=Event, objc_name="keyCode")
  330. Event_keyCode :: proc "c" (self: ^Event) -> u16 {
  331. return msgSend(u16, self, "keyCode")
  332. }
  333. @(objc_type=Event, objc_name="subtype")
  334. Event_subtype :: proc "c" (self: ^Event) -> i16 {
  335. return msgSend(i16, self, "subtype")
  336. }
  337. @(objc_type=Event, objc_name="data1")
  338. Event_data1 :: proc "c" (self: ^Event) -> Integer {
  339. return msgSend(Integer, self, "data1")
  340. }
  341. @(objc_type=Event, objc_name="data2")
  342. Event_data2 :: proc "c" (self: ^Event) -> Integer {
  343. return msgSend(Integer, self, "data2")
  344. }
  345. @(objc_type=Event, objc_name="absoluteX")
  346. Event_absoluteX :: proc "c" (self: ^Event) -> Integer {
  347. return msgSend(Integer, self, "absoluteX")
  348. }
  349. @(objc_type=Event, objc_name="absoluteY")
  350. Event_absoluteY :: proc "c" (self: ^Event) -> Integer {
  351. return msgSend(Integer, self, "absoluteY")
  352. }
  353. @(objc_type=Event, objc_name="absoluteZ")
  354. Event_absoluteZ :: proc "c" (self: ^Event) -> Integer {
  355. return msgSend(Integer, self, "absoluteZ")
  356. }
  357. @(objc_type=Event, objc_name="absolute")
  358. Event_absolute :: proc "c" (self: ^Event) -> (x, y, z: Integer) {
  359. x = self->absoluteX()
  360. y = self->absoluteY()
  361. z = self->absoluteZ()
  362. return
  363. }
  364. @(objc_type=Event, objc_name="buttonMask")
  365. Event_buttonMask :: proc "c" (self: ^Event) -> UInteger {
  366. return msgSend(UInteger, self, "buttonMask")
  367. }
  368. @(objc_type=Event, objc_name="tilt")
  369. tilt :: proc "c" (self: ^Event) -> Point {
  370. return msgSend(Point, self, "tilt")
  371. }
  372. @(objc_type=Event, objc_name="tangentialPressure")
  373. Event_tangentialPressure :: proc "c" (self: ^Event) -> f32 {
  374. return msgSend(f32, self, "tangentialPressure")
  375. }
  376. @(objc_type=Event, objc_name="vendorDefined")
  377. Event_vendorDefined :: proc "c" (self: ^Event) -> id {
  378. return msgSend(id, self, "vendorDefined")
  379. }
  380. @(objc_type=Event, objc_name="vendorID")
  381. Event_vendorID :: proc "c" (self: ^Event) -> UInteger {
  382. return msgSend(UInteger, self, "vendorID")
  383. }
  384. @(objc_type=Event, objc_name="tabletID")
  385. Event_tabletID :: proc "c" (self: ^Event) -> UInteger {
  386. return msgSend(UInteger, self, "tabletID")
  387. }
  388. @(objc_type=Event, objc_name="pointingDeviceID")
  389. Event_pointingDeviceID :: proc "c" (self: ^Event) -> UInteger {
  390. return msgSend(UInteger, self, "pointingDeviceID")
  391. }
  392. @(objc_type=Event, objc_name="systemTabletID")
  393. Event_systemTabletID :: proc "c" (self: ^Event) -> UInteger {
  394. return msgSend(UInteger, self, "systemTabletID")
  395. }
  396. @(objc_type=Event, objc_name="vendorPointingDeviceType")
  397. Event_vendorPointingDeviceType :: proc "c" (self: ^Event) -> UInteger {
  398. return msgSend(UInteger, self, "vendorPointingDeviceType")
  399. }
  400. @(objc_type=Event, objc_name="pointingDeviceSerialNumber")
  401. Event_pointingDeviceSerialNumber :: proc "c" (self: ^Event) -> UInteger {
  402. return msgSend(UInteger, self, "pointingDeviceSerialNumber")
  403. }
  404. @(objc_type=Event, objc_name="uniqueID")
  405. Event_uniqueID :: proc "c" (self: ^Event) -> u64 {
  406. return msgSend(u64, self, "uniqueID")
  407. }
  408. @(objc_type=Event, objc_name="capabilityMask")
  409. Event_capabilityMask :: proc "c" (self: ^Event) -> UInteger {
  410. return msgSend(UInteger, self, "capabilityMask")
  411. }
  412. @(objc_type=Event, objc_name="pointingDeviceType")
  413. Event_pointingDeviceType :: proc "c" (self: ^Event) -> PointingDeviceType {
  414. return msgSend(PointingDeviceType, self, "pointingDeviceType")
  415. }
  416. @(objc_type=Event, objc_name="isEnteringProximity")
  417. Event_isEnteringProximity :: proc "c" (self: ^Event) -> BOOL {
  418. return msgSend(BOOL, self, "isEnteringProximity")
  419. }
  420. @(objc_type=Event, objc_name="isSwipeTrackingFromScrollEventsEnabled")
  421. Event_isSwipeTrackingFromScrollEventsEnabled :: proc "c" (self: ^Event) -> BOOL {
  422. return msgSend(BOOL, self, "isSwipeTrackingFromScrollEventsEnabled")
  423. }