core: get wayland to compile
This commit is contained in:
parent
8eb2da1044
commit
88d14b5c04
4 changed files with 191 additions and 126 deletions
|
|
@ -1,8 +1,8 @@
|
|||
const std = @import("std");
|
||||
const mach = @import("../main.zig");
|
||||
const Core = @import("../Core.zig");
|
||||
// const X11 = @import("linux/X11.zig");
|
||||
// const Wayland = @import("linux/Wayland.zig");
|
||||
const X11 = @import("linux/X11.zig");
|
||||
const Wayland = @import("linux/Wayland.zig");
|
||||
const gpu = mach.gpu;
|
||||
const InitOptions = Core.InitOptions;
|
||||
const Event = Core.Event;
|
||||
|
|
@ -21,14 +21,14 @@ const KeyMods = Core.KeyMods;
|
|||
const log = std.log.scoped(.mach);
|
||||
const gamemode_log = std.log.scoped(.gamemode);
|
||||
|
||||
// const Backend = union(enum) {
|
||||
// x11: X11,
|
||||
// wayland: Wayland,
|
||||
// };
|
||||
const Backend = enum { // dummy backend
|
||||
const BackendEnum = enum {
|
||||
x11,
|
||||
wayland,
|
||||
};
|
||||
const Backend = union(BackendEnum) {
|
||||
x11: X11,
|
||||
wayland: Wayland,
|
||||
};
|
||||
|
||||
pub const Linux = @This();
|
||||
|
||||
|
|
@ -51,13 +51,11 @@ pub fn init(
|
|||
core: *Core.Mod,
|
||||
options: InitOptions,
|
||||
) !void {
|
||||
_ = core;
|
||||
|
||||
linux.allocator = options.allocator;
|
||||
|
||||
if (!options.is_app and try wantGamemode(linux.allocator)) linux.gamemode = initLinuxGamemode();
|
||||
|
||||
const desired_backend: Backend = blk: {
|
||||
const desired_backend: BackendEnum = blk: {
|
||||
const backend = std.process.getEnvVarOwned(
|
||||
linux.allocator,
|
||||
"MACH_CORE_BACKEND",
|
||||
|
|
@ -83,32 +81,37 @@ pub fn init(
|
|||
// Try to initialize the desired backend, falling back to the other if that one is not supported
|
||||
switch (desired_backend) {
|
||||
.x11 => {
|
||||
// const x11 = X11.init(core, options) catch |err| switch (err) {
|
||||
// error.NotSupported => {
|
||||
// log.err("failed to initialize X11 backend, falling back to Wayland", .{});
|
||||
// linux.backend = .{ .wayland = try Wayland.init(linux, core, options) };
|
||||
// },
|
||||
// else => return err,
|
||||
// };
|
||||
// linux.backend = .{ .x11 = x11 };
|
||||
const x11 = X11.init(linux, core, options) catch |err| switch (err) {
|
||||
error.NotSupported => {
|
||||
log.err("failed to initialize X11 backend, falling back to Wayland", .{});
|
||||
linux.backend = .{ .wayland = try Wayland.init(linux, core, options) };
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
linux.backend = .{ .x11 = x11 };
|
||||
},
|
||||
.wayland => {
|
||||
// const wayland = Wayland.init(core, options) catch |err| switch (err) {
|
||||
// error.NotSupported => {
|
||||
// log.err("failed to initialize Wayland backend, falling back to X11", .{});
|
||||
// linux.backend = .{ .x11 = try X11.init(linux, core, options) };
|
||||
//
|
||||
// // TODO(core): support X11 in the future
|
||||
// @panic("X11 is not supported...YET");
|
||||
// },
|
||||
// else => return err,
|
||||
// };
|
||||
// linux.backend = .{ .wayland = wayland };
|
||||
const wayland = Wayland.init(linux, core, options) catch |err| switch (err) {
|
||||
error.LibraryNotFound => {
|
||||
log.err("failed to initialize Wayland backend, falling back to X11", .{});
|
||||
linux.backend = .{ .x11 = try X11.init(linux, core, options) };
|
||||
|
||||
// TODO(core): support X11 in the future
|
||||
@panic("X11 is not supported...YET");
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
linux.backend = .{ .wayland = wayland };
|
||||
},
|
||||
}
|
||||
|
||||
// linux.size = linux.backend.size;
|
||||
// linux.surface_descriptor = linux.backend.surface_descriptor;
|
||||
switch (linux.backend) {
|
||||
.wayland => |be| {
|
||||
linux.surface_descriptor = .{ .next_in_chain = .{ .from_wayland_surface = &be.surface_descriptor } };
|
||||
},
|
||||
.x11 => {}, // TODO: setup surface descriptor
|
||||
}
|
||||
|
||||
linux.refresh_rate = 60; // TODO: set to something meaningful
|
||||
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue