diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index b0ca175..b3fca03 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -17,6 +17,7 @@ jobs: - name: Checkout prepare script uses: actions/checkout@v4 with: + fetch-depth: 1 sparse-checkout: prepare.sh sparse-checkout-cone-mode: false @@ -34,3 +35,31 @@ jobs: - name: Check README.md run: tools/is-clean --make --root=doc README.md + + test: + needs: build + strategy: + matrix: + kind: [ "system", "user" ] + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Prepare build environment + run: ./prepare.sh -us | tee -a "$GITHUB_ENV" + + - name: Install (${{ matrix.kind }}) + run: | + if [ "${{ matrix.kind }}" = "user" ]; then + ./install.sh -u + elif [ "${{ matrix.kind }}" = "system" ]; then + SUDO=sudo ./install.sh -s + else + exit 1 + fi + + - name: Run tests + run: ./tests.sh diff --git a/data/displayswitcheroo/list.lua b/data/displayswitcheroo/list.lua index 06fe711..cd358cd 100644 --- a/data/displayswitcheroo/list.lua +++ b/data/displayswitcheroo/list.lua @@ -15,38 +15,48 @@ for n, o in pairs(setup.outputs) do local c = o.crtc local geom = c and string.format(" %dx%d+%d+%d", c.width, c.height, c.x, c.y) or "" - print(string.format("output %s:%s%s (%dmm x %dmm) (fpr 0x%x)", n, pri, geom, o.mmwidth, o.mmheight, o.fingerprint)) + + local str = string.format("output %s:%s%s", n, pri, geom) + if o.mmwidth and o.mmheight then + str = str .. string.format(" (%dmm x %dmm)", o.mmwidth, o.mmheight) + end + if o.fingerprint then + str = str .. string.format(" (fpr 0x%x)", o.fingerprint) + end + print(str) local s, w, h for _, m in ipairs(o.modes) do - local flags = "" - if m.interlace then - flags = flags .. "i" - end + if m.refresh_rate then + local flags = "" + if m.interlace then + flags = flags .. "i" + end - if m.double_scan then - flags = flags .. "d" - end + if m.double_scan then + flags = flags .. "d" + end - if o.modes:is_preferred(m) then - flags = flags .. "+" - end + if o.modes:is_preferred(m) then + flags = flags .. "+" + end - if c and m == c.mode then - flags = flags .. "*" - end + if c and m == c.mode then + flags = flags .. "*" + end - local t = string.format(" %.2f%s", m.refresh_rate, flags) + local t = string.format(" %.2f%s", m.refresh_rate, flags) - if w == m.width and h == m.height then - s = s .. t - else - if s then - print(s) + if w == m.width and h == m.height then + s = s .. t + else + if s then + print(s) + end + w = m.width + h = m.height + s = string.format(" %dx%d%s", w, h, t) end - w = m.width - h = m.height - s = string.format(" %dx%d%s", w, h, t) end end if s then diff --git a/install.sh b/install.sh index 3c082f1..ff82a88 100755 --- a/install.sh +++ b/install.sh @@ -17,13 +17,15 @@ EOF exit "${1-0}" } +SUDO=${SUDO-} DESTDIR=${DESTDIR-$HOME/.local} +DIR_MODE=0700 APP=${APP-displayswitcheroo} while getopts "dusah-" OPT; do case $OPT in d) DESTDIR=$OPTARG ;; - u) DESTDIR=$HOME/.local ;; - s) DESTDIR=/usr ;; + u) DESTDIR=$HOME/.local; DIR_MODE=0700;; + s) DESTDIR=/usr; DIR_MODE=0755 ;; a) APP=$OPTARG ;; h) usage ;; -) break ;; @@ -34,9 +36,10 @@ shift $((OPTIND-1)) make -C "$SCRIPT_DIR" clean build EXTRA_CFLAGS="-DXDG_APP='\"$APP\"'" -mkdir -pm 0700 "$DESTDIR/bin" -install -v "$SCRIPT_DIR/src/cli.exe" "$DESTDIR/bin/$APP" -mkdir -pm 0700 "$DESTDIR/share/$APP" -install -v -D "$SCRIPT_DIR/data/displayswitcheroo/list.lua" "$DESTDIR/share/$APP/list.lua" -install -v -D "$SCRIPT_DIR/data/displayswitcheroo/displayswitcheroo.lua" "$DESTDIR/share/$APP/$APP.lua" +$SUDO mkdir -pm "$DIR_MODE" "$DESTDIR/bin" +$SUDO install -v "$SCRIPT_DIR/src/cli.exe" "$DESTDIR/bin/$APP" + +$SUDO mkdir -pm "$DIR_MODE" "$DESTDIR/share/$APP" +$SUDO install -v -D "$SCRIPT_DIR/data/displayswitcheroo/list.lua" "$DESTDIR/share/$APP/list.lua" +$SUDO install -v -D "$SCRIPT_DIR/data/displayswitcheroo/displayswitcheroo.lua" "$DESTDIR/share/$APP/$APP.lua" diff --git a/prepare.sh b/prepare.sh index 237b806..4c5fee6 100755 --- a/prepare.sh +++ b/prepare.sh @@ -5,12 +5,14 @@ set -o nounset -o pipefail -o errexit SUDO=${SUDO-} DISTRO=${DISTRO-} UPDATE=${UPDATE-} -while getopts "ud:sS:-" OPT; do +TESTS=${TESTS-} +while getopts "ud:sS:t-" OPT; do case $OPT in d) DISTRO=$OPTARG ;; u) UPDATE=1 ;; s) SUDO=sudo ;; S) SUDO=$OPTARG ;; + t) TESTS=1 ;; -) break ;; ?) usage 2 ;; esac @@ -18,7 +20,7 @@ done shift $((OPTIND-1)) if [ -z "$DISTRO" ]; then - if command -v lsb_release; then + if command -v lsb_release >/dev/null; then DISTRO=$(lsb_release -is) elif command -v pacman >/dev/null; then DISTRO="Arch" @@ -36,21 +38,28 @@ if [ "$DISTRO" = "Arch" ] || command -v pacman >/dev/null; then if [ -n "$UPDATE" ]; then $SUDO pacman -Sy 1>&2 fi - $SUDO pacman -S --noconfirm 1>&2 \ - git \ - make gcc pkgconf \ - python gawk \ - lua libxrandr + PKGs=(git) + PKGs+=(make gcc pkgconf) + PKGs+=(python gawk) + PKGs+=(lua libxrandr) + if [ -n "$TESTS" ]; then + PKGs+=(xorg-server-xvfb) + fi + $SUDO pacman -S --noconfirm "${PKGs[@]}" 1>&2 elif [ "$DISTRO" = "Ubuntu" ] || command -v apt-get >/dev/null; then if [ -n "$UPDATE" ]; then $SUDO apt-get update 1>&2 fi - $SUDO apt-get install --yes 1>&2 \ + PKGs=(git ca-certificates) + PKGs+=(make gcc pkg-config) + PKGs+=(python3 gawk) + PKGs+=(liblua5.4-dev libxrandr-dev) + if [ -n "$TESTS" ]; then + PKGs+=(xvfb) + fi + $SUDO apt-get install --yes \ --no-install-recommends --no-install-suggests \ - git ca-certificates \ - make gcc pkg-config \ - python3 gawk \ - liblua5.4-dev libxrandr-dev + 1>&2 "${PKGs[@]}" echo "LUA_PKG=lua54" else echo "unconfigured distribution: $DISTRO" 1>&2 diff --git a/src/.k b/src/.k index 59ca2ed..8ef666e 100644 --- a/src/.k +++ b/src/.k @@ -4,6 +4,11 @@ cli() { make LOG_LEVEL=DEBUG cli.exe && ./cli.exe "${1-list}" } +xvfb() { + make LOG_LEVEL=DEBUG cli.exe && xvfb-run ./cli.exe "$K_DIR/../data/displayswitcheroo/list.lua" +} + + watch() { make LOG_LEVEL=DEBUG cli.exe && ./cli.exe -w go.lua } diff --git a/tests.sh b/tests.sh new file mode 100755 index 0000000..711f11a --- /dev/null +++ b/tests.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -o nounset -o pipefail -o errexit + +APP=${APP-displayswitcheroo} + +which "$APP" + +xvfb-run "$APP" list