glfw: add Monitor.getPos

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-07-16 16:57:50 -07:00
parent 8ade50719d
commit cfcd97d167

View file

@ -12,6 +12,30 @@ const Monitor = @This();
handle: *c.GLFWmonitor, handle: *c.GLFWmonitor,
/// A monitor position, in screen coordinates, of the upper left corner of the monitor on the
/// virtual screen.
const Pos = struct {
/// The x coordinate.
x: isize,
/// The y coordinate.
y: isize,
};
/// Returns the position of the monitor's viewport on the virtual screen.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: monitor_properties
pub fn getPos(self: Monitor) !Pos {
var xpos: c_int = 0;
var ypos: c_int = 0;
c.glfwGetMonitorPos(self.handle, &xpos, &ypos);
try getError();
return Pos{ .x = xpos, .y = ypos };
}
/// Returns the currently connected monitors. /// Returns the currently connected monitors.
/// ///
/// This function returns a slice of all currently connected monitors. The primary monitor is /// This function returns a slice of all currently connected monitors. The primary monitor is
@ -63,3 +87,10 @@ test "getAll" {
test "getPrimary" { test "getPrimary" {
_ = try getPrimary(); _ = try getPrimary();
} }
test "getPos" {
const monitor = try getPrimary();
if (monitor) |m| {
_ = try m.getPos();
}
}