Skip to content

Commit

Permalink
minor: added 'active' flag to indicate the active item for dmenu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
abenz1267 committed Aug 24, 2024
1 parent 291ed37 commit e334242
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<entryclass>` | Always |
| class | condition |
| -------------------- | -------------------------- |
| `#window.activation` | AM enabled |
| `#spinner.visible` | Processing in progress |
| `#item.<entryclass>` | Always |
| `#item.active` | Dmenu with '--active'-flag |

### Starting as service

Expand Down
14 changes: 14 additions & 0 deletions cmd/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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 {
Expand All @@ -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(), ",")
Expand Down
1 change: 1 addition & 0 deletions internal/state/appstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

type AppState struct {
ActiveItem int
Clipboard modules.Workable
IsDmenu bool
Dmenu *modules.Dmenu
Expand Down
14 changes: 13 additions & 1 deletion internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e334242

Please sign in to comment.