Further reduce startup time
parent
2f2172c6e5
commit
072595c573
|
@ -70,11 +70,6 @@ func fallbackIcon(entry *gmenu.ListEntry) string {
|
|||
}
|
||||
|
||||
func loadIconImage(img *gtk.Image, entry *gmenu.ListEntry) {
|
||||
img.SetMarginStart(iconMarginStart)
|
||||
img.SetMarginTop(iconMargin)
|
||||
img.SetMarginEnd(iconMargin)
|
||||
img.SetMarginBottom(iconMargin)
|
||||
|
||||
var (
|
||||
pbuf *gdk.Pixbuf
|
||||
err error
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"git.sr.ht/~tslocum/desktop"
|
||||
"git.sr.ht/~tslocum/gmenu/pkg/gmenu"
|
||||
|
@ -19,10 +20,9 @@ import (
|
|||
|
||||
const (
|
||||
iconSize = 48
|
||||
iconMargin = 4
|
||||
iconMarginStart = 4
|
||||
labelMarginStart = 8
|
||||
labelMarginTop = 8
|
||||
rowMargin = 4
|
||||
labelMarginStart = 12
|
||||
labelMarginTop = 4
|
||||
labelMarginTopComment = 4
|
||||
)
|
||||
|
||||
|
@ -81,45 +81,34 @@ func initList(container *gtk.Box) {
|
|||
|
||||
lastEntry := len(gmenu.FilteredEntries) - 1
|
||||
|
||||
var entry *gmenu.ListEntry
|
||||
var (
|
||||
entry *gmenu.ListEntry
|
||||
wg = new(sync.WaitGroup)
|
||||
)
|
||||
for i, label := range gmenu.Names {
|
||||
// Capture variables
|
||||
i := i
|
||||
wg.Add(1)
|
||||
|
||||
row, err := gtk.ListBoxRowNew()
|
||||
if err != nil {
|
||||
log.Fatal("failed to create ListBoxRow:", err)
|
||||
}
|
||||
|
||||
if i == lastEntry {
|
||||
entry = &gmenu.ListEntry{Entry: nil, Label: ""}
|
||||
} else {
|
||||
row.SetName("#" + strconv.Itoa(i))
|
||||
|
||||
entry = &gmenu.ListEntry{Entry: gmenu.Entries[i], Label: label}
|
||||
}
|
||||
|
||||
container := newBox(gtk.ORIENTATION_HORIZONTAL)
|
||||
row.Add(container)
|
||||
|
||||
initRow(container, entry, i, lastEntry)
|
||||
|
||||
listBox.Add(row)
|
||||
glib.IdleAdd(rowInitFunc(i, label, entry, lastEntry, wg))
|
||||
}
|
||||
|
||||
listBox.SetSortFunc(listSort, 0)
|
||||
listBox.SetFilterFunc(listFilter, 0)
|
||||
listBox.SelectRow(listBox.GetRowAtIndex(0))
|
||||
|
||||
_, err = listBox.Connect("row-activated", func(_ *gtk.ListBox, _ *gtk.ListBoxRow) {
|
||||
err := listSelect(inputView, false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal("failed to connect to row-activated event of ListBox:", err)
|
||||
}
|
||||
go func() {
|
||||
wg.Wait()
|
||||
|
||||
glib.IdleAdd(func() {
|
||||
_, err = listBox.Connect("row-activated", func(_ *gtk.ListBox, _ *gtk.ListBoxRow) {
|
||||
err := listSelect(inputView, false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal("failed to connect to row-activated event of ListBox:", err)
|
||||
}
|
||||
})
|
||||
}()
|
||||
}
|
||||
|
||||
func initRow(container *gtk.Box, entry *gmenu.ListEntry, i int, lastEntry int) {
|
||||
|
@ -347,3 +336,36 @@ func listFilter(row *gtk.ListBoxRow, _ uintptr) bool {
|
|||
|
||||
return match
|
||||
}
|
||||
|
||||
func rowInitFunc(i int, label string, entry *gmenu.ListEntry, lastEntry int, wg *sync.WaitGroup) func() {
|
||||
return func() {
|
||||
row, err := gtk.ListBoxRowNew()
|
||||
if err != nil {
|
||||
log.Fatal("failed to create ListBoxRow:", err)
|
||||
}
|
||||
|
||||
if i == lastEntry {
|
||||
entry = &gmenu.ListEntry{Entry: nil, Label: ""}
|
||||
} else {
|
||||
row.SetName("#" + strconv.Itoa(i))
|
||||
|
||||
entry = &gmenu.ListEntry{Entry: gmenu.Entries[i], Label: label}
|
||||
}
|
||||
|
||||
container := newBox(gtk.ORIENTATION_HORIZONTAL)
|
||||
container.SetMarginStart(rowMargin)
|
||||
container.SetMarginTop(rowMargin)
|
||||
container.SetMarginBottom(rowMargin)
|
||||
container.SetMarginEnd(rowMargin)
|
||||
|
||||
initRow(container, entry, i, lastEntry)
|
||||
|
||||
row.Add(container)
|
||||
listBox.Add(row)
|
||||
row.ShowAll()
|
||||
|
||||
listBox.SelectRow(listBox.GetRowAtIndex(0))
|
||||
|
||||
wg.Done()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue