| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | cd -- "$(dirname -- "${BASH_SOURCE[0]}")" |
| 4 | |
| 5 | mode=${1:-install} |
| 6 | from_source=false |
| 7 | case "$mode" in |
| 8 | install|--build-only|--uninstall) ;; |
| 9 | --build) mode=install; from_source=true ;; |
| 10 | *) echo "Gebruik: $0 [--build|--build-only|--uninstall]" >&2; exit 2 ;; |
| 11 | esac |
| 12 | # Releases: https://git.timfalken.com/timfa/click-tween/-/releases |
| 13 | repo_url=${CLICKTWEEN_REPO_URL:-https://git.timfalken.com/timfa/click-tween} |
| 14 | if [[ $mode != --build-only ]]; then |
| 15 | [[ $EUID -ne 0 ]] || { echo 'Start dit script als gewone gebruiker, zonder sudo ervoor.' >&2; exit 1; } |
| 16 | for tool in sudo kwriteconfig6 qdbus6; do |
| 17 | command -v "$tool" >/dev/null || { echo "Ontbreekt: $tool" >&2; exit 1; } |
| 18 | done |
| 19 | fi |
| 20 | |
| 21 | # This build intentionally targets Arch's Plasma 6.7/6.8 layout and private API. |
| 22 | plugin_dir=/usr/lib/qt6/plugins/kwin/effects/plugins |
| 23 | plugin_file=$plugin_dir/kwin_effect_clicktween.so |
| 24 | config_file=/usr/lib/qt6/plugins/kwin/effects/configs/kwin_clicktween_config.so |
| 25 | if [[ $mode == --uninstall ]]; then |
| 26 | kwriteconfig6 --file kwinrc --group Plugins --key kwin_effect_clicktweenEnabled false |
| 27 | qdbus6 org.kde.KWin /Effects org.kde.kwin.Effects.unloadEffect kwin_effect_clicktween || true |
| 28 | sudo rm -f -- "$plugin_file" "$config_file" |
| 29 | echo 'Click Tween verwijderd. Bij een D-Bus-fout: meld opnieuw aan.' |
| 30 | exit 0 |
| 31 | fi |
| 32 | |
| 33 | [[ -x /usr/lib/qt6/moc && -f /usr/include/kwin/config-kwin.h ]] || { |
| 34 | echo 'KWin/Qt-ontwikkelbestanden ontbreken. Nodig op Arch: kwin qt6-base qt6-declarative.' >&2 |
| 35 | exit 1 |
| 36 | } |
| 37 | version=$(sed -n 's/^#define KWIN_PLUGIN_VERSION_STRING "\([^"]*\)"/\1/p' /usr/include/kwin/config-kwin.h) |
| 38 | [[ $version == 6.[78].* ]] || { echo "Deze versie ondersteunt KWin 6.7.x en 6.8.x; gevonden: $version" >&2; exit 1; } |
| 39 | # Probeert een kant-en-klare build uit een release voor precies deze kwin. |
| 40 | # Een KWin-effect gebruikt de interne KWin-API en moet per kwin-versie |
| 41 | # gebouwd worden; bij elke twijfel wordt er lokaal gebouwd. |
| 42 | download_release() { |
| 43 | command -v curl >/dev/null && command -v git >/dev/null && command -v pacman >/dev/null || return 1 |
| 44 | local tag tmp kwin_pkg qt_pkg |
| 45 | tag=$(git ls-remote --tags "$repo_url.git" 2>/dev/null | sed -n 's#.*refs/tags/\([^^]*\)$#\1#p' \ |
| 46 | | grep -E "^${version//./\\.}(-[0-9]+)?$" | sort -V | tail -n1) || return 1 |
| 47 | [[ -n $tag ]] || { echo "Geen release voor KWin $version; lokaal bouwen."; return 1; } |
| 48 | tmp=$(mktemp -d) |
| 49 | local base="$repo_url/-/releases/$tag/assets" |
| 50 | if ! curl -fsSL "$base/clicktween-x86_64.tar.gz" -o "$tmp/clicktween-x86_64.tar.gz" || |
| 51 | ! curl -fsSL "$base/clicktween-x86_64.tar.gz.sha256" -o "$tmp/clicktween-x86_64.tar.gz.sha256" || |
| 52 | ! (cd "$tmp" && sha256sum -c --quiet clicktween-x86_64.tar.gz.sha256) || |
| 53 | ! tar -C "$tmp" -xzf "$tmp/clicktween-x86_64.tar.gz" || |
| 54 | ! (cd "$tmp" && sha256sum -c --quiet SHA256SUMS); then |
| 55 | echo "Download of checksum van release $tag mislukt; lokaal bouwen."; rm -rf -- "$tmp"; return 1 |
| 56 | fi |
| 57 | kwin_pkg=$(sed -n 's/^kwin_pkg=//p' "$tmp/build-info.txt"); qt_pkg=$(sed -n 's/^qt6_base_pkg=//p' "$tmp/build-info.txt") |
| 58 | if [[ $kwin_pkg != "$(pacman -Q kwin | cut -d' ' -f2)" || $qt_pkg != "$(pacman -Q qt6-base | cut -d' ' -f2)" ]]; then |
| 59 | echo "Release $tag is gebouwd tegen kwin $kwin_pkg / qt6-base $qt_pkg; hier staat iets anders. Lokaal bouwen." |
| 60 | rm -rf -- "$tmp"; return 1 |
| 61 | fi |
| 62 | mkdir -p build |
| 63 | cp "$tmp/kwin_effect_clicktween.so" "$tmp/kwin_clicktween_config.so" build/ |
| 64 | rm -rf -- "$tmp" |
| 65 | echo "Release $tag gedownload voor KWin $version (checksums kloppen)." |
| 66 | } |
| 67 | |
| 68 | build_local() { |
| 69 | for tool in g++ pkg-config; do |
| 70 | command -v "$tool" >/dev/null || { echo "Ontbreekt: $tool. Installeer: sudo pacman -S --needed gcc pkgconf" >&2; exit 1; } |
| 71 | done |
| 72 | mkdir -p build |
| 73 | read -r -a qt_flags <<< "$(pkg-config --cflags Qt6Core Qt6Gui Qt6Quick Qt6DBus Qt6Widgets wayland-server epoxy libdrm)" |
| 74 | read -r -a qt_libs <<< "$(pkg-config --libs Qt6Core Qt6Gui Qt6Quick Qt6DBus Qt6Widgets wayland-server epoxy libdrm)" |
| 75 | includes=(-I/usr/include/kwin -I/usr/include/KF6/KCoreAddons -I/usr/include/KF6/KConfig -I/usr/include/KF6/KConfigCore -I/usr/include/KF6/KCMUtils -I/usr/include/KF6/KCMUtilsCore -I/usr/include/KF6/KWindowSystem -I. -Ibuild) |
| 76 | /usr/lib/qt6/moc "${qt_flags[@]}" "${includes[@]}" clicktween.cpp -o build/clicktween.moc |
| 77 | g++ -std=c++23 -O2 -Wall -Wextra -fPIC -shared -Wl,-z,defs \ |
| 78 | "${qt_flags[@]}" "${includes[@]}" clicktween.cpp -o build/kwin_effect_clicktween.so \ |
| 79 | -lkwin -lKF6CoreAddons -lKF6ConfigCore "${qt_libs[@]}" |
| 80 | /usr/lib/qt6/moc "${qt_flags[@]}" "${includes[@]}" clicktween_config.cpp -o build/clicktween_config.moc |
| 81 | g++ -std=c++23 -O2 -Wall -Wextra -fPIC -shared -Wl,-z,defs \ |
| 82 | "${qt_flags[@]}" "${includes[@]}" clicktween_config.cpp -o build/kwin_clicktween_config.so \ |
| 83 | -lKF6KCMUtils -lKF6KCMUtilsCore -lKF6CoreAddons -lKF6ConfigCore "${qt_libs[@]}" |
| 84 | g++ -std=c++17 -fPIC "${qt_flags[@]}" check-plugin.cpp -o build/check-plugin "${qt_libs[@]}" |
| 85 | build/check-plugin "$PWD/build/kwin_effect_clicktween.so" |
| 86 | /usr/lib/qt6/moc "${qt_flags[@]}" check-config.cpp -o build/check-config.moc |
| 87 | g++ -std=c++23 -fPIC "${qt_flags[@]}" "${includes[@]}" check-config.cpp -o build/check-config \ |
| 88 | -lKF6KCMUtils -lKF6KCMUtilsCore -lKF6CoreAddons -lKF6ConfigCore "${qt_libs[@]}" |
| 89 | # Isolate configuration and D-Bus so the check cannot change the live desktop. |
| 90 | test_config=$(mktemp -d) |
| 91 | QT_QPA_PLATFORM=offscreen XDG_CONFIG_HOME="$test_config" \ |
| 92 | dbus-run-session -- build/check-config "$PWD/build/kwin_clicktween_config.so" |
| 93 | rm -rf -- "$test_config" |
| 94 | echo "Gebouwd voor KWin $version; instellingenmodule en 31 curves gecontroleerd." |
| 95 | } |
| 96 | |
| 97 | if [[ $mode == --build-only || $from_source == true ]] || ! download_release; then |
| 98 | build_local |
| 99 | fi |
| 100 | |
| 101 | [[ $mode != --build-only ]] || exit 0 |
| 102 | |
| 103 | # Obtain credentials before touching the running effect. |
| 104 | sudo -v |
| 105 | |
| 106 | # Qt keeps native plugin libraries resident (PreventUnloadHint). Recreating |
| 107 | # the effect does not reload updated machine code. Leave the running effect |
| 108 | # alone and replace files atomically; an upgrade requires a new KWin session. |
| 109 | upgrading=false |
| 110 | [[ ! -f "$plugin_file" ]] || upgrading=true |
| 111 | sudo install -Dm755 build/kwin_effect_clicktween.so "$plugin_file.new" |
| 112 | sudo mv -f -- "$plugin_file.new" "$plugin_file" |
| 113 | sudo install -Dm755 build/kwin_clicktween_config.so "$config_file.new" |
| 114 | sudo mv -f -- "$config_file.new" "$config_file" |
| 115 | # Animation defaults are compiled from settings.h (150 ms / easeOutBack, |
| 116 | # 720 ms / easeOutElastic). Existing user settings take precedence. |
| 117 | kwriteconfig6 --file kwinrc --group Plugins --key kwin_effect_clicktweenEnabled true |
| 118 | # Also activate on reinstall, but never unload an already running instance. |
| 119 | if result=$(qdbus6 org.kde.KWin /Effects org.kde.kwin.Effects.isEffectLoaded kwin_effect_clicktween 2>/dev/null) && [[ $result == true ]]; then |
| 120 | echo 'Click Tween is geïnstalleerd en actief.' |
| 121 | elif result=$(qdbus6 org.kde.KWin /Effects org.kde.kwin.Effects.loadEffect kwin_effect_clicktween 2>/dev/null) && [[ $result == true ]]; then |
| 122 | echo 'Click Tween is geïnstalleerd en actief.' |
| 123 | else |
| 124 | echo 'Geïnstalleerd en ingeschakeld. Meld af en opnieuw aan om het effect te laden.' |
| 125 | fi |
| 126 | if [[ $upgrading == true ]]; then |
| 127 | echo 'Update geïnstalleerd. Meld één keer af en opnieuw aan om de nieuwe plugincode te laden.' |
| 128 | echo 'Uit-/aanvinken of Systeeminstellingen heropenen vervangt de code in KWin niet.' |
| 129 | fi |