2
0

embedded_process.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**************************************************************************/
  2. /* embedded_process.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 "scene/gui/control.h"
  32. class ScriptEditorDebugger;
  33. class EmbeddedProcessBase : public Control {
  34. GDCLASS(EmbeddedProcessBase, Control);
  35. void _draw();
  36. protected:
  37. Ref<StyleBox> focus_style_box;
  38. Size2i window_size;
  39. bool keep_aspect = false;
  40. Point2i margin_top_left;
  41. Point2i margin_bottom_right;
  42. Window *window = nullptr;
  43. bool transp_enabled = false;
  44. Color clear_color;
  45. Ref<Texture2D> checkerboard;
  46. void _project_settings_changed();
  47. static void _bind_methods();
  48. void _notification(int p_what);
  49. public:
  50. virtual void set_script_debugger(ScriptEditorDebugger *p_debugger) {}
  51. virtual bool is_embedding_completed() const = 0;
  52. virtual bool is_embedding_in_progress() const = 0;
  53. virtual bool is_process_focused() const = 0;
  54. virtual void embed_process(OS::ProcessID p_pid) = 0;
  55. virtual int get_embedded_pid() const = 0;
  56. virtual void reset() = 0;
  57. virtual void request_close() = 0;
  58. virtual void queue_update_embedded_process() = 0;
  59. void set_window_size(const Size2i &p_window_size);
  60. void set_keep_aspect(bool p_keep_aspect);
  61. virtual Rect2i get_adjusted_embedded_window_rect(const Rect2i &p_rect) const = 0;
  62. Rect2i get_screen_embedded_window_rect() const;
  63. int get_margin_size(Side p_side) const;
  64. Size2 get_margins_size() const;
  65. EmbeddedProcessBase();
  66. virtual ~EmbeddedProcessBase();
  67. };
  68. class EmbeddedProcess : public EmbeddedProcessBase {
  69. GDCLASS(EmbeddedProcess, EmbeddedProcessBase);
  70. bool application_has_focus = true;
  71. uint64_t last_application_focus_time = 0;
  72. OS::ProcessID focused_process_id = 0;
  73. OS::ProcessID current_process_id = 0;
  74. bool embedding_grab_focus = false;
  75. bool embedding_completed = false;
  76. uint64_t start_embedding_time = 0;
  77. bool updated_embedded_process_queued = false;
  78. bool last_updated_embedded_process_focused = false;
  79. Timer *timer_embedding = nullptr;
  80. Timer *timer_update_embedded_process = nullptr;
  81. const int embedding_timeout = 45000;
  82. Rect2i last_global_rect;
  83. void _try_embed_process();
  84. void _update_embedded_process();
  85. void _timer_embedding_timeout();
  86. void _timer_update_embedded_process_timeout();
  87. void _check_mouse_over();
  88. void _check_focused_process_id();
  89. bool _is_embedded_process_updatable();
  90. Window *_get_current_modal_window();
  91. protected:
  92. void _notification(int p_what);
  93. public:
  94. bool is_embedding_in_progress() const override;
  95. bool is_embedding_completed() const override;
  96. bool is_process_focused() const override;
  97. void embed_process(OS::ProcessID p_pid) override;
  98. int get_embedded_pid() const override;
  99. void reset() override;
  100. void request_close() override;
  101. void queue_update_embedded_process() override;
  102. Rect2i get_adjusted_embedded_window_rect(const Rect2i &p_rect) const override;
  103. EmbeddedProcess();
  104. ~EmbeddedProcess() override;
  105. };