From 10eb3b56808940b48c637921abf2dc757cb1a662 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 16 Jul 2021 16:42:03 -0700 Subject: [PATCH] glfw: add monitors.getPrimary Signed-off-by: Stephen Gutekanst --- glfw/src/Monitor.zig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/glfw/src/Monitor.zig b/glfw/src/Monitor.zig index 6d1503c5..4b707476 100644 --- a/glfw/src/Monitor.zig +++ b/glfw/src/Monitor.zig @@ -35,8 +35,30 @@ pub fn getAll(allocator: *mem.Allocator) ![]Monitor { return slice; } +/// Returns the primary monitor. +/// +/// This function returns the primary monitor. This is usually the monitor where elements like +/// the task bar or global menu bar are located. +/// +/// Possible errors include glfw.Error.NotInitialized. +/// +/// @thread_safety This function must only be called from the main thread. +/// +/// see also: monitor_monitors, glfw.monitors.getAll +pub fn getPrimary() !?Monitor { + const handle = c.glfwGetPrimaryMonitor(); + if (handle == null) { + return null; + } + return Monitor{ .handle = handle }; +} + test "getAll" { const allocator = testing.allocator; const monitors = try getAll(allocator); defer allocator.free(monitors); } + +test "getPrimary" { + _ = try getPrimary(); +}