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);
81 : m_window(other.m_window)
82 , m_create_info(std::move(other.m_create_info))
83 , m_state(other.m_state)
84 , m_input_config(other.m_input_config)
85 , m_event_callback(std::move(other.m_event_callback))
87 other.m_window =
nullptr;
89 glfwSetWindowUserPointer(m_window,
this);
97 glfwDestroyWindow(m_window);
101 m_window = other.m_window;
102 m_create_info = std::move(other.m_create_info);
103 m_state = other.m_state;
104 m_input_config = other.m_input_config;
105 m_event_callback = std::move(other.m_event_callback);
107 other.m_window =
nullptr;
109 glfwSetWindowUserPointer(m_window,
this);
118 glfwSetWindowTitle(
m_window, title.c_str());
125 glfwDefaultWindowHints();
131 glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
134 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
136 glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
183#ifdef MAYAFLUX_PLATFORM_WINDOWS
184 return glfwGetWin32Window(
m_window);
185#elif MAYAFLUX_PLATFORM_LINUX
186#if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
187 if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
188 return glfwGetWaylandWindow(
m_window);
191#if defined(GLFW_EXPOSE_NATIVE_X11)
192 if (glfwGetPlatform() == GLFW_PLATFORM_X11) {
193 return reinterpret_cast<void*
>(glfwGetX11Window(
m_window));
197#elif MAYAFLUX_PLATFORM_MACOS
198 return glfwGetCocoaWindow(
m_window);
206#ifdef MAYAFLUX_PLATFORM_LINUX
207#if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
208 if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
209 return glfwGetWaylandDisplay();
212#if defined(GLFW_EXPOSE_NATIVE_X11)
213 if (glfwGetPlatform() == GLFW_PLATFORM_X11) {
214 return glfwGetX11Display();
223 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
224 if (win && win->m_event_callback) {
226 win->m_state.current_height = height;
228 if (win->m_event_callback) {
231 event.timestamp = glfwGetTime();
233 .
width =
static_cast<uint32_t
>(width),
234 .height =
static_cast<uint32_t
>(height)
236 win->m_event_callback(event);
244 glfwSetWindowSize(
m_window,
static_cast<int>(width),
static_cast<int>(height));
254 glfwSetWindowPos(
m_window,
static_cast<int>(x),
static_cast<int>(y));
260 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
266 event.timestamp = glfwGetTime();
268 win->m_event_source.signal(event);
270 if (win->m_event_callback) {
271 win->m_event_callback(event);
277 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
286 event.timestamp = glfwGetTime();
288 win->m_event_source.signal(event);
290 if (win->m_event_callback) {
291 win->m_event_callback(event);
297 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
303 event.timestamp = glfwGetTime();
305 .
width =
static_cast<uint32_t
>(width),
306 .height =
static_cast<uint32_t
>(height)
309 win->m_event_source.signal(event);
311 if (win->m_event_callback) {
312 win->m_event_callback(event);
318 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
339 event.timestamp = glfwGetTime();
342 .scancode = scancode,
346 win->m_event_source.signal(event);
348 if (win->m_event_callback) {
349 win->m_event_callback(event);
355 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
361 event.timestamp = glfwGetTime();
368 win->m_event_source.signal(event);
370 if (win->m_event_callback) {
371 win->m_event_callback(event);
377 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
384 event.timestamp = glfwGetTime();
391 win->m_event_source.signal(event);
393 if (win->m_event_callback) {
394 win->m_event_callback(event);
400 auto* win =
static_cast<GlfwWindow*
>(glfwGetWindowUserPointer(window));
406 event.timestamp = glfwGetTime();
412 win->m_event_source.signal(event);
414 if (win->m_event_callback) {
415 win->m_event_callback(event);
#define MF_INFO(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 terminate()
Terminates the GLFW library if initialized and no windows remain.
static void configure(const GlfwPreInitConfig &config)
Configures GLFW with pre-initialization hints.
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)
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.
std::atomic< bool > m_graphics_registered
static void glfw_window_focus_callback(GLFWwindow *window, int focused)
GlfwWindow & operator=(const GlfwWindow &)=delete
static void glfw_mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
void hide() override
Hide the window.
void configure_window_hints(const GraphicsSurfaceInfo &surface_info, GlobalGraphicsConfig::GraphicsApi api) const
static void glfw_window_close_callback(GLFWwindow *window)
void set_size(uint32_t width, uint32_t height) override
Resize the window.
static void glfw_framebuffer_size_callback(GLFWwindow *window, int width, int height)
WindowEventCallback m_event_callback
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)
@ 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.