如何更改系统托盘中的图标?

如何更改系统托盘中的图标?

系统托盘中的大多数图标都是白色的,但有一个是彩色的。我想将彩色的改为白色,就像其他的一样。

有问题的图标属于 Flameshot,他们在 Github 问题中表示,他们不会提供单色系统托盘图标的选项,因为这应该由其他进程处理。

那么这个其他过程是什么呢?如何更改系统托盘图标?它以某种方式存在于主题中吗?

如何?

谢谢。

答案1

不确定您正在使用什么发行版、桌面环境和主题 - 所有这些都可能对特定命令很重要。大多数 Linux 桌面将遵循标准的图标位置。虽然应用程序可能不会故意在不同的发行版上使用不同的文件名,但如果一个发行版具有不同的版本并且开发人员更改了文件名,那么这可能很重要。

对各个地点有一个不错的总体概述。

一般来说,如果应用程序安装在您的用户上下文下,那么您将需要开始在下查找~/.local/share/icons,如果它是为所有用户安装的,您将需要在下查找/usr/share/icons。这些只是最常见的位置,还有其他一些我不会在这里深入探讨。

以下是我在 Fedora 33(Cinnamon spin)上使用默认主题集(图标为 Mint-Y-Aqua)时发现的内容:

$ sudo dnf install -y flameshot
 
$ dnf list --installed --cacheonly --quiet flameshot
Installed Packages
flameshot.x86_64    0.8.5-1.fc33     @updates
 
$ cd /usr/share/icons
$ find . -type f -iname '*flameshot*'
./breeze-dark/status/22/flameshot-tray.svg
./breeze-dark/status/22@3x/flameshot-tray.svg
./breeze-dark/status/22@2x/flameshot-tray.svg
./hicolor/128x128/apps/flameshot.png
./hicolor/128x128/apps/org.flameshot.Flameshot.png
./hicolor/scalable/apps/org.flameshot.Flameshot.svg
./hicolor/scalable/apps/flameshot.svg
./hicolor/48x48/apps/flameshot.png
./hicolor/48x48/apps/org.flameshot.Flameshot.png
./breeze/status/22/flameshot-tray.svg
./breeze/status/22x@3x/flameshot-tray.svg
./breeze/status/22@2x/flameshot-tray.svg

根据文件名,我猜测其中之一flameshot-tray.svg就是我们正在寻找的罪魁祸首。如果这是 png 或 jpg,我们可以用相同大小的新图像覆盖。

SVG 是基于文本文件的图像渲染方式定义。我不太熟悉编辑这种格式,因此如果您需要实际 SVG 编辑方面的帮助以使其成为单色,则必须向其他人询问。但 Image Magik 的转换工具可能会有所帮助,假设它支持 svg 格式。

也就是说,我可以用另一个图标替换它并测试它是否有效,因为我打算在这篇文章之后卸载(我自己更喜欢 Shutter/maim/scrot),所以我并不在乎。如果您进行了您关心的修改,我建议您先进行备份。

hicolor 是 gnome 主题的一种默认图标位置(我根本没有使用微风主题,如果我愿意的话可以忽略它们)。当应用程序具有诸如“firefox”之类的图标名称时,它通常会在所有当前文件夹(例如 ~/.local/share/icons、/usr/share/icons 和其他一些文件夹)中检查您的特定主题,然后回退到 hicolor 下检查。您可以在我上面提供的链接中更详细地了解这一点,或者您也可以使用一个脚本来调用 GTK 的图标解析器 api 并输出结果(比如这里的那个- 或者请参阅本文底部以获取链接的 python 脚本的修改版本)。

无论如何,我运行了以下命令,用 firefox.svg 替换 Flameshot-tray.svg 文件并重建图标缓存:

# replace flameshot icon with firefox icon
sudo find -H /usr/share/icons -type f -iname 'flameshot-tray.svg' -exec cp -a '/usr/share/icons/hicolor/symbolic/apps/firefox-symbolic.svg' "{}" \;
 
# rebuild the icon cache so you can see it right away
# note: this works on cinnamon and presumably all gtk-based
# based DEs (gnome, mate, xfce, etc). I have no clue if it
# would work on KDE but I assume it would not
sudo gtk-update-icon-cache -f /usr/share/icons/*

重新启动应用程序后,其系统托盘图标显示为单色 Firefox 图标。文件名和命令可能会根据您的发行版而有所不同,但这应该可以让您很好地了解所需的步骤以及在哪里查找。


奖励:这里有我提到的修改后的 python 脚本,它更适合我。我用它来查找图标路径。简短的版本是它使用 GTK api 来进行查找。

#!/usr/bin/env python3
 
# ==========================================================================================
# This script is for looking up an icon file path based on the icon name from a *.desktop file.
# Parts of it are based on snippets provided by Stefano Palazzo and kiri on askubuntu.com
#   https://askubuntu.com/questions/52430/how-can-i-find-the-location-of-an-icon-of-a-launcher-in-use
# ==========================================================================================
# The original version(s) simply prompted the user for the icon name.
# However, I have modified this version in the following ways:
#   1. Added ability to pass specific size as arg (e.g. --size=22 or --size=48, etc)
#   2. Added ability to pass icon names as arg (any other arg besides --size)
#       Note: if --size is used with multiple icon names, then it is assummed
#             that all of the icons in the search will be for the same size
#   3. Like kiri's version, I removed the hard-coded size of 48x48 and default to all sizes
#   4. Unlike kiri's version, you can optionally still search for a specific size (using #1)
#   5. Performance improvements from kiri's version (he was checking every even number from
#       0 to 500 -- so 250 iterations. I base mine off the values that actually existing under
#       /etc/share/icons/hicolor - of which there were 17. So his is more flexible but
#       mine should be quicker and more forgiving in terms of HDD wear and tear)
# ==========================================================================================
 
import gi
import sys
import array as arr 
 
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
 
def resolveIconPath( iconName, iconSize = -1 ):
    "This takes a freedesktop.org icon name and prints the GTK 3.0 resolved file location."
 
    iconTheme = Gtk.IconTheme.get_default()
    
    # if looking up a specific size
    if iconSize >= 16:
        msgTemplate = "iconname: \"" + iconName + "\" (size: " + str(iconSize) + "): "
        
        iconFile = iconTheme.lookup_icon(iconName, iconSize, 0)
        if iconFile:
            print(msgTemplate + iconFile.get_filename() + "\n")
        else:
            print("W:" + msgTemplate + " No matching path(s) found.\n")
    else:
        # otherwise, look up *all* sizes that can be found
        sep="===================================================================="
        msgTemplate = sep + "\niconname: \"" + iconName + "\":\n" + sep
        
        foundIconsList = list()
        for resolution in [16, 20, 22, 24, 28, 32, 36, 48, 64, 72, 96, 128, 192, 256, 480, 512, 1024]:
            iconFile = iconTheme.lookup_icon(iconName, resolution, 0)
            if iconFile:
                filePath=str(iconFile.get_filename())
                if not (filePath in foundIconsList):
                    foundIconsList.append(iconFile.get_filename())
 
        if foundIconsList:
            print(msgTemplate + "\n"+ "\n".join(foundIconsList)+ "\n")
        else:
            print("W: iconname: \"" + iconName + "\":  No matching path(s) found.\n")
        return
 
 
# get the total number of args passed (excluding first arg which is the script name)
argumentsLen = len(sys.argv) - 1
 
# define a list for storing all passed icon names
iconNamesList = []
 
# loop through passed args, if we have any and handle appropriately
showHelp=False
size=-1
if argumentsLen > 0:
    for i in range(1, len(sys.argv)):
        arg=str(sys.argv[i])
        #print(i, "arg: " + arg)
        if arg.startswith('--size=') or arg.startswith('-s=') or arg.startswith('-S='):
            tmpSize=(arg.split("=",2))[1]
            if len(tmpSize) > 0 and tmpSize.isnumeric():
                size=int(tmpSize)
            else:
                print("Invalid size '" + tmpSize + "'; Expected --size=xx where xx is a positive integer.")
        elif arg == '--help' or arg == '-h':
            print(str(sys.argv[0]) + " [OPTIONS] [ICON_NAME]\n")
            print("Takes a freedesktop.org/GNOME icon name, as commonly appears in a *.desktop file,")
            print("and performs a lookup to determine matching filesystem path(s). By default, this")
            print("path resolution is determined for all available icon sizes. However, a specific")
            print("size can be used by providing one of the options below.\n")
            print("OPTIONS:")
            print("  -s=n, --size=n   Restricts path resolution to icons matching a specific size.")
            print("                   The value n must be a positive integer correspending to icon size.")
            print("                   When using this option with multiple passed icon names, the size")
            print("                   restrictions are applied to *all* of the resolved icons. Querying")
            print("                   different sizes for different icons is only possible via the use of")
            print("                   multiple calls or by parsing the default output.\n")
            print("  -h, --help       Display this help page and exit.\n")
            exit()
        else:
            iconNamesList.append(arg)
 
# if no icon names were passed on command line, then prompt user
if len(iconNamesList) == 0:
    iconNamesList.append(input("Icon name (case sensitive): "))
 
#print("size: " + str(size))
#print("iconNamesList: ")
if len(iconNamesList) > 0:
    for iconName in iconNamesList:
        if size < 16:
            # find all sizes (on my system, 16x16 was the smallest size icons under hicolor)
            resolveIconPath(iconName)
        else:
            # use custom size
            resolveIconPath(iconName, size)

用法:

# view help
get-icon-path.py --help
 
# lookup all matching icons
get-icon-path.py firefox
 
# lookup all matching icons for a specific size (16x16)
get-icon-path.py --size=16 firefox
 
# lookup specific size for multiple icons in one command
get-icon-path.py --size=16 firefox gimp

相关内容