glfw: 100% usable via package manager
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
93a6c333b9
commit
ddb1cf1cb7
15 changed files with 95 additions and 248 deletions
6
.gitmodules
vendored
6
.gitmodules
vendored
|
@ -1,6 +0,0 @@
|
||||||
[submodule "libs/xcode-frameworks"]
|
|
||||||
path = libs/xcode-frameworks
|
|
||||||
url = https://github.com/hexops/xcode-frameworks
|
|
||||||
[submodule "upstream"]
|
|
||||||
path = upstream
|
|
||||||
url = https://github.com/hexops-graveyard/glfw
|
|
170
build.zig
170
build.zig
|
@ -73,120 +73,17 @@ pub fn module(b: *std.Build) *std.build.Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link(b: *Build, step: *std.build.CompileStep, options: Options) !void {
|
pub fn link(b: *Build, step: *std.build.CompileStep, options: Options) !void {
|
||||||
if (options.shared) step.defineCMacro("GLFW_DLL", null);
|
_ = options;
|
||||||
const lib = try buildLibrary(b, step.optimize, step.target, options);
|
step.linkLibrary(b.dependency("glfw", .{
|
||||||
step.linkLibrary(lib);
|
|
||||||
addGLFWIncludes(step);
|
|
||||||
linkGLFWDependencies(b, step, options);
|
|
||||||
if (step.target_info.target.os.tag == .macos) {
|
|
||||||
// TODO(build-system): This cannot be imported with the Zig package manager
|
|
||||||
// error: TarUnsupportedFileType
|
|
||||||
//
|
|
||||||
// step.linkLibrary(b.dependency("xcode_frameworks", .{
|
|
||||||
// .target = step.target,
|
|
||||||
// .optimize = step.optimize,
|
|
||||||
// }).artifact("xcode-frameworks"));
|
|
||||||
// @import("xcode_frameworks").addPaths(step);
|
|
||||||
xcode_frameworks.addPaths(b, step);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn buildLibrary(b: *Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget, options: Options) !*std.build.CompileStep {
|
|
||||||
// TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
|
|
||||||
ensureDependencySubmodule(b.allocator, "upstream") catch return error.CannotEnsureDependency;
|
|
||||||
|
|
||||||
const lib = if (options.shared)
|
|
||||||
b.addSharedLibrary(.{ .name = "glfw", .target = target, .optimize = optimize })
|
|
||||||
else
|
|
||||||
b.addStaticLibrary(.{ .name = "glfw", .target = target, .optimize = optimize });
|
|
||||||
|
|
||||||
if (options.shared)
|
|
||||||
lib.defineCMacro("_GLFW_BUILD_DLL", null);
|
|
||||||
|
|
||||||
addGLFWIncludes(lib);
|
|
||||||
try addGLFWSources(b, lib, options);
|
|
||||||
linkGLFWDependencies(b, lib, options);
|
|
||||||
|
|
||||||
if (options.install_libs)
|
|
||||||
b.installArtifact(lib);
|
|
||||||
|
|
||||||
return lib;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn addGLFWIncludes(step: *std.build.CompileStep) void {
|
|
||||||
step.addIncludePath(sdkPath("/upstream/glfw/include"));
|
|
||||||
step.addIncludePath(sdkPath("/src"));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn addGLFWSources(b: *Build, lib: *std.build.CompileStep, options: Options) std.mem.Allocator.Error!void {
|
|
||||||
const include_glfw_src = comptime "-I" ++ sdkPath("/upstream/glfw/src");
|
|
||||||
switch (lib.target_info.target.os.tag) {
|
|
||||||
.windows => lib.addCSourceFiles(&.{
|
|
||||||
sdkPath("/src/sources_all.c"),
|
|
||||||
sdkPath("/src/sources_windows.c"),
|
|
||||||
}, &.{ "-D_GLFW_WIN32", include_glfw_src }),
|
|
||||||
.macos => lib.addCSourceFiles(&.{
|
|
||||||
sdkPath("/src/sources_all.c"),
|
|
||||||
sdkPath("/src/sources_macos.m"),
|
|
||||||
sdkPath("/src/sources_macos.c"),
|
|
||||||
}, &.{ "-D_GLFW_COCOA", include_glfw_src }),
|
|
||||||
else => {
|
|
||||||
// TODO(future): for now, Linux can't be built with musl:
|
|
||||||
//
|
|
||||||
// ```
|
|
||||||
// ld.lld: error: cannot create a copy relocation for symbol stderr
|
|
||||||
// thread 2004762 panic: attempt to unwrap error: LLDReportedFailure
|
|
||||||
// ```
|
|
||||||
var sources = std.ArrayList([]const u8).init(b.allocator);
|
|
||||||
var flags = std.ArrayList([]const u8).init(b.allocator);
|
|
||||||
try sources.append(sdkPath("/src/sources_all.c"));
|
|
||||||
try sources.append(sdkPath("/src/sources_linux.c"));
|
|
||||||
if (options.x11) {
|
|
||||||
try sources.append(sdkPath("/src/sources_linux_x11.c"));
|
|
||||||
try flags.append("-D_GLFW_X11");
|
|
||||||
}
|
|
||||||
if (options.wayland) {
|
|
||||||
try sources.append(sdkPath("/src/sources_linux_wayland.c"));
|
|
||||||
try flags.append("-D_GLFW_WAYLAND");
|
|
||||||
}
|
|
||||||
try flags.append(comptime "-I" ++ sdkPath("/upstream/glfw/src"));
|
|
||||||
// TODO(upstream): glfw can't compile on clang15 without this flag
|
|
||||||
try flags.append("-Wno-implicit-function-declaration");
|
|
||||||
|
|
||||||
lib.addCSourceFiles(sources.items, flags.items);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn linkGLFWDependencies(b: *Build, step: *std.build.CompileStep, options: Options) void {
|
|
||||||
if (step.target_info.target.os.tag == .windows) {
|
|
||||||
step.linkLibrary(b.dependency("direct3d_headers", .{
|
|
||||||
.target = step.target,
|
.target = step.target,
|
||||||
.optimize = step.optimize,
|
.optimize = step.optimize,
|
||||||
}).artifact("direct3d-headers"));
|
}).artifact("glfw"));
|
||||||
}
|
|
||||||
if (options.x11) {
|
|
||||||
step.linkLibrary(b.dependency("x11_headers", .{
|
|
||||||
.target = step.target,
|
|
||||||
.optimize = step.optimize,
|
|
||||||
}).artifact("x11-headers"));
|
|
||||||
}
|
|
||||||
if (options.vulkan) {
|
|
||||||
step.linkLibrary(b.dependency("vulkan_headers", .{
|
step.linkLibrary(b.dependency("vulkan_headers", .{
|
||||||
.target = step.target,
|
.target = step.target,
|
||||||
.optimize = step.optimize,
|
.optimize = step.optimize,
|
||||||
}).artifact("vulkan-headers"));
|
}).artifact("vulkan-headers"));
|
||||||
}
|
|
||||||
if (options.wayland) {
|
|
||||||
step.defineCMacro("WL_MARSHAL_FLAG_DESTROY", null);
|
|
||||||
step.linkLibrary(b.dependency("wayland_headers", .{
|
|
||||||
.target = step.target,
|
|
||||||
.optimize = step.optimize,
|
|
||||||
}).artifact("wayland-headers"));
|
|
||||||
}
|
|
||||||
if (step.target_info.target.os.tag == .windows) @import("direct3d_headers").addLibraryPath(step);
|
|
||||||
|
|
||||||
step.linkLibC();
|
|
||||||
if (step.target_info.target.os.tag == .macos) {
|
if (step.target_info.target.os.tag == .macos) {
|
||||||
// TODO(build-system): This cannot be imported with the Zig package manager
|
// TODO(build-system): This cannot be imported with the Zig package manager
|
||||||
// error: TarUnsupportedFileType
|
// error: TarUnsupportedFileType
|
||||||
|
@ -198,53 +95,6 @@ fn linkGLFWDependencies(b: *Build, step: *std.build.CompileStep, options: Option
|
||||||
// @import("xcode_frameworks").addPaths(step);
|
// @import("xcode_frameworks").addPaths(step);
|
||||||
xcode_frameworks.addPaths(b, step);
|
xcode_frameworks.addPaths(b, step);
|
||||||
}
|
}
|
||||||
switch (step.target_info.target.os.tag) {
|
|
||||||
.windows => {
|
|
||||||
step.linkSystemLibraryName("gdi32");
|
|
||||||
step.linkSystemLibraryName("user32");
|
|
||||||
step.linkSystemLibraryName("shell32");
|
|
||||||
if (options.opengl) {
|
|
||||||
step.linkSystemLibraryName("opengl32");
|
|
||||||
}
|
|
||||||
if (options.gles) {
|
|
||||||
step.linkSystemLibraryName("GLESv3");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
.macos => {
|
|
||||||
step.linkFramework("IOKit");
|
|
||||||
step.linkFramework("CoreFoundation");
|
|
||||||
if (options.metal) {
|
|
||||||
step.linkFramework("Metal");
|
|
||||||
}
|
|
||||||
if (options.opengl) {
|
|
||||||
step.linkFramework("OpenGL");
|
|
||||||
}
|
|
||||||
step.linkSystemLibraryName("objc");
|
|
||||||
step.linkFramework("AppKit");
|
|
||||||
step.linkFramework("CoreServices");
|
|
||||||
step.linkFramework("CoreGraphics");
|
|
||||||
step.linkFramework("Foundation");
|
|
||||||
},
|
|
||||||
else => {
|
|
||||||
// Assume Linux-like
|
|
||||||
if (options.wayland) {
|
|
||||||
step.defineCMacro("WL_MARSHAL_FLAG_DESTROY", null);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ensureDependencySubmodule(allocator: std.mem.Allocator, path: []const u8) !void {
|
|
||||||
if (std.process.getEnvVarOwned(allocator, "NO_ENSURE_SUBMODULES")) |no_ensure_submodules| {
|
|
||||||
defer allocator.free(no_ensure_submodules);
|
|
||||||
if (std.mem.eql(u8, no_ensure_submodules, "true")) return;
|
|
||||||
} else |_| {}
|
|
||||||
var child = std.ChildProcess.init(&.{ "git", "submodule", "update", "--init", path }, allocator);
|
|
||||||
child.cwd = sdkPath("/");
|
|
||||||
child.stderr = std.io.getStdErr();
|
|
||||||
child.stdout = std.io.getStdOut();
|
|
||||||
|
|
||||||
_ = try child.spawnAndWait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sdkPath(comptime suffix: []const u8) []const u8 {
|
fn sdkPath(comptime suffix: []const u8) []const u8 {
|
||||||
|
@ -277,7 +127,7 @@ fn sdkPath(comptime suffix: []const u8) []const u8 {
|
||||||
const xcode_frameworks = struct {
|
const xcode_frameworks = struct {
|
||||||
pub fn addPaths(b: *std.Build, step: *std.build.CompileStep) void {
|
pub fn addPaths(b: *std.Build, step: *std.build.CompileStep) void {
|
||||||
// branch: mach
|
// branch: mach
|
||||||
xEnsureGitRepoCloned(b.allocator, "https://github.com/hexops/xcode-frameworks", "723aa55e9752c8c6c25d3413722b5fe13d72ac4f", "zig-cache/xcode_frameworks") catch |err| @panic(@errorName(err));
|
xEnsureGitRepoCloned(b.allocator, "https://github.com/hexops/xcode-frameworks", "723aa55e9752c8c6c25d3413722b5fe13d72ac4f", xSdkPath("/zig-cache/xcode_frameworks")) catch |err| @panic(@errorName(err));
|
||||||
|
|
||||||
step.addFrameworkPath("zig-cache/xcode_frameworks/Frameworks");
|
step.addFrameworkPath("zig-cache/xcode_frameworks/Frameworks");
|
||||||
step.addSystemIncludePath("zig-cache/xcode_frameworks/include");
|
step.addSystemIncludePath("zig-cache/xcode_frameworks/include");
|
||||||
|
@ -291,7 +141,7 @@ const xcode_frameworks = struct {
|
||||||
|
|
||||||
xEnsureGit(allocator);
|
xEnsureGit(allocator);
|
||||||
|
|
||||||
if (std.fs.cwd().openDir(dir, .{})) |_| {
|
if (std.fs.openDirAbsolute(dir, .{})) |_| {
|
||||||
const current_revision = try xGetCurrentGitRevision(allocator, dir);
|
const current_revision = try xGetCurrentGitRevision(allocator, dir);
|
||||||
if (!std.mem.eql(u8, current_revision, revision)) {
|
if (!std.mem.eql(u8, current_revision, revision)) {
|
||||||
// Reset to the desired revision
|
// Reset to the desired revision
|
||||||
|
@ -355,4 +205,12 @@ const xcode_frameworks = struct {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn xSdkPath(comptime suffix: []const u8) []const u8 {
|
||||||
|
if (suffix[0] != '/') @compileError("suffix must be an absolute path");
|
||||||
|
return comptime blk: {
|
||||||
|
const root_dir = std.fs.path.dirname(@src().file) orelse ".";
|
||||||
|
break :blk root_dir ++ suffix;
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,5 +18,9 @@
|
||||||
.url = "https://github.com/hexops/x11-headers/archive/99af89c7bfdc7db503f3a7003571f8e81bcd09f3.tar.gz",
|
.url = "https://github.com/hexops/x11-headers/archive/99af89c7bfdc7db503f3a7003571f8e81bcd09f3.tar.gz",
|
||||||
.hash = "1220e6bd3186841c1da38d862d52ba88dec9633d24f409eda27627321937419a0ddb",
|
.hash = "1220e6bd3186841c1da38d862d52ba88dec9633d24f409eda27627321937419a0ddb",
|
||||||
},
|
},
|
||||||
|
.glfw = .{
|
||||||
|
.url = "https://github.com/hexops/glfw/archive/49c21c3d2fcaf9799b593f5320ce8e598a692c74.tar.gz",
|
||||||
|
.hash = "12200a907165afc4c099d4d19e2f7ce9923a72116006d8f5f5af3a9a071fa66171d2",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 723aa55e9752c8c6c25d3413722b5fe13d72ac4f
|
|
|
@ -186,7 +186,7 @@ pub inline fn getUserPointer(self: Monitor, comptime T: type) ?*T {
|
||||||
/// then by resolution area (the product of width and height), then resolution width and finally
|
/// then by resolution area (the product of width and height), then resolution width and finally
|
||||||
/// by refresh rate.
|
/// by refresh rate.
|
||||||
///
|
///
|
||||||
/// Possible errors include glfw.ErrorCode.PlatformError.
|
/// Possible errors include glfw.ErrorCode.PlatformError, glfw.ErrorCode.FeatureUnavailable.
|
||||||
/// Returns null in the event of an error.
|
/// Returns null in the event of an error.
|
||||||
///
|
///
|
||||||
/// The returned slice memory is owned by the caller.
|
/// The returned slice memory is owned by the caller.
|
||||||
|
@ -194,7 +194,10 @@ pub inline fn getUserPointer(self: Monitor, comptime T: type) ?*T {
|
||||||
/// @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_modes, glfw.Monitor.getVideoMode
|
/// see also: monitor_modes, glfw.Monitor.getVideoMode
|
||||||
//
|
///
|
||||||
|
/// wayland: Gamma handling is privileged protocol, this function will thus never be implemented and
|
||||||
|
/// emits glfw.ErrorCode.FeatureUnavailable
|
||||||
|
///
|
||||||
/// TODO(glfw): rewrite this to not require any allocation.
|
/// TODO(glfw): rewrite this to not require any allocation.
|
||||||
pub inline fn getVideoModes(self: Monitor, allocator: mem.Allocator) mem.Allocator.Error!?[]VideoMode {
|
pub inline fn getVideoModes(self: Monitor, allocator: mem.Allocator) mem.Allocator.Error!?[]VideoMode {
|
||||||
internal_debug.assertInitialized();
|
internal_debug.assertInitialized();
|
||||||
|
@ -216,11 +219,14 @@ pub inline fn getVideoModes(self: Monitor, allocator: mem.Allocator) mem.Allocat
|
||||||
/// full screen window for that monitor, the return value will depend on whether that window is
|
/// full screen window for that monitor, the return value will depend on whether that window is
|
||||||
/// iconified.
|
/// iconified.
|
||||||
///
|
///
|
||||||
/// Possible errors include glfw.ErrorCode.PlatformError.
|
/// Possible errors include glfw.ErrorCode.PlatformError, glfw.ErrorCode.FeatureUnavailable.
|
||||||
/// Additionally returns null in the event of an error.
|
/// Additionally returns null in the event of an error.
|
||||||
///
|
///
|
||||||
/// @thread_safety This function must only be called from the main thread.
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
///
|
///
|
||||||
|
/// wayland: Gamma handling is a privileged protocol, this function will thus never be implemented
|
||||||
|
/// and will thus never be implemented and emits glfw.ErrorCode.FeatureUnavailable
|
||||||
|
///
|
||||||
/// see also: monitor_modes, glfw.Monitor.getVideoModes
|
/// see also: monitor_modes, glfw.Monitor.getVideoModes
|
||||||
pub inline fn getVideoMode(self: Monitor) ?VideoMode {
|
pub inline fn getVideoMode(self: Monitor) ?VideoMode {
|
||||||
internal_debug.assertInitialized();
|
internal_debug.assertInitialized();
|
||||||
|
@ -239,10 +245,10 @@ pub inline fn getVideoMode(self: Monitor) ?VideoMode {
|
||||||
///
|
///
|
||||||
/// For gamma correct rendering with OpenGL or OpenGL ES, see the glfw.srgb_capable hint.
|
/// For gamma correct rendering with OpenGL or OpenGL ES, see the glfw.srgb_capable hint.
|
||||||
///
|
///
|
||||||
/// Possible errors include glfw.ErrorCode.InvalidValue and glfw.ErrorCode.PlatformError.
|
/// Possible errors include glfw.ErrorCode.PlatformError, glfw.ErrorCode.FeatureUnavailable.
|
||||||
///
|
///
|
||||||
/// wayland: Gamma handling is a privileged protocol, this function will thus never be implemented
|
/// wayland: Gamma handling is privileged protocol, this function will thus never be implemented and
|
||||||
/// and emits glfw.ErrorCode.PlatformError.
|
/// emits glfw.ErrorCode.FeatureUnavailable
|
||||||
///
|
///
|
||||||
/// @thread_safety This function must only be called from the main thread.
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
///
|
///
|
||||||
|
@ -265,8 +271,7 @@ pub inline fn setGamma(self: Monitor, gamma: f32) void {
|
||||||
/// Additionally returns null in the event of an error.
|
/// Additionally returns null in the event of an error.
|
||||||
///
|
///
|
||||||
/// wayland: Gamma handling is a privileged protocol, this function will thus never be implemented
|
/// wayland: Gamma handling is a privileged protocol, this function will thus never be implemented
|
||||||
/// and returns glfw.ErrorCode.PlatformError.
|
/// and returns glfw.ErrorCode.FeatureUnavailable.
|
||||||
/// TODO: Is the documentation obsolete? On wayland the error returned is FeatureUnavailable
|
|
||||||
///
|
///
|
||||||
/// The returned gamma ramp is `.owned = true` by GLFW, and is valid until the monitor is
|
/// 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.
|
/// disconnected, this function is called again, or `glfw.terminate()` is called.
|
||||||
|
@ -292,13 +297,13 @@ pub inline fn getGammaRamp(self: Monitor) ?GammaRamp {
|
||||||
///
|
///
|
||||||
/// For gamma correct rendering with OpenGL or OpenGL ES, see the glfw.srgb_capable hint.
|
/// For gamma correct rendering with OpenGL or OpenGL ES, see the glfw.srgb_capable hint.
|
||||||
///
|
///
|
||||||
/// Possible errors include glfw.ErrorCode.PlatformError.
|
/// Possible errors include glfw.ErrorCode.PlatformError, glfw.ErrorCode.FeatureUnavailable.
|
||||||
///
|
///
|
||||||
/// The size of the specified gamma ramp should match the size of the current ramp for that
|
/// The size of the specified gamma ramp should match the size of the current ramp for that
|
||||||
/// monitor. On win32, the gamma ramp size must be 256.
|
/// monitor. On win32, the gamma ramp size must be 256.
|
||||||
///
|
///
|
||||||
/// wayland: Gamma handling is a privileged protocol, this function will thus never be implemented
|
/// wayland: Gamma handling is a privileged protocol, this function will thus never be implemented
|
||||||
/// and emits glfw.ErrorCode.PlatformError.
|
/// and returns glfw.ErrorCode.FeatureUnavailable.
|
||||||
///
|
///
|
||||||
/// @pointer_lifetime The specified gamma ramp is copied before this function returns.
|
/// @pointer_lifetime The specified gamma ramp is copied before this function returns.
|
||||||
///
|
///
|
||||||
|
|
|
@ -50,6 +50,8 @@ const Hint = enum(c_int) {
|
||||||
transparent_framebuffer = c.GLFW_TRANSPARENT_FRAMEBUFFER,
|
transparent_framebuffer = c.GLFW_TRANSPARENT_FRAMEBUFFER,
|
||||||
focus_on_show = c.GLFW_FOCUS_ON_SHOW,
|
focus_on_show = c.GLFW_FOCUS_ON_SHOW,
|
||||||
mouse_passthrough = c.GLFW_MOUSE_PASSTHROUGH,
|
mouse_passthrough = c.GLFW_MOUSE_PASSTHROUGH,
|
||||||
|
position_x = c.GLFW_POSITION_X,
|
||||||
|
position_y = c.GLFW_POSITION_Y,
|
||||||
scale_to_monitor = c.GLFW_SCALE_TO_MONITOR,
|
scale_to_monitor = c.GLFW_SCALE_TO_MONITOR,
|
||||||
|
|
||||||
/// Framebuffer hints
|
/// Framebuffer hints
|
||||||
|
@ -112,6 +114,9 @@ const Hint = enum(c_int) {
|
||||||
|
|
||||||
/// Windows specific
|
/// Windows specific
|
||||||
win32_keyboard_menu = c.GLFW_WIN32_KEYBOARD_MENU,
|
win32_keyboard_menu = c.GLFW_WIN32_KEYBOARD_MENU,
|
||||||
|
|
||||||
|
/// Allows specification of the Wayland app_id.
|
||||||
|
wayland_app_id = c.GLFW_WAYLAND_APP_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Window hints
|
/// Window hints
|
||||||
|
@ -128,6 +133,9 @@ pub const Hints = struct {
|
||||||
transparent_framebuffer: bool = false,
|
transparent_framebuffer: bool = false,
|
||||||
focus_on_show: bool = true,
|
focus_on_show: bool = true,
|
||||||
mouse_passthrough: bool = false,
|
mouse_passthrough: bool = false,
|
||||||
|
position_x: c_int = @intFromEnum(Position.any),
|
||||||
|
position_y: c_int = @intFromEnum(Position.any),
|
||||||
|
|
||||||
scale_to_monitor: bool = false,
|
scale_to_monitor: bool = false,
|
||||||
|
|
||||||
/// Framebuffer hints
|
/// Framebuffer hints
|
||||||
|
@ -194,6 +202,9 @@ pub const Hints = struct {
|
||||||
/// Windows specific
|
/// Windows specific
|
||||||
win32_keyboard_menu: bool = false,
|
win32_keyboard_menu: bool = false,
|
||||||
|
|
||||||
|
/// Allows specification of the Wayland app_id.
|
||||||
|
wayland_app_id: [:0]const u8 = "",
|
||||||
|
|
||||||
pub const PositiveCInt = std.math.IntFittingRange(0, std.math.maxInt(c_int));
|
pub const PositiveCInt = std.math.IntFittingRange(0, std.math.maxInt(c_int));
|
||||||
|
|
||||||
pub const ClientAPI = enum(c_int) {
|
pub const ClientAPI = enum(c_int) {
|
||||||
|
@ -226,6 +237,18 @@ pub const Hints = struct {
|
||||||
opengl_core_profile = c.GLFW_OPENGL_CORE_PROFILE,
|
opengl_core_profile = c.GLFW_OPENGL_CORE_PROFILE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const Position = enum(c_int) {
|
||||||
|
/// By default, newly created windows use the placement recommended by the window system,
|
||||||
|
///
|
||||||
|
/// To create the window at a specific position, make it initially invisible using the
|
||||||
|
/// Window.Hint.visible hint, set its Window.Hint.position and then Window.hide() it.
|
||||||
|
///
|
||||||
|
/// To create the window at a specific position, set the Window.Hint.position_x and
|
||||||
|
/// Window.Hint.position_y hints before creation. To restore the default behavior, set
|
||||||
|
/// either or both hints back to Window.Hints.Position.any
|
||||||
|
any = @bitCast(c.GLFW_ANY_POSITION),
|
||||||
|
};
|
||||||
|
|
||||||
fn set(hints: Hints) void {
|
fn set(hints: Hints) void {
|
||||||
internal_debug.assertInitialized();
|
internal_debug.assertInitialized();
|
||||||
inline for (comptime std.meta.fieldNames(Hint)) |field_name| {
|
inline for (comptime std.meta.fieldNames(Hint)) |field_name| {
|
||||||
|
@ -241,6 +264,7 @@ pub const Hints = struct {
|
||||||
ContextRobustness,
|
ContextRobustness,
|
||||||
ContextReleaseBehavior,
|
ContextReleaseBehavior,
|
||||||
OpenGLProfile,
|
OpenGLProfile,
|
||||||
|
Position,
|
||||||
=> c.glfwWindowHint(hint_tag, @intFromEnum(hint_value)),
|
=> c.glfwWindowHint(hint_tag, @intFromEnum(hint_value)),
|
||||||
|
|
||||||
[:0]const u8 => c.glfwWindowHintString(hint_tag, hint_value.ptr),
|
[:0]const u8 => c.glfwWindowHintString(hint_tag, hint_value.ptr),
|
||||||
|
@ -820,8 +844,8 @@ pub inline fn setOpacity(self: Window, opacity: f32) void {
|
||||||
/// This function iconifies (minimizes) the specified window if it was previously restored. If the
|
/// This function iconifies (minimizes) the specified window if it was previously restored. If the
|
||||||
/// window is already iconified, this function does nothing.
|
/// window is already iconified, this function does nothing.
|
||||||
///
|
///
|
||||||
/// If the specified window is a full screen window, the original monitor resolution is restored
|
/// If the specified window is a full screen window, GLFW restores the original video mode of the
|
||||||
/// until the window is restored.
|
/// monitor. The window's desired video mode is set again when the window is restored.
|
||||||
///
|
///
|
||||||
/// Possible errors include glfw.ErrorCode.PlatformError.
|
/// Possible errors include glfw.ErrorCode.PlatformError.
|
||||||
///
|
///
|
||||||
|
@ -841,8 +865,8 @@ pub inline fn iconify(self: Window) void {
|
||||||
/// This function restores the specified window if it was previously iconified (minimized) or
|
/// This function restores the specified window if it was previously iconified (minimized) or
|
||||||
/// maximized. If the window is already restored, this function does nothing.
|
/// maximized. If the window is already restored, this function does nothing.
|
||||||
///
|
///
|
||||||
/// If the specified window is a full screen window, the resolution chosen for the window is
|
/// If the specified window is an iconified full screen window, its desired video mode is set
|
||||||
/// restored on the selected monitor.
|
/// again for its monitor when the window is restored.
|
||||||
///
|
///
|
||||||
/// Possible errors include glfw.ErrorCode.PlatformError.
|
/// Possible errors include glfw.ErrorCode.PlatformError.
|
||||||
///
|
///
|
||||||
|
@ -1104,6 +1128,9 @@ pub const Attrib = enum(c_int) {
|
||||||
///
|
///
|
||||||
/// @thread_safety This function must only be called from the main thread.
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
///
|
///
|
||||||
|
/// wayland: The Wayland protocol provides no way to check whether a window is iconified, so
|
||||||
|
/// glfw.Window.Attrib.iconified always returns `false`.
|
||||||
|
///
|
||||||
/// see also: window_attribs, glfw.Window.setAttrib
|
/// see also: window_attribs, glfw.Window.setAttrib
|
||||||
pub inline fn getAttrib(self: Window, attrib: Attrib) i32 {
|
pub inline fn getAttrib(self: Window, attrib: Attrib) i32 {
|
||||||
internal_debug.assertInitialized();
|
internal_debug.assertInitialized();
|
||||||
|
@ -1125,8 +1152,8 @@ pub inline fn getAttrib(self: Window, attrib: Attrib) i32 {
|
||||||
///
|
///
|
||||||
/// @param[in] attrib A supported window attribute.
|
/// @param[in] attrib A supported window attribute.
|
||||||
///
|
///
|
||||||
/// Possible errors include glfw.ErrorCode.InvalidEnum, glfw.ErrorCode.InvalidValue and
|
/// Possible errors include glfw.ErrorCode.InvalidEnum, glfw.ErrorCode.InvalidValue,
|
||||||
/// glfw.ErrorCode.PlatformError.
|
/// glfw.ErrorCode.PlatformError, glfw.ErrorCode.FeatureUnavailable
|
||||||
///
|
///
|
||||||
/// Calling glfw.Window.getAttrib will always return the latest
|
/// Calling glfw.Window.getAttrib will always return the latest
|
||||||
/// value, even if that value is ignored by the current mode of the window.
|
/// value, even if that value is ignored by the current mode of the window.
|
||||||
|
@ -1527,6 +1554,9 @@ pub const InputModeCursor = enum(c_int) {
|
||||||
/// Hides and grabs the cursor, providing virtual and unlimited cursor movement. This is useful
|
/// Hides and grabs the cursor, providing virtual and unlimited cursor movement. This is useful
|
||||||
/// for implementing for example 3D camera controls.
|
/// for implementing for example 3D camera controls.
|
||||||
disabled = c.GLFW_CURSOR_DISABLED,
|
disabled = c.GLFW_CURSOR_DISABLED,
|
||||||
|
|
||||||
|
/// Makes the cursor visible but confines it to the content area of the window.
|
||||||
|
captured = c.GLFW_CURSOR_CAPTURED,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Sets the input mode of the cursor, whether it should behave normally, be hidden, or grabbed.
|
/// Sets the input mode of the cursor, whether it should behave normally, be hidden, or grabbed.
|
||||||
|
@ -1669,8 +1699,9 @@ pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) void {
|
||||||
/// Returns the last reported press state of a keyboard key for the specified window.
|
/// Returns the last reported press state of a keyboard key for the specified window.
|
||||||
///
|
///
|
||||||
/// This function returns the last press state reported for the specified key to the specified
|
/// This function returns the last press state reported for the specified key to the specified
|
||||||
/// window. The returned state is one of `true` (pressed) or `false` (released). The higher-level
|
/// window. The returned state is one of `true` (pressed) or `false` (released).
|
||||||
/// action `glfw.Action.repeat` is only reported to the key callback.
|
///
|
||||||
|
/// * `glfw.Action.repeat` is only reported to the key callback.
|
||||||
///
|
///
|
||||||
/// If the `glfw.sticky_keys` input mode is enabled, this function returns `glfw.Action.press` the
|
/// If the `glfw.sticky_keys` input mode is enabled, this function returns `glfw.Action.press` the
|
||||||
/// first time you call it for a key that was pressed, even if that key has already been released.
|
/// first time you call it for a key that was pressed, even if that key has already been released.
|
||||||
|
@ -1773,7 +1804,7 @@ pub inline fn getCursorPos(self: Window) CursorPos {
|
||||||
/// @param[in] xpos The desired x-coordinate, relative to the left edge of the content area.
|
/// @param[in] xpos The desired x-coordinate, relative to the left edge of the content area.
|
||||||
/// @param[in] ypos The desired y-coordinate, relative to the top edge of the content area.
|
/// @param[in] ypos The desired y-coordinate, relative to the top edge of the content area.
|
||||||
///
|
///
|
||||||
/// Possible errors include glfw.ErrorCode.PlatformError.
|
/// Possible errors include glfw.ErrorCode.PlatformError, glfw.ErrorCode.FeatureUnavailable.
|
||||||
///
|
///
|
||||||
/// wayland: This function will only work when the cursor mode is `glfw.cursor_disabled`, otherwise
|
/// wayland: This function will only work when the cursor mode is `glfw.cursor_disabled`, otherwise
|
||||||
/// it will do nothing.
|
/// it will do nothing.
|
||||||
|
|
15
src/main.zig
15
src/main.zig
|
@ -225,6 +225,11 @@ const InitHint = enum(c_int) {
|
||||||
|
|
||||||
/// X11 specific init hint.
|
/// X11 specific init hint.
|
||||||
x11_xcb_vulkan_surface = c.GLFW_X11_XCB_VULKAN_SURFACE,
|
x11_xcb_vulkan_surface = c.GLFW_X11_XCB_VULKAN_SURFACE,
|
||||||
|
|
||||||
|
/// Wayland specific init hint.
|
||||||
|
///
|
||||||
|
/// Possible values are `WaylandLibdecorInitHint` enums.
|
||||||
|
wayland_libdecor = c.GLFW_WAYLAND_LIBDECOR,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Angle platform type hints for glfw.InitHint.angle_platform_type
|
/// Angle platform type hints for glfw.InitHint.angle_platform_type
|
||||||
|
@ -238,6 +243,16 @@ pub const AnglePlatformType = enum(c_int) {
|
||||||
metal = c.GLFW_ANGLE_PLATFORM_TYPE_METAL,
|
metal = c.GLFW_ANGLE_PLATFORM_TYPE_METAL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Wayland libdecor hints for glfw.InitHint.wayland_libdecor
|
||||||
|
///
|
||||||
|
/// libdecor is important for GNOME, since GNOME does not implement server side decorations on
|
||||||
|
/// wayland. libdecor is loaded dynamically at runtime, so in general enabling it is always
|
||||||
|
/// safe to do. It is enabled by default.
|
||||||
|
pub const WaylandLibdecorInitHint = enum(c_int) {
|
||||||
|
wayland_prefer_libdecor = c.GLFW_WAYLAND_PREFER_LIBDECOR,
|
||||||
|
wayland_disable_libdecor = c.GLFW_WAYLAND_DISABLE_LIBDECOR,
|
||||||
|
};
|
||||||
|
|
||||||
/// Platform type hints for glfw.InitHint.platform
|
/// Platform type hints for glfw.InitHint.platform
|
||||||
pub const PlatformType = enum(c_int) {
|
pub const PlatformType = enum(c_int) {
|
||||||
/// Enables automatic platform detection.
|
/// Enables automatic platform detection.
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
// MacOS: this must be defined for macOS 13.3 and older.
|
|
||||||
#define __kernel_ptr_semantics
|
|
||||||
|
|
||||||
// General sources
|
|
||||||
#include "monitor.c"
|
|
||||||
#include "init.c"
|
|
||||||
#include "vulkan.c"
|
|
||||||
#include "input.c"
|
|
||||||
#include "osmesa_context.c"
|
|
||||||
#include "egl_context.c"
|
|
||||||
#include "context.c"
|
|
||||||
#include "window.c"
|
|
||||||
#include "platform.c"
|
|
||||||
#include "null_init.c"
|
|
||||||
#include "null_monitor.c"
|
|
||||||
#include "null_window.c"
|
|
||||||
#include "null_joystick.c"
|
|
|
@ -1,7 +0,0 @@
|
||||||
// General Linux-like sources
|
|
||||||
#include "posix_time.c"
|
|
||||||
#include "posix_thread.c"
|
|
||||||
#include "linux_joystick.c"
|
|
||||||
#include "xkb_unicode.c"
|
|
||||||
#include "posix_module.c"
|
|
||||||
#include "posix_poll.c"
|
|
|
@ -1,4 +0,0 @@
|
||||||
// General Linux-like sources
|
|
||||||
#include "wl_monitor.c"
|
|
||||||
#include "wl_window.c"
|
|
||||||
#include "wl_init.c"
|
|
|
@ -1,5 +0,0 @@
|
||||||
// General Linux-like sources
|
|
||||||
#include "x11_init.c"
|
|
||||||
#include "x11_window.c"
|
|
||||||
#include "x11_monitor.c"
|
|
||||||
#include "glx_context.c"
|
|
|
@ -1,7 +0,0 @@
|
||||||
// MacOS: this must be defined for macOS 13.3 and older.
|
|
||||||
#define __kernel_ptr_semantics
|
|
||||||
|
|
||||||
// MacOS-specific sources
|
|
||||||
#include "cocoa_time.c"
|
|
||||||
#include "posix_thread.c"
|
|
||||||
#include "posix_module.c"
|
|
|
@ -1,9 +0,0 @@
|
||||||
// MacOS: this must be defined for macOS 13.3 and older.
|
|
||||||
#define __kernel_ptr_semantics
|
|
||||||
|
|
||||||
// MacOS-specific sources
|
|
||||||
#include "cocoa_joystick.m"
|
|
||||||
#include "cocoa_init.m"
|
|
||||||
#include "cocoa_window.m"
|
|
||||||
#include "cocoa_monitor.m"
|
|
||||||
#include "nsgl_context.m"
|
|
|
@ -1,9 +0,0 @@
|
||||||
// Windows-specific sources
|
|
||||||
#include "win32_thread.c"
|
|
||||||
#include "wgl_context.c"
|
|
||||||
#include "win32_init.c"
|
|
||||||
#include "win32_monitor.c"
|
|
||||||
#include "win32_time.c"
|
|
||||||
#include "win32_joystick.c"
|
|
||||||
#include "win32_window.c"
|
|
||||||
#include "win32_module.c"
|
|
1
upstream
1
upstream
|
@ -1 +0,0 @@
|
||||||
Subproject commit 915548c8694c1b4a96abd5a8729d0e777582d077
|
|
Loading…
Add table
Reference in a new issue