glfw: add Monitor.getName function

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-07-17 12:19:46 -07:00
parent 57c9ae9a40
commit d57a53df49

View file

@ -125,6 +125,24 @@ pub fn getContentScale(self: Monitor) Error!ContentScale {
return ContentScale{ .x_scale = @floatCast(f32, x_scale), .y_scale = @floatCast(f32, y_scale) };
}
/// Returns the name of the specified monitor.
///
/// This function returns a human-readable name, encoded as UTF-8, of the specified monitor. The
/// name typically reflects the make and model of the monitor and is not guaranteed to be unique
/// among the connected monitors.
///
/// Possible errors include glfw.Error.NotInitialized.
///
/// @pointer_lifetime The returned string is allocated and freed by GLFW. You should not free it
/// yourself. It is valid until the specified monitor is disconnected or the library is terminated.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: monitor_properties
pub fn getName(self: Monitor) Error![*c]const u8 {
return c.glfwGetMonitorName(self.handle);
}
/// Returns the currently connected monitors.
///
/// This function returns a slice of all currently connected monitors. The primary monitor is
@ -204,3 +222,10 @@ test "getContentScale" {
_ = try m.getContentScale();
}
}
test "getName" {
const monitor = try getPrimary();
if (monitor) |m| {
_ = try m.getName();
}
}