MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
WindowManager.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Core {
7
8/**
9 * @class WindowManager
10 * @brief Manages window lifecycle and GLFW event polling
11 *
12 * Responsibilities:
13 * - Create/destroy windows
14 * - Poll GLFW events (calls glfwPollEvents)
15 * - Query windows by title/index
16 */
17class MAYAFLUX_API WindowManager {
18public:
19 /**
20 * @brief Constructs WindowManager with global graphics config
21 * @param config Global graphics configuration for window defaults
22 */
23 explicit WindowManager(const GlobalGraphicsConfig& config);
24
26
27 WindowManager(const WindowManager&) = delete;
29 WindowManager(WindowManager&&) noexcept = delete;
30 WindowManager& operator=(WindowManager&&) noexcept = delete;
31
32 /**
33 * @brief Creates a new window
34 * @param create_info Window creation parameters
35 * @return Pointer to created window (owned by manager)
36 */
37 std::shared_ptr<Window> create_window(const WindowCreateInfo& create_info);
38
39 /**
40 * @brief Destroys a window by pointer
41 * @param window Pointer to window to destroy
42 */
43 void destroy_window(const std::shared_ptr<Window>& window);
44
45 /**
46 * @brief Destroys a window by title
47 * @param title Title of window to destroy
48 * @return True if window was found and destroyed
49 */
50 bool destroy_window_by_title(const std::string& title);
51
52 /**
53 * @brief Gets all active windows
54 */
55 std::vector<std::shared_ptr<Window>> get_windows() const;
56
57 /**
58 * @brief Finds window by title
59 * @return Pointer to window, or nullptr if not found
60 */
61 std::shared_ptr<Window> find_window(const std::string& title) const;
62
63 /**
64 * @brief Gets window by index
65 * @return Pointer to window, or nullptr if index out of bounds
66 */
67 std::shared_ptr<Window> get_window(size_t index) const;
68
69 /**
70 * @brief Gets number of active windows
71 */
72 size_t window_count() const { return m_windows.size(); }
73
74 /**
75 * @brief Checks if any window should close
76 * @return True if at least one window has close requested
77 */
78 bool any_window_should_close() const;
79
80 /**
81 * @brief Destroys all windows that should close
82 * @return Number of windows destroyed
83 */
84 size_t destroy_closed_windows();
85
86 /**
87 * @brief Gets the global graphics configuration
88 */
89 const GraphicsSurfaceInfo& get_config() const { return m_config.surface_info; }
90
91 /**
92 * @brief Process windows for one frame
93 *
94 * This is the main per-frame operation that should be called
95 * from the application's main loop. It:
96 * 1. Polls GLFW events (triggers EventSource)
97 * 2. Cleans up closed windows
98 * 3. Optionally runs per-frame hooks
99 *
100 * @return True if processing should continue, false if all windows closed
101 */
102 bool process();
103
104 /**
105 * @brief Register a hook that runs every frame
106 * @param name Hook identifier
107 * @param hook Function to call each frame
108 */
109 void register_frame_hook(const std::string& name,
110 std::function<void()> hook);
111
112 /**
113 * @brief Unregister a previously registered frame hook
114 * @param name Hook identifier to remove
115 */
116 void unregister_frame_hook(const std::string& name);
117
118 /**
119 * @brief Get windows registered for processing
120 */
121 std::vector<std::shared_ptr<Window>> get_processing_windows() const { return m_processing_windows; }
122
123private:
125 std::vector<std::shared_ptr<Window>> m_windows;
126 std::unordered_map<std::string, std::weak_ptr<Window>> m_window_lookup;
127
128 /**
129 * @brief Factory for creating backend-specific windows
130 */
131 std::shared_ptr<Window> create_window_internal(const WindowCreateInfo& create_info);
132
133 /** @brief Atomic flag to signal event loop thread to stop */
134 std::atomic<bool> m_should_stop { false };
135
136 /**
137 * @brief Removes window from lookup table
138 */
139 void remove_from_lookup(const std::shared_ptr<Window>& window);
140
141 /**
142 * @brief Calls all registered frame hooks
143 */
144 std::unordered_map<std::string, std::function<void()>> m_frame_hooks;
145
146 /** @brief Mutex for protecting m_windows and m_window_lookup */
147 mutable std::mutex m_hooks_mutex;
148
149 std::vector<std::shared_ptr<Window>> m_processing_windows;
150};
151
152} // namespace MayaFlux::Core
std::vector< std::shared_ptr< Window > > get_processing_windows() const
Get windows registered for processing.
const GraphicsSurfaceInfo & get_config() const
Gets the global graphics configuration.
WindowManager & operator=(const WindowManager &)=delete
WindowManager(const WindowManager &)=delete
std::mutex m_hooks_mutex
Mutex for protecting m_windows and m_window_lookup.
std::vector< std::shared_ptr< Window > > m_windows
WindowManager(WindowManager &&) noexcept=delete
GlobalGraphicsConfig m_config
std::unordered_map< std::string, std::function< void()> > m_frame_hooks
Calls all registered frame hooks.
std::unordered_map< std::string, std::weak_ptr< Window > > m_window_lookup
std::vector< std::shared_ptr< Window > > m_processing_windows
Manages window lifecycle and GLFW event polling.
Platform-agnostic window wrapper.
Definition Window.hpp:18
System-wide configuration for visual stream processing.
Configuration for creating a single window instance.