6#ifdef MAYAFLUX_PLATFORM_WINDOWS
7#define GLFW_EXPOSE_NATIVE_WIN32
8#include <GLFW/glfw3native.h>
9#elif MAYAFLUX_PLATFORM_LINUX
10#include <GLFW/glfw3native.h>
11#elif MAYAFLUX_PLATFORM_MACOS
12#define GLFW_EXPOSE_NATIVE_COCOA
13#include <GLFW/glfw3native.h>
20 : m_create_info(create_info)
26 "Failed to initialize GLFW for window creation");
31 GLFWmonitor* monitor =
nullptr;
35 std::span<GLFWmonitor*> monitors(glfwGetMonitors(&count), count);
40 monitor = glfwGetPrimaryMonitor();
47 create_info.
title.c_str(),
53 "Failed to create GLFW window: {}", create_info.
title);
56 glfwSetWindowUserPointer(
m_window,
this);
68 "Created window '{}' ({}x{})", create_info.
title, w, h);
86 : m_window(other.m_window)
87 , m_create_info(std::move(other.m_create_info))
88 , m_state(other.m_state)
89 , m_input_config(other.m_input_config)
90 , m_event_callback(std::move(other.m_event_callback))
92 other.m_window =
nullptr;
94 glfwSetWindowUserPointer(m_window,
this);
100 if (
this != &other) {
102 glfwDestroyWindow(m_window);
106 m_window = other.m_window;
107 m_create_info = std::move(other.m_create_info);
108 m_state = other.m_state;
109 m_input_config = other.m_input_config;
110 m_event_callback = std::move(other.m_event_callback);
112 other.m_window =
nullptr;
114 glfwSetWindowUserPointer(m_window,
this);
123 glfwSetWindowTitle(
m_window, title.c_str());
130 glfwDefaultWindowHints();
132#ifdef MAYAFLUX_PLATFORM_MACOS
133 glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
141 glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
144 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
146 glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
193#ifdef MAYAFLUX_PLATFORM_WINDOWS
194 return glfwGetWin32Window(
m_window);
195#elif MAYAFLUX_PLATFORM_LINUX
196#if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
197 if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
198 return glfwGetWaylandWindow(
m_window);
201#if defined(GLFW_EXPOSE_NATIVE_X11)
202 if (glfwGetPlatform() == GLFW_PLATFORM_X11) {
203 return reinterpret_cast<void*
>(glfwGetX11Window(
m_window));
207#elif MAYAFLUX_PLATFORM_MACOS
208 return glfwGetCocoaWindow(
m_window);
216#ifdef MAYAFLUX_PLATFORM_LINUX
217#if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
218 if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
219 return glfwGetWaylandDisplay();
222#if defined(GLFW_EXPOSE_NATIVE_X11)
223 if (glfwGetPlatform() == GLFW_PLATFORM_X11) {
224 return glfwGetX11Display();
233 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
234 if (win && win->m_event_callback) {
236 win->m_state.current_height = height;
238 if (win->m_event_callback) {
241 event.timestamp = glfwGetTime();
243 .
width =
static_cast<uint32_t
>(width),
244 .height =
static_cast<uint32_t
>(height)
246 win->m_event_callback(event);
254 glfwSetWindowSize(
m_window,
static_cast<int>(width),
static_cast<int>(height));
264 glfwSetWindowPos(
m_window,
static_cast<int>(x),
static_cast<int>(y));
270 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
276 event.timestamp = glfwGetTime();
278 win->m_event_source.signal(event);
280 if (win->m_event_callback) {
281 win->m_event_callback(event);
287 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
296 event.timestamp = glfwGetTime();
298 win->m_event_source.signal(event);
300 if (win->m_event_callback) {
301 win->m_event_callback(event);
307 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
313 event.timestamp = glfwGetTime();
315 .
width =
static_cast<uint32_t
>(width),
316 .height =
static_cast<uint32_t
>(height)
319 win->m_event_source.signal(event);
321 if (win->m_event_callback) {
322 win->m_event_callback(event);
328 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
349 event.timestamp = glfwGetTime();
352 .scancode = scancode,
356 win->m_event_source.signal(event);
358 if (win->m_event_callback) {
359 win->m_event_callback(event);
365 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
371 event.timestamp = glfwGetTime();
378 win->m_event_source.signal(event);
380 if (win->m_event_callback) {
381 win->m_event_callback(event);
387 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
394 event.timestamp = glfwGetTime();
401 win->m_event_source.signal(event);
403 if (win->m_event_callback) {
404 win->m_event_callback(event);
410 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
416 event.timestamp = glfwGetTime();
422 win->m_event_source.signal(event);
424 if (win->m_event_callback) {
425 win->m_event_callback(event);
437 if (
auto buf = weak_buf.lock()) {
448 "Window '{}': registered VKBuffer for rendering (total: {})",
455 [&buffer](
const std::weak_ptr<Buffers::VKBuffer>& weak_buf) {
456 auto buf = weak_buf.lock();
457 return buf == buffer;
472 "Window '{}': tracked command buffer {} (total this frame: {})",
491 std::vector<std::shared_ptr<Buffers::VKBuffer>> buffers;
493 if (
auto buf = weak_buf.lock()) {
494 buffers.push_back(buf);
#define MF_INFO(comp, ctx,...)
#define MF_RT_TRACE(comp, ctx,...)
#define MF_RT_DEBUG(comp, ctx,...)
static void mark_window_created()
Increments the count of active GLFW windows.
static void mark_window_destroyed()
Decrements the count of active GLFW windows.
static bool initialize()
Initializes the GLFW library if not already initialized.
static void configure(const GlfwPreInitConfig &config)
Configures GLFW with pre-initialization hints.
void clear_frame_commands() override
Clear tracked commands for this frame.
void register_rendering_buffer(std::shared_ptr< Buffers::VKBuffer > buffer) override
Register a VKBuffer as rendering to this window.
std::vector< std::weak_ptr< Buffers::VKBuffer > > m_rendering_buffers
bool should_close() const override
Poll for window events (non-blocking)
void * get_native_display() const override
Get native display handle (platform-specific)
static void glfw_scroll_callback(GLFWwindow *window, double xoffset, double yoffset)
void set_graphics_registered(bool registered) override
Mark window as registered/unregistered with graphics Called by GraphicsSubsystem during register/unre...
static void glfw_key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
WindowCreateInfo m_create_info
static void glfw_cursor_pos_callback(GLFWwindow *window, double xpos, double ypos)
void * get_native_handle() const override
Get native window handle (platform-specific)
void show() override
Show the window.
void set_title(const std::string &title) override
Set window title, size, or position.
static void glfw_window_size_callback(GLFWwindow *window, int width, int height)
const std::vector< uint64_t > & get_frame_commands() const override
Get all command buffers recorded for this frame.
void set_position(uint32_t x, uint32_t y) override
Move the window to a new position.
void set_event_callback(WindowEventCallback callback) override
Set the callback function for window events.
void destroy() override
Destroy the window and release resources.
std::atomic< bool > m_graphics_registered
static void glfw_window_focus_callback(GLFWwindow *window, int focused)
void unregister_rendering_buffer(std::shared_ptr< Buffers::VKBuffer > buffer) override
Unregister a VKBuffer from this window.
GlfwWindow & operator=(const GlfwWindow &)=delete
static void glfw_mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
void track_frame_command(uint64_t cmd_id) override
Track a secondary command buffer for this frame.
void hide() override
Hide the window.
void configure_window_hints(const GraphicsSurfaceInfo &surface_info, GlobalGraphicsConfig::GraphicsApi api) const
std::vector< std::shared_ptr< Buffers::VKBuffer > > get_rendering_buffers() const override
Get all VKBuffers currently rendering to this window.
static void glfw_window_close_callback(GLFWwindow *window)
void set_size(uint32_t width, uint32_t height) override
Resize the window.
std::vector< uint64_t > m_frame_commands
static void glfw_framebuffer_size_callback(GLFWwindow *window, int width, int height)
WindowEventCallback m_event_callback
std::mutex m_render_tracking_mutex
GlfwWindow(const WindowCreateInfo &create_info, const GraphicsSurfaceInfo &surface_info, GlobalGraphicsConfig::GraphicsApi api, GlfwPreInitConfig pre_init_config={})
Creates a window with the given configuration.
Platform-agnostic window wrapper.
WindowEventType
Types of window and input events.
std::function< void(const WindowEvent &)> WindowEventCallback
@ WindowingSubsystem
Windowing system operations (GLFW, SDL)
@ GraphicsCallback
Graphics/visual rendering callback - frame-rate real-time.
@ Core
Core engine, backend, subsystems.
Configuration hints for GLFW initialization.
System-wide configuration for visual stream processing.
bool transparent
Transparent framebuffer (compositing)
std::string title
Window title/identifier.
bool fullscreen
Start in fullscreen mode.
bool floating
Window always on top.
bool resizable
Window can be resized by user.
uint32_t width
Initial window dimensions.
int32_t monitor_id
Target monitor ID (-1 = primary monitor)
bool decorated
Show OS window decorations (title bar, borders)
Configuration for creating a single window instance.
Event data for window and input events.