glfw: add monitor.getWorkarea
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
cfcd97d167
commit
d9797481d2
1 changed files with 41 additions and 4 deletions
|
|
@ -16,9 +16,9 @@ handle: *c.GLFWmonitor,
|
||||||
/// virtual screen.
|
/// virtual screen.
|
||||||
const Pos = struct {
|
const Pos = struct {
|
||||||
/// The x coordinate.
|
/// The x coordinate.
|
||||||
x: isize,
|
x: usize,
|
||||||
/// The y coordinate.
|
/// The y coordinate.
|
||||||
y: isize,
|
y: usize,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Returns the position of the monitor's viewport on the virtual screen.
|
/// Returns the position of the monitor's viewport on the virtual screen.
|
||||||
|
|
@ -28,12 +28,42 @@ const Pos = struct {
|
||||||
/// @thread_safety This function must only be called from the main thread.
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
///
|
///
|
||||||
/// see also: monitor_properties
|
/// see also: monitor_properties
|
||||||
pub fn getPos(self: Monitor) !Pos {
|
pub fn getPos(self: Monitor) Error!Pos {
|
||||||
var xpos: c_int = 0;
|
var xpos: c_int = 0;
|
||||||
var ypos: c_int = 0;
|
var ypos: c_int = 0;
|
||||||
c.glfwGetMonitorPos(self.handle, &xpos, &ypos);
|
c.glfwGetMonitorPos(self.handle, &xpos, &ypos);
|
||||||
try getError();
|
try getError();
|
||||||
return Pos{ .x = xpos, .y = ypos };
|
return Pos{ .x = @intCast(usize, xpos), .y = @intCast(usize, ypos) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The monitor workarea, in screen coordinates.
|
||||||
|
///
|
||||||
|
/// This is the position of the upper-left corner of the work area of the monitor, along with the
|
||||||
|
/// work area size. The work area is defined as the area of the monitor not occluded by the
|
||||||
|
/// operating system task bar where present. If no task bar exists then the work area is the
|
||||||
|
/// monitor resolution in screen coordinates.
|
||||||
|
const Workarea = struct {
|
||||||
|
x: usize,
|
||||||
|
y: usize,
|
||||||
|
width: usize,
|
||||||
|
height: usize,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Retrieves the work area of the monitor.
|
||||||
|
///
|
||||||
|
/// 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_workarea
|
||||||
|
pub fn getWorkarea(self: Monitor) Error!Workarea {
|
||||||
|
var xpos: c_int = 0;
|
||||||
|
var ypos: c_int = 0;
|
||||||
|
var width: c_int = 0;
|
||||||
|
var height: c_int = 0;
|
||||||
|
c.glfwGetMonitorWorkarea(self.handle, &xpos, &ypos, &width, &height);
|
||||||
|
try getError();
|
||||||
|
return Workarea{ .x = @intCast(usize, xpos), .y = @intCast(usize, ypos), .width = @intCast(usize, width), .height = @intCast(usize, height) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the currently connected monitors.
|
/// Returns the currently connected monitors.
|
||||||
|
|
@ -94,3 +124,10 @@ test "getPos" {
|
||||||
_ = try m.getPos();
|
_ = try m.getPos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "getWorkarea" {
|
||||||
|
const monitor = try getPrimary();
|
||||||
|
if (monitor) |m| {
|
||||||
|
_ = try m.getWorkarea();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue