diff --git a/internal/registrar/registrar_unix.go b/internal/registrar/registrar_unix.go index a28fa8c..53172cf 100644 --- a/internal/registrar/registrar_unix.go +++ b/internal/registrar/registrar_unix.go @@ -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 { diff --git a/internal/theme/xdgicons/icon.go b/internal/theme/xdgicons/icon.go index f5966ee..f0ce89d 100644 --- a/internal/theme/xdgicons/icon.go +++ b/internal/theme/xdgicons/icon.go @@ -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 {