From 3ab49fdb5fb681295670cf06a410f076794b6947 Mon Sep 17 00:00:00 2001 From: rhodes-b <59537185+rhodes-b@users.noreply.github.com> Date: Sun, 30 Nov 2025 21:06:25 -0600 Subject: [PATCH 1/2] only notify search change when widget was inactive --- src/apprt/gtk/class/search_overlay.zig | 11 +++++++---- src/apprt/gtk/class/surface.zig | 11 +++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/apprt/gtk/class/search_overlay.zig b/src/apprt/gtk/class/search_overlay.zig index ffa9174b2..b193d9511 100644 --- a/src/apprt/gtk/class/search_overlay.zig +++ b/src/apprt/gtk/class/search_overlay.zig @@ -223,6 +223,13 @@ pub const SearchOverlay = extern struct { gtk.Widget.initTemplate(self.as(gtk.Widget)); } + /// Update search contents when widget is activated + pub fn updateSearch(self: *Self) void { + const priv = self.private(); + const text = priv.search_entry.as(gtk.Editable).getText(); + signals.@"search-changed".impl.emit(self, null, .{text}, null); + } + /// Grab focus on the search entry and select all text. pub fn grabFocus(self: *Self) void { const priv = self.private(); @@ -231,10 +238,6 @@ pub const SearchOverlay = extern struct { // Select all text in the search entry field. -1 is distance from // the end, causing the entire text to be selected. priv.search_entry.as(gtk.Editable).selectRegion(0, -1); - - // update search state with the active text - const text = priv.search_entry.as(gtk.Editable).getText(); - signals.@"search-changed".impl.emit(self, null, .{text}, null); } /// Set the total number of search matches. diff --git a/src/apprt/gtk/class/surface.zig b/src/apprt/gtk/class/surface.zig index 2af53e1ef..49a6fbf42 100644 --- a/src/apprt/gtk/class/surface.zig +++ b/src/apprt/gtk/class/surface.zig @@ -1964,6 +1964,17 @@ pub const Surface = extern struct { SearchOverlay.properties.active.name, &value, ); + + var is_active = gobject.ext.Value.newFrom(false); + defer is_active.unset(); + gobject.Object.getProperty( + priv.search_overlay.as(gobject.Object), + SearchOverlay.properties.active.name, + &is_active + ); + if (active and !is_active) { + priv.search_overlay.updateSearch(); + } if (active) { priv.search_overlay.grabFocus(); } From 27c82f739e9ae22a93e9cef0bb1912dd976dd0d0 Mon Sep 17 00:00:00 2001 From: rhodes-b <59537185+rhodes-b@users.noreply.github.com> Date: Sun, 30 Nov 2025 21:22:07 -0600 Subject: [PATCH 2/2] only update search when going from inactive to active --- src/apprt/gtk/class/search_overlay.zig | 30 +++++++++++++++++++------- src/apprt/gtk/class/surface.zig | 10 --------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/apprt/gtk/class/search_overlay.zig b/src/apprt/gtk/class/search_overlay.zig index b193d9511..4936cd967 100644 --- a/src/apprt/gtk/class/search_overlay.zig +++ b/src/apprt/gtk/class/search_overlay.zig @@ -43,7 +43,14 @@ pub const SearchOverlay = extern struct { bool, .{ .default = false, - .accessor = C.privateShallowFieldAccessor("active"), + .accessor = gobject.ext.typedAccessor( + Self, + bool, + .{ + .getter = getSearchActive, + .setter = setSearchActive, + }, + ), }, ); }; @@ -223,13 +230,6 @@ pub const SearchOverlay = extern struct { gtk.Widget.initTemplate(self.as(gtk.Widget)); } - /// Update search contents when widget is activated - pub fn updateSearch(self: *Self) void { - const priv = self.private(); - const text = priv.search_entry.as(gtk.Editable).getText(); - signals.@"search-changed".impl.emit(self, null, .{text}, null); - } - /// Grab focus on the search entry and select all text. pub fn grabFocus(self: *Self) void { const priv = self.private(); @@ -240,6 +240,16 @@ pub const SearchOverlay = extern struct { priv.search_entry.as(gtk.Editable).selectRegion(0, -1); } + // Set active status, and update search on activation + fn setSearchActive(self: *Self, active: bool) void { + const priv = self.private(); + if (!priv.active and active) { + const text = priv.search_entry.as(gtk.Editable).getText(); + signals.@"search-changed".impl.emit(self, null, .{text}, null); + } + priv.active = active; + } + /// Set the total number of search matches. pub fn setSearchTotal(self: *Self, total: ?usize) void { const priv = self.private(); @@ -264,6 +274,10 @@ pub const SearchOverlay = extern struct { } } + fn getSearchActive(self: *Self) bool { + return self.private().active; + } + fn getSearchTotal(self: *Self) u64 { return self.private().search_total orelse 0; } diff --git a/src/apprt/gtk/class/surface.zig b/src/apprt/gtk/class/surface.zig index 49a6fbf42..a4d2d6696 100644 --- a/src/apprt/gtk/class/surface.zig +++ b/src/apprt/gtk/class/surface.zig @@ -1965,16 +1965,6 @@ pub const Surface = extern struct { &value, ); - var is_active = gobject.ext.Value.newFrom(false); - defer is_active.unset(); - gobject.Object.getProperty( - priv.search_overlay.as(gobject.Object), - SearchOverlay.properties.active.name, - &is_active - ); - if (active and !is_active) { - priv.search_overlay.updateSearch(); - } if (active) { priv.search_overlay.grabFocus(); }