Skip to content

Commit

Permalink
core: send info message about missing features in linux
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-holmes committed Oct 12, 2024
1 parent d18e196 commit f2c0c5d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/core/Linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 }); // TODO: remove this when all features are complete for wayland
}

/// 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;
}

0 comments on commit f2c0c5d

Please sign in to comment.