XDG icon theme loader now uses Wintergreen icons as fallback

This commit is contained in:
Sasha Koshka 2024-05-28 22:13:42 -04:00
parent fc41696b5e
commit cf3b7ca651
2 changed files with 26 additions and 10 deletions

View File

@ -13,7 +13,7 @@ func Init () error {
iconThemeName := os.Getenv("TOMO_XDG_ICON_THEME")
if iconThemeName != "" {
iconTheme, err := xdgIcons.FindThemeWarn(iconThemeName)
iconTheme, err := xdgIcons.FindThemeWarn(iconThemeName, theme.IconTheme)
if err == nil {
theme.IconTheme = iconTheme
} else {

View File

@ -15,13 +15,15 @@ import "git.tebibyte.media/tomo/nasin/internal/theme"
type iconTheme struct {
xdg xdgIconTheme.Theme
fallback theme.IconTheme
texturesSmall map[tomo.Icon] canvas.Texture
texturesMedium map[tomo.Icon] canvas.Texture
texturesLarge map[tomo.Icon] canvas.Texture
}
func FindThemeWarn (name string, path ...string) (theme.IconTheme, error) {
func FindThemeWarn (name string, fallback theme.IconTheme, path ...string) (theme.IconTheme, error) {
this := &iconTheme {
fallback: fallback,
texturesLarge: make(map[tomo.Icon] canvas.Texture),
texturesMedium: make(map[tomo.Icon] canvas.Texture),
texturesSmall: make(map[tomo.Icon] canvas.Texture),
@ -68,19 +70,33 @@ func (this *iconTheme) xdgIcon (name string, size tomo.IconSize) (canvas.Texture
func (this *iconTheme) Icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture {
source := this.selectSource(size)
if texture, ok := source[icon]; ok { return texture }
texture := this.icon(icon, size)
source[icon] = texture
return texture
texture, ok := source[icon]
if !ok {
texture = this.icon(icon, size)
source[icon] = texture
}
if texture == nil {
return this.fallback.Icon(icon, size)
} else {
return texture
}
}
func (this *iconTheme) MimeIcon (mime data.Mime, size tomo.IconSize) canvas.Texture {
icon := tomo.Icon(mime.String())
source := this.selectSource(size)
if texture, ok := source[icon]; ok { return texture }
texture := this.mimeIcon(mime, size)
source[icon] = texture
return texture
texture, ok := source[icon]
if !ok {
texture = this.mimeIcon(mime, size)
source[icon] = texture
}
if texture == nil {
return this.fallback.MimeIcon(mime, size)
} else {
return texture
}
}
func (this *iconTheme) icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture {