From e33424278a3285ff93058ae69b71c8a7dc3d2b33 Mon Sep 17 00:00:00 2001 From: Andrej Benz Date: Sat, 24 Aug 2024 19:33:18 +0200 Subject: [PATCH] minor: added 'active' flag to indicate the active item for dmenu usage --- README.md | 11 ++++++----- cmd/walker.go | 14 ++++++++++++++ internal/state/appstate.go | 1 + internal/ui/ui.go | 14 +++++++++++++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e6cf1d4..c14142d 100644 --- a/README.md +++ b/README.md @@ -208,11 +208,12 @@ The window and items will have a class based on the source. Selecting an item wi F.e. search = `!somecommand` => `#window.runner` -| class | condition | -| -------------------- | ---------------------- | -| `#window.activation` | AM enabled | -| `#spinner.visible` | Processing in progress | -| `#item.` | Always | +| class | condition | +| -------------------- | -------------------------- | +| `#window.activation` | AM enabled | +| `#spinner.visible` | Processing in progress | +| `#item.` | Always | +| `#item.active` | Dmenu with '--active'-flag | ### Starting as service diff --git a/cmd/walker.go b/cmd/walker.go index 7bffd6f..4534787 100644 --- a/cmd/walker.go +++ b/cmd/walker.go @@ -105,6 +105,7 @@ func main() { app.AddMainOption("version", 'v', glib.OptionFlagNone, glib.OptionArgNone, "print version", "") app.AddMainOption("forceprint", 'f', glib.OptionFlagNone, glib.OptionArgNone, "forces printing input if no item is selected", "") app.AddMainOption("bench", 'b', glib.OptionFlagNone, glib.OptionArgNone, "prints nanoseconds for start and displaying in both service and client", "") + app.AddMainOption("active", 'a', glib.OptionFlagNone, glib.OptionArgString, "active item", "") app.Connect("activate", ui.Activate(state)) @@ -128,6 +129,7 @@ func main() { if options.Contains("dmenu") { labelColumnString := options.LookupValue("labelcolumn", glib.NewVariantString("").Type()) separatorString := options.LookupValue("separator", glib.NewVariantString("").Type()) + activeItemString := options.LookupValue("active", glib.NewVariantString("").Type()) if separatorString != nil && separatorString.String() != "" { if state.Dmenu != nil { @@ -150,8 +152,20 @@ func main() { } } + if activeItemString != nil && activeItemString.String() != "" { + n := activeItemString.String() + + a, err := strconv.Atoi(n) + if err != nil { + log.Println(err) + } + + state.ActiveItem = a - 1 + } + state.ExplicitModules = append(state.ExplicitModules, "dmenu") state.IsDmenu = true + } else { if modulesString != nil && modulesString.String() != "" { m := strings.Split(modulesString.String(), ",") diff --git a/internal/state/appstate.go b/internal/state/appstate.go index c0436bd..6cf5e5d 100644 --- a/internal/state/appstate.go +++ b/internal/state/appstate.go @@ -11,6 +11,7 @@ import ( ) type AppState struct { + ActiveItem int Clipboard modules.Workable IsDmenu bool Dmenu *modules.Dmenu diff --git a/internal/ui/ui.go b/internal/ui/ui.go index 78fe5f0..02472a6 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -342,7 +342,19 @@ func setupFactory() *gtk.SignalListItemFactory { box.AddController(dd) } - box.SetCSSClasses([]string{"item", val.Class}) + boxClasses := []string{"item", val.Class} + + if appstate.ActiveItem >= 0 { + if item.Position() == uint(appstate.ActiveItem) { + boxClasses = append(boxClasses, "active") + } + } else { + if item.Position() == common.selection.NItems()-1 { + boxClasses = append(boxClasses, "active") + } + } + + box.SetCSSClasses(boxClasses) var icon *gtk.Image