gtk(x11): update blur region upon syncAppearance (#5443)

Fixes a bug where the blur region offset used to accomodate CSDs are
applied even when CSDs are disabled.
This commit is contained in:
Mitchell Hashimoto
2025-01-30 13:43:48 -08:00
committed by GitHub
2 changed files with 26 additions and 25 deletions

View File

@ -658,8 +658,9 @@ fn gtkWindowNotifyMaximized(
fn gtkWindowNotifyDecorated(
object: *c.GObject,
_: *c.GParamSpec,
_: ?*anyopaque,
ud: ?*anyopaque,
) callconv(.C) void {
const self = userdataSelf(ud orelse return);
const is_decorated = c.gtk_window_get_decorated(@ptrCast(object)) == 1;
// Fix any artifacting that may occur in window corners. The .ssd CSS
@ -668,6 +669,11 @@ fn gtkWindowNotifyDecorated(
// for .ssd is provided by GTK and Adwaita.
toggleCssClass(@ptrCast(object), "ssd", !is_decorated);
toggleCssClass(@ptrCast(object), "no-border-radius", !is_decorated);
// FIXME: This is to update the blur region offset on X11.
// Remove this when we move everything related to window appearance
// to `syncAppearance` for Ghostty 1.2.
self.winproto.syncAppearance() catch {};
}
fn gtkWindowNotifyFullscreened(

View File

@ -157,7 +157,7 @@ pub const Window = struct {
config: DerivedConfig,
window: c.Window,
gtk_window: *c.GtkWindow,
blur_region: Region,
blur_region: Region = .{},
const DerivedConfig = struct {
blur: bool,
@ -190,34 +190,11 @@ pub const Window = struct {
c.gdk_x11_surface_get_type(),
) == 0) return error.NotX11Surface;
const blur_region: Region = blur: {
if ((comptime !adwaita.versionAtLeast(0, 0, 0)) or
!adwaita.enabled(config)) break :blur .{};
// NOTE(pluiedev): CSDs are a f--king mistake.
// Please, GNOME, stop this nonsense of making a window ~30% bigger
// internally than how they really are just for your shadows and
// rounded corners and all that fluff. Please. I beg of you.
var x: f64 = 0;
var y: f64 = 0;
c.gtk_native_get_surface_transform(
@ptrCast(gtk_window),
&x,
&y,
);
break :blur .{
.x = @intFromFloat(x),
.y = @intFromFloat(y),
};
};
return .{
.app = app,
.config = DerivedConfig.init(config),
.window = c.gdk_x11_surface_get_xid(surface),
.gtk_window = gtk_window,
.blur_region = blur_region,
};
}
@ -241,6 +218,24 @@ pub const Window = struct {
}
pub fn syncAppearance(self: *Window) !void {
self.blur_region = blur: {
// NOTE(pluiedev): CSDs are a f--king mistake.
// Please, GNOME, stop this nonsense of making a window ~30% bigger
// internally than how they really are just for your shadows and
// rounded corners and all that fluff. Please. I beg of you.
var x: f64 = 0;
var y: f64 = 0;
c.gtk_native_get_surface_transform(
@ptrCast(self.gtk_window),
&x,
&y,
);
break :blur .{
.x = @intFromFloat(x),
.y = @intFromFloat(y),
};
};
try self.syncBlur();
}