gtk/winproto: fix memleak & other tweaks

This commit is contained in:
Leah Amelia Chen
2026-03-18 03:19:22 +08:00
parent 80ab5d92ea
commit 27fd1c7788
6 changed files with 47 additions and 42 deletions

View File

@@ -1235,7 +1235,7 @@ pub const Window = extern struct {
fn finalize(self: *Self) callconv(.c) void {
const priv = self.private();
priv.tab_bindings.unref();
priv.winproto.deinit(Application.default().allocator());
priv.winproto.deinit();
gobject.Object.virtual_methods.finalize.call(
Class.parent,

View File

@@ -117,9 +117,9 @@ pub const Window = union(Protocol) {
};
}
pub fn deinit(self: *Window, alloc: Allocator) void {
pub fn deinit(self: *Window) void {
switch (self.*) {
inline else => |*v| v.deinit(alloc),
inline else => |*v| v.deinit(),
}
}

View File

@@ -63,9 +63,11 @@ pub fn calcForWindow(
var x: f64 = 0;
var y: f64 = 0;
native.getSurfaceTransform(&x, &y);
// Slightly inset the corners
x += 1;
y += 1;
// Slightly inset the corners if we're using CSDs
if (csd) {
x += 1;
y += 1;
}
break :off .{ @intFromFloat(x), @intFromFloat(y) };
};

View File

@@ -46,9 +46,8 @@ pub const Window = struct {
return .{};
}
pub fn deinit(self: Window, alloc: Allocator) void {
pub fn deinit(self: *Window) void {
_ = self;
_ = alloc;
}
pub fn updateConfigEvent(

View File

@@ -185,8 +185,8 @@ pub const Window = struct {
};
}
pub fn deinit(self: Window, alloc: Allocator) void {
_ = alloc;
pub fn deinit(self: *Window) void {
self.blur_region.deinit(self.globals.alloc);
if (self.bg_effect) |bg| bg.destroy();
if (self.decoration) |deco| deco.release();
if (self.slide) |slide| slide.release();
@@ -203,7 +203,7 @@ pub const Window = struct {
log.err("failed to sync blur={}", .{err});
};
self.syncDecoration() catch |err| {
log.err("failed to sync blur={}", .{err});
log.err("failed to sync decoration={}", .{err});
};
if (self.apprt_window.isQuickTerminal()) {

View File

@@ -200,24 +200,25 @@ pub const Window = struct {
};
}
pub fn deinit(self: Window, alloc: Allocator) void {
_ = self;
_ = alloc;
pub fn deinit(self: *Window) void {
self.blur_region.deinit(self.alloc);
}
pub fn resizeEvent(self: *Window) !void {
// The blur region must update with window resizes
try self.syncBlur();
self.syncBlur() catch |err| {
log.err("failed to sync blur={}", .{err});
};
}
pub fn syncAppearance(self: *Window) !void {
// The user could have toggled between CSDs and SSDs,
// therefore we need to recalculate the blur region offset.
self.syncBlur() catch |err| {
log.err("failed to synchronize blur={}", .{err});
log.err("failed to sync blur={}", .{err});
};
self.syncDecorations() catch |err| {
log.err("failed to synchronize decorations={}", .{err});
log.err("failed to sync decorations={}", .{err});
};
}
@@ -233,19 +234,16 @@ pub const Window = struct {
// When blur is disabled, remove the property if it was previously set
const blur = config.@"background-blur";
if (!blur.enabled()) {
self.blur_region.deinit(self.alloc);
self.blur_region = .empty;
try self.deleteProperty(self.app.atoms.kde_blur);
return;
}
var region: BlurRegion = try .calcForWindow(
self.alloc,
self.apprt_window,
self.clientSideDecorationEnabled(),
true,
);
var region: BlurRegion = if (blur.enabled())
try .calcForWindow(
self.alloc,
self.apprt_window,
self.clientSideDecorationEnabled(),
true,
)
else
.empty;
errdefer region.deinit(self.alloc);
// Only update X11 properties when the blur region actually changes
@@ -254,20 +252,26 @@ pub const Window = struct {
return;
}
log.debug("set blur={}, window xid={}, region={}", .{
blur,
self.x11_surface.getXid(),
self.blur_region,
});
if (region.slices.items.len > 0) {
log.debug("set blur={}, window xid={}, region={}", .{
blur,
self.x11_surface.getXid(),
region,
});
try self.changeProperty(
BlurRegion.Slice,
self.app.atoms.kde_blur,
c.XA_CARDINAL,
._32,
.{ .mode = .replace },
self.blur_region.slices.items,
);
try self.changeProperty(
BlurRegion.Slice,
self.app.atoms.kde_blur,
c.XA_CARDINAL,
._32,
.{ .mode = .replace },
region.slices.items,
);
} else {
try self.deleteProperty(self.app.atoms.kde_blur);
}
self.blur_region.deinit(self.alloc);
self.blur_region = region;
}