mach: Implement fullscreen window support for native platforms (glfw)
This feature remembers the last position of window before turning to fullscreen.
This commit is contained in:
parent
d3feaed383
commit
3dc131d4fa
2 changed files with 15 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue