nasin/internal/registrar/registrar_unix.go

83 lines
2.1 KiB
Go

//go:build unix && (!darwin)
package registrar
import "log"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/backend/x"
import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/sashakoshka/goparse"
import "git.tebibyte.media/tomo/nasin/internal/icons/xdg"
import "git.tebibyte.media/tomo/nasin/internal/styles/tss"
import "git.tebibyte.media/tomo/nasin/internal/icons/fallback"
import "git.tebibyte.media/tomo/nasin/internal/styles/fallback"
import "git.tebibyte.media/tomo/nasin/internal/faces/fallback"
type Registrar struct {
backend *x.Backend
iconSetCookie event.Cookie
styleCookie event.Cookie
}
func (this *Registrar) SetBackend () (tomo.Backend, error) {
backend, err := x.New()
if err != nil { return nil, err }
this.backend = backend.(*x.Backend)
tomo.SetBackend(backend)
return backend, nil
}
func (this *Registrar) SetStyle (name string) error {
if this.styleCookie != nil {
this.styleCookie.Close()
this.styleCookie = nil
}
if name != "" {
styl, cookie, err := tss.LoadFile(name)
if err == nil {
this.backend.SetStyle(styl)
this.styleCookie = cookie
return nil
} else {
log.Printf (
"nasin: could not load style sheet '%s'\n%v",
name, parse.Format(err))
}
}
styl, cookie := fallbackStyle.New()
this.styleCookie = cookie
this.backend.SetStyle(styl)
return nil
}
func (this *Registrar) SetIconSet (name string) error {
if this.iconSetCookie != nil {
this.iconSetCookie.Close()
this.iconSetCookie = nil
}
iconSet, cookie := fallbackIcons.New()
if name != "" {
xdgIconSet, xdgCookie, err := xdgIcons.FindThemeWarn(name, iconSet)
cookie = event.MultiCookie(cookie, xdgCookie)
if err == nil {
iconSet = xdgIconSet
} else {
log.Printf("nasin: could not load icon theme '%s': %v", name, err)
}
}
this.backend.SetIconSet(iconSet)
this.iconSetCookie = cookie
return nil
}
func (this *Registrar) SetFaceSet () error {
// TODO replace this with something that uses findfont, and caches and
// refcounts the faces
faceSet := fallbackFaces.New()
this.backend.SetFaceSet(faceSet)
return nil
}