embedded_process.h 5.0 KB

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