embedded_process_macos.h 4.4 KB

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