glfw: add Window.setMonitor

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-10-17 22:42:16 -07:00 committed by Stephen Gutekanst
parent 06e114c2dd
commit ceec340d95

View file

@ -951,56 +951,62 @@ pub inline fn swapBuffers(self: Window) Error!void {
// /// // ///
// GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window); // 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.
// /// ///
// /// This function sets the monitor that the window uses for full screen mode or, /// This function sets the monitor that the window uses for full screen mode or, if the monitor is
// /// if the monitor is null, makes it windowed mode. /// null, makes it windowed mode.
// /// ///
// /// When setting a monitor, this function updates the width, height and refresh /// When setting a monitor, this function updates the width, height and refresh rate of the desired
// /// rate of the desired video mode and switches to the video mode closest to it. /// video mode and switches to the video mode closest to it. The window position is ignored when
// /// The window position is ignored when setting a monitor. /// setting a monitor.
// /// ///
// /// When the monitor is null, the position, width and height are used to /// When the monitor is null, the position, width and height are used to place the window content
// /// place the window content area. The refresh rate is ignored when no monitor /// area. The refresh rate is ignored when no monitor is specified.
// /// is specified. ///
// /// /// If you only wish to update the resolution of a full screen window or the size of a windowed
// /// If you only wish to update the resolution of a full screen window or the /// mode window, see @ref glfwSetWindowSize.
// /// size of a windowed mode window, see @ref glfwSetWindowSize. ///
// /// /// When a window transitions from full screen to windowed mode, this function restores any
// /// When a window transitions from full screen to windowed mode, this function /// previous window settings such as whether it is decorated, floating, resizable, has size or
// /// restores any previous window settings such as whether it is decorated, /// aspect ratio limits, etc.
// /// floating, resizable, has size or aspect ratio limits, etc. ///
// /// /// @param[in] window The window whose monitor, size or video mode to set.
// /// @param[in] window The window whose monitor, size or video mode to set. /// @param[in] monitor The desired monitor, or null to set windowed mode.
// /// @param[in] monitor The desired monitor, or null to set windowed mode. /// @param[in] xpos The desired x-coordinate of the upper-left corner of the content area.
// /// @param[in] xpos The desired x-coordinate of the upper-left corner of the /// @param[in] ypos The desired y-coordinate of the upper-left corner of the content area.
// /// content area. /// @param[in] width The desired with, in screen coordinates, of the content area or video mode.
// /// @param[in] ypos The desired y-coordinate of the upper-left corner of the /// @param[in] height The desired height, in screen coordinates, of the content area or video mode.
// /// content area. /// @param[in] refreshRate The desired refresh rate, in Hz, of the video mode, or `glfw.dont_care`.
// /// @param[in] width The desired with, in screen coordinates, of the content ///
// /// area or video mode. /// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
// /// @param[in] height The desired height, in screen coordinates, of the content ///
// /// area or video mode. /// The OpenGL or OpenGL ES context will not be destroyed or otherwise affected by any resizing or
// /// @param[in] refreshRate The desired refresh rate, in Hz, of the video mode, /// mode switching, although you may need to update your viewport if the framebuffer size has
// /// or `GLFW_DONT_CARE`. /// changed.
// /// ///
// /// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError. /// wayland: The desired window position is ignored, as there is no way for an application to set
// /// /// this property.
// /// The OpenGL or OpenGL ES context will not be destroyed or otherwise ///
// /// affected by any resizing or mode switching, although you may need to update /// wayland: Setting the window to full screen will not attempt to change the mode, no matter what
// /// your viewport if the framebuffer size has changed. /// the requested size or refresh rate.
// /// ///
// /// wayland: The desired window position is ignored, as there is no way /// @thread_safety This function must only be called from the main thread.
// /// for an application to set this property. ///
// /// /// see also: window_monitor, window_full_screen, glfw.Window.getMonitor, glfw.Window.setSize
// /// wayland: Setting the window to full screen will not attempt to pub inline fn setMonitor(self: Window, monitor: ?Monitor, xpos: isize, ypos: isize, width: isize, height: isize, refresh_rate: isize) Error!void {
// /// change the mode, no matter what the requested size or refresh rate. c.glfwSetWindowMonitor(
// /// self.handle,
// /// @thread_safety This function must only be called from the main thread. if (monitor) |m| m.handle else null,
// /// @intCast(c_int, xpos),
// /// see also: window_monitor, window_full_screen, glfw.Window.getMonitor, glfw.Window.setSize @intCast(c_int, ypos),
// /// @intCast(c_int, width),
// GLFWAPI void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); @intCast(c_int, height),
@intCast(c_int, refresh_rate),
);
try getError();
}
// TODO(window):
// /// Returns an attribute of the specified window. // /// Returns an attribute of the specified window.
// /// // ///
@ -1811,3 +1817,19 @@ test "swapBuffers" {
_ = try window.swapBuffers(); _ = try window.swapBuffers();
} }
test "setMonitor" {
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.setMonitor(null, 10, 10, 640, 480, 60) catch |err| std.debug.print("can't set monitor, not supported by OS maybe? error={}\n", .{err});
}