Add niri-visual-tests
Browse files at this commit122afff7d10ac96250f428a3f06dca6288d3d0b8Parent: d2a4e6a12 changed files +1062 -7
- .github/workflows/ci.yml +30 -5
- Cargo.lock +236 -0
- Cargo.toml +7 -2
- niri-visual-tests/Cargo.toml +18 -0
- niri-visual-tests/README.md +14 -0
- niri-visual-tests/resources/style.css +3 -0
- niri-visual-tests/src/cases/mod.rs +21 -0
- niri-visual-tests/src/cases/tile.rs +83 -0
- niri-visual-tests/src/cases/window.rs +57 -0
- niri-visual-tests/src/main.rs +142 -0
- niri-visual-tests/src/smithay_view.rs +245 -0
- niri-visual-tests/src/test_window.rs +206 -0
.github/workflows/ci.ymlmodified+30 -5
| @@ -52,10 +52,35 @@ jobs: | |||
| 52 | run: cargo build ${{ matrix.release-flag }} --features profile-with-tracy | 52 | run: cargo build ${{ matrix.release-flag }} --features profile-with-tracy |
| 53 | 53 | ||
| 54 | - name: Build Tests | 54 | - name: Build Tests |
| 55 | - run: cargo test --no-run --all ${{ matrix.release-flag }} | 55 | + run: cargo test --no-run --all --exclude niri-visual-tests ${{ matrix.release-flag }} |
| 56 | 56 | ||
| 57 | - name: Test | 57 | - name: Test |
| 58 | - run: cargo test --all ${{ matrix.release-flag }} -- --nocapture | 58 | + run: cargo test --all --exclude niri-visual-tests ${{ matrix.release-flag }} -- --nocapture |
| 59 | + | ||
| 60 | + visual-tests: | ||
| 61 | + strategy: | ||
| 62 | + fail-fast: false | ||
| 63 | + | ||
| 64 | + name: visual tests | ||
| 65 | + runs-on: ubuntu-22.04 | ||
| 66 | + container: ubuntu:23.10 | ||
| 67 | + | ||
| 68 | + steps: | ||
| 69 | + - uses: actions/checkout@v4 | ||
| 70 | + with: | ||
| 71 | + show-progress: false | ||
| 72 | + | ||
| 73 | + - name: Install dependencies | ||
| 74 | + run: | | ||
| 75 | + apt-get update -y | ||
| 76 | + apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev libadwaita-1-dev | ||
| 77 | + | ||
| 78 | + - uses: dtolnay/rust-toolchain@stable | ||
| 79 | + | ||
| 80 | + - uses: Swatinem/rust-cache@v2 | ||
| 81 | + | ||
| 82 | + - name: Build | ||
| 83 | + run: cargo build --package niri-visual-tests | ||
| 59 | 84 | ||
| 60 | clippy: | 85 | clippy: |
| 61 | strategy: | 86 | strategy: |
| @@ -73,7 +98,7 @@ jobs: | |||
| 73 | - name: Install dependencies | 98 | - name: Install dependencies |
| 74 | run: | | 99 | run: | |
| 75 | apt-get update -y | 100 | apt-get update -y |
| 76 | - apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev | 101 | + apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev libadwaita-1-dev |
| 77 | 102 | ||
| 78 | - uses: dtolnay/rust-toolchain@stable | 103 | - uses: dtolnay/rust-toolchain@stable |
| 79 | with: | 104 | with: |
| @@ -113,8 +138,8 @@ jobs: | |||
| 113 | - name: Install dependencies | 138 | - name: Install dependencies |
| 114 | run: | | 139 | run: | |
| 115 | sudo dnf update -y | 140 | sudo dnf update -y |
| 116 | - sudo dnf install -y cargo gcc libudev-devel libgbm-devel libxkbcommon-devel wayland-devel libinput-devel dbus-devel systemd-devel libseat-devel pipewire-devel pango-devel cairo-gobject-devel clang | 141 | + sudo dnf install -y cargo gcc libudev-devel libgbm-devel libxkbcommon-devel wayland-devel libinput-devel dbus-devel systemd-devel libseat-devel pipewire-devel pango-devel cairo-gobject-devel clang libadwaita-devel |
| 117 | 142 | ||
| 118 | - uses: Swatinem/rust-cache@v2 | 143 | - uses: Swatinem/rust-cache@v2 |
| 119 | - - run: cargo build | 144 | + - run: cargo build --all |
| 120 | 145 | ||
Cargo.lockmodified+236 -0
| @@ -994,6 +994,16 @@ dependencies = [ | |||
| 994 | "simd-adler32", | 994 | "simd-adler32", |
| 995 | ] | 995 | ] |
| 996 | 996 | ||
| 997 | +[[package]] | ||
| 998 | +name = "field-offset" | ||
| 999 | +version = "0.3.6" | ||
| 1000 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1001 | +checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" | ||
| 1002 | +dependencies = [ | ||
| 1003 | + "memoffset 0.9.0", | ||
| 1004 | + "rustc_version", | ||
| 1005 | +] | ||
| 1006 | + | ||
| 997 | [[package]] | 1007 | [[package]] |
| 998 | name = "flate2" | 1008 | name = "flate2" |
| 999 | version = "1.0.28" | 1009 | version = "1.0.28" |
| @@ -1170,6 +1180,63 @@ dependencies = [ | |||
| 1170 | "libc", | 1180 | "libc", |
| 1171 | ] | 1181 | ] |
| 1172 | 1182 | ||
| 1183 | +[[package]] | ||
| 1184 | +name = "gdk-pixbuf" | ||
| 1185 | +version = "0.19.0" | ||
| 1186 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1187 | +checksum = "c311c47800051b87de1335e8792774d7cec551c91a0a3d109ab21d76b36f208f" | ||
| 1188 | +dependencies = [ | ||
| 1189 | + "gdk-pixbuf-sys", | ||
| 1190 | + "gio", | ||
| 1191 | + "glib", | ||
| 1192 | + "libc", | ||
| 1193 | +] | ||
| 1194 | + | ||
| 1195 | +[[package]] | ||
| 1196 | +name = "gdk-pixbuf-sys" | ||
| 1197 | +version = "0.19.0" | ||
| 1198 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1199 | +checksum = "3dcbd04c1b2c4834cc008b4828bc917d062483b88d26effde6342e5622028f96" | ||
| 1200 | +dependencies = [ | ||
| 1201 | + "gio-sys", | ||
| 1202 | + "glib-sys", | ||
| 1203 | + "gobject-sys", | ||
| 1204 | + "libc", | ||
| 1205 | + "system-deps", | ||
| 1206 | +] | ||
| 1207 | + | ||
| 1208 | +[[package]] | ||
| 1209 | +name = "gdk4" | ||
| 1210 | +version = "0.8.0" | ||
| 1211 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1212 | +checksum = "6771942f85a2beaa220c64739395e4401b9fab4a52aba9b503fa1e6ed4d4d806" | ||
| 1213 | +dependencies = [ | ||
| 1214 | + "cairo-rs", | ||
| 1215 | + "gdk-pixbuf", | ||
| 1216 | + "gdk4-sys", | ||
| 1217 | + "gio", | ||
| 1218 | + "glib", | ||
| 1219 | + "libc", | ||
| 1220 | + "pango", | ||
| 1221 | +] | ||
| 1222 | + | ||
| 1223 | +[[package]] | ||
| 1224 | +name = "gdk4-sys" | ||
| 1225 | +version = "0.8.0" | ||
| 1226 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1227 | +checksum = "1eb95854fab65072023a7814434f003db571d6e45c287c0b0c540c1c78bdf6ae" | ||
| 1228 | +dependencies = [ | ||
| 1229 | + "cairo-sys-rs", | ||
| 1230 | + "gdk-pixbuf-sys", | ||
| 1231 | + "gio-sys", | ||
| 1232 | + "glib-sys", | ||
| 1233 | + "gobject-sys", | ||
| 1234 | + "libc", | ||
| 1235 | + "pango-sys", | ||
| 1236 | + "pkg-config", | ||
| 1237 | + "system-deps", | ||
| 1238 | +] | ||
| 1239 | + | ||
| 1173 | [[package]] | 1240 | [[package]] |
| 1174 | name = "generator" | 1241 | name = "generator" |
| 1175 | version = "0.7.5" | 1242 | version = "0.7.5" |
| @@ -1338,6 +1405,114 @@ dependencies = [ | |||
| 1338 | "system-deps", | 1405 | "system-deps", |
| 1339 | ] | 1406 | ] |
| 1340 | 1407 | ||
| 1408 | +[[package]] | ||
| 1409 | +name = "graphene-rs" | ||
| 1410 | +version = "0.19.0" | ||
| 1411 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1412 | +checksum = "147827e4f506f8073ac3ec5b28cc2255bdf3abc30f5b4e101a80506eebe11d2c" | ||
| 1413 | +dependencies = [ | ||
| 1414 | + "glib", | ||
| 1415 | + "graphene-sys", | ||
| 1416 | + "libc", | ||
| 1417 | +] | ||
| 1418 | + | ||
| 1419 | +[[package]] | ||
| 1420 | +name = "graphene-sys" | ||
| 1421 | +version = "0.19.0" | ||
| 1422 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1423 | +checksum = "236ed66cc9b18d8adf233716f75de803d0bf6fc806f60d14d948974a12e240d0" | ||
| 1424 | +dependencies = [ | ||
| 1425 | + "glib-sys", | ||
| 1426 | + "libc", | ||
| 1427 | + "pkg-config", | ||
| 1428 | + "system-deps", | ||
| 1429 | +] | ||
| 1430 | + | ||
| 1431 | +[[package]] | ||
| 1432 | +name = "gsk4" | ||
| 1433 | +version = "0.8.0" | ||
| 1434 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1435 | +checksum = "0e8ce8dee0fd87a11002214b1204ff18c9272fbd530408f0884a0f9b25dc31de" | ||
| 1436 | +dependencies = [ | ||
| 1437 | + "cairo-rs", | ||
| 1438 | + "gdk4", | ||
| 1439 | + "glib", | ||
| 1440 | + "graphene-rs", | ||
| 1441 | + "gsk4-sys", | ||
| 1442 | + "libc", | ||
| 1443 | + "pango", | ||
| 1444 | +] | ||
| 1445 | + | ||
| 1446 | +[[package]] | ||
| 1447 | +name = "gsk4-sys" | ||
| 1448 | +version = "0.8.0" | ||
| 1449 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1450 | +checksum = "2660a652da5b662d43924df19ba40d73f015ed427329ef51d2b1360a4e0dc0e4" | ||
| 1451 | +dependencies = [ | ||
| 1452 | + "cairo-sys-rs", | ||
| 1453 | + "gdk4-sys", | ||
| 1454 | + "glib-sys", | ||
| 1455 | + "gobject-sys", | ||
| 1456 | + "graphene-sys", | ||
| 1457 | + "libc", | ||
| 1458 | + "pango-sys", | ||
| 1459 | + "system-deps", | ||
| 1460 | +] | ||
| 1461 | + | ||
| 1462 | +[[package]] | ||
| 1463 | +name = "gtk4" | ||
| 1464 | +version = "0.8.0" | ||
| 1465 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1466 | +checksum = "7d26ffa3ec6316ccaa1df62d3e7f5bae1637c0acbb43f250fabef38319f73c64" | ||
| 1467 | +dependencies = [ | ||
| 1468 | + "cairo-rs", | ||
| 1469 | + "field-offset", | ||
| 1470 | + "futures-channel", | ||
| 1471 | + "gdk-pixbuf", | ||
| 1472 | + "gdk4", | ||
| 1473 | + "gio", | ||
| 1474 | + "glib", | ||
| 1475 | + "graphene-rs", | ||
| 1476 | + "gsk4", | ||
| 1477 | + "gtk4-macros", | ||
| 1478 | + "gtk4-sys", | ||
| 1479 | + "libc", | ||
| 1480 | + "pango", | ||
| 1481 | +] | ||
| 1482 | + | ||
| 1483 | +[[package]] | ||
| 1484 | +name = "gtk4-macros" | ||
| 1485 | +version = "0.8.0" | ||
| 1486 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1487 | +checksum = "c8b86439e9896f6f3f47c3d8077c5c8205174078760afdabd9098a8e9e937d97" | ||
| 1488 | +dependencies = [ | ||
| 1489 | + "anyhow", | ||
| 1490 | + "proc-macro-crate 3.1.0", | ||
| 1491 | + "proc-macro-error", | ||
| 1492 | + "proc-macro2", | ||
| 1493 | + "quote", | ||
| 1494 | + "syn 1.0.109", | ||
| 1495 | +] | ||
| 1496 | + | ||
| 1497 | +[[package]] | ||
| 1498 | +name = "gtk4-sys" | ||
| 1499 | +version = "0.8.0" | ||
| 1500 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1501 | +checksum = "2abc0a6d356d59a3806021829ce6ed3e70bba3509b41a535fedcb09fae13fbc0" | ||
| 1502 | +dependencies = [ | ||
| 1503 | + "cairo-sys-rs", | ||
| 1504 | + "gdk-pixbuf-sys", | ||
| 1505 | + "gdk4-sys", | ||
| 1506 | + "gio-sys", | ||
| 1507 | + "glib-sys", | ||
| 1508 | + "gobject-sys", | ||
| 1509 | + "graphene-sys", | ||
| 1510 | + "gsk4-sys", | ||
| 1511 | + "libc", | ||
| 1512 | + "pango-sys", | ||
| 1513 | + "system-deps", | ||
| 1514 | +] | ||
| 1515 | + | ||
| 1341 | [[package]] | 1516 | [[package]] |
| 1342 | name = "hashbrown" | 1517 | name = "hashbrown" |
| 1343 | version = "0.14.3" | 1518 | version = "0.14.3" |
| @@ -1545,6 +1720,38 @@ version = "1.3.0" | |||
| 1545 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1720 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1546 | checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" | 1721 | checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" |
| 1547 | 1722 | ||
| 1723 | +[[package]] | ||
| 1724 | +name = "libadwaita" | ||
| 1725 | +version = "0.6.0" | ||
| 1726 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1727 | +checksum = "91b4990248b9e1ec5e72094a2ccaea70ec3809f88f6fd52192f2af306b87c5d9" | ||
| 1728 | +dependencies = [ | ||
| 1729 | + "gdk-pixbuf", | ||
| 1730 | + "gdk4", | ||
| 1731 | + "gio", | ||
| 1732 | + "glib", | ||
| 1733 | + "gtk4", | ||
| 1734 | + "libadwaita-sys", | ||
| 1735 | + "libc", | ||
| 1736 | + "pango", | ||
| 1737 | +] | ||
| 1738 | + | ||
| 1739 | +[[package]] | ||
| 1740 | +name = "libadwaita-sys" | ||
| 1741 | +version = "0.6.0" | ||
| 1742 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1743 | +checksum = "23a748e4e92be1265cd9e93d569c0b5dfc7814107985aa6743d670ab281ea1a8" | ||
| 1744 | +dependencies = [ | ||
| 1745 | + "gdk4-sys", | ||
| 1746 | + "gio-sys", | ||
| 1747 | + "glib-sys", | ||
| 1748 | + "gobject-sys", | ||
| 1749 | + "gtk4-sys", | ||
| 1750 | + "libc", | ||
| 1751 | + "pango-sys", | ||
| 1752 | + "system-deps", | ||
| 1753 | +] | ||
| 1754 | + | ||
| 1548 | [[package]] | 1755 | [[package]] |
| 1549 | name = "libc" | 1756 | name = "libc" |
| 1550 | version = "0.2.153" | 1757 | version = "0.2.153" |
| @@ -1896,6 +2103,20 @@ dependencies = [ | |||
| 1896 | "serde", | 2103 | "serde", |
| 1897 | ] | 2104 | ] |
| 1898 | 2105 | ||
| 2106 | +[[package]] | ||
| 2107 | +name = "niri-visual-tests" | ||
| 2108 | +version = "0.1.1" | ||
| 2109 | +dependencies = [ | ||
| 2110 | + "anyhow", | ||
| 2111 | + "gtk4", | ||
| 2112 | + "libadwaita", | ||
| 2113 | + "niri", | ||
| 2114 | + "niri-config", | ||
| 2115 | + "smithay", | ||
| 2116 | + "tracing", | ||
| 2117 | + "tracing-subscriber", | ||
| 2118 | +] | ||
| 2119 | + | ||
| 1899 | [[package]] | 2120 | [[package]] |
| 1900 | name = "nix" | 2121 | name = "nix" |
| 1901 | version = "0.26.4" | 2122 | version = "0.26.4" |
| @@ -2537,6 +2758,15 @@ version = "1.1.0" | |||
| 2537 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2758 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2538 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" | 2759 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" |
| 2539 | 2760 | ||
| 2761 | +[[package]] | ||
| 2762 | +name = "rustc_version" | ||
| 2763 | +version = "0.4.0" | ||
| 2764 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2765 | +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" | ||
| 2766 | +dependencies = [ | ||
| 2767 | + "semver", | ||
| 2768 | +] | ||
| 2769 | + | ||
| 2540 | [[package]] | 2770 | [[package]] |
| 2541 | name = "rustix" | 2771 | name = "rustix" |
| 2542 | version = "0.37.27" | 2772 | version = "0.37.27" |
| @@ -2615,6 +2845,12 @@ version = "0.4.1" | |||
| 2615 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2845 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2616 | checksum = "621e3680f3e07db4c9c2c3fb07c6223ab2fab2e54bd3c04c3ae037990f428c32" | 2846 | checksum = "621e3680f3e07db4c9c2c3fb07c6223ab2fab2e54bd3c04c3ae037990f428c32" |
| 2617 | 2847 | ||
| 2848 | +[[package]] | ||
| 2849 | +name = "semver" | ||
| 2850 | +version = "1.0.21" | ||
| 2851 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2852 | +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" | ||
| 2853 | + | ||
| 2618 | [[package]] | 2854 | [[package]] |
| 2619 | name = "serde" | 2855 | name = "serde" |
| 2620 | version = "1.0.196" | 2856 | version = "1.0.196" |
Cargo.tomlmodified+7 -2
| @@ -1,3 +1,6 @@ | |||
| 1 | +[workspace] | ||
| 2 | +members = ["niri-visual-tests"] | ||
| 3 | + | ||
| 1 | [workspace.package] | 4 | [workspace.package] |
| 2 | version = "0.1.1" | 5 | version = "0.1.1" |
| 3 | description = "A scrollable-tiling Wayland compositor" | 6 | description = "A scrollable-tiling Wayland compositor" |
| @@ -7,10 +10,12 @@ edition = "2021" | |||
| 7 | repository = "https://github.com/YaLTeR/niri" | 10 | repository = "https://github.com/YaLTeR/niri" |
| 8 | 11 | ||
| 9 | [workspace.dependencies] | 12 | [workspace.dependencies] |
| 13 | +anyhow = "1.0.79" | ||
| 10 | bitflags = "2.4.2" | 14 | bitflags = "2.4.2" |
| 11 | directories = "5.0.1" | 15 | directories = "5.0.1" |
| 12 | serde = { version = "1.0.196", features = ["derive"] } | 16 | serde = { version = "1.0.196", features = ["derive"] } |
| 13 | tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] } | 17 | tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] } |
| 18 | +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } | ||
| 14 | tracy-client = { version = "0.16.5", default-features = false } | 19 | tracy-client = { version = "0.16.5", default-features = false } |
| 15 | 20 | ||
| 16 | [workspace.dependencies.smithay] | 21 | [workspace.dependencies.smithay] |
| @@ -35,7 +40,7 @@ readme = "README.md" | |||
| 35 | keywords = ["wayland", "compositor", "tiling", "smithay", "wm"] | 40 | keywords = ["wayland", "compositor", "tiling", "smithay", "wm"] |
| 36 | 41 | ||
| 37 | [dependencies] | 42 | [dependencies] |
| 38 | -anyhow = { version = "1.0.79" } | 43 | +anyhow.workspace = true |
| 39 | arrayvec = "0.7.4" | 44 | arrayvec = "0.7.4" |
| 40 | async-channel = { version = "2.1.1", optional = true } | 45 | async-channel = { version = "2.1.1", optional = true } |
| 41 | async-io = { version = "1.13.0", optional = true } | 46 | async-io = { version = "1.13.0", optional = true } |
| @@ -61,7 +66,7 @@ sd-notify = "0.4.1" | |||
| 61 | serde.workspace = true | 66 | serde.workspace = true |
| 62 | serde_json = "1.0.113" | 67 | serde_json = "1.0.113" |
| 63 | smithay-drm-extras.workspace = true | 68 | smithay-drm-extras.workspace = true |
| 64 | -tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } | 69 | +tracing-subscriber.workspace = true |
| 65 | tracing.workspace = true | 70 | tracing.workspace = true |
| 66 | tracy-client.workspace = true | 71 | tracy-client.workspace = true |
| 67 | url = { version = "2.5.0", optional = true } | 72 | url = { version = "2.5.0", optional = true } |
niri-visual-tests/Cargo.tomladded+18 -0
| @@ -0,0 +1,18 @@ | |||
| 1 | +[package] | ||
| 2 | +name = "niri-visual-tests" | ||
| 3 | +version.workspace = true | ||
| 4 | +description.workspace = true | ||
| 5 | +authors.workspace = true | ||
| 6 | +license.workspace = true | ||
| 7 | +edition.workspace = true | ||
| 8 | +repository.workspace = true | ||
| 9 | + | ||
| 10 | +[dependencies] | ||
| 11 | +adw = { version = "0.6.0", package = "libadwaita", features = ["v1_4"] } | ||
| 12 | +anyhow.workspace = true | ||
| 13 | +gtk = { version = "0.8.0", package = "gtk4", features = ["v4_12"] } | ||
| 14 | +niri = { version = "0.1.1", path = ".." } | ||
| 15 | +niri-config = { version = "0.1.1", path = "../niri-config" } | ||
| 16 | +smithay.workspace = true | ||
| 17 | +tracing.workspace = true | ||
| 18 | +tracing-subscriber.workspace = true | ||
niri-visual-tests/README.mdadded+14 -0
| @@ -0,0 +1,14 @@ | |||
| 1 | +# niri-visual-tests | ||
| 2 | + | ||
| 3 | +> [!NOTE] | ||
| 4 | +> | ||
| 5 | +> This is a development-only app, you shouldn't package it. | ||
| 6 | + | ||
| 7 | +This app contains a number of hard-coded test scenarios for visual inspection. | ||
| 8 | +It uses the real niri layout and rendering code, but with mock windows instead of Wayland clients. | ||
| 9 | +The idea is to go through the test scenarios and check that everything *looks* right. | ||
| 10 | + | ||
| 11 | +## Running | ||
| 12 | + | ||
| 13 | +You will need recent GTK and libadwaita. | ||
| 14 | +Then, `cargo run`. | ||
niri-visual-tests/resources/style.cssadded+3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | +.anim-control-bar { | ||
| 2 | + padding: 12px; | ||
| 3 | +} | ||
niri-visual-tests/src/cases/mod.rsadded+21 -0
| @@ -0,0 +1,21 @@ | |||
| 1 | +use std::time::Duration; | ||
| 2 | + | ||
| 3 | +use smithay::backend::renderer::element::RenderElement; | ||
| 4 | +use smithay::backend::renderer::gles::GlesRenderer; | ||
| 5 | +use smithay::utils::{Physical, Size}; | ||
| 6 | + | ||
| 7 | +pub mod tile; | ||
| 8 | +pub mod window; | ||
| 9 | + | ||
| 10 | +pub trait TestCase { | ||
| 11 | + fn resize(&mut self, width: i32, height: i32); | ||
| 12 | + fn are_animations_ongoing(&self) -> bool { | ||
| 13 | + false | ||
| 14 | + } | ||
| 15 | + fn advance_animations(&mut self, _current_time: Duration) {} | ||
| 16 | + fn render( | ||
| 17 | + &mut self, | ||
| 18 | + renderer: &mut GlesRenderer, | ||
| 19 | + size: Size<i32, Physical>, | ||
| 20 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>>; | ||
| 21 | +} | ||
niri-visual-tests/src/cases/tile.rsadded+83 -0
| @@ -0,0 +1,83 @@ | |||
| 1 | +use std::rc::Rc; | ||
| 2 | +use std::time::Duration; | ||
| 3 | + | ||
| 4 | +use niri::layout::tile::Tile; | ||
| 5 | +use niri::layout::Options; | ||
| 6 | +use niri_config::Color; | ||
| 7 | +use smithay::backend::renderer::element::RenderElement; | ||
| 8 | +use smithay::backend::renderer::gles::GlesRenderer; | ||
| 9 | +use smithay::utils::{Logical, Physical, Point, Scale, Size}; | ||
| 10 | + | ||
| 11 | +use super::TestCase; | ||
| 12 | +use crate::test_window::TestWindow; | ||
| 13 | + | ||
| 14 | +pub struct JustTile { | ||
| 15 | + window: TestWindow, | ||
| 16 | + tile: Tile<TestWindow>, | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +impl JustTile { | ||
| 20 | + pub fn freeform(size: Size<i32, Logical>) -> Self { | ||
| 21 | + let window = TestWindow::freeform(0); | ||
| 22 | + let mut rv = Self::with_window(window); | ||
| 23 | + rv.tile.request_tile_size(size); | ||
| 24 | + rv.window.communicate(); | ||
| 25 | + rv | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + pub fn fixed_size(size: Size<i32, Logical>) -> Self { | ||
| 29 | + let window = TestWindow::fixed_size(0); | ||
| 30 | + let mut rv = Self::with_window(window); | ||
| 31 | + rv.tile.request_tile_size(size); | ||
| 32 | + rv.window.communicate(); | ||
| 33 | + rv | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + pub fn fixed_size_with_csd_shadow(size: Size<i32, Logical>) -> Self { | ||
| 37 | + let window = TestWindow::fixed_size(0); | ||
| 38 | + window.set_csd_shadow_width(64); | ||
| 39 | + let mut rv = Self::with_window(window); | ||
| 40 | + rv.tile.request_tile_size(size); | ||
| 41 | + rv.window.communicate(); | ||
| 42 | + rv | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + pub fn with_window(window: TestWindow) -> Self { | ||
| 46 | + let options = Options { | ||
| 47 | + border: niri_config::FocusRing { | ||
| 48 | + off: false, | ||
| 49 | + width: 32, | ||
| 50 | + active_color: Color::new(255, 163, 72, 255), | ||
| 51 | + ..Default::default() | ||
| 52 | + }, | ||
| 53 | + ..Default::default() | ||
| 54 | + }; | ||
| 55 | + let tile = Tile::new(window.clone(), Rc::new(options)); | ||
| 56 | + Self { window, tile } | ||
| 57 | + } | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +impl TestCase for JustTile { | ||
| 61 | + fn resize(&mut self, width: i32, height: i32) { | ||
| 62 | + self.tile.request_tile_size(Size::from((width, height))); | ||
| 63 | + self.window.communicate(); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + fn advance_animations(&mut self, current_time: Duration) { | ||
| 67 | + self.tile.advance_animations(current_time, true); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + fn render( | ||
| 71 | + &mut self, | ||
| 72 | + renderer: &mut GlesRenderer, | ||
| 73 | + size: Size<i32, Physical>, | ||
| 74 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | ||
| 75 | + let tile_size = self.tile.tile_size().to_physical(1); | ||
| 76 | + let location = Point::from(((size.w - tile_size.w) / 2, (size.h - tile_size.h) / 2)); | ||
| 77 | + | ||
| 78 | + self.tile | ||
| 79 | + .render(renderer, location, Scale::from(1.)) | ||
| 80 | + .map(|elem| Box::new(elem) as _) | ||
| 81 | + .collect() | ||
| 82 | + } | ||
| 83 | +} | ||
niri-visual-tests/src/cases/window.rsadded+57 -0
| @@ -0,0 +1,57 @@ | |||
| 1 | +use niri::layout::LayoutElement; | ||
| 2 | +use smithay::backend::renderer::element::RenderElement; | ||
| 3 | +use smithay::backend::renderer::gles::GlesRenderer; | ||
| 4 | +use smithay::utils::{Logical, Physical, Point, Scale, Size}; | ||
| 5 | + | ||
| 6 | +use super::TestCase; | ||
| 7 | +use crate::test_window::TestWindow; | ||
| 8 | + | ||
| 9 | +pub struct JustWindow { | ||
| 10 | + window: TestWindow, | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +impl JustWindow { | ||
| 14 | + pub fn freeform(size: Size<i32, Logical>) -> Self { | ||
| 15 | + let window = TestWindow::freeform(0); | ||
| 16 | + window.request_size(size); | ||
| 17 | + window.communicate(); | ||
| 18 | + Self { window } | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + pub fn fixed_size(size: Size<i32, Logical>) -> Self { | ||
| 22 | + let window = TestWindow::fixed_size(0); | ||
| 23 | + window.request_size(size); | ||
| 24 | + window.communicate(); | ||
| 25 | + Self { window } | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + pub fn fixed_size_with_csd_shadow(size: Size<i32, Logical>) -> Self { | ||
| 29 | + let window = TestWindow::fixed_size(0); | ||
| 30 | + window.set_csd_shadow_width(64); | ||
| 31 | + window.request_size(size); | ||
| 32 | + window.communicate(); | ||
| 33 | + Self { window } | ||
| 34 | + } | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +impl TestCase for JustWindow { | ||
| 38 | + fn resize(&mut self, width: i32, height: i32) { | ||
| 39 | + self.window.request_size(Size::from((width, height))); | ||
| 40 | + self.window.communicate(); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + fn render( | ||
| 44 | + &mut self, | ||
| 45 | + renderer: &mut GlesRenderer, | ||
| 46 | + size: Size<i32, Physical>, | ||
| 47 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | ||
| 48 | + let win_size = self.window.size().to_physical(1); | ||
| 49 | + let location = Point::from(((size.w - win_size.w) / 2, (size.h - win_size.h) / 2)); | ||
| 50 | + | ||
| 51 | + self.window | ||
| 52 | + .render(renderer, location, Scale::from(1.)) | ||
| 53 | + .into_iter() | ||
| 54 | + .map(|elem| Box::new(elem) as _) | ||
| 55 | + .collect() | ||
| 56 | + } | ||
| 57 | +} | ||
niri-visual-tests/src/main.rsadded+142 -0
| @@ -0,0 +1,142 @@ | |||
| 1 | +#[macro_use] | ||
| 2 | +extern crate tracing; | ||
| 3 | + | ||
| 4 | +use std::env; | ||
| 5 | +use std::sync::atomic::Ordering; | ||
| 6 | + | ||
| 7 | +use adw::prelude::{AdwApplicationWindowExt, NavigationPageExt}; | ||
| 8 | +use cases::tile::JustTile; | ||
| 9 | +use cases::window::JustWindow; | ||
| 10 | +use gtk::prelude::{ | ||
| 11 | + AdjustmentExt, ApplicationExt, ApplicationExtManual, BoxExt, GtkWindowExt, WidgetExt, | ||
| 12 | +}; | ||
| 13 | +use gtk::{gdk, gio, glib}; | ||
| 14 | +use niri::animation::ANIMATION_SLOWDOWN; | ||
| 15 | +use smithay::utils::{Logical, Size}; | ||
| 16 | +use smithay_view::SmithayView; | ||
| 17 | +use tracing_subscriber::EnvFilter; | ||
| 18 | + | ||
| 19 | +use crate::cases::TestCase; | ||
| 20 | + | ||
| 21 | +mod cases; | ||
| 22 | +mod smithay_view; | ||
| 23 | +mod test_window; | ||
| 24 | + | ||
| 25 | +fn main() -> glib::ExitCode { | ||
| 26 | + let directives = | ||
| 27 | + env::var("RUST_LOG").unwrap_or_else(|_| "niri-visual-tests=debug,niri=debug".to_owned()); | ||
| 28 | + let env_filter = EnvFilter::builder().parse_lossy(directives); | ||
| 29 | + tracing_subscriber::fmt() | ||
| 30 | + .compact() | ||
| 31 | + .with_env_filter(env_filter) | ||
| 32 | + .init(); | ||
| 33 | + | ||
| 34 | + let app = adw::Application::new(None::<&str>, gio::ApplicationFlags::NON_UNIQUE); | ||
| 35 | + app.connect_startup(on_startup); | ||
| 36 | + app.connect_activate(build_ui); | ||
| 37 | + app.run() | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +fn on_startup(_app: &adw::Application) { | ||
| 41 | + // Load our CSS. | ||
| 42 | + let provider = gtk::CssProvider::new(); | ||
| 43 | + provider.load_from_string(include_str!("../resources/style.css")); | ||
| 44 | + if let Some(display) = gdk::Display::default() { | ||
| 45 | + gtk::style_context_add_provider_for_display( | ||
| 46 | + &display, | ||
| 47 | + &provider, | ||
| 48 | + gtk::STYLE_PROVIDER_PRIORITY_APPLICATION, | ||
| 49 | + ); | ||
| 50 | + } | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +fn build_ui(app: &adw::Application) { | ||
| 54 | + let stack = gtk::Stack::new(); | ||
| 55 | + | ||
| 56 | + struct S { | ||
| 57 | + stack: gtk::Stack, | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + impl S { | ||
| 61 | + fn add<T: TestCase + 'static>( | ||
| 62 | + &self, | ||
| 63 | + make: impl Fn(Size<i32, Logical>) -> T + 'static, | ||
| 64 | + title: &str, | ||
| 65 | + ) { | ||
| 66 | + let view = SmithayView::new(make); | ||
| 67 | + self.stack.add_titled(&view, None, title); | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + let s = S { | ||
| 72 | + stack: stack.clone(), | ||
| 73 | + }; | ||
| 74 | + | ||
| 75 | + s.add(JustWindow::freeform, "Freeform Window"); | ||
| 76 | + s.add(JustWindow::fixed_size, "Fixed Size Window"); | ||
| 77 | + s.add( | ||
| 78 | + JustWindow::fixed_size_with_csd_shadow, | ||
| 79 | + "Fixed Size Window - CSD Shadow", | ||
| 80 | + ); | ||
| 81 | + s.add(JustTile::freeform, "Freeform Tile"); | ||
| 82 | + s.add(JustTile::fixed_size, "Fixed Size Tile"); | ||
| 83 | + s.add( | ||
| 84 | + JustTile::fixed_size_with_csd_shadow, | ||
| 85 | + "Fixed Size Tile - CSD Shadow", | ||
| 86 | + ); | ||
| 87 | + | ||
| 88 | + let content_headerbar = adw::HeaderBar::new(); | ||
| 89 | + | ||
| 90 | + let anim_adjustment = gtk::Adjustment::new(1., 0., 10., 0.1, 0.5, 0.); | ||
| 91 | + anim_adjustment | ||
| 92 | + .connect_value_changed(|adj| ANIMATION_SLOWDOWN.store(adj.value(), Ordering::SeqCst)); | ||
| 93 | + let anim_scale = gtk::Scale::new(gtk::Orientation::Horizontal, Some(&anim_adjustment)); | ||
| 94 | + anim_scale.set_hexpand(true); | ||
| 95 | + | ||
| 96 | + let anim_control_bar = gtk::Box::new(gtk::Orientation::Horizontal, 6); | ||
| 97 | + anim_control_bar.add_css_class("anim-control-bar"); | ||
| 98 | + anim_control_bar.append(>k::Label::new(Some("Slowdown"))); | ||
| 99 | + anim_control_bar.append(&anim_scale); | ||
| 100 | + | ||
| 101 | + let content_view = adw::ToolbarView::new(); | ||
| 102 | + content_view.set_top_bar_style(adw::ToolbarStyle::RaisedBorder); | ||
| 103 | + content_view.set_bottom_bar_style(adw::ToolbarStyle::RaisedBorder); | ||
| 104 | + content_view.add_top_bar(&content_headerbar); | ||
| 105 | + content_view.add_bottom_bar(&anim_control_bar); | ||
| 106 | + content_view.set_content(Some(&stack)); | ||
| 107 | + let content = adw::NavigationPage::new( | ||
| 108 | + &content_view, | ||
| 109 | + stack | ||
| 110 | + .page(&stack.visible_child().unwrap()) | ||
| 111 | + .title() | ||
| 112 | + .as_deref() | ||
| 113 | + .unwrap(), | ||
| 114 | + ); | ||
| 115 | + | ||
| 116 | + let sidebar_header = adw::HeaderBar::new(); | ||
| 117 | + let stack_sidebar = gtk::StackSidebar::new(); | ||
| 118 | + stack_sidebar.set_stack(&stack); | ||
| 119 | + let sidebar_view = adw::ToolbarView::new(); | ||
| 120 | + sidebar_view.add_top_bar(&sidebar_header); | ||
| 121 | + sidebar_view.set_content(Some(&stack_sidebar)); | ||
| 122 | + let sidebar = adw::NavigationPage::new(&sidebar_view, "Tests"); | ||
| 123 | + | ||
| 124 | + let split_view = adw::NavigationSplitView::new(); | ||
| 125 | + split_view.set_content(Some(&content)); | ||
| 126 | + split_view.set_sidebar(Some(&sidebar)); | ||
| 127 | + | ||
| 128 | + stack.connect_visible_child_notify(move |stack| { | ||
| 129 | + content.set_title( | ||
| 130 | + stack | ||
| 131 | + .visible_child() | ||
| 132 | + .and_then(|c| stack.page(&c).title()) | ||
| 133 | + .as_deref() | ||
| 134 | + .unwrap_or_default(), | ||
| 135 | + ) | ||
| 136 | + }); | ||
| 137 | + | ||
| 138 | + let window = adw::ApplicationWindow::new(app); | ||
| 139 | + window.set_title(Some("niri visual tests")); | ||
| 140 | + window.set_content(Some(&split_view)); | ||
| 141 | + window.present(); | ||
| 142 | +} | ||
niri-visual-tests/src/smithay_view.rsadded+245 -0
| @@ -0,0 +1,245 @@ | |||
| 1 | +use gtk::glib; | ||
| 2 | +use gtk::subclass::prelude::*; | ||
| 3 | +use smithay::utils::{Logical, Size}; | ||
| 4 | + | ||
| 5 | +use crate::cases::TestCase; | ||
| 6 | + | ||
| 7 | +mod imp { | ||
| 8 | + use std::cell::{Cell, OnceCell, RefCell}; | ||
| 9 | + use std::ptr::null; | ||
| 10 | + | ||
| 11 | + use anyhow::{ensure, Context}; | ||
| 12 | + use gtk::gdk; | ||
| 13 | + use gtk::prelude::*; | ||
| 14 | + use niri::utils::get_monotonic_time; | ||
| 15 | + use smithay::backend::egl::ffi::egl; | ||
| 16 | + use smithay::backend::egl::EGLContext; | ||
| 17 | + use smithay::backend::renderer::gles::{Capability, GlesRenderer}; | ||
| 18 | + use smithay::backend::renderer::{Frame, Renderer, Unbind}; | ||
| 19 | + use smithay::utils::{Physical, Rectangle, Scale, Transform}; | ||
| 20 | + | ||
| 21 | + use super::*; | ||
| 22 | + | ||
| 23 | + type DynMakeTestCase = Box<dyn Fn(Size<i32, Logical>) -> Box<dyn TestCase>>; | ||
| 24 | + | ||
| 25 | + #[derive(Default)] | ||
| 26 | + pub struct SmithayView { | ||
| 27 | + gl_area: gtk::GLArea, | ||
| 28 | + size: Cell<(i32, i32)>, | ||
| 29 | + renderer: RefCell<Option<Result<GlesRenderer, ()>>>, | ||
| 30 | + pub make_test_case: OnceCell<DynMakeTestCase>, | ||
| 31 | + test_case: RefCell<Option<Box<dyn TestCase>>>, | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + #[glib::object_subclass] | ||
| 35 | + impl ObjectSubclass for SmithayView { | ||
| 36 | + const NAME: &'static str = "NiriSmithayView"; | ||
| 37 | + type Type = super::SmithayView; | ||
| 38 | + type ParentType = gtk::Widget; | ||
| 39 | + | ||
| 40 | + fn class_init(klass: &mut Self::Class) { | ||
| 41 | + klass.set_layout_manager_type::<gtk::BinLayout>(); | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + impl ObjectImpl for SmithayView { | ||
| 46 | + fn constructed(&self) { | ||
| 47 | + let obj = self.obj(); | ||
| 48 | + | ||
| 49 | + self.parent_constructed(); | ||
| 50 | + | ||
| 51 | + self.gl_area.set_allowed_apis(gdk::GLAPI::GLES); | ||
| 52 | + self.gl_area.set_parent(&*obj); | ||
| 53 | + | ||
| 54 | + self.gl_area.connect_resize({ | ||
| 55 | + let imp = self.downgrade(); | ||
| 56 | + move |_, width, height| { | ||
| 57 | + if let Some(imp) = imp.upgrade() { | ||
| 58 | + imp.resize(width, height); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + }); | ||
| 62 | + | ||
| 63 | + self.gl_area.connect_render({ | ||
| 64 | + let imp = self.downgrade(); | ||
| 65 | + move |_, gl_context| { | ||
| 66 | + if let Some(imp) = imp.upgrade() { | ||
| 67 | + if let Err(err) = imp.render(gl_context) { | ||
| 68 | + warn!("error rendering: {err:?}"); | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + glib::Propagation::Stop | ||
| 72 | + } | ||
| 73 | + }); | ||
| 74 | + | ||
| 75 | + obj.add_tick_callback(|obj, _frame_clock| { | ||
| 76 | + let imp = obj.imp(); | ||
| 77 | + | ||
| 78 | + if let Some(case) = &mut *imp.test_case.borrow_mut() { | ||
| 79 | + if case.are_animations_ongoing() { | ||
| 80 | + imp.gl_area.queue_draw(); | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + glib::ControlFlow::Continue | ||
| 85 | + }); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + fn dispose(&self) { | ||
| 89 | + self.gl_area.unparent(); | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + impl WidgetImpl for SmithayView { | ||
| 94 | + fn unmap(&self) { | ||
| 95 | + self.test_case.replace(None); | ||
| 96 | + self.parent_unmap(); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + fn unrealize(&self) { | ||
| 100 | + self.renderer.replace(None); | ||
| 101 | + self.parent_unrealize(); | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + impl SmithayView { | ||
| 106 | + fn resize(&self, width: i32, height: i32) { | ||
| 107 | + self.size.set((width, height)); | ||
| 108 | + | ||
| 109 | + if let Some(case) = &mut *self.test_case.borrow_mut() { | ||
| 110 | + case.resize(width, height); | ||
| 111 | + } | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + fn render(&self, _gl_context: &gdk::GLContext) -> anyhow::Result<()> { | ||
| 115 | + // Set up the Smithay renderer. | ||
| 116 | + let mut renderer = self.renderer.borrow_mut(); | ||
| 117 | + let renderer = renderer.get_or_insert_with(|| { | ||
| 118 | + unsafe { create_renderer() } | ||
| 119 | + .map_err(|err| warn!("error creating a Smithay renderer: {err:?}")) | ||
| 120 | + }); | ||
| 121 | + let Ok(renderer) = renderer else { | ||
| 122 | + return Ok(()); | ||
| 123 | + }; | ||
| 124 | + | ||
| 125 | + let size = self.size.get(); | ||
| 126 | + | ||
| 127 | + // Create the test case if missing. | ||
| 128 | + let mut case = self.test_case.borrow_mut(); | ||
| 129 | + let case = case.get_or_insert_with(|| { | ||
| 130 | + let make = self.make_test_case.get().unwrap(); | ||
| 131 | + make(Size::from(size)) | ||
| 132 | + }); | ||
| 133 | + | ||
| 134 | + case.advance_animations(get_monotonic_time()); | ||
| 135 | + | ||
| 136 | + let rect: Rectangle<i32, Physical> = Rectangle::from_loc_and_size((0, 0), size); | ||
| 137 | + | ||
| 138 | + let elements = unsafe { | ||
| 139 | + with_framebuffer_save_restore(renderer, |renderer| { | ||
| 140 | + case.render(renderer, Size::from(size)) | ||
| 141 | + }) | ||
| 142 | + }?; | ||
| 143 | + | ||
| 144 | + let mut frame = renderer | ||
| 145 | + .render(rect.size, Transform::Normal) | ||
| 146 | + .context("error creating frame")?; | ||
| 147 | + | ||
| 148 | + frame | ||
| 149 | + .clear([0.3, 0.3, 0.3, 1.], &[rect]) | ||
| 150 | + .context("error clearing")?; | ||
| 151 | + | ||
| 152 | + for element in elements.iter().rev() { | ||
| 153 | + let src = element.src(); | ||
| 154 | + let dst = element.geometry(Scale::from(1.)); | ||
| 155 | + | ||
| 156 | + if let Some(mut damage) = rect.intersection(dst) { | ||
| 157 | + damage.loc -= dst.loc; | ||
| 158 | + element | ||
| 159 | + .draw(&mut frame, src, dst, &[damage]) | ||
| 160 | + .context("error drawing element")?; | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + Ok(()) | ||
| 165 | + } | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + unsafe fn create_renderer() -> anyhow::Result<GlesRenderer> { | ||
| 169 | + smithay::backend::egl::ffi::make_sure_egl_is_loaded() | ||
| 170 | + .context("error loading EGL symbols in Smithay")?; | ||
| 171 | + | ||
| 172 | + let egl_display = egl::GetCurrentDisplay(); | ||
| 173 | + ensure!(egl_display != egl::NO_DISPLAY, "no current EGL display"); | ||
| 174 | + | ||
| 175 | + let egl_context = egl::GetCurrentContext(); | ||
| 176 | + ensure!(egl_context != egl::NO_CONTEXT, "no current EGL context"); | ||
| 177 | + | ||
| 178 | + // There's no config ID on the EGL context and there's no current EGL surface, but we don't | ||
| 179 | + // really use it anyway so just get some random one. | ||
| 180 | + let mut egl_config_id = null(); | ||
| 181 | + let mut num_configs = 0; | ||
| 182 | + let res = egl::GetConfigs(egl_display, &mut egl_config_id, 1, &mut num_configs); | ||
| 183 | + ensure!(res == egl::TRUE, "error choosing EGL config"); | ||
| 184 | + ensure!(num_configs != 0, "no EGL config"); | ||
| 185 | + | ||
| 186 | + let egl_context = EGLContext::from_raw(egl_display, egl_config_id as *const _, egl_context) | ||
| 187 | + .context("error creating EGL context")?; | ||
| 188 | + let capabilities = GlesRenderer::supported_capabilities(&egl_context) | ||
| 189 | + .context("error getting supported renderer capabilities")? | ||
| 190 | + .into_iter() | ||
| 191 | + .filter(|c| *c != Capability::ColorTransformations); | ||
| 192 | + | ||
| 193 | + GlesRenderer::with_capabilities(egl_context, capabilities) | ||
| 194 | + .context("error creating GlesRenderer") | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + unsafe fn with_framebuffer_save_restore<T>( | ||
| 198 | + renderer: &mut GlesRenderer, | ||
| 199 | + f: impl FnOnce(&mut GlesRenderer) -> T, | ||
| 200 | + ) -> anyhow::Result<T> { | ||
| 201 | + let mut framebuffer = 0; | ||
| 202 | + renderer | ||
| 203 | + .with_context(|gl| unsafe { | ||
| 204 | + gl.GetIntegerv( | ||
| 205 | + smithay::backend::renderer::gles::ffi::FRAMEBUFFER_BINDING, | ||
| 206 | + &mut framebuffer, | ||
| 207 | + ); | ||
| 208 | + }) | ||
| 209 | + .context("error running closure in GL context")?; | ||
| 210 | + ensure!(framebuffer != 0, "error getting the framebuffer"); | ||
| 211 | + | ||
| 212 | + let rv = f(renderer); | ||
| 213 | + | ||
| 214 | + renderer.unbind().context("error unbinding")?; | ||
| 215 | + renderer | ||
| 216 | + .with_context(|gl| unsafe { | ||
| 217 | + gl.BindFramebuffer( | ||
| 218 | + smithay::backend::renderer::gles::ffi::FRAMEBUFFER, | ||
| 219 | + framebuffer as u32, | ||
| 220 | + ); | ||
| 221 | + }) | ||
| 222 | + .context("error running closure in GL context")?; | ||
| 223 | + | ||
| 224 | + Ok(rv) | ||
| 225 | + } | ||
| 226 | +} | ||
| 227 | + | ||
| 228 | +glib::wrapper! { | ||
| 229 | + pub struct SmithayView(ObjectSubclass<imp::SmithayView>) | ||
| 230 | + @extends gtk::Widget; | ||
| 231 | +} | ||
| 232 | + | ||
| 233 | +impl SmithayView { | ||
| 234 | + pub fn new<T: TestCase + 'static>( | ||
| 235 | + make_test_case: impl Fn(Size<i32, Logical>) -> T + 'static, | ||
| 236 | + ) -> Self { | ||
| 237 | + let obj: Self = glib::Object::builder().build(); | ||
| 238 | + | ||
| 239 | + let make = move |size| Box::new(make_test_case(size)) as Box<dyn TestCase>; | ||
| 240 | + let make_test_case = Box::new(make) as _; | ||
| 241 | + let _ = obj.imp().make_test_case.set(make_test_case); | ||
| 242 | + | ||
| 243 | + obj | ||
| 244 | + } | ||
| 245 | +} | ||
niri-visual-tests/src/test_window.rsadded+206 -0
| @@ -0,0 +1,206 @@ | |||
| 1 | +use std::cell::RefCell; | ||
| 2 | +use std::cmp::{max, min}; | ||
| 3 | +use std::rc::Rc; | ||
| 4 | + | ||
| 5 | +use niri::layout::{LayoutElement, LayoutElementRenderElement}; | ||
| 6 | +use niri::render_helpers::NiriRenderer; | ||
| 7 | +use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement}; | ||
| 8 | +use smithay::backend::renderer::element::Kind; | ||
| 9 | +use smithay::output::Output; | ||
| 10 | +use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | ||
| 11 | +use smithay::utils::{Logical, Point, Scale, Size, Transform}; | ||
| 12 | + | ||
| 13 | +#[derive(Debug)] | ||
| 14 | +struct TestWindowInner { | ||
| 15 | + id: usize, | ||
| 16 | + size: Size<i32, Logical>, | ||
| 17 | + requested_size: Option<Size<i32, Logical>>, | ||
| 18 | + min_size: Size<i32, Logical>, | ||
| 19 | + max_size: Size<i32, Logical>, | ||
| 20 | + buffer: SolidColorBuffer, | ||
| 21 | + pending_fullscreen: bool, | ||
| 22 | + csd_shadow_width: i32, | ||
| 23 | + csd_shadow_buffer: SolidColorBuffer, | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +#[derive(Debug, Clone)] | ||
| 27 | +pub struct TestWindow(Rc<RefCell<TestWindowInner>>); | ||
| 28 | + | ||
| 29 | +impl TestWindow { | ||
| 30 | + pub fn freeform(id: usize) -> Self { | ||
| 31 | + let size = Size::from((100, 200)); | ||
| 32 | + let min_size = Size::from((0, 0)); | ||
| 33 | + let max_size = Size::from((0, 0)); | ||
| 34 | + let buffer = SolidColorBuffer::new(size, [0.15, 0.64, 0.41, 1.]); | ||
| 35 | + | ||
| 36 | + Self(Rc::new(RefCell::new(TestWindowInner { | ||
| 37 | + id, | ||
| 38 | + size, | ||
| 39 | + requested_size: None, | ||
| 40 | + min_size, | ||
| 41 | + max_size, | ||
| 42 | + buffer, | ||
| 43 | + pending_fullscreen: false, | ||
| 44 | + csd_shadow_width: 0, | ||
| 45 | + csd_shadow_buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.3]), | ||
| 46 | + }))) | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + pub fn fixed_size(id: usize) -> Self { | ||
| 50 | + let rv = Self::freeform(id); | ||
| 51 | + rv.set_min_size((200, 400).into()); | ||
| 52 | + rv.set_max_size((200, 400).into()); | ||
| 53 | + rv.set_color([0.88, 0.11, 0.14, 1.]); | ||
| 54 | + rv.communicate(); | ||
| 55 | + rv | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + pub fn set_min_size(&self, size: Size<i32, Logical>) { | ||
| 59 | + self.0.borrow_mut().min_size = size; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + pub fn set_max_size(&self, size: Size<i32, Logical>) { | ||
| 63 | + self.0.borrow_mut().max_size = size; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + pub fn set_color(&self, color: [f32; 4]) { | ||
| 67 | + self.0.borrow_mut().buffer.set_color(color); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + pub fn set_csd_shadow_width(&self, width: i32) { | ||
| 71 | + self.0.borrow_mut().csd_shadow_width = width; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + pub fn communicate(&self) -> bool { | ||
| 75 | + let mut rv = false; | ||
| 76 | + let mut inner = self.0.borrow_mut(); | ||
| 77 | + | ||
| 78 | + let mut new_size = inner.size; | ||
| 79 | + | ||
| 80 | + if let Some(size) = inner.requested_size.take() { | ||
| 81 | + assert!(size.w >= 0); | ||
| 82 | + assert!(size.h >= 0); | ||
| 83 | + | ||
| 84 | + if size.w != 0 { | ||
| 85 | + new_size.w = size.w; | ||
| 86 | + } | ||
| 87 | + if size.h != 0 { | ||
| 88 | + new_size.h = size.h; | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + if inner.max_size.w > 0 { | ||
| 93 | + new_size.w = min(new_size.w, inner.max_size.w); | ||
| 94 | + } | ||
| 95 | + if inner.max_size.h > 0 { | ||
| 96 | + new_size.h = min(new_size.h, inner.max_size.h); | ||
| 97 | + } | ||
| 98 | + if inner.min_size.w > 0 { | ||
| 99 | + new_size.w = max(new_size.w, inner.min_size.w); | ||
| 100 | + } | ||
| 101 | + if inner.min_size.h > 0 { | ||
| 102 | + new_size.h = max(new_size.h, inner.min_size.h); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + if inner.size != new_size { | ||
| 106 | + inner.size = new_size; | ||
| 107 | + inner.buffer.resize(new_size); | ||
| 108 | + rv = true; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + let mut csd_shadow_size = new_size; | ||
| 112 | + csd_shadow_size.w += inner.csd_shadow_width * 2; | ||
| 113 | + csd_shadow_size.h += inner.csd_shadow_width * 2; | ||
| 114 | + inner.csd_shadow_buffer.resize(csd_shadow_size); | ||
| 115 | + | ||
| 116 | + rv | ||
| 117 | + } | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +impl PartialEq for TestWindow { | ||
| 121 | + fn eq(&self, other: &Self) -> bool { | ||
| 122 | + self.0.borrow().id == other.0.borrow().id | ||
| 123 | + } | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +impl LayoutElement for TestWindow { | ||
| 127 | + fn size(&self) -> Size<i32, Logical> { | ||
| 128 | + self.0.borrow().size | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + fn buf_loc(&self) -> Point<i32, Logical> { | ||
| 132 | + (0, 0).into() | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + fn is_in_input_region(&self, _point: Point<f64, Logical>) -> bool { | ||
| 136 | + false | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + fn render<R: NiriRenderer>( | ||
| 140 | + &self, | ||
| 141 | + _renderer: &mut R, | ||
| 142 | + location: Point<i32, Logical>, | ||
| 143 | + scale: Scale<f64>, | ||
| 144 | + ) -> Vec<LayoutElementRenderElement<R>> { | ||
| 145 | + let inner = self.0.borrow(); | ||
| 146 | + | ||
| 147 | + vec![ | ||
| 148 | + SolidColorRenderElement::from_buffer( | ||
| 149 | + &inner.buffer, | ||
| 150 | + location.to_physical_precise_round(scale), | ||
| 151 | + scale, | ||
| 152 | + 1., | ||
| 153 | + Kind::Unspecified, | ||
| 154 | + ) | ||
| 155 | + .into(), | ||
| 156 | + SolidColorRenderElement::from_buffer( | ||
| 157 | + &inner.csd_shadow_buffer, | ||
| 158 | + (location - Point::from((inner.csd_shadow_width, inner.csd_shadow_width))) | ||
| 159 | + .to_physical_precise_round(scale), | ||
| 160 | + scale, | ||
| 161 | + 1., | ||
| 162 | + Kind::Unspecified, | ||
| 163 | + ) | ||
| 164 | + .into(), | ||
| 165 | + ] | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + fn request_size(&self, size: Size<i32, Logical>) { | ||
| 169 | + self.0.borrow_mut().requested_size = Some(size); | ||
| 170 | + self.0.borrow_mut().pending_fullscreen = false; | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + fn request_fullscreen(&self, _size: Size<i32, Logical>) { | ||
| 174 | + self.0.borrow_mut().pending_fullscreen = true; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + fn min_size(&self) -> Size<i32, Logical> { | ||
| 178 | + self.0.borrow().min_size | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + fn max_size(&self) -> Size<i32, Logical> { | ||
| 182 | + self.0.borrow().max_size | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + fn is_wl_surface(&self, _wl_surface: &WlSurface) -> bool { | ||
| 186 | + false | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + fn set_preferred_scale_transform(&self, _scale: i32, _transform: Transform) {} | ||
| 190 | + | ||
| 191 | + fn has_ssd(&self) -> bool { | ||
| 192 | + false | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + fn output_enter(&self, _output: &Output) {} | ||
| 196 | + | ||
| 197 | + fn output_leave(&self, _output: &Output) {} | ||
| 198 | + | ||
| 199 | + fn is_fullscreen(&self) -> bool { | ||
| 200 | + false | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + fn is_pending_fullscreen(&self) -> bool { | ||
| 204 | + self.0.borrow().pending_fullscreen | ||
| 205 | + } | ||
| 206 | +} | ||