embedded_process_macos.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  39. protected:
  40. void _notification(int p_what);
  41. public:
  42. void set_script_debugger(ScriptEditorDebugger *p_debugger) {
  43. script_debugger = p_debugger;
  44. }
  45. LayerHost(EmbeddedProcessMacOS *p_process);
  46. };
  47. class EmbeddedProcessMacOS final : public EmbeddedProcessBase {
  48. GDCLASS(EmbeddedProcessMacOS, EmbeddedProcessBase);
  49. enum class EmbeddingState {
  50. IDLE,
  51. IN_PROGRESS,
  52. COMPLETED,
  53. FAILED,
  54. };
  55. DisplayServerMacOS *ds = nullptr;
  56. EmbeddingState embedding_state = EmbeddingState::IDLE;
  57. uint32_t context_id = 0;
  58. ScriptEditorDebugger *script_debugger = nullptr;
  59. LayerHost *layer_host = nullptr;
  60. OS::ProcessID current_process_id = 0;
  61. // Embedded process state.
  62. // The last mouse mode sent by the embedded process.
  63. DisplayServer::MouseMode mouse_mode = DisplayServer::MOUSE_MODE_VISIBLE;
  64. // Helper functions.
  65. void _try_embed_process();
  66. void update_embedded_process();
  67. void _joy_connection_changed(int p_index, bool p_connected) const;
  68. protected:
  69. void _notification(int p_what);
  70. public:
  71. // MARK: - Message Handlers
  72. void set_context_id(uint32_t p_context_id);
  73. void mouse_set_mode(DisplayServer::MouseMode p_mode);
  74. uint32_t get_context_id() const { return context_id; }
  75. void set_script_debugger(ScriptEditorDebugger *p_debugger) override;
  76. bool is_embedding_in_progress() const override {
  77. return embedding_state == EmbeddingState::IN_PROGRESS;
  78. }
  79. _FORCE_INLINE_ bool is_embedding_completed() const override {
  80. return embedding_state == EmbeddingState::COMPLETED;
  81. }
  82. bool is_process_focused() const override { return layer_host->has_focus(); }
  83. void embed_process(OS::ProcessID p_pid) override;
  84. int get_embedded_pid() const override { return current_process_id; }
  85. void reset() override;
  86. void request_close() override;
  87. void queue_update_embedded_process() override { update_embedded_process(); }
  88. Rect2i get_adjusted_embedded_window_rect(const Rect2i &p_rect) const override;
  89. _FORCE_INLINE_ LayerHost *get_layer_host() const { return layer_host; }
  90. void display_state_changed();
  91. // MARK: - Embedded process state
  92. _FORCE_INLINE_ DisplayServer::MouseMode get_mouse_mode() const { return mouse_mode; }
  93. EmbeddedProcessMacOS();
  94. ~EmbeddedProcessMacOS() override;
  95. };