glfw: add Window.getMonitor

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-10-18 01:03:11 -07:00 committed by Stephen Gutekanst
parent a98e437bcd
commit d0fb09be91

View file

@ -822,24 +822,23 @@ pub inline fn swapBuffers(self: Window) Error!void {
try getError(); try getError();
} }
// TODO(window): /// Returns the monitor that the window uses for full screen mode.
///
// /// Returns the monitor that the window uses for full screen mode. /// This function returns the handle of the monitor that the specified window is in full screen on.
// /// ///
// /// This function returns the handle of the monitor that the specified window is /// @return The monitor, or null if the window is in windowed mode.
// /// in full screen on. ///
// /// /// Possible errors include glfw.Error.NotInitialized.
// /// @param[in] window The window to query. ///
// /// @return The monitor, or null if the window is in windowed mode or an /// @thread_safety This function must only be called from the main thread.
// /// error occurred. ///
// /// /// see also: window_monitor, glfw.Window.setMonitor
// /// Possible errors include glfw.Error.NotInitialized. pub inline fn getMonitor(self: Window) Error!?Monitor {
// /// const monitor = c.glfwGetWindowMonitor(self.handle);
// /// @thread_safety This function must only be called from the main thread. try getError();
// /// if (monitor) |m| return Monitor{ .handle = m };
// /// see also: window_monitor, glfw.Window.setMonitor return null;
// /// }
// GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window);
/// Sets the mode, monitor, video mode and placement of a window. /// Sets the mode, monitor, video mode and placement of a window.
/// ///
@ -1750,6 +1749,22 @@ test "swapBuffers" {
_ = try window.swapBuffers(); _ = try window.swapBuffers();
} }
test "getMonitor" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
const window = glfw.Window.create(640, 480, "Hello, Zig!", null, null) catch |err| {
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std.debug.print("note: failed to create window: {}\n", .{err});
return;
};
defer window.destroy();
_ = window.getMonitor() catch |err| std.debug.print("can't get monitor, not supported by OS maybe? error={}\n", .{err});
}
test "setMonitor" { test "setMonitor" {
const glfw = @import("main.zig"); const glfw = @import("main.zig");
try glfw.init(); try glfw.init();