Restructure internal/theme
This commit is contained in:
BIN
internal/theme/icons/fallback/assets/icons-large.png
Normal file
BIN
internal/theme/icons/fallback/assets/icons-large.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.3 KiB |
BIN
internal/theme/icons/fallback/assets/icons-large.xcf
Normal file
BIN
internal/theme/icons/fallback/assets/icons-large.xcf
Normal file
Binary file not shown.
BIN
internal/theme/icons/fallback/assets/icons-small.png
Normal file
BIN
internal/theme/icons/fallback/assets/icons-small.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.9 KiB |
BIN
internal/theme/icons/fallback/assets/icons-small.xcf
Normal file
BIN
internal/theme/icons/fallback/assets/icons-small.xcf
Normal file
Binary file not shown.
BIN
internal/theme/icons/fallback/assets/old/icons-large.png
Normal file
BIN
internal/theme/icons/fallback/assets/old/icons-large.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
BIN
internal/theme/icons/fallback/assets/old/icons-large.xcf
Normal file
BIN
internal/theme/icons/fallback/assets/old/icons-large.xcf
Normal file
Binary file not shown.
BIN
internal/theme/icons/fallback/assets/old/icons-small.png
Normal file
BIN
internal/theme/icons/fallback/assets/old/icons-small.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
BIN
internal/theme/icons/fallback/assets/old/icons-small.xcf
Normal file
BIN
internal/theme/icons/fallback/assets/old/icons-small.xcf
Normal file
Binary file not shown.
456
internal/theme/icons/fallback/icon.go
Normal file
456
internal/theme/icons/fallback/icon.go
Normal file
@@ -0,0 +1,456 @@
|
||||
package fallbackIcons
|
||||
|
||||
import "bytes"
|
||||
import "image"
|
||||
import _ "embed"
|
||||
import _ "image/png"
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import "git.tebibyte.media/tomo/tomo/data"
|
||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||
import dataTheme "git.tebibyte.media/tomo/nasin/internal/theme"
|
||||
|
||||
//go:embed assets/icons-small.png
|
||||
var atlasSmallBytes []byte
|
||||
//go:embed assets/icons-large.png
|
||||
var atlasLargeBytes []byte
|
||||
|
||||
func generateSource (data []byte, width int) map[tomo.Icon] canvas.Texture {
|
||||
atlasImage, _, err := image.Decode(bytes.NewReader(data))
|
||||
if err != nil { panic(err) }
|
||||
atlasTexture := tomo.NewTexture(atlasImage)
|
||||
|
||||
source := make(map[tomo.Icon] canvas.Texture)
|
||||
x := 0
|
||||
y := 0
|
||||
|
||||
row := func () {
|
||||
x = 0
|
||||
y ++
|
||||
}
|
||||
col := func (id tomo.Icon) {
|
||||
source[id] = atlasTexture.SubTexture(image.Rect (
|
||||
x * width,
|
||||
y * width,
|
||||
(x + 1) * width,
|
||||
(y + 1) * width))
|
||||
x++
|
||||
}
|
||||
|
||||
col(tomo.IconUnknown)
|
||||
col(tomo.Icon("File"))
|
||||
|
||||
row()
|
||||
// actions
|
||||
col(tomo.IconAddressBookNew)
|
||||
col(tomo.IconApplicationExit)
|
||||
col(tomo.IconAppointmentNew)
|
||||
col(tomo.IconCallStart)
|
||||
col(tomo.IconCallStop)
|
||||
col(tomo.IconContactNew)
|
||||
// actions: dialog
|
||||
col(tomo.IconDialogOkay)
|
||||
col(tomo.IconDialogCancel)
|
||||
// actions: edit
|
||||
col(tomo.IconEditClear)
|
||||
col(tomo.IconEditCopy)
|
||||
col(tomo.IconEditCut)
|
||||
col(tomo.IconEditDelete)
|
||||
col(tomo.IconEditFind)
|
||||
col(tomo.IconEditFindReplace)
|
||||
col(tomo.IconEditPaste)
|
||||
col(tomo.IconEditRedo)
|
||||
col(tomo.IconEditSelectAll)
|
||||
col(tomo.IconEditUndo)
|
||||
// actions: file
|
||||
col(tomo.IconFileNew)
|
||||
col(tomo.IconDirectoryNew)
|
||||
col(tomo.IconFileOpen)
|
||||
col(tomo.IconFileOpenRecent)
|
||||
col(tomo.IconFilePageSetup)
|
||||
col(tomo.IconFilePrint)
|
||||
col(tomo.IconFilePrintPreview)
|
||||
col(tomo.IconFilePermissions)
|
||||
col(tomo.IconFileProperties)
|
||||
col(tomo.IconFileRename)
|
||||
col(tomo.IconFileRevert)
|
||||
col(tomo.IconFileSave)
|
||||
col(tomo.IconFileSaveAs)
|
||||
col(tomo.IconFileSend)
|
||||
|
||||
row()
|
||||
// actions: format
|
||||
col(tomo.IconFormatIndentLess)
|
||||
col(tomo.IconFormatIndentMore)
|
||||
col(tomo.IconFormatAlignCenter)
|
||||
col(tomo.IconFormatAlignEven)
|
||||
col(tomo.IconFormatAlignLeft)
|
||||
col(tomo.IconFormatAlignRight)
|
||||
col(tomo.IconFormatTextDirectionLtr)
|
||||
col(tomo.IconFormatTextDirectionRtl)
|
||||
col(tomo.IconFormatTextBold)
|
||||
col(tomo.IconFormatTextItalic)
|
||||
col(tomo.IconFormatTextUnderline)
|
||||
col(tomo.IconFormatTextStrikethrough)
|
||||
// actions: go
|
||||
col(tomo.IconGoBottom)
|
||||
col(tomo.IconGoDown)
|
||||
col(tomo.IconGoFirst)
|
||||
col(tomo.IconGoHome)
|
||||
col(tomo.IconGoJump)
|
||||
col(tomo.IconGoLast)
|
||||
col(tomo.IconGoNext)
|
||||
col(tomo.IconGoPrevious)
|
||||
col(tomo.IconGoTop)
|
||||
col(tomo.IconGoUp)
|
||||
// actions: help
|
||||
col(tomo.IconHelpAbout)
|
||||
col(tomo.IconHelpContents)
|
||||
col(tomo.IconHelpFaq)
|
||||
// actions: insert
|
||||
col(tomo.IconInsertImage)
|
||||
col(tomo.IconInsertLink)
|
||||
col(tomo.IconInsertObject)
|
||||
col(tomo.IconInsertText)
|
||||
// actions: list
|
||||
col(tomo.IconListAdd)
|
||||
col(tomo.IconListRemove)
|
||||
|
||||
row()
|
||||
// actions: mail
|
||||
col(tomo.IconMailForward)
|
||||
col(tomo.IconMailMarkImportant)
|
||||
col(tomo.IconMailMarkJunk)
|
||||
col(tomo.IconMailMarkNotJunk)
|
||||
col(tomo.IconMailMarkRead)
|
||||
col(tomo.IconMailMarkUnread)
|
||||
col(tomo.IconMailMessageNew)
|
||||
col(tomo.IconMailReplyAll)
|
||||
col(tomo.IconMailReplySender)
|
||||
col(tomo.IconMailSend)
|
||||
col(tomo.IconMailReceive)
|
||||
// actions: media
|
||||
col(tomo.IconMediaEject)
|
||||
col(tomo.IconMediaPlaybackPause)
|
||||
col(tomo.IconMediaPlaybackStart)
|
||||
col(tomo.IconMediaPlaybackStop)
|
||||
col(tomo.IconMediaRecord)
|
||||
col(tomo.IconMediaSeekBackward)
|
||||
col(tomo.IconMediaSeekForward)
|
||||
col(tomo.IconMediaSkipBackward)
|
||||
col(tomo.IconMediaSkipForward)
|
||||
// actions: object
|
||||
col(tomo.IconObjectFlipHorizontal)
|
||||
col(tomo.IconObjectFlipVertical)
|
||||
col(tomo.IconObjectRotateLeft)
|
||||
col(tomo.IconObjectRotateRight)
|
||||
// actions: process
|
||||
col(tomo.IconProcessStop)
|
||||
// actions: system
|
||||
col(tomo.IconSystemLockScreen)
|
||||
col(tomo.IconSystemLogOut)
|
||||
col(tomo.IconSystemRun)
|
||||
col(tomo.IconSystemSearch)
|
||||
col(tomo.IconSystemReboot)
|
||||
col(tomo.IconSystemShutdown)
|
||||
|
||||
row()
|
||||
// actions: tools
|
||||
col(tomo.IconToolsCheckSpelling)
|
||||
// actions: value
|
||||
col(tomo.IconValueIncrement)
|
||||
col(tomo.IconValueDecrement)
|
||||
col(tomo.IconValueReset)
|
||||
// actions: view
|
||||
col(tomo.IconViewFullscreen)
|
||||
col(tomo.IconViewRefresh)
|
||||
col(tomo.IconViewRestore)
|
||||
col(tomo.IconViewSortAscending)
|
||||
col(tomo.IconViewSortDescending)
|
||||
// actions: window
|
||||
col(tomo.IconWindowClose)
|
||||
col(tomo.IconWindowNew)
|
||||
// actions: zoom
|
||||
col(tomo.IconZoomFitBest)
|
||||
col(tomo.IconZoomIn)
|
||||
col(tomo.IconZoomOriginal)
|
||||
col(tomo.IconZoomOut)
|
||||
|
||||
row()
|
||||
// applications
|
||||
// Keep these in sync with nasin.ApplicationRole!
|
||||
col(tomo.IconApplication)
|
||||
col(tomo.IconApplicationWebBrowser)
|
||||
col(tomo.IconApplicationMesssanger)
|
||||
col(tomo.IconApplicationPhone)
|
||||
col(tomo.IconApplicationMail)
|
||||
col(tomo.IconApplicationTerminalEmulator)
|
||||
col(tomo.IconApplicationFileBrowser)
|
||||
col(tomo.IconApplicationTextEditor)
|
||||
col(tomo.IconApplicationDocumentViewer)
|
||||
col(tomo.IconApplicationWordProcessor)
|
||||
col(tomo.IconApplicationSpreadsheet)
|
||||
col(tomo.IconApplicationSlideshow)
|
||||
col(tomo.IconApplicationCalculator)
|
||||
col(tomo.IconApplicationPreferences)
|
||||
col(tomo.IconApplicationProcessManager)
|
||||
col(tomo.IconApplicationSystemInformation)
|
||||
col(tomo.IconApplicationManual)
|
||||
col(tomo.IconApplicationCamera)
|
||||
col(tomo.IconApplicationImageViewer)
|
||||
col(tomo.IconApplicationMediaPlayer)
|
||||
col(tomo.IconApplicationImageEditor)
|
||||
col(tomo.IconApplicationAudioEditor)
|
||||
col(tomo.IconApplicationVideoEditor)
|
||||
col(tomo.IconApplicationClock)
|
||||
col(tomo.IconApplicationCalendar)
|
||||
col(tomo.IconApplicationChecklist)
|
||||
|
||||
row()
|
||||
// categories: applications
|
||||
col(tomo.IconApplications)
|
||||
col(tomo.IconApplicationsAccessories)
|
||||
col(tomo.IconApplicationsDevelopment)
|
||||
col(tomo.IconApplicationsEngineering)
|
||||
col(tomo.IconApplicationsGames)
|
||||
col(tomo.IconApplicationsGraphics)
|
||||
col(tomo.IconApplicationsInternet)
|
||||
col(tomo.IconApplicationsMultimedia)
|
||||
col(tomo.IconApplicationsOffice)
|
||||
col(tomo.IconApplicationsScience)
|
||||
col(tomo.IconApplicationsSystem)
|
||||
col(tomo.IconApplicationsUtilities)
|
||||
// categories: preferences
|
||||
col(tomo.IconPreferences)
|
||||
col(tomo.IconPreferencesDesktop)
|
||||
col(tomo.IconPreferencesPeripherals)
|
||||
col(tomo.IconPreferencesPersonal)
|
||||
col(tomo.IconPreferencesSystem)
|
||||
col(tomo.IconPreferencesNetwork)
|
||||
|
||||
row()
|
||||
// devices
|
||||
col(tomo.IconDevice)
|
||||
col(tomo.IconDeviceCamera)
|
||||
col(tomo.IconDeviceWebCamera)
|
||||
col(tomo.IconDeviceComputer)
|
||||
col(tomo.IconDevicePda)
|
||||
col(tomo.IconDevicePhone)
|
||||
col(tomo.IconDevicePrinter)
|
||||
col(tomo.IconDeviceScanner)
|
||||
col(tomo.IconDeviceMultimediaPlayer)
|
||||
col(tomo.IconDeviceVideoDisplay)
|
||||
col(tomo.IconDeviceAudioInput)
|
||||
col(tomo.IconDeviceAudioOutput)
|
||||
// devices: hardware
|
||||
col(tomo.IconHardware)
|
||||
col(tomo.IconHardwareCPU)
|
||||
col(tomo.IconHardwareGPU)
|
||||
col(tomo.IconHardwareRAM)
|
||||
col(tomo.IconHardwareSoundCard)
|
||||
col(tomo.IconHardwareNetworkAdapter)
|
||||
// devices: power
|
||||
col(tomo.IconPowerBattery)
|
||||
// devices: storage
|
||||
col(tomo.IconStorageHardDisk)
|
||||
col(tomo.IconStorageFloppyDisk)
|
||||
col(tomo.IconStorageSolidState)
|
||||
col(tomo.IconStorageOptical)
|
||||
col(tomo.IconStorageFlashStick)
|
||||
col(tomo.IconStorageFlashCard)
|
||||
col(tomo.IconStorageMagneticTape)
|
||||
// devices: input
|
||||
col(tomo.IconInputGaming)
|
||||
col(tomo.IconInputKeyboard)
|
||||
col(tomo.IconInputMouse)
|
||||
col(tomo.IconInputTablet)
|
||||
|
||||
row()
|
||||
// devices: network
|
||||
col(tomo.IconNetworkWired)
|
||||
col(tomo.IconNetworkWireless)
|
||||
col(tomo.IconNetworkCellular)
|
||||
col(tomo.IconNetworkLocal)
|
||||
col(tomo.IconNetworkInternet)
|
||||
col(tomo.IconNetworkVPN)
|
||||
col(tomo.IconNetworkServer)
|
||||
col(tomo.IconNetworkWorkgroup)
|
||||
|
||||
row()
|
||||
// emblems
|
||||
col(tomo.IconEmblemDefault)
|
||||
col(tomo.IconEmblemEncrypted)
|
||||
col(tomo.IconEmblemFavorite)
|
||||
col(tomo.IconEmblemImportant)
|
||||
col(tomo.IconEmblemReadOnly)
|
||||
col(tomo.IconEmblemShared)
|
||||
col(tomo.IconEmblemSymbolicLink)
|
||||
col(tomo.IconEmblemSynchronized)
|
||||
col(tomo.IconEmblemSystem)
|
||||
col(tomo.IconEmblemUnreadable)
|
||||
|
||||
row()
|
||||
// places
|
||||
col(tomo.IconPlaceDirectory)
|
||||
col(tomo.IconPlaceRemote)
|
||||
col(tomo.IconPlaceHome)
|
||||
col(tomo.IconPlaceDownloads)
|
||||
col(tomo.IconPlaceDesktop)
|
||||
col(tomo.IconPlacePhotos)
|
||||
col(tomo.IconPlaceBooks)
|
||||
col(tomo.IconPlaceBookmarks)
|
||||
col(tomo.IconPlaceTrash)
|
||||
col(tomo.IconPlaceDocuments)
|
||||
col(tomo.IconPlaceRepositories)
|
||||
col(tomo.IconPlaceMusic)
|
||||
col(tomo.IconPlaceArchives)
|
||||
col(tomo.IconPlaceFonts)
|
||||
col(tomo.IconPlaceBinaries)
|
||||
col(tomo.IconPlaceVideos)
|
||||
col(tomo.IconPlace3DObjects)
|
||||
col(tomo.IconPlaceHistory)
|
||||
col(tomo.IconPlacePreferences)
|
||||
|
||||
row()
|
||||
// status: checkbox
|
||||
col(tomo.IconCheckboxChecked)
|
||||
col(tomo.IconCheckboxUnchecked)
|
||||
// status: appointments
|
||||
col(tomo.IconAppointmentMissed)
|
||||
col(tomo.IconAppointmentSoon)
|
||||
// status: dialogs
|
||||
col(tomo.IconDialogError)
|
||||
col(tomo.IconDialogInformation)
|
||||
col(tomo.IconDialogPassword)
|
||||
col(tomo.IconDialogQuestion)
|
||||
col(tomo.IconDialogWarning)
|
||||
// status: directories
|
||||
col(tomo.IconDirectoryDragAccept)
|
||||
col(tomo.IconDirectoryFull)
|
||||
col(tomo.IconDirectoryOpen)
|
||||
col(tomo.IconDirectoryVisiting)
|
||||
// status: trash
|
||||
col(tomo.IconTrashFull)
|
||||
// status: resource
|
||||
col(tomo.IconResourceLoading)
|
||||
col(tomo.IconResourceMissing)
|
||||
// status: mail
|
||||
col(tomo.IconMailAttachment)
|
||||
col(tomo.IconMailUnread)
|
||||
col(tomo.IconMailReplied)
|
||||
col(tomo.IconMailSigned)
|
||||
col(tomo.IconMailSignedVerified)
|
||||
|
||||
row()
|
||||
// status: network
|
||||
col(tomo.IconCellularSignal0)
|
||||
col(tomo.IconCellularSignal1)
|
||||
col(tomo.IconCellularSignal2)
|
||||
col(tomo.IconCellularSignal3)
|
||||
col(tomo.IconWirelessSignal0)
|
||||
col(tomo.IconWirelessSignal1)
|
||||
col(tomo.IconWirelessSignal2)
|
||||
col(tomo.IconWirelessSignal3)
|
||||
col(tomo.IconNetworkError)
|
||||
col(tomo.IconNetworkIdle)
|
||||
col(tomo.IconNetworkOffline)
|
||||
col(tomo.IconNetworkReceive)
|
||||
col(tomo.IconNetworkTransmit)
|
||||
col(tomo.IconNetworkTransmitReceive)
|
||||
// status: print
|
||||
col(tomo.IconPrintError)
|
||||
col(tomo.IconPrintPrinting)
|
||||
// status: security
|
||||
col(tomo.IconSecurityHigh)
|
||||
col(tomo.IconSecurityMedium)
|
||||
col(tomo.IconSecurityLow)
|
||||
// status: software
|
||||
col(tomo.IconSoftwareUpdateAvailable)
|
||||
col(tomo.IconSoftwareUpdateUrgent)
|
||||
col(tomo.IconSoftwareInstalling)
|
||||
// status: sync
|
||||
col(tomo.IconSyncError)
|
||||
col(tomo.IconSyncSynchronizing)
|
||||
// status: tasks
|
||||
col(tomo.IconTaskDue)
|
||||
col(tomo.IconTaskPastDue)
|
||||
// status: users
|
||||
col(tomo.IconUserAvailable)
|
||||
col(tomo.IconUserAway)
|
||||
col(tomo.IconUserIdle)
|
||||
col(tomo.IconUserOffline)
|
||||
|
||||
row()
|
||||
// status: power
|
||||
col(tomo.IconBattery0)
|
||||
col(tomo.IconBattery1)
|
||||
col(tomo.IconBattery2)
|
||||
col(tomo.IconBattery3)
|
||||
col(tomo.IconBrightness0)
|
||||
col(tomo.IconBrightness1)
|
||||
col(tomo.IconBrightness2)
|
||||
col(tomo.IconBrightness3)
|
||||
// status: media
|
||||
col(tomo.IconVolume0)
|
||||
col(tomo.IconVolume1)
|
||||
col(tomo.IconVolume2)
|
||||
col(tomo.IconVolume3)
|
||||
col(tomo.IconPlaylistRepeat)
|
||||
col(tomo.IconPlaylistShuffle)
|
||||
// status: weather
|
||||
col(tomo.IconWeatherClear)
|
||||
col(tomo.IconWeatherClearNight)
|
||||
col(tomo.IconWeatherFewClouds)
|
||||
col(tomo.IconWeatherFewCloudsNight)
|
||||
col(tomo.IconWeatherFog)
|
||||
col(tomo.IconWeatherOvercast)
|
||||
col(tomo.IconWeatherSevereAlert)
|
||||
col(tomo.IconWeatherShowers)
|
||||
col(tomo.IconWeatherShowersScattered)
|
||||
col(tomo.IconWeatherSnow)
|
||||
col(tomo.IconWeatherStorm)
|
||||
|
||||
return source
|
||||
}
|
||||
|
||||
type iconTheme struct {
|
||||
texturesSmall map[tomo.Icon] canvas.Texture
|
||||
texturesLarge map[tomo.Icon] canvas.Texture
|
||||
}
|
||||
|
||||
// New creates a new fallback icon theme.
|
||||
func New () dataTheme.IconTheme {
|
||||
return new(iconTheme)
|
||||
}
|
||||
|
||||
func (this *iconTheme) ensure () {
|
||||
if this.texturesSmall != nil { return }
|
||||
this.texturesSmall = generateSource(atlasSmallBytes, 16)
|
||||
this.texturesLarge = generateSource(atlasLargeBytes, 32)
|
||||
}
|
||||
|
||||
func (this *iconTheme) selectSource (size tomo.IconSize) map[tomo.Icon] canvas.Texture {
|
||||
if size == tomo.IconSizeSmall {
|
||||
return this.texturesSmall
|
||||
} else {
|
||||
return this.texturesLarge
|
||||
}
|
||||
}
|
||||
|
||||
func (this *iconTheme) Icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture {
|
||||
this.ensure()
|
||||
source := this.selectSource(size)
|
||||
if texture, ok := source[icon]; ok {
|
||||
return texture
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *iconTheme) MimeIcon (mime data.Mime, size tomo.IconSize) canvas.Texture {
|
||||
this.ensure()
|
||||
source := this.selectSource(size)
|
||||
if mime == data.M("inode", "directory") {
|
||||
return source[tomo.IconPlaceDirectory]
|
||||
} else {
|
||||
return source[tomo.Icon("File")]
|
||||
}
|
||||
}
|
||||
183
internal/theme/icons/xdg/icon.go
Normal file
183
internal/theme/icons/xdg/icon.go
Normal file
@@ -0,0 +1,183 @@
|
||||
package xdgIcons
|
||||
|
||||
import "os"
|
||||
import "fmt"
|
||||
import "log"
|
||||
import "image"
|
||||
import "regexp"
|
||||
import "strings"
|
||||
import _ "image/png"
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import xdgIconTheme "git.tebibyte.media/tomo/xdg/icon-theme"
|
||||
import "git.tebibyte.media/tomo/tomo/data"
|
||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||
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, 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),
|
||||
}
|
||||
|
||||
xdg, err := xdgIconTheme.FindThemeWarn(name, path...)
|
||||
if err != nil { return nil, err }
|
||||
this.xdg = xdg
|
||||
|
||||
return this, nil
|
||||
}
|
||||
|
||||
func (this *iconTheme) selectSource (size tomo.IconSize) map[tomo.Icon] canvas.Texture {
|
||||
switch size {
|
||||
case tomo.IconSizeMedium: return this.texturesMedium
|
||||
case tomo.IconSizeLarge: return this.texturesLarge
|
||||
default: return this.texturesSmall
|
||||
}
|
||||
}
|
||||
|
||||
func (this *iconTheme) xdgIcon (name string, size tomo.IconSize) (canvas.Texture, bool) {
|
||||
// TODO use scaling factor instead of 1
|
||||
// find icon file
|
||||
icon, err := this.xdg.FindIcon(name, iconSizePixels(size), 1, xdgIconTheme.PNG)
|
||||
if err != nil { return nil, false }
|
||||
|
||||
// open icon file
|
||||
iconFile, err := os.Open(icon.Path)
|
||||
if err != nil {
|
||||
// this failing indicates a broken icon theme
|
||||
log.Printf("nasin: icon file '%s' is inaccessible: %v\n", icon.Path, err)
|
||||
return nil, false
|
||||
}
|
||||
|
||||
iconImage, _, err := image.Decode(iconFile)
|
||||
if err != nil {
|
||||
// this failing indicates a broken icon theme
|
||||
log.Printf("nasin: icon file '%s' is broken: %v\n", icon.Path, err)
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return tomo.NewTexture(iconImage), true
|
||||
}
|
||||
|
||||
func (this *iconTheme) Icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture {
|
||||
source := this.selectSource(size)
|
||||
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)
|
||||
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 {
|
||||
if texture, ok := this.xdgIcon(XdgIconName(icon), size); ok {
|
||||
return texture
|
||||
}
|
||||
if texture, ok := this.xdgIcon(XdgIconName(generalizeIcon(icon)), size); ok {
|
||||
return texture
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *iconTheme) mimeIcon (mime data.Mime, size tomo.IconSize) canvas.Texture {
|
||||
if texture, ok := this.xdgIcon(xdgFormatMime(mime), size); ok {
|
||||
return texture
|
||||
}
|
||||
if texture, ok := this.xdgIcon(xdgFormatMime(generalizeMimeType(mime)), size); ok {
|
||||
return texture
|
||||
}
|
||||
if texture, ok := this.xdgIcon(xdgFormatMime(data.M("text", "x-generic")), size); ok {
|
||||
return texture
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var kebabMatchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
|
||||
var kebabMatchAllCaps = regexp.MustCompile("([a-z0-9])([A-Z])")
|
||||
|
||||
// XdgIconName returns the best XDG name for the given icon.
|
||||
func XdgIconName (icon tomo.Icon) string {
|
||||
if name, ok := xdgIconNames[icon]; ok {
|
||||
return name
|
||||
}
|
||||
|
||||
name := kebabMatchFirstCap.ReplaceAllString(string(icon), "${1}-${2}")
|
||||
name = kebabMatchAllCaps.ReplaceAllString(string(name), "${1}-${2}")
|
||||
return strings.ToLower(name)
|
||||
}
|
||||
|
||||
func generalizeIcon (icon tomo.Icon) tomo.Icon {
|
||||
name := string(icon)
|
||||
switch {
|
||||
case strings.HasPrefix(name, "Application"): return tomo.IconApplication
|
||||
case strings.HasPrefix(name, "Preferences"): return tomo.IconPreferences
|
||||
case strings.HasPrefix(name, "Device"): return tomo.IconDevice
|
||||
case strings.HasPrefix(name, "Hardware"): return tomo.IconHardware
|
||||
case strings.HasPrefix(name, "Storage"): return tomo.IconStorageHardDisk
|
||||
case strings.HasPrefix(name, "Input"): return tomo.IconInputMouse
|
||||
case strings.HasPrefix(name, "Network"): return tomo.IconNetworkWired
|
||||
case strings.HasPrefix(name, "Place"): return tomo.IconPlaceDirectory
|
||||
case strings.HasPrefix(name, "Directory"): return tomo.IconPlaceDirectory
|
||||
case strings.HasPrefix(name, "Trash"): return tomo.IconPlaceTrash
|
||||
case strings.HasPrefix(name, "Help"): return tomo.IconHelpContents
|
||||
}
|
||||
|
||||
switch icon {
|
||||
case tomo.IconCellularSignal0: return tomo.IconWirelessSignal0
|
||||
case tomo.IconCellularSignal1: return tomo.IconWirelessSignal1
|
||||
case tomo.IconCellularSignal2: return tomo.IconWirelessSignal2
|
||||
case tomo.IconCellularSignal3: return tomo.IconWirelessSignal3
|
||||
}
|
||||
|
||||
return icon
|
||||
}
|
||||
|
||||
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 {
|
||||
case tomo.IconSizeMedium: return 24
|
||||
case tomo.IconSizeLarge: return 48
|
||||
default: return 16
|
||||
}
|
||||
}
|
||||
136
internal/theme/icons/xdg/xdgiconname.go
Normal file
136
internal/theme/icons/xdg/xdgiconname.go
Normal file
@@ -0,0 +1,136 @@
|
||||
package xdgIcons
|
||||
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
|
||||
// icons that can't be directly translated with regex
|
||||
var xdgIconNames = map[tomo.Icon] string {
|
||||
tomo.IconUnknown: "image-missing",
|
||||
tomo.IconFileNew: "document-new",
|
||||
tomo.IconDirectoryNew: "folder-new",
|
||||
tomo.IconFileOpen: "document-open",
|
||||
tomo.IconFileOpenRecent: "document-open-recent",
|
||||
tomo.IconFilePageSetup: "document-page-setup",
|
||||
tomo.IconFilePrint: "document-print",
|
||||
tomo.IconFilePrintPreview: "document-print-preview",
|
||||
tomo.IconFilePermissions: "document-permissions", // non-standard
|
||||
tomo.IconFileProperties: "document-properties",
|
||||
tomo.IconFileRename: "document-rename", // non-standard
|
||||
tomo.IconFileRevert: "document-revert",
|
||||
tomo.IconFileSave: "document-save",
|
||||
tomo.IconFileSaveAs: "document-save-as",
|
||||
tomo.IconFileSend: "document-send",
|
||||
tomo.IconFormatAlignCenter: "format-justify-center",
|
||||
tomo.IconFormatAlignEven: "format-justify-fill",
|
||||
tomo.IconFormatAlignLeft: "format-justify-left",
|
||||
tomo.IconFormatAlignRight: "format-justify-right",
|
||||
tomo.IconMailReceive: "mail-send-receive",
|
||||
tomo.IconValueIncrement: "list-add",
|
||||
tomo.IconValueDecrement: "list-remove",
|
||||
tomo.IconValueReset: "value-reset", // non-standard
|
||||
tomo.IconApplication: "system-run",
|
||||
tomo.IconApplicationWebBrowser: "web-browser",
|
||||
tomo.IconApplicationMesssanger: "internet-messanger", // non-standard
|
||||
tomo.IconApplicationPhone: "accessories-phone", // non-standard
|
||||
tomo.IconApplicationMail: "internet-mail-client", // non-standard
|
||||
tomo.IconApplicationTerminalEmulator: "utilities-terminal",
|
||||
tomo.IconApplicationFileBrowser: "system-file-manager",
|
||||
tomo.IconApplicationTextEditor: "accessories-text-editor",
|
||||
tomo.IconApplicationDocumentViewer: "office-document-viewer", // non-standard
|
||||
tomo.IconApplicationWordProcessor: "office-word-processor", // non-standard
|
||||
tomo.IconApplicationSpreadsheet: "office-spreadsheet", // non-standard
|
||||
tomo.IconApplicationSlideshow: "office-slideshow", // non-standard
|
||||
tomo.IconApplicationCalculator: "accessories-calculator",
|
||||
tomo.IconApplicationPreferences: "preferences-system",
|
||||
tomo.IconApplicationProcessManager: "utilities-system-monitor",
|
||||
tomo.IconApplicationSystemInformation: "distributor-logo", // non-standard
|
||||
tomo.IconApplicationManual: "help-browser",
|
||||
tomo.IconApplicationCamera: "accessories-camera", // non-standard
|
||||
tomo.IconApplicationImageViewer: "graphics-image-viewer", // non-standard
|
||||
tomo.IconApplicationMediaPlayer: "audio-video-media-player", // non-standard
|
||||
tomo.IconApplicationImageEditor: "graphics-image-editor", // non-standard
|
||||
tomo.IconApplicationAudioEditor: "audio-audio-editor", // non-standard
|
||||
tomo.IconApplicationVideoEditor: "video-video-editor", // non-standard
|
||||
tomo.IconApplicationClock: "accessories-clock", // non-standard
|
||||
tomo.IconApplicationCalendar: "accessories-calendar", // non-standard
|
||||
tomo.IconApplicationChecklist: "accessories-checklist", // non-standard
|
||||
tomo.IconApplications: "applications-other",
|
||||
tomo.IconPreferences: "preferences-other",
|
||||
tomo.IconPreferencesNetwork: "preferences-system-network",
|
||||
tomo.IconDevice: "device", // non-standard
|
||||
tomo.IconDeviceCamera: "camera-photo",
|
||||
tomo.IconDeviceWebCamera: "camera-web",
|
||||
tomo.IconDeviceComputer: "computer",
|
||||
tomo.IconDevicePda: "pda",
|
||||
tomo.IconDevicePhone: "phone",
|
||||
tomo.IconDevicePrinter: "printer",
|
||||
tomo.IconDeviceScanner: "scanner",
|
||||
tomo.IconDeviceMultimediaPlayer: "multimedia-player",
|
||||
tomo.IconDeviceVideoDisplay: "video-display",
|
||||
tomo.IconDeviceAudioInput: "audio-input-microphone",
|
||||
tomo.IconDeviceAudioOutput: "audio-speakers",
|
||||
tomo.IconHardware: "card", // non-standard
|
||||
tomo.IconHardwareCPU: "cpu",
|
||||
tomo.IconHardwareGPU: "video-card",
|
||||
tomo.IconHardwareRAM: "ram",
|
||||
tomo.IconHardwareSoundCard: "audio-card",
|
||||
tomo.IconHardwareNetworkAdapter: "network-card",
|
||||
tomo.IconPowerBattery: "battery",
|
||||
tomo.IconStorageHardDisk: "drive-harddisk",
|
||||
tomo.IconStorageFloppyDisk: "media-floppy",
|
||||
tomo.IconStorageSolidState: "drive-solid",
|
||||
tomo.IconStorageOptical: "media-optical",
|
||||
tomo.IconStorageFlashStick: "media-removable",
|
||||
tomo.IconStorageFlashCard: "media-flash",
|
||||
tomo.IconStorageMagneticTape: "media-tape",
|
||||
tomo.IconEmblemReadOnly: "emblem-readonly",
|
||||
tomo.IconPlaceDirectory: "folder",
|
||||
tomo.IconPlaceRemote: "folder-remote",
|
||||
tomo.IconPlaceHome: "user-home",
|
||||
tomo.IconPlaceDownloads: "folder-downloads", // common
|
||||
tomo.IconPlaceDesktop: "user-desktop",
|
||||
tomo.IconPlacePhotos: "folder-pictures", // common
|
||||
tomo.IconPlaceBooks: "folder-books", // non-standard
|
||||
tomo.IconPlaceBookmarks: "user-bookmarks",
|
||||
tomo.IconPlaceTrash: "user-trash",
|
||||
tomo.IconPlaceDocuments: "folder-documents", // common
|
||||
tomo.IconPlaceRepositories: "folder-repositories", // non-standard
|
||||
tomo.IconPlaceMusic: "folder-music", // common
|
||||
tomo.IconPlaceArchives: "folder-archives", // non-standard
|
||||
tomo.IconPlaceFonts: "folder-fonts", // non-standard
|
||||
tomo.IconPlaceBinaries: "folder-executables", // non-standard
|
||||
tomo.IconPlaceVideos: "folder-videos", // common
|
||||
tomo.IconPlace3DObjects: "folder-3d-objects", // non-standard
|
||||
tomo.IconPlaceHistory: "folder-history", // non-standard
|
||||
tomo.IconPlacePreferences: "preferences-other",
|
||||
tomo.IconDirectoryDragAccept: "folder-drag-accept",
|
||||
tomo.IconDirectoryFull: "folder-full",
|
||||
tomo.IconDirectoryOpen: "folder-open",
|
||||
tomo.IconDirectoryVisiting: "folder-visiting",
|
||||
tomo.IconTrashFull: "user-trash-full",
|
||||
tomo.IconResourceLoading: "image-loading",
|
||||
tomo.IconResourceMissing: "image-missing",
|
||||
tomo.IconCellularSignal0: "nm-signal-00", // common
|
||||
tomo.IconCellularSignal1: "nm-signal-25", // common
|
||||
tomo.IconCellularSignal2: "nm-signal-75", // common
|
||||
tomo.IconCellularSignal3: "nm-signal-100", // common
|
||||
tomo.IconWirelessSignal0: "wifi-signal-00", // common
|
||||
tomo.IconWirelessSignal1: "wifi-signal-25", // common
|
||||
tomo.IconWirelessSignal2: "wifi-signal-75", // common
|
||||
tomo.IconWirelessSignal3: "wifi-signal-100", // common
|
||||
tomo.IconPrintError: "printer-error",
|
||||
tomo.IconPrintPrinting: "printer-printing",
|
||||
tomo.IconBattery0: "battery-caution",
|
||||
tomo.IconBattery1: "battery-low",
|
||||
tomo.IconBattery2: "battery-good", // common
|
||||
tomo.IconBattery3: "battery-full", // common
|
||||
tomo.IconBrightness0: "brightness-dim", // non-standard
|
||||
tomo.IconBrightness1: "brightness-medium", // non-standard
|
||||
tomo.IconBrightness2: "brightness-bright", // non-standard
|
||||
tomo.IconBrightness3: "brightness-full", // non-standard
|
||||
tomo.IconVolume0: "audio-volume-muted",
|
||||
tomo.IconVolume1: "audio-volume-low",
|
||||
tomo.IconVolume2: "audio-volume-medium",
|
||||
tomo.IconVolume3: "audio-volume-high",
|
||||
tomo.IconPlaylistRepeat: "media-playlist-repeat",
|
||||
tomo.IconPlaylistShuffle: "media-playlist-shuffle",
|
||||
}
|
||||
Reference in New Issue
Block a user