diff --git a/build.zig b/build.zig index 58553c18..3a436849 100644 --- a/build.zig +++ b/build.zig @@ -267,6 +267,7 @@ pub fn build(b: *std.Build) !void { pub const Platform = enum { wasm, + linux, windows, darwin, null, @@ -275,6 +276,7 @@ pub const Platform = enum { if (target.cpu.arch == .wasm32) return .wasm; if (target.os.tag.isDarwin()) return .darwin; if (target.os.tag == .windows) return .windows; + if (target.os.tag == .linux) return .linux; return .null; } }; diff --git a/src/Core.zig b/src/Core.zig index 3156bcec..05d2a8fb 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -12,10 +12,14 @@ const gamemode_log = std.log.scoped(.gamemode); // Whether or not you can drive the main loop in a non-blocking fashion, or if the underlying // platform must take control and drive the main loop itself. pub const supports_non_blocking = switch (build_options.core_platform) { + // Platforms that support non-blocking mode. + .linux => true, .windows => true, + .null => true, + + // Platforms which take control of the main loop. .wasm => false, .darwin => false, - .null => true, }; const EventQueue = std.fifo.LinearFifo(Event, .Dynamic); @@ -786,6 +790,7 @@ pub fn detectBackendType(allocator: std.mem.Allocator) !gpu.BackendType { const Platform = switch (build_options.core_platform) { .wasm => @panic("TODO: support mach.Core WASM platform"), .windows => @import("core/Windows.zig"), + .linux => @import("core/Linux.zig"), .darwin => @import("core/Darwin.zig"), .null => @import("core/Null.zig"), }; diff --git a/src/core/Linux.zig b/src/core/Linux.zig index a352d9c1..7572830f 100644 --- a/src/core/Linux.zig +++ b/src/core/Linux.zig @@ -1,3 +1,94 @@ +const std = @import("std"); +const mach = @import("../main.zig"); +const Core = @import("../Core.zig"); +const gpu = mach.gpu; +const InitOptions = Core.InitOptions; +const Event = Core.Event; +const KeyEvent = Core.KeyEvent; +const MouseButtonEvent = Core.MouseButtonEvent; +const MouseButton = Core.MouseButton; +const Size = Core.Size; +const DisplayMode = Core.DisplayMode; +const CursorShape = Core.CursorShape; +const VSyncMode = Core.VSyncMode; +const CursorMode = Core.CursorMode; +const Position = Core.Position; +const Key = Core.Key; +const KeyMods = Core.KeyMods; + +const log = std.log.scoped(.mach); + +pub const Linux = @This(); + +allocator: std.mem.Allocator, +core: *Core, +modifiers: KeyMods, +title: [:0]u8, +display_mode: DisplayMode, +vsync_mode: VSyncMode, +cursor_mode: CursorMode, +cursor_shape: CursorShape, +border: bool, +headless: bool, +refresh_rate: u32, +size: Size, +surface_descriptor: gpu.Surface.Descriptor, + +pub fn init( + linux: *Linux, + core: *Core.Mod, + options: InitOptions, +) !void { + _ = linux; + _ = options; + _ = core; + return; +} + +pub fn deinit(_: *Linux) void { + return; +} + +pub fn update(_: *Linux) !void { + return; +} + +pub fn setTitle(_: *Linux, _: [:0]const u8) void { + return; +} + +pub fn setDisplayMode(_: *Linux, _: DisplayMode) void { + return; +} + +pub fn setBorder(_: *Linux, _: bool) void { + return; +} + +pub fn setHeadless(_: *Linux, _: bool) void { + return; +} + +pub fn setVSync(_: *Linux, _: VSyncMode) void { + return; +} + +pub fn setSize(_: *Linux, _: Size) void { + return; +} + +pub fn size(_: *Linux) Size { + return Size{ .width = 100, .height = 100 }; +} + +pub fn setCursorMode(_: *Linux, _: CursorMode) void { + return; +} + +pub fn setCursorShape(_: *Linux, _: CursorShape) void { + return; +} + ///! Taken from https://github.com/glfw/glfw/blob/master/src/xkb_unicode.c const KeySym = c_ulong; const keysym_table = &[_]struct { KeySym, u21 }{