| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | cd -- "$(dirname -- "${BASH_SOURCE[0]}")" |
| 4 | |
| 5 | mode=${1:-install} |
| 6 | case "$mode" in |
| 7 | install|--build-only|--uninstall) ;; |
| 8 | *) echo "Gebruik: $0 [--build-only|--uninstall]" >&2; exit 2 ;; |
| 9 | esac |
| 10 | if [[ $mode != --build-only ]]; then |
| 11 | [[ $EUID -ne 0 ]] || { echo 'Start dit script als gewone gebruiker, zonder sudo ervoor.' >&2; exit 1; } |
| 12 | for tool in sudo kwriteconfig6 qdbus6; do |
| 13 | command -v "$tool" >/dev/null || { echo "Ontbreekt: $tool" >&2; exit 1; } |
| 14 | done |
| 15 | fi |
| 16 | |
| 17 | # This build intentionally targets Arch's Plasma 6.7 layout and private API. |
| 18 | plugin_dir=/usr/lib/qt6/plugins/kwin/effects/plugins |
| 19 | plugin_file=$plugin_dir/kwin_effect_clicktween.so |
| 20 | config_file=/usr/lib/qt6/plugins/kwin/effects/configs/kwin_clicktween_config.so |
| 21 | if [[ $mode == --uninstall ]]; then |
| 22 | kwriteconfig6 --file kwinrc --group Plugins --key kwin_effect_clicktweenEnabled false |
| 23 | qdbus6 org.kde.KWin /Effects org.kde.kwin.Effects.unloadEffect kwin_effect_clicktween || true |
| 24 | sudo rm -f -- "$plugin_file" "$config_file" |
| 25 | echo 'Click Tween verwijderd. Bij een D-Bus-fout: meld opnieuw aan.' |
| 26 | exit 0 |
| 27 | fi |
| 28 | |
| 29 | for tool in g++ pkg-config; do |
| 30 | command -v "$tool" >/dev/null || { echo "Ontbreekt: $tool. Installeer: sudo pacman -S --needed gcc pkgconf" >&2; exit 1; } |
| 31 | done |
| 32 | [[ -x /usr/lib/qt6/moc && -f /usr/include/kwin/config-kwin.h ]] || { |
| 33 | echo 'KWin/Qt-ontwikkelbestanden ontbreken. Nodig op Arch: kwin qt6-base qt6-declarative.' >&2 |
| 34 | exit 1 |
| 35 | } |
| 36 | version=$(sed -n 's/^#define KWIN_PLUGIN_VERSION_STRING "\([^"]*\)"/\1/p' /usr/include/kwin/config-kwin.h) |
| 37 | [[ $version == 6.[78].* ]] || { echo "Deze versie ondersteunt KWin 6.7.x en 6.8.x; gevonden: $version" >&2; exit 1; } |
| 38 | mkdir -p build |
| 39 | read -r -a qt_flags <<< "$(pkg-config --cflags Qt6Core Qt6Gui Qt6Quick Qt6DBus Qt6Widgets wayland-server epoxy libdrm)" |
| 40 | read -r -a qt_libs <<< "$(pkg-config --libs Qt6Core Qt6Gui Qt6Quick Qt6DBus Qt6Widgets wayland-server epoxy libdrm)" |
| 41 | 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) |
| 42 | /usr/lib/qt6/moc "${qt_flags[@]}" "${includes[@]}" clicktween.cpp -o build/clicktween.moc |
| 43 | g++ -std=c++23 -O2 -Wall -Wextra -fPIC -shared -Wl,-z,defs \ |
| 44 | "${qt_flags[@]}" "${includes[@]}" clicktween.cpp -o build/kwin_effect_clicktween.so \ |
| 45 | -lkwin -lKF6CoreAddons -lKF6ConfigCore "${qt_libs[@]}" |
| 46 | /usr/lib/qt6/moc "${qt_flags[@]}" "${includes[@]}" clicktween_config.cpp -o build/clicktween_config.moc |
| 47 | g++ -std=c++23 -O2 -Wall -Wextra -fPIC -shared -Wl,-z,defs \ |
| 48 | "${qt_flags[@]}" "${includes[@]}" clicktween_config.cpp -o build/kwin_clicktween_config.so \ |
| 49 | -lKF6KCMUtils -lKF6KCMUtilsCore -lKF6CoreAddons -lKF6ConfigCore "${qt_libs[@]}" |
| 50 | g++ -std=c++17 -fPIC "${qt_flags[@]}" check-plugin.cpp -o build/check-plugin "${qt_libs[@]}" |
| 51 | build/check-plugin "$PWD/build/kwin_effect_clicktween.so" |
| 52 | /usr/lib/qt6/moc "${qt_flags[@]}" check-config.cpp -o build/check-config.moc |
| 53 | g++ -std=c++23 -fPIC "${qt_flags[@]}" "${includes[@]}" check-config.cpp -o build/check-config \ |
| 54 | -lKF6KCMUtils -lKF6KCMUtilsCore -lKF6CoreAddons -lKF6ConfigCore "${qt_libs[@]}" |
| 55 | # Isolate configuration and D-Bus so the check cannot change the live desktop. |
| 56 | test_config=$(mktemp -d) |
| 57 | QT_QPA_PLATFORM=offscreen XDG_CONFIG_HOME="$test_config" \ |
| 58 | dbus-run-session -- build/check-config "$PWD/build/kwin_clicktween_config.so" |
| 59 | rm -rf -- "$test_config" |
| 60 | echo "Gebouwd voor KWin $version; instellingenmodule en 31 curves gecontroleerd." |
| 61 | [[ $mode != --build-only ]] || exit 0 |
| 62 | |
| 63 | # Obtain credentials before touching the running effect. |
| 64 | sudo -v |
| 65 | |
| 66 | # Qt keeps native plugin libraries resident (PreventUnloadHint). Recreating |
| 67 | # the effect does not reload updated machine code. Leave the running effect |
| 68 | # alone and replace files atomically; an upgrade requires a new KWin session. |
| 69 | upgrading=false |
| 70 | [[ ! -f "$plugin_file" ]] || upgrading=true |
| 71 | sudo install -Dm755 build/kwin_effect_clicktween.so "$plugin_file.new" |
| 72 | sudo mv -f -- "$plugin_file.new" "$plugin_file" |
| 73 | sudo install -Dm755 build/kwin_clicktween_config.so "$config_file.new" |
| 74 | sudo mv -f -- "$config_file.new" "$config_file" |
| 75 | # Animation defaults are compiled from settings.h (150 ms / easeOutBack, |
| 76 | # 720 ms / easeOutElastic). Existing user settings take precedence. |
| 77 | kwriteconfig6 --file kwinrc --group Plugins --key kwin_effect_clicktweenEnabled true |
| 78 | # Also activate on reinstall, but never unload an already running instance. |
| 79 | if result=$(qdbus6 org.kde.KWin /Effects org.kde.kwin.Effects.isEffectLoaded kwin_effect_clicktween 2>/dev/null) && [[ $result == true ]]; then |
| 80 | echo 'Click Tween is geïnstalleerd en actief.' |
| 81 | elif result=$(qdbus6 org.kde.KWin /Effects org.kde.kwin.Effects.loadEffect kwin_effect_clicktween 2>/dev/null) && [[ $result == true ]]; then |
| 82 | echo 'Click Tween is geïnstalleerd en actief.' |
| 83 | else |
| 84 | echo 'Geïnstalleerd en ingeschakeld. Meld af en opnieuw aan om het effect te laden.' |
| 85 | fi |
| 86 | if [[ $upgrading == true ]]; then |
| 87 | echo 'Update geïnstalleerd. Meld één keer af en opnieuw aan om de nieuwe plugincode te laden.' |
| 88 | echo 'Uit-/aanvinken of Systeeminstellingen heropenen vervangt de code in KWin niet.' |
| 89 | fi |