fix: render desktop icons on older librsvg releases

This commit is contained in:
Kevin Yue committed 2026-10-20 14:53:44 +08:00
1 parent dfab3882e1
commit e15422a64f
4 files changed
+105 -4

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
name: Desktop icon compatibility
on:
pull_request:
paths:
- '.github/workflows/desktop-icons.yaml'
- 'scripts/tests/test_desktop_icon.py'
- 'packaging/files/usr/share/icons/**'
- 'apps/gpgui-helper/src-tauri/icons/**'
push:
branches: [main]
paths:
- '.github/workflows/desktop-icons.yaml'
- 'scripts/tests/test_desktop_icon.py'
- 'packaging/files/usr/share/icons/**'
- 'apps/gpgui-helper/src-tauri/icons/**'
permissions:
contents: read
jobs:
render:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-24.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- name: Install the distro SVG loader
run: |
sudo apt-get update
sudo apt-get install -y python3-gi gir1.2-gdkpixbuf-2.0 librsvg2-common
- name: Render desktop icons
run: /usr/bin/python3 -m unittest discover -s scripts/tests -p test_desktop_icon.py
+11 -2
View File
@@ -18,11 +18,20 @@
<clipPath id="globe-clip">
<circle cx="512" cy="455" r="315"/>
</clipPath>
<!-- Use SVG 1.1 primitives: feDropShadow needs librsvg >= 2.55.91. -->
<filter id="globe-shadow" x="150" y="90" width="730" height="760" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feDropShadow dx="0" dy="8" stdDeviation="12" flood-color="#174d6f" flood-opacity=".14"/>
<feGaussianBlur in="SourceAlpha" stdDeviation="12" result="blur"/>
<feOffset in="blur" dx="0" dy="8" result="offsetBlur"/>
<feFlood flood-color="#174d6f" flood-opacity=".14" result="shadowColor"/>
<feComposite in="shadowColor" in2="offsetBlur" operator="in" result="shadow"/>
<feMerge><feMergeNode in="shadow"/><feMergeNode in="SourceGraphic"/></feMerge>
</filter>
<filter id="lock-shadow" x="280" y="210" width="470" height="540" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feDropShadow dx="0" dy="18" stdDeviation="18" flood-color="#70430c" flood-opacity=".2"/>
<feGaussianBlur in="SourceAlpha" stdDeviation="18" result="blur"/>
<feOffset in="blur" dx="0" dy="18" result="offsetBlur"/>
<feFlood flood-color="#70430c" flood-opacity=".2" result="shadowColor"/>
<feComposite in="shadowColor" in2="offsetBlur" operator="in" result="shadow"/>
<feMerge><feMergeNode in="shadow"/><feMergeNode in="SourceGraphic"/></feMerge>
</filter>
</defs>

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

@@ -18,11 +18,20 @@
<clipPath id="globe-clip">
<circle cx="512" cy="455" r="315"/>
</clipPath>
<!-- Use SVG 1.1 primitives: feDropShadow needs librsvg >= 2.55.91. -->
<filter id="globe-shadow" x="150" y="90" width="730" height="760" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feDropShadow dx="0" dy="8" stdDeviation="12" flood-color="#174d6f" flood-opacity=".14"/>
<feGaussianBlur in="SourceAlpha" stdDeviation="12" result="blur"/>
<feOffset in="blur" dx="0" dy="8" result="offsetBlur"/>
<feFlood flood-color="#174d6f" flood-opacity=".14" result="shadowColor"/>
<feComposite in="shadowColor" in2="offsetBlur" operator="in" result="shadow"/>
<feMerge><feMergeNode in="shadow"/><feMergeNode in="SourceGraphic"/></feMerge>
</filter>
<filter id="lock-shadow" x="280" y="210" width="470" height="540" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feDropShadow dx="0" dy="18" stdDeviation="18" flood-color="#70430c" flood-opacity=".2"/>
<feGaussianBlur in="SourceAlpha" stdDeviation="18" result="blur"/>
<feOffset in="blur" dx="0" dy="18" result="offsetBlur"/>
<feFlood flood-color="#70430c" flood-opacity=".2" result="shadowColor"/>
<feComposite in="shadowColor" in2="offsetBlur" operator="in" result="shadow"/>
<feMerge><feMergeNode in="shadow"/><feMergeNode in="SourceGraphic"/></feMerge>
</filter>
</defs>

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

+49
View File
@@ -0,0 +1,49 @@
"""Render desktop icons through the distro's GdkPixbuf/librsvg loader.
Run with /usr/bin/python3; requires python3-gi and gir1.2-gdkpixbuf-2.0.
"""
from pathlib import Path
import unittest
import gi
gi.require_version("GdkPixbuf", "2.0")
from gi.repository import GdkPixbuf
ROOT = Path(__file__).resolve().parents[2]
ICONS = (
ROOT / "packaging/files/usr/share/icons/hicolor/scalable/apps/gpgui.svg",
ROOT / "apps/gpgui-helper/src-tauri/icons/icon.svg",
)
class DesktopIconTests(unittest.TestCase):
def test_packaged_and_helper_icons_match(self):
self.assertEqual(ICONS[0].read_bytes(), ICONS[1].read_bytes())
def test_icons_render_visible_artwork(self):
# Unsupported filter primitives can load successfully yet produce an
# entirely transparent icon, so successful decoding alone is not enough.
for icon in ICONS:
for size in (32, 48, 128, 256, 512):
with self.subTest(icon=icon, size=size):
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
str(icon), size, size, True
)
self.assertEqual((pixbuf.get_width(), pixbuf.get_height()), (size, size))
self.assertTrue(pixbuf.get_has_alpha())
pixels = pixbuf.get_pixels()
stride = pixbuf.get_rowstride()
channels = pixbuf.get_n_channels()
visible = sum(
pixels[y * stride + x * channels + channels - 1] > 128
for y in range(size)
for x in range(size)
)
self.assertGreater(visible, size * size * 0.4)
if __name__ == "__main__":
unittest.main()