diff --git a/internal/icons/fallback/icon.go b/internal/icons/fallback/icon.go index 67bee00..860c0b2 100644 --- a/internal/icons/fallback/icon.go +++ b/internal/icons/fallback/icon.go @@ -6,6 +6,7 @@ import _ "embed" import _ "image/png" import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo/data" +import "git.tebibyte.media/tomo/nasin/internal/util" import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/backend/style" @@ -14,6 +15,26 @@ var atlasSmallBytes []byte //go:embed assets/icons-large.png var atlasLargeBytes []byte +const ( + iconApplicationXGeneric = tomo.Icon("application/x-generic") + iconApplicationXExecutable = tomo.Icon("application/x-executable") + iconAudioXGeneric = tomo.Icon("audio/x-generic") + iconFontXGeneric = tomo.Icon("font/x-generic") + iconImageXGeneric = tomo.Icon("image/x-generic") + iconModelXGeneric = tomo.Icon("model/x-generic") + iconPackageXGeneric = tomo.Icon("package/x-generic") + iconTextXGeneric = tomo.Icon("text/x-generic") + iconTextHtml = tomo.Icon("text/html") + iconTextXGenericTemplate = tomo.Icon("text/x-generic-template") + iconTextXScript = tomo.Icon("text/x-script") + iconVideoXGeneric = tomo.Icon("video/x-generic") + iconXOfficeAddressBook = tomo.Icon("x-office-address-book") + iconXOfficeCalendar = tomo.Icon("x-office-calendar") + iconXOfficeDocument = tomo.Icon("x-office-document") + iconXOfficePresentation = tomo.Icon("x-office-presentation") + iconXOfficeSpreadsheet = tomo.Icon("x-office-spreadsheet") +) + func generateSource (data []byte, width int) map[tomo.Icon] canvas.Texture { atlasImage, _, err := image.Decode(bytes.NewReader(data)) if err != nil { panic(err) } @@ -37,7 +58,23 @@ func generateSource (data []byte, width int) map[tomo.Icon] canvas.Texture { } col(tomo.IconUnknown) - col(tomo.Icon("File")) + col(iconApplicationXGeneric) + col(iconApplicationXExecutable) + col(iconAudioXGeneric) + col(iconFontXGeneric) + col(iconImageXGeneric) + col(iconModelXGeneric) + col(iconPackageXGeneric) + col(iconTextXGeneric) + col(iconTextHtml) + col(iconTextXGenericTemplate) + col(iconTextXScript) + col(iconVideoXGeneric) + col(iconXOfficeAddressBook) + col(iconXOfficeCalendar) + col(iconXOfficeDocument) + col(iconXOfficePresentation) + col(iconXOfficeSpreadsheet) row() // actions @@ -450,9 +487,16 @@ func (this *iconSet) Icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture { func (this *iconSet) MimeIcon (mime data.Mime, size tomo.IconSize) canvas.Texture { this.ensure() source := this.selectSource(size) + + if icon, ok := source[tomo.Icon(mime.String())]; ok { + return icon + } + if mime == data.M("inode", "directory") { return source[tomo.IconPlaceDirectory] + } else if icon, ok := source[tomo.Icon(util.GeneralizeXDGIconMimeType(mime).String())]; ok { + return icon } else { - return source[tomo.Icon("File")] + return source[tomo.Icon(iconApplicationXGeneric)] } } diff --git a/internal/icons/xdg/icon.go b/internal/icons/xdg/icon.go index d8ad2a4..828c22e 100644 --- a/internal/icons/xdg/icon.go +++ b/internal/icons/xdg/icon.go @@ -11,6 +11,7 @@ import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo/data" import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/backend/style" +import "git.tebibyte.media/tomo/nasin/internal/util" import xdgIconTheme "git.tebibyte.media/tomo/xdg/icon-theme" type iconTheme struct { @@ -113,7 +114,7 @@ func (this *iconTheme) mimeIcon (mime data.Mime, size tomo.IconSize) canvas.Text if texture, ok := this.xdgIcon(xdgFormatMime(mime), size); ok { return texture } - if texture, ok := this.xdgIcon(xdgFormatMime(generalizeMimeType(mime)), size); ok { + if texture, ok := this.xdgIcon(xdgFormatMime(util.GeneralizeXDGIconMimeType(mime)), size); ok { return texture } if texture, ok := this.xdgIcon(xdgFormatMime(data.M("text", "x-generic")), size); ok { @@ -166,13 +167,6 @@ func xdgFormatMime (mime data.Mime) string { return fmt.Sprintf("%s-%s", mime.Type, mime.Subtype) } -func generalizeMimeType (mime data.Mime) data.Mime { - // FIXME make this more accurate - // https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html - mime.Subtype = "x-generic" - return mime -} - func iconSizePixels (size tomo.IconSize) int { // TODO: once Tomo has scaling support, take that into account here switch size { diff --git a/internal/util/util.go b/internal/util/util.go new file mode 100644 index 0000000..2900f71 --- /dev/null +++ b/internal/util/util.go @@ -0,0 +1,10 @@ +package util + +import "git.tebibyte.media/tomo/tomo/data" + +func GeneralizeXDGIconMimeType (mime data.Mime) data.Mime { + // FIXME make this more accurate + // https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html + mime.Subtype = "x-generic" + return mime +}