os_osx.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*************************************************************************/
  2. /* os_osx.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef OS_OSX_H
  31. #define OS_OSX_H
  32. #include "crash_handler_osx.h"
  33. #include "drivers/coreaudio/audio_driver_coreaudio.h"
  34. #include "drivers/unix/os_unix.h"
  35. #include "joypad_osx.h"
  36. #include "main/input_default.h"
  37. #include "os/input.h"
  38. #include "power_osx.h"
  39. #include "servers/audio_server.h"
  40. #include "servers/visual/rasterizer.h"
  41. #include "servers/visual/visual_server_wrap_mt.h"
  42. #include "servers/visual_server.h"
  43. #include <AppKit/NSCursor.h>
  44. #include <ApplicationServices/ApplicationServices.h>
  45. #undef CursorShape
  46. /**
  47. @author Juan Linietsky <reduzio@gmail.com>
  48. */
  49. class OS_OSX : public OS_Unix {
  50. public:
  51. struct KeyEvent {
  52. unsigned int osx_state;
  53. bool pressed;
  54. bool echo;
  55. uint32_t scancode;
  56. uint32_t unicode;
  57. };
  58. Vector<KeyEvent> key_event_buffer;
  59. int key_event_pos;
  60. bool force_quit;
  61. // rasterizer seems to no longer be given to visual server, its using GLES3 directly?
  62. //Rasterizer *rasterizer;
  63. VisualServer *visual_server;
  64. List<String> args;
  65. MainLoop *main_loop;
  66. IP_Unix *ip_unix;
  67. AudioDriverCoreAudio audio_driver;
  68. InputDefault *input;
  69. JoypadOSX *joypad_osx;
  70. /* objc */
  71. CGEventSourceRef eventSource;
  72. void process_events();
  73. void process_key_events();
  74. void *framework;
  75. // pthread_key_t current;
  76. bool mouse_grab;
  77. Point2 mouse_pos;
  78. id delegate;
  79. id window_delegate;
  80. id window_object;
  81. id window_view;
  82. id autoreleasePool;
  83. id cursor;
  84. id pixelFormat;
  85. id context;
  86. CursorShape cursor_shape;
  87. NSCursor *cursors[CURSOR_MAX] = { NULL };
  88. MouseMode mouse_mode;
  89. String title;
  90. bool minimized;
  91. bool maximized;
  92. bool zoomed;
  93. Size2 window_size;
  94. Rect2 restore_rect;
  95. String open_with_filename;
  96. Point2 im_position;
  97. ImeCallback im_callback;
  98. void *im_target;
  99. power_osx *power_manager;
  100. CrashHandler crash_handler;
  101. float _mouse_scale(float p_scale) {
  102. if (_display_scale() > 1.0)
  103. return p_scale;
  104. else
  105. return 1.0;
  106. }
  107. float _display_scale() const;
  108. float _display_scale(id screen) const;
  109. void _update_window();
  110. protected:
  111. virtual int get_video_driver_count() const;
  112. virtual const char *get_video_driver_name(int p_driver) const;
  113. virtual void initialize_core();
  114. virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
  115. virtual void finalize();
  116. virtual void set_main_loop(MainLoop *p_main_loop);
  117. virtual void delete_main_loop();
  118. public:
  119. static OS_OSX *singleton;
  120. void wm_minimized(bool p_minimized);
  121. virtual String get_name();
  122. virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
  123. virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false);
  124. virtual void set_cursor_shape(CursorShape p_shape);
  125. virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot);
  126. virtual void set_mouse_show(bool p_show);
  127. virtual void set_mouse_grab(bool p_grab);
  128. virtual bool is_mouse_grab_enabled() const;
  129. virtual void warp_mouse_position(const Point2 &p_to);
  130. virtual Point2 get_mouse_position() const;
  131. virtual int get_mouse_button_state() const;
  132. virtual void set_window_title(const String &p_title);
  133. virtual Size2 get_window_size() const;
  134. virtual Size2 get_real_window_size() const;
  135. virtual void set_icon(const Ref<Image> &p_icon);
  136. virtual MainLoop *get_main_loop() const;
  137. virtual String get_config_path() const;
  138. virtual String get_data_path() const;
  139. virtual String get_cache_path() const;
  140. virtual String get_godot_dir_name() const;
  141. virtual String get_system_dir(SystemDir p_dir) const;
  142. virtual bool can_draw() const;
  143. virtual void set_clipboard(const String &p_text);
  144. virtual String get_clipboard() const;
  145. virtual void release_rendering_thread();
  146. virtual void make_rendering_thread();
  147. virtual void swap_buffers();
  148. Error shell_open(String p_uri);
  149. void push_input(const Ref<InputEvent> &p_event);
  150. String get_locale() const;
  151. virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
  152. virtual VideoMode get_video_mode(int p_screen = 0) const;
  153. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
  154. virtual String get_executable_path() const;
  155. virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
  156. virtual void move_window_to_foreground();
  157. virtual int get_screen_count() const;
  158. virtual int get_current_screen() const;
  159. virtual void set_current_screen(int p_screen);
  160. virtual Point2 get_screen_position(int p_screen = -1) const;
  161. virtual Size2 get_screen_size(int p_screen = -1) const;
  162. virtual int get_screen_dpi(int p_screen = -1) const;
  163. virtual Point2 get_window_position() const;
  164. virtual void set_window_position(const Point2 &p_position);
  165. virtual void set_window_size(const Size2 p_size);
  166. virtual void set_window_fullscreen(bool p_enabled);
  167. virtual bool is_window_fullscreen() const;
  168. virtual void set_window_resizable(bool p_enabled);
  169. virtual bool is_window_resizable() const;
  170. virtual void set_window_minimized(bool p_enabled);
  171. virtual bool is_window_minimized() const;
  172. virtual void set_window_maximized(bool p_enabled);
  173. virtual bool is_window_maximized() const;
  174. virtual void set_window_always_on_top(bool p_enabled);
  175. virtual bool is_window_always_on_top() const;
  176. virtual void request_attention();
  177. virtual String get_joy_guid(int p_device) const;
  178. virtual void set_borderless_window(bool p_borderless);
  179. virtual bool get_borderless_window();
  180. virtual void set_ime_position(const Point2 &p_pos);
  181. virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp);
  182. virtual OS::PowerState get_power_state();
  183. virtual int get_power_seconds_left();
  184. virtual int get_power_percent_left();
  185. virtual bool _check_internal_feature_support(const String &p_feature);
  186. virtual void _set_use_vsync(bool p_enable);
  187. //virtual bool is_vsync_enabled() const;
  188. void run();
  189. void set_mouse_mode(MouseMode p_mode);
  190. MouseMode get_mouse_mode() const;
  191. void disable_crash_handler();
  192. bool is_disable_crash_handler() const;
  193. virtual Error move_to_trash(const String &p_path);
  194. void force_process_input();
  195. OS_OSX();
  196. private:
  197. Point2 get_native_screen_position(int p_screen) const;
  198. Point2 get_native_window_position() const;
  199. void set_native_window_position(const Point2 &p_position);
  200. Point2 get_screens_origin() const;
  201. };
  202. #endif