From 87f5d6f6a868c3f14614e80366c506db6c83e5c3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 14 Jan 2024 14:31:14 -0800 Subject: [PATCH] apprt/embedded: do not depend on macOS APIs on non-macOS --- src/apprt/embedded.zig | 3 +++ src/input.zig | 4 ++-- src/input/KeymapNoop.zig | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/input/KeymapNoop.zig diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 9b79fefca..a88aa55b0 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -1664,6 +1664,9 @@ pub const CAPI = struct { ptr: *Surface, window: *anyopaque, ) void { + // This is only supported on macOS + if (comptime builtin.target.os.tag != .macos) return; + const config = ptr.app.config; // Do nothing if we don't have background transparency enabled diff --git a/src/input.zig b/src/input.zig index 47024ff67..814415fcb 100644 --- a/src/input.zig +++ b/src/input.zig @@ -17,8 +17,8 @@ pub const SplitResizeDirection = Binding.Action.SplitResizeDirection; // Keymap is only available on macOS right now. We could implement it // in theory for XKB too on Linux but we don't need it right now. pub const Keymap = switch (builtin.os.tag) { - .ios, .macos => @import("input/KeymapDarwin.zig"), - else => struct {}, + .macos => @import("input/KeymapDarwin.zig"), + else => @import("input/KeymapNoop.zig"), }; test { diff --git a/src/input/KeymapNoop.zig b/src/input/KeymapNoop.zig new file mode 100644 index 000000000..414c52954 --- /dev/null +++ b/src/input/KeymapNoop.zig @@ -0,0 +1,38 @@ +//! A noop implementation of the keymap interface so that the embedded +//! library can compile on non-macOS platforms. +const KeymapNoop = @This(); + +const Mods = @import("key.zig").Mods; + +pub const State = struct {}; +pub const Translation = struct { + text: []const u8, + composing: bool, +}; + +pub fn init() !KeymapNoop { + return .{}; +} + +pub fn deinit(self: *const KeymapNoop) void { + _ = self; +} + +pub fn reload(self: *KeymapNoop) !void { + _ = self; +} + +pub fn translate( + self: *const KeymapNoop, + out: []u8, + state: *State, + code: u16, + mods: Mods, +) !Translation { + _ = self; + _ = out; + _ = state; + _ = code; + _ = mods; + return .{ .text = "", .composing = false }; +}