fix: Disable quick terminal on linux when gtk4-layer-shell version is incompatible

This commit is contained in:
azhn
2025-04-22 03:49:52 +10:00
parent fad05c752b
commit 511889b3aa
4 changed files with 39 additions and 1 deletions

View File

@ -1,6 +1,7 @@
const c = @cImport({
@cInclude("gtk4-layer-shell.h");
});
const std = @import("std");
const gtk = @import("gtk");
pub const ShellLayer = enum(c_uint) {
@ -23,14 +24,27 @@ pub const KeyboardMode = enum(c_uint) {
on_demand = c.GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND,
};
/// Returns True if the platform is Wayland and Wayland compositor supports the
/// zwlr_layer_shell_v1 protocol.
pub fn isProtocolSupported() bool {
return c.gtk_layer_is_supported() != 0;
}
/// Returns the version of the zwlr_layer_shell_v1 protocol supported by the
/// compositor or 0 if the protocol is not supported.
pub fn getProtocolVersion() c_uint {
return c.gtk_layer_get_protocol_version();
}
/// Returns the runtime version of the GTK Layer Shell library
pub fn getRuntimeVersion() std.SemanticVersion {
return std.SemanticVersion{
.major = c.gtk_layer_get_major_version(),
.minor = c.gtk_layer_get_minor_version(),
.patch = c.gtk_layer_get_micro_version(),
};
}
pub fn initForWindow(window: *gtk.Window) void {
c.gtk_layer_init_for_window(@ptrCast(window));
}

View File

@ -0,0 +1,10 @@
const std = @import("std");
const gtk4_layer_shell = @import("gtk4-layer-shell");
const VersionChecked = @import("version.zig").VersionChecked;
pub const getRuntimeVersion = gtk4_layer_shell.getRuntimeVersion;
const LayerShellVersion = VersionChecked("gtk4-layer-shell", std.log.scoped(.gtk), getRuntimeVersion, null);
pub const atLeast = LayerShellVersion.atLeast;
pub const runtimeAtLeast = LayerShellVersion.runtimeAtLeast;
pub const logVersion = LayerShellVersion.logVersion;

View File

@ -10,6 +10,8 @@ const gtk = @import("gtk");
const layer_shell = @import("gtk4-layer-shell");
const wayland = @import("wayland");
const gtk_version = @import("../gtk_version.zig");
const gtk_layer_version = @import("../gtk_layer_version.zig");
const Config = @import("../../../config.zig").Config;
const input = @import("../../../input.zig");
const ApprtWindow = @import("../Window.zig");
@ -37,6 +39,7 @@ pub const App = struct {
default_deco_mode: ?org.KdeKwinServerDecorationManager.Mode = null,
xdg_activation: ?*xdg.ActivationV1 = null,
xdg_wm_dialog: ?*xdg.WmDialogV1 = null,
};
pub fn init(
@ -95,11 +98,19 @@ pub const App = struct {
return null;
}
pub fn supportsQuickTerminal(_: App) bool {
pub fn supportsQuickTerminal(self: App) bool {
if (!layer_shell.isProtocolSupported()) {
log.warn("your compositor does not support the wlr-layer-shell protocol; disabling quick terminal", .{});
return false;
}
// GTK4 >= 4.16.0 uses xdg_wm_dialog protocol if available which breaks gtk_layer_shell < 1.0.4
// See: https://github.com/wmww/gtk4-layer-shell/issues/50
if (self.context.xdg_wm_dialog) |_| {
if (gtk_version.atLeast(4, 16, 0) and !gtk_layer_version.atLeast(1, 0, 4)) {
log.warn("Your gtk4-layer-shell version is too old for your compositor and gtk4 version; disabling quick terminal", .{});
return false;
}
}
return true;
}

View File

@ -620,12 +620,15 @@ fn addGTK(
plasma_wayland_protocols_dep.path("src/protocols/slide.xml"),
);
scanner.addSystemProtocol("staging/xdg-activation/xdg-activation-v1.xml");
scanner.addCustomProtocol(wayland_protocols_dep.path("staging/xdg-dialog/xdg-dialog-v1.xml"));
scanner.addCustomProtocol(wayland_protocols_dep.path("stable/xdg-shell/xdg-shell.xml"));
scanner.generate("wl_compositor", 1);
scanner.generate("org_kde_kwin_blur_manager", 1);
scanner.generate("org_kde_kwin_server_decoration_manager", 1);
scanner.generate("org_kde_kwin_slide_manager", 1);
scanner.generate("xdg_activation_v1", 1);
scanner.generate("xdg_wm_dialog_v1", 1);
step.root_module.addImport("wayland", b.createModule(.{
.root_source_file = scanner.result,