From 349462cb77eaaa8f801d2c57ed478a3313424121 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 17 Jul 2021 21:37:53 -0700 Subject: [PATCH] glfw: add Monitor.getGammaRamp Signed-off-by: Stephen Gutekanst --- glfw/src/Monitor.zig | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/glfw/src/Monitor.zig b/glfw/src/Monitor.zig index 94c80837..c2ad81f5 100644 --- a/glfw/src/Monitor.zig +++ b/glfw/src/Monitor.zig @@ -7,6 +7,7 @@ const c = @import("c.zig").c; const Error = @import("errors.zig").Error; const getError = @import("errors.zig").getError; +const GammaRamp = @import("GammaRamp.zig"); const VideoMode = @import("VideoMode.zig"); const Monitor = @This(); @@ -250,6 +251,27 @@ pub fn setGamma(self: Monitor, gamma: f32) Error!void { try getError(); } +/// Returns the current gamma ramp for the specified monitor. +/// +/// This function returns the current gamma ramp of the specified monitor. +/// +/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError. +/// +/// wayland: Gamma handling is a privileged protocol, this function will thus never be implemented +/// and returns glfw.Error.PlatformError. +/// +/// The returned gamma ramp is `.owned = true` by GLFW, and is valid until the monitor is +/// disconnected, this function is called again, or `glfw.terminate()` is called. +/// +/// @thread_safety This function must only be called from the main thread. +/// +/// see also: monitor_gamma +pub fn getGammaRamp(self: Monitor) Error!GammaRamp { + const ramp = c.glfwGetGammaRamp(self.handle); + try getError(); + return GammaRamp.fromC(ramp.*); +} + /// Returns the currently connected monitors. /// /// This function returns a slice of all currently connected monitors. The primary monitor is @@ -468,3 +490,18 @@ test "getVideoMode" { _ = try m.getVideoMode(); } } + +test "getGammaRamp" { + const allocator = testing.allocator; + const glfw = @import("main.zig"); + try glfw.init(); + defer glfw.terminate(); + + const monitor = try getPrimary(); + if (monitor) |m| { + const ramp = try m.getGammaRamp(); + + // technically not needed here / noop because GLFW owns this gamma ramp. + defer ramp.deinit(allocator); + } +} \ No newline at end of file