core: enable x11 and set as default for linux
This commit is contained in:
parent
9a0398e782
commit
fcba68282d
2 changed files with 32 additions and 27 deletions
|
|
@ -54,6 +54,14 @@ pub fn init(
|
||||||
linux.allocator = options.allocator;
|
linux.allocator = options.allocator;
|
||||||
|
|
||||||
if (!options.is_app and try wantGamemode(linux.allocator)) linux.gamemode = initLinuxGamemode();
|
if (!options.is_app and try wantGamemode(linux.allocator)) linux.gamemode = initLinuxGamemode();
|
||||||
|
linux.headless = options.headless;
|
||||||
|
linux.refresh_rate = 60; // TODO: set to something meaningful
|
||||||
|
linux.vsync_mode = .triple;
|
||||||
|
linux.size = options.size;
|
||||||
|
if (!options.headless) {
|
||||||
|
// TODO: this function does nothing right now
|
||||||
|
setDisplayMode(linux, options.display_mode);
|
||||||
|
}
|
||||||
|
|
||||||
const desired_backend: BackendEnum = blk: {
|
const desired_backend: BackendEnum = blk: {
|
||||||
const backend = std.process.getEnvVarOwned(
|
const backend = std.process.getEnvVarOwned(
|
||||||
|
|
@ -61,8 +69,7 @@ pub fn init(
|
||||||
"MACH_CORE_BACKEND",
|
"MACH_CORE_BACKEND",
|
||||||
) catch |err| switch (err) {
|
) catch |err| switch (err) {
|
||||||
error.EnvironmentVariableNotFound => {
|
error.EnvironmentVariableNotFound => {
|
||||||
// TODO(core): default to .x11 in the future
|
break :blk .x11;
|
||||||
break :blk .wayland;
|
|
||||||
},
|
},
|
||||||
else => return err,
|
else => return err,
|
||||||
};
|
};
|
||||||
|
|
@ -73,31 +80,27 @@ pub fn init(
|
||||||
std.debug.panic("mach: unknown MACH_CORE_BACKEND: {s}", .{backend});
|
std.debug.panic("mach: unknown MACH_CORE_BACKEND: {s}", .{backend});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (desired_backend == .x11) {
|
|
||||||
// TODO(core): support X11 in the future
|
|
||||||
@panic("X11 is not supported...YET");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to initialize the desired backend, falling back to the other if that one is not supported
|
// Try to initialize the desired backend, falling back to the other if that one is not supported
|
||||||
switch (desired_backend) {
|
switch (desired_backend) {
|
||||||
.x11 => {
|
.x11 => blk: {
|
||||||
// const x11 = X11.init(linux, core, options) catch |err| switch (err) {
|
const x11 = X11.init(linux, core, options) catch |err| switch (err) {
|
||||||
// error.NotSupported => {
|
error.LibraryNotFound => {
|
||||||
// log.err("failed to initialize X11 backend, falling back to Wayland", .{});
|
log.err("failed to initialize X11 backend, falling back to Wayland", .{});
|
||||||
// linux.backend = .{ .wayland = try Wayland.init(linux, core, options) };
|
linux.backend = .{ .wayland = try Wayland.init(linux, core, options) };
|
||||||
// },
|
|
||||||
// else => return err,
|
break :blk;
|
||||||
// };
|
},
|
||||||
// linux.backend = .{ .x11 = x11 };
|
else => return err,
|
||||||
|
};
|
||||||
|
linux.backend = .{ .x11 = x11 };
|
||||||
},
|
},
|
||||||
.wayland => {
|
.wayland => blk: {
|
||||||
const wayland = Wayland.init(linux, core, options) catch |err| switch (err) {
|
const wayland = Wayland.init(linux, core, options) catch |err| switch (err) {
|
||||||
error.LibraryNotFound => {
|
error.LibraryNotFound => {
|
||||||
log.err("failed to initialize Wayland backend, falling back to X11", .{});
|
log.err("failed to initialize Wayland backend, falling back to X11", .{});
|
||||||
linux.backend = .{ .x11 = try X11.init(linux, core, options) };
|
linux.backend = .{ .x11 = try X11.init(linux, core, options) };
|
||||||
|
|
||||||
// TODO(core): support X11 in the future
|
break :blk;
|
||||||
@panic("X11 is not supported...YET");
|
|
||||||
},
|
},
|
||||||
else => return err,
|
else => return err,
|
||||||
};
|
};
|
||||||
|
|
@ -114,8 +117,6 @@ pub fn init(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
linux.refresh_rate = 60; // TODO: set to something meaningful
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,7 +130,11 @@ pub fn deinit(linux: *Linux) void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(_: *Linux) !void {
|
pub fn update(linux: *Linux) !void {
|
||||||
|
switch (linux.backend) {
|
||||||
|
.wayland => {},
|
||||||
|
.x11 => try linux.backend.x11.update(),
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ display_mode: DisplayMode = .windowed,
|
||||||
vsync_mode: VSyncMode = .triple,
|
vsync_mode: VSyncMode = .triple,
|
||||||
border: bool,
|
border: bool,
|
||||||
headless: bool,
|
headless: bool,
|
||||||
size: Core.Size,
|
size: *Core.Size,
|
||||||
cursor_mode: CursorMode = .normal,
|
cursor_mode: CursorMode = .normal,
|
||||||
cursor_shape: CursorShape = .arrow,
|
cursor_shape: CursorShape = .arrow,
|
||||||
surface_descriptor: *gpu.Surface.DescriptorFromXlibWindow,
|
surface_descriptor: *gpu.Surface.DescriptorFromXlibWindow,
|
||||||
|
|
@ -119,8 +119,8 @@ pub fn init(
|
||||||
root_window,
|
root_window,
|
||||||
@divFloor(libx11.XDisplayWidth(display, screen), 2), // TODO: add window width?
|
@divFloor(libx11.XDisplayWidth(display, screen), 2), // TODO: add window width?
|
||||||
@divFloor(libx11.XDisplayHeight(display, screen), 2), // TODO: add window height?
|
@divFloor(libx11.XDisplayHeight(display, screen), 2), // TODO: add window height?
|
||||||
options.size.width,
|
linux.size.width,
|
||||||
options.size.height,
|
linux.size.height,
|
||||||
0,
|
0,
|
||||||
c.DefaultDepth(display, screen),
|
c.DefaultDepth(display, screen),
|
||||||
c.InputOutput,
|
c.InputOutput,
|
||||||
|
|
@ -130,7 +130,7 @@ pub fn init(
|
||||||
);
|
);
|
||||||
var window_attrs: c.XWindowAttributes = undefined;
|
var window_attrs: c.XWindowAttributes = undefined;
|
||||||
_ = libx11.XGetWindowAttributes(display, window, &window_attrs);
|
_ = libx11.XGetWindowAttributes(display, window, &window_attrs);
|
||||||
const window_size = Core.Size{
|
linux.size = Core.Size{
|
||||||
.width = @intCast(window_attrs.width),
|
.width = @intCast(window_attrs.width),
|
||||||
.height = @intCast(window_attrs.height),
|
.height = @intCast(window_attrs.height),
|
||||||
};
|
};
|
||||||
|
|
@ -180,7 +180,7 @@ pub fn init(
|
||||||
.display_mode = .windowed,
|
.display_mode = .windowed,
|
||||||
.border = options.border,
|
.border = options.border,
|
||||||
.headless = options.headless,
|
.headless = options.headless,
|
||||||
.size = window_size,
|
.size = &linux.size,
|
||||||
.cursors = std.mem.zeroes([@typeInfo(CursorShape).@"enum".fields.len]?c.Cursor),
|
.cursors = std.mem.zeroes([@typeInfo(CursorShape).@"enum".fields.len]?c.Cursor),
|
||||||
.surface_descriptor = surface_descriptor,
|
.surface_descriptor = surface_descriptor,
|
||||||
.libxkbcommon = try LibXkbCommon.load(),
|
.libxkbcommon = try LibXkbCommon.load(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue