2024-05-03 10:46:09 -06:00
|
|
|
//go:build unix && (!darwin)
|
2024-05-06 21:25:25 -06:00
|
|
|
package registrar
|
2024-04-29 14:21:53 -06:00
|
|
|
|
2024-05-28 19:56:52 -06:00
|
|
|
import "log"
|
2024-04-29 14:21:53 -06:00
|
|
|
import "git.tebibyte.media/tomo/tomo"
|
2024-06-11 22:19:12 -06:00
|
|
|
import "git.tebibyte.media/tomo/backend/x"
|
2024-08-22 23:10:54 -06:00
|
|
|
import "git.tebibyte.media/tomo/tomo/event"
|
2024-07-29 13:13:02 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/goparse"
|
2024-06-11 22:19:12 -06:00
|
|
|
import "git.tebibyte.media/tomo/nasin/internal/icons/xdg"
|
2024-08-12 15:12:43 -06:00
|
|
|
import "git.tebibyte.media/tomo/nasin/internal/styles/tss"
|
2024-06-11 22:19:12 -06:00
|
|
|
import "git.tebibyte.media/tomo/nasin/internal/icons/fallback"
|
2024-08-12 15:12:43 -06:00
|
|
|
import "git.tebibyte.media/tomo/nasin/internal/styles/fallback"
|
2024-08-11 08:42:22 -06:00
|
|
|
import "git.tebibyte.media/tomo/nasin/internal/faces/fallback"
|
2024-04-29 14:21:53 -06:00
|
|
|
|
2024-08-11 08:36:29 -06:00
|
|
|
type Registrar struct {
|
|
|
|
backend *x.Backend
|
2024-08-22 23:10:54 -06:00
|
|
|
iconSetCookie event.Cookie
|
|
|
|
styleCookie event.Cookie
|
2024-08-11 08:36:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2024-06-11 22:27:34 -06:00
|
|
|
}
|
|
|
|
|
2024-08-22 23:10:54 -06:00
|
|
|
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)
|
2024-05-28 19:56:52 -06:00
|
|
|
if err == nil {
|
2024-08-11 08:36:29 -06:00
|
|
|
this.backend.SetStyle(styl)
|
2024-08-22 23:10:54 -06:00
|
|
|
this.styleCookie = cookie
|
2024-07-29 13:13:02 -06:00
|
|
|
return nil
|
2024-05-28 19:56:52 -06:00
|
|
|
} else {
|
2024-07-29 13:13:02 -06:00
|
|
|
log.Printf (
|
|
|
|
"nasin: could not load style sheet '%s'\n%v",
|
2024-08-22 23:10:54 -06:00
|
|
|
name, parse.Format(err))
|
2024-05-28 19:56:52 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-22 23:10:54 -06:00
|
|
|
styl, cookie := fallbackStyle.New()
|
|
|
|
this.styleCookie = cookie
|
2024-08-11 08:36:29 -06:00
|
|
|
this.backend.SetStyle(styl)
|
2024-07-28 00:36:28 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-08-22 23:10:54 -06:00
|
|
|
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)
|
2024-07-28 00:36:28 -06:00
|
|
|
if err == nil {
|
|
|
|
iconSet = xdgIconSet
|
|
|
|
} else {
|
2024-08-22 23:10:54 -06:00
|
|
|
log.Printf("nasin: could not load icon theme '%s': %v", name, err)
|
2024-07-28 00:36:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-11 08:36:29 -06:00
|
|
|
this.backend.SetIconSet(iconSet)
|
2024-08-22 23:10:54 -06:00
|
|
|
this.iconSetCookie = cookie
|
2024-07-28 00:36:28 -06:00
|
|
|
return nil
|
2024-04-29 14:21:53 -06:00
|
|
|
}
|
2024-08-11 08:42:22 -06:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|