nasin/internal/registrar/registrar_unix.go

69 lines
1.8 KiB
Go

//go:build unix && (!darwin)
package registrar
import "os"
import "log"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/backend/x"
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
}
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) SetTheme () error {
styleSheetName := os.Getenv("TOMO_STYLE_SHEET")
if styleSheetName != "" {
styl, _, err := tss.LoadFile(styleSheetName)
if err == nil {
this.backend.SetStyle(styl)
return nil
} else {
log.Printf (
"nasin: could not load style sheet '%s'\n%v",
styleSheetName, parse.Format(err))
}
}
styl, _ := fallbackStyle.New()
this.backend.SetStyle(styl)
return nil
}
func (this *Registrar) SetIconSet () error {
iconSet := fallbackIcons.New()
iconSetName := os.Getenv("TOMO_XDG_ICON_THEME")
if iconSetName != "" {
xdgIconSet, err := xdgIcons.FindThemeWarn(iconSetName, iconSet)
if err == nil {
iconSet = xdgIconSet
} else {
log.Printf("nasin: could not load icon theme '%s': %v", iconSetName, err)
}
}
this.backend.SetIconSet(iconSet)
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
}