clean up some blurring code

pull/8075/head
Mitchell Hashimoto 2025-12-15 09:38:36 -08:00
parent 4ec8adc1b9
commit 47462ccc95
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
1 changed files with 30 additions and 33 deletions

View File

@ -173,7 +173,9 @@ pub const Window = struct {
blur_region: Region = .{}, blur_region: Region = .{},
// Cache last applied values to avoid redundant X11 property updates // Cache last applied values to avoid redundant X11 property updates.
// Redundant property updates seem to cause some visual glitches
// with some window managers: https://github.com/ghostty-org/ghostty/pull/8075
last_applied_blur_region: ?Region = null, last_applied_blur_region: ?Region = null,
last_applied_decoration_hints: ?MotifWMHints = null, last_applied_decoration_hints: ?MotifWMHints = null,
@ -266,6 +268,7 @@ pub const Window = struct {
try self.deleteProperty(self.app.atoms.kde_blur); try self.deleteProperty(self.app.atoms.kde_blur);
self.last_applied_blur_region = null; self.last_applied_blur_region = null;
} }
return; return;
} }
@ -274,29 +277,26 @@ pub const Window = struct {
self.blur_region.width = gtk_widget.getWidth() * scale; self.blur_region.width = gtk_widget.getWidth() * scale;
self.blur_region.height = gtk_widget.getHeight() * scale; self.blur_region.height = gtk_widget.getHeight() * scale;
// Only update X11 properties when the blur region actually changes
if (self.last_applied_blur_region) |last| {
if (std.meta.eql(self.blur_region, last)) return;
}
log.debug("set blur={}, window xid={}, region={}", .{ log.debug("set blur={}, window xid={}, region={}", .{
blur, blur,
self.x11_surface.getXid(), self.x11_surface.getXid(),
self.blur_region, self.blur_region,
}); });
// Only update X11 properties when the blur region actually changes try self.changeProperty(
const region_changed = if (self.last_applied_blur_region) |last| Region,
!std.meta.eql(self.blur_region, last) self.app.atoms.kde_blur,
else c.XA_CARDINAL,
true; ._32,
.{ .mode = .replace },
if (region_changed) { &self.blur_region,
try self.changeProperty( );
Region, self.last_applied_blur_region = self.blur_region;
self.app.atoms.kde_blur,
c.XA_CARDINAL,
._32,
.{ .mode = .replace },
&self.blur_region,
);
self.last_applied_blur_region = self.blur_region;
}
} }
fn syncDecorations(self: *Window) !void { fn syncDecorations(self: *Window) !void {
@ -326,22 +326,19 @@ pub const Window = struct {
}; };
// Only update decoration hints when they actually change // Only update decoration hints when they actually change
const hints_changed = if (self.last_applied_decoration_hints) |last| if (self.last_applied_decoration_hints) |last| {
!std.meta.eql(hints, last) if (std.meta.eql(hints, last)) return;
else
true;
if (hints_changed) {
try self.changeProperty(
MotifWMHints,
self.app.atoms.motif_wm_hints,
self.app.atoms.motif_wm_hints,
._32,
.{ .mode = .replace },
&hints,
);
self.last_applied_decoration_hints = hints;
} }
try self.changeProperty(
MotifWMHints,
self.app.atoms.motif_wm_hints,
self.app.atoms.motif_wm_hints,
._32,
.{ .mode = .replace },
&hints,
);
self.last_applied_decoration_hints = hints;
} }
pub fn addSubprocessEnv(self: *Window, env: *std.process.EnvMap) !void { pub fn addSubprocessEnv(self: *Window, env: *std.process.EnvMap) !void {