gtk: build gtk4-layer-shell ourselves

As of now `gtk4-layer-shell` is unavailable on recent, stable releases
of many distros (Debian 12, Ubuntu 24.04, openSUSE Leap & Tumbleweed, etc.)
and outdated on many others (Nixpkgs 24.11/unstable, Fedora 41, etc.)
This is inconvenient for our users and severely limits where the quick
terminal can be used. As a result we then build gtk4-layer-shell ourselves
by default unless `--system` or `-fsys=gtk4-layer-shell` are specified.
This also allows me to add an idiomatic Zig API on top of the library
and avoiding adding even more raw C code in the GTK apprt.

Since we now build gtk4-layer-shell it should be theoretically available
on all Linux systems we target. As such, the `-Dgtk-layer-shell` build
option has been removed. This is somewhat of an experimental change as
I don't know if gtk4-layer-shell works perfectly across all distros, and
we can always add the option back if need be.
This commit is contained in:
Leah Amelia Chen
2025-03-07 17:03:23 +01:00
parent e07b6fdf6b
commit cd442eb9e2
15 changed files with 241 additions and 68 deletions

View File

@@ -0,0 +1,48 @@
const c = @cImport({
@cInclude("gtk4-layer-shell.h");
});
const gtk = @import("gtk");
pub const ShellLayer = enum(c_uint) {
background = c.GTK_LAYER_SHELL_LAYER_BACKGROUND,
bottom = c.GTK_LAYER_SHELL_LAYER_BOTTOM,
top = c.GTK_LAYER_SHELL_LAYER_TOP,
overlay = c.GTK_LAYER_SHELL_LAYER_OVERLAY,
};
pub const ShellEdge = enum(c_uint) {
left = c.GTK_LAYER_SHELL_EDGE_LEFT,
right = c.GTK_LAYER_SHELL_EDGE_RIGHT,
top = c.GTK_LAYER_SHELL_EDGE_TOP,
bottom = c.GTK_LAYER_SHELL_EDGE_BOTTOM,
};
pub const KeyboardMode = enum(c_uint) {
none = c.GTK_LAYER_SHELL_KEYBOARD_MODE_NONE,
exclusive = c.GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE,
on_demand = c.GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND,
};
pub fn isSupported() bool {
return c.gtk_layer_is_supported() != 0;
}
pub fn initForWindow(window: *gtk.Window) void {
c.gtk_layer_init_for_window(@ptrCast(window));
}
pub fn setLayer(window: *gtk.Window, layer: ShellLayer) void {
c.gtk_layer_set_layer(@ptrCast(window), @intFromEnum(layer));
}
pub fn setAnchor(window: *gtk.Window, edge: ShellEdge, anchor_to_edge: bool) void {
c.gtk_layer_set_anchor(@ptrCast(window), @intFromEnum(edge), @intFromBool(anchor_to_edge));
}
pub fn setMargin(window: *gtk.Window, edge: ShellEdge, margin_size: c_int) void {
c.gtk_layer_set_margin(@ptrCast(window), @intFromEnum(edge), margin_size);
}
pub fn setKeyboardMode(window: *gtk.Window, mode: KeyboardMode) void {
c.gtk_layer_set_keyboard_mode(@ptrCast(window), @intFromEnum(mode));
}