Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
window_manager.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <pulp/view/theme.hpp>
5#include <cstdint>
6#include <functional>
7#include <memory>
8#include <mutex>
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13namespace pulp::view {
14
15// ── Window type hints ───────────────────────────────────────────────────────
16
24
25// ── Screen / monitor information ────────────────────────────────────────────
26
27struct ScreenInfo {
28 int id = 0;
29 float x = 0, y = 0;
30 float width = 0;
31 float height = 0;
32 float scale_factor = 1.0f;
33 bool is_primary = false;
34 std::string name;
35};
36
37// ── Window state for save / restore ─────────────────────────────────────────
38
40 float x = 0, y = 0;
41 float width = 400, height = 300;
42 int screen_id = 0;
43 bool is_visible = true;
44};
45
46// ── Per-window record in the manager ────────────────────────────────────────
47
48using WindowId = uint32_t;
49
59
60// ── Inter-window message ────────────────────────────────────────────────────
61
63 std::string type;
64 std::string payload;
66};
67
68using MessageHandler = std::function<void(const WindowMessage&)>;
69
70// ── WindowManager ───────────────────────────────────────────────────────────
71//
72// Coordination layer for multiple windows. Manages:
73// - Registry of active windows
74// - Parent-child relationships and cascading close
75// - Theme propagation across all windows
76// - Inter-window message passing
77// - Screen/monitor enumeration
78// - Window state save/restore
79// - Shared GPU device reference for Dawn-based rendering
80//
81// Thread safety: all public methods are safe to call from the main thread.
82// Audio-thread code should not call WindowManager directly.
83
85public:
88
89 WindowManager(const WindowManager&) = delete;
91
92 // ── Window registration ─────────────────────────────────────────────
93
97 WindowType type, WindowId parent_id = 0);
98
102
104 const WindowRecord* window(WindowId id) const;
105
107 std::vector<WindowId> window_ids() const;
108
110 std::vector<WindowId> children_of(WindowId parent_id) const;
111
113 size_t window_count() const;
114
115 // ── Cascading close ─────────────────────────────────────────────────
116
120
123 void set_on_window_closed(std::function<void(WindowId)> cb);
124
125 // ── Theme propagation ───────────────────────────────────────────────
126
129 void set_shared_theme(const Theme& theme);
130
132 const Theme& shared_theme() const;
133
134 // ── Inter-window messaging ──────────────────────────────────────────
135
137 void send_message(WindowId target, const WindowMessage& msg);
138
141
144
145 // ── Screen enumeration ──────────────────────────────────────────────
146
148 static std::vector<ScreenInfo> available_screens();
149
152
153 // ── Window state save / restore ─────────────────────────────────────
154
156 std::unordered_map<WindowId, WindowState> save_all_states() const;
157
161
162 // ── GPU device sharing ──────────────────────────────────────────────
163
168 void set_shared_gpu_device(void* device_handle);
169
171 void* shared_gpu_device() const;
172
173 // ── Multi-window capability query ───────────────────────────────────
174
179
180private:
181 WindowId next_id_ = 1;
182
183 // Ordered map would give deterministic iteration, but unordered is fine
184 // for the expected window count (< 20).
185 std::unordered_map<WindowId, WindowRecord> windows_;
186 std::unordered_map<WindowId, MessageHandler> handlers_;
187
188 Theme shared_theme_;
189 void* shared_gpu_device_ = nullptr;
190
191 std::function<void(WindowId)> on_window_closed_;
192
193 // Collect children recursively (depth-first).
194 void collect_descendants(WindowId id, std::vector<WindowId>& out) const;
195};
196
197} // namespace pulp::view
Definition view.hpp:73
Definition window_host.hpp:113
void set_on_window_closed(std::function< void(WindowId)> cb)
Set a callback invoked when a window is about to be unregistered.
void restore_state(WindowId id, const WindowState &state)
Restore window state from a previous snapshot.
WindowManager(const WindowManager &)=delete
WindowManager & operator=(const WindowManager &)=delete
std::vector< WindowId > children_of(WindowId parent_id) const
Get children of a given window.
void set_message_handler(WindowId id, MessageHandler handler)
Register a message handler for a window. Replaces any previous handler.
void * shared_gpu_device() const
Get the shared GPU device handle. Returns nullptr if not set.
void unregister_window(WindowId id)
Remove a window from the registry.
void send_message(WindowId target, const WindowMessage &msg)
Send a message to a specific window.
WindowId register_window(WindowHost *host, View *root_view, WindowType type, WindowId parent_id=0)
Register a window with the manager.
void set_shared_theme(const Theme &theme)
Set the shared theme.
const Theme & shared_theme() const
Get the current shared theme.
std::vector< WindowId > window_ids() const
Get all active window IDs.
static bool is_multi_window_supported()
Whether the current platform supports multi-window.
size_t window_count() const
Count of active windows.
void close_window(WindowId id)
Close a window and all its children (depth-first).
const WindowRecord * window(WindowId id) const
Get the record for a window (nullptr if not found).
static std::vector< ScreenInfo > available_screens()
Enumerate available screens/monitors. Platform-specific.
void set_shared_gpu_device(void *device_handle)
Set the shared GPU device handle (Dawn wgpu::Device*).
void broadcast_message(const WindowMessage &msg)
Broadcast a message to all windows.
static ScreenInfo primary_screen()
Get info for the primary screen.
std::unordered_map< WindowId, WindowState > save_all_states() const
Snapshot the current state of all windows (positions, sizes, screens).
Bounded event contracts shared by host ingress and graph-authored nodes.
Definition anticipation_eligibility.hpp:9
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
std::function< void(const WindowMessage &)> MessageHandler
Definition window_manager.hpp:68
WindowType
Definition window_manager.hpp:17
@ palette
Floating palette (stays on top, no taskbar entry).
Definition window_manager.hpp:19
@ inspector
Resizable inspector panel.
Definition window_manager.hpp:20
@ popup
Ephemeral popup/dropdown (auto-dismiss on focus loss).
Definition window_manager.hpp:21
@ dialog
Modal or modeless dialog.
Definition window_manager.hpp:22
@ main
Primary editor window.
Definition window_manager.hpp:18
@ type
Built-in / common type name (e.g. int, Number).
Definition code_editor_tokenizer.hpp:39
uint32_t WindowId
Definition window_manager.hpp:48
Definition window_manager.hpp:27
float scale_factor
HiDPI scale (e.g. 2.0 for Retina).
Definition window_manager.hpp:32
float y
Origin in global coordinates.
Definition window_manager.hpp:29
float width
Logical width.
Definition window_manager.hpp:30
float height
Logical height.
Definition window_manager.hpp:31
bool is_primary
Whether this is the main/primary screen.
Definition window_manager.hpp:33
std::string name
Human-readable name (e.g. "Built-in Retina Display").
Definition window_manager.hpp:34
float x
Definition window_manager.hpp:29
Definition theme.hpp:32
Definition window_manager.hpp:62
WindowId source
Sender window (0 = broadcast).
Definition window_manager.hpp:65
std::string type
Message type identifier.
Definition window_manager.hpp:63
std::string payload
JSON or string payload.
Definition window_manager.hpp:64
Definition window_manager.hpp:50
WindowId parent_id
0 = no parent (root window)
Definition window_manager.hpp:53
WindowType type
Definition window_manager.hpp:52
WindowState state
Definition window_manager.hpp:56
bool alive
Definition window_manager.hpp:57
View * root_view
Root view for this window.
Definition window_manager.hpp:55
WindowHost * host
Non-owning — caller owns the WindowHost.
Definition window_manager.hpp:54
Definition window_manager.hpp:39
float y
Definition window_manager.hpp:40
int screen_id
Which screen the window was on.
Definition window_manager.hpp:42
float x
Definition window_manager.hpp:40
bool is_visible
Definition window_manager.hpp:43
float width
Definition window_manager.hpp:41
float height
Definition window_manager.hpp:41