core: silently fail to connect to linux display and improve logging
This commit is contained in:
parent
2f095fdc21
commit
0a5d817f54
3 changed files with 23 additions and 21 deletions
|
|
@ -88,26 +88,28 @@ pub fn init(
|
||||||
// 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 => blk: {
|
.x11 => blk: {
|
||||||
const x11 = X11.init(linux, core, options) catch |err| switch (err) {
|
const x11 = X11.init(linux, core, options) catch |err| {
|
||||||
error.LibraryNotFound => {
|
const err_msg = switch (err) {
|
||||||
log.err("failed to initialize X11 backend, falling back to Wayland", .{});
|
error.LibraryNotFound => "Missing X11 library",
|
||||||
linux.backend = .{ .wayland = try Wayland.init(linux, core, options) };
|
error.FailedToConnectToDisplay => "Failed to connect to display",
|
||||||
|
else => "An unknown error occured while trying to connect to X11",
|
||||||
break :blk;
|
};
|
||||||
},
|
log.err("{s}\nFalling back to Wayland\n", .{err_msg});
|
||||||
else => return err,
|
linux.backend = .{ .wayland = try Wayland.init(linux, core, options) };
|
||||||
|
break :blk;
|
||||||
};
|
};
|
||||||
linux.backend = .{ .x11 = x11 };
|
linux.backend = .{ .x11 = x11 };
|
||||||
},
|
},
|
||||||
.wayland => blk: {
|
.wayland => blk: {
|
||||||
const wayland = Wayland.init(linux, core, options) catch |err| switch (err) {
|
const wayland = Wayland.init(linux, core, options) catch |err| {
|
||||||
error.LibraryNotFound => {
|
const err_msg = switch (err) {
|
||||||
log.err("failed to initialize Wayland backend, falling back to X11", .{});
|
error.LibraryNotFound => "Missing Wayland library",
|
||||||
linux.backend = .{ .x11 = try X11.init(linux, core, options) };
|
error.FailedToConnectToDisplay => "Failed to connect to display",
|
||||||
|
else => "An unknown error occured while trying to connect to Wayland",
|
||||||
break :blk;
|
};
|
||||||
},
|
log.err("{s}\nFalling back to X11\n", .{err_msg});
|
||||||
else => return err,
|
linux.backend = .{ .x11 = try X11.init(linux, core, options) };
|
||||||
|
break :blk;
|
||||||
};
|
};
|
||||||
linux.backend = .{ .wayland = wayland };
|
linux.backend = .{ .wayland = wayland };
|
||||||
},
|
},
|
||||||
|
|
@ -196,13 +198,13 @@ pub fn wantGamemode(allocator: std.mem.Allocator) error{ OutOfMemory, InvalidWtf
|
||||||
pub fn initLinuxGamemode() bool {
|
pub fn initLinuxGamemode() bool {
|
||||||
mach.gamemode.start();
|
mach.gamemode.start();
|
||||||
if (!mach.gamemode.isActive()) return false;
|
if (!mach.gamemode.isActive()) return false;
|
||||||
gamemode_log.info("gamemode: activated", .{});
|
gamemode_log.info("gamemode: activated\n", .{});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinitLinuxGamemode() void {
|
pub fn deinitLinuxGamemode() void {
|
||||||
mach.gamemode.stop();
|
mach.gamemode.stop();
|
||||||
gamemode_log.info("gamemode: deactivated", .{});
|
gamemode_log.info("gamemode: deactivated\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to inform users that some features are not present. Remove when features are complete.
|
/// Used to inform users that some features are not present. Remove when features are complete.
|
||||||
|
|
@ -213,6 +215,7 @@ fn warnAboutIncompleteFeatures(backend: BackendEnum, missing_features_x11: []con
|
||||||
\\{s}
|
\\{s}
|
||||||
\\
|
\\
|
||||||
\\Contributions welcome!
|
\\Contributions welcome!
|
||||||
|
\\
|
||||||
;
|
;
|
||||||
const bullet_points = switch (backend) {
|
const bullet_points = switch (backend) {
|
||||||
.x11 => try generateFeatureBulletPoints(missing_features_x11, alloc),
|
.x11 => try generateFeatureBulletPoints(missing_features_x11, alloc),
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ pub fn init(
|
||||||
.libxkbcommon = try LibXkbCommon.load(),
|
.libxkbcommon = try LibXkbCommon.load(),
|
||||||
.libwaylandclient = libwaylandclient_global,
|
.libwaylandclient = libwaylandclient_global,
|
||||||
.interfaces = Interfaces{},
|
.interfaces = Interfaces{},
|
||||||
.display = libwaylandclient_global.wl_display_connect(null) orelse return error.FailedToConnectToWaylandDisplay,
|
.display = libwaylandclient_global.wl_display_connect(null) orelse return error.FailedToConnectToDisplay,
|
||||||
.title = try options.allocator.dupeZ(u8, options.title),
|
.title = try options.allocator.dupeZ(u8, options.title),
|
||||||
.size = &linux.size,
|
.size = &linux.size,
|
||||||
.modifiers = .{
|
.modifiers = .{
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,7 @@ pub fn init(
|
||||||
else => return err,
|
else => return err,
|
||||||
};
|
};
|
||||||
const display = libx11.XOpenDisplay(null) orelse {
|
const display = libx11.XOpenDisplay(null) orelse {
|
||||||
std.log.err("X11: Cannot open display", .{});
|
return error.FailedToConnectToDisplay;
|
||||||
return error.CannotOpenDisplay;
|
|
||||||
};
|
};
|
||||||
const screen = c.DefaultScreen(display);
|
const screen = c.DefaultScreen(display);
|
||||||
const visual = c.DefaultVisual(display, screen);
|
const visual = c.DefaultVisual(display, screen);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue