システムトレイのアイコンを変更するには?

システムトレイのアイコンを変更するには?

システムトレイのほとんどのアイコンは白ですが、そのうちの1つはカラーです。他の色と同様に、色を白に変更したいと思います。

問題のアイコンはFlameshotに属し、Githubの問題ではモノクロシステムトレイアイコンのオプションを提供しないと述べました。これは他のプロセスで処理する必要があるためです。

それでは、この他のプロセスは何ですか?システムトレイのアイコンを変更するには?どのような方法でテーマに存在しますか?

どのように?

ありがとうございます。

ベストアンサー1

どのディストリビューション、デスクトップ環境、テーマを使用しているのかわかりません。これらすべてが特定のコマンドにとって重要な場合があります。ほとんどのLinuxデスクトップは標準のアイコン配置に従います。アプリケーションが意図的に複数のディストリビューションで異なるファイル名を使用しない場合がありますが、あるディストリビューションのバージョンが異なり、開発者がファイル名を変更する場合は重要です。

これさまざまな場所の一般的な概要があります。

一般に、アプリケーションがユーザーコンテキストにインストールされている場合は以下を確認し、~/.local/share/iconsすべてのユーザー用にインストールされている場合は以下を確認する必要があります/usr/share/icons。これは最も一般的な場所にすぎず、ここでは深く扱わない他の場所もあります。

基本テーマセット(アイコンはMint-Y-Aqua)を使用してFedora 33(Cinnamonスピン)で見つけたものは次のとおりです。

$ 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

ファイル名で見ると、そのうちの1つが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スクリプトの修正バージョンについては、この記事の下部を参照してください。

とにかく、次のコマンドを実行してFlameshot-tray.svgファイルをfirefox.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

おすすめ記事