Compare commits
1 Commits
camera-ite
...
openxr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ae20b23c5 |
1009
Cargo.lock
generated
1009
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
54
Cargo.toml
54
Cargo.toml
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
name = "stardust-xr-server"
|
name = "stardust-xr-server"
|
||||||
version = "0.43.0"
|
version = "0.42.1"
|
||||||
authors = ["Nova King <technobaboo@proton.me>"]
|
authors = ["Nova King <technobaboo@proton.me>"]
|
||||||
description = "Stardust XR reference display server"
|
description = "Stardust XR reference display server"
|
||||||
license = "GPLv2"
|
license = "GPLv2"
|
||||||
@@ -13,11 +13,12 @@ name = "stardust-xr-server"
|
|||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["wayland"]
|
default = ["wayland", "xwayland"]
|
||||||
|
openxr_runtime = []
|
||||||
wayland = ["dep:smithay", "dep:xkbcommon"]
|
wayland = ["dep:smithay", "dep:xkbcommon"]
|
||||||
xwayland = ["smithay/xwayland"]
|
xwayland = ["smithay/xwayland"]
|
||||||
profile_tokio = ["dep:console-subscriber", "tokio/tracing"]
|
profile_tokio = ["dep:console-subscriber", "tokio/tracing"]
|
||||||
profile_app = ["dep:tracing-tracy"]
|
profile_app = ["dep:tracing-chrome"]
|
||||||
|
|
||||||
[package.metadata.appimage]
|
[package.metadata.appimage]
|
||||||
auto_link = true
|
auto_link = true
|
||||||
@@ -39,6 +40,7 @@ lto = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
color-eyre = { version = "0.6.2", default-features = false }
|
color-eyre = { version = "0.6.2", default-features = false }
|
||||||
clap = { version = "4.2.4", features = ["derive"] }
|
clap = { version = "4.2.4", features = ["derive"] }
|
||||||
|
dashmap = "5.4.0"
|
||||||
glam = { version = "0.23.0", features = ["mint"] }
|
glam = { version = "0.23.0", features = ["mint"] }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
mint = "0.5.9"
|
mint = "0.5.9"
|
||||||
@@ -47,56 +49,46 @@ once_cell = "1.17.1"
|
|||||||
parking_lot = "0.12.1"
|
parking_lot = "0.12.1"
|
||||||
portable-atomic = { version = "1.2.0", features = ["float", "std"] }
|
portable-atomic = { version = "1.2.0", features = ["float", "std"] }
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
tokio = { version = "1.27.0", features = ["rt-multi-thread", "signal", "time"] }
|
tokio = { version = "1.27.0", features = ["rt-multi-thread", "signal"] }
|
||||||
send_wrapper = "0.6.0"
|
send_wrapper = "0.6.0"
|
||||||
prisma = "0.1.1"
|
prisma = "0.1.1"
|
||||||
|
xkbcommon = { version = "0.5.0", default-features = false, optional = true }
|
||||||
|
stardust-xr = "0.13.0"
|
||||||
directories = "5.0.0"
|
directories = "5.0.0"
|
||||||
serde = { version = "1.0.160", features = ["derive"] }
|
serde = { version = "1.0.160", features = ["derive"] }
|
||||||
serde_repr = "0.1.16"
|
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
|
||||||
global_counter = "0.2.2"
|
global_counter = "0.2.2"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
atty = "0.2.14"
|
atty = "0.2.14"
|
||||||
xkbcommon = { version = "0.6.0", default-features = false, optional = true }
|
|
||||||
ctrlc = "3.4.1"
|
|
||||||
libc = "0.2.148"
|
|
||||||
input-event-codes = "5.16.8"
|
|
||||||
drm-fourcc = { version = "2.2.0", features = ["serde"] }
|
|
||||||
|
|
||||||
[dependencies.smithay]
|
|
||||||
# git = "https://github.com/technobaboo/smithay.git" # Until we get stereokit to understand OES samplers and external textures
|
|
||||||
git = "https://github.com/smithay/smithay.git" # Until we get stereokit to understand OES samplers and external textures
|
|
||||||
# path = "../smithay"
|
|
||||||
default-features = false
|
|
||||||
features = [
|
|
||||||
"desktop",
|
|
||||||
"backend_drm",
|
|
||||||
"backend_egl",
|
|
||||||
"renderer_gl",
|
|
||||||
"wayland_frontend",
|
|
||||||
]
|
|
||||||
version = "*"
|
|
||||||
optional = true
|
|
||||||
|
|
||||||
[dependencies.stereokit]
|
[dependencies.stereokit]
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["linux-egl"]
|
features = ["linux-egl"]
|
||||||
version = "0.16.9"
|
version = "0.16.9"
|
||||||
|
|
||||||
|
[dependencies.smithay]
|
||||||
|
# git = "https://github.com/technobaboo/smithay.git" # Until we get stereokit to understand OES samplers and external textures
|
||||||
|
git = "https://github.com/smithay/smithay.git" # Until we get stereokit to understand OES samplers and external textures
|
||||||
|
# path = "../smithay"
|
||||||
|
default-features = false
|
||||||
|
features = ["desktop", "backend_drm", "renderer_gl", "wayland_frontend"]
|
||||||
|
version = "*"
|
||||||
|
optional = true
|
||||||
|
|
||||||
[dependencies.console-subscriber]
|
[dependencies.console-subscriber]
|
||||||
version = "0.1.8"
|
version = "0.1.8"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.tracing-tracy]
|
[dependencies.tracing-chrome]
|
||||||
version = "0.10.4"
|
version = "0.7.1"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.stardust-xr]
|
|
||||||
git = "https://github.com/StardustXR/core.git"
|
|
||||||
branch = "camera-item"
|
|
||||||
|
|
||||||
# [patch.crates-io.stereokit]
|
# [patch.crates-io.stereokit]
|
||||||
# path = "../stereokit-rs"
|
# path = "../stereokit-rs"
|
||||||
# [patch.crates-io.stereokit-sys]
|
# [patch.crates-io.stereokit-sys]
|
||||||
# path = "../stereokit-sys"
|
# path = "../stereokit-sys"
|
||||||
|
# [patch.crates-io.stardust-xr]
|
||||||
|
# path = "../core/core"
|
||||||
|
# [patch.crates-io.stardust-xr-schemas]
|
||||||
|
# path = "../core/schemas"
|
||||||
|
|||||||
260
flake.lock
generated
260
flake.lock
generated
@@ -3,11 +3,32 @@
|
|||||||
"fenix": {
|
"fenix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"flatland",
|
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
],
|
],
|
||||||
"rust-analyzer-src": "rust-analyzer-src"
|
"rust-analyzer-src": "rust-analyzer-src"
|
||||||
},
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1683786056,
|
||||||
|
"narHash": "sha256-Wrz/X9D0t8akhvEGj5a93xgpxI3vAcdPGcwn6tKHooc=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "fenix",
|
||||||
|
"rev": "5816c7bbcc385d2e65877631497df3f7d66b354a",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "fenix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fenix_2": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"flatland",
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"rust-analyzer-src": "rust-analyzer-src_2"
|
||||||
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1678775037,
|
"lastModified": 1678775037,
|
||||||
"narHash": "sha256-chx0tWnXKpcayPkPY3Qh+2hNwptvX8XE3o+fYZ+GNzg=",
|
"narHash": "sha256-chx0tWnXKpcayPkPY3Qh+2hNwptvX8XE3o+fYZ+GNzg=",
|
||||||
@@ -22,34 +43,32 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"flake-compat": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1673956053,
|
||||||
|
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
|
||||||
|
"owner": "edolstra",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "edolstra",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"flake-parts": {
|
"flake-parts": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs-lib": "nixpkgs-lib"
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1690933134,
|
"lastModified": 1678379998,
|
||||||
"narHash": "sha256-ab989mN63fQZBFrkk4Q8bYxQCktuHmBIBqUG1jl6/FQ=",
|
"narHash": "sha256-TZdfNqftHhDuIFwBcN9MUThx5sQXCTeZk9je5byPKRw=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "flake-parts",
|
"repo": "flake-parts",
|
||||||
"rev": "59cf3f1447cfc75087e7273b04b31e689a8599fb",
|
"rev": "c13d60b89adea3dc20704c045ec4d50dd964d447",
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "hercules-ci",
|
|
||||||
"repo": "flake-parts",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-parts_2": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs-lib": "nixpkgs-lib_2"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1688466019,
|
|
||||||
"narHash": "sha256-VeM2akYrBYMsb4W/MmBo1zmaMfgbL4cH3Pu8PGyIwJ0=",
|
|
||||||
"owner": "hercules-ci",
|
|
||||||
"repo": "flake-parts",
|
|
||||||
"rev": "8e8d955c22df93dbe24f19ea04f47a74adbdc5ec",
|
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -57,7 +76,7 @@
|
|||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"flake-parts_3": {
|
"flake-parts_2": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs-lib": [
|
"nixpkgs-lib": [
|
||||||
"hercules-ci-effects",
|
"hercules-ci-effects",
|
||||||
@@ -66,11 +85,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1688466019,
|
"lastModified": 1678379998,
|
||||||
"narHash": "sha256-VeM2akYrBYMsb4W/MmBo1zmaMfgbL4cH3Pu8PGyIwJ0=",
|
"narHash": "sha256-TZdfNqftHhDuIFwBcN9MUThx5sQXCTeZk9je5byPKRw=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "flake-parts",
|
"repo": "flake-parts",
|
||||||
"rev": "8e8d955c22df93dbe24f19ea04f47a74adbdc5ec",
|
"rev": "c13d60b89adea3dc20704c045ec4d50dd964d447",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -79,17 +98,32 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"flake-utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1667395993,
|
||||||
|
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"flatland": {
|
"flatland": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"fenix": "fenix",
|
"fenix": "fenix_2",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1694190588,
|
"lastModified": 1683766358,
|
||||||
"narHash": "sha256-tcvp09A54AbXkkXS/P6Ed5TUWzMEuQ9h/fnfLz7gnJc=",
|
"narHash": "sha256-wX1Lpj95kkHUZAloB1fGs+ixaRycaOJq4F77+HvaJCQ=",
|
||||||
"owner": "StardustXR",
|
"owner": "StardustXR",
|
||||||
"repo": "flatland",
|
"repo": "flatland",
|
||||||
"rev": "3867067452761959a95497d6589f9336b347270c",
|
"rev": "24613a496841bdf38e5f136608d5295860a75fce",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -98,34 +132,59 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"haskell-flake": {
|
"gitignore": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"hercules-ci-effects",
|
||||||
|
"hercules-ci-agent",
|
||||||
|
"pre-commit-hooks-nix",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1684780604,
|
"lastModified": 1660459072,
|
||||||
"narHash": "sha256-2uMZsewmRn7rRtAnnQNw1lj0uZBMh4m6Cs/7dV5YF08=",
|
"narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=",
|
||||||
"owner": "srid",
|
"owner": "hercules-ci",
|
||||||
"repo": "haskell-flake",
|
"repo": "gitignore.nix",
|
||||||
"rev": "74210fa80a49f1b6f67223debdbf1494596ff9f2",
|
"rev": "a20de23b925fd8264fd7fad6454652e142fd7f73",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "srid",
|
"owner": "hercules-ci",
|
||||||
"ref": "0.3.0",
|
"repo": "gitignore.nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"haskell-flake": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1678138103,
|
||||||
|
"narHash": "sha256-D0lao82bV3t2gEFjHiU6RN233t+1MnkQV+bq8MEu2ic=",
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "haskell-flake",
|
||||||
|
"rev": "1e1660e6dd00838ba73bc7952e6e73be67da18d1",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"ref": "0.1-extraLibraries",
|
||||||
"repo": "haskell-flake",
|
"repo": "haskell-flake",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hercules-ci-agent": {
|
"hercules-ci-agent": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-parts": "flake-parts_3",
|
"flake-parts": "flake-parts_2",
|
||||||
"haskell-flake": "haskell-flake",
|
"haskell-flake": "haskell-flake",
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nix-darwin": "nix-darwin",
|
||||||
|
"nixpkgs": "nixpkgs_2",
|
||||||
|
"pre-commit-hooks-nix": "pre-commit-hooks-nix"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1688568579,
|
"lastModified": 1678446614,
|
||||||
"narHash": "sha256-ON0M56wtY/TIIGPkXDlJboAmuYwc73Hi8X9iJGtxOhM=",
|
"narHash": "sha256-Z6Gsba5ahn/N0QlF0vJfIEfnZgCs4qr1IZtXAqjbE7s=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "hercules-ci-agent",
|
"repo": "hercules-ci-agent",
|
||||||
"rev": "367dd8cd649b57009a6502e878005a1e54ad78c5",
|
"rev": "0b90d1a87c117a5861785cb85833dd1c9df0b6ef",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -135,16 +194,16 @@
|
|||||||
},
|
},
|
||||||
"hercules-ci-effects": {
|
"hercules-ci-effects": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-parts": "flake-parts_2",
|
"flake-parts": "flake-parts",
|
||||||
"hercules-ci-agent": "hercules-ci-agent",
|
"hercules-ci-agent": "hercules-ci-agent",
|
||||||
"nixpkgs": "nixpkgs_3"
|
"nixpkgs": "nixpkgs_3"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1689397210,
|
"lastModified": 1681898675,
|
||||||
"narHash": "sha256-fVxZnqxMbsDkB4GzGAs/B41K0wt/e+B/fLxmTFF/S20=",
|
"narHash": "sha256-nIJ7CAdiHv4i1no/VgDoeTJLzbLYwu5+/Ycoyzn0S78=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "hercules-ci-effects",
|
"repo": "hercules-ci-effects",
|
||||||
"rev": "0a63bfa3f00a3775ea3a6722b247880f1ffe91ce",
|
"rev": "15ff4f63e5f28070391a5b09a82f6d5c6cc5c9d0",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -153,6 +212,28 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nix-darwin": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"hercules-ci-effects",
|
||||||
|
"hercules-ci-agent",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1673295039,
|
||||||
|
"narHash": "sha256-AsdYgE8/GPwcelGgrntlijMg4t3hLFJFCRF3tL5WVjA=",
|
||||||
|
"owner": "LnL7",
|
||||||
|
"repo": "nix-darwin",
|
||||||
|
"rev": "87b9d090ad39b25b2400029c64825fc2a8868943",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "LnL7",
|
||||||
|
"repo": "nix-darwin",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1678703398,
|
"lastModified": 1678703398,
|
||||||
@@ -172,11 +253,11 @@
|
|||||||
"nixpkgs-lib": {
|
"nixpkgs-lib": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
"lastModified": 1690881714,
|
"lastModified": 1678375444,
|
||||||
"narHash": "sha256-h/nXluEqdiQHs1oSgkOOWF+j8gcJMWhwnZ9PFabN6q0=",
|
"narHash": "sha256-XIgHfGvjFvZQ8hrkfocanCDxMefc/77rXeHvYdzBMc8=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "9e1960bc196baf6881340d53dccb203a951745a2",
|
"rev": "130fa0baaa2b93ec45523fdcde942f6844ee9f6e",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -187,31 +268,29 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs-lib_2": {
|
"nixpkgs-stable": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "lib",
|
"lastModified": 1673800717,
|
||||||
"lastModified": 1688049487,
|
"narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=",
|
||||||
"narHash": "sha256-100g4iaKC9MalDjUW9iN6Jl/OocTDtXdeAj7pEGIRh4=",
|
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "4bc72cae107788bf3f24f30db2e2f685c9298dc9",
|
"rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"dir": "lib",
|
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"ref": "nixos-unstable",
|
"ref": "nixos-22.11",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1688322751,
|
"lastModified": 1678293141,
|
||||||
"narHash": "sha256-eW62dC5f33oKZL7VWlomttbUnOTHrAbte9yNUNW8rbk=",
|
"narHash": "sha256-lLlQHaR0y+q6nd6kfpydPTGHhl1rS9nU9OQmztzKOYs=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "0fbe93c5a7cac99f90b60bdf5f149383daaa615f",
|
"rev": "c90c4025bb6e0c4eaf438128a3b2640314b1c58d",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -223,11 +302,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs_3": {
|
"nixpkgs_3": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1689393711,
|
"lastModified": 1678891326,
|
||||||
"narHash": "sha256-l3gyTPy/qWLDk1CY1EgYwlsxcGxN2aVd7MlCzQa69rk=",
|
"narHash": "sha256-cjgrjKx7y+hO9I8O2b6QvBaTt9w7Xhk/5hsnJYTUb2I=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "27fcd46fa18df36d270174246e7bd8f1787129ff",
|
"rev": "1544ef240132d4357d9a39a40c8e6afd1678b052",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -238,29 +317,72 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs_4": {
|
"nixpkgs_4": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1692734709,
|
"lastModified": 1683408522,
|
||||||
"narHash": "sha256-SCFnyHCyYjwEmgUsHDDuU0TsbVMKeU1vwkR+r7uS2Rg=",
|
"narHash": "sha256-9kcPh6Uxo17a3kK3XCHhcWiV1Yu1kYj22RHiymUhMkU=",
|
||||||
"owner": "nixos",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "b85ed9dcbf187b909ef7964774f8847d554fab3b",
|
"rev": "897876e4c484f1e8f92009fd11b7d988a121a4e7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nixos",
|
"owner": "NixOS",
|
||||||
"ref": "nixos-unstable",
|
"ref": "nixos-unstable",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"pre-commit-hooks-nix": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-compat": "flake-compat",
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"gitignore": "gitignore",
|
||||||
|
"nixpkgs": [
|
||||||
|
"hercules-ci-effects",
|
||||||
|
"hercules-ci-agent",
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"nixpkgs-stable": "nixpkgs-stable"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1678376203,
|
||||||
|
"narHash": "sha256-3tyYGyC8h7fBwncLZy5nCUjTJPrHbmNwp47LlNLOHSM=",
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "pre-commit-hooks.nix",
|
||||||
|
"rev": "1a20b9708962096ec2481eeb2ddca29ed747770a",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "pre-commit-hooks.nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-parts": "flake-parts",
|
"fenix": "fenix",
|
||||||
"flatland": "flatland",
|
"flatland": "flatland",
|
||||||
"hercules-ci-effects": "hercules-ci-effects",
|
"hercules-ci-effects": "hercules-ci-effects",
|
||||||
"nixpkgs": "nixpkgs_4"
|
"nixpkgs": "nixpkgs_4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rust-analyzer-src": {
|
"rust-analyzer-src": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1683653808,
|
||||||
|
"narHash": "sha256-GiKwJySG/YCPIKwz9wSm9fJa5e4CU3GvTYAKZzjBhFo=",
|
||||||
|
"owner": "rust-lang",
|
||||||
|
"repo": "rust-analyzer",
|
||||||
|
"rev": "b7cdd93f3e1533e96d4cfa1ac8573e6210a2bedf",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "rust-lang",
|
||||||
|
"ref": "nightly",
|
||||||
|
"repo": "rust-analyzer",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rust-analyzer-src_2": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1678695923,
|
"lastModified": 1678695923,
|
||||||
|
|||||||
183
flake.nix
183
flake.nix
@@ -3,77 +3,130 @@
|
|||||||
extra-substituters = [ "https://stardustxr.cachix.org" ];
|
extra-substituters = [ "https://stardustxr.cachix.org" ];
|
||||||
extra-trusted-public-keys = [ "stardustxr.cachix.org-1:mWSn8Ap2RLsIWT/8gsj+VfbJB6xoOkPaZpbjO+r9HBo=" ];
|
extra-trusted-public-keys = [ "stardustxr.cachix.org-1:mWSn8Ap2RLsIWT/8gsj+VfbJB6xoOkPaZpbjO+r9HBo=" ];
|
||||||
};
|
};
|
||||||
inputs = {
|
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
||||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
||||||
hercules-ci-effects.url = "github:hercules-ci/hercules-ci-effects";
|
|
||||||
|
|
||||||
# Since we do not have a monorepo, we have to fetch Flatland in order to use
|
# 22.11 does not include PR #218472, hence we use the unstable version
|
||||||
# it to create VM Tests
|
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;
|
||||||
flatland.url = "github:StardustXR/flatland";
|
|
||||||
};
|
# Since we do not have a monorepo, we have to fetch Flatland in order to use
|
||||||
outputs = inputs@{ self, flake-parts, nixpkgs, hercules-ci-effects, flatland, ... }:
|
# it to create VM Tests
|
||||||
|
inputs.flatland.url = "github:StardustXR/flatland";
|
||||||
|
|
||||||
|
inputs.fenix.url = github:nix-community/fenix;
|
||||||
|
inputs.fenix.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
||||||
|
inputs.hercules-ci-effects.url = "github:hercules-ci/hercules-ci-effects";
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, fenix, hercules-ci-effects, flatland, ... }:
|
||||||
let
|
let
|
||||||
name = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.name;
|
name = "server";
|
||||||
src = builtins.path {
|
pkgs = system: import nixpkgs {
|
||||||
name = "${name}-source";
|
inherit system;
|
||||||
path = toString ./.;
|
|
||||||
filter = path: type:
|
|
||||||
nixpkgs.lib.all
|
|
||||||
(n: builtins.baseNameOf path != n)
|
|
||||||
[
|
|
||||||
"flake.nix"
|
|
||||||
"flake.lock"
|
|
||||||
"nix"
|
|
||||||
"README.md"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
in
|
shell = pkgs: pkgs.mkShell {
|
||||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
inputsFrom = [ self.packages.${pkgs.system}.default ];
|
||||||
imports = [
|
|
||||||
flake-parts.flakeModules.easyOverlay
|
# ---- START package specific dev settings ----
|
||||||
];
|
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
|
||||||
systems = [ "aarch64-linux" "x86_64-linux" "riscv64-linux" ];
|
# ---- END package specific dev settings ----
|
||||||
perSystem = { config, self', inputs', pkgs, system, ... }: {
|
|
||||||
_module.args.pkgs = import inputs.nixpkgs { inherit system; overlays = [ inputs.self.overlays.default ]; };
|
|
||||||
overlayAttrs = config.packages;
|
|
||||||
packages = {
|
|
||||||
default = self'.packages.${name};
|
|
||||||
gnome-graphical-test = self'.checks.gnome-graphical-test;
|
|
||||||
"${name}" = pkgs.callPackage ./nix/stardust-xr-server.nix { inherit name src; };
|
|
||||||
};
|
|
||||||
checks.gnome-graphical-test = pkgs.nixosTest (import ./nix/gnome-graphical-test.nix { inherit pkgs self; });
|
|
||||||
devShells.default = pkgs.mkShell {
|
|
||||||
inputsFrom = [ self'.packages.default ];
|
|
||||||
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
flake = {
|
package = pkgs:
|
||||||
herculesCI.ciSystems = [ "x86_64-linux" ];
|
let
|
||||||
effects = let
|
toolchain = fenix.packages.${pkgs.system}.minimal.toolchain;
|
||||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
in
|
||||||
hci-effects = hercules-ci-effects.lib.withPkgs pkgs;
|
(pkgs.makeRustPlatform {
|
||||||
in { branch, rev, ... }: {
|
cargo = toolchain;
|
||||||
gnome-graphical-test = hci-effects.mkEffect {
|
rustc = toolchain;
|
||||||
secretsMap."stardustxrDiscord" = "stardustxrDiscord";
|
}).buildRustPackage rec {
|
||||||
secretsMap."stardustxrIpfs" = "stardustxrIpfs";
|
pname = "stardust-xr-${name}";
|
||||||
effectScript = ''
|
src = builtins.path {
|
||||||
readSecretString stardustxrDiscord .webhook > .webhook
|
name = "stardust-xr-source";
|
||||||
readSecretString stardustxrIpfs .basicauth > .basicauth
|
path = toString ./.;
|
||||||
set -x
|
filter = path: type:
|
||||||
export RESPONSE=$(curl -H @.basicauth -F file=@${self.packages."x86_64-linux".gnome-graphical-test}/screen.png https://ipfs-api.stardustxr.org/api/v0/add)
|
nixpkgs.lib.all
|
||||||
export CID=$(echo "$RESPONSE" | ${pkgs.jq}/bin/jq -r .Hash)
|
(n: builtins.baseNameOf path != n)
|
||||||
set +x
|
[
|
||||||
export ADDRESS="https://ipfs.stardustxr.org/ipfs/$CID"
|
"flake.nix"
|
||||||
${pkgs.discord-sh}/bin/discord.sh \
|
"flake.lock"
|
||||||
--description "\`stardustxr/server\` has been modified, here's how it renders \`weston-cliptest\` on \`flatland\` via \`monado-service\` inside of the \`gnome-graphical-test\`" \
|
"nix"
|
||||||
--field "Branch;${branch}" \
|
"README.md"
|
||||||
--field "Commit ID;${rev}" \
|
];
|
||||||
--field "Flatland Revision;${flatland.rev}" \
|
};
|
||||||
--field "Reproducer;\`nix build github:stardustxr/server/${rev}#gnome-graphical-test\`" \
|
|
||||||
--image "$ADDRESS"
|
# ---- START package specific settings ----
|
||||||
|
version = "0.10.2";
|
||||||
|
|
||||||
|
cargoLock = {
|
||||||
|
lockFile = ./Cargo.lock;
|
||||||
|
allowBuiltinFetchGit = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
postPatch = ''
|
||||||
|
sk=$(echo $cargoDepsCopy/stereokit-sys-*/StereoKit)
|
||||||
|
mkdir -p $sk/build/cpm
|
||||||
|
cp ${pkgs.fetchurl {
|
||||||
|
url = "https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.32.2/CPM.cmake";
|
||||||
|
hash = "sha256-yDHlpqmpAE8CWiwJRoWyaqbuBAg0090G8WJIC2KLHp8=";
|
||||||
|
}} $sk/build/cpm/CPM_0.32.2.cmake
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
CPM_SOURCE_CACHE = "./build";
|
||||||
|
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
cmake pkg-config llvmPackages.libcxxClang
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
openxr-loader libGL mesa xorg.libX11 fontconfig libxkbcommon
|
||||||
|
];
|
||||||
|
|
||||||
|
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
|
||||||
|
# ---- END package specific settings ----
|
||||||
};
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
overlays.default = final: prev: {
|
||||||
|
stardust-xr = (prev.stardust-xr or {}) // {
|
||||||
|
${name} = package final;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
packages."x86_64-linux".default = package (pkgs "x86_64-linux");
|
||||||
|
packages."aarch64-linux".default = package (pkgs "aarch64-linux");
|
||||||
|
|
||||||
|
packages."x86_64-linux".gnome-graphical-test = self.checks.x86_64-linux.gnome-graphical-test;
|
||||||
|
packages."aarch64-linux".gnome-graphical-test = self.checks.aarch64-linux.gnome-graphical-test;
|
||||||
|
|
||||||
|
checks."x86_64-linux".gnome-graphical-test = (pkgs "x86_64-linux").nixosTest (import ./nix/gnome-graphical-test.nix { pkgs = (pkgs "x86_64-linux"); inherit self; });
|
||||||
|
checks."aarch64-linux".gnome-graphical-test = (pkgs "aarch64-linux").nixosTest (import ./nix/gnome-graphical-test.nix { pkgs = (pkgs "aarch64-linux"); inherit self; });
|
||||||
|
|
||||||
|
devShells."x86_64-linux".default = shell (pkgs "x86_64-linux");
|
||||||
|
devShells."aarch64-linux".default = shell (pkgs "aarch64-linux");
|
||||||
|
|
||||||
|
herculesCI.ciSystems = [ "x86_64-linux" ];
|
||||||
|
|
||||||
|
effects = let
|
||||||
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||||
|
hci-effects = hercules-ci-effects.lib.withPkgs pkgs;
|
||||||
|
in { branch, rev, ... }: {
|
||||||
|
gnome-graphical-test = hci-effects.mkEffect {
|
||||||
|
secretsMap."stardustxrDiscord" = "stardustxrDiscord";
|
||||||
|
secretsMap."stardustxrIpfs" = "stardustxrIpfs";
|
||||||
|
effectScript = ''
|
||||||
|
readSecretString stardustxrDiscord .webhook > .webhook
|
||||||
|
readSecretString stardustxrIpfs .basicauth > .basicauth
|
||||||
|
set -x
|
||||||
|
export RESPONSE=$(curl -H @.basicauth -F file=@${self.packages."x86_64-linux".gnome-graphical-test}/screen.png https://ipfs-api.stardustxr.org/api/v0/add)
|
||||||
|
export CID=$(echo "$RESPONSE" | ${pkgs.jq}/bin/jq -r .Hash)
|
||||||
|
set +x
|
||||||
|
export ADDRESS="https://ipfs.stardustxr.org/ipfs/$CID"
|
||||||
|
${pkgs.discord-sh}/bin/discord.sh \
|
||||||
|
--description "\`stardustxr/server\` has been modified, here's how it renders \`weston-cliptest\` on \`flatland\` via \`monado-service\` inside of the \`gnome-graphical-test\`" \
|
||||||
|
--field "Branch;${branch}" \
|
||||||
|
--field "Commit ID;${rev}" \
|
||||||
|
--field "Flatland Revision;${flatland.rev}" \
|
||||||
|
--field "Reproducer;\`nix build github:stardustxr/server/${rev}#gnome-graphical-test\`" \
|
||||||
|
--image "$ADDRESS"
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
{ rustPlatform
|
|
||||||
, src
|
|
||||||
, name
|
|
||||||
, openxr-loader
|
|
||||||
, libGL
|
|
||||||
, mesa
|
|
||||||
, xorg
|
|
||||||
, fontconfig
|
|
||||||
, libxkbcommon
|
|
||||||
, libclang
|
|
||||||
, cmake
|
|
||||||
, cpm-cmake
|
|
||||||
, pkg-config
|
|
||||||
, llvmPackages
|
|
||||||
}:
|
|
||||||
|
|
||||||
rustPlatform.buildRustPackage rec {
|
|
||||||
inherit src name;
|
|
||||||
cargoLock = {
|
|
||||||
lockFile = (src + "/Cargo.lock");
|
|
||||||
allowBuiltinFetchGit = true;
|
|
||||||
};
|
|
||||||
CPM_SOURCE_CACHE = "./build";
|
|
||||||
postPatch = ''
|
|
||||||
sk=$(echo $cargoDepsCopy/stereokit-sys-*/StereoKit)
|
|
||||||
mkdir -p $sk/build/cpm
|
|
||||||
|
|
||||||
# This is not ideal, the original approach was to fetch the exact cmake
|
|
||||||
# file version that was wanted from GitHub directly, but at least this way it comes from Nixpkgs.. so meh
|
|
||||||
cp ${cpm-cmake}/share/cpm/CPM.cmake $sk/build/cpm/CPM_0.32.2.cmake
|
|
||||||
'';
|
|
||||||
nativeBuildInputs = [
|
|
||||||
cmake pkg-config llvmPackages.libcxxClang
|
|
||||||
];
|
|
||||||
buildInputs = [
|
|
||||||
openxr-loader libGL mesa xorg.libX11 fontconfig libxkbcommon
|
|
||||||
];
|
|
||||||
LIBCLANG_PATH = "${libclang.lib}/lib";
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
use std::ffi::c_void;
|
|
||||||
|
|
||||||
use color_eyre::eyre::{ensure, Result};
|
|
||||||
use smithay::backend::{egl::EGLContext, renderer::gles::GlesRenderer};
|
|
||||||
use stereokit as sk;
|
|
||||||
|
|
||||||
struct EGLRawHandles {
|
|
||||||
display: *const c_void,
|
|
||||||
config: *const c_void,
|
|
||||||
context: *const c_void,
|
|
||||||
}
|
|
||||||
fn get_sk_egl() -> Result<EGLRawHandles> {
|
|
||||||
ensure!(
|
|
||||||
unsafe { sk::sys::backend_graphics_get() }
|
|
||||||
== sk::sys::backend_graphics__backend_graphics_opengles_egl,
|
|
||||||
"StereoKit is not running using EGL!"
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(unsafe {
|
|
||||||
EGLRawHandles {
|
|
||||||
display: sk::sys::backend_opengl_egl_get_display() as *const c_void,
|
|
||||||
config: sk::sys::backend_opengl_egl_get_config() as *const c_void,
|
|
||||||
context: sk::sys::backend_opengl_egl_get_context() as *const c_void,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct BufferManager {
|
|
||||||
pub renderer: GlesRenderer,
|
|
||||||
}
|
|
||||||
impl BufferManager {
|
|
||||||
pub fn new() -> Result<Self> {
|
|
||||||
let egl_raw_handles = get_sk_egl()?;
|
|
||||||
let renderer = unsafe {
|
|
||||||
GlesRenderer::new(EGLContext::from_raw(
|
|
||||||
egl_raw_handles.display,
|
|
||||||
egl_raw_handles.config,
|
|
||||||
egl_raw_handles.context,
|
|
||||||
)?)?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(BufferManager { renderer })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn make_context_current(&self) {
|
|
||||||
unsafe {
|
|
||||||
let _ = self.renderer.egl_context().make_current();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,22 @@
|
|||||||
use super::{
|
use super::scenegraph::Scenegraph;
|
||||||
client_state::{ClientState, CLIENT_STATES},
|
#[cfg(feature = "oxr_runtime")]
|
||||||
scenegraph::Scenegraph,
|
use crate::openxr;
|
||||||
};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
core::{registry::OwnedRegistry, task},
|
core::{registry::OwnedRegistry, task},
|
||||||
nodes::{audio, data, drawable, fields, hmd, input, items, root::Root, spatial, Node},
|
nodes::{
|
||||||
|
audio, data, drawable, fields, hmd, input, items,
|
||||||
|
root::Root,
|
||||||
|
spatial,
|
||||||
|
startup::{self, StartupSettings, STARTUP_SETTINGS},
|
||||||
|
Node,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use color_eyre::eyre::{eyre, Result};
|
use color_eyre::eyre::{eyre, Result};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use stardust_xr::{
|
use stardust_xr::messenger::{self, MessageSenderHandle};
|
||||||
messenger::{self, MessageSenderHandle},
|
|
||||||
schemas::flex::serialize,
|
|
||||||
};
|
|
||||||
use std::{fs, iter::FromIterator, path::PathBuf, sync::Arc};
|
use std::{fs, iter::FromIterator, path::PathBuf, sync::Arc};
|
||||||
use tokio::{net::UnixStream, task::JoinHandle};
|
use tokio::{net::UnixStream, task::JoinHandle};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
@@ -34,7 +36,7 @@ lazy_static! {
|
|||||||
scenegraph: Default::default(),
|
scenegraph: Default::default(),
|
||||||
root: OnceCell::new(),
|
root: OnceCell::new(),
|
||||||
base_resource_prefixes: Default::default(),
|
base_resource_prefixes: Default::default(),
|
||||||
state: Arc::new(ClientState::default()),
|
startup_settings: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,13 +48,13 @@ pub fn get_env(pid: i32) -> Result<FxHashMap<String, String>, std::io::Error> {
|
|||||||
.map(|(k, v)| (k.to_string(), v.to_string())),
|
.map(|(k, v)| (k.to_string(), v.to_string())),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
pub fn state(env: &FxHashMap<String, String>) -> Option<Arc<ClientState>> {
|
pub fn startup_settings(env: &FxHashMap<String, String>) -> Option<StartupSettings> {
|
||||||
let token = env.get("STARDUST_STARTUP_TOKEN")?;
|
let token = env.get("STARDUST_STARTUP_TOKEN")?;
|
||||||
CLIENT_STATES.lock().get(token).cloned()
|
STARTUP_SETTINGS.lock().get(token).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
pub pid: Option<i32>,
|
pid: Option<i32>,
|
||||||
// env: Option<FxHashMap<String, String>>,
|
// env: Option<FxHashMap<String, String>>,
|
||||||
exe: Option<PathBuf>,
|
exe: Option<PathBuf>,
|
||||||
dispatch_join_handle: OnceCell<JoinHandle<Result<()>>>,
|
dispatch_join_handle: OnceCell<JoinHandle<Result<()>>>,
|
||||||
@@ -63,7 +65,7 @@ pub struct Client {
|
|||||||
pub scenegraph: Arc<Scenegraph>,
|
pub scenegraph: Arc<Scenegraph>,
|
||||||
pub root: OnceCell<Arc<Root>>,
|
pub root: OnceCell<Arc<Root>>,
|
||||||
pub base_resource_prefixes: Mutex<Vec<PathBuf>>,
|
pub base_resource_prefixes: Mutex<Vec<PathBuf>>,
|
||||||
pub state: Arc<ClientState>,
|
pub startup_settings: Option<StartupSettings>,
|
||||||
}
|
}
|
||||||
impl Client {
|
impl Client {
|
||||||
pub fn from_connection(connection: UnixStream) -> Result<Arc<Self>> {
|
pub fn from_connection(connection: UnixStream) -> Result<Arc<Self>> {
|
||||||
@@ -80,10 +82,7 @@ impl Client {
|
|||||||
|
|
||||||
let (mut messenger_tx, mut messenger_rx) = messenger::create(connection);
|
let (mut messenger_tx, mut messenger_rx) = messenger::create(connection);
|
||||||
let scenegraph = Arc::new(Scenegraph::default());
|
let scenegraph = Arc::new(Scenegraph::default());
|
||||||
let state = env
|
let startup_settings = env.as_ref().and_then(startup_settings);
|
||||||
.as_ref()
|
|
||||||
.and_then(state)
|
|
||||||
.unwrap_or_else(|| Arc::new(ClientState::default()));
|
|
||||||
|
|
||||||
let client = CLIENTS.add(Client {
|
let client = CLIENTS.add(Client {
|
||||||
pid,
|
pid,
|
||||||
@@ -98,7 +97,7 @@ impl Client {
|
|||||||
scenegraph: scenegraph.clone(),
|
scenegraph: scenegraph.clone(),
|
||||||
root: OnceCell::new(),
|
root: OnceCell::new(),
|
||||||
base_resource_prefixes: Default::default(),
|
base_resource_prefixes: Default::default(),
|
||||||
state,
|
startup_settings,
|
||||||
});
|
});
|
||||||
let _ = client.scenegraph.client.set(Arc::downgrade(&client));
|
let _ = client.scenegraph.client.set(Arc::downgrade(&client));
|
||||||
let _ = client.root.set(Root::create(&client)?);
|
let _ = client.root.set(Root::create(&client)?);
|
||||||
@@ -110,13 +109,9 @@ impl Client {
|
|||||||
data::create_interface(&client)?;
|
data::create_interface(&client)?;
|
||||||
items::create_interface(&client)?;
|
items::create_interface(&client)?;
|
||||||
input::create_interface(&client)?;
|
input::create_interface(&client)?;
|
||||||
|
startup::create_interface(&client)?;
|
||||||
client
|
#[cfg(feature = "openxr_runtime")]
|
||||||
.root
|
openxr::create_interface(&client);
|
||||||
.get()
|
|
||||||
.unwrap()
|
|
||||||
.node
|
|
||||||
.send_remote_signal("restore_state", serialize(client.state.apply_to(&client))?)?;
|
|
||||||
|
|
||||||
let pid_printable = pid
|
let pid_printable = pid
|
||||||
.map(|pid| pid.to_string())
|
.map(|pid| pid.to_string())
|
||||||
@@ -173,27 +168,6 @@ impl Client {
|
|||||||
Ok(client)
|
Ok(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cmdline(&self) -> Option<Vec<String>> {
|
|
||||||
let pid = self.pid?;
|
|
||||||
let exe_proc_path = format!("/proc/{pid}/exe");
|
|
||||||
let cmdline_proc_path = format!("/proc/{pid}/cmdline");
|
|
||||||
let exe = std::fs::read_link(exe_proc_path).ok()?;
|
|
||||||
let cmdline = std::fs::read_to_string(cmdline_proc_path).ok()?;
|
|
||||||
let mut cmdline_split: Vec<_> = cmdline.split('\0').map(ToString::to_string).collect();
|
|
||||||
cmdline_split.pop();
|
|
||||||
*cmdline_split.get_mut(0).unwrap() = exe.to_str()?.to_string();
|
|
||||||
Some(cmdline_split)
|
|
||||||
}
|
|
||||||
pub fn get_cwd(&self) -> Option<PathBuf> {
|
|
||||||
let pid = self.pid?;
|
|
||||||
let cwd_proc_path = format!("/proc/{pid}/cwd");
|
|
||||||
std::fs::read_link(cwd_proc_path).ok()
|
|
||||||
}
|
|
||||||
pub async fn save_state(&self) -> Option<ClientState> {
|
|
||||||
let internal = self.root.get()?.save_state().await.ok()?;
|
|
||||||
Some(ClientState::from_deserialized(self, internal))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_node(&self, name: &'static str, path: &str) -> Result<Arc<Node>> {
|
pub fn get_node(&self, name: &'static str, path: &str) -> Result<Arc<Node>> {
|
||||||
self.scenegraph
|
self.scenegraph
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
use super::client::{get_env, Client};
|
|
||||||
use crate::nodes::{spatial::Spatial, Node};
|
|
||||||
use glam::Mat4;
|
|
||||||
use parking_lot::Mutex;
|
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::{io::Write, path::PathBuf, sync::Arc};
|
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
|
||||||
pub static ref CLIENT_STATES: Mutex<FxHashMap<String, Arc<ClientState>>> = Default::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct LaunchInfo {
|
|
||||||
pub cmdline: Vec<String>,
|
|
||||||
pub cwd: PathBuf,
|
|
||||||
pub env: FxHashMap<String, String>,
|
|
||||||
}
|
|
||||||
impl LaunchInfo {
|
|
||||||
fn from_client(client: &Client) -> Option<Self> {
|
|
||||||
Some(LaunchInfo {
|
|
||||||
cmdline: client.get_cmdline()?,
|
|
||||||
cwd: client.get_cwd()?,
|
|
||||||
env: get_env(client.pid?).ok()?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct ClientState {
|
|
||||||
pub launch_info: Option<LaunchInfo>,
|
|
||||||
pub data: Option<Vec<u8>>,
|
|
||||||
pub root: Mat4,
|
|
||||||
pub spatial_anchors: FxHashMap<String, Mat4>,
|
|
||||||
}
|
|
||||||
impl ClientState {
|
|
||||||
pub fn from_deserialized(client: &Client, state: ClientStateInternal) -> Self {
|
|
||||||
ClientState {
|
|
||||||
launch_info: LaunchInfo::from_client(client),
|
|
||||||
data: state.data,
|
|
||||||
root: Self::spatial_transform(client, &state.root.unwrap_or_default())
|
|
||||||
.unwrap_or_default(),
|
|
||||||
spatial_anchors: state
|
|
||||||
.spatial_anchors
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|(k, v)| Some((k, Self::spatial_transform(client, &v)?)))
|
|
||||||
.collect(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn spatial_transform(client: &Client, path: &str) -> Option<Mat4> {
|
|
||||||
let node = client.scenegraph.get_node(path)?;
|
|
||||||
let spatial = node.spatial.get()?;
|
|
||||||
Some(spatial.global_transform())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn token(self) -> String {
|
|
||||||
let token = nanoid::nanoid!();
|
|
||||||
CLIENT_STATES.lock().insert(token.clone(), Arc::new(self));
|
|
||||||
token
|
|
||||||
}
|
|
||||||
pub fn to_file(self) {
|
|
||||||
let project_dirs = directories::ProjectDirs::from("", "", "stardust").unwrap();
|
|
||||||
let state_dir = project_dirs.state_dir().unwrap();
|
|
||||||
std::fs::create_dir_all(state_dir).unwrap();
|
|
||||||
let mut file = std::fs::File::create(state_dir.join(nanoid::nanoid!())).unwrap();
|
|
||||||
file.write_all(&stardust_xr::schemas::flex::flexbuffers::to_vec(self).unwrap())
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
pub fn apply_to(&self, client: &Arc<Client>) -> ClientStateInternal {
|
|
||||||
if let Some(root) = client.root.get() {
|
|
||||||
root.set_transform(self.root)
|
|
||||||
}
|
|
||||||
ClientStateInternal {
|
|
||||||
data: self.data.clone(),
|
|
||||||
root: Some("/".to_string()),
|
|
||||||
spatial_anchors: self
|
|
||||||
.spatial_anchors
|
|
||||||
.iter()
|
|
||||||
.map(|(k, v)| {
|
|
||||||
(k.clone(), {
|
|
||||||
let node = Node::create(client, "/spatial/anchor", k, true)
|
|
||||||
.add_to_scenegraph()
|
|
||||||
.unwrap();
|
|
||||||
Spatial::add_to(&node, None, *v, false).unwrap();
|
|
||||||
k.clone()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Default for ClientState {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
launch_info: None,
|
|
||||||
data: None,
|
|
||||||
root: Mat4::IDENTITY,
|
|
||||||
spatial_anchors: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Serialize, Deserialize)]
|
|
||||||
pub struct ClientStateInternal {
|
|
||||||
data: Option<Vec<u8>>,
|
|
||||||
root: Option<String>,
|
|
||||||
spatial_anchors: FxHashMap<String, String>,
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
pub mod client;
|
pub mod client;
|
||||||
pub mod client_state;
|
|
||||||
pub mod delta;
|
pub mod delta;
|
||||||
pub mod destroy_queue;
|
pub mod destroy_queue;
|
||||||
pub mod eventloop;
|
pub mod eventloop;
|
||||||
@@ -9,4 +8,3 @@ pub mod resource;
|
|||||||
pub mod scenegraph;
|
pub mod scenegraph;
|
||||||
pub mod task;
|
pub mod task;
|
||||||
pub mod typed_datamap;
|
pub mod typed_datamap;
|
||||||
pub mod buffers;
|
|
||||||
|
|||||||
@@ -7,32 +7,33 @@ use std::{
|
|||||||
sync::{Arc, Weak},
|
sync::{Arc, Weak},
|
||||||
};
|
};
|
||||||
|
|
||||||
// #[derive(Default)]
|
#[derive(Default)]
|
||||||
// pub struct LifeLinkedNodeList {
|
pub struct LifeLinkedNodeList {
|
||||||
// nodes: Mutex<Vec<Weak<Node>>>,
|
nodes: Mutex<Vec<Weak<Node>>>,
|
||||||
// }
|
}
|
||||||
// impl LifeLinkedNodeList {
|
impl LifeLinkedNodeList {
|
||||||
// pub fn add(&self, node: Weak<Node>) {
|
pub fn add(&self, node: Weak<Node>) {
|
||||||
// self.nodes.lock().push(node);
|
self.nodes.lock().push(node);
|
||||||
// }
|
}
|
||||||
// pub fn clear(&self) {
|
|
||||||
// self.nodes
|
|
||||||
// .lock()
|
|
||||||
// .iter()
|
|
||||||
// .filter_map(|node| node.upgrade())
|
|
||||||
// .for_each(|node| {
|
|
||||||
// node.destroy();
|
|
||||||
// });
|
|
||||||
// self.nodes.lock().clear();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// impl Drop for LifeLinkedNodeList {
|
|
||||||
// fn drop(&mut self) {
|
|
||||||
// self.clear();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
pub fn clear(&self) {
|
||||||
|
self.nodes
|
||||||
|
.lock()
|
||||||
|
.iter()
|
||||||
|
.filter_map(|node| node.upgrade())
|
||||||
|
.for_each(|node| {
|
||||||
|
node.destroy();
|
||||||
|
});
|
||||||
|
self.nodes.lock().clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Drop for LifeLinkedNodeList {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct LifeLinkedNodeMap<K: Hash + Eq> {
|
pub struct LifeLinkedNodeMap<K: Hash + Eq> {
|
||||||
nodes: Mutex<FxHashMap<K, Weak<Node>>>,
|
nodes: Mutex<FxHashMap<K, Weak<Node>>>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,14 +54,6 @@ impl<T: Send + Sync + ?Sized> Registry<T> {
|
|||||||
pub fn clear(&self) {
|
pub fn clear(&self) {
|
||||||
self.lock().clear();
|
self.lock().clear();
|
||||||
}
|
}
|
||||||
pub fn is_empty(&self) -> bool {
|
|
||||||
let registry = self.0.lock();
|
|
||||||
let Some(registry) = &*registry else {return true};
|
|
||||||
if registry.is_empty() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
registry.values().all(|v| v.strong_count() == 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
impl<T: Send + Sync + ?Sized> Clone for Registry<T> {
|
impl<T: Send + Sync + ?Sized> Clone for Registry<T> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
|
|||||||
@@ -2,20 +2,20 @@ use crate::nodes::Node;
|
|||||||
use crate::{core::client::Client, nodes::Message};
|
use crate::{core::client::Client, nodes::Message};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
|
||||||
use portable_atomic::Ordering;
|
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use stardust_xr::scenegraph;
|
use stardust_xr::scenegraph;
|
||||||
use stardust_xr::scenegraph::ScenegraphError;
|
use stardust_xr::scenegraph::ScenegraphError;
|
||||||
use std::os::fd::OwnedFd;
|
use std::os::fd::OwnedFd;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use tokio::sync::oneshot;
|
use tracing::{debug, debug_span, instrument};
|
||||||
use tracing::{debug, debug_span};
|
|
||||||
|
use core::hash::BuildHasherDefault;
|
||||||
|
use dashmap::DashMap;
|
||||||
|
use rustc_hash::FxHasher;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Scenegraph {
|
pub struct Scenegraph {
|
||||||
pub(super) client: OnceCell<Weak<Client>>,
|
pub(super) client: OnceCell<Weak<Client>>,
|
||||||
nodes: Mutex<FxHashMap<String, Arc<Node>>>,
|
nodes: DashMap<String, Arc<Node>, BuildHasherDefault<FxHasher>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scenegraph {
|
impl Scenegraph {
|
||||||
@@ -31,38 +31,25 @@ impl Scenegraph {
|
|||||||
pub fn add_node_raw(&self, node: Arc<Node>) {
|
pub fn add_node_raw(&self, node: Arc<Node>) {
|
||||||
debug!(node = ?&*node, "Add node");
|
debug!(node = ?&*node, "Add node");
|
||||||
let path = node.get_path().to_string();
|
let path = node.get_path().to_string();
|
||||||
self.nodes.lock().insert(path, node);
|
self.nodes.insert(path, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip(self))]
|
||||||
pub fn get_node(&self, path: &str) -> Option<Arc<Node>> {
|
pub fn get_node(&self, path: &str) -> Option<Arc<Node>> {
|
||||||
let mut node = self.nodes.lock().get(path)?.clone();
|
let mut node = self.nodes.get(path)?.clone();
|
||||||
while let Some(alias) = node.alias.get() {
|
while let Some(alias) = node.alias.get() {
|
||||||
if alias.enabled.load(Ordering::Relaxed) {
|
node = alias.original.upgrade()?;
|
||||||
node = alias.original.upgrade()?;
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some(node)
|
Some(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_node(&self, path: &str) -> Option<Arc<Node>> {
|
pub fn remove_node(&self, path: &str) -> Option<Arc<Node>> {
|
||||||
debug!(path, "Remove node");
|
debug!(path, "Remove node");
|
||||||
self.nodes.lock().remove(path)
|
let (_, node) = self.nodes.remove(path)?;
|
||||||
|
Some(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MethodResponseSender(oneshot::Sender<Result<(Vec<u8>, Vec<OwnedFd>), ScenegraphError>>);
|
|
||||||
impl MethodResponseSender {
|
|
||||||
pub fn send(self, t: Result<Message, ScenegraphError>) {
|
|
||||||
let _ = self.0.send(t.map(|m| (m.data, m.fds)));
|
|
||||||
}
|
|
||||||
pub fn wrap_sync<F: FnOnce() -> color_eyre::eyre::Result<Message>>(self, f: F) {
|
|
||||||
self.send(f().map_err(|e| ScenegraphError::MethodError {
|
|
||||||
error: e.to_string(),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl scenegraph::Scenegraph for Scenegraph {
|
impl scenegraph::Scenegraph for Scenegraph {
|
||||||
fn send_signal(
|
fn send_signal(
|
||||||
&self,
|
&self,
|
||||||
@@ -71,9 +58,7 @@ impl scenegraph::Scenegraph for Scenegraph {
|
|||||||
data: &[u8],
|
data: &[u8],
|
||||||
fds: Vec<OwnedFd>,
|
fds: Vec<OwnedFd>,
|
||||||
) -> Result<(), ScenegraphError> {
|
) -> Result<(), ScenegraphError> {
|
||||||
let Some(client) = self.get_client() else {
|
let Some(client) = self.get_client() else {return Err(ScenegraphError::SignalNotFound)};
|
||||||
return Err(ScenegraphError::SignalNotFound);
|
|
||||||
};
|
|
||||||
debug_span!("Handle signal", path, method).in_scope(|| {
|
debug_span!("Handle signal", path, method).in_scope(|| {
|
||||||
self.get_node(path)
|
self.get_node(path)
|
||||||
.ok_or(ScenegraphError::NodeNotFound)?
|
.ok_or(ScenegraphError::NodeNotFound)?
|
||||||
@@ -93,25 +78,21 @@ impl scenegraph::Scenegraph for Scenegraph {
|
|||||||
method: &str,
|
method: &str,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
fds: Vec<OwnedFd>,
|
fds: Vec<OwnedFd>,
|
||||||
response: oneshot::Sender<Result<(Vec<u8>, Vec<OwnedFd>), ScenegraphError>>,
|
) -> Result<(Vec<u8>, Vec<OwnedFd>), ScenegraphError> {
|
||||||
) {
|
let Some(client) = self.get_client() else {return Err(ScenegraphError::MethodNotFound)};
|
||||||
let Some(client) = self.get_client() else {
|
debug_span!("Handle method", path, method).in_scope(|| {
|
||||||
let _ = response.send(Err(ScenegraphError::MethodNotFound));
|
let message = self
|
||||||
return;
|
.get_node(path)
|
||||||
};
|
.ok_or(ScenegraphError::NodeNotFound)?
|
||||||
debug!(path, method, "Handle method");
|
.execute_local_method(
|
||||||
let Some(node) = self.get_node(path) else {
|
client,
|
||||||
let _ = response.send(Err(ScenegraphError::NodeNotFound));
|
method,
|
||||||
return;
|
Message {
|
||||||
};
|
data: data.to_vec(),
|
||||||
node.execute_local_method(
|
fds,
|
||||||
client,
|
},
|
||||||
method,
|
)?;
|
||||||
Message {
|
Ok((message.data, message.fds))
|
||||||
data: data.to_vec(),
|
})
|
||||||
fds,
|
|
||||||
},
|
|
||||||
MethodResponseSender(response),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn new<
|
pub fn new<
|
||||||
F: FnOnce() -> S,
|
F: FnOnce() -> S,
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
|
|||||||
141
src/main.rs
141
src/main.rs
@@ -1,13 +1,12 @@
|
|||||||
mod core;
|
mod core;
|
||||||
mod nodes;
|
mod nodes;
|
||||||
mod objects;
|
mod objects;
|
||||||
|
#[cfg(feature = "openxr_runtime")]
|
||||||
|
mod openxr;
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
mod wayland;
|
mod wayland;
|
||||||
|
|
||||||
use crate::core::client::CLIENTS;
|
use crate::core::destroy_queue;
|
||||||
use crate::core::client_state::ClientState;
|
|
||||||
use crate::core::{destroy_queue, buffers};
|
|
||||||
use crate::nodes::items::camera;
|
|
||||||
use crate::nodes::{audio, drawable, hmd, input};
|
use crate::nodes::{audio, drawable, hmd, input};
|
||||||
use crate::objects::input::eye_pointer::EyePointer;
|
use crate::objects::input::eye_pointer::EyePointer;
|
||||||
use crate::objects::input::mouse_pointer::MousePointer;
|
use crate::objects::input::mouse_pointer::MousePointer;
|
||||||
@@ -19,9 +18,7 @@ use self::core::eventloop::EventLoop;
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use smithay::reexports::nix;
|
|
||||||
use stardust_xr::server;
|
use stardust_xr::server;
|
||||||
use std::os::unix::process::CommandExt;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -31,13 +28,13 @@ use stereokit::{
|
|||||||
TextureFormat, TextureType,
|
TextureFormat, TextureType,
|
||||||
};
|
};
|
||||||
use stereokit::{DisplayBlend, Sk};
|
use stereokit::{DisplayBlend, Sk};
|
||||||
use tokio::sync::Notify;
|
|
||||||
use tokio::task::LocalSet;
|
|
||||||
use tokio::{runtime::Handle, sync::oneshot};
|
use tokio::{runtime::Handle, sync::oneshot};
|
||||||
use tracing::metadata::LevelFilter;
|
use tracing::metadata::LevelFilter;
|
||||||
use tracing::{debug_span, error, info};
|
use tracing::{debug_span, error, info};
|
||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
|
|
||||||
|
pub static SK_INFO: OnceCell<SystemInfo> = OnceCell::new();
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct CliArgs {
|
struct CliArgs {
|
||||||
@@ -60,7 +57,6 @@ struct CliArgs {
|
|||||||
|
|
||||||
static STARDUST_INSTANCE: OnceCell<String> = OnceCell::new();
|
static STARDUST_INSTANCE: OnceCell<String> = OnceCell::new();
|
||||||
static SK_MULTITHREAD: OnceCell<Sk> = OnceCell::new();
|
static SK_MULTITHREAD: OnceCell<Sk> = OnceCell::new();
|
||||||
static STOP_NOTIFIER: Notify = Notify::const_new();
|
|
||||||
|
|
||||||
struct EventLoopInfo {
|
struct EventLoopInfo {
|
||||||
tokio_handle: Handle,
|
tokio_handle: Handle,
|
||||||
@@ -68,17 +64,13 @@ struct EventLoopInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
ctrlc::set_handler(|| {
|
|
||||||
if atty::isnt(atty::Stream::Stdout) {
|
|
||||||
STOP_NOTIFIER.notify_waiters()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let registry = tracing_subscriber::registry();
|
let registry = tracing_subscriber::registry();
|
||||||
|
|
||||||
#[cfg(feature = "profile_app")]
|
#[cfg(feature = "profile_app")]
|
||||||
let registry = registry.with(tracing_tracy::TracyLayer::new().with_filter(LevelFilter::DEBUG));
|
let (chrome_layer, _guard) = tracing_chrome::ChromeLayerBuilder::new()
|
||||||
|
.include_args(true)
|
||||||
|
.build();
|
||||||
|
#[cfg(feature = "profile_app")]
|
||||||
|
let registry = registry.with(chrome_layer);
|
||||||
|
|
||||||
#[cfg(feature = "profile_tokio")]
|
#[cfg(feature = "profile_tokio")]
|
||||||
let (console_layer, _) = console_subscriber::ConsoleLayer::builder().build();
|
let (console_layer, _) = console_subscriber::ConsoleLayer::builder().build();
|
||||||
@@ -126,6 +118,8 @@ fn main() {
|
|||||||
let _ = SK_MULTITHREAD.set(sk.multithreaded());
|
let _ = SK_MULTITHREAD.set(sk.multithreaded());
|
||||||
info!("Init StereoKit");
|
info!("Init StereoKit");
|
||||||
|
|
||||||
|
SK_INFO.set(stereokit.system_info()).unwrap();
|
||||||
|
|
||||||
sk.material_set_shader(
|
sk.material_set_shader(
|
||||||
sk.material_find("default/material_pbr").unwrap(),
|
sk.material_find("default/material_pbr").unwrap(),
|
||||||
sk.shader_find("default/shader_pbr_clip").unwrap(),
|
sk.shader_find("default/shader_pbr_clip").unwrap(),
|
||||||
@@ -175,11 +169,10 @@ fn main() {
|
|||||||
left.zip(right)
|
left.zip(right)
|
||||||
})
|
})
|
||||||
.flatten();
|
.flatten();
|
||||||
let eye_pointer = (sk.active_display_mode() == DisplayMode::MixedReality
|
let eye_pointer = (!cli_args.flatscreen && sk.device_has_eye_gaze())
|
||||||
&& sk.device_has_eye_gaze())
|
.then(EyePointer::new)
|
||||||
.then(EyePointer::new)
|
.transpose()
|
||||||
.transpose()
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if hands.is_none() {
|
if hands.is_none() {
|
||||||
sk.input_hand_visible(Handed::Left, false);
|
sk.input_hand_visible(Handed::Left, false);
|
||||||
@@ -191,34 +184,28 @@ fn main() {
|
|||||||
.then(|| PlaySpace::new().ok())
|
.then(|| PlaySpace::new().ok())
|
||||||
.flatten();
|
.flatten();
|
||||||
|
|
||||||
|
let (event_stop_tx, event_stop_rx) = oneshot::channel::<()>();
|
||||||
let (info_sender, info_receiver) = oneshot::channel::<EventLoopInfo>();
|
let (info_sender, info_receiver) = oneshot::channel::<EventLoopInfo>();
|
||||||
let event_thread = std::thread::Builder::new()
|
let event_thread = std::thread::Builder::new()
|
||||||
.name("event_loop".to_owned())
|
.name("event_loop".to_owned())
|
||||||
.spawn(move || event_loop(info_sender))
|
.spawn(move || event_loop(info_sender, event_stop_rx))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let event_loop_info = info_receiver.blocking_recv().unwrap();
|
let event_loop_info = info_receiver.blocking_recv().unwrap();
|
||||||
let _tokio_handle = event_loop_info.tokio_handle.enter();
|
let _tokio_handle = event_loop_info.tokio_handle.enter();
|
||||||
|
|
||||||
let mut buffer_manager = buffers::BufferManager::new().expect("Could not initialize buffer manager");
|
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
let mut wayland = wayland::Wayland::new(&buffer_manager).expect("Could not initialize wayland");
|
let mut wayland = Some(wayland::Wayland::new().expect("Could not initialize wayland"));
|
||||||
info!("Stardust ready!");
|
info!("Stardust ready!");
|
||||||
|
|
||||||
let mut startup_child = (|| {
|
let mut startup_child = if let Some(project_dirs) = project_dirs.as_ref() {
|
||||||
let project_dirs = project_dirs.as_ref()?;
|
|
||||||
let startup_script_path = cli_args
|
let startup_script_path = cli_args
|
||||||
.startup_script
|
.startup_script
|
||||||
.clone()
|
.clone()
|
||||||
.and_then(|p| p.canonicalize().ok())
|
.and_then(|p| p.canonicalize().ok())
|
||||||
.unwrap_or_else(|| project_dirs.config_dir().join("startup"));
|
.unwrap_or_else(|| project_dirs.config_dir().join("startup"));
|
||||||
let mut startup_command = Command::new("bash");
|
let mut startup_command = Command::new(startup_script_path);
|
||||||
startup_command.arg(startup_script_path);
|
|
||||||
startup_command.arg("&");
|
|
||||||
|
|
||||||
startup_command.stdin(Stdio::null());
|
startup_command.stdin(Stdio::null());
|
||||||
startup_command.stdout(Stdio::null());
|
|
||||||
startup_command.stderr(Stdio::null());
|
|
||||||
startup_command.env(
|
startup_command.env(
|
||||||
"FLAT_WAYLAND_DISPLAY",
|
"FLAT_WAYLAND_DISPLAY",
|
||||||
std::env::var_os("WAYLAND_DISPLAY").unwrap_or_default(),
|
std::env::var_os("WAYLAND_DISPLAY").unwrap_or_default(),
|
||||||
@@ -232,48 +219,43 @@ fn main() {
|
|||||||
);
|
);
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
{
|
{
|
||||||
if let Some(wayland_socket) = wayland.socket_name.as_ref() {
|
startup_command.env("WAYLAND_DISPLAY", &wayland.as_ref().unwrap().socket_name);
|
||||||
startup_command.env("WAYLAND_DISPLAY", &wayland_socket);
|
|
||||||
}
|
|
||||||
#[cfg(feature = "xwayland")]
|
#[cfg(feature = "xwayland")]
|
||||||
startup_command.env("DISPLAY", format!(":{}", wayland.xwayland_state.display));
|
startup_command.env(
|
||||||
|
"DISPLAY",
|
||||||
|
format!(":{}", wayland.as_ref().unwrap().xwayland_state.display),
|
||||||
|
);
|
||||||
startup_command.env("GDK_BACKEND", "wayland");
|
startup_command.env("GDK_BACKEND", "wayland");
|
||||||
startup_command.env("QT_QPA_PLATFORM", "wayland");
|
startup_command.env("QT_QPA_PLATFORM", "wayland");
|
||||||
startup_command.env("MOZ_ENABLE_WAYLAND", "1");
|
startup_command.env("MOZ_ENABLE_WAYLAND", "1");
|
||||||
startup_command.env("CLUTTER_BACKEND", "wayland");
|
startup_command.env("CLUTTER_BACKEND", "wayland");
|
||||||
startup_command.env("SDL_VIDEODRIVER", "wayland");
|
startup_command.env("SDL_VIDEODRIVER", "wayland");
|
||||||
}
|
}
|
||||||
unsafe {
|
startup_command.spawn().ok()
|
||||||
startup_command.pre_exec(|| {
|
} else {
|
||||||
nix::unistd::setsid()
|
None
|
||||||
.map(|_| ())
|
};
|
||||||
.map_err(|_| std::io::ErrorKind::Other.into())
|
|
||||||
})
|
|
||||||
};
|
|
||||||
let child = startup_command.spawn().ok()?;
|
|
||||||
Some(child)
|
|
||||||
})();
|
|
||||||
|
|
||||||
let mut last_frame_delta = Duration::ZERO;
|
let mut last_frame_delta = Duration::ZERO;
|
||||||
let mut sleep_duration = Duration::ZERO;
|
let mut sleep_duration = Duration::ZERO;
|
||||||
debug_span!("StereoKit").in_scope(|| {
|
debug_span!("StereoKit").in_scope(|| {
|
||||||
sk.run(
|
sk.run_stateful(
|
||||||
|sk| {
|
&mut wayland,
|
||||||
|
move |wayland, _, sk| {
|
||||||
let _span = debug_span!("StereoKit step");
|
let _span = debug_span!("StereoKit step");
|
||||||
let _span = _span.enter();
|
let _span = _span.enter();
|
||||||
|
|
||||||
camera::send_rendered();
|
|
||||||
hmd::frame(sk);
|
hmd::frame(sk);
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
wayland.frame_event(sk);
|
wayland.as_mut().unwrap().frame_event(sk);
|
||||||
destroy_queue::clear();
|
destroy_queue::clear();
|
||||||
|
|
||||||
if let Some(mouse_pointer) = &mut mouse_pointer {
|
if let Some(mouse_pointer) = &mut mouse_pointer {
|
||||||
mouse_pointer.update(sk);
|
mouse_pointer.update(sk);
|
||||||
}
|
}
|
||||||
if let Some((left_hand, right_hand)) = &mut hands {
|
if let Some((left_hand, right_hand)) = &mut hands {
|
||||||
left_hand.update(!cli_args.disable_controller, sk);
|
left_hand.update(sk);
|
||||||
right_hand.update(!cli_args.disable_controller, sk);
|
right_hand.update(sk);
|
||||||
}
|
}
|
||||||
if let Some((left_controller, right_controller)) = &mut controllers {
|
if let Some((left_controller, right_controller)) = &mut controllers {
|
||||||
left_controller.update(sk);
|
left_controller.update(sk);
|
||||||
@@ -295,32 +277,32 @@ fn main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
wayland.update(sk, &mut buffer_manager);
|
wayland.as_mut().unwrap().update(sk);
|
||||||
drawable::draw(sk);
|
drawable::draw(sk);
|
||||||
audio::update(sk);
|
audio::update(sk);
|
||||||
|
#[cfg(feature = "wayland")]
|
||||||
buffer_manager.make_context_current();
|
wayland.as_mut().unwrap().make_context_current();
|
||||||
|
|
||||||
camera::update(sk, &mut buffer_manager);
|
|
||||||
},
|
},
|
||||||
|_sk| {
|
|wayland, _sk| {
|
||||||
info!("Cleanly shut down StereoKit");
|
info!("Cleanly shut down StereoKit");
|
||||||
|
|
||||||
if let Some(mut startup_child) = startup_child.take() {
|
if let Some(mut startup_child) = startup_child.take() {
|
||||||
let _ = startup_child.kill();
|
let _ = startup_child.kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "wayland")]
|
||||||
|
wayland.take();
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
let _ = event_stop_tx.send(());
|
||||||
drop(wayland);
|
|
||||||
|
|
||||||
STOP_NOTIFIER.notify_waiters();
|
|
||||||
event_thread
|
event_thread
|
||||||
.join()
|
.join()
|
||||||
.expect("Failed to cleanly shut down event loop")
|
.expect("Failed to cleanly shut down event loop")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
// #[cfg(feature = "wayland")]
|
||||||
|
// let _wayland = ManuallyDrop::new(wayland);
|
||||||
|
|
||||||
info!("Cleanly shut down Stardust");
|
info!("Cleanly shut down Stardust");
|
||||||
}
|
}
|
||||||
@@ -350,7 +332,10 @@ fn adaptive_sleep(
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
// #[tokio::main(flavor = "current_thread")]
|
// #[tokio::main(flavor = "current_thread")]
|
||||||
async fn event_loop(info_sender: oneshot::Sender<EventLoopInfo>) -> color_eyre::eyre::Result<()> {
|
async fn event_loop(
|
||||||
|
info_sender: oneshot::Sender<EventLoopInfo>,
|
||||||
|
stop_rx: oneshot::Receiver<()>,
|
||||||
|
) -> color_eyre::eyre::Result<()> {
|
||||||
let socket_path =
|
let socket_path =
|
||||||
server::get_free_socket_path().expect("Unable to find a free stardust socket path");
|
server::get_free_socket_path().expect("Unable to find a free stardust socket path");
|
||||||
STARDUST_INSTANCE.set(socket_path.file_name().unwrap().to_string_lossy().into_owned()).expect("Someone hasn't done their job, yell at Nova because how is this set multiple times what the hell");
|
STARDUST_INSTANCE.set(socket_path.file_name().unwrap().to_string_lossy().into_owned()).expect("Someone hasn't done their job, yell at Nova because how is this set multiple times what the hell");
|
||||||
@@ -365,9 +350,15 @@ async fn event_loop(info_sender: oneshot::Sender<EventLoopInfo>) -> color_eyre::
|
|||||||
socket_path,
|
socket_path,
|
||||||
});
|
});
|
||||||
|
|
||||||
STOP_NOTIFIER.notified().await;
|
if atty::is(atty::Stream::Stdin) {
|
||||||
println!("Stopping...");
|
stop_rx.await?;
|
||||||
save_clients().await;
|
} else {
|
||||||
|
tokio::select! {
|
||||||
|
biased;
|
||||||
|
_ = tokio::signal::ctrl_c() => (),
|
||||||
|
_ = stop_rx => (),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
info!("Cleanly shut down event loop");
|
info!("Cleanly shut down event loop");
|
||||||
|
|
||||||
@@ -377,17 +368,3 @@ async fn event_loop(info_sender: oneshot::Sender<EventLoopInfo>) -> color_eyre::
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save_clients() {
|
|
||||||
let local_set = LocalSet::new();
|
|
||||||
for client in CLIENTS.get_vec() {
|
|
||||||
local_set.spawn_local(async move {
|
|
||||||
tokio::select! {
|
|
||||||
biased;
|
|
||||||
s = client.save_state() => {s.map(ClientState::to_file);},
|
|
||||||
_ = tokio::time::sleep(Duration::from_millis(100)) => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
local_set.await;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use super::Node;
|
use super::Node;
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use color_eyre::eyre::{ensure, Result};
|
use color_eyre::eyre::{ensure, Result};
|
||||||
use portable_atomic::AtomicBool;
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
@@ -13,7 +12,6 @@ pub struct AliasInfo {
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct Alias {
|
pub struct Alias {
|
||||||
pub enabled: Arc<AtomicBool>,
|
|
||||||
pub(super) node: Weak<Node>,
|
pub(super) node: Weak<Node>,
|
||||||
pub original: Weak<Node>,
|
pub original: Weak<Node>,
|
||||||
|
|
||||||
@@ -37,7 +35,6 @@ impl Alias {
|
|||||||
|
|
||||||
let node = Node::create(client, parent, name, true).add_to_scenegraph()?;
|
let node = Node::create(client, parent, name, true).add_to_scenegraph()?;
|
||||||
let alias = Alias {
|
let alias = Alias {
|
||||||
enabled: Arc::new(AtomicBool::new(true)),
|
|
||||||
node: Arc::downgrade(&node),
|
node: Arc::downgrade(&node),
|
||||||
original: Arc::downgrade(original),
|
original: Arc::downgrade(original),
|
||||||
info,
|
info,
|
||||||
|
|||||||
@@ -5,26 +5,17 @@ use super::{Alias, Message, Node};
|
|||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::core::node_collections::LifeLinkedNodeMap;
|
use crate::core::node_collections::LifeLinkedNodeMap;
|
||||||
use crate::core::registry::Registry;
|
use crate::core::registry::Registry;
|
||||||
use crate::core::scenegraph::MethodResponseSender;
|
|
||||||
use crate::nodes::fields::{find_field, FIELD_ALIAS_INFO};
|
use crate::nodes::fields::{find_field, FIELD_ALIAS_INFO};
|
||||||
use crate::nodes::spatial::find_spatial_parent;
|
use crate::nodes::spatial::find_spatial_parent;
|
||||||
use color_eyre::eyre::{bail, ensure, eyre, Result};
|
use color_eyre::eyre::{ensure, eyre, Result};
|
||||||
use glam::vec3a;
|
use glam::vec3a;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use mint::{Quaternion, Vector3};
|
use mint::{Quaternion, Vector3};
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use parking_lot::Mutex;
|
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use stardust_xr::schemas::flex::{deserialize, flexbuffers, serialize};
|
use stardust_xr::schemas::flex::{deserialize, flexbuffers, serialize};
|
||||||
use stardust_xr::values::Transform;
|
use stardust_xr::values::Transform;
|
||||||
use std::fmt::Display;
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
pub static ref KEYMAPS: Mutex<FxHashMap<String, String>> = Mutex::new(FxHashMap::default());
|
|
||||||
}
|
|
||||||
|
|
||||||
static PULSE_SENDER_REGISTRY: Registry<PulseSender> = Registry::new();
|
static PULSE_SENDER_REGISTRY: Registry<PulseSender> = Registry::new();
|
||||||
pub static PULSE_RECEIVER_REGISTRY: Registry<PulseReceiver> = Registry::new();
|
pub static PULSE_RECEIVER_REGISTRY: Registry<PulseReceiver> = Registry::new();
|
||||||
|
|
||||||
@@ -33,16 +24,7 @@ pub fn mask_matches(mask_map_lesser: &Mask, mask_map_greater: &Mask) -> bool {
|
|||||||
for key in mask_map_lesser.get_mask()?.iter_keys() {
|
for key in mask_map_lesser.get_mask()?.iter_keys() {
|
||||||
let lesser_key = mask_map_lesser.get_mask()?.index(key)?;
|
let lesser_key = mask_map_lesser.get_mask()?.index(key)?;
|
||||||
let greater_key = mask_map_greater.get_mask()?.index(key)?;
|
let greater_key = mask_map_greater.get_mask()?.index(key)?;
|
||||||
// otherwise zero-length vectors don't count the same as a single type vector
|
if lesser_key.flexbuffer_type() != greater_key.flexbuffer_type() {
|
||||||
if lesser_key.flexbuffer_type().is_heterogenous_vector()
|
|
||||||
&& lesser_key.as_vector().len() == 0
|
|
||||||
&& greater_key.flexbuffer_type().is_vector()
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if !lesser_key.flexbuffer_type().is_null()
|
|
||||||
&& lesser_key.flexbuffer_type() != greater_key.flexbuffer_type()
|
|
||||||
{
|
|
||||||
return Err(flexbuffers::ReaderError::InvalidPackedType {}.into());
|
return Err(flexbuffers::ReaderError::InvalidPackedType {}.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,14 +47,6 @@ impl Mask {
|
|||||||
.map_err(|_| eyre!("Mask is not a valid map"))
|
.map_err(|_| eyre!("Mask is not a valid map"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Display for Mask {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
flexbuffers::Reader::get_root(self.0.as_slice())
|
|
||||||
.unwrap()
|
|
||||||
.to_string()
|
|
||||||
.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct SendDataInfo<'a> {
|
struct SendDataInfo<'a> {
|
||||||
@@ -195,9 +169,7 @@ impl PulseSender {
|
|||||||
data_mask.get_mask()?;
|
data_mask.get_mask()?;
|
||||||
ensure!(
|
ensure!(
|
||||||
mask_matches(receiver_mask, &data_mask),
|
mask_matches(receiver_mask, &data_mask),
|
||||||
"Message ({}) does not contain the same keys as the receiver's mask ({})",
|
"Message does not contain the same keys as the receiver's mask"
|
||||||
data_mask,
|
|
||||||
receiver_mask
|
|
||||||
);
|
);
|
||||||
receiver.send_data(&node.pulse_sender.get().unwrap().uid, data_mask.0)
|
receiver.send_data(&node.pulse_sender.get().unwrap().uid, data_mask.0)
|
||||||
}
|
}
|
||||||
@@ -257,8 +229,6 @@ pub fn create_interface(client: &Arc<Client>) -> Result<()> {
|
|||||||
let node = Node::create(client, "", "data", false);
|
let node = Node::create(client, "", "data", false);
|
||||||
node.add_local_signal("create_pulse_sender", create_pulse_sender_flex);
|
node.add_local_signal("create_pulse_sender", create_pulse_sender_flex);
|
||||||
node.add_local_signal("create_pulse_receiver", create_pulse_receiver_flex);
|
node.add_local_signal("create_pulse_receiver", create_pulse_receiver_flex);
|
||||||
node.add_local_method("register_keymap", register_keymap_flex);
|
|
||||||
node.add_local_method("get_keymap", get_keymap_flex);
|
|
||||||
node.add_to_scenegraph().map(|_| ())
|
node.add_to_scenegraph().map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,42 +284,3 @@ pub fn create_pulse_receiver_flex(
|
|||||||
PulseReceiver::add_to(&node, field, mask)?;
|
PulseReceiver::add_to(&node, field, mask)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_keymap_flex(
|
|
||||||
_node: &Node,
|
|
||||||
_calling_client: Arc<Client>,
|
|
||||||
message: Message,
|
|
||||||
response: MethodResponseSender,
|
|
||||||
) {
|
|
||||||
response.wrap_sync(move || {
|
|
||||||
let keymap: String = deserialize(message.as_ref())?;
|
|
||||||
let mut keymaps = KEYMAPS.lock();
|
|
||||||
if let Some(found_keymap_id) = keymaps
|
|
||||||
.iter()
|
|
||||||
.filter(|(_k, v)| *v == &keymap)
|
|
||||||
.map(|(k, _v)| k)
|
|
||||||
.last()
|
|
||||||
{
|
|
||||||
return Ok(serialize(found_keymap_id)?.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let generated_id = nanoid!();
|
|
||||||
keymaps.insert(generated_id.clone(), keymap);
|
|
||||||
|
|
||||||
Ok(serialize(generated_id)?.into())
|
|
||||||
});
|
|
||||||
}
|
|
||||||
pub fn get_keymap_flex(
|
|
||||||
_node: &Node,
|
|
||||||
_calling_client: Arc<Client>,
|
|
||||||
message: Message,
|
|
||||||
response: MethodResponseSender,
|
|
||||||
) {
|
|
||||||
response.wrap_sync(move || {
|
|
||||||
let keymap_id: &str = deserialize(message.as_ref())?;
|
|
||||||
let keymaps = KEYMAPS.lock();
|
|
||||||
let Some(keymap) = keymaps.get(keymap_id) else {bail!("Could not find keymap. Try registering it")};
|
|
||||||
|
|
||||||
Ok(serialize(keymap)?.into())
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use once_cell::sync::OnceCell;
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use portable_atomic::{AtomicBool, Ordering};
|
use portable_atomic::{AtomicBool, Ordering};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
use send_wrapper::SendWrapper;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use stardust_xr::schemas::flex::deserialize;
|
use stardust_xr::schemas::flex::deserialize;
|
||||||
use stardust_xr::values::Transform;
|
use stardust_xr::values::Transform;
|
||||||
@@ -121,7 +122,7 @@ pub struct ModelPart {
|
|||||||
space: Arc<Spatial>,
|
space: Arc<Spatial>,
|
||||||
model: Weak<Model>,
|
model: Weak<Model>,
|
||||||
pending_material_parameters: Mutex<FxHashMap<String, MaterialParameter>>,
|
pending_material_parameters: Mutex<FxHashMap<String, MaterialParameter>>,
|
||||||
pending_material_replacement: Mutex<Option<Arc<Material>>>,
|
pending_material_replacement: Mutex<Option<Arc<SendWrapper<Material>>>>,
|
||||||
}
|
}
|
||||||
impl ModelPart {
|
impl ModelPart {
|
||||||
fn create_for_model(sk: &impl StereoKitMultiThread, model: &Arc<Model>, sk_model: &SKModel) {
|
fn create_for_model(sk: &impl StereoKitMultiThread, model: &Arc<Model>, sk_model: &SKModel) {
|
||||||
@@ -227,7 +228,7 @@ impl ModelPart {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replace_material(&self, replacement: Arc<Material>) {
|
pub fn replace_material(&self, replacement: Arc<SendWrapper<Material>>) {
|
||||||
self.pending_material_replacement
|
self.pending_material_replacement
|
||||||
.lock()
|
.lock()
|
||||||
.replace(replacement);
|
.replace(replacement);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use smithay::backend::renderer::gles::{
|
use smithay::backend::renderer::gles::{
|
||||||
ffi::{self, Gles2, FRAGMENT_SHADER, VERTEX_SHADER},
|
ffi::{self, Gles2, FRAGMENT_SHADER, VERTEX_SHADER},
|
||||||
GlesError,
|
GlesError,
|
||||||
@@ -7,12 +8,6 @@ use std::mem::transmute;
|
|||||||
use stereokit::Shader;
|
use stereokit::Shader;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
// Simula shader with fancy lanzcos sampling
|
|
||||||
pub const UNLIT_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_gamma.sks");
|
|
||||||
|
|
||||||
// Simula shader with fancy lanzcos sampling
|
|
||||||
pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_simula.sks");
|
|
||||||
|
|
||||||
struct FfiAssetHeader {
|
struct FfiAssetHeader {
|
||||||
asset_type: i32,
|
asset_type: i32,
|
||||||
asset_state: i32,
|
asset_state: i32,
|
||||||
@@ -13,6 +13,7 @@ use once_cell::sync::OnceCell;
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use portable_atomic::{AtomicBool, Ordering};
|
use portable_atomic::{AtomicBool, Ordering};
|
||||||
use prisma::{Flatten, Rgba};
|
use prisma::{Flatten, Rgba};
|
||||||
|
use send_wrapper::SendWrapper;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use stardust_xr::{schemas::flex::deserialize, values::Transform};
|
use stardust_xr::{schemas::flex::deserialize, values::Transform};
|
||||||
use std::{ffi::OsStr, path::PathBuf, sync::Arc};
|
use std::{ffi::OsStr, path::PathBuf, sync::Arc};
|
||||||
@@ -34,7 +35,7 @@ pub struct Text {
|
|||||||
enabled: Arc<AtomicBool>,
|
enabled: Arc<AtomicBool>,
|
||||||
space: Arc<Spatial>,
|
space: Arc<Spatial>,
|
||||||
font_path: Option<PathBuf>,
|
font_path: Option<PathBuf>,
|
||||||
style: OnceCell<TextStyle>,
|
style: OnceCell<SendWrapper<TextStyle>>,
|
||||||
|
|
||||||
data: Mutex<TextData>,
|
data: Mutex<TextData>,
|
||||||
}
|
}
|
||||||
@@ -90,16 +91,18 @@ impl Text {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&self, sk: &impl StereoKitDraw) {
|
fn draw(&self, sk: &impl StereoKitDraw) {
|
||||||
let style = self
|
let style = self.style.get_or_try_init(
|
||||||
.style
|
|| -> Result<SendWrapper<TextStyle>, color_eyre::eyre::Error> {
|
||||||
.get_or_try_init(|| -> Result<TextStyle, color_eyre::eyre::Error> {
|
|
||||||
let font = self
|
let font = self
|
||||||
.font_path
|
.font_path
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.and_then(|path| sk.font_create(path).ok())
|
.and_then(|path| sk.font_create(path).ok())
|
||||||
.unwrap_or_else(|| sk.font_find("default/font").unwrap());
|
.unwrap_or_else(|| sk.font_find("default/font").unwrap());
|
||||||
Ok(unsafe { sk.text_make_style(font, 1.0, WHITE) })
|
Ok(SendWrapper::new(unsafe {
|
||||||
});
|
sk.text_make_style(font, 1.0, WHITE)
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if let Ok(style) = style {
|
if let Ok(style) = style {
|
||||||
let data = self.data.lock();
|
let data = self.data.lock();
|
||||||
@@ -115,7 +118,7 @@ impl Text {
|
|||||||
transform,
|
transform,
|
||||||
bounds / data.character_height,
|
bounds / data.character_height,
|
||||||
data.fit,
|
data.fit,
|
||||||
*style,
|
**style,
|
||||||
data.bounds_align,
|
data.bounds_align,
|
||||||
data.text_align,
|
data.text_align,
|
||||||
vec3(0.0, 0.0, 0.0),
|
vec3(0.0, 0.0, 0.0),
|
||||||
@@ -130,7 +133,7 @@ impl Text {
|
|||||||
sk.text_add_at(
|
sk.text_add_at(
|
||||||
&data.text,
|
&data.text,
|
||||||
transform,
|
transform,
|
||||||
*style,
|
**style,
|
||||||
data.bounds_align,
|
data.bounds_align,
|
||||||
data.text_align,
|
data.text_align,
|
||||||
vec3(0.0, 0.0, 0.0),
|
vec3(0.0, 0.0, 0.0),
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use super::alias::AliasInfo;
|
|||||||
use super::spatial::Spatial;
|
use super::spatial::Spatial;
|
||||||
use super::{Message, Node};
|
use super::{Message, Node};
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::core::scenegraph::MethodResponseSender;
|
|
||||||
use crate::nodes::spatial::find_reference_space;
|
use crate::nodes::spatial::find_reference_space;
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use glam::{vec2, vec3a, Vec3, Vec3A};
|
use glam::{vec2, vec3a, Vec3, Vec3A};
|
||||||
@@ -138,94 +137,84 @@ fn field_distance_flex(
|
|||||||
node: &Node,
|
node: &Node,
|
||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
message: Message,
|
message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message> {
|
||||||
) {
|
#[derive(Deserialize)]
|
||||||
response.wrap_sync(move || {
|
struct FieldInfoArgs<'a> {
|
||||||
#[derive(Deserialize)]
|
reference_space_path: &'a str,
|
||||||
struct FieldInfoArgs<'a> {
|
point: Vector3<f32>,
|
||||||
reference_space_path: &'a str,
|
}
|
||||||
point: Vector3<f32>,
|
let args: FieldInfoArgs = deserialize(message.as_ref())?;
|
||||||
}
|
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
||||||
let args: FieldInfoArgs = deserialize(message.as_ref())?;
|
|
||||||
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
|
||||||
|
|
||||||
let distance = node
|
let distance = node
|
||||||
.field
|
.field
|
||||||
.get()
|
.get()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.distance(reference_space.as_ref(), args.point.into());
|
.distance(reference_space.as_ref(), args.point.into());
|
||||||
Ok(serialize(distance)?.into())
|
Ok(serialize(distance)?.into())
|
||||||
});
|
|
||||||
}
|
}
|
||||||
fn field_normal_flex(
|
fn field_normal_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
message: Message,
|
message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message> {
|
||||||
) {
|
#[derive(Deserialize)]
|
||||||
response.wrap_sync(move || {
|
struct FieldInfoArgs<'a> {
|
||||||
#[derive(Deserialize)]
|
reference_space_path: &'a str,
|
||||||
struct FieldInfoArgs<'a> {
|
point: Vector3<f32>,
|
||||||
reference_space_path: &'a str,
|
radius: Option<f32>,
|
||||||
point: Vector3<f32>,
|
}
|
||||||
}
|
let args: FieldInfoArgs = deserialize(message.as_ref())?;
|
||||||
let args: FieldInfoArgs = deserialize(message.as_ref())?;
|
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
||||||
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
|
||||||
|
|
||||||
let normal = node.field.get().as_ref().unwrap().normal(
|
let normal = node.field.get().as_ref().unwrap().normal(
|
||||||
reference_space.as_ref(),
|
reference_space.as_ref(),
|
||||||
args.point.into(),
|
args.point.into(),
|
||||||
0.001,
|
args.radius.unwrap_or(0.001),
|
||||||
);
|
);
|
||||||
Ok(serialize(mint::Vector3::from(normal))?.into())
|
Ok(serialize(mint::Vector3::from(normal))?.into())
|
||||||
});
|
|
||||||
}
|
}
|
||||||
fn field_closest_point_flex(
|
fn field_closest_point_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
message: Message,
|
message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message> {
|
||||||
) {
|
#[derive(Deserialize)]
|
||||||
response.wrap_sync(move || {
|
struct FieldInfoArgs<'a> {
|
||||||
#[derive(Deserialize)]
|
reference_space_path: &'a str,
|
||||||
struct FieldInfoArgs<'a> {
|
point: Vector3<f32>,
|
||||||
reference_space_path: &'a str,
|
radius: Option<f32>,
|
||||||
point: Vector3<f32>,
|
}
|
||||||
}
|
let args: FieldInfoArgs = deserialize(message.as_ref())?;
|
||||||
let args: FieldInfoArgs = deserialize(message.as_ref())?;
|
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
||||||
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
|
||||||
|
|
||||||
let closest_point = node.field.get().as_ref().unwrap().closest_point(
|
let closest_point = node.field.get().as_ref().unwrap().closest_point(
|
||||||
reference_space.as_ref(),
|
reference_space.as_ref(),
|
||||||
args.point.into(),
|
args.point.into(),
|
||||||
0.001,
|
args.radius.unwrap_or(0.001),
|
||||||
);
|
);
|
||||||
Ok(serialize(mint::Vector3::from(closest_point))?.into())
|
Ok(serialize(mint::Vector3::from(closest_point))?.into())
|
||||||
});
|
|
||||||
}
|
}
|
||||||
fn field_ray_march_flex(
|
fn field_ray_march_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
message: Message,
|
message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message> {
|
||||||
) {
|
#[derive(Deserialize)]
|
||||||
response.wrap_sync(move || {
|
struct FieldInfoArgs<'a> {
|
||||||
#[derive(Deserialize)]
|
reference_space_path: &'a str,
|
||||||
struct FieldInfoArgs<'a> {
|
ray_origin: Vector3<f32>,
|
||||||
reference_space_path: &'a str,
|
ray_direction: Vector3<f32>,
|
||||||
ray_origin: Vector3<f32>,
|
}
|
||||||
ray_direction: Vector3<f32>,
|
let args: FieldInfoArgs = deserialize(message.as_ref())?;
|
||||||
}
|
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
||||||
let args: FieldInfoArgs = deserialize(message.as_ref())?;
|
|
||||||
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
|
||||||
|
|
||||||
let ray_march_result = node.field.get().unwrap().ray_march(Ray {
|
let ray_march_result = node.field.get().unwrap().ray_march(Ray {
|
||||||
origin: args.ray_origin.into(),
|
origin: args.ray_origin.into(),
|
||||||
direction: args.ray_direction.into(),
|
direction: args.ray_direction.into(),
|
||||||
space: reference_space,
|
space: reference_space,
|
||||||
});
|
|
||||||
Ok(serialize(ray_march_result)?.into())
|
|
||||||
});
|
});
|
||||||
|
Ok(serialize(ray_march_result)?.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Field {
|
pub enum Field {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use color_eyre::eyre::Result;
|
|||||||
use glam::{vec3, Mat4};
|
use glam::{vec3, Mat4};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use stereokit::StereoKitMultiThread;
|
use stereokit::StereoKitMultiThread;
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref HMD: Arc<Node> = create();
|
static ref HMD: Arc<Node> = create();
|
||||||
@@ -19,6 +20,7 @@ fn create() -> Arc<Node> {
|
|||||||
node
|
node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", name = "Update HMD Pose", skip(sk))]
|
||||||
pub fn frame(sk: &impl StereoKitMultiThread) {
|
pub fn frame(sk: &impl StereoKitMultiThread) {
|
||||||
let spatial = HMD
|
let spatial = HMD
|
||||||
.spatial
|
.spatial
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ impl InputSpecialization for Hand {
|
|||||||
}
|
}
|
||||||
fn serialize(
|
fn serialize(
|
||||||
&self,
|
&self,
|
||||||
distance_link: &DistanceLink,
|
_distance_link: &DistanceLink,
|
||||||
local_to_handler_matrix: Mat4,
|
local_to_handler_matrix: Mat4,
|
||||||
) -> InputDataType {
|
) -> InputDataType {
|
||||||
let mut hand = self.base;
|
let mut hand = self.base;
|
||||||
@@ -68,10 +68,6 @@ impl InputSpecialization for Hand {
|
|||||||
let (_, rotation, position) = joint_matrix.to_scale_rotation_translation();
|
let (_, rotation, position) = joint_matrix.to_scale_rotation_translation();
|
||||||
joint.position = position.into();
|
joint.position = position.into();
|
||||||
joint.rotation = rotation.into();
|
joint.rotation = rotation.into();
|
||||||
joint.distance = distance_link
|
|
||||||
.handler
|
|
||||||
.field
|
|
||||||
.distance(&distance_link.handler.spatial, position.into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InputDataType::Hand(Box::new(hand))
|
InputDataType::Hand(Box::new(hand))
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ use super::{
|
|||||||
spatial::{find_spatial_parent, parse_transform, Spatial},
|
spatial::{find_spatial_parent, parse_transform, Spatial},
|
||||||
Message, Node,
|
Message, Node,
|
||||||
};
|
};
|
||||||
use crate::core::registry::Registry;
|
|
||||||
use crate::core::{client::Client, node_collections::LifeLinkedNodeMap};
|
use crate::core::{client::Client, node_collections::LifeLinkedNodeMap};
|
||||||
|
use crate::core::{node_collections::LifeLinkedNodeList, registry::Registry};
|
||||||
use color_eyre::eyre::{ensure, Result};
|
use color_eyre::eyre::{ensure, Result};
|
||||||
use glam::Mat4;
|
use glam::Mat4;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
@@ -99,7 +99,6 @@ impl InputMethod {
|
|||||||
};
|
};
|
||||||
for handler in INPUT_HANDLER_REGISTRY.get_valid_contents() {
|
for handler in INPUT_HANDLER_REGISTRY.get_valid_contents() {
|
||||||
method.handle_new_handler(&handler);
|
method.handle_new_handler(&handler);
|
||||||
method.make_alias(&handler);
|
|
||||||
}
|
}
|
||||||
let method = INPUT_METHOD_REGISTRY.add(method);
|
let method = INPUT_METHOD_REGISTRY.add(method);
|
||||||
let _ = node.input_method.set(method.clone());
|
let _ = node.input_method.set(method.clone());
|
||||||
@@ -138,26 +137,6 @@ impl InputMethod {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_alias(&self, handler: &InputHandler) {
|
|
||||||
let Some(method_node) = self.node.upgrade() else {return};
|
|
||||||
let Some(handler_node) = handler.node.upgrade() else {return};
|
|
||||||
let Some(client) = handler_node.get_client() else {return};
|
|
||||||
let Ok(method_alias) = Alias::create(
|
|
||||||
&client,
|
|
||||||
handler_node.get_path(),
|
|
||||||
&self.uid,
|
|
||||||
&method_node,
|
|
||||||
AliasInfo {
|
|
||||||
server_signals: vec!["capture"],
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
) else {return};
|
|
||||||
method_alias.enabled.store(false, Ordering::Relaxed);
|
|
||||||
handler
|
|
||||||
.method_aliases
|
|
||||||
.add(self as *const InputMethod as usize, &method_alias);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compare_distance(&self, to: &Field) -> f32 {
|
fn compare_distance(&self, to: &Field) -> f32 {
|
||||||
self.specialization
|
self.specialization
|
||||||
.lock()
|
.lock()
|
||||||
@@ -222,12 +201,25 @@ pub struct DistanceLink {
|
|||||||
handler: Arc<InputHandler>,
|
handler: Arc<InputHandler>,
|
||||||
}
|
}
|
||||||
impl DistanceLink {
|
impl DistanceLink {
|
||||||
fn from(method: Arc<InputMethod>, handler: Arc<InputHandler>) -> Self {
|
fn from(method: Arc<InputMethod>, handler: Arc<InputHandler>) -> Option<Self> {
|
||||||
DistanceLink {
|
let handler_node = handler.node.upgrade()?;
|
||||||
|
let method_alias = Alias::create(
|
||||||
|
&handler_node.get_client()?,
|
||||||
|
handler_node.get_path(),
|
||||||
|
&method.uid,
|
||||||
|
&method.node.upgrade()?,
|
||||||
|
AliasInfo {
|
||||||
|
server_signals: vec!["capture"],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.ok()?;
|
||||||
|
handler.method_aliases.add(Arc::downgrade(&method_alias));
|
||||||
|
Some(DistanceLink {
|
||||||
distance: method.compare_distance(&handler.field),
|
distance: method.compare_distance(&handler.field),
|
||||||
method,
|
method,
|
||||||
handler,
|
handler,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_input(&self, order: u32, datamap: Datamap) {
|
fn send_input(&self, order: u32, datamap: Datamap) {
|
||||||
@@ -257,7 +249,7 @@ pub struct InputHandler {
|
|||||||
node: Weak<Node>,
|
node: Weak<Node>,
|
||||||
spatial: Arc<Spatial>,
|
spatial: Arc<Spatial>,
|
||||||
field: Arc<Field>,
|
field: Arc<Field>,
|
||||||
method_aliases: LifeLinkedNodeMap<usize>,
|
method_aliases: LifeLinkedNodeList,
|
||||||
}
|
}
|
||||||
impl InputHandler {
|
impl InputHandler {
|
||||||
pub fn add_to(node: &Arc<Node>, field: &Arc<Field>) -> Result<()> {
|
pub fn add_to(node: &Arc<Node>, field: &Arc<Field>) -> Result<()> {
|
||||||
@@ -272,10 +264,9 @@ impl InputHandler {
|
|||||||
node: Arc::downgrade(node),
|
node: Arc::downgrade(node),
|
||||||
spatial: node.spatial.get().unwrap().clone(),
|
spatial: node.spatial.get().unwrap().clone(),
|
||||||
field: field.clone(),
|
field: field.clone(),
|
||||||
method_aliases: LifeLinkedNodeMap::default(),
|
method_aliases: LifeLinkedNodeList::default(),
|
||||||
};
|
};
|
||||||
for method in INPUT_METHOD_REGISTRY.get_valid_contents() {
|
for method in INPUT_METHOD_REGISTRY.get_valid_contents() {
|
||||||
method.make_alias(&handler);
|
|
||||||
method.handle_new_handler(&handler);
|
method.handle_new_handler(&handler);
|
||||||
}
|
}
|
||||||
let handler = INPUT_HANDLER_REGISTRY.add(handler);
|
let handler = INPUT_HANDLER_REGISTRY.add(handler);
|
||||||
@@ -352,12 +343,10 @@ pub fn process_input() {
|
|||||||
.filter(|method| method.datamap.lock().is_some())
|
.filter(|method| method.datamap.lock().is_some())
|
||||||
});
|
});
|
||||||
let handlers = INPUT_HANDLER_REGISTRY.get_valid_contents();
|
let handlers = INPUT_HANDLER_REGISTRY.get_valid_contents();
|
||||||
const LIMIT: usize = 50;
|
for handler in &handlers {
|
||||||
|
handler.method_aliases.clear();
|
||||||
|
}
|
||||||
for method in methods {
|
for method in methods {
|
||||||
for alias in method.node.upgrade().unwrap().aliases.get_valid_contents() {
|
|
||||||
alias.enabled.store(false, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug_span!("Process input method").in_scope(|| {
|
debug_span!("Process input method").in_scope(|| {
|
||||||
// Get all valid input handlers and convert them to DistanceLink objects
|
// Get all valid input handlers and convert them to DistanceLink objects
|
||||||
let distance_links: Vec<DistanceLink> = debug_span!("Generate distance links")
|
let distance_links: Vec<DistanceLink> = debug_span!("Generate distance links")
|
||||||
@@ -368,16 +357,14 @@ pub fn process_input() {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter_map(|h| h.upgrade())
|
.filter_map(|h| h.upgrade())
|
||||||
.filter(|handler| handler.enabled.load(Ordering::Relaxed))
|
.filter(|handler| handler.enabled.load(Ordering::Relaxed))
|
||||||
.map(|handler| DistanceLink::from(method.clone(), handler))
|
.filter_map(|handler| DistanceLink::from(method.clone(), handler))
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
let mut distance_links: Vec<_> = handlers
|
let mut distance_links: Vec<_> = handlers
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|handler| handler.enabled.load(Ordering::Relaxed))
|
.filter(|handler| handler.enabled.load(Ordering::Relaxed))
|
||||||
.map(|handler| {
|
.filter_map(|handler| {
|
||||||
debug_span!("Create distance link").in_scope(|| {
|
DistanceLink::from(method.clone(), handler.clone())
|
||||||
DistanceLink::from(method.clone(), handler.clone())
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -388,7 +375,6 @@ pub fn process_input() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
distance_links.truncate(LIMIT);
|
|
||||||
distance_links
|
distance_links
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -396,18 +382,6 @@ pub fn process_input() {
|
|||||||
let captures = method.captures.take_valid_contents();
|
let captures = method.captures.take_valid_contents();
|
||||||
// Iterate over the distance links and send input to them
|
// Iterate over the distance links and send input to them
|
||||||
for (i, distance_link) in distance_links.into_iter().enumerate() {
|
for (i, distance_link) in distance_links.into_iter().enumerate() {
|
||||||
if i > LIMIT {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(method_alias) = distance_link
|
|
||||||
.handler
|
|
||||||
.method_aliases
|
|
||||||
.get(&(Arc::as_ptr(&distance_link.method) as usize))
|
|
||||||
.and_then(|a| a.alias.get().cloned())
|
|
||||||
{
|
|
||||||
method_alias.enabled.store(true, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
distance_link.send_input(i as u32, method.datamap.lock().clone().unwrap());
|
distance_link.send_input(i as u32, method.datamap.lock().clone().unwrap());
|
||||||
|
|
||||||
// If the current distance link is in the list of captured input handlers,
|
// If the current distance link is in the list of captured input handlers,
|
||||||
|
|||||||
@@ -34,13 +34,9 @@ impl Pointer {
|
|||||||
impl InputSpecialization for Pointer {
|
impl InputSpecialization for Pointer {
|
||||||
fn compare_distance(&self, space: &Arc<Spatial>, field: &Field) -> f32 {
|
fn compare_distance(&self, space: &Arc<Spatial>, field: &Field) -> f32 {
|
||||||
let ray_info = self.ray_march(space, field);
|
let ray_info = self.ray_march(space, field);
|
||||||
if ray_info.min_distance > 0.0 {
|
ray_info
|
||||||
ray_info.deepest_point_distance + 1000.0
|
.deepest_point_distance
|
||||||
} else {
|
.hypot(ray_info.min_distance.recip())
|
||||||
ray_info
|
|
||||||
.deepest_point_distance
|
|
||||||
.hypot(0.001 / ray_info.min_distance)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fn true_distance(&self, space: &Arc<Spatial>, field: &Field) -> f32 {
|
fn true_distance(&self, space: &Arc<Spatial>, field: &Field) -> f32 {
|
||||||
let ray_info = self.ray_march(space, field);
|
let ray_info = self.ray_march(space, field);
|
||||||
|
|||||||
@@ -1,357 +0,0 @@
|
|||||||
use super::{Item, ItemType};
|
|
||||||
use crate::{
|
|
||||||
core::{
|
|
||||||
buffers::BufferManager,
|
|
||||||
client::{Client, INTERNAL_CLIENT},
|
|
||||||
registry::Registry,
|
|
||||||
scenegraph::MethodResponseSender,
|
|
||||||
},
|
|
||||||
nodes::{
|
|
||||||
drawable::{model::ModelPart, shaders::UNLIT_SHADER_BYTES, Drawable},
|
|
||||||
items::TypeInfo,
|
|
||||||
spatial::{find_spatial_parent, parse_transform, Spatial},
|
|
||||||
Message, Node,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use color_eyre::eyre::{bail, Result};
|
|
||||||
use glam::Mat4;
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use mint::{RowMatrix4, Vector2};
|
|
||||||
use nanoid::nanoid;
|
|
||||||
use once_cell::sync::OnceCell;
|
|
||||||
use parking_lot::Mutex;
|
|
||||||
use serde::Deserialize;
|
|
||||||
use smithay::backend::{
|
|
||||||
allocator::{
|
|
||||||
dmabuf::{Dmabuf, DmabufFlags},
|
|
||||||
Buffer,
|
|
||||||
},
|
|
||||||
renderer::ImportDma,
|
|
||||||
};
|
|
||||||
use stardust_xr::{
|
|
||||||
scenegraph::ScenegraphError,
|
|
||||||
schemas::flex::{deserialize, serialize},
|
|
||||||
values::{BufferInfo, Transform},
|
|
||||||
};
|
|
||||||
use std::{ffi::c_void, sync::Arc};
|
|
||||||
use stereokit::{
|
|
||||||
Color128, Material, Rect, RenderLayer, StereoKitDraw, Tex, TextureFormat, TextureType,
|
|
||||||
Transparency,
|
|
||||||
};
|
|
||||||
use tokio::sync::mpsc::{self, error::SendError};
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
pub(super) static ref ITEM_TYPE_INFO_CAMERA: TypeInfo = TypeInfo {
|
|
||||||
type_name: "camera",
|
|
||||||
aliased_local_signals: vec!["apply_preview_material", "set_proj_matrix"],
|
|
||||||
aliased_local_methods: vec!["render"],
|
|
||||||
aliased_remote_signals: vec![],
|
|
||||||
ui: Default::default(),
|
|
||||||
items: Registry::new(),
|
|
||||||
acceptors: Registry::new(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct FrameInfo {
|
|
||||||
proj_matrix: Mat4,
|
|
||||||
preview_size: Vector2<u32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CameraItem {
|
|
||||||
space: Arc<Spatial>,
|
|
||||||
frame_info: Mutex<FrameInfo>,
|
|
||||||
sk_tex: OnceCell<Tex>,
|
|
||||||
sk_mat: OnceCell<Arc<Material>>,
|
|
||||||
render_requests_tx: mpsc::UnboundedSender<(Dmabuf, MethodResponseSender)>,
|
|
||||||
render_requests_rx: Mutex<mpsc::UnboundedReceiver<(Dmabuf, MethodResponseSender)>>,
|
|
||||||
rendered_notifiers: Mutex<Vec<MethodResponseSender>>,
|
|
||||||
applied_preview_to: Registry<ModelPart>,
|
|
||||||
apply_preview_to: Registry<ModelPart>,
|
|
||||||
}
|
|
||||||
impl CameraItem {
|
|
||||||
pub fn add_to(node: &Arc<Node>, proj_matrix: Mat4, preview_size: Vector2<u32>) {
|
|
||||||
let (render_requests_tx, render_requests_rx) = mpsc::unbounded_channel();
|
|
||||||
let camera_specialization = CameraItem {
|
|
||||||
space: node.spatial.get().unwrap().clone(),
|
|
||||||
frame_info: Mutex::new(FrameInfo {
|
|
||||||
proj_matrix,
|
|
||||||
preview_size,
|
|
||||||
}),
|
|
||||||
sk_tex: OnceCell::new(),
|
|
||||||
sk_mat: OnceCell::new(),
|
|
||||||
render_requests_tx,
|
|
||||||
render_requests_rx: Mutex::new(render_requests_rx),
|
|
||||||
rendered_notifiers: Mutex::new(Vec::new()),
|
|
||||||
applied_preview_to: Registry::new(),
|
|
||||||
apply_preview_to: Registry::new(),
|
|
||||||
};
|
|
||||||
Item::add_to(
|
|
||||||
node,
|
|
||||||
nanoid!(),
|
|
||||||
&ITEM_TYPE_INFO_CAMERA,
|
|
||||||
ItemType::Camera(camera_specialization),
|
|
||||||
);
|
|
||||||
node.add_local_method("render", CameraItem::render_flex);
|
|
||||||
node.add_local_signal(
|
|
||||||
"apply_preview_material",
|
|
||||||
CameraItem::apply_preview_material_flex,
|
|
||||||
);
|
|
||||||
node.add_local_signal("set_proj_matrix", CameraItem::set_proj_matrix_flex);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_flex(
|
|
||||||
node: &Node,
|
|
||||||
_calling_client: Arc<Client>,
|
|
||||||
message: Message,
|
|
||||||
response: MethodResponseSender,
|
|
||||||
) {
|
|
||||||
let Some(item) = node.item.get() else {
|
|
||||||
let _ = response.send(Err(ScenegraphError::MethodError {
|
|
||||||
error: "Item not found".to_string(),
|
|
||||||
}));
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let ItemType::Camera(camera) = &item.specialization else {
|
|
||||||
let _ = response.send(Err(ScenegraphError::MethodError {
|
|
||||||
error: "Wrong item type?".to_string(),
|
|
||||||
}));
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let buffer_info: BufferInfo = match deserialize(&message.data) {
|
|
||||||
Ok(i) => i,
|
|
||||||
Err(e) => {
|
|
||||||
let _ = response.send(Err(ScenegraphError::MethodError {
|
|
||||||
error: e.to_string(),
|
|
||||||
}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let mut builder = Dmabuf::builder(
|
|
||||||
(buffer_info.width as i32, buffer_info.height as i32),
|
|
||||||
buffer_info.fourcc.try_into().unwrap(),
|
|
||||||
DmabufFlags::from_bits_truncate(buffer_info.flags),
|
|
||||||
);
|
|
||||||
for (fd, plane) in message.fds.into_iter().zip(buffer_info.planes) {
|
|
||||||
builder.add_plane(
|
|
||||||
fd,
|
|
||||||
plane.idx,
|
|
||||||
plane.offset,
|
|
||||||
plane.stride,
|
|
||||||
plane.modifier.try_into().unwrap(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let buffer_to_render = builder.build().unwrap();
|
|
||||||
|
|
||||||
if let Err(SendError((_dmabuf, sender))) =
|
|
||||||
camera.render_requests_tx.send((buffer_to_render, response))
|
|
||||||
{
|
|
||||||
sender.send(Err(ScenegraphError::MethodError {
|
|
||||||
error: "Internal: sender broke????".to_string(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn apply_preview_material_flex(
|
|
||||||
node: &Node,
|
|
||||||
calling_client: Arc<Client>,
|
|
||||||
message: Message,
|
|
||||||
) -> Result<()> {
|
|
||||||
let Some(item) = node.item.get() else {
|
|
||||||
bail!("Item not found?")
|
|
||||||
};
|
|
||||||
let ItemType::Camera(camera) = &item.specialization else {
|
|
||||||
bail!("Wrong item type?")
|
|
||||||
};
|
|
||||||
|
|
||||||
let model_part_path = deserialize(&message.data)?;
|
|
||||||
let model_part_node = calling_client.get_node("Model part", model_part_path)?;
|
|
||||||
let Drawable::ModelPart(model_part) =
|
|
||||||
model_part_node.get_aspect("Model part", "model part", |n| &n.drawable)?
|
|
||||||
else {
|
|
||||||
bail!("Drawable is not a model node")
|
|
||||||
};
|
|
||||||
|
|
||||||
camera.applied_preview_to.add_raw(model_part);
|
|
||||||
camera.apply_preview_to.add_raw(model_part);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_proj_matrix_flex(
|
|
||||||
node: &Node,
|
|
||||||
_calling_client: Arc<Client>,
|
|
||||||
message: Message,
|
|
||||||
) -> Result<()> {
|
|
||||||
let Some(item) = node.item.get() else {
|
|
||||||
bail!("Item not found?")
|
|
||||||
};
|
|
||||||
let ItemType::Camera(camera) = &item.specialization else {
|
|
||||||
bail!("Wrong item type?")
|
|
||||||
};
|
|
||||||
|
|
||||||
let proj_matrix: RowMatrix4<f32> = deserialize(&message.data)?;
|
|
||||||
|
|
||||||
let mut frame_info = camera.frame_info.lock();
|
|
||||||
frame_info.proj_matrix = proj_matrix.into();
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn serialize_start_data(&self, id: &str) -> Result<Message> {
|
|
||||||
Ok(serialize(id)?.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(&self, sk: &impl StereoKitDraw, buffer_manager: &mut BufferManager) {
|
|
||||||
let frame_info = self.frame_info.lock();
|
|
||||||
self.render_preview(sk, &*frame_info);
|
|
||||||
self.render_dmabuf(sk, buffer_manager, &*frame_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_preview(&self, sk: &impl StereoKitDraw, frame_info: &FrameInfo) {
|
|
||||||
if !self.apply_preview_to.is_empty() {
|
|
||||||
let sk_tex = self.sk_tex.get_or_init(|| {
|
|
||||||
sk.tex_gen_color(
|
|
||||||
Color128::default(),
|
|
||||||
frame_info.preview_size.x as i32,
|
|
||||||
frame_info.preview_size.y as i32,
|
|
||||||
TextureType::RENDER_TARGET,
|
|
||||||
TextureFormat::RGBA32Linear,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
let sk_mat = self.sk_mat.get_or_init(|| {
|
|
||||||
let shader = sk.shader_create_mem(&UNLIT_SHADER_BYTES).unwrap();
|
|
||||||
let mat = sk.material_create(&shader);
|
|
||||||
sk.material_set_texture(&mat, "diffuse", sk_tex.as_ref());
|
|
||||||
sk.material_set_transparency(&mat, Transparency::Blend);
|
|
||||||
Arc::new(mat)
|
|
||||||
});
|
|
||||||
for model_part in self.apply_preview_to.take_valid_contents() {
|
|
||||||
model_part.replace_material(sk_mat.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !self.applied_preview_to.is_empty() {
|
|
||||||
sk.render_to(
|
|
||||||
self.sk_tex.get().unwrap(),
|
|
||||||
self.space.global_transform(),
|
|
||||||
frame_info.proj_matrix,
|
|
||||||
RenderLayer::all(),
|
|
||||||
stereokit::RenderClear::All,
|
|
||||||
Rect {
|
|
||||||
x: 0.0,
|
|
||||||
y: 0.0,
|
|
||||||
w: 0.0,
|
|
||||||
h: 0.0,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_dmabuf(
|
|
||||||
&self,
|
|
||||||
sk: &impl StereoKitDraw,
|
|
||||||
buffer_manager: &mut BufferManager,
|
|
||||||
frame_info: &FrameInfo,
|
|
||||||
) {
|
|
||||||
let mut render_notifiers = self.rendered_notifiers.lock();
|
|
||||||
let mut render_requests_rx = self.render_requests_rx.lock();
|
|
||||||
while let Ok((buffer_to_render, render_response_sender)) = render_requests_rx.try_recv() {
|
|
||||||
let imported_dmabuf = buffer_manager
|
|
||||||
.renderer
|
|
||||||
.import_dmabuf(&buffer_to_render, None);
|
|
||||||
let smithay_tex = match imported_dmabuf {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(e) => {
|
|
||||||
let _ = render_response_sender.send(Err(ScenegraphError::MethodError {
|
|
||||||
error: e.to_string(),
|
|
||||||
}));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let sk_tex = sk.tex_create(TextureType::IMAGE_NO_MIPS, TextureFormat::RGBA32);
|
|
||||||
unsafe {
|
|
||||||
sk.tex_set_surface(
|
|
||||||
&sk_tex,
|
|
||||||
smithay_tex.tex_id() as usize as *mut c_void,
|
|
||||||
TextureType::RENDER_TARGET,
|
|
||||||
smithay::backend::renderer::gles::ffi::SRGB8_ALPHA8.into(),
|
|
||||||
buffer_to_render.size().w,
|
|
||||||
buffer_to_render.size().h,
|
|
||||||
1,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
sk.render_to(
|
|
||||||
sk_tex,
|
|
||||||
self.space.global_transform(),
|
|
||||||
frame_info.proj_matrix,
|
|
||||||
RenderLayer::all(),
|
|
||||||
stereokit::RenderClear::All,
|
|
||||||
Rect {
|
|
||||||
x: 0.0,
|
|
||||||
y: 0.0,
|
|
||||||
w: 0.0,
|
|
||||||
h: 0.0,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
render_notifiers.push(render_response_sender);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn send_rendered(&self) {
|
|
||||||
for notifier in self.rendered_notifiers.lock().drain(..) {
|
|
||||||
let _ = notifier.send(Ok(Vec::new().into()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(sk: &impl StereoKitDraw, buffer_manager: &mut BufferManager) {
|
|
||||||
for camera in ITEM_TYPE_INFO_CAMERA.items.get_valid_contents() {
|
|
||||||
let ItemType::Camera(camera) = &camera.specialization else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
camera.update(sk, buffer_manager);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn send_rendered() {
|
|
||||||
for camera in ITEM_TYPE_INFO_CAMERA.items.get_valid_contents() {
|
|
||||||
let ItemType::Camera(camera) = &camera.specialization else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
camera.send_rendered();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn create_camera_item_flex(
|
|
||||||
_node: &Node,
|
|
||||||
calling_client: Arc<Client>,
|
|
||||||
message: Message,
|
|
||||||
) -> Result<()> {
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct CreateCameraItemInfo<'a> {
|
|
||||||
name: &'a str,
|
|
||||||
parent_path: &'a str,
|
|
||||||
transform: Transform,
|
|
||||||
proj_matrix: RowMatrix4<f32>,
|
|
||||||
preview_size: Vector2<u32>,
|
|
||||||
}
|
|
||||||
let info: CreateCameraItemInfo = deserialize(message.as_ref())?;
|
|
||||||
let parent_name = format!("/item/{}/item", ITEM_TYPE_INFO_CAMERA.type_name);
|
|
||||||
let space = find_spatial_parent(&calling_client, info.parent_path)?;
|
|
||||||
let transform = parse_transform(info.transform, true, true, false);
|
|
||||||
|
|
||||||
let node =
|
|
||||||
Node::create(&INTERNAL_CLIENT, &parent_name, info.name, false).add_to_scenegraph()?;
|
|
||||||
Spatial::add_to(&node, None, transform * space.global_transform(), false)?;
|
|
||||||
CameraItem::add_to(&node, info.proj_matrix.into(), info.preview_size);
|
|
||||||
// TODO: this means ANY client can render anywhere with no limits, this needs to be changed!!
|
|
||||||
node.item
|
|
||||||
.get()
|
|
||||||
.unwrap()
|
|
||||||
.make_alias_named(&calling_client, &parent_name, info.name)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ use crate::{
|
|||||||
core::{
|
core::{
|
||||||
client::{Client, INTERNAL_CLIENT},
|
client::{Client, INTERNAL_CLIENT},
|
||||||
registry::Registry,
|
registry::Registry,
|
||||||
scenegraph::MethodResponseSender,
|
|
||||||
},
|
},
|
||||||
nodes::{
|
nodes::{
|
||||||
items::TypeInfo,
|
items::TypeInfo,
|
||||||
@@ -51,14 +50,11 @@ impl EnvironmentItem {
|
|||||||
node: &Node,
|
node: &Node,
|
||||||
_calling_client: Arc<Client>,
|
_calling_client: Arc<Client>,
|
||||||
_message: Message,
|
_message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message> {
|
||||||
) {
|
let ItemType::Environment(environment_item) = &node.item.get().unwrap().specialization else {
|
||||||
response.wrap_sync(move || {
|
|
||||||
let ItemType::Environment(environment_item) = &node.item.get().unwrap().specialization else {
|
|
||||||
return Err(eyre!("Wrong item type?"))
|
return Err(eyre!("Wrong item type?"))
|
||||||
};
|
};
|
||||||
Ok(serialize(environment_item.path.as_str())?.into())
|
Ok(serialize(environment_item.path.as_str())?.into())
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize_start_data(&self, id: &str) -> Result<Message> {
|
pub fn serialize_start_data(&self, id: &str) -> Result<Message> {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
pub mod camera;
|
|
||||||
mod environment;
|
mod environment;
|
||||||
pub mod panel;
|
pub mod panel;
|
||||||
|
|
||||||
use self::camera::CameraItem;
|
|
||||||
use self::environment::{EnvironmentItem, ITEM_TYPE_INFO_ENVIRONMENT};
|
use self::environment::{EnvironmentItem, ITEM_TYPE_INFO_ENVIRONMENT};
|
||||||
use self::panel::{PanelItemTrait, ITEM_TYPE_INFO_PANEL};
|
use self::panel::{PanelItemTrait, ITEM_TYPE_INFO_PANEL};
|
||||||
use super::fields::Field;
|
use super::fields::Field;
|
||||||
@@ -39,8 +37,8 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn capture(item: &Arc<Item>, acceptor: &Arc<ItemAcceptor>) {
|
pub fn capture(item: &Arc<Item>, acceptor: &Arc<ItemAcceptor>) {
|
||||||
if item.captured_acceptor.lock().strong_count() > 0 {
|
if let Some(acceptor) = item.captured_acceptor.lock().upgrade() {
|
||||||
release(item);
|
release(item, Some(&acceptor));
|
||||||
}
|
}
|
||||||
*item.captured_acceptor.lock() = Arc::downgrade(acceptor);
|
*item.captured_acceptor.lock() = Arc::downgrade(acceptor);
|
||||||
acceptor.handle_capture(item);
|
acceptor.handle_capture(item);
|
||||||
@@ -48,9 +46,9 @@ pub fn capture(item: &Arc<Item>, acceptor: &Arc<ItemAcceptor>) {
|
|||||||
ui.handle_capture_item(item, acceptor);
|
ui.handle_capture_item(item, acceptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn release(item: &Item) {
|
fn release(item: &Item, acceptor: Option<&ItemAcceptor>) {
|
||||||
let mut captured_acceptor = item.captured_acceptor.lock();
|
let mut captured_acceptor = item.captured_acceptor.lock();
|
||||||
if let Some(acceptor) = captured_acceptor.upgrade().as_ref() {
|
if let Some(acceptor) = captured_acceptor.upgrade().as_deref().or(acceptor) {
|
||||||
*captured_acceptor = Weak::default();
|
*captured_acceptor = Weak::default();
|
||||||
acceptor.handle_release(item);
|
acceptor.handle_release(item);
|
||||||
if let Some(ui) = item.type_info.ui.lock().upgrade() {
|
if let Some(ui) = item.type_info.ui.lock().upgrade() {
|
||||||
@@ -109,15 +107,15 @@ impl Item {
|
|||||||
}
|
}
|
||||||
let _ = node.item.set(item.clone());
|
let _ = node.item.set(item.clone());
|
||||||
|
|
||||||
// if let Some(auto_acceptor) = node.get_client().and_then(|client| {
|
if let Some(auto_acceptor) = node.get_client().and_then(|client| {
|
||||||
// client
|
client
|
||||||
// .state
|
.startup_settings
|
||||||
// .as_ref()
|
.as_ref()
|
||||||
// .and_then(|settings| settings.acceptors.get(type_info))
|
.and_then(|settings| settings.acceptors.get(type_info))
|
||||||
// .and_then(|acceptor| acceptor.upgrade())
|
.and_then(|acceptor| acceptor.upgrade())
|
||||||
// }) {
|
}) {
|
||||||
// capture(&item, &auto_acceptor);
|
capture(&item, &auto_acceptor);
|
||||||
// }
|
}
|
||||||
|
|
||||||
item
|
item
|
||||||
}
|
}
|
||||||
@@ -157,7 +155,7 @@ impl Item {
|
|||||||
|
|
||||||
fn release_flex(node: &Node, _calling_client: Arc<Client>, _message: Message) -> Result<()> {
|
fn release_flex(node: &Node, _calling_client: Arc<Client>, _message: Message) -> Result<()> {
|
||||||
let item = node.get_aspect("Item", "item", |n| &n.item)?;
|
let item = node.get_aspect("Item", "item", |n| &n.item)?;
|
||||||
release(item);
|
release(item, None);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -165,7 +163,7 @@ impl Item {
|
|||||||
impl Drop for Item {
|
impl Drop for Item {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.type_info.items.remove(self);
|
self.type_info.items.remove(self);
|
||||||
release(self);
|
release(self, None);
|
||||||
if let Some(ui) = self.type_info.ui.lock().upgrade() {
|
if let Some(ui) = self.type_info.ui.lock().upgrade() {
|
||||||
ui.handle_destroy_item(self);
|
ui.handle_destroy_item(self);
|
||||||
}
|
}
|
||||||
@@ -173,14 +171,12 @@ impl Drop for Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub enum ItemType {
|
pub enum ItemType {
|
||||||
Camera(CameraItem),
|
|
||||||
Environment(EnvironmentItem),
|
Environment(EnvironmentItem),
|
||||||
Panel(Arc<dyn PanelItemTrait>),
|
Panel(Arc<dyn PanelItemTrait>),
|
||||||
}
|
}
|
||||||
impl ItemType {
|
impl ItemType {
|
||||||
fn serialize_start_data(&self, id: &str) -> Result<Message> {
|
fn serialize_start_data(&self, id: &str) -> Result<Message> {
|
||||||
match self {
|
match self {
|
||||||
ItemType::Camera(c) => c.serialize_start_data(id),
|
|
||||||
ItemType::Environment(e) => e.serialize_start_data(id),
|
ItemType::Environment(e) => e.serialize_start_data(id),
|
||||||
ItemType::Panel(p) => p.serialize_start_data(id),
|
ItemType::Panel(p) => p.serialize_start_data(id),
|
||||||
}
|
}
|
||||||
@@ -378,7 +374,7 @@ impl Drop for ItemAcceptor {
|
|||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.type_info.acceptors.remove(self);
|
self.type_info.acceptors.remove(self);
|
||||||
for item in self.accepted_registry.get_valid_contents() {
|
for item in self.accepted_registry.get_valid_contents() {
|
||||||
release(&item);
|
release(&item, Some(self));
|
||||||
}
|
}
|
||||||
if let Some(ui) = self.type_info.ui.lock().upgrade() {
|
if let Some(ui) = self.type_info.ui.lock().upgrade() {
|
||||||
ui.handle_destroy_acceptor(self);
|
ui.handle_destroy_acceptor(self);
|
||||||
@@ -388,7 +384,6 @@ impl Drop for ItemAcceptor {
|
|||||||
|
|
||||||
pub fn create_interface(client: &Arc<Client>) -> Result<()> {
|
pub fn create_interface(client: &Arc<Client>) -> Result<()> {
|
||||||
let node = Node::create(client, "", "item", false);
|
let node = Node::create(client, "", "item", false);
|
||||||
node.add_local_signal("create_camera_item", camera::create_camera_item_flex);
|
|
||||||
node.add_local_signal(
|
node.add_local_signal(
|
||||||
"create_environment_item",
|
"create_environment_item",
|
||||||
environment::create_environment_item_flex,
|
environment::create_environment_item_flex,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
core::{
|
core::{
|
||||||
client::{get_env, state, Client, INTERNAL_CLIENT},
|
client::{get_env, startup_settings, Client, INTERNAL_CLIENT},
|
||||||
registry::Registry,
|
registry::Registry,
|
||||||
},
|
},
|
||||||
nodes::{
|
nodes::{
|
||||||
drawable::{model::ModelPart, Drawable},
|
drawable::{model::ModelPart, Drawable},
|
||||||
items::{Item, ItemType, TypeInfo},
|
items::{self, Item, ItemType, TypeInfo},
|
||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
Message, Node,
|
Message, Node,
|
||||||
},
|
},
|
||||||
@@ -15,7 +15,6 @@ use glam::Mat4;
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use mint::Vector2;
|
use mint::Vector2;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use serde::{
|
use serde::{
|
||||||
de::{Deserializer, Error, SeqAccess, Visitor},
|
de::{Deserializer, Error, SeqAccess, Visitor},
|
||||||
ser::Serializer,
|
ser::Serializer,
|
||||||
@@ -30,33 +29,24 @@ lazy_static! {
|
|||||||
type_name: "panel",
|
type_name: "panel",
|
||||||
aliased_local_signals: vec![
|
aliased_local_signals: vec![
|
||||||
"apply_surface_material",
|
"apply_surface_material",
|
||||||
"close_toplevel",
|
"configure_toplevel",
|
||||||
"auto_size_toplevel",
|
"set_toplevel_capabilities",
|
||||||
"set_toplevel_size",
|
|
||||||
"set_toplevel_focused_visuals",
|
|
||||||
"pointer_motion",
|
|
||||||
"pointer_button",
|
|
||||||
"pointer_scroll",
|
"pointer_scroll",
|
||||||
"keyboard_keymap",
|
"pointer_button",
|
||||||
|
"pointer_motion",
|
||||||
"keyboard_key",
|
"keyboard_key",
|
||||||
"touch_down",
|
"keyboard_set_keymap_names",
|
||||||
"touch_move",
|
"keyboard_set_keymap_string",
|
||||||
"touch_up",
|
"close",
|
||||||
"reset_touches",
|
|
||||||
],
|
],
|
||||||
aliased_local_methods: vec![],
|
aliased_local_methods: vec![],
|
||||||
aliased_remote_signals: vec![
|
aliased_remote_signals: vec![
|
||||||
"toplevel_parent_changed",
|
"commit_toplevel",
|
||||||
"toplevel_title_changed",
|
"recommend_toplevel_state",
|
||||||
"toplevel_app_id_changed",
|
|
||||||
"toplevel_fullscreen_active",
|
|
||||||
"toplevel_move_request",
|
|
||||||
"toplevel_resize_request",
|
|
||||||
"toplevel_size_changed",
|
|
||||||
"set_cursor",
|
"set_cursor",
|
||||||
"new_child",
|
"new_popup",
|
||||||
"reposition_child",
|
"reposition_popup",
|
||||||
"drop_child",
|
"drop_popup",
|
||||||
],
|
],
|
||||||
ui: Default::default(),
|
ui: Default::default(),
|
||||||
items: Registry::new(),
|
items: Registry::new(),
|
||||||
@@ -70,7 +60,7 @@ lazy_static! {
|
|||||||
pub enum SurfaceID {
|
pub enum SurfaceID {
|
||||||
Cursor,
|
Cursor,
|
||||||
Toplevel,
|
Toplevel,
|
||||||
Child(String),
|
Popup(String),
|
||||||
}
|
}
|
||||||
impl Default for SurfaceID {
|
impl Default for SurfaceID {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@@ -104,15 +94,15 @@ impl<'de> Visitor<'de> for SurfaceIDVisitor {
|
|||||||
match discrim {
|
match discrim {
|
||||||
"Cursor" => Ok(SurfaceID::Cursor),
|
"Cursor" => Ok(SurfaceID::Cursor),
|
||||||
"Toplevel" => Ok(SurfaceID::Toplevel),
|
"Toplevel" => Ok(SurfaceID::Toplevel),
|
||||||
"Child" => {
|
"Popup" => {
|
||||||
let Some(text) = seq.next_element()? else {
|
let Some(text) = seq.next_element()? else {
|
||||||
return Err(A::Error::missing_field("child_text"));
|
return Err(A::Error::missing_field("popup_text"));
|
||||||
};
|
};
|
||||||
Ok(SurfaceID::Child(text))
|
Ok(SurfaceID::Popup(text))
|
||||||
}
|
}
|
||||||
_ => Err(A::Error::unknown_variant(
|
_ => Err(A::Error::unknown_variant(
|
||||||
discrim,
|
discrim,
|
||||||
&["Cursor", "Toplevel", "Child"],
|
&["Cursor", "Toplevel", "Popup"],
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,68 +113,33 @@ impl serde::Serialize for SurfaceID {
|
|||||||
match self {
|
match self {
|
||||||
Self::Cursor => ["Cursor"].serialize(serializer),
|
Self::Cursor => ["Cursor"].serialize(serializer),
|
||||||
Self::Toplevel => ["Toplevel"].serialize(serializer),
|
Self::Toplevel => ["Toplevel"].serialize(serializer),
|
||||||
Self::Child(text) => ["Child", text].serialize(serializer),
|
Self::Popup(text) => ["Popup", text].serialize(serializer),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The origin and size of the surface's "solid" part.
|
#[derive(Debug, Clone, Copy, Serialize)]
|
||||||
#[derive(Debug, Serialize, Clone, Copy)]
|
#[serde(tag = "type", content = "content")]
|
||||||
pub struct Geometry {
|
pub enum RecommendedState {
|
||||||
pub origin: Vector2<i32>,
|
Maximize(bool),
|
||||||
pub size: Vector2<u32>,
|
Fullscreen(bool),
|
||||||
}
|
Minimize,
|
||||||
/// The state of the panel item's toplevel.
|
Move,
|
||||||
#[derive(Debug, Clone, Serialize)]
|
Resize(u32),
|
||||||
pub struct ToplevelInfo {
|
|
||||||
/// The UID of the panel item of the parent of this toplevel, if it exists
|
|
||||||
pub parent: Option<String>,
|
|
||||||
/// Equivalent to the window title
|
|
||||||
pub title: Option<String>,
|
|
||||||
/// Application identifier, see <https://standards.freedesktop.org/desktop-entry-spec/>
|
|
||||||
pub app_id: Option<String>,
|
|
||||||
/// Current size in pixels
|
|
||||||
pub size: Vector2<u32>,
|
|
||||||
/// Recommended minimum size in pixels
|
|
||||||
pub min_size: Option<Vector2<u32>>,
|
|
||||||
/// Recommended maximum size in pixels
|
|
||||||
pub max_size: Option<Vector2<u32>>,
|
|
||||||
/// Surface geometry
|
|
||||||
pub logical_rectangle: Geometry,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Data on positioning a child
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct ChildInfo {
|
|
||||||
pub parent: SurfaceID,
|
|
||||||
pub geometry: Geometry,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The init data for the panel item.
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct PanelItemInitData {
|
|
||||||
/// The cursor, if applicable.
|
|
||||||
pub cursor: Option<Geometry>,
|
|
||||||
/// Size of the toplevel surface in pixels.
|
|
||||||
pub toplevel: ToplevelInfo,
|
|
||||||
/// Vector of childs that already exist
|
|
||||||
pub children: FxHashMap<String, ChildInfo>,
|
|
||||||
/// The surface, if any, that has exclusive input to the pointer.
|
|
||||||
pub pointer_grab: Option<SurfaceID>,
|
|
||||||
/// The surface, if any, that has exclusive input to the keyboard.
|
|
||||||
pub keyboard_grab: Option<SurfaceID>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Backend: Send + Sync + 'static {
|
pub trait Backend: Send + Sync + 'static {
|
||||||
fn start_data(&self) -> Result<PanelItemInitData>;
|
fn serialize_start_data(&self, id: &str) -> Result<Message>;
|
||||||
|
fn serialize_toplevel(&self) -> Result<Message>;
|
||||||
|
fn set_toplevel_capabilities(&self, capabilities: Vec<u8>);
|
||||||
|
fn configure_toplevel(
|
||||||
|
&self,
|
||||||
|
size: Option<Vector2<u32>>,
|
||||||
|
states: Vec<u32>,
|
||||||
|
bounds: Option<Vector2<u32>>,
|
||||||
|
);
|
||||||
fn apply_surface_material(&self, surface: SurfaceID, model_part: &Arc<ModelPart>);
|
fn apply_surface_material(&self, surface: SurfaceID, model_part: &Arc<ModelPart>);
|
||||||
|
|
||||||
fn close_toplevel(&self);
|
|
||||||
fn auto_size_toplevel(&self);
|
|
||||||
fn set_toplevel_size(&self, size: Vector2<u32>);
|
|
||||||
fn set_toplevel_focused_visuals(&self, focused: bool);
|
|
||||||
|
|
||||||
fn pointer_motion(&self, surface: &SurfaceID, position: Vector2<f32>);
|
fn pointer_motion(&self, surface: &SurfaceID, position: Vector2<f32>);
|
||||||
fn pointer_button(&self, surface: &SurfaceID, button: u32, pressed: bool);
|
fn pointer_button(&self, surface: &SurfaceID, button: u32, pressed: bool);
|
||||||
fn pointer_scroll(
|
fn pointer_scroll(
|
||||||
@@ -194,12 +149,8 @@ pub trait Backend: Send + Sync + 'static {
|
|||||||
scroll_steps: Option<Vector2<f32>>,
|
scroll_steps: Option<Vector2<f32>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn keyboard_keys(&self, surface: &SurfaceID, keymap_id: &str, keys: Vec<i32>);
|
fn keyboard_set_keymap(&self, keymap: &str) -> Result<()>;
|
||||||
|
fn keyboard_key(&self, surface: &SurfaceID, key: u32, state: bool);
|
||||||
fn touch_down(&self, surface: &SurfaceID, id: u32, position: Vector2<f32>);
|
|
||||||
fn touch_move(&self, id: u32, position: Vector2<f32>);
|
|
||||||
fn touch_up(&self, id: u32);
|
|
||||||
fn reset_touches(&self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn panel_item_from_node(node: &Node) -> Option<Arc<dyn PanelItemTrait>> {
|
pub fn panel_item_from_node(node: &Node) -> Option<Arc<dyn PanelItemTrait>> {
|
||||||
@@ -209,7 +160,7 @@ pub fn panel_item_from_node(node: &Node) -> Option<Arc<dyn PanelItemTrait>> {
|
|||||||
|
|
||||||
pub trait PanelItemTrait: Backend + Send + Sync + 'static {
|
pub trait PanelItemTrait: Backend + Send + Sync + 'static {
|
||||||
fn uid(&self) -> &str;
|
fn uid(&self) -> &str;
|
||||||
fn serialize_start_data(&self, id: &str) -> Result<Message>;
|
// fn node(&self) -> Option<Arc<Node>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PanelItem<B: Backend + ?Sized> {
|
pub struct PanelItem<B: Backend + ?Sized> {
|
||||||
@@ -218,12 +169,12 @@ pub struct PanelItem<B: Backend + ?Sized> {
|
|||||||
pub backend: Box<B>,
|
pub backend: Box<B>,
|
||||||
}
|
}
|
||||||
impl<B: Backend + ?Sized> PanelItem<B> {
|
impl<B: Backend + ?Sized> PanelItem<B> {
|
||||||
pub fn create(backend: Box<B>, pid: Option<i32>) -> Arc<PanelItem<B>> {
|
pub fn create(backend: Box<B>, pid: Option<i32>) -> (Arc<Node>, Arc<PanelItem<B>>) {
|
||||||
debug!(?pid, "Create panel item");
|
debug!(?pid, "Create panel item");
|
||||||
|
|
||||||
let startup_settings = pid
|
let startup_settings = pid
|
||||||
.and_then(|pid| get_env(pid).ok())
|
.and_then(|pid| get_env(pid).ok())
|
||||||
.and_then(|env| state(&env));
|
.and_then(|env| startup_settings(&env));
|
||||||
|
|
||||||
let uid = nanoid!();
|
let uid = nanoid!();
|
||||||
let node = Node::create(&INTERNAL_CLIENT, "/item/panel/item", &uid, true)
|
let node = Node::create(&INTERNAL_CLIENT, "/item/panel/item", &uid, true)
|
||||||
@@ -231,7 +182,9 @@ impl<B: Backend + ?Sized> PanelItem<B> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let spatial = Spatial::add_to(&node, None, Mat4::IDENTITY, false).unwrap();
|
let spatial = Spatial::add_to(&node, None, Mat4::IDENTITY, false).unwrap();
|
||||||
if let Some(startup_settings) = &startup_settings {
|
if let Some(startup_settings) = &startup_settings {
|
||||||
spatial.set_local_transform(startup_settings.root);
|
spatial.set_local_transform(
|
||||||
|
spatial.global_transform().inverse() * startup_settings.transform,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let panel_item = Arc::new(PanelItem {
|
let panel_item = Arc::new(PanelItem {
|
||||||
@@ -241,112 +194,53 @@ impl<B: Backend + ?Sized> PanelItem<B> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let generic_panel_item: Arc<dyn PanelItemTrait> = panel_item.clone();
|
let generic_panel_item: Arc<dyn PanelItemTrait> = panel_item.clone();
|
||||||
Item::add_to(
|
let item = Item::add_to(
|
||||||
&node,
|
&node,
|
||||||
uid,
|
uid,
|
||||||
&ITEM_TYPE_INFO_PANEL,
|
&ITEM_TYPE_INFO_PANEL,
|
||||||
ItemType::Panel(generic_panel_item),
|
ItemType::Panel(generic_panel_item),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// panel_item
|
||||||
|
// .seat_data
|
||||||
|
// .new_surface(&wl_surface, Arc::downgrade(&panel_item));
|
||||||
|
|
||||||
|
if let Some(startup_settings) = &startup_settings {
|
||||||
|
if let Some(acceptor) = startup_settings
|
||||||
|
.acceptors
|
||||||
|
.get(&*ITEM_TYPE_INFO_PANEL)
|
||||||
|
.and_then(|acc| acc.upgrade())
|
||||||
|
{
|
||||||
|
items::capture(&item, &acceptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
node.add_local_signal("apply_surface_material", Self::apply_surface_material_flex);
|
node.add_local_signal("apply_surface_material", Self::apply_surface_material_flex);
|
||||||
node.add_local_signal("close_toplevel", Self::close_toplevel_flex);
|
node.add_local_signal("configure_toplevel", Self::configure_toplevel_flex);
|
||||||
node.add_local_signal("auto_size_toplevel", Self::auto_size_toplevel_flex);
|
|
||||||
node.add_local_signal(
|
node.add_local_signal(
|
||||||
"set_toplevel_size_changed",
|
"set_toplevel_capabilities",
|
||||||
Self::set_toplevel_size_changed_flex,
|
Self::set_toplevel_capabilities_flex,
|
||||||
);
|
);
|
||||||
|
|
||||||
node.add_local_signal("pointer_motion", Self::pointer_motion_flex);
|
|
||||||
node.add_local_signal("pointer_button", Self::pointer_button_flex);
|
|
||||||
node.add_local_signal("pointer_scroll", Self::pointer_scroll_flex);
|
node.add_local_signal("pointer_scroll", Self::pointer_scroll_flex);
|
||||||
|
node.add_local_signal("pointer_button", Self::pointer_button_flex);
|
||||||
|
node.add_local_signal("pointer_motion", Self::pointer_motion_flex);
|
||||||
|
|
||||||
node.add_local_signal("keyboard_key", Self::keyboard_keys_flex);
|
node.add_local_signal(
|
||||||
|
"keyboard_set_keymap_string",
|
||||||
node.add_local_signal("touch_down", Self::touch_down_flex);
|
Self::keyboard_set_keymap_string_flex,
|
||||||
node.add_local_signal("touch_move", Self::touch_move_flex);
|
|
||||||
node.add_local_signal("touch_up", Self::touch_up_flex);
|
|
||||||
node.add_local_signal("reset_touches", Self::reset_touches_flex);
|
|
||||||
|
|
||||||
panel_item
|
|
||||||
}
|
|
||||||
pub fn drop_toplevel(&self) {
|
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
|
||||||
node.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remote signals
|
|
||||||
impl<B: Backend + ?Sized> PanelItem<B> {
|
|
||||||
pub fn toplevel_parent_changed(&self, parent: &str) {
|
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
|
||||||
let _ = node.send_remote_signal("toplevel_parent_changed", serialize(parent).unwrap());
|
|
||||||
}
|
|
||||||
pub fn toplevel_title_changed(&self, title: &str) {
|
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
|
||||||
let _ = node.send_remote_signal("toplevel_title_changed", serialize(title).unwrap());
|
|
||||||
}
|
|
||||||
pub fn toplevel_app_id_changed(&self, app_id: &str) {
|
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
|
||||||
let _ = node.send_remote_signal("toplevel_app_id_changed", serialize(app_id).unwrap());
|
|
||||||
}
|
|
||||||
pub fn toplevel_fullscreen_active(&self, active: bool) {
|
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
|
||||||
let _ = node.send_remote_signal("toplevel_fullscreen_active", serialize(active).unwrap());
|
|
||||||
}
|
|
||||||
pub fn toplevel_move_request(&self) {
|
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
|
||||||
let _ = node.send_remote_signal("toplevel_move_request", Vec::<u8>::new());
|
|
||||||
}
|
|
||||||
pub fn toplevel_resize_request(&self, up: bool, down: bool, left: bool, right: bool) {
|
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
|
||||||
let _ = node.send_remote_signal(
|
|
||||||
"toplevel_resize_request",
|
|
||||||
serialize((up, down, left, right)).unwrap(),
|
|
||||||
);
|
);
|
||||||
}
|
// node.add_local_signal(
|
||||||
pub fn toplevel_size_changed(&self, size: Vector2<u32>) {
|
// "keyboard_set_keymap_names",
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
// Self::keyboard_set_keymap_names_flex,
|
||||||
let _ = node.send_remote_signal("toplevel_size_changed", serialize(size).unwrap());
|
// );
|
||||||
|
node.add_local_signal("keyboard_key", Self::keyboard_key_flex);
|
||||||
|
|
||||||
|
(node, panel_item)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_cursor(&self, geometry: Option<Geometry>) {
|
pub fn node(&self) -> Option<Arc<Node>> {
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
self.node.upgrade()
|
||||||
let _ = node.send_remote_signal("set_cursor", serialize(geometry).unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_child(&self, uid: &str, info: ChildInfo) {
|
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
|
||||||
let _ = node.send_remote_signal("new_child", serialize((uid, info)).unwrap());
|
|
||||||
}
|
|
||||||
pub fn reposition_child(&self, uid: &str, geometry: Geometry) {
|
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
|
||||||
let _ = node.send_remote_signal("reposition_child", serialize((uid, geometry)).unwrap());
|
|
||||||
}
|
|
||||||
pub fn drop_child(&self, uid: &str) {
|
|
||||||
let Some(node) = self.node.upgrade() else {return};
|
|
||||||
let _ = node.send_remote_signal("drop_child", serialize(uid).unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Local signals
|
|
||||||
macro_rules! flex_no_args {
|
|
||||||
($fn_name: ident, $trait_fn: ident) => {
|
|
||||||
fn $fn_name(node: &Node, _calling_client: Arc<Client>, _message: Message) -> Result<()> {
|
|
||||||
let Some(panel_item) = panel_item_from_node(node) else { return Ok(()) };
|
|
||||||
panel_item.$trait_fn();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
macro_rules! flex_deserialize {
|
|
||||||
($fn_name: ident, $trait_fn: ident) => {
|
|
||||||
fn $fn_name(node: &Node, _calling_client: Arc<Client>, message: Message) -> Result<()> {
|
|
||||||
let Some(panel_item) = panel_item_from_node(node) else { return Ok(()) };
|
|
||||||
panel_item.$trait_fn(deserialize(message.as_ref())?);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
impl<B: Backend + ?Sized> PanelItem<B> {
|
|
||||||
fn apply_surface_material_flex(
|
fn apply_surface_material_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
@@ -374,10 +268,6 @@ impl<B: Backend + ?Sized> PanelItem<B> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
flex_no_args!(close_toplevel_flex, close_toplevel);
|
|
||||||
flex_no_args!(auto_size_toplevel_flex, auto_size_toplevel);
|
|
||||||
flex_deserialize!(set_toplevel_size_changed_flex, set_toplevel_size);
|
|
||||||
|
|
||||||
fn pointer_motion_flex(
|
fn pointer_motion_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
_calling_client: Arc<Client>,
|
_calling_client: Arc<Client>,
|
||||||
@@ -402,7 +292,7 @@ impl<B: Backend + ?Sized> PanelItem<B> {
|
|||||||
let (surface_id, button, state): (SurfaceID, u32, u32) = deserialize(message.as_ref())?;
|
let (surface_id, button, state): (SurfaceID, u32, u32) = deserialize(message.as_ref())?;
|
||||||
debug!(?surface_id, button, state, "Pointer button");
|
debug!(?surface_id, button, state, "Pointer button");
|
||||||
|
|
||||||
panel_item.pointer_button(&surface_id, button, state != 0);
|
panel_item.pointer_button(&surface_id, button, state == 0);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn pointer_scroll_flex(
|
fn pointer_scroll_flex(
|
||||||
@@ -426,17 +316,75 @@ impl<B: Backend + ?Sized> PanelItem<B> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_keys_flex(
|
fn keyboard_set_keymap_string_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
message: Message,
|
||||||
|
) -> Result<()> {
|
||||||
|
let keymap_string: &str = deserialize(message.as_ref())?;
|
||||||
|
|
||||||
|
let Some(panel_item) = panel_item_from_node(node) else { return Ok(()) };
|
||||||
|
debug!("Keyboard set keymap");
|
||||||
|
panel_item.keyboard_set_keymap(keymap_string)
|
||||||
|
|
||||||
|
// PanelItem::keyboard_set_keymap_flex(node, &keymap)
|
||||||
|
}
|
||||||
|
// fn keyboard_set_keymap_names_flex(
|
||||||
|
// node: &Node,
|
||||||
|
// _calling_client: Arc<Client>,
|
||||||
|
// message: Message,
|
||||||
|
// ) -> Result<()> {
|
||||||
|
// #[derive(Debug, Deserialize)]
|
||||||
|
// struct Names<'a> {
|
||||||
|
// rules: &'a str,
|
||||||
|
// model: &'a str,
|
||||||
|
// layout: &'a str,
|
||||||
|
// variant: &'a str,
|
||||||
|
// options: Option<String>,
|
||||||
|
// }
|
||||||
|
// let names: Names = deserialize(message.as_ref())?;
|
||||||
|
// let context = xkb::Context::new(0);
|
||||||
|
// let keymap = Keymap::new_from_names(
|
||||||
|
// &context,
|
||||||
|
// names.rules,
|
||||||
|
// names.model,
|
||||||
|
// names.layout,
|
||||||
|
// names.variant,
|
||||||
|
// names.options,
|
||||||
|
// XKB_KEYMAP_FORMAT_TEXT_V1,
|
||||||
|
// )
|
||||||
|
// .ok_or_else(|| eyre!("Keymap is not valid"))?;
|
||||||
|
|
||||||
|
// PanelItem::keyboard_set_keymap_flex(node, &keymap)
|
||||||
|
// }
|
||||||
|
// fn keyboard_set_keymap_flex(node: &Node, keymap: &str) -> Result<()> {
|
||||||
|
// let Some(panel_item): Option<Arc<PanelItem<dyn WaylandBackend>>> = panel_item_from_node(node) else { return Ok(()) };
|
||||||
|
// debug!("Keyboard set keymap");
|
||||||
|
|
||||||
|
// panel_item.seat_data.set_keymap(
|
||||||
|
// keymap,
|
||||||
|
// match &panel_item {
|
||||||
|
// Backend::Wayland(w) => w.input_surfaces(),
|
||||||
|
// #[cfg(feature = "xwayland")]
|
||||||
|
// Backend::X11(_) => panel_item
|
||||||
|
// .toplevel_wl_surface()
|
||||||
|
// .map(|s| vec![s])
|
||||||
|
// .unwrap_or_default(),
|
||||||
|
// },
|
||||||
|
// );
|
||||||
|
|
||||||
|
// Ok(())
|
||||||
|
// }
|
||||||
|
fn keyboard_key_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
_calling_client: Arc<Client>,
|
_calling_client: Arc<Client>,
|
||||||
message: Message,
|
message: Message,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let Some(panel_item) = panel_item_from_node(node) else { return Ok(()) };
|
let Some(panel_item) = panel_item_from_node(node) else { return Ok(()) };
|
||||||
let (surface_id, keymap_id, keys): (SurfaceID, &str, Vec<i32>) =
|
let (surface_id, key, state): (SurfaceID, u32, u32) = deserialize(message.as_ref())?;
|
||||||
deserialize(message.as_ref())?;
|
debug!(key, state, "Set keyboard key state");
|
||||||
debug!(?keys, "Set keyboard key state");
|
|
||||||
|
|
||||||
panel_item.keyboard_keys(&surface_id, keymap_id, keys);
|
panel_item.keyboard_key(&surface_id, key, state == 0);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -447,67 +395,93 @@ impl<B: Backend + ?Sized> PanelItem<B> {
|
|||||||
let _ = node.send_remote_signal("grab_keyboard", message);
|
let _ = node.send_remote_signal("grab_keyboard", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn touch_down_flex(node: &Node, _calling_client: Arc<Client>, message: Message) -> Result<()> {
|
fn configure_toplevel_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
message: Message,
|
||||||
|
) -> Result<()> {
|
||||||
let Some(panel_item) = panel_item_from_node(node) else { return Ok(()) };
|
let Some(panel_item) = panel_item_from_node(node) else { return Ok(()) };
|
||||||
|
|
||||||
let (surface_id, id, position): (SurfaceID, u32, Vector2<f32>) =
|
#[derive(Debug, Deserialize)]
|
||||||
deserialize(message.as_ref())?;
|
struct ConfigureToplevelInfo {
|
||||||
debug!(?surface_id, id, ?position, "Touch down");
|
size: Option<Vector2<u32>>,
|
||||||
|
states: Vec<u32>,
|
||||||
|
bounds: Option<Vector2<u32>>,
|
||||||
|
}
|
||||||
|
let info: ConfigureToplevelInfo = deserialize(message.as_ref())?;
|
||||||
|
|
||||||
panel_item.touch_down(&surface_id, id, position);
|
panel_item.configure_toplevel(info.size, info.states, info.bounds);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_toplevel_capabilities_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
message: Message,
|
||||||
|
) -> Result<()> {
|
||||||
|
let Some(panel_item) = panel_item_from_node(node) else { return Ok(()) };
|
||||||
|
|
||||||
|
let capabilities: Vec<u8> = deserialize(message.as_ref())?;
|
||||||
|
debug!("Set toplevel capabilities");
|
||||||
|
panel_item.set_toplevel_capabilities(capabilities);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn touch_move_flex(node: &Node, _calling_client: Arc<Client>, message: Message) -> Result<()> {
|
|
||||||
let Some(panel_item) = panel_item_from_node(node) else { return Ok(()) };
|
|
||||||
|
|
||||||
let (id, position): (u32, Vector2<f32>) = deserialize(message.as_ref())?;
|
pub fn commit_toplevel(&self) {
|
||||||
debug!(?position, "Touch move");
|
debug!("Commit toplevel");
|
||||||
|
let Some(node) = self.node.upgrade() else {return};
|
||||||
panel_item.touch_move(id, position);
|
let Ok(data) = self.backend.serialize_toplevel() else {return};
|
||||||
|
let _ = node.send_remote_signal("commit_toplevel", data);
|
||||||
Ok(())
|
}
|
||||||
|
|
||||||
|
pub fn recommend_toplevel_state(&self, state: RecommendedState) {
|
||||||
|
let Some(node) = self.node.upgrade() else {return};
|
||||||
|
let data = serialize(state).unwrap();
|
||||||
|
debug!(?state, "Recommend toplevel state");
|
||||||
|
|
||||||
|
let _ = node.send_remote_signal("recommend_toplevel_state", data);
|
||||||
}
|
}
|
||||||
flex_deserialize!(touch_up_flex, touch_up);
|
|
||||||
flex_no_args!(reset_touches_flex, reset_touches);
|
|
||||||
}
|
}
|
||||||
impl<B: Backend + ?Sized> PanelItemTrait for PanelItem<B> {
|
impl<B: Backend + ?Sized> PanelItemTrait for PanelItem<B> {
|
||||||
fn uid(&self) -> &str {
|
fn uid(&self) -> &str {
|
||||||
&self.uid
|
&self.uid
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_start_data(&self, id: &str) -> Result<Message> {
|
|
||||||
Ok(serialize((id, self.start_data()?))?.into())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
impl<B: Backend + ?Sized> Backend for PanelItem<B> {
|
impl<B: Backend + ?Sized> Backend for PanelItem<B> {
|
||||||
fn start_data(&self) -> Result<PanelItemInitData> {
|
fn serialize_start_data(&self, id: &str) -> Result<Message> {
|
||||||
self.backend.start_data()
|
self.backend.serialize_start_data(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn serialize_toplevel(&self) -> Result<Message> {
|
||||||
|
self.backend.serialize_toplevel()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_toplevel_capabilities(&self, capabilities: Vec<u8>) {
|
||||||
|
self.backend.set_toplevel_capabilities(capabilities)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn configure_toplevel(
|
||||||
|
&self,
|
||||||
|
size: Option<Vector2<u32>>,
|
||||||
|
states: Vec<u32>,
|
||||||
|
bounds: Option<Vector2<u32>>,
|
||||||
|
) {
|
||||||
|
self.backend.configure_toplevel(size, states, bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_surface_material(&self, surface: SurfaceID, model_part: &Arc<ModelPart>) {
|
fn apply_surface_material(&self, surface: SurfaceID, model_part: &Arc<ModelPart>) {
|
||||||
self.backend.apply_surface_material(surface, model_part)
|
self.backend.apply_surface_material(surface, model_part)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_toplevel(&self) {
|
|
||||||
self.backend.close_toplevel()
|
|
||||||
}
|
|
||||||
fn auto_size_toplevel(&self) {
|
|
||||||
self.backend.auto_size_toplevel()
|
|
||||||
}
|
|
||||||
fn set_toplevel_size(&self, size: Vector2<u32>) {
|
|
||||||
self.backend.set_toplevel_size(size)
|
|
||||||
}
|
|
||||||
fn set_toplevel_focused_visuals(&self, focused: bool) {
|
|
||||||
self.backend.set_toplevel_focused_visuals(focused)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pointer_motion(&self, surface: &SurfaceID, position: Vector2<f32>) {
|
fn pointer_motion(&self, surface: &SurfaceID, position: Vector2<f32>) {
|
||||||
self.backend.pointer_motion(surface, position)
|
self.backend.pointer_motion(surface, position)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pointer_button(&self, surface: &SurfaceID, button: u32, pressed: bool) {
|
fn pointer_button(&self, surface: &SurfaceID, button: u32, pressed: bool) {
|
||||||
self.backend.pointer_button(surface, button, pressed)
|
self.backend.pointer_button(surface, button, pressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pointer_scroll(
|
fn pointer_scroll(
|
||||||
&self,
|
&self,
|
||||||
surface: &SurfaceID,
|
surface: &SurfaceID,
|
||||||
@@ -518,21 +492,12 @@ impl<B: Backend + ?Sized> Backend for PanelItem<B> {
|
|||||||
.pointer_scroll(surface, scroll_distance, scroll_steps)
|
.pointer_scroll(surface, scroll_distance, scroll_steps)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_keys(&self, surface: &SurfaceID, keymap_id: &str, keys: Vec<i32>) {
|
fn keyboard_set_keymap(&self, keymap: &str) -> Result<()> {
|
||||||
self.backend.keyboard_keys(surface, keymap_id, keys)
|
self.backend.keyboard_set_keymap(keymap)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn touch_down(&self, surface: &SurfaceID, id: u32, position: Vector2<f32>) {
|
fn keyboard_key(&self, surface: &SurfaceID, key: u32, state: bool) {
|
||||||
self.backend.touch_down(surface, id, position)
|
self.backend.keyboard_key(surface, key, state)
|
||||||
}
|
|
||||||
fn touch_move(&self, id: u32, position: Vector2<f32>) {
|
|
||||||
self.backend.touch_move(id, position)
|
|
||||||
}
|
|
||||||
fn touch_up(&self, id: u32) {
|
|
||||||
self.backend.touch_up(id)
|
|
||||||
}
|
|
||||||
fn reset_touches(&self) {
|
|
||||||
self.backend.reset_touches()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<B: Backend + ?Sized> Drop for PanelItem<B> {
|
impl<B: Backend + ?Sized> Drop for PanelItem<B> {
|
||||||
|
|||||||
131
src/nodes/mod.rs
131
src/nodes/mod.rs
@@ -8,25 +8,29 @@ pub mod input;
|
|||||||
pub mod items;
|
pub mod items;
|
||||||
pub mod root;
|
pub mod root;
|
||||||
pub mod spatial;
|
pub mod spatial;
|
||||||
|
pub mod startup;
|
||||||
|
|
||||||
use color_eyre::eyre::{eyre, Result};
|
use color_eyre::eyre::{eyre, Result};
|
||||||
|
use core::hash::BuildHasherDefault;
|
||||||
|
use dashmap::DashMap;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use portable_atomic::{AtomicBool, Ordering};
|
use portable_atomic::{AtomicBool, Ordering};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHasher;
|
||||||
use stardust_xr::messenger::MessageSenderHandle;
|
use stardust_xr::messenger::MessageSenderHandle;
|
||||||
use stardust_xr::scenegraph::ScenegraphError;
|
use stardust_xr::scenegraph::ScenegraphError;
|
||||||
use stardust_xr::schemas::flex::deserialize;
|
use stardust_xr::schemas::flex::deserialize;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::future::Future;
|
|
||||||
use std::os::fd::OwnedFd;
|
use std::os::fd::OwnedFd;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
use tracing::{debug_span, instrument};
|
||||||
|
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::core::registry::Registry;
|
use crate::core::registry::Registry;
|
||||||
use crate::core::scenegraph::MethodResponseSender;
|
#[cfg(feature = "openxr_runtime")]
|
||||||
|
use crate::openxr;
|
||||||
|
|
||||||
use self::alias::Alias;
|
use self::alias::Alias;
|
||||||
use self::audio::Sound;
|
use self::audio::Sound;
|
||||||
@@ -37,8 +41,8 @@ use self::input::{InputHandler, InputMethod};
|
|||||||
use self::items::{Item, ItemAcceptor, ItemUI};
|
use self::items::{Item, ItemAcceptor, ItemUI};
|
||||||
use self::spatial::zone::Zone;
|
use self::spatial::zone::Zone;
|
||||||
use self::spatial::Spatial;
|
use self::spatial::Spatial;
|
||||||
|
use self::startup::StartupSettings;
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
pub fds: Vec<OwnedFd>,
|
pub fds: Vec<OwnedFd>,
|
||||||
@@ -58,7 +62,7 @@ impl AsRef<[u8]> for Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type Signal = fn(&Node, Arc<Client>, Message) -> Result<()>;
|
pub type Signal = fn(&Node, Arc<Client>, Message) -> Result<()>;
|
||||||
pub type Method = fn(&Node, Arc<Client>, Message, MethodResponseSender);
|
pub type Method = fn(&Node, Arc<Client>, Message) -> Result<Message>;
|
||||||
|
|
||||||
pub struct Node {
|
pub struct Node {
|
||||||
pub enabled: Arc<AtomicBool>,
|
pub enabled: Arc<AtomicBool>,
|
||||||
@@ -67,8 +71,8 @@ pub struct Node {
|
|||||||
client: Weak<Client>,
|
client: Weak<Client>,
|
||||||
message_sender_handle: Option<MessageSenderHandle>,
|
message_sender_handle: Option<MessageSenderHandle>,
|
||||||
// trailing_slash_pos: usize,
|
// trailing_slash_pos: usize,
|
||||||
local_signals: Mutex<FxHashMap<String, Signal>>,
|
local_signals: DashMap<String, Signal, BuildHasherDefault<FxHasher>>,
|
||||||
local_methods: Mutex<FxHashMap<String, Method>>,
|
local_methods: DashMap<String, Method, BuildHasherDefault<FxHasher>>,
|
||||||
destroyable: bool,
|
destroyable: bool,
|
||||||
|
|
||||||
pub alias: OnceCell<Arc<Alias>>,
|
pub alias: OnceCell<Arc<Alias>>,
|
||||||
@@ -96,6 +100,13 @@ pub struct Node {
|
|||||||
|
|
||||||
// Sound
|
// Sound
|
||||||
pub sound: OnceCell<Arc<Sound>>,
|
pub sound: OnceCell<Arc<Sound>>,
|
||||||
|
|
||||||
|
// Startup
|
||||||
|
pub startup_settings: OnceCell<Mutex<StartupSettings>>,
|
||||||
|
|
||||||
|
// OpenXR
|
||||||
|
#[cfg(feature = "openxr_runtime")]
|
||||||
|
pub openxr_object: OnceCell<openxr::Object>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node {
|
impl Node {
|
||||||
@@ -139,6 +150,9 @@ impl Node {
|
|||||||
item_acceptor: OnceCell::new(),
|
item_acceptor: OnceCell::new(),
|
||||||
item_ui: OnceCell::new(),
|
item_ui: OnceCell::new(),
|
||||||
sound: OnceCell::new(),
|
sound: OnceCell::new(),
|
||||||
|
#[cfg(feature = "openxr_runtime")]
|
||||||
|
openxr_object: OnceCell::new(),
|
||||||
|
startup_settings: OnceCell::new(),
|
||||||
};
|
};
|
||||||
node.add_local_signal("set_enabled", Node::set_enabled_flex);
|
node.add_local_signal("set_enabled", Node::set_enabled_flex);
|
||||||
node.add_local_signal("destroy", Node::destroy_flex);
|
node.add_local_signal("destroy", Node::destroy_flex);
|
||||||
@@ -166,19 +180,6 @@ impl Node {
|
|||||||
.store(deserialize(message.as_ref())?, Ordering::Relaxed);
|
.store(deserialize(message.as_ref())?, Ordering::Relaxed);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
// very much up for debate if we should allow this, as you can match objects using this
|
|
||||||
// pub fn get_client_pid_flex(
|
|
||||||
// node: &Node,
|
|
||||||
// _calling_client: Arc<Client>,
|
|
||||||
// _message: Message,
|
|
||||||
// ) -> Result<Message> {
|
|
||||||
// let client = node
|
|
||||||
// .client
|
|
||||||
// .upgrade()
|
|
||||||
// .ok_or_else(|| eyre!("Could not get client for node?"))?;
|
|
||||||
// let pid = client.pid.ok_or_else(|| eyre!("Client PID is unknown"))?;
|
|
||||||
// Ok(serialize(pid)?.into())
|
|
||||||
// }
|
|
||||||
pub fn destroy_flex(
|
pub fn destroy_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
_calling_client: Arc<Client>,
|
_calling_client: Arc<Client>,
|
||||||
@@ -191,10 +192,10 @@ impl Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_local_signal(&self, name: &str, signal: Signal) {
|
pub fn add_local_signal(&self, name: &str, signal: Signal) {
|
||||||
self.local_signals.lock().insert(name.to_string(), signal);
|
self.local_signals.insert(name.to_string(), signal);
|
||||||
}
|
}
|
||||||
pub fn add_local_method(&self, name: &str, method: Method) {
|
pub fn add_local_method(&self, name: &str, method: Method) {
|
||||||
self.local_methods.lock().insert(name.to_string(), method);
|
self.local_methods.insert(name.to_string(), method);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_aspect<F, T>(
|
pub fn get_aspect<F, T>(
|
||||||
@@ -229,9 +230,7 @@ impl Node {
|
|||||||
} else {
|
} else {
|
||||||
let signal = self
|
let signal = self
|
||||||
.local_signals
|
.local_signals
|
||||||
.lock()
|
|
||||||
.get(method)
|
.get(method)
|
||||||
.cloned()
|
|
||||||
.ok_or(ScenegraphError::SignalNotFound)?;
|
.ok_or(ScenegraphError::SignalNotFound)?;
|
||||||
signal(self, calling_client, message).map_err(|error| ScenegraphError::SignalError {
|
signal(self, calling_client, message).map_err(|error| ScenegraphError::SignalError {
|
||||||
error: error.to_string(),
|
error: error.to_string(),
|
||||||
@@ -243,34 +242,39 @@ impl Node {
|
|||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
method: &str,
|
method: &str,
|
||||||
message: Message,
|
message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message, ScenegraphError> {
|
||||||
) {
|
|
||||||
if let Some(alias) = self.alias.get() {
|
if let Some(alias) = self.alias.get() {
|
||||||
if !alias.info.server_methods.iter().any(|e| e == &method) {
|
if !alias.info.server_methods.iter().any(|e| e == &method) {
|
||||||
response.send(Err(ScenegraphError::MethodNotFound));
|
return Err(ScenegraphError::MethodNotFound);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
let Some(alias) = alias.original.upgrade() else {
|
alias
|
||||||
response.send(Err(ScenegraphError::BrokenAlias));
|
.original
|
||||||
return;
|
.upgrade()
|
||||||
};
|
.ok_or(ScenegraphError::BrokenAlias)?
|
||||||
alias.execute_local_method(
|
.execute_local_method(
|
||||||
calling_client,
|
calling_client,
|
||||||
method,
|
method,
|
||||||
Message {
|
Message {
|
||||||
data: message.data.clone(),
|
data: message.data.clone(),
|
||||||
fds: Vec::new(),
|
fds: Vec::new(),
|
||||||
},
|
},
|
||||||
response,
|
)
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
let Some(method) = self.local_methods.lock().get(method).cloned() else {
|
let method = self
|
||||||
response.send(Err(ScenegraphError::MethodNotFound));
|
.local_methods
|
||||||
return;
|
.get(method)
|
||||||
};
|
.ok_or(ScenegraphError::MethodNotFound)?;
|
||||||
method(self, calling_client, message, response);
|
|
||||||
|
debug_span!("Handle method").in_scope(|| {
|
||||||
|
method(self, calling_client, message).map_err(|error| {
|
||||||
|
ScenegraphError::MethodError {
|
||||||
|
error: error.to_string(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn send_remote_signal(&self, method: &str, message: impl Into<Message>) -> Result<()> {
|
pub fn send_remote_signal(&self, method: &str, message: impl Into<Message>) -> Result<()> {
|
||||||
let message = message.into();
|
let message = message.into();
|
||||||
self.aliases
|
self.aliases
|
||||||
@@ -295,30 +299,21 @@ impl Node {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn execute_remote_method(
|
// #[instrument(level = "debug", skip_all)]
|
||||||
&self,
|
// pub fn execute_remote_method(
|
||||||
method: &str,
|
// &self,
|
||||||
message: impl Into<Message>,
|
// method: &str,
|
||||||
) -> Result<impl Future<Output = Result<Message>>> {
|
// data: Vec<u8>,
|
||||||
let message = message.into();
|
// ) -> Result<impl Future<Output = Result<Message>>> {
|
||||||
let message_sender_handle = self
|
// let message_sender_handle = self
|
||||||
.message_sender_handle
|
// .message_sender_handle
|
||||||
.as_ref()
|
// .as_ref()
|
||||||
.ok_or(eyre!("Messenger does not exist for this node"))?;
|
// .ok_or(eyre!("Messenger does not exist for this node"))?;
|
||||||
|
|
||||||
let future =
|
// let future = message_sender_handle.method(self.path.as_str(), method, &data)?;
|
||||||
message_sender_handle.method(self.path.as_str(), method, &message.data, message.fds)?;
|
|
||||||
|
|
||||||
Ok(async {
|
// Ok(async { future.await.map_err(|e| eyre!(e)) })
|
||||||
match future.await {
|
// }
|
||||||
Ok(m) => {
|
|
||||||
let (data, fds) = m.into_components();
|
|
||||||
Ok(Message { data, fds })
|
|
||||||
}
|
|
||||||
Err(e) => Err(eyre!(e)),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
impl Debug for Node {
|
impl Debug for Node {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
|||||||
@@ -1,25 +1,19 @@
|
|||||||
use super::spatial::Spatial;
|
use super::spatial::Spatial;
|
||||||
use super::{Message, Node};
|
use super::{Message, Node};
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::core::client_state::{ClientState, ClientStateInternal};
|
|
||||||
use crate::core::registry::Registry;
|
use crate::core::registry::Registry;
|
||||||
use crate::core::scenegraph::MethodResponseSender;
|
|
||||||
use crate::wayland::WAYLAND_DISPLAY;
|
|
||||||
use crate::STARDUST_INSTANCE;
|
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use glam::Mat4;
|
use glam::Mat4;
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use stardust_xr::schemas::flex::{deserialize, serialize};
|
use stardust_xr::schemas::flex::{deserialize, serialize};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use std::future::Future;
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
static ROOT_REGISTRY: Registry<Root> = Registry::new();
|
static ROOT_REGISTRY: Registry<Root> = Registry::new();
|
||||||
|
|
||||||
pub struct Root {
|
pub struct Root {
|
||||||
pub node: Arc<Node>,
|
node: Arc<Node>,
|
||||||
send_frame_event: AtomicBool,
|
send_frame_event: AtomicBool,
|
||||||
}
|
}
|
||||||
impl Root {
|
impl Root {
|
||||||
@@ -27,13 +21,17 @@ impl Root {
|
|||||||
let node = Node::create(client, "", "", false);
|
let node = Node::create(client, "", "", false);
|
||||||
node.add_local_signal("subscribe_frame", Root::subscribe_frame_flex);
|
node.add_local_signal("subscribe_frame", Root::subscribe_frame_flex);
|
||||||
node.add_local_signal("set_base_prefixes", Root::set_base_prefixes_flex);
|
node.add_local_signal("set_base_prefixes", Root::set_base_prefixes_flex);
|
||||||
node.add_local_method("state_token", Root::state_token_flex);
|
|
||||||
node.add_local_method(
|
|
||||||
"get_connection_environment",
|
|
||||||
get_connection_environment_flex,
|
|
||||||
);
|
|
||||||
let node = node.add_to_scenegraph()?;
|
let node = node.add_to_scenegraph()?;
|
||||||
let _ = Spatial::add_to(&node, None, client.state.root, false);
|
let _ = Spatial::add_to(
|
||||||
|
&node,
|
||||||
|
None,
|
||||||
|
client
|
||||||
|
.startup_settings
|
||||||
|
.as_ref()
|
||||||
|
.map(|settings| settings.transform)
|
||||||
|
.unwrap_or(Mat4::IDENTITY),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(ROOT_REGISTRY.add(Root {
|
Ok(ROOT_REGISTRY.add(Root {
|
||||||
node,
|
node,
|
||||||
@@ -74,31 +72,6 @@ impl Root {
|
|||||||
*calling_client.base_resource_prefixes.lock() = deserialize(message.as_ref())?;
|
*calling_client.base_resource_prefixes.lock() = deserialize(message.as_ref())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn state_token_flex(
|
|
||||||
_node: &Node,
|
|
||||||
calling_client: Arc<Client>,
|
|
||||||
message: Message,
|
|
||||||
response: MethodResponseSender,
|
|
||||||
) {
|
|
||||||
response.wrap_sync(|| {
|
|
||||||
let state: ClientStateInternal = deserialize(message.as_ref())?;
|
|
||||||
let token = ClientState::from_deserialized(&calling_client, state).token();
|
|
||||||
Ok(serialize(token)?.into())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_transform(&self, transform: Mat4) {
|
|
||||||
let spatial = self.node.spatial.get().unwrap();
|
|
||||||
spatial.set_spatial_parent(None).unwrap();
|
|
||||||
spatial.set_local_transform(transform);
|
|
||||||
}
|
|
||||||
pub fn save_state(&self) -> impl Future<Output = Result<ClientStateInternal>> {
|
|
||||||
let future = self
|
|
||||||
.node
|
|
||||||
.execute_remote_method("save_state", Message::default());
|
|
||||||
async move { Ok(deserialize(&future?.await?.data)?) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Root {
|
impl Drop for Root {
|
||||||
@@ -106,33 +79,3 @@ impl Drop for Root {
|
|||||||
ROOT_REGISTRY.remove(self);
|
ROOT_REGISTRY.remove(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! var_env_insert {
|
|
||||||
($env:ident, $name:ident) => {
|
|
||||||
$env.insert(stringify!($name).to_string(), $name.get().unwrap().clone());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
pub fn get_connection_environment_flex(
|
|
||||||
_node: &Node,
|
|
||||||
_calling_client: Arc<Client>,
|
|
||||||
_message: Message,
|
|
||||||
response: MethodResponseSender,
|
|
||||||
) {
|
|
||||||
response.wrap_sync(move || {
|
|
||||||
let mut env: FxHashMap<String, String> = FxHashMap::default();
|
|
||||||
var_env_insert!(env, STARDUST_INSTANCE);
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
{
|
|
||||||
var_env_insert!(env, WAYLAND_DISPLAY);
|
|
||||||
#[cfg(feature = "xwayland")]
|
|
||||||
var_env_insert!(env, DISPLAY);
|
|
||||||
env.insert("GDK_BACKEND".to_string(), "wayland".to_string());
|
|
||||||
env.insert("QT_QPA_PLATFORM".to_string(), "wayland".to_string());
|
|
||||||
env.insert("MOZ_ENABLE_WAYLAND".to_string(), "1".to_string());
|
|
||||||
env.insert("CLUTTER_BACKEND".to_string(), "wayland".to_string());
|
|
||||||
env.insert("SDL_VIDEODRIVER".to_string(), "wayland".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(serialize(env)?.into())
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use self::zone::{create_zone_flex, Zone};
|
|||||||
use super::{Message, Node};
|
use super::{Message, Node};
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::core::registry::Registry;
|
use crate::core::registry::Registry;
|
||||||
use crate::core::scenegraph::MethodResponseSender;
|
|
||||||
use color_eyre::eyre::{ensure, eyre, Result};
|
use color_eyre::eyre::{ensure, eyre, Result};
|
||||||
use glam::{vec3a, Mat4, Quat};
|
use glam::{vec3a, Mat4, Quat};
|
||||||
use mint::Vector3;
|
use mint::Vector3;
|
||||||
@@ -17,6 +16,7 @@ use std::fmt::Debug;
|
|||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::{Arc, OnceLock, Weak};
|
use std::sync::{Arc, OnceLock, Weak};
|
||||||
use stereokit::{bounds_grow_to_fit_box, Bounds};
|
use stereokit::{bounds_grow_to_fit_box, Bounds};
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
static ZONEABLE_REGISTRY: Registry<Spatial> = Registry::new();
|
static ZONEABLE_REGISTRY: Registry<Spatial> = Registry::new();
|
||||||
|
|
||||||
@@ -80,6 +80,7 @@ impl Spatial {
|
|||||||
self.node.upgrade()
|
self.node.upgrade()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn space_to_space_matrix(from: Option<&Spatial>, to: Option<&Spatial>) -> Mat4 {
|
pub fn space_to_space_matrix(from: Option<&Spatial>, to: Option<&Spatial>) -> Mat4 {
|
||||||
let space_to_world_matrix = from.map_or(Mat4::IDENTITY, |from| from.global_transform());
|
let space_to_world_matrix = from.map_or(Mat4::IDENTITY, |from| from.global_transform());
|
||||||
let world_to_space_matrix = to.map_or(Mat4::IDENTITY, |to| to.global_transform().inverse());
|
let world_to_space_matrix = to.map_or(Mat4::IDENTITY, |to| to.global_transform().inverse());
|
||||||
@@ -87,6 +88,7 @@ impl Spatial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the output bounds are probably way bigger than they need to be
|
// the output bounds are probably way bigger than they need to be
|
||||||
|
#[instrument(level = "debug")]
|
||||||
pub fn get_bounding_box(&self) -> Bounds {
|
pub fn get_bounding_box(&self) -> Bounds {
|
||||||
let Some(node) = self.node() else {return Bounds::default()};
|
let Some(node) = self.node() else {return Bounds::default()};
|
||||||
let mut bounds = self
|
let mut bounds = self
|
||||||
@@ -104,6 +106,7 @@ impl Spatial {
|
|||||||
bounds
|
bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn local_transform(&self) -> Mat4 {
|
pub fn local_transform(&self) -> Mat4 {
|
||||||
*self.transform.lock()
|
*self.transform.lock()
|
||||||
}
|
}
|
||||||
@@ -113,9 +116,11 @@ impl Spatial {
|
|||||||
None => *self.transform.lock(),
|
None => *self.transform.lock(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[instrument]
|
||||||
pub fn set_local_transform(&self, transform: Mat4) {
|
pub fn set_local_transform(&self, transform: Mat4) {
|
||||||
*self.transform.lock() = transform;
|
*self.transform.lock() = transform;
|
||||||
}
|
}
|
||||||
|
#[instrument(level = "debug", skip(self, reference_space))]
|
||||||
pub fn set_local_transform_components(
|
pub fn set_local_transform_components(
|
||||||
&self,
|
&self,
|
||||||
reference_space: Option<&Spatial>,
|
reference_space: Option<&Spatial>,
|
||||||
@@ -159,6 +164,7 @@ impl Spatial {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn is_ancestor_of(&self, spatial: Arc<Spatial>) -> bool {
|
pub fn is_ancestor_of(&self, spatial: Arc<Spatial>) -> bool {
|
||||||
let mut current_ancestor = spatial;
|
let mut current_ancestor = spatial;
|
||||||
loop {
|
loop {
|
||||||
@@ -190,6 +196,7 @@ impl Spatial {
|
|||||||
*self.parent.lock() = new_parent;
|
*self.parent.lock() = new_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn set_spatial_parent(&self, parent: Option<Arc<Spatial>>) -> Result<()> {
|
pub fn set_spatial_parent(&self, parent: Option<Arc<Spatial>>) -> Result<()> {
|
||||||
let is_ancestor = parent
|
let is_ancestor = parent
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -203,6 +210,7 @@ impl Spatial {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip_all)]
|
||||||
pub fn set_spatial_parent_in_place(&self, parent: Option<Arc<Spatial>>) -> Result<()> {
|
pub fn set_spatial_parent_in_place(&self, parent: Option<Arc<Spatial>>) -> Result<()> {
|
||||||
let is_ancestor = parent
|
let is_ancestor = parent
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -225,71 +233,64 @@ impl Spatial {
|
|||||||
node: &Node,
|
node: &Node,
|
||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
message: Message,
|
message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message> {
|
||||||
) {
|
let this_spatial = node
|
||||||
response.wrap_sync(move || {
|
.spatial
|
||||||
let this_spatial = node
|
.get()
|
||||||
.spatial
|
.ok_or_else(|| eyre!("Node doesn't have a spatial?"))?;
|
||||||
.get()
|
let relative_spatial_path: Option<&str> = deserialize(message.as_ref())?;
|
||||||
.ok_or_else(|| eyre!("Node doesn't have a spatial?"))?;
|
let bounds = if let Some(relative_spatial_path) = relative_spatial_path {
|
||||||
let relative_spatial_path: Option<&str> = deserialize(message.as_ref())?;
|
let relative_spatial = find_reference_space(&calling_client, relative_spatial_path)?;
|
||||||
let bounds = if let Some(relative_spatial_path) = relative_spatial_path {
|
let center =
|
||||||
let relative_spatial =
|
Spatial::space_to_space_matrix(Some(&this_spatial), Some(&relative_spatial))
|
||||||
find_reference_space(&calling_client, relative_spatial_path)?;
|
.transform_point3([0.0; 3].into());
|
||||||
let center =
|
let bounds: Bounds = Bounds {
|
||||||
Spatial::space_to_space_matrix(Some(&this_spatial), Some(&relative_spatial))
|
center,
|
||||||
.transform_point3([0.0; 3].into());
|
dimensions: [0.0; 3].into(),
|
||||||
let bounds: Bounds = Bounds {
|
|
||||||
center,
|
|
||||||
dimensions: [0.0; 3].into(),
|
|
||||||
};
|
|
||||||
bounds_grow_to_fit_box(
|
|
||||||
bounds,
|
|
||||||
this_spatial.get_bounding_box(),
|
|
||||||
Some(Spatial::space_to_space_matrix(
|
|
||||||
Some(&this_spatial),
|
|
||||||
Some(&relative_spatial),
|
|
||||||
)),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this_spatial.get_bounding_box()
|
|
||||||
};
|
};
|
||||||
|
bounds_grow_to_fit_box(
|
||||||
|
bounds,
|
||||||
|
this_spatial.get_bounding_box(),
|
||||||
|
Some(Spatial::space_to_space_matrix(
|
||||||
|
Some(&this_spatial),
|
||||||
|
Some(&relative_spatial),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
this_spatial.get_bounding_box()
|
||||||
|
};
|
||||||
|
|
||||||
Ok(serialize((
|
Ok(serialize((
|
||||||
mint::Vector3::from(bounds.center),
|
mint::Vector3::from(bounds.center),
|
||||||
mint::Vector3::from(bounds.dimensions),
|
mint::Vector3::from(bounds.dimensions),
|
||||||
))?
|
))?
|
||||||
.into())
|
.into())
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_transform_flex(
|
pub fn get_transform_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
message: Message,
|
message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message> {
|
||||||
) {
|
let this_spatial = node
|
||||||
response.wrap_sync(move || {
|
.spatial
|
||||||
let this_spatial = node
|
.get()
|
||||||
.spatial
|
.ok_or_else(|| eyre!("Node doesn't have a spatial?"))?;
|
||||||
.get()
|
let relative_spatial =
|
||||||
.ok_or_else(|| eyre!("Node doesn't have a spatial?"))?;
|
find_reference_space(&calling_client, deserialize(message.as_ref())?)?;
|
||||||
let relative_spatial =
|
|
||||||
find_reference_space(&calling_client, deserialize(message.as_ref())?)?;
|
|
||||||
|
|
||||||
let (scale, rotation, position) = Spatial::space_to_space_matrix(
|
let (scale, rotation, position) = Spatial::space_to_space_matrix(
|
||||||
Some(this_spatial.as_ref()),
|
Some(this_spatial.as_ref()),
|
||||||
Some(relative_spatial.as_ref()),
|
Some(relative_spatial.as_ref()),
|
||||||
)
|
)
|
||||||
.to_scale_rotation_translation();
|
.to_scale_rotation_translation();
|
||||||
|
|
||||||
Ok(serialize((
|
Ok(serialize((
|
||||||
mint::Vector3::from(position),
|
mint::Vector3::from(position),
|
||||||
mint::Quaternion::from(rotation),
|
mint::Quaternion::from(rotation),
|
||||||
mint::Vector3::from(scale),
|
mint::Vector3::from(scale),
|
||||||
))?
|
))?
|
||||||
.into())
|
.into())
|
||||||
});
|
|
||||||
}
|
}
|
||||||
pub fn set_transform_flex(
|
pub fn set_transform_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
@@ -353,81 +354,73 @@ impl Spatial {
|
|||||||
node: &Node,
|
node: &Node,
|
||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
message: Message,
|
message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message> {
|
||||||
) {
|
let (point, fields): (Vector3<f32>, Vec<Option<&str>>) = deserialize(message.as_ref())?;
|
||||||
response.wrap_sync(move || {
|
let spatial = node.spatial.get().unwrap();
|
||||||
let (point, fields): (Vector3<f32>, Vec<Option<&str>>) = deserialize(message.as_ref())?;
|
|
||||||
let spatial = node.spatial.get().unwrap();
|
|
||||||
|
|
||||||
let output = fields
|
let output = fields
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|f| {
|
.map(|f| {
|
||||||
calling_client
|
calling_client
|
||||||
.get_node("Field", f?)
|
.get_node("Field", f?)
|
||||||
.ok()?
|
.ok()?
|
||||||
.get_aspect("Field", "field", |n| &n.field)
|
.get_aspect("Field", "field", |n| &n.field)
|
||||||
.ok()
|
.ok()
|
||||||
.cloned()
|
.cloned()
|
||||||
})
|
})
|
||||||
.map(|f| f.map(|f| f.distance(spatial, point.into())))
|
.map(|f| f.map(|f| f.distance(spatial, point.into())))
|
||||||
.collect::<Vec<Option<f32>>>();
|
.collect::<Vec<Option<f32>>>();
|
||||||
|
|
||||||
Ok(serialize(output)?.into())
|
Ok(serialize(output)?.into())
|
||||||
});
|
|
||||||
}
|
}
|
||||||
pub fn field_normal_flex(
|
pub fn field_normal_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
message: Message,
|
message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message> {
|
||||||
) {
|
let (point, fields): (Vector3<f32>, Vec<Option<&str>>) = deserialize(message.as_ref())?;
|
||||||
response.wrap_sync(move || {
|
let spatial = node.spatial.get().unwrap();
|
||||||
let (point, fields): (Vector3<f32>, Vec<Option<&str>>) = deserialize(message.as_ref())?;
|
|
||||||
let spatial = node.spatial.get().unwrap();
|
|
||||||
|
|
||||||
let output = fields
|
let output = fields
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|f| {
|
.map(|f| {
|
||||||
calling_client
|
calling_client
|
||||||
.get_node("Field", f?)
|
.get_node("Field", f?)
|
||||||
.ok()?
|
.ok()?
|
||||||
.get_aspect("Field", "field", |n| &n.field)
|
.get_aspect("Field", "field", |n| &n.field)
|
||||||
.ok()
|
.ok()
|
||||||
.cloned()
|
.cloned()
|
||||||
})
|
})
|
||||||
.map(|f| f.map(|f| Vector3::from(f.normal(spatial, point.into(), 0.001))))
|
.map(|f| f.map(|f| Vector3::from(f.normal(spatial, point.into(), 0.001))))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Ok(serialize(output)?.into())
|
Ok(serialize(output)?.into())
|
||||||
});
|
|
||||||
}
|
}
|
||||||
pub fn field_closest_point_flex(
|
pub fn field_closest_point_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
calling_client: Arc<Client>,
|
calling_client: Arc<Client>,
|
||||||
message: Message,
|
message: Message,
|
||||||
response: MethodResponseSender,
|
) -> Result<Message> {
|
||||||
) {
|
let (point, fields): (Vector3<f32>, Vec<Option<&str>>) = deserialize(message.as_ref())?;
|
||||||
response.wrap_sync(move || {
|
let spatial = node.spatial.get().unwrap();
|
||||||
let (point, fields): (Vector3<f32>, Vec<Option<&str>>) = deserialize(message.as_ref())?;
|
|
||||||
let spatial = node.spatial.get().unwrap();
|
|
||||||
|
|
||||||
let output = fields
|
let output = fields
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|f| {
|
.map(|f| {
|
||||||
calling_client
|
calling_client
|
||||||
.get_node("Field", f?)
|
.get_node("Field", f?)
|
||||||
.ok()?
|
.ok()?
|
||||||
.get_aspect("Field", "field", |n| &n.field)
|
.get_aspect("Field", "field", |n| &n.field)
|
||||||
.ok()
|
.ok()
|
||||||
.cloned()
|
.cloned()
|
||||||
})
|
})
|
||||||
.map(|f| f.map(|f| Vector3::from(f.closest_point(spatial, point.into(), 0.001))))
|
.map(|f| f.map(|f| Vector3::from(f.closest_point(spatial, point.into(), 0.001))))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Ok(serialize(output)?.into())
|
Ok(serialize(output)?.into())
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub(self) fn zone_distance(&self) -> f32 {
|
pub(self) fn zone_distance(&self) -> f32 {
|
||||||
self.zone
|
self.zone
|
||||||
.lock()
|
.lock()
|
||||||
|
|||||||
155
src/nodes/startup.rs
Normal file
155
src/nodes/startup.rs
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
#[cfg(feature = "xwayland")]
|
||||||
|
use crate::wayland::xwayland::DISPLAY;
|
||||||
|
use crate::{core::client::Client, wayland::WAYLAND_DISPLAY, STARDUST_INSTANCE};
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
items::{ItemAcceptor, TypeInfo},
|
||||||
|
spatial::find_spatial,
|
||||||
|
Message, Node,
|
||||||
|
};
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
|
use glam::Mat4;
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
use stardust_xr::schemas::flex::{deserialize, serialize};
|
||||||
|
use std::{
|
||||||
|
fmt::Debug,
|
||||||
|
sync::{Arc, Weak},
|
||||||
|
};
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref STARTUP_SETTINGS: Mutex<FxHashMap<String, StartupSettings>> = Default::default();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Clone)]
|
||||||
|
pub struct StartupSettings {
|
||||||
|
pub transform: Mat4,
|
||||||
|
pub acceptors: FxHashMap<&'static TypeInfo, Weak<ItemAcceptor>>,
|
||||||
|
}
|
||||||
|
impl StartupSettings {
|
||||||
|
pub fn add_to(node: &Arc<Node>) {
|
||||||
|
let _ = node
|
||||||
|
.startup_settings
|
||||||
|
.set(Mutex::new(StartupSettings::default()));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_root_flex(node: &Node, calling_client: Arc<Client>, message: Message) -> Result<()> {
|
||||||
|
let spatial = find_spatial(
|
||||||
|
&calling_client,
|
||||||
|
"Root spatial",
|
||||||
|
deserialize(message.as_ref())?,
|
||||||
|
)?;
|
||||||
|
node.startup_settings.get().unwrap().lock().transform = spatial.global_transform();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_automatic_acceptor_flex(
|
||||||
|
node: &Node,
|
||||||
|
calling_client: Arc<Client>,
|
||||||
|
message: Message,
|
||||||
|
) -> Result<()> {
|
||||||
|
let acceptor_node =
|
||||||
|
calling_client.get_node("Item acceptor", deserialize(message.as_ref())?)?;
|
||||||
|
let acceptor =
|
||||||
|
acceptor_node.get_aspect("Item acceptor", "item acceptor", |n| &n.item_acceptor)?;
|
||||||
|
let mut startup_settings = node.startup_settings.get().unwrap().lock();
|
||||||
|
startup_settings
|
||||||
|
.acceptors
|
||||||
|
.insert(acceptor.type_info, Arc::downgrade(acceptor));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_startup_token_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
_message: Message,
|
||||||
|
) -> Result<Message> {
|
||||||
|
let id = nanoid::nanoid!();
|
||||||
|
let data = serialize(&id)?;
|
||||||
|
STARTUP_SETTINGS
|
||||||
|
.lock()
|
||||||
|
.insert(id, node.startup_settings.get().unwrap().lock().clone());
|
||||||
|
Ok(data.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Debug for StartupSettings {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.debug_struct("StartupSettings")
|
||||||
|
.field("transform", &self.transform)
|
||||||
|
.field(
|
||||||
|
"acceptors",
|
||||||
|
&self
|
||||||
|
.acceptors
|
||||||
|
.iter()
|
||||||
|
.map(|(k, _)| k.type_name)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_interface(client: &Arc<Client>) -> Result<()> {
|
||||||
|
let node = Node::create(client, "", "startup", false);
|
||||||
|
node.add_local_signal("create_startup_settings", create_startup_settings_flex);
|
||||||
|
node.add_local_method(
|
||||||
|
"get_connection_environment",
|
||||||
|
get_connection_environment_flex,
|
||||||
|
);
|
||||||
|
node.add_to_scenegraph().map(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_startup_settings_flex(
|
||||||
|
_node: &Node,
|
||||||
|
calling_client: Arc<Client>,
|
||||||
|
message: Message,
|
||||||
|
) -> Result<()> {
|
||||||
|
let node = Node::create(
|
||||||
|
&calling_client,
|
||||||
|
"/startup/settings",
|
||||||
|
deserialize(message.as_ref())?,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.add_to_scenegraph()?;
|
||||||
|
StartupSettings::add_to(&node);
|
||||||
|
|
||||||
|
node.add_local_signal("set_root", StartupSettings::set_root_flex);
|
||||||
|
node.add_local_signal(
|
||||||
|
"add_automatic_acceptor",
|
||||||
|
StartupSettings::add_automatic_acceptor_flex,
|
||||||
|
);
|
||||||
|
node.add_local_method(
|
||||||
|
"generate_startup_token",
|
||||||
|
StartupSettings::generate_startup_token_flex,
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! var_env_insert {
|
||||||
|
($env:ident, $name:ident) => {
|
||||||
|
$env.insert(stringify!($name).to_string(), $name.get().unwrap().clone());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub fn get_connection_environment_flex(
|
||||||
|
_node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
_message: Message,
|
||||||
|
) -> Result<Message> {
|
||||||
|
let mut env: FxHashMap<String, String> = FxHashMap::default();
|
||||||
|
var_env_insert!(env, STARDUST_INSTANCE);
|
||||||
|
#[cfg(feature = "wayland")]
|
||||||
|
{
|
||||||
|
var_env_insert!(env, WAYLAND_DISPLAY);
|
||||||
|
#[cfg(feature = "xwayland")]
|
||||||
|
var_env_insert!(env, DISPLAY);
|
||||||
|
env.insert("GDK_BACKEND".to_string(), "wayland".to_string());
|
||||||
|
env.insert("QT_QPA_PLATFORM".to_string(), "wayland".to_string());
|
||||||
|
env.insert("MOZ_ENABLE_WAYLAND".to_string(), "1".to_string());
|
||||||
|
env.insert("CLUTTER_BACKEND".to_string(), "wayland".to_string());
|
||||||
|
env.insert("SDL_VIDEODRIVER".to_string(), "wayland".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(serialize(env)?.into())
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
@@ -13,6 +13,7 @@ use serde::Serialize;
|
|||||||
use stardust_xr::schemas::{flat::Datamap, flex::flexbuffers};
|
use stardust_xr::schemas::{flat::Datamap, flex::flexbuffers};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use stereokit::StereoKitMultiThread;
|
use stereokit::StereoKitMultiThread;
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct KeyboardEvent {
|
pub struct KeyboardEvent {
|
||||||
@@ -35,6 +36,7 @@ impl EyePointer {
|
|||||||
|
|
||||||
Ok(EyePointer { spatial, pointer })
|
Ok(EyePointer { spatial, pointer })
|
||||||
}
|
}
|
||||||
|
#[instrument(level = "debug", name = "Update Flatscreen Pointer Ray", skip_all)]
|
||||||
pub fn update(&self, sk: &impl StereoKitMultiThread) {
|
pub fn update(&self, sk: &impl StereoKitMultiThread) {
|
||||||
let ray = sk.input_eyes();
|
let ray = sk.input_eyes();
|
||||||
self.spatial
|
self.spatial
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
core::{client::INTERNAL_CLIENT, typed_datamap::TypedDatamap},
|
core::{client::INTERNAL_CLIENT, typed_datamap::TypedDatamap},
|
||||||
nodes::{
|
nodes::{
|
||||||
data::{mask_matches, Mask, PulseSender, KEYMAPS, PULSE_RECEIVER_REGISTRY},
|
data::{mask_matches, Mask, PulseSender, PULSE_RECEIVER_REGISTRY},
|
||||||
fields::Ray,
|
fields::Ray,
|
||||||
input::{pointer::Pointer, InputMethod, InputType},
|
input::{pointer::Pointer, InputMethod, InputType},
|
||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
@@ -12,42 +12,33 @@ use color_eyre::eyre::Result;
|
|||||||
use glam::{vec2, vec3, Mat4, Vec2, Vec3};
|
use glam::{vec2, vec3, Mat4, Vec2, Vec3};
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use stardust_xr::schemas::flex::flexbuffers;
|
||||||
use std::{convert::TryFrom, sync::Arc};
|
use std::{convert::TryFrom, sync::Arc};
|
||||||
use stereokit::{ray_from_mouse, ButtonState, Key, StereoKitMultiThread};
|
use stereokit::{ray_from_mouse, ButtonState, Key, StereoKitMultiThread};
|
||||||
use xkbcommon::xkb::{Context, Keymap, FORMAT_TEXT_V1};
|
use tracing::instrument;
|
||||||
|
|
||||||
|
const SK_KEYMAP: &str = include_str!("sk.kmp");
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize)]
|
#[derive(Default, Deserialize, Serialize)]
|
||||||
struct MouseEvent {
|
struct MouseDatamap {
|
||||||
select: f32,
|
select: f32,
|
||||||
grab: f32,
|
grab: f32,
|
||||||
scroll_continuous: Vec2,
|
scroll: Vec2,
|
||||||
scroll_discrete: Vec2,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct KeyboardEvent {
|
struct KeyboardEvent {
|
||||||
pub keyboard: (),
|
pub keyboard: String,
|
||||||
pub xkbv1: (),
|
pub keymap: Option<String>,
|
||||||
pub keymap_id: String,
|
pub keys_up: Option<Vec<u32>>,
|
||||||
pub keys: Vec<i32>,
|
pub keys_down: Option<Vec<u32>>,
|
||||||
}
|
|
||||||
impl Default for KeyboardEvent {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
keyboard: (),
|
|
||||||
xkbv1: (),
|
|
||||||
keymap_id: "flatscreen".to_string(),
|
|
||||||
keys: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MousePointer {
|
pub struct MousePointer {
|
||||||
node: Arc<Node>,
|
node: Arc<Node>,
|
||||||
spatial: Arc<Spatial>,
|
spatial: Arc<Spatial>,
|
||||||
pointer: Arc<InputMethod>,
|
pointer: Arc<InputMethod>,
|
||||||
mouse_datamap: TypedDatamap<MouseEvent>,
|
datamap: TypedDatamap<MouseDatamap>,
|
||||||
keyboard_datamap: TypedDatamap<KeyboardEvent>,
|
|
||||||
keyboard_sender: Arc<PulseSender>,
|
keyboard_sender: Arc<PulseSender>,
|
||||||
}
|
}
|
||||||
impl MousePointer {
|
impl MousePointer {
|
||||||
@@ -57,25 +48,24 @@ impl MousePointer {
|
|||||||
let pointer =
|
let pointer =
|
||||||
InputMethod::add_to(&node, InputType::Pointer(Pointer::default()), None).unwrap();
|
InputMethod::add_to(&node, InputType::Pointer(Pointer::default()), None).unwrap();
|
||||||
|
|
||||||
KEYMAPS.lock().insert(
|
let keyboard_mask = {
|
||||||
"flatscreen".to_string(),
|
let mut fbb = flexbuffers::Builder::default();
|
||||||
Keymap::new_from_names(&Context::new(0), "evdev", "", "", "", None, 0)
|
let mut map = fbb.start_map();
|
||||||
.unwrap()
|
map.push("keyboard", "xkbv1");
|
||||||
.get_as_string(FORMAT_TEXT_V1),
|
map.end_map();
|
||||||
);
|
Mask(fbb.take_buffer())
|
||||||
|
};
|
||||||
let keyboard_sender =
|
let keyboard_sender = PulseSender::add_to(&node, keyboard_mask).unwrap();
|
||||||
PulseSender::add_to(&node, Mask::from_struct::<KeyboardEvent>()).unwrap();
|
|
||||||
|
|
||||||
Ok(MousePointer {
|
Ok(MousePointer {
|
||||||
node,
|
node,
|
||||||
spatial,
|
spatial,
|
||||||
pointer,
|
pointer,
|
||||||
mouse_datamap: Default::default(),
|
datamap: Default::default(),
|
||||||
keyboard_datamap: Default::default(),
|
|
||||||
keyboard_sender,
|
keyboard_sender,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
#[instrument(level = "debug", name = "Update Flatscreen Pointer Ray", skip_all)]
|
||||||
pub fn update(&mut self, sk: &impl StereoKitMultiThread) {
|
pub fn update(&mut self, sk: &impl StereoKitMultiThread) {
|
||||||
let mouse = sk.input_mouse();
|
let mouse = sk.input_mouse();
|
||||||
|
|
||||||
@@ -90,26 +80,23 @@ impl MousePointer {
|
|||||||
);
|
);
|
||||||
{
|
{
|
||||||
// Set pointer input datamap
|
// Set pointer input datamap
|
||||||
self.mouse_datamap.select =
|
self.datamap.select = if sk.input_key(Key::MouseLeft).contains(ButtonState::ACTIVE) {
|
||||||
if sk.input_key(Key::MouseLeft).contains(ButtonState::ACTIVE) {
|
|
||||||
1.0f32
|
|
||||||
} else {
|
|
||||||
0.0f32
|
|
||||||
};
|
|
||||||
self.mouse_datamap.grab = if sk.input_key(Key::MouseRight).contains(ButtonState::ACTIVE)
|
|
||||||
{
|
|
||||||
1.0f32
|
1.0f32
|
||||||
} else {
|
} else {
|
||||||
0.0f32
|
0.0f32
|
||||||
};
|
};
|
||||||
self.mouse_datamap.scroll_continuous = vec2(0.0, mouse.scroll_change / 120.0);
|
self.datamap.grab = if sk.input_key(Key::MouseRight).contains(ButtonState::ACTIVE) {
|
||||||
self.mouse_datamap.scroll_discrete = vec2(0.0, mouse.scroll_change / 120.0);
|
1.0f32
|
||||||
*self.pointer.datamap.lock() = self.mouse_datamap.to_datamap().ok();
|
} else {
|
||||||
|
0.0f32
|
||||||
|
};
|
||||||
|
self.datamap.scroll = vec2(0.0, mouse.scroll_change / 120.0);
|
||||||
|
*self.pointer.datamap.lock() = self.datamap.to_datamap().ok();
|
||||||
}
|
}
|
||||||
self.send_keyboard_input(sk);
|
self.send_keyboard_input(sk);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_keyboard_input(&mut self, sk: &impl StereoKitMultiThread) {
|
fn send_keyboard_input(&self, sk: &impl StereoKitMultiThread) {
|
||||||
let rx = PULSE_RECEIVER_REGISTRY
|
let rx = PULSE_RECEIVER_REGISTRY
|
||||||
.get_valid_contents()
|
.get_valid_contents()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -135,127 +122,29 @@ impl MousePointer {
|
|||||||
.map(|(rx, _)| rx);
|
.map(|(rx, _)| rx);
|
||||||
|
|
||||||
if let Some(rx) = rx {
|
if let Some(rx) = rx {
|
||||||
|
let mut keys_up = vec![];
|
||||||
|
let mut keys_down = vec![];
|
||||||
let keys = (8_u32..254)
|
let keys = (8_u32..254)
|
||||||
.filter_map(|i| Key::try_from(i).ok())
|
.filter_map(|i| Some((i, Key::try_from(i).ok()?)))
|
||||||
.filter_map(|k| Some((map_key(k)?, sk.input_key(k))))
|
.map(|(i, k)| (i - 8, sk.input_key(k)));
|
||||||
.filter_map(|(i, k)| {
|
for (key, state) in keys {
|
||||||
if k.contains(ButtonState::JUST_ACTIVE) {
|
if state.contains(ButtonState::JUST_ACTIVE) {
|
||||||
Some(i as i32)
|
keys_down.push(key);
|
||||||
} else if k.contains(ButtonState::JUST_INACTIVE) {
|
} else if state.contains(ButtonState::JUST_INACTIVE) {
|
||||||
Some(-(i as i32))
|
keys_up.push(key);
|
||||||
} else {
|
}
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
self.keyboard_datamap.keys = keys;
|
|
||||||
if !self.keyboard_datamap.keys.is_empty() {
|
|
||||||
rx.send_data(&self.node.uid, self.keyboard_datamap.serialize().unwrap())
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let key_event = KeyboardEvent {
|
||||||
|
keyboard: "xkbv1".to_string(),
|
||||||
|
keymap: Some(SK_KEYMAP.to_string()),
|
||||||
|
keys_up: Some(keys_up),
|
||||||
|
keys_down: Some(keys_down),
|
||||||
|
};
|
||||||
|
let mut serializer = flexbuffers::FlexbufferSerializer::new();
|
||||||
|
let _ = key_event.serialize(&mut serializer);
|
||||||
|
rx.send_data(&self.node.uid, serializer.take_buffer())
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_key(key: Key) -> Option<u32> {
|
|
||||||
match key {
|
|
||||||
Key::Backspace => Some(input_event_codes::KEY_BACKSPACE!()),
|
|
||||||
Key::Tab => Some(input_event_codes::KEY_TAB!()),
|
|
||||||
Key::Return => Some(input_event_codes::KEY_ENTER!()),
|
|
||||||
Key::Shift => Some(input_event_codes::KEY_LEFTSHIFT!()),
|
|
||||||
Key::Ctrl => Some(input_event_codes::KEY_LEFTCTRL!()),
|
|
||||||
Key::Alt => Some(input_event_codes::KEY_LEFTALT!()),
|
|
||||||
Key::CapsLock => Some(input_event_codes::KEY_CAPSLOCK!()),
|
|
||||||
Key::Esc => Some(input_event_codes::KEY_ESC!()),
|
|
||||||
Key::Space => Some(input_event_codes::KEY_SPACE!()),
|
|
||||||
Key::End => Some(input_event_codes::KEY_END!()),
|
|
||||||
Key::Home => Some(input_event_codes::KEY_HOME!()),
|
|
||||||
Key::Left => Some(input_event_codes::KEY_LEFT!()),
|
|
||||||
Key::Right => Some(input_event_codes::KEY_RIGHT!()),
|
|
||||||
Key::Up => Some(input_event_codes::KEY_UP!()),
|
|
||||||
Key::Down => Some(input_event_codes::KEY_DOWN!()),
|
|
||||||
Key::PageUp => Some(input_event_codes::KEY_PAGEUP!()),
|
|
||||||
Key::PageDown => Some(input_event_codes::KEY_PAGEDOWN!()),
|
|
||||||
Key::PrintScreen => Some(input_event_codes::KEY_PRINT!()),
|
|
||||||
Key::KeyInsert => Some(input_event_codes::KEY_INSERT!()),
|
|
||||||
Key::Del => Some(input_event_codes::KEY_DELETE!()),
|
|
||||||
Key::Key0 => Some(input_event_codes::KEY_0!()),
|
|
||||||
Key::Key1 => Some(input_event_codes::KEY_1!()),
|
|
||||||
Key::Key2 => Some(input_event_codes::KEY_2!()),
|
|
||||||
Key::Key3 => Some(input_event_codes::KEY_3!()),
|
|
||||||
Key::Key4 => Some(input_event_codes::KEY_4!()),
|
|
||||||
Key::Key5 => Some(input_event_codes::KEY_5!()),
|
|
||||||
Key::Key6 => Some(input_event_codes::KEY_6!()),
|
|
||||||
Key::Key7 => Some(input_event_codes::KEY_7!()),
|
|
||||||
Key::Key8 => Some(input_event_codes::KEY_8!()),
|
|
||||||
Key::Key9 => Some(input_event_codes::KEY_9!()),
|
|
||||||
Key::A => Some(input_event_codes::KEY_A!()),
|
|
||||||
Key::B => Some(input_event_codes::KEY_B!()),
|
|
||||||
Key::C => Some(input_event_codes::KEY_C!()),
|
|
||||||
Key::D => Some(input_event_codes::KEY_D!()),
|
|
||||||
Key::E => Some(input_event_codes::KEY_E!()),
|
|
||||||
Key::F => Some(input_event_codes::KEY_F!()),
|
|
||||||
Key::G => Some(input_event_codes::KEY_G!()),
|
|
||||||
Key::H => Some(input_event_codes::KEY_H!()),
|
|
||||||
Key::I => Some(input_event_codes::KEY_I!()),
|
|
||||||
Key::J => Some(input_event_codes::KEY_J!()),
|
|
||||||
Key::K => Some(input_event_codes::KEY_K!()),
|
|
||||||
Key::L => Some(input_event_codes::KEY_L!()),
|
|
||||||
Key::M => Some(input_event_codes::KEY_M!()),
|
|
||||||
Key::N => Some(input_event_codes::KEY_N!()),
|
|
||||||
Key::O => Some(input_event_codes::KEY_O!()),
|
|
||||||
Key::P => Some(input_event_codes::KEY_P!()),
|
|
||||||
Key::Q => Some(input_event_codes::KEY_Q!()),
|
|
||||||
Key::R => Some(input_event_codes::KEY_R!()),
|
|
||||||
Key::S => Some(input_event_codes::KEY_S!()),
|
|
||||||
Key::T => Some(input_event_codes::KEY_T!()),
|
|
||||||
Key::U => Some(input_event_codes::KEY_U!()),
|
|
||||||
Key::V => Some(input_event_codes::KEY_V!()),
|
|
||||||
Key::W => Some(input_event_codes::KEY_W!()),
|
|
||||||
Key::X => Some(input_event_codes::KEY_X!()),
|
|
||||||
Key::Y => Some(input_event_codes::KEY_Y!()),
|
|
||||||
Key::Z => Some(input_event_codes::KEY_Z!()),
|
|
||||||
Key::Numpad0 => Some(input_event_codes::KEY_NUMERIC_0!()),
|
|
||||||
Key::Numpad1 => Some(input_event_codes::KEY_NUMERIC_1!()),
|
|
||||||
Key::Numpad2 => Some(input_event_codes::KEY_NUMERIC_2!()),
|
|
||||||
Key::Numpad3 => Some(input_event_codes::KEY_NUMERIC_3!()),
|
|
||||||
Key::Numpad4 => Some(input_event_codes::KEY_NUMERIC_4!()),
|
|
||||||
Key::Numpad5 => Some(input_event_codes::KEY_NUMERIC_5!()),
|
|
||||||
Key::Numpad6 => Some(input_event_codes::KEY_NUMERIC_6!()),
|
|
||||||
Key::Numpad7 => Some(input_event_codes::KEY_NUMERIC_7!()),
|
|
||||||
Key::Numpad8 => Some(input_event_codes::KEY_NUMERIC_8!()),
|
|
||||||
Key::Numpad9 => Some(input_event_codes::KEY_NUMERIC_9!()),
|
|
||||||
Key::F1 => Some(input_event_codes::KEY_F1!()),
|
|
||||||
Key::F2 => Some(input_event_codes::KEY_F2!()),
|
|
||||||
Key::F3 => Some(input_event_codes::KEY_F3!()),
|
|
||||||
Key::F4 => Some(input_event_codes::KEY_F4!()),
|
|
||||||
Key::F5 => Some(input_event_codes::KEY_F5!()),
|
|
||||||
Key::F6 => Some(input_event_codes::KEY_F6!()),
|
|
||||||
Key::F7 => Some(input_event_codes::KEY_F7!()),
|
|
||||||
Key::F8 => Some(input_event_codes::KEY_F8!()),
|
|
||||||
Key::F9 => Some(input_event_codes::KEY_F9!()),
|
|
||||||
Key::F10 => Some(input_event_codes::KEY_F10!()),
|
|
||||||
Key::F11 => Some(input_event_codes::KEY_F11!()),
|
|
||||||
Key::F12 => Some(input_event_codes::KEY_F12!()),
|
|
||||||
Key::Comma => Some(input_event_codes::KEY_COMMA!()),
|
|
||||||
Key::Period => Some(input_event_codes::KEY_DOT!()),
|
|
||||||
Key::SlashFwd => Some(input_event_codes::KEY_SLASH!()),
|
|
||||||
Key::SlashBack => Some(input_event_codes::KEY_BACKSLASH!()),
|
|
||||||
Key::Semicolon => Some(input_event_codes::KEY_SEMICOLON!()),
|
|
||||||
Key::Apostrophe => Some(input_event_codes::KEY_APOSTROPHE!()),
|
|
||||||
Key::BracketOpen => Some(input_event_codes::KEY_LEFTBRACE!()),
|
|
||||||
Key::BracketClose => Some(input_event_codes::KEY_RIGHTBRACE!()),
|
|
||||||
Key::Minus => Some(input_event_codes::KEY_MINUS!()),
|
|
||||||
Key::Equals => Some(input_event_codes::KEY_EQUAL!()),
|
|
||||||
Key::Backtick => None,
|
|
||||||
Key::LCmd => Some(input_event_codes::KEY_LEFTMETA!()),
|
|
||||||
Key::RCmd => Some(input_event_codes::KEY_RIGHTMETA!()),
|
|
||||||
Key::Multiply => Some(input_event_codes::KEY_NUMERIC_STAR!()),
|
|
||||||
Key::Add => Some(input_event_codes::KEY_KPPLUS!()),
|
|
||||||
Key::Subtract => Some(input_event_codes::KEY_MINUS!()),
|
|
||||||
Key::Decimal => Some(input_event_codes::KEY_DOT!()),
|
|
||||||
Key::Divide => Some(input_event_codes::KEY_SLASH!()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
275
src/objects/input/sk.kmp
Normal file
275
src/objects/input/sk.kmp
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
xkb_keymap {
|
||||||
|
|
||||||
|
default xkb_keycodes "basic" {
|
||||||
|
minimum = 8;
|
||||||
|
maximum = 255;
|
||||||
|
|
||||||
|
<backspace> = 8;
|
||||||
|
<tab> = 9;
|
||||||
|
<return> = 13;
|
||||||
|
<shift> = 16;
|
||||||
|
<ctrl> = 17;
|
||||||
|
<alt> = 18;
|
||||||
|
<caps_lock> = 20;
|
||||||
|
<esc> = 27;
|
||||||
|
<space> = 32;
|
||||||
|
<end> = 35;
|
||||||
|
<home> = 36;
|
||||||
|
<left> = 37;
|
||||||
|
<right> = 39;
|
||||||
|
<up> = 38;
|
||||||
|
<down> = 40;
|
||||||
|
<page_up> = 33;
|
||||||
|
<page_down> = 34;
|
||||||
|
<printscreen> = 42;
|
||||||
|
<key_insert> = 45;
|
||||||
|
<del> = 46;
|
||||||
|
|
||||||
|
<0> = 48;
|
||||||
|
<1> = 49;
|
||||||
|
<2> = 50;
|
||||||
|
<3> = 51;
|
||||||
|
<4> = 52;
|
||||||
|
<5> = 53;
|
||||||
|
<6> = 54;
|
||||||
|
<7> = 55;
|
||||||
|
<8> = 56;
|
||||||
|
<9> = 57;
|
||||||
|
|
||||||
|
<a> = 65;
|
||||||
|
<b> = 66;
|
||||||
|
<c> = 67;
|
||||||
|
<d> = 68;
|
||||||
|
<e> = 69;
|
||||||
|
<f> = 70;
|
||||||
|
<g> = 71;
|
||||||
|
<h> = 72;
|
||||||
|
<i> = 73;
|
||||||
|
<j> = 74;
|
||||||
|
<k> = 75;
|
||||||
|
<l> = 76;
|
||||||
|
<m> = 77;
|
||||||
|
<n> = 78;
|
||||||
|
<o> = 79;
|
||||||
|
<p> = 80;
|
||||||
|
<q> = 81;
|
||||||
|
<r> = 82;
|
||||||
|
<s> = 83;
|
||||||
|
<t> = 84;
|
||||||
|
<u> = 85;
|
||||||
|
<v> = 86;
|
||||||
|
<w> = 87;
|
||||||
|
<x> = 88;
|
||||||
|
<y> = 89;
|
||||||
|
<z> = 90;
|
||||||
|
|
||||||
|
<num0> = 96;
|
||||||
|
<num1> = 97;
|
||||||
|
<num2> = 98;
|
||||||
|
<num3> = 99;
|
||||||
|
<num4> = 100;
|
||||||
|
<num5> = 101;
|
||||||
|
<num6> = 102;
|
||||||
|
<num7> = 103;
|
||||||
|
<num8> = 104;
|
||||||
|
<num9> = 105;
|
||||||
|
|
||||||
|
<f1> = 112;
|
||||||
|
<f2> = 113;
|
||||||
|
<f3> = 114;
|
||||||
|
<f4> = 115;
|
||||||
|
<f5> = 116;
|
||||||
|
<f6> = 117;
|
||||||
|
<f7> = 118;
|
||||||
|
<f8> = 119;
|
||||||
|
<f9> = 120;
|
||||||
|
<f10> = 121;
|
||||||
|
<f11> = 122;
|
||||||
|
<f12> = 123;
|
||||||
|
|
||||||
|
<comma> = 188;
|
||||||
|
<period> = 190;
|
||||||
|
<slash_fwd> = 191;
|
||||||
|
<slash_back> = 220;
|
||||||
|
<semicolon> = 186;
|
||||||
|
<apostrophe> = 222;
|
||||||
|
<bracket_open> = 219;
|
||||||
|
<bracket_close> = 221;
|
||||||
|
<minus> = 189;
|
||||||
|
<equals> = 187;
|
||||||
|
<backtick> = 192;
|
||||||
|
<lcmd> = 91;
|
||||||
|
<rcmd> = 92;
|
||||||
|
<multiply> = 106;
|
||||||
|
<add> = 107;
|
||||||
|
<subtract> = 109;
|
||||||
|
<decimal> = 110;
|
||||||
|
<divide> = 111;
|
||||||
|
};
|
||||||
|
|
||||||
|
partial default xkb_types "basic" {
|
||||||
|
virtual_modifiers Alt;
|
||||||
|
|
||||||
|
type "ONE_LEVEL" {
|
||||||
|
modifiers= none;
|
||||||
|
level_name[1]= "Any";
|
||||||
|
};
|
||||||
|
type "TWO_LEVEL" {
|
||||||
|
modifiers= Shift;
|
||||||
|
map[Shift]= 2;
|
||||||
|
level_name[1]= "Base";
|
||||||
|
level_name[2]= "Shift";
|
||||||
|
};
|
||||||
|
type "ALPHABETIC" {
|
||||||
|
modifiers= Shift+Lock;
|
||||||
|
map[Shift]= 2;
|
||||||
|
map[Lock]= 2;
|
||||||
|
level_name[1]= "Base";
|
||||||
|
level_name[2]= "Caps";
|
||||||
|
};
|
||||||
|
type "SHIFT+ALT" {
|
||||||
|
modifiers= Shift+Alt;
|
||||||
|
map[Shift+Alt]= 2;
|
||||||
|
level_name[1]= "Base";
|
||||||
|
level_name[2]= "Shift+Alt";
|
||||||
|
};
|
||||||
|
type "PC_CONTROL_LEVEL2" {
|
||||||
|
modifiers= Control;
|
||||||
|
map[Control]= 2;
|
||||||
|
level_name[1]= "Base";
|
||||||
|
level_name[2]= "Control";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
partial default xkb_compatibility "basic" {
|
||||||
|
interpret.useModMapMods= AnyLevel;
|
||||||
|
interpret.repeat= False;
|
||||||
|
|
||||||
|
interpret ISO_Level2_Latch+Exactly(Shift) {
|
||||||
|
useModMapMods=level1;
|
||||||
|
action= LatchMods(modifiers=Shift,clearLocks,latchToLock);
|
||||||
|
};
|
||||||
|
interpret Caps_Lock+AnyOfOrNone(all) {
|
||||||
|
action= LockMods(modifiers=Lock);
|
||||||
|
};
|
||||||
|
indicator "Caps Lock" {
|
||||||
|
whichModState= locked;
|
||||||
|
modifiers= Lock;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
default xkb_symbols "basic" {
|
||||||
|
name[Group1]="English (US)";
|
||||||
|
key <backspace> { [ BackSpace, BackSpace ] };
|
||||||
|
key <tab> { [ Tab, ISO_Left_Tab ] };
|
||||||
|
key <return> { [ Return ] };
|
||||||
|
key <shift> { [ Shift_L ] };
|
||||||
|
key <shift> { [ Shift_R ] };
|
||||||
|
key <ctrl> { [ Control_L ] };
|
||||||
|
key <ctrl> { [ Control_R ] };
|
||||||
|
key <alt> { [ Alt_L ] };
|
||||||
|
key <alt> { [ Alt_R ] };
|
||||||
|
key <caps_lock> { [ Caps_Lock ] };
|
||||||
|
key <esc> { [ Escape ] };
|
||||||
|
key <space> { [ space ] };
|
||||||
|
key <end> { [ End ] };
|
||||||
|
key <home> { [ Home ] };
|
||||||
|
key <left> { [ Left ] };
|
||||||
|
key <right> { [ Right ] };
|
||||||
|
key <up> { [ Up ] };
|
||||||
|
key <down> { [ Down ] };
|
||||||
|
key <page_up> { [ Page_Up ] };
|
||||||
|
key <page_down> { [ Page_Down ] };
|
||||||
|
key <printscreen> { [ Print ] };
|
||||||
|
key <key_insert> { [ Insert ] };
|
||||||
|
key <del> { [ Delete ] };
|
||||||
|
|
||||||
|
key <1> { [ 1, exclam ] };
|
||||||
|
key <2> { [ 2, at ] };
|
||||||
|
key <3> { [ 3, numbersign ] };
|
||||||
|
key <4> { [ 4, dollar ] };
|
||||||
|
key <5> { [ 5, percent ] };
|
||||||
|
key <6> { [ 6, asciicircum ] };
|
||||||
|
key <7> { [ 7, ampersand ] };
|
||||||
|
key <8> { [ 8, asterisk ] };
|
||||||
|
key <9> { [ 9, parenleft ] };
|
||||||
|
key <0> { [ 0, parenright ] };
|
||||||
|
|
||||||
|
key <a> { [ a, A ] };
|
||||||
|
key <b> { [ b, B ] };
|
||||||
|
key <c> { [ c, C ] };
|
||||||
|
key <d> { [ d, D ] };
|
||||||
|
key <e> { [ e, E ] };
|
||||||
|
key <f> { [ f, F ] };
|
||||||
|
key <g> { [ g, G ] };
|
||||||
|
key <h> { [ h, H ] };
|
||||||
|
key <i> { [ i, I ] };
|
||||||
|
key <j> { [ j, J ] };
|
||||||
|
key <k> { [ k, K ] };
|
||||||
|
key <l> { [ l, L ] };
|
||||||
|
key <m> { [ m, M ] };
|
||||||
|
key <n> { [ n, N ] };
|
||||||
|
key <o> { [ o, O ] };
|
||||||
|
key <p> { [ p, P ] };
|
||||||
|
key <q> { [ q, Q ] };
|
||||||
|
key <r> { [ r, R ] };
|
||||||
|
key <s> { [ s, S ] };
|
||||||
|
key <t> { [ t, T ] };
|
||||||
|
key <u> { [ u, U ] };
|
||||||
|
key <v> { [ v, V ] };
|
||||||
|
key <w> { [ w, W ] };
|
||||||
|
key <x> { [ x, X ] };
|
||||||
|
key <y> { [ y, Y ] };
|
||||||
|
key <z> { [ z, Z ] };
|
||||||
|
|
||||||
|
key <num0> { [ KP_0 ] };
|
||||||
|
key <num1> { [ KP_1 ] };
|
||||||
|
key <num2> { [ KP_2 ] };
|
||||||
|
key <num3> { [ KP_3 ] };
|
||||||
|
key <num4> { [ KP_4 ] };
|
||||||
|
key <num5> { [ KP_5 ] };
|
||||||
|
key <num6> { [ KP_6 ] };
|
||||||
|
key <num7> { [ KP_7 ] };
|
||||||
|
key <num8> { [ KP_8 ] };
|
||||||
|
key <num9> { [ KP_9 ] };
|
||||||
|
|
||||||
|
key <f1> { [ F1 ] };
|
||||||
|
key <f2> { [ F2 ] };
|
||||||
|
key <f3> { [ F3 ] };
|
||||||
|
key <f4> { [ F4 ] };
|
||||||
|
key <f5> { [ F5 ] };
|
||||||
|
key <f6> { [ F6 ] };
|
||||||
|
key <f7> { [ F7 ] };
|
||||||
|
key <f8> { [ F8 ] };
|
||||||
|
key <f9> { [ F9 ] };
|
||||||
|
key <f10> { [ F10 ] };
|
||||||
|
key <f11> { [ F11 ] };
|
||||||
|
key <f12> { [ F12 ] };
|
||||||
|
|
||||||
|
key <comma> { [ comma, less ] };
|
||||||
|
key <period> { [ period, greater ] };
|
||||||
|
key <slash_fwd> { [ slash, question ] };
|
||||||
|
key <slash_back> { [ backslash, bar ] };
|
||||||
|
key <semicolon> { [ semicolon, colon ] };
|
||||||
|
key <apostrophe> { [ apostrophe ] };
|
||||||
|
key <bracket_open> { [ bracketleft, braceleft ] };
|
||||||
|
key <bracket_close> { [ bracketright, braceright ] };
|
||||||
|
key <minus> { [ minus, underscore ] };
|
||||||
|
key <equals> { [ equal, plus ] };
|
||||||
|
key <backtick> { [ grave, asciitilde ] };
|
||||||
|
key <lcmd> { [ Super_L ] };
|
||||||
|
key <rcmd> { [ Super_R ] };
|
||||||
|
key <multiply> { [ KP_Multiply ] };
|
||||||
|
key <add> { [ KP_Add ] };
|
||||||
|
key <subtract> { [ KP_Subtract ] };
|
||||||
|
key <decimal> { [ KP_Decimal ] };
|
||||||
|
key <divide> { [ KP_Divide ] };
|
||||||
|
|
||||||
|
modifier_map Shift { <shift> };
|
||||||
|
modifier_map Lock { <caps_lock> };
|
||||||
|
modifier_map Control { <caps_lock> };
|
||||||
|
modifier_map Mod1 { <alt> };
|
||||||
|
modifier_map Mod4 { <lcmd>, <rcmd> };
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
@@ -7,13 +7,15 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use glam::{Mat4, Vec2, Vec3};
|
use glam::{Mat4, Vec2};
|
||||||
|
use nanoid::nanoid;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use stardust_xr::values::Transform;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use stereokit::{
|
use stereokit::{
|
||||||
named_colors::WHITE, ButtonState, Handed, Model, RenderLayer, StereoKitDraw,
|
ButtonState, Color128, Handed, Model, RenderLayer, StereoKitDraw, StereoKitMultiThread,
|
||||||
StereoKitMultiThread,
|
|
||||||
};
|
};
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize)]
|
#[derive(Default, Deserialize, Serialize)]
|
||||||
struct ControllerDatamap {
|
struct ControllerDatamap {
|
||||||
@@ -31,19 +33,9 @@ pub struct SkController {
|
|||||||
}
|
}
|
||||||
impl SkController {
|
impl SkController {
|
||||||
pub fn new(sk: &impl StereoKitMultiThread, handed: Handed) -> Result<Self> {
|
pub fn new(sk: &impl StereoKitMultiThread, handed: Handed) -> Result<Self> {
|
||||||
let _node = Node::create(
|
let _node = Node::create(&INTERNAL_CLIENT, "", &nanoid!(), false).add_to_scenegraph()?;
|
||||||
&INTERNAL_CLIENT,
|
|
||||||
"",
|
|
||||||
if handed == Handed::Left {
|
|
||||||
"controller_left"
|
|
||||||
} else {
|
|
||||||
"controller_right"
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.add_to_scenegraph()?;
|
|
||||||
Spatial::add_to(&_node, None, Mat4::IDENTITY, false)?;
|
Spatial::add_to(&_node, None, Mat4::IDENTITY, false)?;
|
||||||
let model = sk.model_create_mem("cursor.glb", include_bytes!("cursor.glb"), None)?;
|
let model = sk.model_create_mem("cursor", include_bytes!("cursor.glb"), None)?;
|
||||||
let tip = InputType::Tip(Tip::default());
|
let tip = InputType::Tip(Tip::default());
|
||||||
let input = InputMethod::add_to(&_node, tip, None)?;
|
let input = InputMethod::add_to(&_node, tip, None)?;
|
||||||
Ok(SkController {
|
Ok(SkController {
|
||||||
@@ -54,21 +46,27 @@ impl SkController {
|
|||||||
datamap: Default::default(),
|
datamap: Default::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
#[instrument(level = "debug", name = "Update StereoKit Tip Input Method", skip_all)]
|
||||||
pub fn update(&mut self, sk: &impl StereoKitDraw) {
|
pub fn update(&mut self, sk: &impl StereoKitDraw) {
|
||||||
let controller = sk.input_controller(self.handed);
|
let controller = sk.input_controller(self.handed);
|
||||||
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::ACTIVE);
|
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::ACTIVE);
|
||||||
if *self.input.enabled.lock() {
|
if *self.input.enabled.lock() {
|
||||||
let world_transform = Mat4::from_rotation_translation(
|
|
||||||
controller.aim.orientation,
|
|
||||||
controller.aim.position,
|
|
||||||
);
|
|
||||||
sk.model_draw(
|
sk.model_draw(
|
||||||
&self.model,
|
&self.model,
|
||||||
world_transform * Mat4::from_scale(Vec3::ONE * 0.02),
|
Mat4::from_rotation_translation(
|
||||||
WHITE,
|
controller.aim.orientation,
|
||||||
RenderLayer::LAYER0,
|
controller.aim.position,
|
||||||
|
),
|
||||||
|
Color128::default(),
|
||||||
|
RenderLayer::all(),
|
||||||
|
);
|
||||||
|
self.input.spatial.set_local_transform_components(
|
||||||
|
None,
|
||||||
|
Transform::from_position_rotation(
|
||||||
|
controller.aim.position,
|
||||||
|
controller.aim.orientation,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
self.input.spatial.set_local_transform(world_transform);
|
|
||||||
}
|
}
|
||||||
self.datamap.select = controller.trigger;
|
self.datamap.select = controller.trigger;
|
||||||
self.datamap.grab = controller.grip;
|
self.datamap.grab = controller.grip;
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ use serde::{Deserialize, Serialize};
|
|||||||
use stardust_xr::schemas::flat::{Hand as FlatHand, Joint};
|
use stardust_xr::schemas::flat::{Hand as FlatHand, Joint};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use stereokit::{ButtonState, HandJoint, Handed, StereoKitMultiThread};
|
use stereokit::{ButtonState, HandJoint, Handed, StereoKitMultiThread};
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
fn convert_joint(joint: HandJoint) -> Joint {
|
fn convert_joint(joint: HandJoint) -> Joint {
|
||||||
Joint {
|
Joint {
|
||||||
position: joint.position.into(),
|
position: joint.position.into(),
|
||||||
rotation: joint.orientation.into(),
|
rotation: joint.orientation.into(),
|
||||||
radius: joint.radius,
|
radius: joint.radius,
|
||||||
distance: 0.0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,16 +53,13 @@ impl SkHand {
|
|||||||
datamap: Default::default(),
|
datamap: Default::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn update(&mut self, controller_enabled: bool, sk: &impl StereoKitMultiThread) {
|
#[instrument(level = "debug", name = "Update Hand Input Method", skip_all)]
|
||||||
|
pub fn update(&mut self, sk: &impl StereoKitMultiThread) {
|
||||||
let sk_hand = sk.input_hand(self.handed);
|
let sk_hand = sk.input_hand(self.handed);
|
||||||
if let InputType::Hand(hand) = &mut *self.input.specialization.lock() {
|
if let InputType::Hand(hand) = &mut *self.input.specialization.lock() {
|
||||||
let controller_active = controller_enabled
|
let controller = sk.input_controller(self.handed);
|
||||||
&& sk
|
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::INACTIVE)
|
||||||
.input_controller(self.handed)
|
&& sk_hand.tracked_state.contains(ButtonState::ACTIVE);
|
||||||
.tracked
|
|
||||||
.contains(ButtonState::ACTIVE);
|
|
||||||
*self.input.enabled.lock() =
|
|
||||||
!controller_active && sk_hand.tracked_state.contains(ButtonState::ACTIVE);
|
|
||||||
sk.input_hand_visible(self.handed, *self.input.enabled.lock());
|
sk.input_hand_visible(self.handed, *self.input.enabled.lock());
|
||||||
if *self.input.enabled.lock() {
|
if *self.input.enabled.lock() {
|
||||||
hand.base.thumb.tip = convert_joint(sk_hand.fingers[0][4]);
|
hand.base.thumb.tip = convert_joint(sk_hand.fingers[0][4]);
|
||||||
|
|||||||
76
src/openxr/action.rs
Normal file
76
src/openxr/action.rs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
use super::Object;
|
||||||
|
use crate::{core::client::Client, nodes::Node};
|
||||||
|
use color_eyre::eyre::{bail, Result};
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use stardust_xr::schemas::flex::deserialize;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Action {
|
||||||
|
// _info: InstanceInfo,
|
||||||
|
_localized_name: String,
|
||||||
|
suggested_bindings: Mutex<FxHashMap<String, String>>,
|
||||||
|
}
|
||||||
|
impl Action {
|
||||||
|
pub fn create_action_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
|
let Object::ActionSet(action_set) = node.get_aspect("OpenXR interface", "Instance", |n| &n.openxr_object)? else {
|
||||||
|
bail!("Object not an instance")
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct CreateActionInfo {
|
||||||
|
name: String,
|
||||||
|
localized_name: String,
|
||||||
|
}
|
||||||
|
let info: CreateActionInfo = dbg!(deserialize(data)?);
|
||||||
|
|
||||||
|
let node = Node::create(
|
||||||
|
&node.get_client().unwrap(),
|
||||||
|
node.get_path(),
|
||||||
|
&info.name,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.add_to_scenegraph();
|
||||||
|
node.add_local_signal("suggest_binding", Self::suggest_binding_flex);
|
||||||
|
|
||||||
|
let action = Arc::new(Action {
|
||||||
|
_localized_name: info.localized_name,
|
||||||
|
suggested_bindings: Mutex::new(FxHashMap::default()),
|
||||||
|
});
|
||||||
|
action_set
|
||||||
|
.actions
|
||||||
|
.lock()
|
||||||
|
.insert(info.name, Arc::downgrade(&action));
|
||||||
|
node.openxr_object.set(Object::Action(action)).unwrap();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
pub fn suggest_binding_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
|
let Object::Action(action) = node.get_aspect("OpenXR interface", "Action", |n| &n.openxr_object)? else {
|
||||||
|
bail!("Object not an action")
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct SuggestBindingArgs {
|
||||||
|
interaction_profile: String,
|
||||||
|
binding: String,
|
||||||
|
}
|
||||||
|
let args: SuggestBindingArgs = dbg!(deserialize(data)?);
|
||||||
|
action
|
||||||
|
.suggested_bindings
|
||||||
|
.lock()
|
||||||
|
.insert(args.interaction_profile, args.binding);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
60
src/openxr/action_set.rs
Normal file
60
src/openxr/action_set.rs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
use super::{action::Action, Object};
|
||||||
|
use crate::{core::client::Client, nodes::Node};
|
||||||
|
use color_eyre::eyre::{bail, Result};
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use stardust_xr::schemas::flex::deserialize;
|
||||||
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ActionSet {
|
||||||
|
// _info: InstanceInfo,
|
||||||
|
_localized_name: String,
|
||||||
|
_priority: u32,
|
||||||
|
pub actions: Mutex<FxHashMap<String, Weak<Action>>>,
|
||||||
|
}
|
||||||
|
impl ActionSet {
|
||||||
|
pub fn create_action_set_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
|
let Object::Instance(instance) = node.get_aspect("OpenXR interface", "Instance", |n| &n.openxr_object)? else {
|
||||||
|
bail!("Object not an instance")
|
||||||
|
};
|
||||||
|
let Some(instance) = instance.get() else { bail!("Instance not initialized") };
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct CreateActionSetInfo {
|
||||||
|
name: String,
|
||||||
|
localized_name: String,
|
||||||
|
priority: u32,
|
||||||
|
}
|
||||||
|
let info: CreateActionSetInfo = deserialize(data)?;
|
||||||
|
|
||||||
|
let node = Node::create(
|
||||||
|
&node.get_client().unwrap(),
|
||||||
|
"/openxr/action_set",
|
||||||
|
&info.name,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.add_to_scenegraph();
|
||||||
|
node.add_local_signal("create_action", Action::create_action_flex);
|
||||||
|
|
||||||
|
let action_set = Arc::new(ActionSet {
|
||||||
|
_localized_name: info.localized_name,
|
||||||
|
_priority: info.priority,
|
||||||
|
actions: Mutex::new(FxHashMap::default()),
|
||||||
|
});
|
||||||
|
instance
|
||||||
|
.action_sets
|
||||||
|
.lock()
|
||||||
|
.insert(info.name, Arc::downgrade(&action_set));
|
||||||
|
node.openxr_object
|
||||||
|
.set(Object::ActionSet(action_set))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/openxr/instance.rs
Normal file
47
src/openxr/instance.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
use super::{action_set::ActionSet, Object};
|
||||||
|
use crate::{core::client::Client, nodes::Node};
|
||||||
|
use color_eyre::eyre::{bail, eyre, Result};
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use stardust_xr::schemas::flex::deserialize;
|
||||||
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct InstanceInfo {
|
||||||
|
_app_info: ApplicationInfo,
|
||||||
|
_extension_names: Vec<String>,
|
||||||
|
}
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct ApplicationInfo {
|
||||||
|
_app_name: String,
|
||||||
|
_app_version: u32,
|
||||||
|
_engine_name: String,
|
||||||
|
_engine_version: u32,
|
||||||
|
_api_version: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Instance {
|
||||||
|
_info: InstanceInfo,
|
||||||
|
pub action_sets: Mutex<FxHashMap<String, Weak<ActionSet>>>,
|
||||||
|
}
|
||||||
|
impl Instance {
|
||||||
|
pub fn setup_instance_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
|
let Object::Instance(instance) = node.get_aspect("OpenXR interface", "Instance", |n| &n.openxr_object)? else {
|
||||||
|
bail!("Object not an instance")
|
||||||
|
};
|
||||||
|
let instance_info = Instance {
|
||||||
|
_info: deserialize(data)?,
|
||||||
|
action_sets: Mutex::new(FxHashMap::default()),
|
||||||
|
};
|
||||||
|
dbg!(&instance_info);
|
||||||
|
instance
|
||||||
|
.set(Arc::new(instance_info))
|
||||||
|
.map_err(|_| eyre!("Instance already set up"))
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/openxr/mod.rs
Normal file
34
src/openxr/mod.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
mod action;
|
||||||
|
mod action_set;
|
||||||
|
mod instance;
|
||||||
|
mod session;
|
||||||
|
mod system;
|
||||||
|
|
||||||
|
use self::{
|
||||||
|
action::Action, action_set::ActionSet, instance::Instance, session::Session, system::System,
|
||||||
|
};
|
||||||
|
use crate::{core::client::Client, nodes::Node};
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Object {
|
||||||
|
Instance(OnceCell<Arc<Instance>>),
|
||||||
|
System(System),
|
||||||
|
Session(Session),
|
||||||
|
ActionSet(Arc<ActionSet>),
|
||||||
|
Action(Arc<Action>),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_interface(client: &Arc<Client>) {
|
||||||
|
let node = Node::create(client, "", "openxr", false);
|
||||||
|
node.add_local_signal("setup_instance", Instance::setup_instance_flex);
|
||||||
|
node.add_local_method("get_system", System::get_system_flex);
|
||||||
|
node.add_local_signal("create_action_set", ActionSet::create_action_set_flex);
|
||||||
|
|
||||||
|
node.openxr_object
|
||||||
|
.set(Object::Instance(OnceCell::new()))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
node.add_to_scenegraph();
|
||||||
|
}
|
||||||
34
src/openxr/session.rs
Normal file
34
src/openxr/session.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use color_eyre::eyre::{bail, Result};
|
||||||
|
use stardust_xr::schemas::flex::deserialize;
|
||||||
|
|
||||||
|
use super::Object;
|
||||||
|
use crate::{core::client::Client, nodes::Node};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Session {
|
||||||
|
// _info: InstanceInfo,
|
||||||
|
}
|
||||||
|
impl Session {
|
||||||
|
pub fn create_session_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
|
let Object::System(_system) = node.get_aspect("OpenXR interface", "Instance", |n| &n.openxr_object)? else {
|
||||||
|
bail!("Object not a system")
|
||||||
|
};
|
||||||
|
let node = Node::create(
|
||||||
|
&node.get_client().unwrap(),
|
||||||
|
node.get_path(),
|
||||||
|
deserialize(data)?,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.add_to_scenegraph();
|
||||||
|
let session = Session {};
|
||||||
|
node.openxr_object.set(Object::Session(session)).unwrap();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
76
src/openxr/system.rs
Normal file
76
src/openxr/system.rs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
use super::{session::Session, Object};
|
||||||
|
use crate::{core::client::Client, nodes::Node, SK_INFO};
|
||||||
|
use color_eyre::eyre::{bail, eyre, Result};
|
||||||
|
use serde::Serialize;
|
||||||
|
use stardust_xr::schemas::flex::{deserialize, serialize};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum System {
|
||||||
|
Handheld,
|
||||||
|
HeadMounted,
|
||||||
|
}
|
||||||
|
impl System {
|
||||||
|
pub fn from_raw(raw: u32) -> Option<Self> {
|
||||||
|
match raw {
|
||||||
|
1 => Some(System::Handheld),
|
||||||
|
2 => Some(System::HeadMounted),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_system_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<Vec<u8>> {
|
||||||
|
// let Object::Instance(instance) = node.get_aspect("OpenXR interface", "Instance", |n| &n.openxr_object)? else {
|
||||||
|
// bail!("Object not an instance")
|
||||||
|
// };
|
||||||
|
let system_type: u32 = deserialize(data)?;
|
||||||
|
let system = System::from_raw(system_type).ok_or_else(|| eyre!("No system exists!"))?;
|
||||||
|
let node = Node::create(
|
||||||
|
&node.get_client().unwrap(),
|
||||||
|
node.get_path(),
|
||||||
|
&format!("system{}", system_type),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.add_to_scenegraph();
|
||||||
|
node.add_local_method("views", System::views_flex);
|
||||||
|
node.add_local_signal("create_session", Session::create_session_flex);
|
||||||
|
node.openxr_object.set(Object::System(system)).unwrap();
|
||||||
|
|
||||||
|
Ok(serialize(system_type)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn views_flex(_node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<Vec<u8>> {
|
||||||
|
let view_configuration_type: u64 = deserialize(data)?;
|
||||||
|
let view_count: u32 = match view_configuration_type {
|
||||||
|
1 => 1,
|
||||||
|
2 => 2,
|
||||||
|
1000037000 => 4,
|
||||||
|
1000054000 => 1,
|
||||||
|
_ => bail!("Invalid view config type"),
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
struct View {
|
||||||
|
recommended_image_rect_width: u32,
|
||||||
|
max_image_rect_width: u32,
|
||||||
|
recommended_image_rect_height: u32,
|
||||||
|
max_image_rect_height: u32,
|
||||||
|
}
|
||||||
|
let sk_info = SK_INFO.get().unwrap();
|
||||||
|
|
||||||
|
Ok(serialize(
|
||||||
|
(0..view_count)
|
||||||
|
.map(|_| View {
|
||||||
|
recommended_image_rect_width: sk_info.display_width,
|
||||||
|
max_image_rect_width: sk_info.display_width,
|
||||||
|
recommended_image_rect_height: sk_info.display_height,
|
||||||
|
max_image_rect_height: sk_info.display_height,
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,9 +25,11 @@ impl CompositorHandler for WaylandState {
|
|||||||
.data_map
|
.data_map
|
||||||
.insert_if_missing_threadsafe(|| AtomicU32::new(0));
|
.insert_if_missing_threadsafe(|| AtomicU32::new(0));
|
||||||
if !count_new {
|
if !count_new {
|
||||||
if let Some(stored_count) = data.data_map.get::<AtomicU32>() {
|
count = data
|
||||||
count = stored_count.fetch_add(1, Ordering::Relaxed);
|
.data_map
|
||||||
}
|
.get::<AtomicU32>()
|
||||||
|
.unwrap()
|
||||||
|
.fetch_add(1, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.data_map.get::<Arc<CoreSurface>>().cloned()
|
data.data_map.get::<Arc<CoreSurface>>().cloned()
|
||||||
|
|||||||
@@ -90,8 +90,7 @@ impl KdeDecorationHandler for WaylandState {
|
|||||||
decoration: &OrgKdeKwinServerDecoration,
|
decoration: &OrgKdeKwinServerDecoration,
|
||||||
mode: WEnum<KdeMode>,
|
mode: WEnum<KdeMode>,
|
||||||
) {
|
) {
|
||||||
let Ok(mode) = mode.into_result() else {return};
|
decoration.mode(mode.into_result().unwrap());
|
||||||
decoration.mode(mode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delegate_kde_decoration!(WaylandState);
|
delegate_kde_decoration!(WaylandState);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ mod compositor;
|
|||||||
mod data_device;
|
mod data_device;
|
||||||
mod decoration;
|
mod decoration;
|
||||||
mod seat;
|
mod seat;
|
||||||
|
mod shaders;
|
||||||
mod state;
|
mod state;
|
||||||
mod surface;
|
mod surface;
|
||||||
// mod xdg_activation;
|
// mod xdg_activation;
|
||||||
@@ -10,23 +11,21 @@ mod xdg_shell;
|
|||||||
pub mod xwayland;
|
pub mod xwayland;
|
||||||
|
|
||||||
use self::{state::WaylandState, surface::CORE_SURFACES};
|
use self::{state::WaylandState, surface::CORE_SURFACES};
|
||||||
use crate::core::buffers::BufferManager;
|
|
||||||
use crate::wayland::seat::SeatData;
|
use crate::wayland::seat::SeatData;
|
||||||
use crate::{core::task, wayland::state::ClientState};
|
use crate::{core::task, wayland::state::ClientState};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::{ensure, Result};
|
||||||
use global_counter::primitive::exact::CounterU32;
|
use global_counter::primitive::exact::CounterU32;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use sk::StereoKitDraw;
|
use sk::StereoKitDraw;
|
||||||
use smithay::backend::allocator::dmabuf::Dmabuf;
|
use smithay::backend::allocator::dmabuf::Dmabuf;
|
||||||
|
use smithay::backend::egl::EGLContext;
|
||||||
|
use smithay::backend::renderer::gles::GlesRenderer;
|
||||||
use smithay::backend::renderer::ImportDma;
|
use smithay::backend::renderer::ImportDma;
|
||||||
use smithay::reexports::wayland_server::backend::ClientId;
|
use smithay::reexports::wayland_server::{backend::GlobalId, Display, ListeningSocket};
|
||||||
use smithay::reexports::wayland_server::DisplayHandle;
|
|
||||||
use smithay::reexports::wayland_server::{Display, ListeningSocket};
|
|
||||||
use std::ffi::OsStr;
|
|
||||||
use std::os::fd::OwnedFd;
|
|
||||||
use std::os::unix::prelude::AsRawFd;
|
use std::os::unix::prelude::AsRawFd;
|
||||||
use std::{
|
use std::{
|
||||||
|
ffi::c_void,
|
||||||
os::unix::{net::UnixListener, prelude::FromRawFd},
|
os::unix::{net::UnixListener, prelude::FromRawFd},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
@@ -35,65 +34,87 @@ use tokio::sync::mpsc::UnboundedReceiver;
|
|||||||
use tokio::{
|
use tokio::{
|
||||||
io::unix::AsyncFd, net::UnixListener as AsyncUnixListener, sync::mpsc, task::JoinHandle,
|
io::unix::AsyncFd, net::UnixListener as AsyncUnixListener, sync::mpsc, task::JoinHandle,
|
||||||
};
|
};
|
||||||
use tracing::{debug_span, info, instrument};
|
use tracing::{debug, debug_span, info, instrument};
|
||||||
|
|
||||||
pub static WAYLAND_DISPLAY: OnceCell<String> = OnceCell::new();
|
pub static WAYLAND_DISPLAY: OnceCell<String> = OnceCell::new();
|
||||||
pub static SERIAL_COUNTER: CounterU32 = CounterU32::new(0);
|
pub static SERIAL_COUNTER: CounterU32 = CounterU32::new(0);
|
||||||
|
|
||||||
pub struct DisplayWrapper(Mutex<Display<WaylandState>>, DisplayHandle);
|
struct EGLRawHandles {
|
||||||
impl DisplayWrapper {
|
display: *const c_void,
|
||||||
pub fn handle(&self) -> DisplayHandle {
|
config: *const c_void,
|
||||||
self.1.clone()
|
context: *const c_void,
|
||||||
}
|
}
|
||||||
pub fn dispatch_clients(&self, state: &mut WaylandState) -> Result<usize, std::io::Error> {
|
fn get_sk_egl() -> Result<EGLRawHandles> {
|
||||||
self.0.lock().dispatch_clients(state)
|
ensure!(
|
||||||
}
|
unsafe { sk::sys::backend_graphics_get() }
|
||||||
pub fn flush_clients(&self, client: Option<ClientId>) {
|
== sk::sys::backend_graphics__backend_graphics_opengles_egl,
|
||||||
if let Some(mut lock) = self.0.try_lock() {
|
"StereoKit is not running using EGL!"
|
||||||
let _ = lock.backend().flush(client);
|
);
|
||||||
|
|
||||||
|
Ok(unsafe {
|
||||||
|
EGLRawHandles {
|
||||||
|
display: sk::sys::backend_opengl_egl_get_display() as *const c_void,
|
||||||
|
config: sk::sys::backend_opengl_egl_get_config() as *const c_void,
|
||||||
|
context: sk::sys::backend_opengl_egl_get_context() as *const c_void,
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
pub fn poll_fd(&self) -> Result<OwnedFd, std::io::Error> {
|
|
||||||
self.0.lock().backend().poll_fd().try_clone_to_owned()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GLOBAL_DESTROY_QUEUE: OnceCell<mpsc::Sender<GlobalId>> = OnceCell::new();
|
||||||
|
|
||||||
pub struct Wayland {
|
pub struct Wayland {
|
||||||
display: Arc<DisplayWrapper>,
|
display: Arc<Mutex<Display<WaylandState>>>,
|
||||||
pub socket_name: Option<String>,
|
pub socket_name: String,
|
||||||
join_handle: JoinHandle<Result<()>>,
|
join_handle: JoinHandle<Result<()>>,
|
||||||
|
renderer: GlesRenderer,
|
||||||
dmabuf_rx: UnboundedReceiver<Dmabuf>,
|
dmabuf_rx: UnboundedReceiver<Dmabuf>,
|
||||||
wayland_state: Arc<Mutex<WaylandState>>,
|
wayland_state: Arc<Mutex<WaylandState>>,
|
||||||
#[cfg(feature = "xwayland")]
|
#[cfg(feature = "xwayland")]
|
||||||
pub xwayland_state: xwayland::XWaylandState,
|
pub xwayland_state: xwayland::XWaylandState,
|
||||||
}
|
}
|
||||||
impl Wayland {
|
impl Wayland {
|
||||||
pub fn new(buffer_manager: &BufferManager) -> Result<Self> {
|
pub fn new() -> Result<Self> {
|
||||||
|
let egl_raw_handles = get_sk_egl()?;
|
||||||
|
let renderer = unsafe {
|
||||||
|
GlesRenderer::new(EGLContext::from_raw(
|
||||||
|
egl_raw_handles.display,
|
||||||
|
egl_raw_handles.config,
|
||||||
|
egl_raw_handles.context,
|
||||||
|
)?)?
|
||||||
|
};
|
||||||
|
|
||||||
let display: Display<WaylandState> = Display::new()?;
|
let display: Display<WaylandState> = Display::new()?;
|
||||||
let display_handle = display.handle();
|
let display_handle = display.handle();
|
||||||
|
|
||||||
let (dmabuf_tx, dmabuf_rx) = mpsc::unbounded_channel();
|
let (dmabuf_tx, dmabuf_rx) = mpsc::unbounded_channel();
|
||||||
let display = Arc::new(DisplayWrapper(Mutex::new(display), display_handle.clone()));
|
let display = Arc::new(Mutex::new(display));
|
||||||
#[cfg(feature = "xwayland")]
|
#[cfg(feature = "xwayland")]
|
||||||
let xwayland_state = xwayland::XWaylandState::create(&display_handle)?;
|
let xwayland_state = xwayland::XWaylandState::create(&display_handle).unwrap();
|
||||||
let wayland_state = WaylandState::new(display_handle, &buffer_manager.renderer, dmabuf_tx);
|
let wayland_state =
|
||||||
|
WaylandState::new(display.clone(), display_handle, &renderer, dmabuf_tx);
|
||||||
|
|
||||||
|
let (global_destroy_queue_in, global_destroy_queue) = mpsc::channel(8);
|
||||||
|
GLOBAL_DESTROY_QUEUE.set(global_destroy_queue_in).unwrap();
|
||||||
|
|
||||||
let socket = ListeningSocket::bind_auto("wayland", 0..33)?;
|
let socket = ListeningSocket::bind_auto("wayland", 0..33)?;
|
||||||
let socket_name = socket
|
let socket_name = socket.socket_name().unwrap().to_str().unwrap().to_string();
|
||||||
.socket_name()
|
WAYLAND_DISPLAY
|
||||||
.and_then(OsStr::to_str)
|
.set(socket_name.clone())
|
||||||
.map(ToString::to_string);
|
.expect("seriously message nova this time they screwed up big time");
|
||||||
if let Some(socket_name) = &socket_name {
|
|
||||||
let _ = WAYLAND_DISPLAY.set(socket_name.clone());
|
|
||||||
}
|
|
||||||
info!(socket_name, "Wayland active");
|
info!(socket_name, "Wayland active");
|
||||||
|
|
||||||
let join_handle = Wayland::start_loop(display.clone(), socket, wayland_state.clone())?;
|
let join_handle = Wayland::start_loop(
|
||||||
|
display.clone(),
|
||||||
|
socket,
|
||||||
|
wayland_state.clone(),
|
||||||
|
global_destroy_queue,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(Wayland {
|
Ok(Wayland {
|
||||||
display,
|
display,
|
||||||
socket_name,
|
socket_name,
|
||||||
join_handle,
|
join_handle,
|
||||||
|
renderer,
|
||||||
dmabuf_rx,
|
dmabuf_rx,
|
||||||
wayland_state,
|
wayland_state,
|
||||||
#[cfg(feature = "xwayland")]
|
#[cfg(feature = "xwayland")]
|
||||||
@@ -102,39 +123,44 @@ impl Wayland {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start_loop(
|
fn start_loop(
|
||||||
display: Arc<DisplayWrapper>,
|
display: Arc<Mutex<Display<WaylandState>>>,
|
||||||
socket: ListeningSocket,
|
socket: ListeningSocket,
|
||||||
state: Arc<Mutex<WaylandState>>,
|
state: Arc<Mutex<WaylandState>>,
|
||||||
|
mut global_destroy_queue: mpsc::Receiver<GlobalId>,
|
||||||
) -> Result<JoinHandle<Result<()>>> {
|
) -> Result<JoinHandle<Result<()>>> {
|
||||||
let listen_async =
|
let listen_async =
|
||||||
AsyncUnixListener::from_std(unsafe { UnixListener::from_raw_fd(socket.as_raw_fd()) })?;
|
AsyncUnixListener::from_std(unsafe { UnixListener::from_raw_fd(socket.as_raw_fd()) })?;
|
||||||
|
|
||||||
let dispatch_poll_fd = display.poll_fd()?;
|
let dispatch_poll_fd = display.lock().backend().poll_fd().try_clone_to_owned()?;
|
||||||
let dispatch_poll_listener = AsyncFd::new(dispatch_poll_fd)?;
|
let dispatch_poll_listener = AsyncFd::new(dispatch_poll_fd)?;
|
||||||
|
|
||||||
let dh1 = display.handle();
|
let dh1 = display.lock().handle();
|
||||||
let mut dh2 = dh1.clone();
|
let mut dh2 = dh1.clone();
|
||||||
|
|
||||||
Ok(task::new(|| "wayland loop", async move {
|
Ok(task::new(|| "wayland loop", async move {
|
||||||
let _socket = socket; // Keep the socket alive
|
let _socket = socket; // Keep the socket alive
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
|
e = global_destroy_queue.recv() => { // New global to destroy
|
||||||
|
debug!(?e, "destroy global");
|
||||||
|
dh1.remove_global::<WaylandState>(e.unwrap());
|
||||||
|
}
|
||||||
acc = listen_async.accept() => { // New client connected
|
acc = listen_async.accept() => { // New client connected
|
||||||
let (stream, _) = acc?;
|
let (stream, _) = acc?;
|
||||||
let client_state = Arc::new(ClientState {
|
let client_state = Arc::new(ClientState {
|
||||||
id: OnceCell::new(),
|
|
||||||
compositor_state: Default::default(),
|
compositor_state: Default::default(),
|
||||||
display: Arc::downgrade(&display),
|
display: Arc::downgrade(&display),
|
||||||
seat: SeatData::new(&dh1)
|
seat: SeatData::new(&dh1)
|
||||||
});
|
});
|
||||||
let client = dh2.insert_client(stream.into_std()?, client_state.clone())?;
|
let client = dh2.insert_client(stream.into_std()?, client_state.clone())?;
|
||||||
let _ = client_state.seat.client.set(client.id());
|
client_state.seat.client.set(client.id()).unwrap();
|
||||||
}
|
}
|
||||||
e = dispatch_poll_listener.readable() => { // Dispatch
|
e = dispatch_poll_listener.readable() => { // Dispatch
|
||||||
let mut guard = e?;
|
let mut guard = e?;
|
||||||
debug_span!("Dispatch wayland event").in_scope(|| -> Result<(), color_eyre::Report> {
|
debug_span!("Dispatch wayland event").in_scope(|| -> Result<(), color_eyre::Report> {
|
||||||
|
let mut display = display.lock();
|
||||||
display.dispatch_clients(&mut *state.lock())?;
|
display.dispatch_clients(&mut *state.lock())?;
|
||||||
display.flush_clients(None);
|
display.flush_clients()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
guard.clear_ready();
|
guard.clear_ready();
|
||||||
@@ -144,27 +170,29 @@ impl Wayland {
|
|||||||
})?)
|
})?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(
|
#[instrument(level = "debug", name = "Wayland frame", skip(self, sk))]
|
||||||
level = "debug",
|
pub fn update(&mut self, sk: &impl StereoKitDraw) {
|
||||||
name = "Wayland frame",
|
|
||||||
skip(self, sk, buffer_manager)
|
|
||||||
)]
|
|
||||||
pub fn update(&mut self, sk: &impl StereoKitDraw, buffer_manager: &mut BufferManager) {
|
|
||||||
while let Ok(dmabuf) = self.dmabuf_rx.try_recv() {
|
while let Ok(dmabuf) = self.dmabuf_rx.try_recv() {
|
||||||
let _ = buffer_manager.renderer.import_dmabuf(&dmabuf, None);
|
let _ = self.renderer.import_dmabuf(&dmabuf, None);
|
||||||
}
|
}
|
||||||
for core_surface in CORE_SURFACES.get_valid_contents() {
|
for core_surface in CORE_SURFACES.get_valid_contents() {
|
||||||
core_surface.process(sk, &mut buffer_manager.renderer);
|
core_surface.process(sk, &mut self.renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.display.flush_clients(None);
|
self.display.lock().flush_clients().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn frame_event(&self, sk: &impl StereoKitDraw) {
|
pub fn frame_event(&self, sk: &impl StereoKitDraw) {
|
||||||
let output = self.wayland_state.lock().output.clone();
|
let state = self.wayland_state.lock();
|
||||||
|
|
||||||
for core_surface in CORE_SURFACES.get_valid_contents() {
|
for core_surface in CORE_SURFACES.get_valid_contents() {
|
||||||
core_surface.frame(sk, output.clone());
|
core_surface.frame(sk, state.output.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn make_context_current(&self) {
|
||||||
|
unsafe {
|
||||||
|
self.renderer.egl_context().make_current().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
use super::{
|
use super::{
|
||||||
state::{ClientState, WaylandState},
|
state::{ClientState, WaylandState},
|
||||||
surface::CoreSurface,
|
surface::CoreSurface,
|
||||||
SERIAL_COUNTER,
|
GLOBAL_DESTROY_QUEUE, SERIAL_COUNTER,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::core::task;
|
||||||
core::task,
|
use color_eyre::eyre::{eyre, Result};
|
||||||
nodes::items::panel::{Backend, Geometry, PanelItem},
|
|
||||||
};
|
|
||||||
use color_eyre::eyre::{bail, eyre, Result};
|
|
||||||
use mint::Vector2;
|
use mint::Vector2;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
@@ -36,46 +33,35 @@ use std::{
|
|||||||
};
|
};
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
use xkbcommon::xkb::{self, ffi::XKB_KEYMAP_FORMAT_TEXT_V1, Keycode, Keymap};
|
use xkbcommon::xkb::{self, ffi::XKB_KEYMAP_FORMAT_TEXT_V1, Keymap};
|
||||||
|
|
||||||
pub fn handle_cursor<B: Backend>(
|
|
||||||
panel_item: &Arc<PanelItem<B>>,
|
|
||||||
mut cursor: watch::Receiver<Option<CursorInfo>>,
|
|
||||||
) {
|
|
||||||
let panel_item_weak = Arc::downgrade(panel_item);
|
|
||||||
let _ = task::new(|| "cursor handler", async move {
|
|
||||||
while cursor.changed().await.is_ok() {
|
|
||||||
let Some(panel_item) = panel_item_weak.upgrade() else {continue};
|
|
||||||
let cursor_info = cursor.borrow();
|
|
||||||
panel_item.set_cursor(cursor_info.as_ref().and_then(CursorInfo::cursor_data));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct KeyboardInfo {
|
pub struct KeyboardInfo {
|
||||||
keymap_string: String,
|
|
||||||
keymap: KeymapFile,
|
keymap: KeymapFile,
|
||||||
state: xkb::State,
|
state: xkb::State,
|
||||||
mods: ModifiersState,
|
mods: ModifiersState,
|
||||||
keys: FxHashSet<u32>,
|
keys: FxHashSet<u32>,
|
||||||
}
|
}
|
||||||
impl KeyboardInfo {
|
impl KeyboardInfo {
|
||||||
pub fn new(keymap_string: String, keymap: &Keymap) -> Self {
|
pub fn new(keymap: &Keymap) -> Self {
|
||||||
KeyboardInfo {
|
KeyboardInfo {
|
||||||
keymap_string,
|
|
||||||
state: xkb::State::new(keymap),
|
state: xkb::State::new(keymap),
|
||||||
keymap: KeymapFile::new(keymap),
|
keymap: KeymapFile::new(keymap),
|
||||||
mods: ModifiersState::default(),
|
mods: ModifiersState::default(),
|
||||||
keys: FxHashSet::default(),
|
keys: FxHashSet::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn process(&mut self, key: u32, pressed: bool, keyboard: &WlKeyboard) -> Result<usize> {
|
pub fn process(&mut self, key: u32, state: u32, keyboard: &WlKeyboard) -> Result<usize> {
|
||||||
let xkb_key_state = if pressed {
|
let wl_key_state = match state {
|
||||||
xkb::KeyDirection::Down
|
0 => KeyState::Released,
|
||||||
} else {
|
1 => KeyState::Pressed,
|
||||||
xkb::KeyDirection::Up
|
_ => color_eyre::eyre::bail!("Invalid key state!"),
|
||||||
};
|
};
|
||||||
let state_components = self.state.update_key(Keycode::new(key + 8), xkb_key_state);
|
let xkb_key_state = match state {
|
||||||
|
0 => xkb::KeyDirection::Up,
|
||||||
|
1 => xkb::KeyDirection::Down,
|
||||||
|
_ => color_eyre::eyre::bail!("Invalid key state!"),
|
||||||
|
};
|
||||||
|
let state_components = self.state.update_key(key + 8, xkb_key_state);
|
||||||
if state_components != 0 {
|
if state_components != 0 {
|
||||||
self.mods.update_with(&self.state);
|
self.mods.update_with(&self.state);
|
||||||
keyboard.modifiers(
|
keyboard.modifiers(
|
||||||
@@ -86,17 +72,6 @@ impl KeyboardInfo {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// if pressed {
|
|
||||||
// println!("Key {key} is being pressed with {state_components} modifiers");
|
|
||||||
// } else {
|
|
||||||
// println!("Key {key} is being released with {state_components} modifiers");
|
|
||||||
// }
|
|
||||||
|
|
||||||
let wl_key_state = if pressed {
|
|
||||||
KeyState::Pressed
|
|
||||||
} else {
|
|
||||||
KeyState::Released
|
|
||||||
};
|
|
||||||
keyboard.key(SERIAL_COUNTER.inc(), 0, key, wl_key_state);
|
keyboard.key(SERIAL_COUNTER.inc(), 0, key, wl_key_state);
|
||||||
match wl_key_state {
|
match wl_key_state {
|
||||||
KeyState::Pressed => {
|
KeyState::Pressed => {
|
||||||
@@ -127,10 +102,10 @@ pub enum PointerEvent {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum KeyboardEvent {
|
pub enum KeyboardEvent {
|
||||||
Keymap,
|
Keymap,
|
||||||
Key { key: u32, state: bool },
|
Key { key: u32, state: u32 },
|
||||||
}
|
}
|
||||||
|
|
||||||
const POINTER_EVENT_TIMEOUT: Duration = Duration::from_millis(50);
|
const POINTER_EVENT_TIMEOUT: Duration = Duration::from_secs(1);
|
||||||
struct SurfaceInfo {
|
struct SurfaceInfo {
|
||||||
wl_surface: WlWeak<WlSurface>,
|
wl_surface: WlWeak<WlSurface>,
|
||||||
cursor_sender: watch::Sender<Option<CursorInfo>>,
|
cursor_sender: watch::Sender<Option<CursorInfo>>,
|
||||||
@@ -210,12 +185,12 @@ impl SurfaceInfo {
|
|||||||
) => {
|
) => {
|
||||||
if let Some(axis_continuous) = axis_continuous {
|
if let Some(axis_continuous) = axis_continuous {
|
||||||
pointer.axis(0, Axis::HorizontalScroll, axis_continuous.x as f64);
|
pointer.axis(0, Axis::HorizontalScroll, axis_continuous.x as f64);
|
||||||
pointer.axis(0, Axis::VerticalScroll, -axis_continuous.y as f64);
|
pointer.axis(0, Axis::VerticalScroll, axis_continuous.y as f64);
|
||||||
}
|
}
|
||||||
if pointer.version() >= wl_pointer::EVT_AXIS_DISCRETE_SINCE {
|
if pointer.version() >= wl_pointer::EVT_AXIS_DISCRETE_SINCE {
|
||||||
if let Some(axis_discrete) = axis_discrete {
|
if let Some(axis_discrete) = axis_discrete {
|
||||||
pointer.axis_discrete(Axis::HorizontalScroll, axis_discrete.x as i32);
|
pointer.axis_discrete(Axis::HorizontalScroll, axis_discrete.x as i32);
|
||||||
pointer.axis_discrete(Axis::VerticalScroll, -axis_discrete.y as i32);
|
pointer.axis_discrete(Axis::VerticalScroll, axis_discrete.y as i32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pointer.version() >= wl_pointer::EVT_AXIS_STOP_SINCE
|
if pointer.version() >= wl_pointer::EVT_AXIS_STOP_SINCE
|
||||||
@@ -284,7 +259,6 @@ pub struct SeatData {
|
|||||||
pointer: OnceCell<(WlPointer, Mutex<ObjectId>)>,
|
pointer: OnceCell<(WlPointer, Mutex<ObjectId>)>,
|
||||||
keyboard: OnceCell<(WlKeyboard, Mutex<ObjectId>)>,
|
keyboard: OnceCell<(WlKeyboard, Mutex<ObjectId>)>,
|
||||||
touch: OnceCell<WlTouch>,
|
touch: OnceCell<WlTouch>,
|
||||||
touches: Mutex<FxHashMap<ObjectId, u32>>,
|
|
||||||
}
|
}
|
||||||
impl SeatData {
|
impl SeatData {
|
||||||
pub fn new(dh: &DisplayHandle) -> Arc<Self> {
|
pub fn new(dh: &DisplayHandle) -> Arc<Self> {
|
||||||
@@ -295,39 +269,37 @@ impl SeatData {
|
|||||||
pointer: OnceCell::new(),
|
pointer: OnceCell::new(),
|
||||||
keyboard: OnceCell::new(),
|
keyboard: OnceCell::new(),
|
||||||
touch: OnceCell::new(),
|
touch: OnceCell::new(),
|
||||||
touches: Mutex::new(FxHashMap::default()),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let _ = seat_data
|
seat_data
|
||||||
.global_id
|
.global_id
|
||||||
.set(dh.create_global::<WaylandState, _, _>(7, seat_data.clone()));
|
.set(dh.create_global::<WaylandState, _, _>(7, seat_data.clone()))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
seat_data
|
seat_data
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_keymap(&self, keymap_str: String, surfaces: Vec<WlSurface>) -> Result<()> {
|
pub fn set_keymap_str(&self, keymap: &str, surfaces: Vec<WlSurface>) -> Result<()> {
|
||||||
let context = xkb::Context::new(0);
|
let context = xkb::Context::new(0);
|
||||||
let keymap =
|
let keymap =
|
||||||
Keymap::new_from_string(&context, keymap_str.clone(), XKB_KEYMAP_FORMAT_TEXT_V1, 0)
|
Keymap::new_from_string(&context, keymap.to_string(), XKB_KEYMAP_FORMAT_TEXT_V1, 0)
|
||||||
.ok_or_else(|| eyre!("Keymap is not valid"))?;
|
.ok_or_else(|| eyre!("Keymap is not valid"))?;
|
||||||
|
self.set_keymap(&keymap, surfaces);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
pub fn set_keymap(&self, keymap: &Keymap, surfaces: Vec<WlSurface>) {
|
||||||
let mut panels = self.surfaces.lock();
|
let mut panels = self.surfaces.lock();
|
||||||
let Some((_, focus)) = self.keyboard.get() else {bail!("Could not get keyboard")};
|
let Some((_, focus)) = self.keyboard.get() else {return};
|
||||||
for surface in surfaces {
|
for surface in surfaces {
|
||||||
let Some(surface_info) = panels.get_mut(&surface.id()) else {continue};
|
let Some(surface_info) = panels.get_mut(&surface.id()) else {continue};
|
||||||
if let Some(keyboard_info) = &mut surface_info.keyboard_info {
|
|
||||||
if &keyboard_info.keymap_string == &keymap_str {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
surface_info
|
surface_info
|
||||||
.keyboard_info
|
.keyboard_info
|
||||||
.replace(KeyboardInfo::new(keymap_str.clone(), &keymap));
|
.replace(KeyboardInfo::new(keymap));
|
||||||
|
|
||||||
if *focus.lock() == surface.id() {
|
if *focus.lock() == surface.id() {
|
||||||
surface_info.keyboard_queue.push_back(KeyboardEvent::Keymap);
|
surface_info.keyboard_queue.push_back(KeyboardEvent::Keymap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pointer_event(&self, surface: &WlSurface, event: PointerEvent) {
|
pub fn pointer_event(&self, surface: &WlSurface, event: PointerEvent) {
|
||||||
@@ -425,36 +397,14 @@ impl SeatData {
|
|||||||
*keyboard_focus = ObjectId::null();
|
*keyboard_focus = ObjectId::null();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.touches.lock().remove(&surface.id());
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
pub fn touch_down(&self, surface: &WlSurface, id: u32, position: Vector2<f32>) {
|
impl Drop for SeatData {
|
||||||
let Some(touch) = self.touch.get() else {return};
|
fn drop(&mut self) {
|
||||||
touch.down(
|
let id = self.global_id.take().unwrap();
|
||||||
SERIAL_COUNTER.inc(),
|
let _ = task::new(|| "global destroy queue garbage collection", async move {
|
||||||
0,
|
GLOBAL_DESTROY_QUEUE.get().unwrap().send(id).await
|
||||||
surface,
|
});
|
||||||
id as i32,
|
|
||||||
position.x as f64,
|
|
||||||
position.y as f64,
|
|
||||||
);
|
|
||||||
self.touches.lock().insert(surface.id(), id);
|
|
||||||
}
|
|
||||||
pub fn touch_move(&self, id: u32, position: Vector2<f32>) {
|
|
||||||
let Some(touch) = self.touch.get() else {return};
|
|
||||||
touch.motion(0, id as i32, position.x as f64, position.y as f64);
|
|
||||||
}
|
|
||||||
pub fn touch_up(&self, id: u32) {
|
|
||||||
let Some(touch) = self.touch.get() else {return};
|
|
||||||
touch.up(SERIAL_COUNTER.inc(), 0, id as i32);
|
|
||||||
let mut touches = self.touches.lock();
|
|
||||||
touches.retain(|_, tid| *tid != id);
|
|
||||||
}
|
|
||||||
pub fn reset_touches(&self) {
|
|
||||||
let Some(touch) = self.touch.get() else {return};
|
|
||||||
for (_, touch_id) in self.touches.lock().drain() {
|
|
||||||
touch.up(SERIAL_COUNTER.inc(), 0, touch_id as i32);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,12 +414,9 @@ pub struct CursorInfo {
|
|||||||
pub hotspot_y: i32,
|
pub hotspot_y: i32,
|
||||||
}
|
}
|
||||||
impl CursorInfo {
|
impl CursorInfo {
|
||||||
pub fn cursor_data(&self) -> Option<Geometry> {
|
pub fn cursor_data(&self) -> Option<(Vector2<u32>, Vector2<i32>)> {
|
||||||
let cursor_size = CoreSurface::from_wl_surface(&self.surface.upgrade().ok()?)?.size()?;
|
let cursor_size = CoreSurface::from_wl_surface(&self.surface.upgrade().ok()?)?.size()?;
|
||||||
Some(Geometry {
|
Some((cursor_size, [self.hotspot_x, self.hotspot_y].into()))
|
||||||
origin: [self.hotspot_x, self.hotspot_y].into(),
|
|
||||||
size: cursor_size,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,7 +435,7 @@ impl GlobalDispatch<WlSeat, Arc<SeatData>, WaylandState> for WaylandState {
|
|||||||
resource.name(nanoid!());
|
resource.name(nanoid!());
|
||||||
}
|
}
|
||||||
|
|
||||||
resource.capabilities(Capability::Pointer | Capability::Keyboard | Capability::Touch);
|
resource.capabilities(Capability::Pointer | Capability::Keyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn can_view(client: Client, data: &Arc<SeatData>) -> bool {
|
fn can_view(client: Client, data: &Arc<SeatData>) -> bool {
|
||||||
|
|||||||
16
src/wayland/shaders/gamma.frag
Normal file
16
src/wayland/shaders/gamma.frag
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#version 320 es
|
||||||
|
precision mediump float;
|
||||||
|
precision highp int;
|
||||||
|
|
||||||
|
layout(binding = 0) uniform highp sampler2D diffuse;
|
||||||
|
|
||||||
|
layout(location = 0) in highp vec2 fs_uv;
|
||||||
|
layout(location = 0) out highp vec4 _entryPointOutput;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
highp vec4 _101 = texture(diffuse, fs_uv);
|
||||||
|
highp vec3 _104 = pow(_101.xyz, vec3(2.2000000476837158203125));
|
||||||
|
_entryPointOutput = vec4(_104.x, _104.y, _104.z, _101.w);
|
||||||
|
}
|
||||||
|
|
||||||
13
src/wayland/shaders/mod.rs
Normal file
13
src/wayland/shaders/mod.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
// Basic gamma correction shader
|
||||||
|
// pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_gamma.sks");
|
||||||
|
|
||||||
|
// Simula shader with fancy lanzcos sampling
|
||||||
|
pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_simula.sks");
|
||||||
|
|
||||||
|
// Simula text shader (fragment)
|
||||||
|
// pub const SIMULA_FRAG_STR: &str = include_str!("simula.frag");
|
||||||
|
|
||||||
|
// Simula text shader (vertex)
|
||||||
|
// pub const SIMULA_VERT_STR: &str = include_str!("simula.vert");
|
||||||
75
src/wayland/shaders/simula.frag
Normal file
75
src/wayland/shaders/simula.frag
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#version 320 es
|
||||||
|
#extension GL_OES_EGL_image_external : require
|
||||||
|
precision mediump float;
|
||||||
|
precision highp int;
|
||||||
|
|
||||||
|
layout(binding = 0, std140) uniform _Global
|
||||||
|
{
|
||||||
|
highp vec4 diffuse_i;
|
||||||
|
highp vec2 uv_scale;
|
||||||
|
highp vec2 uv_offset;
|
||||||
|
highp float fcFactor;
|
||||||
|
highp float ripple;
|
||||||
|
highp float alpha_min;
|
||||||
|
highp float alpha_max;
|
||||||
|
} uniforms;
|
||||||
|
|
||||||
|
layout(binding = 0) uniform highp samplerExternalOES diffuse;
|
||||||
|
|
||||||
|
layout(location = 0) in highp vec2 fs_uv;
|
||||||
|
layout(location = 0) out highp vec4 fragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
highp vec2 dx_uv = dFdx(fs_uv);
|
||||||
|
highp vec2 dy_uv = dFdy(fs_uv);
|
||||||
|
highp vec2 width = fs_uv * uniforms.diffuse_i.xy;
|
||||||
|
ivec2 _475 = ivec2(width);
|
||||||
|
highp vec2 _477 = clamp(floor(abs(vec2(dx_uv.x, dy_uv.y)) * uniforms.diffuse_i.xy), vec2(1.0), vec2(2.0));
|
||||||
|
ivec2 _480 = ivec2(_477);
|
||||||
|
ivec2 _481 = _475 - _480;
|
||||||
|
ivec2 _485 = _475 + _480;
|
||||||
|
int _487 = _481.y;
|
||||||
|
highp vec4 _671;
|
||||||
|
highp float _672;
|
||||||
|
_672 = 0.0;
|
||||||
|
_671 = vec4(0.0);
|
||||||
|
highp vec4 _679;
|
||||||
|
highp float _681;
|
||||||
|
for (int _670 = _487; _670 <= _485.y; _672 = _681, _671 = _679, _670++)
|
||||||
|
{
|
||||||
|
int _496 = _481.x;
|
||||||
|
_681 = _672;
|
||||||
|
_679 = _671;
|
||||||
|
highp vec4 _553;
|
||||||
|
highp float _556;
|
||||||
|
for (int _673 = _496; _673 <= _485.x; _681 = _556, _679 = _553, _673++)
|
||||||
|
{
|
||||||
|
highp float _509 = float(_673);
|
||||||
|
highp float _514 = (uniforms.fcFactor * (width.x - _509)) / _477.x;
|
||||||
|
highp float _520 = float(_670);
|
||||||
|
highp float _525 = (uniforms.fcFactor * (width.y - _520)) / _477.y;
|
||||||
|
highp float _533 = sqrt((_514 * _514) + (_525 * _525));
|
||||||
|
highp float _675;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (_533 > 1.0)
|
||||||
|
{
|
||||||
|
_675 = 0.0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
highp float _592 = pow(uniforms.ripple * sqrt(1.0 - (_533 * _533)), 2.0);
|
||||||
|
_675 = 1.0 + (_592 * (0.25 + (_592 * (0.015625 + (_592 * (0.00043402801384218037128448486328125 + (_592 * (6.7816799855791032314300537109375e-06 + (_592 * (6.7816799287356843706220388412476e-08 + (_592 * (4.709500012189948847662890329957e-10 + (_592 * (2.4028099388645474121517509047408e-12 + (_592 * (9.3859703944590075486154034933861e-15 + (_592 * (2.8968999943407451927966655969016e-17 + (7.242260299760125752555485045131e-20 * _592)))))))))))))))))));
|
||||||
|
break;
|
||||||
|
} while(false);
|
||||||
|
_553 = _679 + (texture2D(diffuse, (vec2(_509, _520) + vec2(0.5)) / uniforms.diffuse_i.xy) * _675);
|
||||||
|
_556 = _681 + _675;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
highp vec4 _568 = _671 / vec4(_672);
|
||||||
|
highp vec3 _417 = pow(_568.xyz, vec3(2.2000000476837158203125));
|
||||||
|
highp vec4 _669 = vec4(_417.x, _417.y, _417.z, _568.w);
|
||||||
|
_669.w = uniforms.alpha_min + (_568.w * (uniforms.alpha_max - uniforms.alpha_min));
|
||||||
|
fragColor = _669;
|
||||||
|
}
|
||||||
|
|
||||||
61
src/wayland/shaders/simula.vert
Normal file
61
src/wayland/shaders/simula.vert
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#version 320 es
|
||||||
|
// #ifdef GL_AMD_vertex_shader_layer
|
||||||
|
// #extension GL_AMD_vertex_shader_layer : enable
|
||||||
|
// #elif defined(GL_NV_viewport_array2)
|
||||||
|
// #extension GL_NV_viewport_array2 : enable
|
||||||
|
// #else
|
||||||
|
// #define gl_Layer int _dummy_gl_layer_var
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
struct Inst
|
||||||
|
{
|
||||||
|
mat4 world;
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(binding = 1, std140) uniform StereoKitBuffer
|
||||||
|
{
|
||||||
|
layout(row_major) mat4 sk_view[2];
|
||||||
|
layout(row_major) mat4 sk_proj[2];
|
||||||
|
layout(row_major) mat4 sk_proj_inv[2];
|
||||||
|
layout(row_major) mat4 sk_viewproj[2];
|
||||||
|
vec4 sk_lighting_sh[9];
|
||||||
|
vec4 sk_camera_pos[2];
|
||||||
|
vec4 sk_camera_dir[2];
|
||||||
|
vec4 sk_fingertip[2];
|
||||||
|
vec4 sk_cubemap_i;
|
||||||
|
float sk_time;
|
||||||
|
uint sk_view_count;
|
||||||
|
} _38;
|
||||||
|
|
||||||
|
layout(binding = 2, std140) uniform TransformBuffer
|
||||||
|
{
|
||||||
|
layout(row_major) Inst sk_inst[819];
|
||||||
|
} _56;
|
||||||
|
|
||||||
|
layout(binding = 0, std140) uniform _Global
|
||||||
|
{
|
||||||
|
vec4 diffuse_i;
|
||||||
|
vec2 uv_scale;
|
||||||
|
vec2 uv_offset;
|
||||||
|
float fcFactor;
|
||||||
|
float ripple;
|
||||||
|
float alpha_min;
|
||||||
|
float alpha_max;
|
||||||
|
} _91;
|
||||||
|
|
||||||
|
layout(location = 0) in vec4 input_pos;
|
||||||
|
layout(location = 1) in vec3 input_norm;
|
||||||
|
layout(location = 2) in vec2 input_uv;
|
||||||
|
layout(location = 0) out vec2 fs_uv;
|
||||||
|
|
||||||
|
mat4 spvWorkaroundRowMajor(mat4 wrap) { return wrap; }
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
uint _155 = uint(gl_InstanceID) % _38.sk_view_count;
|
||||||
|
gl_Position = spvWorkaroundRowMajor(_38.sk_viewproj[_155]) * vec4((spvWorkaroundRowMajor(_56.sk_inst[uint(gl_InstanceID) / _38.sk_view_count].world) * vec4(input_pos.xyz, 1.0)).xyz, 1.0);
|
||||||
|
fs_uv = (input_uv + _91.uv_offset) * _91.uv_scale;
|
||||||
|
// gl_Layer = int(_155);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
use crate::wayland::seat::SeatData;
|
use crate::wayland::seat::SeatData;
|
||||||
use once_cell::sync::OnceCell;
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{allocator::dmabuf::Dmabuf, egl::EGLDevice, renderer::gles::GlesRenderer},
|
backend::{
|
||||||
|
allocator::dmabuf::Dmabuf,
|
||||||
|
egl::EGLDevice,
|
||||||
|
renderer::{gles::GlesRenderer, ImportDma},
|
||||||
|
},
|
||||||
delegate_dmabuf, delegate_output, delegate_shm,
|
delegate_dmabuf, delegate_output, delegate_shm,
|
||||||
output::{Mode, Output, Scale, Subpixel},
|
output::{Mode, Output, Scale, Subpixel},
|
||||||
reexports::{
|
reexports::{
|
||||||
@@ -14,7 +17,7 @@ use smithay::{
|
|||||||
wayland_server::{
|
wayland_server::{
|
||||||
backend::{ClientData, ClientId, DisconnectReason},
|
backend::{ClientData, ClientId, DisconnectReason},
|
||||||
protocol::{wl_buffer::WlBuffer, wl_data_device_manager::WlDataDeviceManager},
|
protocol::{wl_buffer::WlBuffer, wl_data_device_manager::WlDataDeviceManager},
|
||||||
DisplayHandle,
|
Display, DisplayHandle,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
utils::{Size, Transform},
|
utils::{Size, Transform},
|
||||||
@@ -33,24 +36,20 @@ use std::sync::{Arc, Weak};
|
|||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use super::DisplayWrapper;
|
|
||||||
|
|
||||||
pub struct ClientState {
|
pub struct ClientState {
|
||||||
pub id: OnceCell<ClientId>,
|
|
||||||
pub compositor_state: CompositorClientState,
|
pub compositor_state: CompositorClientState,
|
||||||
pub display: Weak<DisplayWrapper>,
|
pub display: Weak<Mutex<Display<WaylandState>>>,
|
||||||
pub seat: Arc<SeatData>,
|
pub seat: Arc<SeatData>,
|
||||||
}
|
}
|
||||||
impl ClientState {
|
impl ClientState {
|
||||||
pub fn flush(&self) {
|
pub fn flush(&self) {
|
||||||
let Some(display) = self.display.upgrade() else {return};
|
let Some(display) = self.display.upgrade() else {return};
|
||||||
let _ = display.flush_clients(self.id.get().cloned());
|
let _ = display.lock().flush_clients();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl ClientData for ClientState {
|
impl ClientData for ClientState {
|
||||||
fn initialized(&self, client_id: ClientId) {
|
fn initialized(&self, client_id: ClientId) {
|
||||||
info!("Wayland client {:?} connected", client_id);
|
info!("Wayland client {:?} connected", client_id);
|
||||||
let _ = self.id.set(client_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disconnected(&self, client_id: ClientId, reason: DisconnectReason) {
|
fn disconnected(&self, client_id: ClientId, reason: DisconnectReason) {
|
||||||
@@ -63,6 +62,7 @@ impl ClientData for ClientState {
|
|||||||
|
|
||||||
pub struct WaylandState {
|
pub struct WaylandState {
|
||||||
pub weak_ref: Weak<Mutex<WaylandState>>,
|
pub weak_ref: Weak<Mutex<WaylandState>>,
|
||||||
|
pub display: Arc<Mutex<Display<WaylandState>>>,
|
||||||
pub display_handle: DisplayHandle,
|
pub display_handle: DisplayHandle,
|
||||||
|
|
||||||
pub compositor_state: CompositorState,
|
pub compositor_state: CompositorState,
|
||||||
@@ -76,6 +76,7 @@ pub struct WaylandState {
|
|||||||
|
|
||||||
impl WaylandState {
|
impl WaylandState {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
display: Arc<Mutex<Display<WaylandState>>>,
|
||||||
display_handle: DisplayHandle,
|
display_handle: DisplayHandle,
|
||||||
renderer: &GlesRenderer,
|
renderer: &GlesRenderer,
|
||||||
dmabuf_tx: UnboundedSender<Dmabuf>,
|
dmabuf_tx: UnboundedSender<Dmabuf>,
|
||||||
@@ -88,16 +89,15 @@ impl WaylandState {
|
|||||||
let render_node = EGLDevice::device_for_display(renderer.egl_context().display())
|
let render_node = EGLDevice::device_for_display(renderer.egl_context().display())
|
||||||
.and_then(|device| device.try_get_render_node());
|
.and_then(|device| device.try_get_render_node());
|
||||||
|
|
||||||
let dmabuf_formats = renderer
|
|
||||||
.egl_context()
|
|
||||||
.dmabuf_render_formats()
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let dmabuf_default_feedback = match render_node {
|
let dmabuf_default_feedback = match render_node {
|
||||||
Ok(Some(node)) => DmabufFeedbackBuilder::new(node.dev_id(), dmabuf_formats.clone())
|
Ok(Some(node)) => {
|
||||||
.build()
|
let dmabuf_formats = renderer.dmabuf_formats().collect::<Vec<_>>();
|
||||||
.ok(),
|
let dmabuf_default_feedback =
|
||||||
|
DmabufFeedbackBuilder::new(node.dev_id(), dmabuf_formats)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
Some(dmabuf_default_feedback)
|
||||||
|
}
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
warn!("failed to query render node, dmabuf will use v3");
|
warn!("failed to query render node, dmabuf will use v3");
|
||||||
None
|
None
|
||||||
@@ -117,9 +117,10 @@ impl WaylandState {
|
|||||||
);
|
);
|
||||||
(dmabuf_state, dmabuf_global, Some(default_feedback))
|
(dmabuf_state, dmabuf_global, Some(default_feedback))
|
||||||
} else {
|
} else {
|
||||||
|
let dmabuf_formats = renderer.dmabuf_formats().collect::<Vec<_>>();
|
||||||
let mut dmabuf_state = DmabufState::new();
|
let mut dmabuf_state = DmabufState::new();
|
||||||
let dmabuf_global =
|
let dmabuf_global =
|
||||||
dmabuf_state.create_global::<WaylandState>(&display_handle, dmabuf_formats.clone());
|
dmabuf_state.create_global::<WaylandState>(&display_handle, dmabuf_formats);
|
||||||
(dmabuf_state, dmabuf_global, None)
|
(dmabuf_state, dmabuf_global, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -153,6 +154,7 @@ impl WaylandState {
|
|||||||
Arc::new_cyclic(|weak| {
|
Arc::new_cyclic(|weak| {
|
||||||
Mutex::new(WaylandState {
|
Mutex::new(WaylandState {
|
||||||
weak_ref: weak.clone(),
|
weak_ref: weak.clone(),
|
||||||
|
display,
|
||||||
display_handle,
|
display_handle,
|
||||||
|
|
||||||
compositor_state,
|
compositor_state,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use super::state::WaylandState;
|
use super::{shaders::PANEL_SHADER_BYTES, state::WaylandState};
|
||||||
use crate::{
|
use crate::{
|
||||||
core::{delta::Delta, destroy_queue, registry::Registry},
|
core::{delta::Delta, destroy_queue, registry::Registry},
|
||||||
nodes::drawable::{model::ModelPart, shaders::PANEL_SHADER_BYTES},
|
nodes::drawable::model::ModelPart,
|
||||||
};
|
};
|
||||||
use mint::Vector2;
|
use mint::Vector2;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
@@ -18,10 +18,10 @@ use smithay::{
|
|||||||
reexports::wayland_server::{self, protocol::wl_surface::WlSurface, DisplayHandle, Resource},
|
reexports::wayland_server::{self, protocol::wl_surface::WlSurface, DisplayHandle, Resource},
|
||||||
wayland::compositor::{self, SurfaceData},
|
wayland::compositor::{self, SurfaceData},
|
||||||
};
|
};
|
||||||
use std::{cell::RefCell, ffi::c_void, sync::Arc, time::Duration};
|
use std::{ffi::c_void, sync::Arc, time::Duration};
|
||||||
use stereokit::{
|
use stereokit::{
|
||||||
Material, Shader, StereoKitDraw, Tex, TextureAddress, TextureFormat, TextureSample,
|
Material, StereoKitDraw, Tex, TextureAddress, TextureFormat, TextureSample, TextureType,
|
||||||
TextureType, Transparency,
|
Transparency,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub static CORE_SURFACES: Registry<CoreSurface> = Registry::new();
|
pub static CORE_SURFACES: Registry<CoreSurface> = Registry::new();
|
||||||
@@ -40,8 +40,8 @@ pub struct CoreSurface {
|
|||||||
pub dh: DisplayHandle,
|
pub dh: DisplayHandle,
|
||||||
pub weak_surface: wayland_server::Weak<WlSurface>,
|
pub weak_surface: wayland_server::Weak<WlSurface>,
|
||||||
mapped_data: Mutex<Option<CoreSurfaceData>>,
|
mapped_data: Mutex<Option<CoreSurfaceData>>,
|
||||||
sk_tex: OnceCell<Tex>,
|
sk_tex: OnceCell<SendWrapper<Tex>>,
|
||||||
sk_mat: OnceCell<Arc<Material>>,
|
sk_mat: OnceCell<Arc<SendWrapper<Material>>>,
|
||||||
material_offset: Mutex<Delta<u32>>,
|
material_offset: Mutex<Delta<u32>>,
|
||||||
on_mapped: Box<dyn Fn() + Send + Sync>,
|
on_mapped: Box<dyn Fn() + Send + Sync>,
|
||||||
on_commit: Box<dyn Fn(u32) + Send + Sync>,
|
on_commit: Box<dyn Fn(u32) + Send + Sync>,
|
||||||
@@ -85,19 +85,19 @@ impl CoreSurface {
|
|||||||
pub fn process(&self, sk: &impl StereoKitDraw, renderer: &mut GlesRenderer) {
|
pub fn process(&self, sk: &impl StereoKitDraw, renderer: &mut GlesRenderer) {
|
||||||
let Some(wl_surface) = self.wl_surface() else {return};
|
let Some(wl_surface) = self.wl_surface() else {return};
|
||||||
|
|
||||||
let sk_tex = self
|
let sk_tex = self.sk_tex.get_or_init(|| {
|
||||||
.sk_tex
|
SendWrapper::new(sk.tex_create(TextureType::IMAGE_NO_MIPS, TextureFormat::RGBA32))
|
||||||
.get_or_init(|| sk.tex_create(TextureType::IMAGE_NO_MIPS, TextureFormat::RGBA32));
|
});
|
||||||
self.sk_mat.get_or_init(|| {
|
self.sk_mat.get_or_init(|| {
|
||||||
let shader = sk.shader_create_mem(&PANEL_SHADER_BYTES);
|
let shader = sk.shader_create_mem(&PANEL_SHADER_BYTES).unwrap();
|
||||||
// let _ = renderer.with_context(|c| unsafe {
|
// let _ = renderer.with_context(|c| unsafe {
|
||||||
// shader_inject(c, &mut shader, SIMULA_VERT_STR, SIMULA_FRAG_STR)
|
// shader_inject(c, &mut shader, SIMULA_VERT_STR, SIMULA_FRAG_STR)
|
||||||
// });
|
// });
|
||||||
|
|
||||||
let mat = sk.material_create(shader.as_ref().unwrap_or(Shader::UI.as_ref()));
|
let mat = sk.material_create(&shader);
|
||||||
sk.material_set_texture(&mat, "diffuse", sk_tex.as_ref());
|
sk.material_set_texture(&mat, "diffuse", sk_tex.as_ref());
|
||||||
sk.material_set_transparency(&mat, Transparency::Blend);
|
sk.material_set_transparency(&mat, Transparency::Blend);
|
||||||
Arc::new(mat)
|
Arc::new(SendWrapper::new(mat))
|
||||||
});
|
});
|
||||||
|
|
||||||
// Let smithay handle buffer management (has to be done here as RendererSurfaceStates is not thread safe)
|
// Let smithay handle buffer management (has to be done here as RendererSurfaceStates is not thread safe)
|
||||||
@@ -121,16 +121,18 @@ impl CoreSurface {
|
|||||||
let mut mapped_data = self.mapped_data.lock();
|
let mut mapped_data = self.mapped_data.lock();
|
||||||
let just_mapped = mapped_data.is_none();
|
let just_mapped = mapped_data.is_none();
|
||||||
self.with_states(|data| {
|
self.with_states(|data| {
|
||||||
let Some(renderer_surface_state) = data
|
let renderer_surface_state = data
|
||||||
.data_map
|
.data_map
|
||||||
.get::<RendererSurfaceStateUserData>()
|
.get::<RendererSurfaceStateUserData>()
|
||||||
.map(RefCell::borrow) else {return};
|
.unwrap()
|
||||||
let Some(smithay_tex) = renderer_surface_state
|
.borrow();
|
||||||
|
let smithay_tex = renderer_surface_state
|
||||||
.texture::<GlesRenderer>(renderer.id())
|
.texture::<GlesRenderer>(renderer.id())
|
||||||
.cloned() else {return};
|
.unwrap()
|
||||||
|
.clone();
|
||||||
|
|
||||||
let Some(sk_tex) = self.sk_tex.get() else {return};
|
let sk_tex = self.sk_tex.get().unwrap();
|
||||||
let Some(sk_mat) = self.sk_mat.get() else {return};
|
let sk_mat = self.sk_mat.get().unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
sk.tex_set_surface(
|
sk.tex_set_surface(
|
||||||
sk_tex.as_ref(),
|
sk_tex.as_ref(),
|
||||||
@@ -149,7 +151,7 @@ impl CoreSurface {
|
|||||||
sk.material_set_queue_offset(sk_mat.as_ref().as_ref(), *material_offset as i32);
|
sk.material_set_queue_offset(sk_mat.as_ref().as_ref(), *material_offset as i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(surface_size) = renderer_surface_state.surface_size() else {return};
|
let surface_size = renderer_surface_state.surface_size().unwrap();
|
||||||
let new_mapped_data = CoreSurfaceData {
|
let new_mapped_data = CoreSurfaceData {
|
||||||
size: Vector2::from([surface_size.w as u32, surface_size.h as u32]),
|
size: Vector2::from([surface_size.w as u32, surface_size.h as u32]),
|
||||||
wl_tex: Some(SendWrapper::new(smithay_tex)),
|
wl_tex: Some(SendWrapper::new(smithay_tex)),
|
||||||
@@ -184,12 +186,10 @@ impl CoreSurface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn apply_surface_materials(&self) {
|
fn apply_surface_materials(&self) {
|
||||||
if let Some(sk_mat) = self.sk_mat.get() {
|
for model_node in self.pending_material_applications.get_valid_contents() {
|
||||||
for model_node in self.pending_material_applications.get_valid_contents() {
|
model_node.replace_material(self.sk_mat.clone().get().unwrap().clone());
|
||||||
model_node.replace_material(sk_mat.clone());
|
|
||||||
}
|
|
||||||
self.pending_material_applications.clear();
|
|
||||||
}
|
}
|
||||||
|
self.pending_material_applications.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wl_surface(&self) -> Option<WlSurface> {
|
pub fn wl_surface(&self) -> Option<WlSurface> {
|
||||||
|
|||||||
@@ -4,41 +4,40 @@ use super::{
|
|||||||
surface::CoreSurface,
|
surface::CoreSurface,
|
||||||
SERIAL_COUNTER,
|
SERIAL_COUNTER,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::nodes::{
|
||||||
nodes::{
|
drawable::model::ModelPart,
|
||||||
data::KEYMAPS,
|
items::panel::{Backend, PanelItem, RecommendedState, SurfaceID},
|
||||||
drawable::model::ModelPart,
|
Message, Node,
|
||||||
items::panel::{
|
|
||||||
Backend, ChildInfo, Geometry, PanelItem, PanelItemInitData, SurfaceID, ToplevelInfo,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
wayland::seat::handle_cursor,
|
|
||||||
};
|
};
|
||||||
use color_eyre::eyre::{bail, eyre, Result};
|
use color_eyre::eyre::{eyre, Result};
|
||||||
use mint::Vector2;
|
use mint::Vector2;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use once_cell::sync::OnceCell;
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
use serde::{ser::SerializeSeq, Serialize, Serializer};
|
||||||
use smithay::reexports::{
|
use smithay::reexports::{
|
||||||
wayland_protocols::xdg::shell::server::{
|
wayland_protocols::xdg::shell::server::{
|
||||||
xdg_popup::{self, XdgPopup},
|
xdg_popup::{self, XdgPopup},
|
||||||
xdg_positioner::{self, Anchor, ConstraintAdjustment, Gravity, XdgPositioner},
|
xdg_positioner::{self, Anchor, ConstraintAdjustment, Gravity, XdgPositioner},
|
||||||
xdg_surface::{self, XdgSurface},
|
xdg_surface::{self, XdgSurface},
|
||||||
xdg_toplevel::{self, ResizeEdge, XdgToplevel, EVT_WM_CAPABILITIES_SINCE},
|
xdg_toplevel::{self, XdgToplevel, EVT_CONFIGURE_BOUNDS_SINCE, EVT_WM_CAPABILITIES_SINCE},
|
||||||
xdg_wm_base::{self, XdgWmBase},
|
xdg_wm_base::{self, XdgWmBase},
|
||||||
},
|
},
|
||||||
wayland_server::{
|
wayland_server::{
|
||||||
backend::ClientId, protocol::wl_surface::WlSurface, Client, DataInit, Dispatch,
|
backend::{ClientId, ObjectId},
|
||||||
DisplayHandle, GlobalDispatch, New, Resource, WEnum, Weak as WlWeak,
|
protocol::wl_surface::WlSurface,
|
||||||
|
Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, WEnum,
|
||||||
|
Weak as WlWeak,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use stardust_xr::schemas::flex::serialize;
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
sync::{Arc, Weak},
|
sync::{Arc, Weak},
|
||||||
};
|
};
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
|
use xkbcommon::xkb::{self, ffi::XKB_KEYMAP_FORMAT_TEXT_V1, Keymap};
|
||||||
|
|
||||||
impl GlobalDispatch<XdgWmBase, (), WaylandState> for WaylandState {
|
impl GlobalDispatch<XdgWmBase, (), WaylandState> for WaylandState {
|
||||||
fn bind(
|
fn bind(
|
||||||
@@ -83,14 +82,14 @@ impl Dispatch<XdgWmBase, (), WaylandState> for WaylandState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Serialize, Clone, Copy)]
|
||||||
pub struct PositionerData {
|
pub struct PositionerData {
|
||||||
size: Vector2<u32>,
|
size: Vector2<u32>,
|
||||||
anchor_rect_pos: Vector2<i32>,
|
anchor_rect_pos: Vector2<i32>,
|
||||||
anchor_rect_size: Vector2<u32>,
|
anchor_rect_size: Vector2<u32>,
|
||||||
anchor: Anchor,
|
anchor: u32,
|
||||||
gravity: Gravity,
|
gravity: u32,
|
||||||
constraint_adjustment: ConstraintAdjustment,
|
constraint_adjustment: u32,
|
||||||
offset: Vector2<i32>,
|
offset: Vector2<i32>,
|
||||||
reactive: bool,
|
reactive: bool,
|
||||||
}
|
}
|
||||||
@@ -100,111 +99,15 @@ impl Default for PositionerData {
|
|||||||
size: Vector2::from([0; 2]),
|
size: Vector2::from([0; 2]),
|
||||||
anchor_rect_pos: Vector2::from([0; 2]),
|
anchor_rect_pos: Vector2::from([0; 2]),
|
||||||
anchor_rect_size: Vector2::from([0; 2]),
|
anchor_rect_size: Vector2::from([0; 2]),
|
||||||
anchor: Anchor::None,
|
anchor: Anchor::None as u32,
|
||||||
gravity: Gravity::None,
|
gravity: Gravity::None as u32,
|
||||||
constraint_adjustment: ConstraintAdjustment::None,
|
constraint_adjustment: ConstraintAdjustment::None.bits(),
|
||||||
offset: Vector2::from([0; 2]),
|
offset: Vector2::from([0; 2]),
|
||||||
reactive: false,
|
reactive: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PositionerData {
|
|
||||||
fn anchor_has_edge(&self, edge: Anchor) -> bool {
|
|
||||||
match edge {
|
|
||||||
Anchor::Top => {
|
|
||||||
self.anchor == Anchor::Top
|
|
||||||
|| self.anchor == Anchor::TopLeft
|
|
||||||
|| self.anchor == Anchor::TopRight
|
|
||||||
}
|
|
||||||
Anchor::Bottom => {
|
|
||||||
self.anchor == Anchor::Bottom
|
|
||||||
|| self.anchor == Anchor::BottomLeft
|
|
||||||
|| self.anchor == Anchor::BottomRight
|
|
||||||
}
|
|
||||||
Anchor::Left => {
|
|
||||||
self.anchor == Anchor::Left
|
|
||||||
|| self.anchor == Anchor::TopLeft
|
|
||||||
|| self.anchor == Anchor::BottomLeft
|
|
||||||
}
|
|
||||||
Anchor::Right => {
|
|
||||||
self.anchor == Anchor::Right
|
|
||||||
|| self.anchor == Anchor::TopRight
|
|
||||||
|| self.anchor == Anchor::BottomRight
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gravity_has_edge(&self, edge: Gravity) -> bool {
|
|
||||||
match edge {
|
|
||||||
Gravity::Top => {
|
|
||||||
self.gravity == Gravity::Top
|
|
||||||
|| self.gravity == Gravity::TopLeft
|
|
||||||
|| self.gravity == Gravity::TopRight
|
|
||||||
}
|
|
||||||
Gravity::Bottom => {
|
|
||||||
self.gravity == Gravity::Bottom
|
|
||||||
|| self.gravity == Gravity::BottomLeft
|
|
||||||
|| self.gravity == Gravity::BottomRight
|
|
||||||
}
|
|
||||||
Gravity::Left => {
|
|
||||||
self.gravity == Gravity::Left
|
|
||||||
|| self.gravity == Gravity::TopLeft
|
|
||||||
|| self.gravity == Gravity::BottomLeft
|
|
||||||
}
|
|
||||||
Gravity::Right => {
|
|
||||||
self.gravity == Gravity::Right
|
|
||||||
|| self.gravity == Gravity::TopRight
|
|
||||||
|| self.gravity == Gravity::BottomRight
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_pos(&self) -> Vector2<i32> {
|
|
||||||
let mut pos = self.offset;
|
|
||||||
|
|
||||||
if self.anchor_has_edge(Anchor::Top) {
|
|
||||||
pos.y += self.anchor_rect_pos.y;
|
|
||||||
} else if self.anchor_has_edge(Anchor::Bottom) {
|
|
||||||
pos.y += self.anchor_rect_pos.y + self.anchor_rect_size.y as i32;
|
|
||||||
} else {
|
|
||||||
pos.y += self.anchor_rect_pos.y + self.anchor_rect_size.y as i32 / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.anchor_has_edge(Anchor::Left) {
|
|
||||||
pos.x += self.anchor_rect_pos.x;
|
|
||||||
} else if self.anchor_has_edge(Anchor::Right) {
|
|
||||||
pos.x += self.anchor_rect_pos.x + self.anchor_rect_size.x as i32;
|
|
||||||
} else {
|
|
||||||
pos.x += self.anchor_rect_pos.x + self.anchor_rect_size.x as i32 / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.gravity_has_edge(Gravity::Top) {
|
|
||||||
pos.y -= self.size.y as i32;
|
|
||||||
} else if !self.gravity_has_edge(Gravity::Bottom) {
|
|
||||||
pos.y -= self.size.y as i32 / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.gravity_has_edge(Gravity::Left) {
|
|
||||||
pos.x -= self.size.x as i32;
|
|
||||||
} else if !self.gravity_has_edge(Gravity::Right) {
|
|
||||||
pos.x -= self.size.x as i32 / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl From<PositionerData> for Geometry {
|
|
||||||
fn from(value: PositionerData) -> Self {
|
|
||||||
Geometry {
|
|
||||||
origin: value.get_pos(),
|
|
||||||
size: value.size,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dispatch<XdgPositioner, Mutex<PositionerData>, WaylandState> for WaylandState {
|
impl Dispatch<XdgPositioner, Mutex<PositionerData>, WaylandState> for WaylandState {
|
||||||
fn request(
|
fn request(
|
||||||
_state: &mut WaylandState,
|
_state: &mut WaylandState,
|
||||||
@@ -249,13 +152,13 @@ impl Dispatch<XdgPositioner, Mutex<PositionerData>, WaylandState> for WaylandSta
|
|||||||
xdg_positioner::Request::SetAnchor { anchor } => {
|
xdg_positioner::Request::SetAnchor { anchor } => {
|
||||||
if let WEnum::Value(anchor) = anchor {
|
if let WEnum::Value(anchor) = anchor {
|
||||||
debug!(?positioner, ?anchor, "Set positioner anchor");
|
debug!(?positioner, ?anchor, "Set positioner anchor");
|
||||||
data.lock().anchor = anchor;
|
data.lock().anchor = anchor as u32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xdg_positioner::Request::SetGravity { gravity } => {
|
xdg_positioner::Request::SetGravity { gravity } => {
|
||||||
if let WEnum::Value(gravity) = gravity {
|
if let WEnum::Value(gravity) = gravity {
|
||||||
debug!(?positioner, ?gravity, "Set positioner gravity");
|
debug!(?positioner, ?gravity, "Set positioner gravity");
|
||||||
data.lock().gravity = gravity;
|
data.lock().gravity = gravity as u32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xdg_positioner::Request::SetConstraintAdjustment {
|
xdg_positioner::Request::SetConstraintAdjustment {
|
||||||
@@ -265,7 +168,6 @@ impl Dispatch<XdgPositioner, Mutex<PositionerData>, WaylandState> for WaylandSta
|
|||||||
?positioner,
|
?positioner,
|
||||||
constraint_adjustment, "Set positioner constraint adjustment"
|
constraint_adjustment, "Set positioner constraint adjustment"
|
||||||
);
|
);
|
||||||
let Some(constraint_adjustment) = ConstraintAdjustment::from_bits(constraint_adjustment) else {return};
|
|
||||||
data.lock().constraint_adjustment = constraint_adjustment;
|
data.lock().constraint_adjustment = constraint_adjustment;
|
||||||
}
|
}
|
||||||
xdg_positioner::Request::SetOffset { x, y } => {
|
xdg_positioner::Request::SetOffset { x, y } => {
|
||||||
@@ -294,6 +196,20 @@ impl Dispatch<XdgPositioner, Mutex<PositionerData>, WaylandState> for WaylandSta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Clone, Copy)]
|
||||||
|
pub struct Geometry {
|
||||||
|
pub origin: Vector2<i32>,
|
||||||
|
pub size: Vector2<u32>,
|
||||||
|
}
|
||||||
|
impl Default for Geometry {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
origin: Vector2::from([0; 2]),
|
||||||
|
size: Vector2::from([0; 2]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct XdgSurfaceData {
|
pub struct XdgSurfaceData {
|
||||||
wl_surface: WlWeak<WlSurface>,
|
wl_surface: WlWeak<WlSurface>,
|
||||||
surface_id: SurfaceID,
|
surface_id: SurfaceID,
|
||||||
@@ -345,13 +261,13 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
|||||||
debug!(?toplevel, ?xdg_surface, "Create XDG toplevel");
|
debug!(?toplevel, ?xdg_surface, "Create XDG toplevel");
|
||||||
|
|
||||||
if toplevel.version() >= EVT_WM_CAPABILITIES_SINCE {
|
if toplevel.version() >= EVT_WM_CAPABILITIES_SINCE {
|
||||||
toplevel.wm_capabilities(vec![3]);
|
toplevel.wm_capabilities(vec![2, 3, 4]);
|
||||||
}
|
}
|
||||||
toplevel.configure(
|
toplevel.configure(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
if toplevel.version() >= 2 {
|
if toplevel.version() >= 2 {
|
||||||
vec![1, 5, 6, 7, 8]
|
vec![5, 6, 7, 8]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(u32::to_ne_bytes)
|
.flat_map(u32::to_ne_bytes)
|
||||||
.collect()
|
.collect()
|
||||||
@@ -370,29 +286,25 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
|||||||
{
|
{
|
||||||
let toplevel = toplevel.downgrade();
|
let toplevel = toplevel.downgrade();
|
||||||
move || {
|
move || {
|
||||||
let Ok(toplevel) = toplevel.upgrade() else {return};
|
let toplevel = toplevel.upgrade().unwrap();
|
||||||
let toplevel_data = ToplevelData::get(&toplevel);
|
let toplevel_data = ToplevelData::get(&toplevel);
|
||||||
let Some(xdg_surface) = toplevel_data.lock().xdg_surface() else {return};
|
let Some(xdg_surface) = toplevel_data.lock().xdg_surface() else {return};
|
||||||
let Some(xdg_surface_data) = XdgSurfaceData::get(&xdg_surface) else {return};
|
let Some(xdg_surface_data) = XdgSurfaceData::get(&xdg_surface) else {return};
|
||||||
|
|
||||||
xdg_surface_data.lock().surface_id = SurfaceID::Toplevel;
|
xdg_surface_data.lock().surface_id = SurfaceID::Toplevel;
|
||||||
let Some(backend) = XDGBackend::create(toplevel.clone(), seat_data.clone()) else {return};
|
let Some(backend) = XDGBackend::create(toplevel.clone(), seat_data.clone()) else {return};
|
||||||
let panel_item = PanelItem::create(
|
let (node, panel_item) = PanelItem::create(
|
||||||
Box::new(backend),
|
Box::new(backend),
|
||||||
client_credentials.map(|c| c.pid),
|
client_credentials.map(|c| c.pid),
|
||||||
);
|
);
|
||||||
|
toplevel_data.lock().panel_item_node.replace(node);
|
||||||
xdg_surface_data.lock().panel_item = Arc::downgrade(&panel_item);
|
xdg_surface_data.lock().panel_item = Arc::downgrade(&panel_item);
|
||||||
let _ = toplevel_data
|
|
||||||
.lock()
|
|
||||||
.panel_item
|
|
||||||
.set(Arc::downgrade(&panel_item));
|
|
||||||
handle_cursor(&panel_item, panel_item.backend.cursor.clone());
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
let toplevel = toplevel.downgrade();
|
let toplevel = toplevel.downgrade();
|
||||||
move |_| {
|
move |_| {
|
||||||
let Ok(toplevel) = toplevel.upgrade() else {return};
|
let toplevel = toplevel.upgrade().unwrap();
|
||||||
let toplevel_data = ToplevelData::get(&toplevel);
|
let toplevel_data = ToplevelData::get(&toplevel);
|
||||||
let Some(panel_item) = toplevel_data.lock().panel_item() else {
|
let Some(panel_item) = toplevel_data.lock().panel_item() else {
|
||||||
let Some(xdg_surface) = toplevel_data.lock().xdg_surface() else {return};
|
let Some(xdg_surface) = toplevel_data.lock().xdg_surface() else {return};
|
||||||
@@ -409,12 +321,7 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
|||||||
xdg_surface.configure(SERIAL_COUNTER.inc());
|
xdg_surface.configure(SERIAL_COUNTER.inc());
|
||||||
return
|
return
|
||||||
};
|
};
|
||||||
let Some(xdg_surface) = toplevel_data.lock().xdg_surface() else {return};
|
panel_item.commit_toplevel();
|
||||||
let Some(xdg_surface_data) = XdgSurfaceData::get(&xdg_surface) else {return};
|
|
||||||
let Some(wl_surface) = xdg_surface_data.lock().wl_surface() else {return};
|
|
||||||
let Some(core_surface) = CoreSurface::from_wl_surface(&wl_surface) else {return};
|
|
||||||
let Some(size) = core_surface.size() else {return};
|
|
||||||
panel_item.toplevel_size_changed(size);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -424,10 +331,20 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
|||||||
parent,
|
parent,
|
||||||
positioner,
|
positioner,
|
||||||
} => {
|
} => {
|
||||||
let Some(parent) = parent else {return};
|
let parent_clone = parent.clone().unwrap();
|
||||||
let Some(parent_data) = parent.data::<Mutex<XdgSurfaceData>>() else {return};
|
let parent_data = parent_clone.data::<Mutex<XdgSurfaceData>>().unwrap().lock();
|
||||||
let parent_data = parent_data.lock();
|
// let positioner_data = positioner
|
||||||
|
// .data::<Mutex<PositionerData>>()
|
||||||
|
// .unwrap()
|
||||||
|
// .lock()
|
||||||
|
// .clone();
|
||||||
|
// let parent = match &*parent_data {
|
||||||
|
// XdgSurfaceType::Toplevel(_) => SurfaceID::Toplevel,
|
||||||
|
// XdgSurfaceType::Popup(p) => {
|
||||||
|
// SurfaceID::Popup(p.upgrade().unwrap().uid.clone())
|
||||||
|
// }
|
||||||
|
// XdgSurfaceType::Unknown => return,
|
||||||
|
// };
|
||||||
let uid = nanoid!();
|
let uid = nanoid!();
|
||||||
let popup_data = Mutex::new(PopupData::new(
|
let popup_data = Mutex::new(PopupData::new(
|
||||||
uid.clone(),
|
uid.clone(),
|
||||||
@@ -435,37 +352,32 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
|||||||
parent_data.surface_id.clone(),
|
parent_data.surface_id.clone(),
|
||||||
positioner,
|
positioner,
|
||||||
));
|
));
|
||||||
let Some(panel_item) = parent_data.panel_item() else {return};
|
|
||||||
let Some(popup_wl_surface) = popup_data.lock().wl_surface() else {return};
|
|
||||||
handle_cursor(
|
|
||||||
&panel_item,
|
|
||||||
panel_item.backend.seat.new_surface(&popup_wl_surface),
|
|
||||||
);
|
|
||||||
let xdg_popup = data_init.init(id, popup_data);
|
let xdg_popup = data_init.init(id, popup_data);
|
||||||
xdg_surface_data.lock().surface_id = SurfaceID::Child(uid);
|
xdg_surface_data.lock().surface_id = SurfaceID::Popup(uid);
|
||||||
|
let panel_item = parent_data.panel_item().unwrap();
|
||||||
xdg_surface_data.lock().panel_item = Arc::downgrade(&panel_item);
|
xdg_surface_data.lock().panel_item = Arc::downgrade(&panel_item);
|
||||||
debug!(?xdg_popup, ?xdg_surface, "Create XDG popup");
|
debug!(?xdg_popup, ?xdg_surface, "Create XDG popup");
|
||||||
|
|
||||||
let xdg_surface = xdg_surface.downgrade();
|
let xdg_surface = xdg_surface.downgrade();
|
||||||
let xdg_popup: WlWeak<XdgPopup> = xdg_popup.downgrade();
|
let xdg_popup = xdg_popup.downgrade();
|
||||||
let Ok(wl_surface) = xdg_surface_data.lock().wl_surface.upgrade() else {return};
|
|
||||||
CoreSurface::add_to(
|
CoreSurface::add_to(
|
||||||
state.display_handle.clone(),
|
state.display_handle.clone(),
|
||||||
&wl_surface,
|
&xdg_surface_data.lock().wl_surface.upgrade().unwrap(),
|
||||||
move || {
|
move || {
|
||||||
let Ok(xdg_popup) = xdg_popup.upgrade() else {return};
|
let xdg_popup = xdg_popup.upgrade().unwrap();
|
||||||
let Some(popup_data) = PopupData::get(&xdg_popup) else {return};
|
let Some(popup_data) = PopupData::get(&xdg_popup) else {return};
|
||||||
let popup_data = popup_data.lock();
|
let popup_data = popup_data.lock();
|
||||||
|
// panel_item.commit_popup(popup_data);
|
||||||
panel_item
|
panel_item
|
||||||
.backend
|
.backend
|
||||||
.new_popup(&panel_item, &xdg_popup, &*popup_data);
|
.new_popup(&panel_item, &xdg_popup, &*popup_data);
|
||||||
},
|
},
|
||||||
move |commit_count| {
|
move |commit_count| {
|
||||||
if commit_count == 0 {
|
if commit_count == 0 {
|
||||||
if let Ok(xdg_surface) = xdg_surface.upgrade() {
|
xdg_surface
|
||||||
xdg_surface.configure(SERIAL_COUNTER.inc())
|
.upgrade()
|
||||||
}
|
.unwrap()
|
||||||
|
.configure(SERIAL_COUNTER.inc())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -497,26 +409,32 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
fn serde_error<S: Serializer>(msg: &str) -> Result<S::Ok, S::Error> {
|
||||||
|
Err(serde::ser::Error::custom(msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct ToplevelData {
|
pub struct ToplevelData {
|
||||||
panel_item: OnceCell<Weak<PanelItem<XDGBackend>>>,
|
panel_item_node: Option<Arc<Node>>,
|
||||||
xdg_surface: WlWeak<XdgSurface>,
|
xdg_surface: WlWeak<XdgSurface>,
|
||||||
parent: Option<WlWeak<XdgToplevel>>,
|
parent: Option<WlWeak<XdgToplevel>>,
|
||||||
title: Option<String>,
|
title: Option<String>,
|
||||||
app_id: Option<String>,
|
app_id: Option<String>,
|
||||||
max_size: Option<Vector2<u32>>,
|
max_size: Option<Vector2<u32>>,
|
||||||
min_size: Option<Vector2<u32>>,
|
min_size: Option<Vector2<u32>>,
|
||||||
|
states: Vec<u32>,
|
||||||
}
|
}
|
||||||
impl ToplevelData {
|
impl ToplevelData {
|
||||||
fn new(xdg_surface: &XdgSurface) -> Self {
|
fn new(xdg_surface: &XdgSurface) -> Self {
|
||||||
ToplevelData {
|
ToplevelData {
|
||||||
panel_item: OnceCell::new(),
|
panel_item_node: None,
|
||||||
xdg_surface: xdg_surface.downgrade(),
|
xdg_surface: xdg_surface.downgrade(),
|
||||||
parent: None,
|
parent: None,
|
||||||
title: None,
|
title: None,
|
||||||
app_id: None,
|
app_id: None,
|
||||||
max_size: None,
|
max_size: None,
|
||||||
min_size: None,
|
min_size: None,
|
||||||
|
states: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,13 +446,44 @@ impl ToplevelData {
|
|||||||
self.xdg_surface.upgrade().ok()
|
self.xdg_surface.upgrade().ok()
|
||||||
}
|
}
|
||||||
fn panel_item(&self) -> Option<Arc<PanelItem<XDGBackend>>> {
|
fn panel_item(&self) -> Option<Arc<PanelItem<XDGBackend>>> {
|
||||||
self.panel_item.get()?.upgrade()
|
let xdg_surface = self.xdg_surface()?;
|
||||||
|
let xdg_surface_data = XdgSurfaceData::get(&xdg_surface)?.lock();
|
||||||
|
xdg_surface_data.panel_item()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Drop for ToplevelData {
|
impl Serialize for ToplevelData {
|
||||||
fn drop(&mut self) {
|
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
let Some(panel_item) = self.panel_item() else {return};
|
let Some(xdg_surface) = self.xdg_surface() else {return serializer.serialize_none()};
|
||||||
panel_item.drop_toplevel();
|
let Some(xdg_surface_data) = XdgSurfaceData::get(&xdg_surface) else {return serializer.serialize_none()};
|
||||||
|
let xdg_surface_data = xdg_surface_data.lock();
|
||||||
|
let geometry = xdg_surface_data.geometry.clone();
|
||||||
|
let Some(wl_surface) = xdg_surface_data.wl_surface() else {return serde_error::<S>("Wayland surface not found")};
|
||||||
|
let Some(core_surface) = CoreSurface::from_wl_surface(&wl_surface) else {return serde_error::<S>("Core surface not found")};
|
||||||
|
let Some(size) = core_surface.size() else {return serializer.serialize_none()};
|
||||||
|
let geometry = geometry.unwrap_or_else(|| Geometry {
|
||||||
|
origin: [0; 2].into(),
|
||||||
|
size,
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut seq = serializer.serialize_seq(None)?;
|
||||||
|
// Parent UID
|
||||||
|
seq.serialize_element(&self.parent.as_ref().and_then(|p| {
|
||||||
|
Some(
|
||||||
|
ToplevelData::get(&p.upgrade().ok()?)
|
||||||
|
.lock()
|
||||||
|
.panel_item()?
|
||||||
|
.uid
|
||||||
|
.clone(),
|
||||||
|
)
|
||||||
|
}))?;
|
||||||
|
seq.serialize_element(&self.title)?;
|
||||||
|
seq.serialize_element(&self.app_id)?;
|
||||||
|
seq.serialize_element(&size)?;
|
||||||
|
seq.serialize_element(&self.min_size)?;
|
||||||
|
seq.serialize_element(&self.max_size)?;
|
||||||
|
seq.serialize_element(&geometry)?;
|
||||||
|
seq.serialize_element(&self.states)?;
|
||||||
|
seq.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Dispatch<XdgToplevel, Mutex<ToplevelData>, WaylandState> for WaylandState {
|
impl Dispatch<XdgToplevel, Mutex<ToplevelData>, WaylandState> for WaylandState {
|
||||||
@@ -550,30 +499,30 @@ impl Dispatch<XdgToplevel, Mutex<ToplevelData>, WaylandState> for WaylandState {
|
|||||||
match request {
|
match request {
|
||||||
xdg_toplevel::Request::SetParent { parent } => {
|
xdg_toplevel::Request::SetParent { parent } => {
|
||||||
debug!(?xdg_toplevel, ?parent, "Set XDG Toplevel parent");
|
debug!(?xdg_toplevel, ?parent, "Set XDG Toplevel parent");
|
||||||
data.lock().parent = parent.clone().map(|toplevel| toplevel.downgrade());
|
data.lock().parent = parent.map(|toplevel| toplevel.downgrade());
|
||||||
let Some(panel_item) = data.lock().panel_item() else {return};
|
|
||||||
let Some(parent) = parent else {return};
|
|
||||||
let Some(parent_panel_item) = ToplevelData::get(&parent).lock().panel_item() else {return};
|
|
||||||
panel_item.toplevel_parent_changed(&parent_panel_item.uid);
|
|
||||||
}
|
}
|
||||||
xdg_toplevel::Request::SetTitle { title } => {
|
xdg_toplevel::Request::SetTitle { title } => {
|
||||||
debug!(?xdg_toplevel, ?title, "Set XDG Toplevel title");
|
debug!(?xdg_toplevel, ?title, "Set XDG Toplevel title");
|
||||||
data.lock().title = (!title.is_empty()).then_some(title.clone());
|
data.lock().title = (!title.is_empty()).then_some(title);
|
||||||
|
|
||||||
let Some(panel_item) = data.lock().panel_item() else {return};
|
|
||||||
panel_item.toplevel_title_changed(&title);
|
|
||||||
}
|
}
|
||||||
xdg_toplevel::Request::SetAppId { app_id } => {
|
xdg_toplevel::Request::SetAppId { app_id } => {
|
||||||
debug!(?xdg_toplevel, ?app_id, "Set XDG Toplevel app ID");
|
debug!(?xdg_toplevel, ?app_id, "Set XDG Toplevel app ID");
|
||||||
data.lock().app_id = (!app_id.is_empty()).then_some(app_id.clone());
|
data.lock().app_id = (!app_id.is_empty()).then_some(app_id);
|
||||||
|
}
|
||||||
let Some(panel_item) = data.lock().panel_item() else {return};
|
xdg_toplevel::Request::ShowWindowMenu { seat, serial, x, y } => {
|
||||||
panel_item.toplevel_app_id_changed(&app_id);
|
debug!(
|
||||||
|
?xdg_toplevel,
|
||||||
|
?seat,
|
||||||
|
serial,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
"Show XDG Toplevel window menu"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
xdg_toplevel::Request::Move { seat, serial } => {
|
xdg_toplevel::Request::Move { seat, serial } => {
|
||||||
debug!(?xdg_toplevel, ?seat, serial, "XDG Toplevel move request");
|
debug!(?xdg_toplevel, ?seat, serial, "XDG Toplevel move request");
|
||||||
let Some(panel_item) = data.lock().panel_item() else {return};
|
let Some(panel_item) = data.lock().panel_item() else {return};
|
||||||
panel_item.toplevel_move_request();
|
panel_item.recommend_toplevel_state(RecommendedState::Move);
|
||||||
}
|
}
|
||||||
xdg_toplevel::Request::Resize {
|
xdg_toplevel::Request::Resize {
|
||||||
seat,
|
seat,
|
||||||
@@ -589,18 +538,7 @@ impl Dispatch<XdgToplevel, Mutex<ToplevelData>, WaylandState> for WaylandState {
|
|||||||
"XDG Toplevel resize request"
|
"XDG Toplevel resize request"
|
||||||
);
|
);
|
||||||
let Some(panel_item) = data.lock().panel_item() else {return};
|
let Some(panel_item) = data.lock().panel_item() else {return};
|
||||||
let (up, down, left, right) = match edges {
|
panel_item.recommend_toplevel_state(RecommendedState::Resize(edges as u32));
|
||||||
ResizeEdge::Top => (true, false, false, false),
|
|
||||||
ResizeEdge::Bottom => (false, true, false, false),
|
|
||||||
ResizeEdge::Left => (false, false, true, false),
|
|
||||||
ResizeEdge::TopLeft => (true, false, true, false),
|
|
||||||
ResizeEdge::BottomLeft => (false, true, true, false),
|
|
||||||
ResizeEdge::Right => (false, false, false, true),
|
|
||||||
ResizeEdge::TopRight => (true, false, false, true),
|
|
||||||
ResizeEdge::BottomRight => (false, true, false, true),
|
|
||||||
_ => (false, false, false, false),
|
|
||||||
};
|
|
||||||
panel_item.toplevel_resize_request(up, down, left, right)
|
|
||||||
}
|
}
|
||||||
xdg_toplevel::Request::SetMaxSize { width, height } => {
|
xdg_toplevel::Request::SetMaxSize { width, height } => {
|
||||||
debug!(?xdg_toplevel, width, height, "Set XDG Toplevel max size");
|
debug!(?xdg_toplevel, width, height, "Set XDG Toplevel max size");
|
||||||
@@ -612,24 +550,32 @@ impl Dispatch<XdgToplevel, Mutex<ToplevelData>, WaylandState> for WaylandState {
|
|||||||
data.lock().min_size = (width > 1 || height > 1)
|
data.lock().min_size = (width > 1 || height > 1)
|
||||||
.then_some(Vector2::from([width as u32, height as u32]));
|
.then_some(Vector2::from([width as u32, height as u32]));
|
||||||
}
|
}
|
||||||
|
xdg_toplevel::Request::SetMaximized => {
|
||||||
|
let Some(panel_item) = data.lock().panel_item() else {return};
|
||||||
|
panel_item.recommend_toplevel_state(RecommendedState::Maximize(true));
|
||||||
|
}
|
||||||
|
xdg_toplevel::Request::UnsetMaximized => {
|
||||||
|
let Some(panel_item) = data.lock().panel_item() else {return};
|
||||||
|
panel_item.recommend_toplevel_state(RecommendedState::Maximize(false));
|
||||||
|
}
|
||||||
xdg_toplevel::Request::SetFullscreen { output: _ } => {
|
xdg_toplevel::Request::SetFullscreen { output: _ } => {
|
||||||
let Some(panel_item) = data.lock().panel_item() else {return};
|
let Some(panel_item) = data.lock().panel_item() else {return};
|
||||||
panel_item.backend.toplevel_state.lock().fullscreen = true;
|
panel_item.recommend_toplevel_state(RecommendedState::Fullscreen(true));
|
||||||
panel_item.backend.configure(None);
|
|
||||||
panel_item.toplevel_fullscreen_active(true);
|
|
||||||
}
|
}
|
||||||
xdg_toplevel::Request::UnsetFullscreen => {
|
xdg_toplevel::Request::UnsetFullscreen => {
|
||||||
let Some(panel_item) = data.lock().panel_item() else {return};
|
let Some(panel_item) = data.lock().panel_item() else {return};
|
||||||
panel_item.backend.toplevel_state.lock().fullscreen = false;
|
panel_item.recommend_toplevel_state(RecommendedState::Fullscreen(true));
|
||||||
panel_item.backend.configure(None);
|
}
|
||||||
panel_item.toplevel_fullscreen_active(false);
|
xdg_toplevel::Request::SetMinimized => {
|
||||||
|
let Some(panel_item) = data.lock().panel_item() else {return};
|
||||||
|
panel_item.recommend_toplevel_state(RecommendedState::Minimize);
|
||||||
}
|
}
|
||||||
xdg_toplevel::Request::Destroy => {
|
xdg_toplevel::Request::Destroy => {
|
||||||
debug!(?xdg_toplevel, "Destroy XDG Toplevel");
|
debug!(?xdg_toplevel, "Destroy XDG Toplevel");
|
||||||
let Some(panel_item) = data.lock().panel_item() else {return};
|
let Some(panel_item) = data.lock().panel_item() else {return};
|
||||||
panel_item.drop_toplevel();
|
panel_item.backend.on_drop();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -688,6 +634,16 @@ impl PopupData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Serialize for PopupData {
|
||||||
|
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
|
let Some(positioner_data) = self.positioner_data() else {return serde_error::<S>("Positioner not found")};
|
||||||
|
let mut seq = serializer.serialize_seq(None)?;
|
||||||
|
seq.serialize_element(&self.uid)?;
|
||||||
|
seq.serialize_element(&self.parent_id)?;
|
||||||
|
seq.serialize_element(&positioner_data)?;
|
||||||
|
seq.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
impl Debug for PopupData {
|
impl Debug for PopupData {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.debug_struct("XdgPopupData")
|
f.debug_struct("XdgPopupData")
|
||||||
@@ -713,7 +669,7 @@ impl Dispatch<XdgPopup, Mutex<PopupData>, WaylandState> for WaylandState {
|
|||||||
data.grabbed = true;
|
data.grabbed = true;
|
||||||
debug!(?xdg_popup, ?seat, serial, "XDG popup grab");
|
debug!(?xdg_popup, ?seat, serial, "XDG popup grab");
|
||||||
let Some(panel_item) = data.panel_item() else {return};
|
let Some(panel_item) = data.panel_item() else {return};
|
||||||
panel_item.grab_keyboard(Some(SurfaceID::Child(data.uid.clone())));
|
panel_item.grab_keyboard(Some(SurfaceID::Popup(data.uid.clone())));
|
||||||
}
|
}
|
||||||
xdg_popup::Request::Reposition { positioner, token } => {
|
xdg_popup::Request::Reposition { positioner, token } => {
|
||||||
let mut data = data.lock();
|
let mut data = data.lock();
|
||||||
@@ -738,7 +694,7 @@ impl Dispatch<XdgPopup, Mutex<PopupData>, WaylandState> for WaylandState {
|
|||||||
fn destroyed(
|
fn destroyed(
|
||||||
_state: &mut WaylandState,
|
_state: &mut WaylandState,
|
||||||
_client: ClientId,
|
_client: ClientId,
|
||||||
_popup: &XdgPopup,
|
_resource: ObjectId,
|
||||||
data: &Mutex<PopupData>,
|
data: &Mutex<PopupData>,
|
||||||
) {
|
) {
|
||||||
let data = data.lock();
|
let data = data.lock();
|
||||||
@@ -747,18 +703,12 @@ impl Dispatch<XdgPopup, Mutex<PopupData>, WaylandState> for WaylandState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct XdgToplevelState {
|
|
||||||
fullscreen: bool,
|
|
||||||
activated: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct XDGBackend {
|
pub struct XDGBackend {
|
||||||
toplevel: WlWeak<XdgToplevel>,
|
toplevel: WlWeak<XdgToplevel>,
|
||||||
toplevel_wl_surface: WlWeak<WlSurface>,
|
toplevel_wl_surface: WlWeak<WlSurface>,
|
||||||
toplevel_state: Mutex<XdgToplevelState>,
|
|
||||||
popups: Mutex<FxHashMap<String, WlWeak<XdgPopup>>>,
|
popups: Mutex<FxHashMap<String, WlWeak<XdgPopup>>>,
|
||||||
cursor: watch::Receiver<Option<CursorInfo>>,
|
cursor: watch::Receiver<Option<CursorInfo>>,
|
||||||
seat: Arc<SeatData>,
|
pub seat: Arc<SeatData>,
|
||||||
pointer_grab: Mutex<Option<SurfaceID>>,
|
pointer_grab: Mutex<Option<SurfaceID>>,
|
||||||
keyboard_grab: Mutex<Option<SurfaceID>>,
|
keyboard_grab: Mutex<Option<SurfaceID>>,
|
||||||
}
|
}
|
||||||
@@ -774,10 +724,6 @@ impl XDGBackend {
|
|||||||
Some(XDGBackend {
|
Some(XDGBackend {
|
||||||
toplevel: toplevel.downgrade(),
|
toplevel: toplevel.downgrade(),
|
||||||
toplevel_wl_surface,
|
toplevel_wl_surface,
|
||||||
toplevel_state: Mutex::new(XdgToplevelState {
|
|
||||||
fullscreen: false,
|
|
||||||
activated: false,
|
|
||||||
}),
|
|
||||||
popups: Mutex::new(FxHashMap::default()),
|
popups: Mutex::new(FxHashMap::default()),
|
||||||
cursor,
|
cursor,
|
||||||
seat,
|
seat,
|
||||||
@@ -789,7 +735,7 @@ impl XDGBackend {
|
|||||||
match id {
|
match id {
|
||||||
SurfaceID::Cursor => self.cursor.borrow().as_ref()?.surface.upgrade().ok(),
|
SurfaceID::Cursor => self.cursor.borrow().as_ref()?.surface.upgrade().ok(),
|
||||||
SurfaceID::Toplevel => self.toplevel_wl_surface(),
|
SurfaceID::Toplevel => self.toplevel_wl_surface(),
|
||||||
SurfaceID::Child(popup) => {
|
SurfaceID::Popup(popup) => {
|
||||||
let popups = self.popups.lock();
|
let popups = self.popups.lock();
|
||||||
let popup = popups.get(popup)?.upgrade().ok()?;
|
let popup = popups.get(popup)?.upgrade().ok()?;
|
||||||
let wl_surface = PopupData::get(&popup)?.lock().wl_surface();
|
let wl_surface = PopupData::get(&popup)?.lock().wl_surface();
|
||||||
@@ -808,35 +754,19 @@ impl XDGBackend {
|
|||||||
fn toplevel_wl_surface(&self) -> Option<WlSurface> {
|
fn toplevel_wl_surface(&self) -> Option<WlSurface> {
|
||||||
self.toplevel_wl_surface.upgrade().ok()
|
self.toplevel_wl_surface.upgrade().ok()
|
||||||
}
|
}
|
||||||
|
fn input_surfaces(&self) -> Vec<WlSurface> {
|
||||||
fn configure(&self, size: Option<Vector2<u32>>) {
|
let mut surfaces = self
|
||||||
let Ok(xdg_toplevel) = self.toplevel.upgrade() else {return};
|
.toplevel_wl_surface()
|
||||||
let Some(xdg_surface) = self.toplevel_xdg_surface() else {return};
|
.map(|s| vec![s])
|
||||||
let Some(wl_surface) = self.toplevel_wl_surface() else {return};
|
.unwrap_or_default();
|
||||||
let Some(core_surface) = CoreSurface::from_wl_surface(&wl_surface) else {return};
|
surfaces.extend(self.popups.lock().values().filter_map(|p| {
|
||||||
let Some(surface_size) = core_surface.size() else {return};
|
let popup = p.upgrade().ok()?;
|
||||||
|
let popup_data = PopupData::get(&popup)?.lock();
|
||||||
xdg_toplevel.configure(
|
let xdg_surface = popup_data.xdg_surface()?;
|
||||||
size.unwrap_or(surface_size).x as i32,
|
let xdg_surface_data = XdgSurfaceData::get(&xdg_surface)?.lock();
|
||||||
size.unwrap_or(surface_size).y as i32,
|
xdg_surface_data.wl_surface()
|
||||||
self.states()
|
}));
|
||||||
.into_iter()
|
surfaces
|
||||||
.flat_map(|state| state.to_ne_bytes())
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
xdg_surface.configure(SERIAL_COUNTER.inc());
|
|
||||||
self.flush_client();
|
|
||||||
}
|
|
||||||
fn states(&self) -> Vec<u32> {
|
|
||||||
let mut states = vec![1, 5, 6, 7, 8]; // maximized always and tiled
|
|
||||||
let toplevel_state = self.toplevel_state.lock();
|
|
||||||
if toplevel_state.fullscreen {
|
|
||||||
states.push(2);
|
|
||||||
}
|
|
||||||
if toplevel_state.activated {
|
|
||||||
states.push(4);
|
|
||||||
}
|
|
||||||
states
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_popup(
|
pub fn new_popup(
|
||||||
@@ -845,48 +775,52 @@ impl XDGBackend {
|
|||||||
popup: &XdgPopup,
|
popup: &XdgPopup,
|
||||||
data: &PopupData,
|
data: &PopupData,
|
||||||
) {
|
) {
|
||||||
self.popups
|
let uid = data.uid.clone();
|
||||||
.lock()
|
|
||||||
.insert(data.uid.clone(), popup.downgrade());
|
|
||||||
|
|
||||||
let Some(positioner_data) = data.positioner_data() else {return};
|
self.popups.lock().insert(uid.clone(), popup.downgrade());
|
||||||
panel_item.new_child(
|
|
||||||
&data.uid,
|
let Some(node) = panel_item.node() else {return};
|
||||||
ChildInfo {
|
let Ok(message) = serialize(&(&uid, data)) else {return};
|
||||||
parent: data.parent_id.clone(),
|
let _ = node.send_remote_signal("new_popup", message);
|
||||||
geometry: positioner_data.into(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
pub fn reposition_popup(&self, panel_item: &PanelItem<XDGBackend>, popup_state: &PopupData) {
|
pub fn reposition_popup(&self, panel_item: &PanelItem<XDGBackend>, popup_state: &PopupData) {
|
||||||
let Some(positioner_data) = popup_state.positioner_data() else {return};
|
let Some(node) = panel_item.node() else {return};
|
||||||
panel_item.reposition_child(&popup_state.uid, positioner_data.into())
|
|
||||||
|
let _ = node.send_remote_signal(
|
||||||
|
"reposition_popup",
|
||||||
|
serialize(popup_state.positioner_data().unwrap()).unwrap(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
pub fn drop_popup(&self, panel_item: &PanelItem<XDGBackend>, uid: &str) {
|
pub fn drop_popup(&self, panel_item: &PanelItem<XDGBackend>, uid: &str) {
|
||||||
panel_item.drop_child(uid);
|
'seat_drop: {
|
||||||
let Some(popup) = self
|
let Some(popup) = self
|
||||||
.popups
|
.popups
|
||||||
.lock()
|
.lock()
|
||||||
.remove(uid) else {return};
|
.remove(uid) else {break 'seat_drop};
|
||||||
let Some(popup) = popup.upgrade().ok() else {return};
|
let Some(popup) = popup.upgrade().ok() else {break 'seat_drop};
|
||||||
let Some(popup) = popup.data::<Arc<PopupData>>().cloned() else {return};
|
let Some(popup) = popup.data::<Arc<PopupData>>().cloned() else {break 'seat_drop};
|
||||||
let Some(wl_surface) = popup.wl_surface() else {return};
|
let Some(wl_surface) = popup.wl_surface() else {break 'seat_drop};
|
||||||
self.seat.drop_surface(&wl_surface);
|
self.seat.drop_surface(&wl_surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some(node) = panel_item.node() else {return};
|
||||||
|
let Ok(message) = serialize(uid) else {return};
|
||||||
|
let _ = node.send_remote_signal("drop_popup", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child_data(&self) -> FxHashMap<String, ChildInfo> {
|
fn popups_data(&self) -> Vec<PopupData> {
|
||||||
FxHashMap::from_iter(self.popups.lock().values().filter_map(|v| {
|
self.popups
|
||||||
let popup = v.upgrade().ok()?;
|
.lock()
|
||||||
let data = PopupData::get(&popup)?;
|
.values()
|
||||||
let data_lock = data.lock();
|
.filter_map(|v| Some(v.upgrade().ok()?.data::<Mutex<PopupData>>()?.lock().clone()))
|
||||||
Some((
|
.collect::<Vec<_>>()
|
||||||
data_lock.uid.clone(),
|
}
|
||||||
ChildInfo {
|
|
||||||
parent: data_lock.parent_id.clone(),
|
pub fn on_drop(&self) {
|
||||||
geometry: data_lock.positioner_data()?.into(),
|
let Some(toplevel) = self.toplevel_wl_surface() else {return};
|
||||||
},
|
self.seat.drop_surface(&toplevel);
|
||||||
))
|
|
||||||
}))
|
debug!("Dropped panel item gracefully");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush_client(&self) {
|
fn flush_client(&self) {
|
||||||
@@ -896,67 +830,73 @@ impl XDGBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Drop for XDGBackend {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
let Some(toplevel) = self.toplevel_wl_surface() else {return};
|
|
||||||
self.seat.drop_surface(&toplevel);
|
|
||||||
debug!("Dropped panel item gracefully");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Backend for XDGBackend {
|
impl Backend for XDGBackend {
|
||||||
fn start_data(&self) -> Result<PanelItemInitData> {
|
fn serialize_start_data(&self, id: &str) -> Result<Message> {
|
||||||
let toplevel = self.toplevel();
|
let toplevel_state = self
|
||||||
let toplevel_data = toplevel
|
.toplevel()
|
||||||
.as_ref()
|
.map(|t| ToplevelData::get(&t).lock().clone());
|
||||||
.map(|t| ToplevelData::get(t).lock())
|
|
||||||
.ok_or_else(|| eyre!("Could not get toplevel"))?;
|
|
||||||
|
|
||||||
let parent = toplevel_data
|
|
||||||
.parent
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|p| p.upgrade().ok())
|
|
||||||
.and_then(|p| ToplevelData::get(&p).lock().panel_item())
|
|
||||||
.map(|p| p.uid.clone());
|
|
||||||
let title = toplevel_data.title.clone();
|
|
||||||
let app_id = toplevel_data.app_id.clone();
|
|
||||||
let min_size = toplevel_data.min_size.clone();
|
|
||||||
let max_size = toplevel_data.max_size.clone();
|
|
||||||
drop(toplevel_data);
|
|
||||||
|
|
||||||
let pointer_grab = self.pointer_grab.lock().clone();
|
let pointer_grab = self.pointer_grab.lock().clone();
|
||||||
let keyboard_grab = self.keyboard_grab.lock().clone();
|
let keyboard_grab = self.keyboard_grab.lock().clone();
|
||||||
|
|
||||||
let Some(wl_surface) = self.toplevel_wl_surface() else {bail!("Wayland surface not found")};
|
Ok(serialize((
|
||||||
let Some(core_surface) = CoreSurface::from_wl_surface(&wl_surface) else {bail!("Core surface not found")};
|
id,
|
||||||
let Some(size) = core_surface.size() else {bail!("Surface size not found")};
|
(
|
||||||
|
self.cursor.borrow().as_ref().and_then(|c| c.cursor_data()),
|
||||||
|
toplevel_state,
|
||||||
|
self.popups_data(),
|
||||||
|
pointer_grab,
|
||||||
|
keyboard_grab,
|
||||||
|
),
|
||||||
|
))?
|
||||||
|
.into())
|
||||||
|
}
|
||||||
|
fn serialize_toplevel(&self) -> Result<Message> {
|
||||||
|
let toplevel = self
|
||||||
|
.toplevel()
|
||||||
|
.ok_or_else(|| eyre!("Toplevel does not exist"))?;
|
||||||
|
let state = ToplevelData::get(&toplevel);
|
||||||
|
let data = serialize(&state.lock().clone())?;
|
||||||
|
Ok(data.into())
|
||||||
|
}
|
||||||
|
|
||||||
let logical_rectangle = self
|
fn set_toplevel_capabilities(&self, capabilities: Vec<u8>) {
|
||||||
.toplevel_xdg_surface()
|
let Ok(xdg_toplevel) = self.toplevel.upgrade() else {return};
|
||||||
.as_ref()
|
let Some(xdg_surface) = self.toplevel_xdg_surface() else {return};
|
||||||
.and_then(XdgSurfaceData::get)
|
|
||||||
.and_then(|d| d.lock().geometry.clone())
|
|
||||||
.unwrap_or_else(|| Geometry {
|
|
||||||
origin: [0, 0].into(),
|
|
||||||
size,
|
|
||||||
});
|
|
||||||
|
|
||||||
let toplevel = ToplevelInfo {
|
if xdg_toplevel.version() < EVT_WM_CAPABILITIES_SINCE {
|
||||||
parent,
|
return;
|
||||||
title,
|
}
|
||||||
app_id,
|
xdg_toplevel.wm_capabilities(capabilities);
|
||||||
size,
|
xdg_surface.configure(SERIAL_COUNTER.inc());
|
||||||
min_size,
|
self.flush_client();
|
||||||
max_size,
|
}
|
||||||
logical_rectangle,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(PanelItemInitData {
|
fn configure_toplevel(
|
||||||
cursor: self.cursor.borrow().as_ref().and_then(|c| c.cursor_data()),
|
&self,
|
||||||
toplevel,
|
size: Option<Vector2<u32>>,
|
||||||
children: self.child_data(),
|
states: Vec<u32>,
|
||||||
pointer_grab,
|
bounds: Option<Vector2<u32>>,
|
||||||
keyboard_grab,
|
) {
|
||||||
})
|
let Ok(xdg_toplevel) = self.toplevel.upgrade() else {return};
|
||||||
|
let Some(xdg_surface) = self.toplevel_xdg_surface() else {return};
|
||||||
|
debug!(?size, ?states, ?bounds, "Configure toplevel info");
|
||||||
|
if let Some(bounds) = bounds {
|
||||||
|
if xdg_toplevel.version() > EVT_CONFIGURE_BOUNDS_SINCE {
|
||||||
|
xdg_toplevel.configure_bounds(bounds.x as i32, bounds.y as i32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let size = size.unwrap_or(Vector2::from([0; 2]));
|
||||||
|
xdg_toplevel.configure(
|
||||||
|
size.x as i32,
|
||||||
|
size.y as i32,
|
||||||
|
states
|
||||||
|
.into_iter()
|
||||||
|
.flat_map(|state| state.to_ne_bytes())
|
||||||
|
.collect(),
|
||||||
|
);
|
||||||
|
xdg_surface.configure(SERIAL_COUNTER.inc());
|
||||||
|
self.flush_client();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_surface_material(&self, surface: SurfaceID, model_part: &Arc<ModelPart>) {
|
fn apply_surface_material(&self, surface: SurfaceID, model_part: &Arc<ModelPart>) {
|
||||||
@@ -966,21 +906,6 @@ impl Backend for XDGBackend {
|
|||||||
core_surface.apply_material(model_part);
|
core_surface.apply_material(model_part);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_toplevel(&self) {
|
|
||||||
let Ok(xdg_toplevel) = self.toplevel.upgrade() else {return};
|
|
||||||
xdg_toplevel.close();
|
|
||||||
}
|
|
||||||
fn auto_size_toplevel(&self) {
|
|
||||||
self.configure(Some([0, 0].into()));
|
|
||||||
}
|
|
||||||
fn set_toplevel_size(&self, size: Vector2<u32>) {
|
|
||||||
self.configure(Some(size));
|
|
||||||
}
|
|
||||||
fn set_toplevel_focused_visuals(&self, focused: bool) {
|
|
||||||
self.toplevel_state.lock().activated = focused;
|
|
||||||
self.configure(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pointer_motion(&self, surface: &SurfaceID, position: Vector2<f32>) {
|
fn pointer_motion(&self, surface: &SurfaceID, position: Vector2<f32>) {
|
||||||
let Some(surface) = self.wl_surface_from_id(surface) else {return};
|
let Some(surface) = self.wl_surface_from_id(surface) else {return};
|
||||||
self.seat
|
self.seat
|
||||||
@@ -1012,35 +937,22 @@ impl Backend for XDGBackend {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_keys(&self, surface: &SurfaceID, keymap_id: &str, keys: Vec<i32>) {
|
fn keyboard_set_keymap(&self, keymap: &str) -> Result<()> {
|
||||||
|
let context = xkb::Context::new(0);
|
||||||
|
let keymap =
|
||||||
|
Keymap::new_from_string(&context, keymap.to_string(), XKB_KEYMAP_FORMAT_TEXT_V1, 0)
|
||||||
|
.ok_or_else(|| eyre!("Keymap is not valid"))?;
|
||||||
|
self.seat.set_keymap(&keymap, self.input_surfaces());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
fn keyboard_key(&self, surface: &SurfaceID, key: u32, state: bool) {
|
||||||
let Some(surface) = self.wl_surface_from_id(surface) else {return};
|
let Some(surface) = self.wl_surface_from_id(surface) else {return};
|
||||||
let keymaps = KEYMAPS.lock();
|
self.seat.keyboard_event(
|
||||||
let Some(keymap) = keymaps.get(keymap_id).cloned() else {return};
|
&surface,
|
||||||
if self.seat.set_keymap(keymap, vec![surface.clone()]).is_err() {
|
KeyboardEvent::Key {
|
||||||
return;
|
key,
|
||||||
}
|
state: if state { 1 } else { 0 },
|
||||||
for key in keys {
|
},
|
||||||
self.seat.keyboard_event(
|
)
|
||||||
&surface,
|
|
||||||
KeyboardEvent::Key {
|
|
||||||
key: key.abs() as u32,
|
|
||||||
state: key > 0,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn touch_down(&self, surface: &SurfaceID, id: u32, position: Vector2<f32>) {
|
|
||||||
let Some(surface) = self.wl_surface_from_id(surface) else {return};
|
|
||||||
self.seat.touch_down(&surface, id, position)
|
|
||||||
}
|
|
||||||
fn touch_move(&self, id: u32, position: Vector2<f32>) {
|
|
||||||
self.seat.touch_move(id, position)
|
|
||||||
}
|
|
||||||
fn touch_up(&self, id: u32) {
|
|
||||||
self.seat.touch_up(id)
|
|
||||||
}
|
|
||||||
fn reset_touches(&self) {
|
|
||||||
self.seat.reset_touches()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
use super::{
|
use super::{
|
||||||
seat::{KeyboardEvent, PointerEvent, SeatData},
|
seat::{KeyboardEvent, PointerEvent, SeatData},
|
||||||
state::ClientState,
|
state::ClientState,
|
||||||
|
xdg_shell::PopupData,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
nodes::{
|
nodes::{
|
||||||
data::KEYMAPS,
|
|
||||||
drawable::model::ModelPart,
|
drawable::model::ModelPart,
|
||||||
items::panel::{Backend, Geometry, PanelItem, PanelItemInitData, SurfaceID, ToplevelInfo},
|
items::panel::{Backend, PanelItem, RecommendedState, SurfaceID},
|
||||||
|
Message,
|
||||||
},
|
},
|
||||||
wayland::surface::CoreSurface,
|
wayland::surface::CoreSurface,
|
||||||
};
|
};
|
||||||
@@ -14,11 +15,11 @@ use color_eyre::eyre::Result;
|
|||||||
use mint::Vector2;
|
use mint::Vector2;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use smithay::{
|
use smithay::{
|
||||||
reexports::{
|
reexports::{
|
||||||
calloop::{EventLoop, LoopSignal},
|
calloop::{EventLoop, LoopSignal},
|
||||||
wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle, Resource},
|
wayland_protocols::xdg::shell::server::xdg_toplevel,
|
||||||
|
wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle, Resource, WEnum},
|
||||||
x11rb::protocol::xproto::Window,
|
x11rb::protocol::xproto::Window,
|
||||||
},
|
},
|
||||||
utils::{Logical, Rectangle},
|
utils::{Logical, Rectangle},
|
||||||
@@ -28,6 +29,7 @@ use smithay::{
|
|||||||
X11Surface, X11Wm, XWayland, XWaylandEvent, XwmHandler,
|
X11Surface, X11Wm, XWayland, XWaylandEvent, XwmHandler,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use stardust_xr::schemas::flex::serialize;
|
||||||
use std::{ffi::OsStr, iter::empty, sync::Arc, time::Duration};
|
use std::{ffi::OsStr, iter::empty, sync::Arc, time::Duration};
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
@@ -44,7 +46,7 @@ impl XWaylandState {
|
|||||||
|
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
tokio::task::spawn_blocking(move || {
|
||||||
let mut event_loop: EventLoop<XWaylandHandler> = EventLoop::try_new()?;
|
let mut event_loop: EventLoop<XWaylandHandler> = EventLoop::try_new()?;
|
||||||
let (xwayland, connection) = XWayland::new(&dh);
|
let (xwayland, connection) = XWayland::new(&dh);
|
||||||
let handle = event_loop.handle();
|
let handle = event_loop.handle();
|
||||||
@@ -133,8 +135,6 @@ impl XwmHandler for XWaylandHandler {
|
|||||||
fn map_window_notify(&mut self, _xwm: XwmId, window: X11Surface) {
|
fn map_window_notify(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
debug!(?window, "X map window notify");
|
debug!(?window, "X map window notify");
|
||||||
|
|
||||||
let _ = window.set_maximized(true);
|
|
||||||
|
|
||||||
let dh = self.wayland_display_handle.clone();
|
let dh = self.wayland_display_handle.clone();
|
||||||
let seat = self.seat.clone().unwrap();
|
let seat = self.seat.clone().unwrap();
|
||||||
CoreSurface::add_to(
|
CoreSurface::add_to(
|
||||||
@@ -146,7 +146,7 @@ impl XwmHandler for XWaylandHandler {
|
|||||||
let Some(wl_surface) = window.wl_surface() else {return};
|
let Some(wl_surface) = window.wl_surface() else {return};
|
||||||
let seat = seat.clone();
|
let seat = seat.clone();
|
||||||
window.user_data().insert_if_missing_threadsafe(|| {
|
window.user_data().insert_if_missing_threadsafe(|| {
|
||||||
let panel_item = PanelItem::create(
|
let (_node, panel_item) = PanelItem::create(
|
||||||
Box::new(X11Backend {
|
Box::new(X11Backend {
|
||||||
toplevel_parent: None,
|
toplevel_parent: None,
|
||||||
toplevel: window.clone(),
|
toplevel: window.clone(),
|
||||||
@@ -165,16 +165,11 @@ impl XwmHandler for XWaylandHandler {
|
|||||||
},
|
},
|
||||||
move |_| {
|
move |_| {
|
||||||
let Some(panel_item) = window.user_data().get::<Arc<PanelItem<X11Backend>>>() else {return};
|
let Some(panel_item) = window.user_data().get::<Arc<PanelItem<X11Backend>>>() else {return};
|
||||||
panel_item.toplevel_size_changed(
|
panel_item.commit_toplevel();
|
||||||
[
|
|
||||||
window.geometry().size.w as u32,
|
|
||||||
window.geometry().size.h as u32,
|
|
||||||
]
|
|
||||||
.into(),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mapped_override_redirect_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
fn mapped_override_redirect_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
debug!(?window, "X map override redirect window");
|
debug!(?window, "X map override redirect window");
|
||||||
}
|
}
|
||||||
@@ -182,6 +177,7 @@ impl XwmHandler for XWaylandHandler {
|
|||||||
fn unmapped_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
fn unmapped_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
debug!(?window, "Unmap X window");
|
debug!(?window, "Unmap X window");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn destroyed_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
fn destroyed_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
debug!(?window, "Destroy X window");
|
debug!(?window, "Destroy X window");
|
||||||
}
|
}
|
||||||
@@ -212,7 +208,7 @@ impl XwmHandler for XWaylandHandler {
|
|||||||
fn move_request(&mut self, _xwm: XwmId, window: X11Surface, button: u32) {
|
fn move_request(&mut self, _xwm: XwmId, window: X11Surface, button: u32) {
|
||||||
let Some(panel_item) = self.panel_item(&window) else {return};
|
let Some(panel_item) = self.panel_item(&window) else {return};
|
||||||
debug!(?window, button, "X window requests move");
|
debug!(?window, button, "X window requests move");
|
||||||
panel_item.toplevel_move_request();
|
panel_item.recommend_toplevel_state(RecommendedState::Move);
|
||||||
}
|
}
|
||||||
fn resize_request(
|
fn resize_request(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -223,29 +219,40 @@ impl XwmHandler for XWaylandHandler {
|
|||||||
) {
|
) {
|
||||||
let Some(panel_item) = self.panel_item(&window) else {return};
|
let Some(panel_item) = self.panel_item(&window) else {return};
|
||||||
debug!(?window, button, ?resize_edge, "X window requests resize");
|
debug!(?window, button, ?resize_edge, "X window requests resize");
|
||||||
let (up, down, left, right) = match resize_edge {
|
panel_item.recommend_toplevel_state(RecommendedState::Resize(
|
||||||
ResizeEdge::Top => (true, false, false, false),
|
WEnum::Value(match resize_edge {
|
||||||
ResizeEdge::Bottom => (false, true, false, false),
|
ResizeEdge::Top => xdg_toplevel::ResizeEdge::Top,
|
||||||
ResizeEdge::Left => (false, false, true, false),
|
ResizeEdge::Bottom => xdg_toplevel::ResizeEdge::Bottom,
|
||||||
ResizeEdge::TopLeft => (true, false, true, false),
|
ResizeEdge::Left => xdg_toplevel::ResizeEdge::Left,
|
||||||
ResizeEdge::BottomLeft => (false, true, true, false),
|
ResizeEdge::TopLeft => xdg_toplevel::ResizeEdge::TopLeft,
|
||||||
ResizeEdge::Right => (false, false, false, true),
|
ResizeEdge::BottomLeft => xdg_toplevel::ResizeEdge::BottomLeft,
|
||||||
ResizeEdge::TopRight => (true, false, false, true),
|
ResizeEdge::Right => xdg_toplevel::ResizeEdge::Right,
|
||||||
ResizeEdge::BottomRight => (false, true, false, true),
|
ResizeEdge::TopRight => xdg_toplevel::ResizeEdge::TopRight,
|
||||||
// _ => (false, false, false, false),
|
ResizeEdge::BottomRight => xdg_toplevel::ResizeEdge::BottomRight,
|
||||||
};
|
})
|
||||||
panel_item.toplevel_resize_request(up, down, left, right)
|
.into(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) {
|
fn maximize_request(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
let _ = window.set_fullscreen(true);
|
|
||||||
let Some(panel_item) = self.panel_item(&window) else {return};
|
let Some(panel_item) = self.panel_item(&window) else {return};
|
||||||
panel_item.toplevel_fullscreen_active(true);
|
panel_item.recommend_toplevel_state(RecommendedState::Maximize(true));
|
||||||
|
}
|
||||||
|
fn unmaximize_request(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
|
let Some(panel_item) = self.panel_item(&window) else {return};
|
||||||
|
panel_item.recommend_toplevel_state(RecommendedState::Maximize(false));
|
||||||
|
}
|
||||||
|
fn fullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
|
let Some(panel_item) = self.panel_item(&window) else {return};
|
||||||
|
panel_item.recommend_toplevel_state(RecommendedState::Fullscreen(true));
|
||||||
}
|
}
|
||||||
fn unfullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) {
|
fn unfullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
let _ = window.set_fullscreen(false);
|
|
||||||
let Some(panel_item) = self.panel_item(&window) else {return};
|
let Some(panel_item) = self.panel_item(&window) else {return};
|
||||||
panel_item.toplevel_fullscreen_active(true);
|
panel_item.recommend_toplevel_state(RecommendedState::Fullscreen(true));
|
||||||
|
}
|
||||||
|
fn minimize_request(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
|
let Some(panel_item) = self.panel_item(&window) else {return};
|
||||||
|
panel_item.recommend_toplevel_state(RecommendedState::Minimize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +268,7 @@ impl X11Backend {
|
|||||||
match id {
|
match id {
|
||||||
SurfaceID::Cursor => None,
|
SurfaceID::Cursor => None,
|
||||||
SurfaceID::Toplevel => self.toplevel.wl_surface(),
|
SurfaceID::Toplevel => self.toplevel.wl_surface(),
|
||||||
SurfaceID::Child(_) => None,
|
SurfaceID::Popup(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,110 +280,61 @@ impl X11Backend {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
impl Backend for X11Backend {
|
impl Backend for X11Backend {
|
||||||
// fn start_data(&self, id: &str) -> Result<Message> {
|
fn serialize_start_data(&self, id: &str) -> Result<Message> {
|
||||||
// let size = (
|
let size = (
|
||||||
// self.toplevel.geometry().size.w as u32,
|
self.toplevel.geometry().size.w as u32,
|
||||||
// self.toplevel.geometry().size.h as u32,
|
self.toplevel.geometry().size.h as u32,
|
||||||
// );
|
);
|
||||||
// let toplevel_state = (
|
let toplevel_state = (
|
||||||
// None::<String>,
|
None::<String>,
|
||||||
// self.toplevel.title(),
|
self.toplevel.title(),
|
||||||
// None::<String>,
|
None::<String>,
|
||||||
// (
|
(
|
||||||
// self.toplevel.geometry().size.w as u32,
|
self.toplevel.geometry().size.w as u32,
|
||||||
// self.toplevel.geometry().size.h as u32,
|
self.toplevel.geometry().size.h as u32,
|
||||||
// ),
|
),
|
||||||
// self.toplevel.min_size().map(|s| (s.w as u32, s.h as u32)),
|
self.toplevel.min_size().map(|s| (s.w as u32, s.h as u32)),
|
||||||
// self.toplevel.max_size().map(|s| (s.w as u32, s.w as u32)),
|
self.toplevel.max_size().map(|s| (s.w as u32, s.w as u32)),
|
||||||
// ((0_i32, 0_i32), size),
|
((0_i32, 0_i32), size),
|
||||||
// vec![0_u32; 0],
|
vec![0_u32; 0],
|
||||||
// );
|
);
|
||||||
// let info = (
|
let info = (
|
||||||
// None::<(Vector2<u32>, Vector2<i32>)>,
|
None::<(Vector2<u32>, Vector2<i32>)>,
|
||||||
// toplevel_state,
|
toplevel_state,
|
||||||
// Vec::<PopupData>::new(),
|
Vec::<PopupData>::new(),
|
||||||
// None::<SurfaceID>,
|
None::<SurfaceID>,
|
||||||
// None::<SurfaceID>,
|
None::<SurfaceID>,
|
||||||
// );
|
);
|
||||||
// Ok(serialize((id, info))?.into())
|
Ok(serialize((id, info))?.into())
|
||||||
// }
|
}
|
||||||
// fn serialize_toplevel(&self) -> Result<Message> {
|
fn serialize_toplevel(&self) -> Result<Message> {
|
||||||
// let toplevel_state = (
|
let toplevel_state = (
|
||||||
// None::<String>,
|
None::<String>,
|
||||||
// self.toplevel.title(),
|
self.toplevel.title(),
|
||||||
// None::<String>,
|
None::<String>,
|
||||||
// (
|
(
|
||||||
// self.toplevel.geometry().size.w,
|
self.toplevel.geometry().size.w,
|
||||||
// self.toplevel.geometry().size.h,
|
self.toplevel.geometry().size.h,
|
||||||
// ),
|
),
|
||||||
// self.toplevel.min_size().map(|s| (s.w, s.h)),
|
self.toplevel.min_size().map(|s| (s.w, s.h)),
|
||||||
// self.toplevel.max_size().map(|s| (s.w, s.w)),
|
self.toplevel.max_size().map(|s| (s.w, s.w)),
|
||||||
// );
|
);
|
||||||
// let data = serialize(&toplevel_state)?;
|
let data = serialize(&toplevel_state)?;
|
||||||
// Ok(data.into())
|
Ok(data.into())
|
||||||
// }
|
|
||||||
|
|
||||||
// fn set_toplevel_capabilities(&self, _capabilities: Vec<u8>) {}
|
|
||||||
|
|
||||||
// fn set_toplevel_size(
|
|
||||||
// &self,
|
|
||||||
// size: Option<Vector2<u32>>,
|
|
||||||
// states: Vec<u32>,
|
|
||||||
// _bounds: Option<Vector2<u32>>,
|
|
||||||
// ) {
|
|
||||||
// let _ = self.toplevel.configure(
|
|
||||||
// size.map(|s| Rectangle::from_loc_and_size((0, 0), (s.x as i32, s.y as i32))),
|
|
||||||
// );
|
|
||||||
// let _ = self.toplevel.set_maximized(states.contains(&1));
|
|
||||||
// }
|
|
||||||
|
|
||||||
fn start_data(&self) -> Result<PanelItemInitData> {
|
|
||||||
Ok(PanelItemInitData {
|
|
||||||
cursor: None,
|
|
||||||
toplevel: ToplevelInfo {
|
|
||||||
parent: None,
|
|
||||||
title: Some(self.toplevel.title()),
|
|
||||||
app_id: Some(self.toplevel.instance()),
|
|
||||||
size: [
|
|
||||||
self.toplevel.geometry().size.w as u32,
|
|
||||||
self.toplevel.geometry().size.h as u32,
|
|
||||||
]
|
|
||||||
.into(),
|
|
||||||
min_size: self
|
|
||||||
.toplevel
|
|
||||||
.min_size()
|
|
||||||
.map(|s| [s.w as u32, s.h as u32].into()),
|
|
||||||
max_size: self
|
|
||||||
.toplevel
|
|
||||||
.max_size()
|
|
||||||
.map(|s| [s.w as u32, s.h as u32].into()),
|
|
||||||
logical_rectangle: Geometry {
|
|
||||||
origin: [0, 0].into(),
|
|
||||||
size: [
|
|
||||||
self.toplevel.geometry().size.w as u32,
|
|
||||||
self.toplevel.geometry().size.h as u32,
|
|
||||||
]
|
|
||||||
.into(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: FxHashMap::default(),
|
|
||||||
pointer_grab: self._pointer_grab.lock().clone(),
|
|
||||||
keyboard_grab: self._keyboard_grab.lock().clone(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
fn close_toplevel(&self) {}
|
|
||||||
|
|
||||||
fn auto_size_toplevel(&self) {
|
fn set_toplevel_capabilities(&self, _capabilities: Vec<u8>) {}
|
||||||
let _ = self.toplevel.configure(None);
|
|
||||||
}
|
fn configure_toplevel(
|
||||||
fn set_toplevel_size(&self, size: Vector2<u32>) {
|
&self,
|
||||||
let _ = self.toplevel.configure(Some(Rectangle {
|
size: Option<Vector2<u32>>,
|
||||||
loc: self.toplevel.geometry().loc,
|
states: Vec<u32>,
|
||||||
size: (size.x as i32, size.y as i32).into(),
|
_bounds: Option<Vector2<u32>>,
|
||||||
}));
|
) {
|
||||||
}
|
let _ = self.toplevel.configure(
|
||||||
fn set_toplevel_focused_visuals(&self, focused: bool) {
|
size.map(|s| Rectangle::from_loc_and_size((0, 0), (s.x as i32, s.y as i32))),
|
||||||
let _ = self.toplevel.set_activated(focused);
|
);
|
||||||
|
let _ = self.toplevel.set_maximized(states.contains(&1));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_surface_material(&self, surface: SurfaceID, model_part: &Arc<ModelPart>) {
|
fn apply_surface_material(&self, surface: SurfaceID, model_part: &Arc<ModelPart>) {
|
||||||
@@ -417,21 +375,24 @@ impl Backend for X11Backend {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_keys(&self, surface: &SurfaceID, keymap_id: &str, keys: Vec<i32>) {
|
fn keyboard_set_keymap(&self, keymap: &str) -> Result<()> {
|
||||||
|
self.seat.set_keymap_str(
|
||||||
|
&keymap,
|
||||||
|
if let Some(toplevel) = self.toplevel.wl_surface() {
|
||||||
|
vec![toplevel]
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
fn keyboard_key(&self, surface: &SurfaceID, key: u32, state: bool) {
|
||||||
let Some(surface) = self.wl_surface_from_id(surface) else {return};
|
let Some(surface) = self.wl_surface_from_id(surface) else {return};
|
||||||
let keymaps = KEYMAPS.lock();
|
self.seat.keyboard_event(
|
||||||
let Some(keymap) = keymaps.get(keymap_id).cloned() else {return};
|
&surface,
|
||||||
if self.seat.set_keymap(keymap, vec![surface.clone()]).is_err() {
|
KeyboardEvent::Key {
|
||||||
return;
|
key,
|
||||||
}
|
state: if state { 1 } else { 0 },
|
||||||
for key in keys {
|
},
|
||||||
self.seat.keyboard_event(
|
)
|
||||||
&surface,
|
|
||||||
KeyboardEvent::Key {
|
|
||||||
key: key.abs() as u32,
|
|
||||||
state: if key < 0 { 1 } else { 0 },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user