embedded_process_macos.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**************************************************************************/
  2. /* embedded_process_macos.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. #pragma once
  31. #include "editor/run/embedded_process.h"
  32. class DisplayServerMacOS;
  33. class EmbeddedProcessMacOS;
  34. class LayerHost final : public Control {
  35. GDCLASS(LayerHost, Control);
  36. ScriptEditorDebugger *script_debugger = nullptr;
  37. EmbeddedProcessMacOS *process = nullptr;
  38. bool window_focused = true;
  39. struct CustomCursor {
  40. Ref<Image> image;
  41. Vector2 hotspot;
  42. CustomCursor() {}
  43. CustomCursor(const Ref<Image> &p_image, const Vector2 &p_hotspot) {
  44. image = p_image;
  45. hotspot = p_hotspot;
  46. }
  47. };
  48. HashMap<DisplayServer::CursorShape, CustomCursor> custom_cursors;
  49. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  50. protected:
  51. void _notification(int p_what);
  52. public:
  53. void cursor_set_custom_image(const Ref<Image> &p_image, DisplayServer::CursorShape p_shape, const Vector2 &p_hotspot);
  54. void set_script_debugger(ScriptEditorDebugger *p_debugger) {
  55. script_debugger = p_debugger;
  56. }
  57. LayerHost(EmbeddedProcessMacOS *p_process);
  58. };
  59. class EmbeddedProcessMacOS final : public EmbeddedProcessBase {
  60. GDCLASS(EmbeddedProcessMacOS, EmbeddedProcessBase);
  61. enum class EmbeddingState {
  62. IDLE,
  63. IN_PROGRESS,
  64. COMPLETED,
  65. FAILED,
  66. };
  67. DisplayServerMacOS *ds = nullptr;
  68. EmbeddingState embedding_state = EmbeddingState::IDLE;
  69. uint32_t context_id = 0;
  70. ScriptEditorDebugger *script_debugger = nullptr;
  71. LayerHost *layer_host = nullptr;
  72. OS::ProcessID current_process_id = 0;
  73. // Embedded process state.
  74. // The last mouse mode sent by the embedded process.
  75. DisplayServer::MouseMode mouse_mode = DisplayServer::MOUSE_MODE_VISIBLE;
  76. // Helper functions.
  77. void _try_embed_process();
  78. void update_embedded_process();
  79. void _joy_connection_changed(int p_index, bool p_connected) const;
  80. protected:
  81. void _notification(int p_what);
  82. public:
  83. // MARK: - Message Handlers
  84. void set_context_id(uint32_t p_context_id);
  85. void mouse_set_mode(DisplayServer::MouseMode p_mode);
  86. uint32_t get_context_id() const { return context_id; }
  87. void set_script_debugger(ScriptEditorDebugger *p_debugger) override;
  88. bool is_embedding_in_progress() const override {
  89. return embedding_state == EmbeddingState::IN_PROGRESS;
  90. }
  91. _FORCE_INLINE_ bool is_embedding_completed() const override {
  92. return embedding_state == EmbeddingState::COMPLETED;
  93. }
  94. bool is_process_focused() const override { return layer_host->has_focus(); }
  95. void embed_process(OS::ProcessID p_pid) override;
  96. int get_embedded_pid() const override { return current_process_id; }
  97. void reset() override;
  98. void request_close() override;
  99. void queue_update_embedded_process() override { update_embedded_process(); }
  100. Rect2i get_adjusted_embedded_window_rect(const Rect2i &p_rect) const override;
  101. _FORCE_INLINE_ LayerHost *get_layer_host() const { return layer_host; }
  102. void display_state_changed();
  103. // MARK: - Embedded process state
  104. _FORCE_INLINE_ DisplayServer::MouseMode get_mouse_mode() const { return mouse_mode; }
  105. EmbeddedProcessMacOS();
  106. ~EmbeddedProcessMacOS() override;
  107. };