SDL_cocoawindow.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "../../SDL_internal.h"
  19. #ifndef SDL_cocoawindow_h_
  20. #define SDL_cocoawindow_h_
  21. #import <Cocoa/Cocoa.h>
  22. #if SDL_VIDEO_OPENGL_EGL
  23. #include "../SDL_egl_c.h"
  24. #endif
  25. typedef struct SDL_WindowData SDL_WindowData;
  26. typedef enum
  27. {
  28. PENDING_OPERATION_NONE,
  29. PENDING_OPERATION_ENTER_FULLSCREEN,
  30. PENDING_OPERATION_LEAVE_FULLSCREEN,
  31. PENDING_OPERATION_MINIMIZE
  32. } PendingWindowOperation;
  33. @interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
  34. SDL_WindowData *_data;
  35. BOOL observingVisible;
  36. BOOL wasCtrlLeft;
  37. BOOL wasVisible;
  38. BOOL isFullscreenSpace;
  39. BOOL inFullscreenTransition;
  40. PendingWindowOperation pendingWindowOperation;
  41. BOOL isMoving;
  42. int pendingWindowWarpX, pendingWindowWarpY;
  43. BOOL isDragAreaRunning;
  44. }
  45. -(void) listen:(SDL_WindowData *) data;
  46. -(void) pauseVisibleObservation;
  47. -(void) resumeVisibleObservation;
  48. -(BOOL) setFullscreenSpace:(BOOL) state;
  49. -(BOOL) isInFullscreenSpace;
  50. -(BOOL) isInFullscreenSpaceTransition;
  51. -(void) addPendingWindowOperation:(PendingWindowOperation) operation;
  52. -(void) close;
  53. -(BOOL) isMoving;
  54. -(void) setPendingMoveX:(int)x Y:(int)y;
  55. -(void) windowDidFinishMoving;
  56. /* Window delegate functionality */
  57. -(BOOL) windowShouldClose:(id) sender;
  58. -(void) windowDidExpose:(NSNotification *) aNotification;
  59. -(void) windowDidMove:(NSNotification *) aNotification;
  60. -(void) windowDidResize:(NSNotification *) aNotification;
  61. -(void) windowDidMiniaturize:(NSNotification *) aNotification;
  62. -(void) windowDidDeminiaturize:(NSNotification *) aNotification;
  63. -(void) windowDidBecomeKey:(NSNotification *) aNotification;
  64. -(void) windowDidResignKey:(NSNotification *) aNotification;
  65. -(void) windowDidChangeBackingProperties:(NSNotification *) aNotification;
  66. -(void) windowWillEnterFullScreen:(NSNotification *) aNotification;
  67. -(void) windowDidEnterFullScreen:(NSNotification *) aNotification;
  68. -(void) windowWillExitFullScreen:(NSNotification *) aNotification;
  69. -(void) windowDidExitFullScreen:(NSNotification *) aNotification;
  70. -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions;
  71. /* See if event is in a drag area, toggle on window dragging. */
  72. -(BOOL) processHitTest:(NSEvent *)theEvent;
  73. /* Window event handling */
  74. -(void) mouseDown:(NSEvent *) theEvent;
  75. -(void) rightMouseDown:(NSEvent *) theEvent;
  76. -(void) otherMouseDown:(NSEvent *) theEvent;
  77. -(void) mouseUp:(NSEvent *) theEvent;
  78. -(void) rightMouseUp:(NSEvent *) theEvent;
  79. -(void) otherMouseUp:(NSEvent *) theEvent;
  80. -(void) mouseMoved:(NSEvent *) theEvent;
  81. -(void) mouseDragged:(NSEvent *) theEvent;
  82. -(void) rightMouseDragged:(NSEvent *) theEvent;
  83. -(void) otherMouseDragged:(NSEvent *) theEvent;
  84. -(void) scrollWheel:(NSEvent *) theEvent;
  85. -(void) touchesBeganWithEvent:(NSEvent *) theEvent;
  86. -(void) touchesMovedWithEvent:(NSEvent *) theEvent;
  87. -(void) touchesEndedWithEvent:(NSEvent *) theEvent;
  88. -(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
  89. /* Touch event handling */
  90. -(void) handleTouches:(NSTouchPhase) phase withEvent:(NSEvent*) theEvent;
  91. @end
  92. /* *INDENT-ON* */
  93. @class SDLOpenGLContext;
  94. struct SDL_WindowData
  95. {
  96. SDL_Window *window;
  97. NSWindow *nswindow;
  98. NSMutableArray *nscontexts;
  99. SDL_bool created;
  100. SDL_bool inWindowMove;
  101. Cocoa_WindowListener *listener;
  102. struct SDL_VideoData *videodata;
  103. #if SDL_VIDEO_OPENGL_EGL
  104. EGLSurface egl_surface;
  105. #endif
  106. };
  107. extern int Cocoa_CreateWindow(_THIS, SDL_Window * window);
  108. extern int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window,
  109. const void *data);
  110. extern void Cocoa_SetWindowTitle(_THIS, SDL_Window * window);
  111. extern void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
  112. extern void Cocoa_SetWindowPosition(_THIS, SDL_Window * window);
  113. extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
  114. extern void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window);
  115. extern void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window);
  116. extern int Cocoa_SetWindowOpacity(_THIS, SDL_Window * window, float opacity);
  117. extern void Cocoa_ShowWindow(_THIS, SDL_Window * window);
  118. extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
  119. extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
  120. extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
  121. extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
  122. extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
  123. extern void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
  124. extern void Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
  125. extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
  126. extern int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
  127. extern int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
  128. extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
  129. extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
  130. extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info);
  131. extern int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
  132. extern void Cocoa_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept);
  133. #endif /* SDL_cocoawindow_h_ */
  134. /* vi: set ts=4 sw=4 expandtab: */