mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
use waiting rather than polling on window
This commit is contained in:
84
build.zig
84
build.zig
@ -2,8 +2,6 @@ const std = @import("std");
|
|||||||
const Builder = std.build.Builder;
|
const Builder = std.build.Builder;
|
||||||
const LibExeObjStep = std.build.LibExeObjStep;
|
const LibExeObjStep = std.build.LibExeObjStep;
|
||||||
|
|
||||||
const raylib = @import("vendor/raylib/src/build.zig");
|
|
||||||
|
|
||||||
pub fn build(b: *std.build.Builder) void {
|
pub fn build(b: *std.build.Builder) void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const mode = b.standardReleaseOptions();
|
const mode = b.standardReleaseOptions();
|
||||||
@ -12,7 +10,7 @@ pub fn build(b: *std.build.Builder) void {
|
|||||||
exe.setTarget(target);
|
exe.setTarget(target);
|
||||||
exe.setBuildMode(mode);
|
exe.setBuildMode(mode);
|
||||||
exe.install();
|
exe.install();
|
||||||
exe.linkLibrary(raylib.addRaylib(exe.builder, exe.target));
|
exe.linkLibrary(addRaylib(exe.builder, exe.target));
|
||||||
exe.addIncludeDir("vendor/raylib/src"); // for raylib.h
|
exe.addIncludeDir("vendor/raylib/src"); // for raylib.h
|
||||||
|
|
||||||
const run_cmd = exe.run();
|
const run_cmd = exe.run();
|
||||||
@ -24,3 +22,83 @@ pub fn build(b: *std.build.Builder) void {
|
|||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
|
||||||
|
// Standard release options allow the person running `zig build` to select
|
||||||
|
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||||
|
const mode = b.standardReleaseOptions();
|
||||||
|
|
||||||
|
const raylib_flags = &[_][]const u8{
|
||||||
|
"-std=gnu99",
|
||||||
|
"-DPLATFORM_DESKTOP",
|
||||||
|
"-DGL_SILENCE_DEPRECATION=199309L",
|
||||||
|
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891
|
||||||
|
"-DSUPPORT_EVENTS_WAITING", // for waiting, not polling on events
|
||||||
|
};
|
||||||
|
|
||||||
|
const srcdir = "vendor/raylib/src";
|
||||||
|
|
||||||
|
const raylib = b.addStaticLibrary("raylib", srcdir ++ "/raylib.h");
|
||||||
|
raylib.setTarget(target);
|
||||||
|
raylib.setBuildMode(mode);
|
||||||
|
raylib.linkLibC();
|
||||||
|
|
||||||
|
raylib.addIncludeDir(srcdir ++ "/external/glfw/include");
|
||||||
|
|
||||||
|
raylib.addCSourceFiles(&.{
|
||||||
|
srcdir ++ "/raudio.c",
|
||||||
|
srcdir ++ "/rcore.c",
|
||||||
|
srcdir ++ "/rmodels.c",
|
||||||
|
srcdir ++ "/rshapes.c",
|
||||||
|
srcdir ++ "/rtext.c",
|
||||||
|
srcdir ++ "/rtextures.c",
|
||||||
|
srcdir ++ "/utils.c",
|
||||||
|
}, raylib_flags);
|
||||||
|
|
||||||
|
switch (raylib.target.toTarget().os.tag) {
|
||||||
|
.windows => {
|
||||||
|
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
||||||
|
raylib.linkSystemLibrary("winmm");
|
||||||
|
raylib.linkSystemLibrary("gdi32");
|
||||||
|
raylib.linkSystemLibrary("opengl32");
|
||||||
|
raylib.addIncludeDir("external/glfw/deps/mingw");
|
||||||
|
},
|
||||||
|
.linux => {
|
||||||
|
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
||||||
|
raylib.linkSystemLibrary("GL");
|
||||||
|
raylib.linkSystemLibrary("rt");
|
||||||
|
raylib.linkSystemLibrary("dl");
|
||||||
|
raylib.linkSystemLibrary("m");
|
||||||
|
raylib.linkSystemLibrary("X11");
|
||||||
|
},
|
||||||
|
.freebsd, .openbsd, .netbsd, .dragonfly => {
|
||||||
|
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
||||||
|
raylib.linkSystemLibrary("GL");
|
||||||
|
raylib.linkSystemLibrary("rt");
|
||||||
|
raylib.linkSystemLibrary("dl");
|
||||||
|
raylib.linkSystemLibrary("m");
|
||||||
|
raylib.linkSystemLibrary("X11");
|
||||||
|
raylib.linkSystemLibrary("Xrandr");
|
||||||
|
raylib.linkSystemLibrary("Xinerama");
|
||||||
|
raylib.linkSystemLibrary("Xi");
|
||||||
|
raylib.linkSystemLibrary("Xxf86vm");
|
||||||
|
raylib.linkSystemLibrary("Xcursor");
|
||||||
|
},
|
||||||
|
.macos => {
|
||||||
|
// On macos rglfw.c include Objective-C files.
|
||||||
|
const raylib_flags_extra_macos = &[_][]const u8{
|
||||||
|
"-ObjC",
|
||||||
|
};
|
||||||
|
raylib.addCSourceFiles(
|
||||||
|
&.{srcdir ++ "/rglfw.c"},
|
||||||
|
raylib_flags ++ raylib_flags_extra_macos,
|
||||||
|
);
|
||||||
|
raylib.linkFramework("Foundation");
|
||||||
|
},
|
||||||
|
else => {
|
||||||
|
@panic("Unsupported OS");
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return raylib;
|
||||||
|
}
|
||||||
|
13
src/main.zig
13
src/main.zig
@ -2,9 +2,20 @@ const std = @import("std");
|
|||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
// Set the window as resizable. This is particularly important for
|
||||||
|
// tiling window managers such as i3 since if they are not resizable they
|
||||||
|
// usually default to floating and we do not want to float by default!
|
||||||
|
c.SetConfigFlags(c.FLAG_WINDOW_RESIZABLE | c.FLAG_VSYNC_HINT);
|
||||||
|
|
||||||
|
// Create our window
|
||||||
c.InitWindow(640, 480, "ghostty");
|
c.InitWindow(640, 480, "ghostty");
|
||||||
c.SetTargetFPS(60);
|
c.SetTargetFPS(60);
|
||||||
defer c.CloseWindow();
|
defer c.CloseWindow();
|
||||||
|
|
||||||
while (!c.WindowShouldClose()) {}
|
// Draw
|
||||||
|
while (!c.WindowShouldClose()) {
|
||||||
|
c.BeginDrawing();
|
||||||
|
c.ClearBackground(c.BLACK);
|
||||||
|
c.EndDrawing();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user