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") iconThemeName := os.Getenv("TOMO_XDG_ICON_THEME")
if iconThemeName != "" { if iconThemeName != "" {
iconTheme, err := xdgIcons.FindThemeWarn(iconThemeName) iconTheme, err := xdgIcons.FindThemeWarn(iconThemeName, theme.IconTheme)
if err == nil { if err == nil {
theme.IconTheme = iconTheme theme.IconTheme = iconTheme
} else { } else {

View File

@ -15,13 +15,15 @@ import "git.tebibyte.media/tomo/nasin/internal/theme"
type iconTheme struct { type iconTheme struct {
xdg xdgIconTheme.Theme xdg xdgIconTheme.Theme
fallback theme.IconTheme
texturesSmall map[tomo.Icon] canvas.Texture texturesSmall map[tomo.Icon] canvas.Texture
texturesMedium map[tomo.Icon] canvas.Texture texturesMedium map[tomo.Icon] canvas.Texture
texturesLarge 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 { this := &iconTheme {
fallback: fallback,
texturesLarge: make(map[tomo.Icon] canvas.Texture), texturesLarge: make(map[tomo.Icon] canvas.Texture),
texturesMedium: make(map[tomo.Icon] canvas.Texture), texturesMedium: make(map[tomo.Icon] canvas.Texture),
texturesSmall: 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 { func (this *iconTheme) Icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture {
source := this.selectSource(size) source := this.selectSource(size)
if texture, ok := source[icon]; ok { return texture } texture, ok := source[icon]
texture := this.icon(icon, size) if !ok {
source[icon] = texture texture = this.icon(icon, size)
return texture 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 { func (this *iconTheme) MimeIcon (mime data.Mime, size tomo.IconSize) canvas.Texture {
icon := tomo.Icon(mime.String()) icon := tomo.Icon(mime.String())
source := this.selectSource(size) source := this.selectSource(size)
if texture, ok := source[icon]; ok { return texture } texture, ok := source[icon]
texture := this.mimeIcon(mime, size) if !ok {
source[icon] = texture texture = this.mimeIcon(mime, size)
return texture 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 { func (this *iconTheme) icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture {