From 2f095fdc21ee7613ec7ee1e7c68fb9884b539980 Mon Sep 17 00:00:00 2001 From: Joshua Holmes Date: Fri, 11 Oct 2024 19:03:01 -0700 Subject: [PATCH] core: send info message about missing features in linux --- src/core/Linux.zig | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/core/Linux.zig b/src/core/Linux.zig index e0126284..ade72017 100644 --- a/src/core/Linux.zig +++ b/src/core/Linux.zig @@ -46,6 +46,11 @@ surface_descriptor: gpu.Surface.Descriptor, gamemode: ?bool = null, backend: Backend, +// these arrays are used as info messages to the user that some features are missing +// please keep these up to date until we can remove them +const MISSING_FEATURES_X11 = [_][]const u8{ "Resizing window", "Changing display mode", "VSync", "Setting window border/title/cursor" }; +const MISSING_FEATURES_WAYLAND = [_][]const u8{ "Resizing window", "Keyboard input", "Changing display mode", "VSync", "Setting window border/title/cursor" }; + pub fn init( linux: *Linux, core: *Core.Mod, @@ -117,6 +122,10 @@ pub fn init( }, } + // warn about incomplete features + // TODO: remove this when linux is not missing major features + try warnAboutIncompleteFeatures(linux.backend, &MISSING_FEATURES_X11, &MISSING_FEATURES_WAYLAND, options.allocator); + return; } @@ -195,3 +204,37 @@ pub fn deinitLinuxGamemode() void { mach.gamemode.stop(); gamemode_log.info("gamemode: deactivated", .{}); } + +/// Used to inform users that some features are not present. Remove when features are complete. +fn warnAboutIncompleteFeatures(backend: BackendEnum, missing_features_x11: []const []const u8, missing_features_wayland: []const []const u8, alloc: std.mem.Allocator) !void { + const features_incomplete_message = + \\WARNING: You are using the {s} backend, which is currently experimental as we continue to rewrite Mach in Zig instead of using C libraries like GLFW/etc. The following features are expected to not work: + \\ + \\{s} + \\ + \\Contributions welcome! + ; + const bullet_points = switch (backend) { + .x11 => try generateFeatureBulletPoints(missing_features_x11, alloc), + .wayland => try generateFeatureBulletPoints(missing_features_wayland, alloc), + }; + defer bullet_points.deinit(); + log.info(features_incomplete_message, .{ @tagName(backend), bullet_points.items }); +} + +/// Turn an array of strings into a single, bullet-pointed string, like this: +/// * Item one +/// * Item two +/// +/// Returned value will need to be deinitialized. +fn generateFeatureBulletPoints(features: []const []const u8, alloc: std.mem.Allocator) !std.ArrayList(u8) { + var message = std.ArrayList(u8).init(alloc); + for (features, 0..) |str, i| { + try message.appendSlice("* "); + try message.appendSlice(str); + if (i < features.len - 1) { + try message.appendSlice("\n"); + } + } + return message; +}