From 3dc131d4faf67bd0c57a340e39037a6279dc4ce7 Mon Sep 17 00:00:00 2001 From: iddev5 Date: Fri, 10 Jun 2022 23:36:06 +0530 Subject: [PATCH] mach: Implement fullscreen window support for native platforms (glfw) This feature remembers the last position of window before turning to fullscreen. --- src/platform/native.zig | 12 ++++++++++++ src/structs.zig | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/platform/native.zig b/src/platform/native.zig index e910a499..61b63235 100644 --- a/src/platform/native.zig +++ b/src/platform/native.zig @@ -17,6 +17,7 @@ pub const Platform = struct { last_window_size: structs.Size, last_framebuffer_size: structs.Size, + last_position: glfw.Window.Pos, wait_event_timeout: f64 = 0.0, native_instance: gpu.NativeInstance, @@ -178,6 +179,7 @@ pub const Platform = struct { .allocator = engine.allocator, .last_window_size = .{ .width = window_size.width, .height = window_size.height }, .last_framebuffer_size = .{ .width = framebuffer_size.width, .height = framebuffer_size.height }, + .last_position = try window.getPos(), .native_instance = native_instance, }; } @@ -292,6 +294,16 @@ pub const Platform = struct { @bitCast(glfw.Window.SizeOptional, options.size_min), @bitCast(glfw.Window.SizeOptional, options.size_max), ); + if (options.fullscreen) { + platform.last_position = try platform.window.getPos(); + + const monitor = glfw.Monitor.getPrimary().?; + const video_mode = try monitor.getVideoMode(); + try platform.window.setMonitor(monitor, 0, 0, video_mode.getWidth(), video_mode.getHeight(), null); + } else { + const position = platform.last_position; + try platform.window.setMonitor(null, position.x, position.y, options.width, options.height, null); + } } pub fn setShouldClose(platform: *Platform, value: bool) void { diff --git a/src/structs.zig b/src/structs.zig index 32feefa8..512377ab 100644 --- a/src/structs.zig +++ b/src/structs.zig @@ -31,6 +31,9 @@ pub const Options = struct { /// The maximum allowed size for the window. size_max: SizeOptional = .{ .width = null, .height = null }, + /// Fullscreen window. + fullscreen: bool = false, + /// Monitor synchronization modes. vsync: enums.VSyncMode = .double,