Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

514 lines
17 KiB

  1. /*
  2. File: CGRemoteOperation.h
  3. Contains: CoreGraphics remote operation
  4. Version: QuickTime 7.3
  5. Copyright: (c) 2007 (c) 2000-2001 by Apple Computer, Inc., all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://developer.apple.com/bugreporter/
  9. */
  10. #ifndef CGREMOTEOPERATION_H_
  11. #define CGREMOTEOPERATION_H_
  12. #ifndef __CGBASE__
  13. #include <CGBase.h>
  14. #endif
  15. #ifndef __CGGEOMETRY__
  16. #include <CGGeometry.h>
  17. #endif
  18. #ifndef __CGERROR__
  19. #include <CGError.h>
  20. #endif
  21. #ifndef __CFDATE__
  22. #include <CFDate.h>
  23. #endif
  24. #ifndef __CFMACHPORT__
  25. #include <CFMachPort.h>
  26. #endif
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #if PRAGMA_IMPORT
  34. #pragma import on
  35. #endif
  36. #if PRAGMA_ENUM_ALWAYSINT
  37. #if defined(__fourbyteints__) && !__fourbyteints__
  38. #define __CGREMOTEOPERATION__RESTORE_TWOBYTEINTS
  39. #pragma fourbyteints on
  40. #endif
  41. #pragma enumsalwaysint on
  42. #elif PRAGMA_ENUM_OPTIONS
  43. #pragma option enum=int
  44. #elif PRAGMA_ENUM_PACK
  45. #if __option(pack_enums)
  46. #define __CGREMOTEOPERATION__RESTORE_PACKED_ENUMS
  47. #pragma options(!pack_enums)
  48. #endif
  49. #endif
  50. typedef CGError CGEventErr;
  51. enum {
  52. CGEventNoErr = kCGErrorSuccess
  53. };
  54. /* Screen refresh or drawing notification */
  55. /*
  56. * Callback function pointer;
  57. * Declare your callback function in this form. When an area of the display is
  58. * modified or refreshed, your callback function will be invoked with a count
  59. * of the number of rectangles in the refreshed areas, and a list of the refreshed
  60. * rectangles. The rectangles are in global coordinates.
  61. *
  62. * Your function should not modify, deallocate or free memory pointed to by rectArray.
  63. *
  64. * The system continues to accumulate refreshed areas constantly. Whenever new
  65. * information is available, your callback function is invoked.The list of rects
  66. * passed to the callback function are cleared from the accumulated refreshed area
  67. * when the callback is made.
  68. *
  69. * This callback may be triggered by drawing operations, window movement, and
  70. * display reconfiguration.
  71. *
  72. * Bear in mind that a single rectangle may occupy multiple displays,
  73. * either by overlapping the displays, or by residing on coincident displays
  74. * when mirroring is active. Use the CGGetDisplaysWithRect() to determine
  75. * the displays a rectangle occupies.
  76. */
  77. typedef u_int32_t CGRectCount;
  78. typedef CALLBACK_API_C( void , CGScreenRefreshCallback )(CGRectCount count, const CGRect *rectArray, void *userParameter);
  79. /*
  80. * Register a callback function to be invoked when an area of the display
  81. * is refreshed, or modified. The function is invoked on the same thread
  82. * of execution that is processing events within your application.
  83. * userParameter is passed back with each invocation of the callback function.
  84. */
  85. /*
  86. * CGRegisterScreenRefreshCallback()
  87. *
  88. * Availability:
  89. * Non-Carbon CFM: not available
  90. * CarbonLib: not available
  91. * Mac OS X: in version 10.0 and later
  92. */
  93. EXTERN_API_C( void )
  94. CGRegisterScreenRefreshCallback(
  95. CGScreenRefreshCallback callback,
  96. void * userParameter);
  97. /*
  98. * Remove a previously registered calback function.
  99. * Both the function and the userParameter must match the registered entry to be removed.
  100. */
  101. /*
  102. * CGUnregisterScreenRefreshCallback()
  103. *
  104. * Availability:
  105. * Non-Carbon CFM: not available
  106. * CarbonLib: not available
  107. * Mac OS X: in version 10.0 and later
  108. */
  109. EXTERN_API_C( void )
  110. CGUnregisterScreenRefreshCallback(
  111. CGScreenRefreshCallback callback,
  112. void * userParameter);
  113. /*
  114. * In some applications it may be preferable to have a seperate thread wait for screen refresh data.
  115. * This function should be called on a thread seperate from the event processing thread.
  116. * If screen refresh callback functions are registered, this function should not be used.
  117. * The mechanisms are mutually exclusive.
  118. *
  119. * Deallocate screen refresh rects using CGReleaseScreenRefreshRects().
  120. *
  121. * Returns an error code if parameters are invalid or an error occurs in retrieving
  122. * dirty screen rects from the server.
  123. */
  124. /*
  125. * CGWaitForScreenRefreshRects()
  126. *
  127. * Availability:
  128. * Non-Carbon CFM: not available
  129. * CarbonLib: not available
  130. * Mac OS X: in version 10.0 and later
  131. */
  132. EXTERN_API_C( CGEventErr )
  133. CGWaitForScreenRefreshRects(
  134. CGRect ** pRectArray,
  135. CGRectCount * pCount);
  136. /*
  137. * Deallocate the list of rects recieved from CGWaitForScreenRefreshRects()
  138. */
  139. /*
  140. * CGReleaseScreenRefreshRects()
  141. *
  142. * Availability:
  143. * Non-Carbon CFM: not available
  144. * CarbonLib: not available
  145. * Mac OS X: in version 10.0 and later
  146. */
  147. EXTERN_API_C( void )
  148. CGReleaseScreenRefreshRects(CGRect * rectArray);
  149. /*
  150. * Posting events: These functions post events into the system. Use for remote
  151. * operation and virtualization.
  152. *
  153. * Note that remote operation requires a valid connection to the server, which
  154. * must be owned by either the root/Administrator user or the logged in console
  155. * user. This means that your application must be running as root/Administrator
  156. * user or the logged in console user.
  157. */
  158. /*
  159. * Synthesize mouse events.
  160. * mouseCursorPosition should be the global coordinates the mouse is at for the event.
  161. * updateMouseCursor should be TRUE if the on-screen cursor
  162. * should be moved to mouseCursorPosition.
  163. *
  164. * Based on the values entered, the appropriate mouse-down, mouse-up, mouse-move,
  165. * or mouse-drag events are generated, by comparing the new state with the current state.
  166. *
  167. * The current implemementation of the event system supports a maximum of thirty-two buttons.
  168. * The buttonCount parameter should be followed by 'buttonCount' boolean_t values
  169. * indicating button state. The first value should reflect the state of the primary
  170. * button on the mouse. The second value, if any, should reflect the state of the secondary
  171. * mouse button (right), if any. A third value woule be the center button, and the remaining
  172. * buttons would be in USB device order.
  173. */
  174. typedef u_int32_t CGButtonCount;
  175. /*
  176. * CGPostMouseEvent()
  177. *
  178. * Availability:
  179. * Non-Carbon CFM: not available
  180. * CarbonLib: not available
  181. * Mac OS X: in version 10.0 and later
  182. */
  183. EXTERN_API_C( CGEventErr )
  184. CGPostMouseEvent(
  185. CGPoint mouseCursorPosition,
  186. boolean_t updateMouseCursorPosition,
  187. CGButtonCount buttonCount,
  188. boolean_t mouseButtonDown,
  189. ...);
  190. /*
  191. * Synthesize scroll wheel events.
  192. *
  193. * The current implemementation of the event system supports a maximum of three wheels.
  194. *
  195. * The wheelCount parameter should be followed by 'wheelCount' 32 bit integer values
  196. * indicating wheel movements. The first value should reflect the state of the primary
  197. * wheel on the mouse. The second value, if any, should reflect the state of a secondary
  198. * mouse wheel, if any.
  199. *
  200. * Wheel movement is represented by small signed integer values,
  201. * typically in a range from -10 to +10. Large values may have unexpected results,
  202. * depending on the application that processes the event.
  203. */
  204. typedef u_int32_t CGWheelCount;
  205. /*
  206. * CGPostScrollWheelEvent()
  207. *
  208. * Availability:
  209. * Non-Carbon CFM: not available
  210. * CarbonLib: not available
  211. * Mac OS X: in version 10.0 and later
  212. */
  213. EXTERN_API_C( CGEventErr )
  214. CGPostScrollWheelEvent(
  215. CGWheelCount wheelCount,
  216. int32_t wheel1,
  217. ...);
  218. /*
  219. * Synthesize keyboard events. Based on the values entered,
  220. * the appropriate key down, key up, and flags changed events are generated.
  221. * If keyChar is NUL (0), an apropriate value will be guessed at, based on the
  222. * default keymapping.
  223. *
  224. * All keystrokes needed to generate a character must be entered, including
  225. * SHIFT, CONTROL, OPTION, and COMMAND keys. For example, to produce a 'Z',
  226. * the SHIFT key must be down, the 'z' key must go down, and then the SHIFT
  227. * and 'z' key must be released:
  228. * CGPostKeyboardEvent( (CGCharCode)0, (CGKeyCode)56, true ); // shift down
  229. * CGPostKeyboardEvent( (CGCharCode)'Z', (CGKeyCode)6, true ); // 'z' down
  230. * CGPostKeyboardEvent( (CGCharCode)'Z', (CGKeyCode)6, false ); // 'z' up
  231. * CGPostKeyboardEvent( (CGCharCode)0, (CGKeyCode)56, false ); // 'shift up
  232. */
  233. typedef u_int16_t CGCharCode;
  234. typedef u_int16_t CGKeyCode;
  235. /*
  236. * CGPostKeyboardEvent()
  237. *
  238. * Availability:
  239. * Non-Carbon CFM: not available
  240. * CarbonLib: not available
  241. * Mac OS X: in version 10.0 and later
  242. */
  243. EXTERN_API_C( CGEventErr )
  244. CGPostKeyboardEvent(
  245. CGCharCode keyChar,
  246. CGKeyCode virtualKey,
  247. boolean_t keyDown);
  248. /*
  249. * Warp the mouse cursor to the desired position in global
  250. * coordinates without generating events
  251. */
  252. /*
  253. * CGWarpMouseCursorPosition()
  254. *
  255. * Availability:
  256. * Non-Carbon CFM: not available
  257. * CarbonLib: not available
  258. * Mac OS X: in version 10.0 and later
  259. */
  260. EXTERN_API_C( CGEventErr )
  261. CGWarpMouseCursorPosition(CGPoint newCursorPosition);
  262. /*
  263. * Remote operation may want to inhibit local events (events from
  264. * the machine's keyboard and mouse). This may be done either as a
  265. * explicit request (tracked per app) or as a short term side effect of
  266. * posting an event.
  267. *
  268. * CGInhibitLocalEvents() is typically used for long term remote operation
  269. * of a system, as in automated system testing or telecommuting applications.
  270. * Local device state changes are discarded.
  271. *
  272. * Local event inhibition is turned off if the app that requested it terminates.
  273. */
  274. /*
  275. * CGInhibitLocalEvents()
  276. *
  277. * Availability:
  278. * Non-Carbon CFM: not available
  279. * CarbonLib: not available
  280. * Mac OS X: in version 10.0 and later
  281. */
  282. EXTERN_API_C( CGEventErr )
  283. CGInhibitLocalEvents(boolean_t doInhibit);
  284. /*
  285. * Set the period of time in seconds that local hardware events (keyboard and mouse)
  286. * are supressed after posting an event. Defaults to 0.25 second.
  287. */
  288. /*
  289. * CGSetLocalEventsSuppressionInterval()
  290. *
  291. * Availability:
  292. * Non-Carbon CFM: not available
  293. * CarbonLib: not available
  294. * Mac OS X: in version 10.0 and later
  295. */
  296. EXTERN_API_C( CGEventErr )
  297. CGSetLocalEventsSuppressionInterval(CFTimeInterval seconds);
  298. /*
  299. * By default, the flags that indicate modifier key state (Command, Alt, Shift, etc.)
  300. * from the system's keyboard and from other event sources are ORed together as an event is
  301. * posted into the system, and current key and mouse button state is considered in generating new events.
  302. * This function allows your application to enable or disable the
  303. * merging of event state. When combining is turned off, the event state propagated in the events
  304. * posted by your app reflect state built up only by your app. The state within your app's generated
  305. * event will not be combined with the system's current state, so the system-wide state reflecting key
  306. * and mouse button state will remain unchanged
  307. *
  308. * When called with doCombineState equal to FALSE, this function initializes local (per application)
  309. * state tracking information to a state of all keys, modifiers, and mouse buttons up.
  310. *
  311. * When called with doCombineState equal to TRUE, the current global state of keys, modifiers,
  312. * and mouse buttons are used in generating events.
  313. */
  314. /*
  315. * CGEnableEventStateCombining()
  316. *
  317. * Availability:
  318. * Non-Carbon CFM: not available
  319. * CarbonLib: not available
  320. * Mac OS X: in version 10.1 and later
  321. */
  322. EXTERN_API_C( CGEventErr )
  323. CGEnableEventStateCombining(boolean_t doCombineState);
  324. /*
  325. * By default the system supresses local hardware events from the keyboard and mouse during
  326. * a short interval after a synthetic event is posted (see CGSetLocalEventsSuppressionInterval())
  327. * and while a synthetic mouse drag (mouse movement with the left/only mouse button down).
  328. * Some classes of applications may want to enable events from some of the local hardware.
  329. * For example, an app may want to post only mouse events, and so may wish to permit local
  330. * keyboard hardware events to pass through.
  331. *
  332. * This interface lets an app specify a state (event supression interval, or mouse drag), and
  333. * a mask of event categories to be passed through.
  334. */
  335. enum CGEventFilterMask {
  336. kCGEventFilterMaskPermitLocalMouseEvents = 0x00000001, /* Mouse, scroll wheel */
  337. kCGEventFilterMaskPermitLocalKeyboardEvents = 0x00000002, /* Alphanumeric keys and Command, Option, Control, Shift, AlphaLock */
  338. kCGEventFilterMaskPermitSystemDefinedEvents = 0x00000004, /* Power key, bezel buttons, sticky keys */
  339. kCGEventFilterMaskPermitAllEvents = kCGEventFilterMaskPermitLocalMouseEvents | kCGEventFilterMaskPermitLocalKeyboardEvents | kCGEventFilterMaskPermitSystemDefinedEvents
  340. };
  341. typedef enum CGEventFilterMask CGEventFilterMask;
  342. enum CGEventSupressionState {
  343. kCGEventSupressionStateSupressionInterval = 0,
  344. kCGEventSupressionStateRemoteMouseDrag = 1,
  345. kCGNumberOfEventSupressionStates = 2
  346. };
  347. typedef enum CGEventSupressionState CGEventSupressionState;
  348. /*
  349. * CGSetLocalEventsFilterDuringSupressionState()
  350. *
  351. * Availability:
  352. * Non-Carbon CFM: not available
  353. * CarbonLib: not available
  354. * Mac OS X: in version 10.1 and later
  355. */
  356. EXTERN_API_C( CGEventErr )
  357. CGSetLocalEventsFilterDuringSupressionState(
  358. CGEventFilterMask filter,
  359. CGEventSupressionState state);
  360. /*
  361. * Helper function to connect or disconnect the mouse and mouse cursor.
  362. * CGAssociateMouseAndMouseCursorPosition(false) has the same effect
  363. * as the following, without actually modifying the supression interval:
  364. *
  365. * CGSetLocalEventsSuppressionInterval(MAX_DOUBLE);
  366. * CGWarpMouseCursorPosition(currentPosition);
  367. *
  368. * While disconnected, mouse move and drag events will reflect the current position of
  369. * the mouse cursor position, which will not change with mouse movement. Use the
  370. * <CoreGraphics/CGDirectDisplay.h> function:
  371. *
  372. * void CGGetLastMouseDelta( CGMouseDelta * deltaX, CGMouseDelta * deltaY );
  373. *
  374. * This will report mouse movement associated with the last mouse move or drag event.
  375. *
  376. * To update the display cursor position, use the function defined in this module:
  377. *
  378. * CGEventErr CGWarpMouseCursorPosition( CGPoint newCursorPosition );
  379. */
  380. /*
  381. * CGAssociateMouseAndMouseCursorPosition()
  382. *
  383. * Availability:
  384. * Non-Carbon CFM: not available
  385. * CarbonLib: not available
  386. * Mac OS X: in version 10.0 and later
  387. */
  388. EXTERN_API_C( CGEventErr )
  389. CGAssociateMouseAndMouseCursorPosition(boolean_t connected);
  390. /*
  391. * Some classes of applications need to detect when the window server process dies, or
  392. * is not running. The easiest way to do this is to use a CFMachPortRef.
  393. *
  394. * If the CoreGraphics window server is not running, this function returns NULL.
  395. * If the server is running, a CFMachPortRef is returned.
  396. *
  397. * A program can register a callback function to use a CFMachPortRef to determine
  398. * when the CoreGraphics window server exits:
  399. *
  400. * static void handleWindowServerDeath( CFMachPortRef port, void *info )
  401. * {
  402. * printf( "Window Server port death detected!\n" );
  403. * CFRelease( port );
  404. * exit( 1 );
  405. * }
  406. *
  407. * static void watchForServerDeath()
  408. * {
  409. * CFMachPortRef port;
  410. *
  411. * port = CGWindowServerCFMachPort();
  412. * CFMachPortSetInvalidationCallBack( port, handleWindowServerDeath );
  413. * }
  414. *
  415. * Note that when the window server exits, there may be a few seconds during which
  416. * no window server is running, until the operating system starts a new
  417. * window server/loginwindow pair of processes. This function will return NULL
  418. * until a new window server is running.
  419. *
  420. * Multiple calls to this function may return multiple CFMachPortRefs, each referring
  421. * to the same Mach port. Multiple callbacks registered on multiple CFMachPortRefs
  422. * obtained in this way may fire in a nondetermanistic manner.
  423. *
  424. * Your program will need to run a CFRunLoop for the port death
  425. * callback to function. A program which does not use a CFRunLoop may use
  426. * CFMachPortIsValid(CFMachPortRef port) periodically to check if the port is valid.
  427. */
  428. /*
  429. * CGWindowServerCFMachPort()
  430. *
  431. * Availability:
  432. * Non-Carbon CFM: not available
  433. * CarbonLib: not available
  434. * Mac OS X: in version 10.1 and later
  435. */
  436. EXTERN_API_C( CFMachPortRef )
  437. CGWindowServerCFMachPort(void);
  438. #if PRAGMA_ENUM_ALWAYSINT
  439. #pragma enumsalwaysint reset
  440. #ifdef __CGREMOTEOPERATION__RESTORE_TWOBYTEINTS
  441. #pragma fourbyteints off
  442. #endif
  443. #elif PRAGMA_ENUM_OPTIONS
  444. #pragma option enum=reset
  445. #elif defined(__CGREMOTEOPERATION__RESTORE_PACKED_ENUMS)
  446. #pragma options(pack_enums)
  447. #endif
  448. #ifdef PRAGMA_IMPORT_OFF
  449. #pragma import off
  450. #elif PRAGMA_IMPORT
  451. #pragma import reset
  452. #endif
  453. #ifdef __cplusplus
  454. }
  455. #endif
  456. #endif /* CGREMOTEOPERATION_H_ */