apprt/gtk: hook up start_search/end_search to set active state
parent
027e5d631a
commit
778b49c9a1
|
|
@ -727,6 +727,9 @@ pub const Application = extern struct {
|
||||||
.show_on_screen_keyboard => return Action.showOnScreenKeyboard(target),
|
.show_on_screen_keyboard => return Action.showOnScreenKeyboard(target),
|
||||||
.command_finished => return Action.commandFinished(target, value),
|
.command_finished => return Action.commandFinished(target, value),
|
||||||
|
|
||||||
|
.start_search => Action.startSearch(target),
|
||||||
|
.end_search => Action.endSearch(target),
|
||||||
|
|
||||||
// Unimplemented
|
// Unimplemented
|
||||||
.secure_input,
|
.secure_input,
|
||||||
.close_all_windows,
|
.close_all_windows,
|
||||||
|
|
@ -741,8 +744,6 @@ pub const Application = extern struct {
|
||||||
.check_for_updates,
|
.check_for_updates,
|
||||||
.undo,
|
.undo,
|
||||||
.redo,
|
.redo,
|
||||||
.start_search,
|
|
||||||
.end_search,
|
|
||||||
.search_total,
|
.search_total,
|
||||||
.search_selected,
|
.search_selected,
|
||||||
=> {
|
=> {
|
||||||
|
|
@ -2341,6 +2342,20 @@ const Action = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn startSearch(target: apprt.Target) void {
|
||||||
|
switch (target) {
|
||||||
|
.app => {},
|
||||||
|
.surface => |v| v.rt_surface.surface.setSearchActive(true),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn endSearch(target: apprt.Target) void {
|
||||||
|
switch (target) {
|
||||||
|
.app => {},
|
||||||
|
.surface => |v| v.rt_surface.surface.setSearchActive(false),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setTitle(
|
pub fn setTitle(
|
||||||
target: apprt.Target,
|
target: apprt.Target,
|
||||||
value: apprt.action.SetTitle,
|
value: apprt.action.SetTitle,
|
||||||
|
|
|
||||||
|
|
@ -34,39 +34,39 @@ pub const SearchOverlay = extern struct {
|
||||||
});
|
});
|
||||||
|
|
||||||
pub const properties = struct {
|
pub const properties = struct {
|
||||||
pub const duration = struct {
|
pub const active = struct {
|
||||||
pub const name = "duration";
|
pub const name = "active";
|
||||||
const impl = gobject.ext.defineProperty(
|
const impl = gobject.ext.defineProperty(
|
||||||
name,
|
name,
|
||||||
Self,
|
Self,
|
||||||
c_uint,
|
bool,
|
||||||
.{
|
.{
|
||||||
.default = 750,
|
.default = false,
|
||||||
.minimum = 250,
|
.accessor = C.privateShallowFieldAccessor("active"),
|
||||||
.maximum = std.math.maxInt(c_uint),
|
|
||||||
.accessor = gobject.ext.privateFieldAccessor(
|
|
||||||
Self,
|
|
||||||
Private,
|
|
||||||
&Private.offset,
|
|
||||||
"duration",
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const Private = struct {
|
const Private = struct {
|
||||||
/// The time that the overlay appears.
|
/// The search entry widget.
|
||||||
duration: c_uint,
|
search_entry: *gtk.SearchEntry,
|
||||||
|
|
||||||
|
/// True when a search is active, meaning we should show the overlay.
|
||||||
|
active: bool = false,
|
||||||
|
|
||||||
pub var offset: c_int = 0;
|
pub var offset: c_int = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
fn init(self: *Self, _: *Class) callconv(.c) void {
|
fn init(self: *Self, _: *Class) callconv(.c) void {
|
||||||
gtk.Widget.initTemplate(self.as(gtk.Widget));
|
gtk.Widget.initTemplate(self.as(gtk.Widget));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Grab focus on the search entry and select all text.
|
||||||
|
pub fn grabFocus(self: *Self) void {
|
||||||
const priv = self.private();
|
const priv = self.private();
|
||||||
_ = priv;
|
_ = priv.search_entry.as(gtk.Widget).grabFocus();
|
||||||
|
priv.search_entry.as(gtk.Editable).selectRegion(0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
|
|
@ -119,16 +119,12 @@ pub const SearchOverlay = extern struct {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Bindings
|
// Bindings
|
||||||
// class.bindTemplateChildPrivate("label", .{});
|
class.bindTemplateChildPrivate("search_entry", .{});
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
// gobject.ext.registerProperties(class, &.{
|
gobject.ext.registerProperties(class, &.{
|
||||||
// properties.duration.impl,
|
properties.active.impl,
|
||||||
// properties.label.impl,
|
});
|
||||||
// properties.@"first-delay".impl,
|
|
||||||
// properties.@"overlay-halign".impl,
|
|
||||||
// properties.@"overlay-valign".impl,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Virtual methods
|
// Virtual methods
|
||||||
gobject.Object.virtual_methods.dispose.implement(class, &dispose);
|
gobject.Object.virtual_methods.dispose.implement(class, &dispose);
|
||||||
|
|
|
||||||
|
|
@ -550,6 +550,9 @@ pub const Surface = extern struct {
|
||||||
/// The resize overlay
|
/// The resize overlay
|
||||||
resize_overlay: *ResizeOverlay,
|
resize_overlay: *ResizeOverlay,
|
||||||
|
|
||||||
|
/// The search overlay
|
||||||
|
search_overlay: *SearchOverlay,
|
||||||
|
|
||||||
/// The apprt Surface.
|
/// The apprt Surface.
|
||||||
rt_surface: ApprtSurface = undefined,
|
rt_surface: ApprtSurface = undefined,
|
||||||
|
|
||||||
|
|
@ -1952,6 +1955,20 @@ pub const Surface = extern struct {
|
||||||
self.as(gobject.Object).notifyByPspec(properties.@"error".impl.param_spec);
|
self.as(gobject.Object).notifyByPspec(properties.@"error".impl.param_spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setSearchActive(self: *Self, active: bool) void {
|
||||||
|
const priv = self.private();
|
||||||
|
var value = gobject.ext.Value.newFrom(active);
|
||||||
|
defer value.unset();
|
||||||
|
gobject.Object.setProperty(
|
||||||
|
priv.search_overlay.as(gobject.Object),
|
||||||
|
SearchOverlay.properties.active.name,
|
||||||
|
&value,
|
||||||
|
);
|
||||||
|
if (active) {
|
||||||
|
priv.search_overlay.grabFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn propConfig(
|
fn propConfig(
|
||||||
self: *Self,
|
self: *Self,
|
||||||
_: *gobject.ParamSpec,
|
_: *gobject.ParamSpec,
|
||||||
|
|
@ -3205,6 +3222,7 @@ pub const Surface = extern struct {
|
||||||
class.bindTemplateChildPrivate("error_page", .{});
|
class.bindTemplateChildPrivate("error_page", .{});
|
||||||
class.bindTemplateChildPrivate("progress_bar_overlay", .{});
|
class.bindTemplateChildPrivate("progress_bar_overlay", .{});
|
||||||
class.bindTemplateChildPrivate("resize_overlay", .{});
|
class.bindTemplateChildPrivate("resize_overlay", .{});
|
||||||
|
class.bindTemplateChildPrivate("search_overlay", .{});
|
||||||
class.bindTemplateChildPrivate("terminal_page", .{});
|
class.bindTemplateChildPrivate("terminal_page", .{});
|
||||||
class.bindTemplateChildPrivate("drop_target", .{});
|
class.bindTemplateChildPrivate("drop_target", .{});
|
||||||
class.bindTemplateChildPrivate("im_context", .{});
|
class.bindTemplateChildPrivate("im_context", .{});
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using Gdk 4.0;
|
||||||
using Adw 1;
|
using Adw 1;
|
||||||
|
|
||||||
template $GhosttySearchOverlay: Adw.Bin {
|
template $GhosttySearchOverlay: Adw.Bin {
|
||||||
|
visible: bind template.active;
|
||||||
halign: end;
|
halign: end;
|
||||||
valign: start;
|
valign: start;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue