Skip to content

Commit

Permalink
gtk(x11): update blur region upon syncAppearance (#5443)
Browse files Browse the repository at this point in the history
Fixes a bug where the blur region offset used to accomodate CSDs are
applied even when CSDs are disabled.
  • Loading branch information
mitchellh authored Jan 30, 2025
2 parents 75dec59 + 48a1a10 commit facda0c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
8 changes: 7 additions & 1 deletion src/apprt/gtk/Window.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
43 changes: 19 additions & 24 deletions src/apprt/gtk/winproto/x11.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
};
}

Expand All @@ -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();
}

Expand Down

0 comments on commit facda0c

Please sign in to comment.