desktop_icons_check.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. # desktop_icons_check.sh <vm> [screen] - the desktop's icons must stay visible above the engine's wallpaper, on a running VM
  3. # (release_check.sh runs it for every profile). Screenshots through the VM's display: A the desktop, B the same with a few
  4. # files on the desktop folder (what the icon provider of the session draws is where B differs from A, the mask), E the engine
  5. # running without the files, D the engine with them. The icons are visible when D differs from E over the mask about as much
  6. # as B differs from A. No provider in the session (GNOME without Desktop Icons NG, wlroots compositors, ...) is a SKIP, on
  7. # Plasma it is a FAIL. Plasma on Wayland hides Folder View under the engine's bottom layer surface, there we_manager's
  8. # overlay (OVERLAY, default the sibling checkout's script) is installed with what it needs (gtk4-layer-shell, PyGObject,
  9. # pycairo) and started after the engine, as we_manager does.
  10. HERE=$(cd "$(dirname "$0")" && pwd)
  11. vm=$1 screen=${2:-Virtual-1}
  12. OVERLAY=${OVERLAY:-$HERE/../../../we_manager/src/main/services/desktop-icons-overlay.py}
  13. WP=${WP:-1111948150}
  14. sshv() { "$HERE/linuxvm.sh" ssh "$vm" "$@" </dev/null; }
  15. status=0
  16. pass() { echo "PASS $vm: $1"; }
  17. fail() { echo "FAIL $vm: $1"; status=1; }
  18. skip() { echo "SKIP $vm: $1"; }
  19. tmp=$(mktemp -d)
  20. shot() { "$HERE/linuxvm.sh" shot "$vm" "$tmp/$1.png" >/dev/null 2>&1; }
  21. for _ in $(seq 60); do sshv 'bash ~/lwe/sessenv.sh' >/dev/null 2>&1 && break; sleep 5; done
  22. sshv 'bash ~/lwe/sessenv.sh' >/dev/null 2>&1 || { fail "no desktop session"; exit 1; }
  23. session=$(sshv '. ~/sessenv; echo "$XDG_CURRENT_DESKTOP $XDG_SESSION_TYPE"')
  24. kde=0; [[ $session == *KDE*wayland* ]] && kde=1
  25. desk=$(sshv 'd=$(xdg-user-dir DESKTOP 2>/dev/null); [ -n "$d" ] && [ "$d" != "$HOME" ] || d=$HOME/Desktop; mkdir -p "$d"; echo "$d"')
  26. make_files() {
  27. sshv "mkdir -p '$desk/Projects'; touch '$desk/notes.txt' '$desk/data.csv'; find /usr/share/applications \\( -name '*konsole*.desktop' -o -name 'org.gnome.Nautilus.desktop' -o -name 'firefox*.desktop' \\) | head -2 | xargs -I{} cp {} '$desk/'; true"
  28. }
  29. remove_files() {
  30. sshv "rm -rf '$desk/Projects' '$desk/notes.txt' '$desk/data.csv'; find '$desk' -maxdepth 1 \\( -name '*konsole*.desktop' -o -name 'org.gnome.Nautilus.desktop' -o -name 'firefox*.desktop' \\) -delete; true"
  31. }
  32. cleanup() { sshv 'pkill -f "[o]vl.py"; pkill -x linux-wallpaper; true'; remove_files; }
  33. sshv 'pkill -f "[o]vl.py"; pkill -x linux-wallpaper; true'
  34. remove_files
  35. sleep 4
  36. shot A
  37. make_files
  38. sleep 8
  39. shot B
  40. remove_files
  41. sleep 4
  42. shot A2
  43. # icon pixels: where B differs from the empty desktop both times, a notification that came up and stayed is in B and A2
  44. mask=$(python3 -W ignore - "$tmp" <<'E'
  45. import sys
  46. from PIL import Image, ImageChops
  47. d = sys.argv[1]
  48. a, a2, b = (Image.open(f'{d}/{n}.png').convert('L') for n in ('A', 'A2', 'B'))
  49. cut = lambda x: x.point(lambda v: 255 if v > 40 else 0)
  50. diff = ImageChops.multiply(cut(ImageChops.difference(a, b)), cut(ImageChops.difference(a2, b)))
  51. diff.save(f'{d}/mask.png')
  52. print(sum(1 for p in diff.getdata() if p))
  53. E
  54. )
  55. if [ "${mask:-0}" -lt 300 ]; then
  56. cleanup
  57. if [ $kde = 1 ]; then fail "Plasma's Folder View shows no icons for files on $desk (mask $mask px, screenshots in $tmp)"; else
  58. skip "no desktop icon provider in this session ($session): nothing to keep above the wallpaper"
  59. fi
  60. exit $status
  61. fi
  62. pass "the session draws its icons ($mask px differ with files on the desktop)"
  63. sshv ". ~/sessenv; cd ~/lwe; (setsid nohup ./lwe-hints/linux-wallpaperengine ${ENGINE_ARGS:-} --screen-root $screen --assets-dir ~/lwe/assets ~/lwe/wp-$WP >/tmp/di-engine.log 2>&1 &); sleep 20"
  64. shot E
  65. if [ $kde = 1 ]; then
  66. "$HERE/linuxvm.sh" scp "$vm" "$OVERLAY" ovl.py >/dev/null 2>&1 || { fail "overlay script not found: $OVERLAY"; cleanup; exit 1; }
  67. libs='bash -c "ls /usr/lib64/libgtk4-layer-shell.so* /usr/lib/libgtk4-layer-shell.so* /usr/lib/x86_64-linux-gnu/libgtk4-layer-shell.so* 2>/dev/null | head -1"'
  68. if [ -z "$(sshv "$libs")" ]; then
  69. sshv 'if command -v dnf >/dev/null; then sudo dnf install -y gtk4-layer-shell python3-gobject python3-cairo
  70. elif command -v pacman >/dev/null; then sudo pacman -Sy --noconfirm --needed gtk4-layer-shell python-gobject python-cairo
  71. elif command -v apt-get >/dev/null; then sudo apt-get install -y gir1.2-gtk4layershell-1.0 libgtk4-layer-shell0 python3-gi python3-gi-cairo gir1.2-gtk-4.0
  72. elif command -v zypper >/dev/null; then sudo zypper -n install libgtk4-layer-shell0 typelib-1_0-Gtk4LayerShell-1_0 python3-gobject python3-cairo typelib-1_0-Gtk-4_0
  73. fi' >"$tmp/install.log" 2>&1
  74. fi
  75. lib=$(sshv "$libs")
  76. if [ -z "$lib" ]; then
  77. skip "gtk4-layer-shell can't be installed here ($(tail -1 "$tmp/install.log" | cut -c1-100)), the overlay can't run"
  78. cleanup; exit $status
  79. fi
  80. preload=$(sshv 'bash -c "ls /usr/lib64/libgtk4-layer-shell.so.0 /usr/lib/libgtk4-layer-shell.so.0 /usr/lib/x86_64-linux-gnu/libgtk4-layer-shell.so.0 2>/dev/null | head -1"')
  81. [ -n "$preload" ] || preload=$lib
  82. make_files
  83. # gtk4-layer-shell 1.0.x dlopens the plain libwayland-client.so (-devel only), we_manager points LD_LIBRARY_PATH at a symlink
  84. sshv 'mkdir -p ~/ovl-lib; for l in /usr/lib64 /usr/lib /usr/lib/x86_64-linux-gnu; do [ -e $l/libwayland-client.so.0 ] && ln -sf $l/libwayland-client.so.0 ~/ovl-lib/libwayland-client.so && break; done; true'
  85. sshv ". ~/sessenv; (setsid nohup env LD_LIBRARY_PATH=\$HOME/ovl-lib LD_PRELOAD=$preload GDK_BACKEND=wayland python3 ~/ovl.py $screen >/tmp/di-overlay.log 2>&1 &); sleep 8"
  86. [ "$(sshv 'pgrep -fc "python3 .*[o]vl.py"')" -ge 1 ] && pass "overlay running" || fail "overlay exited: $(sshv 'head -5 /tmp/di-overlay.log')"
  87. else
  88. make_files
  89. sleep 8
  90. fi
  91. shot D
  92. if python3 -W ignore - "$tmp" <<'E'
  93. import sys
  94. from PIL import Image, ImageChops
  95. d = sys.argv[1]
  96. im = {n: Image.open(f'{d}/{n}.png').convert('L') for n in 'ABDE'}
  97. mask = Image.open(f'{d}/mask.png')
  98. def mean(x, y):
  99. diff = ImageChops.difference(x, y)
  100. px = [p for p, m in zip(diff.getdata(), mask.getdata()) if m]
  101. return sum(px) / len(px)
  102. provider = mean(im['A'], im['B'])
  103. kept = mean(im['E'], im['D'])
  104. print(f'icon area: {provider:.1f} levels without the engine, {kept:.1f} with it')
  105. sys.exit(0 if kept > provider * 0.4 else 1)
  106. E
  107. then pass "icons visible above the wallpaper"; else fail "icons hidden by the wallpaper (screenshots in $tmp)"; fi
  108. cleanup
  109. echo " screenshots: $tmp"
  110. exit $status