mirror of
https://github.com/wayvr-org/wayvr.git
synced 2026-10-28 14:02:26 +01:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd77198464 | ||
|
|
a66470a6f9 | ||
|
|
fb971a7999 | ||
|
|
1d0a86ee65 | ||
|
|
f1ed8cd11c | ||
|
|
6e8643e566 | ||
|
|
8de6380ad9 | ||
|
|
a65b33fed2 | ||
|
|
786903efd5 |
No files matched your search
@@ -22,7 +22,7 @@ sudo apt-get update
|
||||
sudo apt-get install -y fuse cmake pkg-config fontconfig libasound2-dev libxkbcommon-dev libxkbcommon-x11-0 libxkbcommon-x11-dev \
|
||||
libopenxr-dev libfontconfig-dev libdbus-1-dev libpipewire-0.3-0 libpipewire-0.3-dev libspa-0.2-dev libx11-6 libxext6 libxrandr2 \
|
||||
libx11-dev libxext-dev libxrandr-dev libopenvr-dev libopenvr-api1t64 libwayland-dev libegl-dev libxcb-glx0 libxcb-glx0-dev \
|
||||
dav1d libdav1d-dev libvulkan-dev glslc vulkan-tools libudev-dev libudev1 libinput-dev libinput10 spirv-headers
|
||||
dav1d libdav1d-dev libvulkan-dev glslc vulkan-tools libudev-dev libudev1 libinput-dev libinput10
|
||||
|
||||
rustup update
|
||||
|
||||
|
||||
Generated
+35
-9
@@ -1744,7 +1744,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2479,6 +2479,26 @@ version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306"
|
||||
|
||||
[[package]]
|
||||
name = "inotify"
|
||||
version = "0.11.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4cc00ea907cab49550b7da656f80ebb97be1b997d931fbcd28d39734e17ce592"
|
||||
dependencies = [
|
||||
"bitflags 2.13.0",
|
||||
"inotify-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inotify-sys"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c033f80b2c113cdf91ab7a33faa9cbc014726dcad99880c8609af2a370edf37d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "input"
|
||||
version = "0.9.1"
|
||||
@@ -3215,7 +3235,7 @@ version = "0.50.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4125,7 +4145,7 @@ version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03da047801ff44bb6a4d407d4860c05fd70bb81714e6b2f3812603d5b145b042"
|
||||
dependencies = [
|
||||
"heck 0.4.1",
|
||||
"heck 0.5.0",
|
||||
"itertools 0.14.0",
|
||||
"log",
|
||||
"multimap",
|
||||
@@ -4726,7 +4746,7 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys 0.12.1",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5459,10 +5479,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.3.4",
|
||||
"getrandom 0.4.3",
|
||||
"once_cell",
|
||||
"rustix 1.1.4",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6223,6 +6243,7 @@ dependencies = [
|
||||
"glam",
|
||||
"idmap",
|
||||
"idmap-derive",
|
||||
"image",
|
||||
"image_dds",
|
||||
"input",
|
||||
"input-linux",
|
||||
@@ -6262,6 +6283,7 @@ dependencies = [
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-misc",
|
||||
"wayland-scanner",
|
||||
"wayvr-ipc",
|
||||
"wgui",
|
||||
"whisper-rs",
|
||||
@@ -6374,7 +6396,8 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "whisper-rs"
|
||||
version = "0.16.0"
|
||||
source = "git+https://github.com/wayvr-org/whisper-rs.git?rev=2d908ec36cd41521a28f7f5fb5dc95499fd40051#2d908ec36cd41521a28f7f5fb5dc95499fd40051"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2088172d00f936c348d6a72f488dc2660ab3f507263a195df308a3c2383229f6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"whisper-rs-sys",
|
||||
@@ -6383,7 +6406,8 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "whisper-rs-sys"
|
||||
version = "0.15.0"
|
||||
source = "git+https://github.com/wayvr-org/whisper-rs.git?rev=2d908ec36cd41521a28f7f5fb5dc95499fd40051#2d908ec36cd41521a28f7f5fb5dc95499fd40051"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6986c0fe081241d391f09b9a071fbcbb59720c3563628c3c829057cf69f2a56f"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"cfg-if",
|
||||
@@ -6420,7 +6444,7 @@ version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||
dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6858,6 +6882,8 @@ dependencies = [
|
||||
"identicons-svg",
|
||||
"idmap",
|
||||
"idmap-derive",
|
||||
"inotify",
|
||||
"libc",
|
||||
"log",
|
||||
"rodio",
|
||||
"serde",
|
||||
|
||||
@@ -23,6 +23,7 @@ dbus = { version = "0.9.12" }
|
||||
glam = { version = "0.30.9", features = ["mint", "serde"] }
|
||||
idmap = "0.2.2"
|
||||
idmap-derive = "0.2.22"
|
||||
image = { version = "0.25.10", default-features = false, features = ["png"] }
|
||||
interprocess = { version = "2.2.3" }
|
||||
libc = "0.2.178"
|
||||
log = "0.4.29"
|
||||
|
||||
@@ -1008,7 +1008,7 @@ fn create_dropdown<B: 'static + BindingsDropdown>(
|
||||
.iter()
|
||||
.map(|item| {
|
||||
context_menu::Cell::Button(context_menu::Button {
|
||||
action_name: Some(item.action_str(&action, side).into()),
|
||||
action_name: Some(item.action_str(&action, side)),
|
||||
title: item.translation(),
|
||||
..Default::default()
|
||||
})
|
||||
@@ -1019,7 +1019,7 @@ fn create_dropdown<B: 'static + BindingsDropdown>(
|
||||
cells.insert(
|
||||
0,
|
||||
context_menu::Cell::Button(context_menu::Button {
|
||||
action_name: Some(action_str.into()),
|
||||
action_name: Some(action_str),
|
||||
title: Translation::from_translation_key("APP_SETTINGS.OPTION.NONE"),
|
||||
..Default::default()
|
||||
}),
|
||||
|
||||
+4
-8
@@ -54,7 +54,8 @@ strum.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
uuid = { workspace = true }
|
||||
wayland-client = { workspace = true }
|
||||
wayland-protocols = { workspace = true }
|
||||
wayland-protocols = { workspace = true, features = ["server", "staging"] }
|
||||
wayland-scanner = "0.31.10"
|
||||
wayland-protocols-misc = { workspace = true }
|
||||
winit = { workspace = true, optional = true }
|
||||
xdg.workspace = true
|
||||
@@ -63,6 +64,7 @@ bytes = { workspace = true }
|
||||
chrono-tz = "0.10.4"
|
||||
config = "0.15.25"
|
||||
futures = "0.3.32"
|
||||
image.workspace = true
|
||||
image_dds = {
|
||||
version = "0.7.2",
|
||||
default-features = false,
|
||||
@@ -109,13 +111,7 @@ smithay-clipboard = "0.7.3"
|
||||
sysinfo = { version = "0.39.6" }
|
||||
thiserror = "2.0.18"
|
||||
tracing = "0.1.44"
|
||||
whisper-rs = {
|
||||
# version = "0.16.0",
|
||||
git = "https://github.com/wayvr-org/whisper-rs.git",
|
||||
rev = "2d908ec36cd41521a28f7f5fb5dc95499fd40051",
|
||||
features = ["vulkan"],
|
||||
optional = true
|
||||
}
|
||||
whisper-rs = { version = "0.16.0", features = ["vulkan"], optional = true }
|
||||
xcb = {
|
||||
version = "1.7.0",
|
||||
features = [
|
||||
|
||||
@@ -0,0 +1,333 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="xdg_session_management_v1">
|
||||
<copyright>
|
||||
Copyright 2018 Mike Blumenkrantz
|
||||
Copyright 2018 Samsung Electronics Co., Ltd
|
||||
Copyright 2018 Red Hat Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
</copyright>
|
||||
|
||||
<description summary="Protocol for managing application sessions">
|
||||
This description provides a high-level overview of the interplay between
|
||||
the interfaces defined this protocol. For details, see the protocol
|
||||
specification.
|
||||
|
||||
The xdg_session_manager protocol declares interfaces necessary to
|
||||
allow clients to restore toplevel state from previous executions. The
|
||||
xdg_session_manager_v1.get_session request can be used to obtain a
|
||||
xdg_session_v1 resource representing the state of a set of toplevels.
|
||||
|
||||
Clients may obtain the session string to use in future calls through
|
||||
the xdg_session_v1.created event. Compositors will use this string
|
||||
as an identifiable token for future runs, possibly storing data about
|
||||
the related toplevels in persistent storage. Clients that wish to
|
||||
track sessions in multiple environments may use the $XDG_CURRENT_DESKTOP
|
||||
environment variable.
|
||||
|
||||
Toplevels are managed through the xdg_session_v1.add_toplevel and
|
||||
xdg_session_v1.remove_toplevel pair of requests. Clients will explicitly
|
||||
request a toplevel to be restored according to prior state through the
|
||||
xdg_session_v1.restore_toplevel request before the toplevel is mapped.
|
||||
|
||||
Compositors may store session information up to any arbitrary level, and
|
||||
apply any limits and policies to the amount of data stored and its lifetime.
|
||||
Clients must account for missing sessions and partial session restoration.
|
||||
|
||||
Warning! The protocol described in this file is currently in the testing
|
||||
phase. Backward compatible changes may be added together with the
|
||||
corresponding interface version bump. Backward incompatible changes can
|
||||
only be done by creating a new major version of the extension.
|
||||
</description>
|
||||
|
||||
<interface name="xdg_session_manager_v1" version="1">
|
||||
<description summary="manage sessions for applications">
|
||||
The xdg_session_manager_v1 interface defines base requests for creating and
|
||||
managing a session for an application. Sessions persist across application
|
||||
and compositor restarts unless explicitly destroyed. A session is created
|
||||
for the purpose of maintaining an application's xdg_toplevel surfaces
|
||||
across compositor or application restarts. The compositor should remember
|
||||
as many states as possible for surfaces in a given session, but there is
|
||||
no requirement for which states must be remembered.
|
||||
|
||||
Policies such as cache eviction are declared an implementation detail of
|
||||
the compositor. Clients should account for no longer existing sessions.
|
||||
</description>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="in_use" summary="a requested session is already in use"
|
||||
value="1"/>
|
||||
<entry name="invalid_session_id" summary="invalid session identifier"
|
||||
value="2"/>
|
||||
<entry name="invalid_reason" summary="invalid reason" value="3"/>
|
||||
</enum>
|
||||
|
||||
<enum name="reason">
|
||||
<description summary="reason for getting a session">
|
||||
The reason may determine in what way a session restores the window
|
||||
management state of associated toplevels.
|
||||
|
||||
For example newly launched applications might be launched on the active
|
||||
workspace with restored size and position, while a recovered
|
||||
application might restore additional state such as active workspace and
|
||||
stacking order.
|
||||
</description>
|
||||
<entry name="launch" value="1">
|
||||
<description summary="an app is newly launched">
|
||||
A new app instance is launched, for example from an app launcher.
|
||||
</description>
|
||||
</entry>
|
||||
<entry name="recover" value="2">
|
||||
<description summary="an app recovered">
|
||||
An app instance is recovering from for example a compositor or app crash.
|
||||
</description>
|
||||
</entry>
|
||||
<entry name="session_restore" value="3">
|
||||
<description summary="an app restored">
|
||||
An app instance is restored, for example part of a restored session, or
|
||||
restored from having been temporarily terminated due to resource
|
||||
constraints.
|
||||
</description>
|
||||
</entry>
|
||||
</enum>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="Destroy this object">
|
||||
Destroy the manager object. The existing session objects will be
|
||||
unaffected.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="get_session">
|
||||
<description summary="create or restore a session">
|
||||
Create a session object corresponding to either an existing session
|
||||
identified by the given session identifier string or a new session.
|
||||
While the session object exists, the session is considered to be "in
|
||||
use".
|
||||
|
||||
If an identifier string represents a session that is currently actively
|
||||
in use by the same client, an 'in_use' error is raised. If some
|
||||
other client is currently using the same session, the new session will
|
||||
replace managing the associated state.
|
||||
|
||||
If the reason is not a valid enum entry, the 'invalid_reason' protocol
|
||||
error is raised.
|
||||
|
||||
NULL is passed to initiate a new session. If a session_id is passed
|
||||
which does not represent a valid session, the compositor treats it as if
|
||||
NULL had been passed.
|
||||
|
||||
The session id string must be UTF-8 encoded. It is also limited by the
|
||||
maximum length of wayland messages (around 4KB). The 'invalid_session_id'
|
||||
protocol error will be raised if an invalid string is provided.
|
||||
|
||||
A client is allowed to have any number of in use sessions at the same
|
||||
time.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="xdg_session_v1"/>
|
||||
<arg name="reason" type="uint" enum="reason"
|
||||
summary="reason for session"/>
|
||||
<arg name="session_id" type="string"
|
||||
summary="the session to restore"
|
||||
allow-null="true"/>
|
||||
</request>
|
||||
</interface>
|
||||
|
||||
<interface name="xdg_session_v1" version="1">
|
||||
<description summary="A session for an application">
|
||||
A xdg_session_v1 object represents a session for an application. While the
|
||||
object exists, all surfaces which have been added to the session will
|
||||
have states stored by the compositor which can be reapplied at a later
|
||||
time. Two sessions cannot exist for the same identifier string.
|
||||
|
||||
States for surfaces added to a session are automatically updated by the
|
||||
compositor when they are changed.
|
||||
</description>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="name_in_use"
|
||||
summary="toplevel name is already in use"
|
||||
value="1"/>
|
||||
<entry name="already_mapped"
|
||||
summary="toplevel was already mapped when restored"
|
||||
value="2"/>
|
||||
<entry name="invalid_name"
|
||||
summary="provided toplevel name is invalid"
|
||||
value="3"/>
|
||||
<entry name="already_added"
|
||||
summary="toplevel already added"
|
||||
value="4"/>
|
||||
</enum>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="Destroy the session">
|
||||
Destroy a session object, preserving the current state but not continuing
|
||||
to make further updates if state changes occur. This makes the associated
|
||||
xdg_toplevel_session_v1 objects inert.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="remove" type="destructor">
|
||||
<description summary="Remove the session">
|
||||
Remove the session, making it no longer available for restoration. A
|
||||
compositor should in response to this request remove the data related to
|
||||
this session from its storage.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="add_toplevel">
|
||||
<description summary="add a new surface to the session">
|
||||
Attempt to add a given surface to the session. The passed name is used
|
||||
to identify what window is being restored, and may be used to store
|
||||
window specific state within the session.
|
||||
|
||||
The name given to the toplevel must not correspond to any previously
|
||||
existing toplevel names in the session. If the name matches an already
|
||||
known toplevel name in the session, a 'name_in_use' protocol error will
|
||||
be raised.
|
||||
|
||||
The toplevel object must not be added more than once to any session
|
||||
created by the client, otherwise the 'already_added' protocol error
|
||||
will be raised.
|
||||
|
||||
This request will return a xdg_toplevel_session_v1 for later
|
||||
manipulation. As this resource is created from an empty initial state,
|
||||
compositors must not emit a xdg_toplevel_session_v1.restored event for
|
||||
resources created through this request.
|
||||
|
||||
The name string must be UTF-8 encoded. It is also limited by the maximum
|
||||
length of wayland messages (around 4KB). The 'invalid_name' protocol
|
||||
error will be raised if an invalid string is provided.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="xdg_toplevel_session_v1"/>
|
||||
<arg name="toplevel" type="object" interface="xdg_toplevel"/>
|
||||
<arg name="name" type="string" summary="name identifying the toplevel"/>
|
||||
</request>
|
||||
|
||||
<request name="restore_toplevel">
|
||||
<description summary="restore a surface state">
|
||||
Inform the compositor that the toplevel associated with the passed name
|
||||
should have its window management state restored.
|
||||
|
||||
If the toplevel name was previously granted to another xdg_toplevel,
|
||||
the 'name_in_use' protocol error will be raised.
|
||||
|
||||
The toplevel object must not be added more than once to any session
|
||||
created by the client, otherwise the 'already_added' protocol error
|
||||
will be raised.
|
||||
|
||||
This request must be called prior to the first commit on the associated
|
||||
wl_surface after creating the toplevel, otherwise an 'already_mapped'
|
||||
error is raised.
|
||||
|
||||
As part of the initial configure sequence, if the toplevel was
|
||||
successfully restored, a xdg_toplevel_session_v1.restored event is
|
||||
emitted. If the toplevel name was not known in the session, this request
|
||||
will be equivalent to the xdg_toplevel_session_v1.add_toplevel request,
|
||||
and no such event will be emitted. See the xdg_toplevel_session_v1.restored
|
||||
event for further details.
|
||||
|
||||
The name string must be UTF-8 encoded. It is also limited by the maximum
|
||||
length of wayland messages (around 4KB). The 'invalid_name' protocol
|
||||
error will be raised if an invalid string is provided.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="xdg_toplevel_session_v1"/>
|
||||
<arg name="toplevel" type="object" interface="xdg_toplevel"/>
|
||||
<arg name="name" type="string" summary="name identifying the toplevel"/>
|
||||
</request>
|
||||
|
||||
<request name="remove_toplevel">
|
||||
<description summary="remove a surface from the session">
|
||||
Remove a specified surface from the session and render any related
|
||||
xdg_toplevel_session_v1 object inert. The compositor should remove any
|
||||
data related to the toplevel in the corresponding session from its internal
|
||||
storage.
|
||||
|
||||
The window is specified by its name in the session. The name string
|
||||
must be encoded in UTF-8, and it is limited in size by the maximum
|
||||
length of wayland messages (around 4KB).
|
||||
</description>
|
||||
<arg name="name" type="string" summary="name identifying the toplevel"/>
|
||||
</request>
|
||||
|
||||
<event name="created">
|
||||
<description summary="newly-created session id">
|
||||
Emitted at most once some time after getting a new session object. It
|
||||
means that no previous state was restored, and a new session was created.
|
||||
The passed id can be persistently stored and used to restore previous
|
||||
sessions.
|
||||
</description>
|
||||
<arg name="session_id" type="string"/>
|
||||
</event>
|
||||
|
||||
<event name="restored">
|
||||
<description summary="the session has been restored">
|
||||
Emitted at most once some time after getting a new session object. It
|
||||
means that previous state was at least partially restored. The same id
|
||||
can again be used to restore previous sessions.
|
||||
</description>
|
||||
</event>
|
||||
|
||||
<event name="replaced">
|
||||
<description summary="the session has been replaced">
|
||||
Emitted at most once, if the session was taken over by some other
|
||||
client. When this happens, the session and all its toplevel session
|
||||
objects become inert, and should be destroyed.
|
||||
</description>
|
||||
</event>
|
||||
</interface>
|
||||
|
||||
<interface name="xdg_toplevel_session_v1" version="1">
|
||||
<description summary="A session for an application">
|
||||
A xdg_toplevel_session_v1 resource acts as a handle for the given
|
||||
toplevel in the session. It allows for receiving events after a
|
||||
toplevel state was restored, and has the requests to manage them.
|
||||
</description>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="Destroy the object">
|
||||
Destroy the object. This has no effect over window management of the
|
||||
associated toplevel.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="rename">
|
||||
<description summary="change the name of toplevel session">
|
||||
Renames the toplevel session. The new name can be used in subsequent requests
|
||||
to identify this session object. The state associated with this toplevel
|
||||
session will be preserved.
|
||||
|
||||
If the xdg_session_v1 already contains a toplevel with the specified name,
|
||||
the 'name_in_use' protocol error will be raised.
|
||||
</description>
|
||||
<arg name="name" type="string" summary="new name to identify the toplevel"/>
|
||||
</request>
|
||||
|
||||
<event name="restored">
|
||||
<description summary="a toplevel's session has been restored">
|
||||
The "restored" event is emitted prior to the first
|
||||
xdg_toplevel.configure for the toplevel. It will only be emitted after
|
||||
xdg_session_v1.restore_toplevel, and the initial empty surface state has
|
||||
been applied, and it indicates that the surface's session is being
|
||||
restored with this configure event.
|
||||
</description>
|
||||
</event>
|
||||
</interface>
|
||||
</protocol>
|
||||
@@ -874,11 +874,11 @@ fn start_grab(par: StartGrabParams) {
|
||||
// - not in editmode
|
||||
// - not using grab_float
|
||||
// - grabbing with one hand. (grabbing with the 2nd hand will grab the individual overlay instead)
|
||||
let grab_anchor = !par.edit_mode
|
||||
&& !par.grab_float
|
||||
&& !app.anchor_grabbed
|
||||
&& matches!(state.positioning, Positioning::Anchored)
|
||||
&& !(app.session.config.middle_grabs_single
|
||||
let grab_anchor = !(par.edit_mode
|
||||
|| par.grab_float
|
||||
|| app.anchor_grabbed
|
||||
|| !matches!(state.positioning, Positioning::Anchored)
|
||||
|| app.session.config.middle_grabs_single
|
||||
&& pointer.interaction.mode == PointerMode::Middle);
|
||||
|
||||
let relative_grab_transform = if grab_anchor {
|
||||
|
||||
@@ -723,7 +723,7 @@ fn for_each_path(spec: Option<&OneOrMany<String>>, mut f: impl FnMut(&str)) {
|
||||
}
|
||||
}
|
||||
|
||||
fn button_actions(profile: &OpenXrInputProfile) -> [Option<&OpenXrInputAction>; 11] {
|
||||
const fn button_actions(profile: &OpenXrInputProfile) -> [Option<&OpenXrInputAction>; 11] {
|
||||
[
|
||||
profile.click.as_ref(),
|
||||
profile.alt_click.as_ref(),
|
||||
@@ -925,7 +925,7 @@ fn add_button_bindings(
|
||||
|
||||
for (side, hand) in hands.iter_mut().enumerate() {
|
||||
for binding in build_button_bindings(action, side, profile_index, physical_input_map) {
|
||||
field(&mut **hand).add_binding(binding);
|
||||
field(hand).add_binding(binding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,34 +133,30 @@ impl PlayspaceMover {
|
||||
self.rotate = Some(data);
|
||||
// drag and rotate can share a button
|
||||
return;
|
||||
} else {
|
||||
// start space rotate
|
||||
for (i, pointer) in app.input_state.pointers.iter().enumerate() {
|
||||
if pointer.now.space_rotate {
|
||||
let Ok(pose) = monado
|
||||
.ipc
|
||||
.get_reference_space_offset(ReferenceSpaceType::Stage)
|
||||
.log_err("Could not get reference space offset.")
|
||||
.map(|p| {
|
||||
Affine3A::from_rotation_translation(
|
||||
p.orientation.into(),
|
||||
p.position.into(),
|
||||
)
|
||||
})
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
let hand_pose = pose * pointer.raw_pose;
|
||||
self.rotate = Some(MoverData {
|
||||
pose,
|
||||
hand: i,
|
||||
hand_pose,
|
||||
});
|
||||
self.drag = None;
|
||||
log::info!("Start space rotate");
|
||||
}
|
||||
// start space rotate
|
||||
for (i, pointer) in app.input_state.pointers.iter().enumerate() {
|
||||
if pointer.now.space_rotate {
|
||||
let Ok(pose) = monado
|
||||
.ipc
|
||||
.get_reference_space_offset(ReferenceSpaceType::Stage)
|
||||
.log_err("Could not get reference space offset.")
|
||||
.map(|p| {
|
||||
Affine3A::from_rotation_translation(p.orientation.into(), p.position.into())
|
||||
})
|
||||
else {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let hand_pose = pose * pointer.raw_pose;
|
||||
self.rotate = Some(MoverData {
|
||||
pose,
|
||||
hand: i,
|
||||
hand_pose,
|
||||
});
|
||||
self.drag = None;
|
||||
log::info!("Start space rotate");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ impl WlxSwapchain {
|
||||
|
||||
struct RetiredSwapchain {
|
||||
// keep alive until completion is signaled
|
||||
_swapchain: WlxSwapchain,
|
||||
swapchain: WlxSwapchain,
|
||||
completion: Option<GpuCompletionMarker>,
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ impl SwapchainRetirementQueue {
|
||||
/// queue the swapchain for non-blocking retirement
|
||||
pub(super) fn retire(&mut self, swapchain: WlxSwapchain, gfx: &Arc<WGfx>) {
|
||||
self.retired.push(RetiredSwapchain {
|
||||
_swapchain: swapchain,
|
||||
swapchain,
|
||||
completion: None,
|
||||
});
|
||||
|
||||
@@ -177,7 +177,7 @@ impl SwapchainRetirementQueue {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
retired._swapchain.ensure_image_released()?;
|
||||
retired.swapchain.ensure_image_released()?;
|
||||
retired.completion = Some(gfx.submit_graphics_completion_marker()?);
|
||||
Ok(())
|
||||
}
|
||||
@@ -185,12 +185,12 @@ impl SwapchainRetirementQueue {
|
||||
pub(super) fn collect(&mut self, gfx: &Arc<WGfx>) {
|
||||
let mut idx = 0;
|
||||
while idx < self.retired.len() {
|
||||
if self.retired[idx].completion.is_none() {
|
||||
if let Err(e) = Self::arm(&mut self.retired[idx], gfx) {
|
||||
log::warn!("Failed re-arming retired OpenXR swapchain: {e:#}");
|
||||
idx += 1;
|
||||
continue;
|
||||
}
|
||||
if self.retired[idx].completion.is_none()
|
||||
&& let Err(e) = Self::arm(&mut self.retired[idx], gfx)
|
||||
{
|
||||
log::warn!("Failed re-arming retired OpenXR swapchain: {e:#}");
|
||||
idx += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
let complete = match self.retired[idx]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::{
|
||||
cmp,
|
||||
collections::{BinaryHeap, VecDeque},
|
||||
sync::Arc,
|
||||
sync::atomic::{self, AtomicUsize},
|
||||
time::Instant,
|
||||
};
|
||||
@@ -10,6 +11,7 @@ use strum::EnumIs;
|
||||
|
||||
use crate::{
|
||||
backend::input,
|
||||
backend::wayvr as wvr,
|
||||
state::AppState,
|
||||
windowing::{
|
||||
OverlayID, OverlaySelector,
|
||||
@@ -109,6 +111,8 @@ pub enum SpawnPos {
|
||||
Spread,
|
||||
/// Spawn relative to a different overlay
|
||||
Parent(OverlaySelector),
|
||||
/// Resolve parent or app-id at the point of spawn
|
||||
WlDefault(wvr::window::WindowHandle, Option<OverlayID>),
|
||||
}
|
||||
|
||||
pub enum GlobalChange {
|
||||
@@ -138,6 +142,10 @@ pub enum OverlayTask {
|
||||
Drop(OverlaySelector),
|
||||
DropImmediate(OverlaySelector),
|
||||
DropExpired(OverlayID),
|
||||
SetOverlayName(OverlayID, Arc<str>, bool, bool),
|
||||
ForgetWindowState(OverlayID, Arc<str>),
|
||||
RenameWindowState(Arc<str>, Arc<str>),
|
||||
ClearWindowState(Arc<str>),
|
||||
}
|
||||
|
||||
pub type GlobalTask = dyn FnOnce(&mut AppState) + Send;
|
||||
|
||||
@@ -21,8 +21,6 @@ use smithay::{
|
||||
use wgui::log::LogErr;
|
||||
use xkbcommon::xkb;
|
||||
|
||||
use crate::backend::wayvr::WayVRTask;
|
||||
|
||||
use super::{
|
||||
ProcessWayVREnv,
|
||||
comp::{self, ClientState},
|
||||
|
||||
@@ -12,6 +12,7 @@ use smithay::output::Output;
|
||||
use smithay::reexports::rustix::fs::{OFlags, fcntl_setfl};
|
||||
use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
|
||||
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
|
||||
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::XdgToplevel;
|
||||
use smithay::reexports::wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration;
|
||||
use smithay::reexports::wayland_server::Resource;
|
||||
use smithay::reexports::wayland_server::backend::ObjectId;
|
||||
@@ -46,6 +47,8 @@ use smithay::wayland::shell::xdg::{
|
||||
use smithay::wayland::shm::{ShmHandler, ShmState, shm_format_to_fourcc, with_buffer_contents};
|
||||
use smithay::wayland::single_pixel_buffer::get_single_pixel_buffer;
|
||||
use smithay::wayland::viewporter::ViewporterState;
|
||||
use smithay::wayland::xdg_toplevel_icon::{XdgToplevelIconHandler, XdgToplevelIconManager};
|
||||
use smithay::wayland::xdg_toplevel_tag::{XdgToplevelTagHandler, XdgToplevelTagManager};
|
||||
use smithay::{
|
||||
delegate_compositor, delegate_data_control, delegate_data_device, delegate_dmabuf,
|
||||
delegate_ext_data_control, delegate_kde_decoration, delegate_output,
|
||||
@@ -62,6 +65,7 @@ use wayland_server::backend::{ClientData, ClientId, DisconnectReason};
|
||||
use wayland_server::protocol::wl_surface::WlSurface;
|
||||
use wlx_capture::DrmFourcc;
|
||||
|
||||
use super::session::SessionRegistry;
|
||||
use crate::backend::wayvr::image_importer::ImageImporter;
|
||||
use crate::backend::wayvr::{SurfaceBufWithImage, WAYVR_SCREEN_RES, time};
|
||||
use crate::ipc::event_queue::SyncEventQueue;
|
||||
@@ -74,6 +78,13 @@ pub struct Application {
|
||||
pub dmabuf_state: (DmabufState, DmabufGlobal, Option<DmabufFeedback>),
|
||||
pub compositor: compositor::CompositorState,
|
||||
pub xdg_shell: XdgShellState,
|
||||
#[allow(dead_code)]
|
||||
pub xdg_toplevel_tags: XdgToplevelTagManager,
|
||||
#[allow(dead_code)]
|
||||
pub xdg_toplevel_icons: XdgToplevelIconManager,
|
||||
pub pending_icon_changes: HashSet<ObjectId>,
|
||||
pub sessions: SessionRegistry,
|
||||
pub toplevel_tags: HashMap<ObjectId, Arc<str>>,
|
||||
pub seat: Seat<Application>,
|
||||
pub seat_state: SeatState<Application>,
|
||||
pub shm: ShmState,
|
||||
@@ -235,7 +246,7 @@ impl Application {
|
||||
}
|
||||
}
|
||||
|
||||
fn drm_format_has_alpha(format: DrmFourcc) -> bool {
|
||||
const fn drm_format_has_alpha(format: DrmFourcc) -> bool {
|
||||
matches!(
|
||||
format,
|
||||
DrmFourcc::Abgr8888 | DrmFourcc::Argb8888 | DrmFourcc::Abgr2101010
|
||||
@@ -256,6 +267,32 @@ impl compositor::CompositorHandler for Application {
|
||||
|
||||
#[allow(clippy::significant_drop_tightening)]
|
||||
fn commit(&mut self, surface: &WlSurface) {
|
||||
if self.pending_icon_changes.remove(&surface.id())
|
||||
&& let Some(toplevel) = self
|
||||
.xdg_shell
|
||||
.toplevel_surfaces()
|
||||
.iter()
|
||||
.find(|t| t.wl_surface() == surface)
|
||||
{
|
||||
self.wayvr_tasks
|
||||
.send(WayVRTask::IconChange(toplevel.clone()));
|
||||
}
|
||||
if let Some(toplevel) = self
|
||||
.xdg_shell
|
||||
.toplevel_surfaces()
|
||||
.iter()
|
||||
.find(|toplevel| toplevel.wl_surface() == surface)
|
||||
{
|
||||
// first commit is special in terms of restoring session
|
||||
if self
|
||||
.sessions
|
||||
.committed_toplevels
|
||||
.insert(toplevel.xdg_toplevel().id())
|
||||
{
|
||||
self.wayvr_tasks
|
||||
.send(WayVRTask::FirstToplevelCommit(toplevel.clone()));
|
||||
}
|
||||
}
|
||||
self.popups_commit(surface);
|
||||
|
||||
smithay::wayland::compositor::with_states(surface, |states| {
|
||||
@@ -497,6 +534,8 @@ impl XdgShellHandler for Application {
|
||||
}
|
||||
|
||||
fn toplevel_destroyed(&mut self, surface: ToplevelSurface) {
|
||||
self.toplevel_tags.remove(&surface.xdg_toplevel().id());
|
||||
self.sessions.forget_toplevel(&surface);
|
||||
self.output.leave(surface.wl_surface());
|
||||
self.no_server_decorations
|
||||
.remove(&surface.wl_surface().id());
|
||||
@@ -653,6 +692,16 @@ impl XdgShellHandler for Application {
|
||||
}
|
||||
}
|
||||
|
||||
fn app_id_changed(&mut self, surface: ToplevelSurface) {
|
||||
self.wayvr_tasks
|
||||
.send(WayVRTask::WindowIdentityChanged(surface));
|
||||
}
|
||||
|
||||
fn parent_changed(&mut self, surface: ToplevelSurface) {
|
||||
self.wayvr_tasks
|
||||
.send(WayVRTask::WindowIdentityChanged(surface));
|
||||
}
|
||||
|
||||
fn title_changed(&mut self, surface: ToplevelSurface) {
|
||||
if let Some(client) = surface.wl_surface().client() {
|
||||
self.wayvr_tasks
|
||||
@@ -661,6 +710,26 @@ impl XdgShellHandler for Application {
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgToplevelIconHandler for Application {
|
||||
fn set_icon(&mut self, _toplevel: XdgToplevel, surface: WlSurface) {
|
||||
self.pending_icon_changes.insert(surface.id());
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgToplevelTagHandler for Application {
|
||||
fn set_tag(&mut self, toplevel: XdgToplevel, tag: String) {
|
||||
if tag.is_empty() {
|
||||
self.toplevel_tags.remove(&toplevel.id());
|
||||
} else {
|
||||
self.toplevel_tags.insert(toplevel.id(), tag.into());
|
||||
}
|
||||
if let Some(surface) = self.xdg_shell.get_toplevel(&toplevel) {
|
||||
self.wayvr_tasks
|
||||
.send(WayVRTask::WindowIdentityChanged(surface));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ShmHandler for Application {
|
||||
fn shm_state(&self) -> &ShmState {
|
||||
&self.shm
|
||||
@@ -765,6 +834,8 @@ impl KdeDecorationHandler for Application {
|
||||
|
||||
delegate_dmabuf!(Application);
|
||||
delegate_xdg_shell!(Application);
|
||||
smithay::delegate_xdg_toplevel_tag!(Application);
|
||||
smithay::delegate_xdg_toplevel_icon!(Application);
|
||||
delegate_compositor!(Application);
|
||||
delegate_viewporter!(Application);
|
||||
delegate_shm!(Application);
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
use smithay::reexports::wayland_server::protocol::wl_shm;
|
||||
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
|
||||
use smithay::wayland::compositor::with_states;
|
||||
use smithay::wayland::shm::with_buffer_contents;
|
||||
use smithay::wayland::xdg_toplevel_icon::ToplevelIconCachedState;
|
||||
use std::sync::Arc;
|
||||
use wlx_common::desktop_finder::DesktopFinder;
|
||||
|
||||
pub fn toplevel_icon(surface: &WlSurface, finder: &DesktopFinder) -> Option<Arc<str>> {
|
||||
let (name, buffers) = with_states(surface, |states| {
|
||||
let mut icon = states.cached_state.get::<ToplevelIconCachedState>();
|
||||
let current = icon.current();
|
||||
(
|
||||
current.icon_name().map(str::to_owned),
|
||||
current.buffers().to_vec(),
|
||||
)
|
||||
});
|
||||
|
||||
for (buffer, _scale) in buffers {
|
||||
let mut png_path = None;
|
||||
let _ = with_buffer_contents(&buffer, |data, size, info| {
|
||||
let data = unsafe { std::slice::from_raw_parts(data, size) };
|
||||
let (w, h) = (info.width as usize, info.height as usize);
|
||||
if info.width <= 0
|
||||
|| info.height <= 0
|
||||
|| info.stride <= 0
|
||||
|| info.offset < 0
|
||||
|| w != h
|
||||
|| w > 1024
|
||||
{
|
||||
return;
|
||||
}
|
||||
let stride = info.stride as usize;
|
||||
let offset = info.offset as usize;
|
||||
if stride < w * 4
|
||||
|| offset
|
||||
.checked_add((h - 1).saturating_mul(stride) + w * 4)
|
||||
.is_none_or(|end| end > size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
let has_alpha = match info.format {
|
||||
wl_shm::Format::Argb8888 => true,
|
||||
wl_shm::Format::Xrgb8888 => false,
|
||||
_ => return,
|
||||
};
|
||||
let mut rgba = vec![0u8; w * h * 4];
|
||||
for y in 0..h {
|
||||
for x in 0..w {
|
||||
let pos = offset + y * stride + x * 4;
|
||||
let dst = (y * w + x) * 4;
|
||||
rgba[dst] = data[pos + 2];
|
||||
rgba[dst + 1] = data[pos + 1];
|
||||
rgba[dst + 2] = data[pos];
|
||||
rgba[dst + 3] = if has_alpha { data[pos + 3] } else { 255 };
|
||||
}
|
||||
}
|
||||
let path = wlx_common::cache_dir::get_path(&format!(
|
||||
"icons/wayland-{}.png",
|
||||
uuid::Uuid::new_v4()
|
||||
));
|
||||
if let Some(parent) = path.parent() {
|
||||
let _ = std::fs::create_dir_all(parent);
|
||||
}
|
||||
if image::save_buffer_with_format(
|
||||
&path,
|
||||
&rgba,
|
||||
w as u32,
|
||||
h as u32,
|
||||
image::ColorType::Rgba8,
|
||||
image::ImageFormat::Png,
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
png_path = Some(path.to_string_lossy().into_owned().into());
|
||||
}
|
||||
});
|
||||
if png_path.is_some() {
|
||||
return png_path;
|
||||
}
|
||||
}
|
||||
name.and_then(|n| finder.resolve_icon(&n)).map(Into::into)
|
||||
}
|
||||
+311
-34
@@ -1,15 +1,19 @@
|
||||
pub mod client;
|
||||
mod comp;
|
||||
pub mod hit_test;
|
||||
mod icon;
|
||||
mod image_importer;
|
||||
mod input_capture;
|
||||
pub mod process;
|
||||
mod session;
|
||||
mod session_protocol;
|
||||
mod time;
|
||||
pub mod window;
|
||||
|
||||
use anyhow::Context;
|
||||
use comp::Application;
|
||||
use glam::{DVec2, Vec2};
|
||||
use session::{SessionRegistry, app_key, tag_key};
|
||||
use slotmap::{DenseSlotMap, SecondaryMap};
|
||||
use smallvec::SmallVec;
|
||||
use smithay::{
|
||||
@@ -19,7 +23,7 @@ use smithay::{
|
||||
reexports::{
|
||||
wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration_manager as kde_decoration,
|
||||
wayland_server::{
|
||||
self,
|
||||
self, Resource,
|
||||
backend::ClientId,
|
||||
protocol::{wl_buffer, wl_surface::WlSurface},
|
||||
},
|
||||
@@ -121,9 +125,15 @@ pub struct ProcessWayVREnv {
|
||||
#[derive(Clone)]
|
||||
pub enum WayVRTask {
|
||||
NewToplevel(ClientId, ToplevelSurface),
|
||||
FirstToplevelCommit(ToplevelSurface),
|
||||
DropToplevel(ClientId, ToplevelSurface),
|
||||
MinimizeRequest(ClientId, ToplevelSurface),
|
||||
TitleChange(ClientId, ToplevelSurface),
|
||||
IconChange(ToplevelSurface),
|
||||
WindowIdentityChanged(ToplevelSurface),
|
||||
FreezeWindowState(ToplevelSurface, Arc<str>),
|
||||
RenameWindowState(Arc<str>, Arc<str>),
|
||||
ForgetWindowState(Arc<str>),
|
||||
VisibilityChange(window::WindowHandle, bool),
|
||||
ProcessTerminationRequest(process::ProcessHandle, KillSignal),
|
||||
CloseWindowRequest(window::WindowHandle),
|
||||
@@ -169,7 +179,11 @@ const KEY_REPEAT_RATE: i32 = 50;
|
||||
const WAYVR_SCREEN_RES: [i32; 2] = [2560, 1440];
|
||||
|
||||
impl WvrServerState {
|
||||
pub fn new(gfx: Arc<WGfx>, gfx_extras: &WGfxExtras) -> anyhow::Result<Self> {
|
||||
pub fn new(
|
||||
gfx: Arc<WGfx>,
|
||||
gfx_extras: &WGfxExtras,
|
||||
config: &GeneralConfig,
|
||||
) -> anyhow::Result<Self> {
|
||||
const fn filter_allow_any(_: &wayland_server::Client) -> bool {
|
||||
true
|
||||
}
|
||||
@@ -178,6 +192,19 @@ impl WvrServerState {
|
||||
let dh = display.handle();
|
||||
let compositor = compositor::CompositorState::new::<Application>(&dh);
|
||||
let xdg_shell = XdgShellState::new::<Application>(&dh);
|
||||
let _session_global = dh.create_global::<Application,
|
||||
session_protocol::server::xdg_session_manager_v1::XdgSessionManagerV1, _>(1, ());
|
||||
let xdg_toplevel_tags =
|
||||
smithay::wayland::xdg_toplevel_tag::XdgToplevelTagManager::new::<Application>(&dh);
|
||||
let mut xdg_toplevel_icons =
|
||||
smithay::wayland::xdg_toplevel_icon::XdgToplevelIconManager::new::<Application>(&dh);
|
||||
xdg_toplevel_icons.add_icon_size(64);
|
||||
let stored_keys: HashSet<Arc<str>> = config
|
||||
.sets
|
||||
.iter()
|
||||
.flat_map(|set| set.overlays.keys().chain(set.hidden_overlays.keys()))
|
||||
.cloned()
|
||||
.collect();
|
||||
let mut seat_state = SeatState::new();
|
||||
let shm = ShmState::new::<Application>(&dh, Vec::new());
|
||||
let data_device = DataDeviceState::new::<Application>(&dh);
|
||||
@@ -269,6 +296,11 @@ impl WvrServerState {
|
||||
display_handle: dh,
|
||||
compositor,
|
||||
xdg_shell,
|
||||
xdg_toplevel_tags,
|
||||
xdg_toplevel_icons,
|
||||
pending_icon_changes: HashSet::new(),
|
||||
sessions: SessionRegistry::new(stored_keys),
|
||||
toplevel_tags: HashMap::new(),
|
||||
seat,
|
||||
seat_state,
|
||||
shm,
|
||||
@@ -414,6 +446,29 @@ impl WvrServerState {
|
||||
),
|
||||
};
|
||||
|
||||
let (xdg_title, app_id): (Option<String>, Option<String>) =
|
||||
with_states(toplevel.wl_surface(), |states| {
|
||||
states.data_map.get::<XdgToplevelSurfaceData>().map_or(
|
||||
(None, None),
|
||||
|t| {
|
||||
let t = t.lock().unwrap();
|
||||
(t.title.clone(), t.app_id.clone())
|
||||
},
|
||||
)
|
||||
});
|
||||
let app_id: Option<Arc<str>> =
|
||||
app_id.filter(|s| !s.is_empty()).map(Into::into);
|
||||
let parent = toplevel.parent().and_then(|surface| {
|
||||
wvr_server
|
||||
.wm
|
||||
.windows
|
||||
.iter()
|
||||
.find(|(_, window)| *window.toplevel.wl_surface() == surface)
|
||||
.map(|(handle, _)| handle)
|
||||
});
|
||||
let (name, restore_on_spawn) =
|
||||
wvr_server.window_identity(&toplevel, app_id.as_deref(), parent, None);
|
||||
|
||||
let window_handle = wvr_server.wm.create_window(CreateWindowParams {
|
||||
toplevel: toplevel.clone(),
|
||||
process: process_handle,
|
||||
@@ -422,6 +477,10 @@ impl WvrServerState {
|
||||
max_size,
|
||||
size_x: fallback_size.w as _,
|
||||
size_y: fallback_size.h as _,
|
||||
app_id: app_id.clone(),
|
||||
parent,
|
||||
name: name.clone(),
|
||||
restore_on_spawn,
|
||||
});
|
||||
|
||||
toplevel.with_pending_state(|state| {
|
||||
@@ -430,42 +489,41 @@ impl WvrServerState {
|
||||
state.size = Some(fallback_size);
|
||||
state.states.set(xdg_toplevel::State::Activated);
|
||||
});
|
||||
toplevel.send_configure();
|
||||
// xdg-shell requires an empty commit before initial configure
|
||||
if wvr_server
|
||||
.manager
|
||||
.state
|
||||
.sessions
|
||||
.committed_toplevels
|
||||
.contains(&toplevel.xdg_toplevel().id())
|
||||
{
|
||||
wvr_server.send_first_configure(&toplevel);
|
||||
}
|
||||
|
||||
let mut title: Arc<str> = fallback_title
|
||||
.unwrap_or_else(|| format!("P{}", client.pid))
|
||||
.into();
|
||||
.map(Arc::from)
|
||||
.or_else(|| name.clone())
|
||||
.unwrap_or_else(|| format!("P{}", client.pid).into());
|
||||
|
||||
let spawn_pos = wvr_server
|
||||
.last_process_overlay(process_handle)
|
||||
.map_or(SpawnPos::Spread, |oid| {
|
||||
SpawnPos::Parent(OverlaySelector::Id(oid))
|
||||
});
|
||||
let spawn_pos = SpawnPos::WlDefault(
|
||||
window_handle,
|
||||
wvr_server.last_process_overlay(process_handle),
|
||||
);
|
||||
|
||||
let mut icon = icon;
|
||||
|
||||
// Try to get title from xdg_toplevel, unless it's running in cage
|
||||
if !is_cage {
|
||||
let mut needs_title = true;
|
||||
let (xdg_title, app_id): (Option<String>, Option<String>) =
|
||||
with_states(toplevel.wl_surface(), |states| {
|
||||
states.data_map.get::<XdgToplevelSurfaceData>().map_or(
|
||||
(None, None),
|
||||
|t| {
|
||||
let t = t.lock().unwrap();
|
||||
(t.title.clone(), t.app_id.clone())
|
||||
},
|
||||
)
|
||||
});
|
||||
if let Some(xdg_title) = xdg_title {
|
||||
needs_title = false;
|
||||
title = xdg_title.into();
|
||||
}
|
||||
|
||||
// Try to get title & icon from desktop entry
|
||||
if let Some(app_id) = app_id
|
||||
if let Some(app_id) = app_id.as_deref()
|
||||
&& let Some(desktop_entry) =
|
||||
app.desktop_finder.get_cached_entry(&app_id)
|
||||
app.desktop_finder.get_cached_entry(app_id)
|
||||
{
|
||||
if needs_title {
|
||||
title = desktop_entry.app_name.as_ref().into();
|
||||
@@ -478,6 +536,9 @@ impl WvrServerState {
|
||||
}
|
||||
}
|
||||
|
||||
let icon = icon::toplevel_icon(toplevel.wl_surface(), &app.desktop_finder)
|
||||
.or(icon);
|
||||
|
||||
// Fall back to identicon
|
||||
let icon = match icon {
|
||||
Some(icon) => icon,
|
||||
@@ -488,8 +549,32 @@ impl WvrServerState {
|
||||
OverlaySelector::Nothing,
|
||||
spawn_pos,
|
||||
Box::new(move |app: &mut AppState| {
|
||||
let (identity, restore_on_spawn) = app
|
||||
.wvr_server
|
||||
.as_ref()
|
||||
.and_then(|wvr| wvr.wm.windows.get(window_handle))
|
||||
.map_or((None, false), |w| {
|
||||
(w.name.clone(), w.restore_on_spawn)
|
||||
});
|
||||
let persistent = identity.is_some();
|
||||
let name =
|
||||
identity.unwrap_or_else(|| window_handle.transient_name());
|
||||
let icon = app
|
||||
.wvr_server
|
||||
.as_ref()
|
||||
.and_then(|wvr| wvr.wm.windows.get(window_handle))
|
||||
.and_then(|window| {
|
||||
icon::toplevel_icon(
|
||||
window.toplevel.wl_surface(),
|
||||
&app.desktop_finder,
|
||||
)
|
||||
})
|
||||
.unwrap_or(icon);
|
||||
create_wl_window_overlay(
|
||||
name,
|
||||
title,
|
||||
persistent,
|
||||
restore_on_spawn,
|
||||
app,
|
||||
window_handle,
|
||||
icon,
|
||||
@@ -503,6 +588,11 @@ impl WvrServerState {
|
||||
)));
|
||||
}
|
||||
}
|
||||
WayVRTask::FirstToplevelCommit(toplevel) => {
|
||||
if wvr_server.wm.find_window_handle(&toplevel).is_some() {
|
||||
wvr_server.send_first_configure(&toplevel);
|
||||
}
|
||||
}
|
||||
WayVRTask::DropToplevel(client_id, toplevel) => {
|
||||
for client in &wvr_server.manager.clients {
|
||||
if client.client.id() != client_id {
|
||||
@@ -543,9 +633,81 @@ impl WvrServerState {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(key) = wvr_server
|
||||
.wm
|
||||
.windows
|
||||
.get(window_handle)
|
||||
.and_then(|w| w.name.clone())
|
||||
{
|
||||
wvr_server.manager.state.sessions.stored_keys.insert(key);
|
||||
}
|
||||
wvr_server.wm.remove_window(window_handle);
|
||||
}
|
||||
}
|
||||
WayVRTask::WindowIdentityChanged(toplevel) => {
|
||||
let Some(handle) = wvr_server.wm.find_window_handle(&toplevel) else {
|
||||
continue;
|
||||
};
|
||||
let app_id: Option<Arc<str>> = with_states(toplevel.wl_surface(), |states| {
|
||||
states
|
||||
.data_map
|
||||
.get::<XdgToplevelSurfaceData>()
|
||||
.and_then(|d| {
|
||||
d.lock()
|
||||
.unwrap()
|
||||
.app_id
|
||||
.as_deref()
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(Into::into)
|
||||
})
|
||||
});
|
||||
let parent = toplevel.parent().and_then(|surface| {
|
||||
wvr_server
|
||||
.wm
|
||||
.windows
|
||||
.iter()
|
||||
.find(|(_, w)| *w.toplevel.wl_surface() == surface)
|
||||
.map(|(id, _)| id)
|
||||
});
|
||||
let (key, restore) = wvr_server.window_identity(
|
||||
&toplevel,
|
||||
app_id.as_deref(),
|
||||
parent,
|
||||
Some(handle),
|
||||
);
|
||||
if let Some(window) = wvr_server.wm.windows.get_mut(handle) {
|
||||
window.app_id = app_id;
|
||||
window.parent = parent;
|
||||
if window.name != key || window.restore_on_spawn != restore {
|
||||
window.name.clone_from(&key);
|
||||
window.restore_on_spawn = restore;
|
||||
if let Some(oid) = wvr_server.window_to_overlay.get(&handle) {
|
||||
let persistent = key.is_some();
|
||||
let name = key.unwrap_or_else(|| handle.transient_name());
|
||||
app.tasks
|
||||
.enqueue(TaskType::Overlay(OverlayTask::SetOverlayName(
|
||||
*oid, name, persistent, restore,
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
WayVRTask::FreezeWindowState(toplevel, key) => {
|
||||
if let Some(handle) = wvr_server.wm.find_window_handle(&toplevel)
|
||||
&& let Some(oid) = wvr_server.window_to_overlay.get(&handle)
|
||||
{
|
||||
app.tasks
|
||||
.enqueue(TaskType::Overlay(OverlayTask::ForgetWindowState(*oid, key)));
|
||||
}
|
||||
}
|
||||
WayVRTask::RenameWindowState(old, new) => {
|
||||
app.tasks
|
||||
.enqueue(TaskType::Overlay(OverlayTask::RenameWindowState(old, new)));
|
||||
}
|
||||
WayVRTask::ForgetWindowState(key) => {
|
||||
app.tasks
|
||||
.enqueue(TaskType::Overlay(OverlayTask::ClearWindowState(key)));
|
||||
}
|
||||
WayVRTask::VisibilityChange(window_handle, visible) => {
|
||||
if let Some(oid) = wvr_server.window_to_overlay.get(&window_handle) {
|
||||
app.tasks
|
||||
@@ -580,6 +742,42 @@ impl WvrServerState {
|
||||
}
|
||||
}
|
||||
}
|
||||
WayVRTask::IconChange(toplevel) => {
|
||||
if let Some(handle) = wvr_server.wm.find_window_handle(&toplevel)
|
||||
&& let Some(oid) = wvr_server.window_to_overlay.get(&handle)
|
||||
{
|
||||
let icon = icon::toplevel_icon(toplevel.wl_surface(), &app.desktop_finder);
|
||||
let fallback = wvr_server
|
||||
.wm
|
||||
.windows
|
||||
.get(handle)
|
||||
.and_then(|w| w.app_id.as_deref())
|
||||
.and_then(|id| app.desktop_finder.get_cached_entry(id))
|
||||
.and_then(|entry| entry.icon_path.as_ref())
|
||||
.map(|s| Arc::<str>::from(s.as_ref()));
|
||||
let icon = icon.or(fallback).or_else(|| {
|
||||
let title =
|
||||
with_states(toplevel.wl_surface(), |states| {
|
||||
states.data_map.get::<XdgToplevelSurfaceData>().and_then(
|
||||
|data| data.lock().ok().and_then(|data| data.title.clone()),
|
||||
)
|
||||
})
|
||||
.unwrap_or_else(|| "window".to_owned());
|
||||
DesktopFinder::create_icon(&title).ok().map(Into::into)
|
||||
});
|
||||
if let Some(icon) = icon {
|
||||
app.tasks.enqueue(TaskType::Overlay(OverlayTask::Modify(
|
||||
OverlaySelector::Id(*oid),
|
||||
Box::new(move |app, owc| {
|
||||
let _ = owc.backend.notify(
|
||||
app,
|
||||
OverlayEventData::WvrCommand(WvrCommand::SetIcon(icon)),
|
||||
);
|
||||
}),
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
WayVRTask::TitleChange(client_id, toplevel) => {
|
||||
for client in &wvr_server.manager.clients {
|
||||
if client.client.id() != client_id {
|
||||
@@ -591,15 +789,29 @@ impl WvrServerState {
|
||||
continue;
|
||||
};
|
||||
if let Some(oid) = wvr_server.window_to_overlay.get(&window_handle) {
|
||||
app.tasks.enqueue(TaskType::Overlay(OverlayTask::Modify(
|
||||
OverlaySelector::Id(*oid),
|
||||
Box::new(|app, owc| {
|
||||
let _ = owc.backend.notify(
|
||||
app,
|
||||
OverlayEventData::WvrCommand(WvrCommand::ReloadTitle),
|
||||
);
|
||||
}),
|
||||
)));
|
||||
let title: Option<Arc<str>> =
|
||||
with_states(toplevel.wl_surface(), |states| {
|
||||
states
|
||||
.data_map
|
||||
.get::<XdgToplevelSurfaceData>()
|
||||
.and_then(|data| {
|
||||
data.lock().ok().and_then(|data| data.title.clone())
|
||||
})
|
||||
.filter(|title| !title.is_empty())
|
||||
.map(Into::into)
|
||||
});
|
||||
if let Some(title) = title {
|
||||
app.tasks.enqueue(TaskType::Overlay(OverlayTask::Modify(
|
||||
OverlaySelector::Id(*oid),
|
||||
Box::new(move |app, owc| {
|
||||
owc.title = Some(title);
|
||||
let _ = owc.backend.notify(
|
||||
app,
|
||||
OverlayEventData::WvrCommand(WvrCommand::ReloadTitle),
|
||||
);
|
||||
}),
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -655,7 +867,7 @@ impl WvrServerState {
|
||||
Box::new(move |app| {
|
||||
create_drag_item(app, icon, pointer)
|
||||
.inspect_err(|e| {
|
||||
log::warn!("Could not create drag item overlay: {e:?}")
|
||||
log::warn!("Could not create drag item overlay: {e:?}");
|
||||
})
|
||||
.ok()
|
||||
}),
|
||||
@@ -732,6 +944,70 @@ impl WvrServerState {
|
||||
.copied()
|
||||
}
|
||||
|
||||
/// session restore send as part of first configure
|
||||
fn send_first_configure(&self, toplevel: &ToplevelSurface) {
|
||||
if toplevel.is_initial_configure_sent() {
|
||||
return;
|
||||
}
|
||||
if let Some(s) = self.manager.state.sessions.get_toplevel(toplevel)
|
||||
&& s.restore_requested
|
||||
&& self.manager.state.sessions.stored_keys.contains(&s.key)
|
||||
&& let Some(resource) = s.restore_resource.as_ref()
|
||||
{
|
||||
resource.restored();
|
||||
}
|
||||
toplevel.send_configure();
|
||||
}
|
||||
|
||||
/// Identifier key based on xdg session or app_id+tags or app_id+pid
|
||||
fn window_identity(
|
||||
&self,
|
||||
toplevel: &ToplevelSurface,
|
||||
app_id: Option<&str>,
|
||||
parent: Option<window::WindowHandle>,
|
||||
except: Option<window::WindowHandle>,
|
||||
) -> (Option<Arc<str>>, bool) {
|
||||
let session = self.manager.state.sessions.get_toplevel(toplevel);
|
||||
let tag = self
|
||||
.manager
|
||||
.state
|
||||
.toplevel_tags
|
||||
.get(&toplevel.xdg_toplevel().id());
|
||||
let identity = session
|
||||
.map(|s| (s.key.clone(), s.restore_requested))
|
||||
.or_else(|| {
|
||||
app_id
|
||||
.zip(tag)
|
||||
.map(|(app_id, tag)| (tag_key(app_id, tag), true))
|
||||
})
|
||||
.or_else(|| {
|
||||
let app_id = app_id?;
|
||||
if parent.is_some()
|
||||
|| self.wm.windows.iter().any(|(id, w)| {
|
||||
Some(id) != except
|
||||
&& w.parent.is_none()
|
||||
&& w.app_id.as_deref() == Some(app_id)
|
||||
})
|
||||
{
|
||||
None
|
||||
} else {
|
||||
Some((app_key(app_id), true))
|
||||
}
|
||||
});
|
||||
match identity {
|
||||
Some((key, restore))
|
||||
if !self
|
||||
.wm
|
||||
.windows
|
||||
.iter()
|
||||
.any(|(id, w)| Some(id) != except && w.name.as_ref() == Some(&key)) =>
|
||||
{
|
||||
(Some(key), restore)
|
||||
}
|
||||
_ => (None, false),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_removed(&mut self, tasks: &mut TaskContainer, process: process::ProcessHandle) {
|
||||
let mut to_remove = vec![];
|
||||
|
||||
@@ -1212,7 +1488,7 @@ impl WvrServerState {
|
||||
self.manager.send_pointer_button(index, pressed);
|
||||
}
|
||||
|
||||
pub fn set_vr_pointer(&mut self, pointer: usize) {
|
||||
pub const fn set_vr_pointer(&mut self, pointer: usize) {
|
||||
self.manager.state.vr_pointer = pointer;
|
||||
}
|
||||
|
||||
@@ -1227,7 +1503,7 @@ impl WvrServerState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dnd_active(&self) -> bool {
|
||||
pub const fn dnd_active(&self) -> bool {
|
||||
self.manager.state.dnd_pointer.is_some()
|
||||
}
|
||||
|
||||
@@ -1449,6 +1725,7 @@ impl SurfaceBufWithImage {
|
||||
|
||||
let mut guard = surface_data.cached_state.get::<ViewportCachedState>();
|
||||
let viewport = *guard.current();
|
||||
drop(guard);
|
||||
let Some(src) = viewport.src else {
|
||||
return [0.0, 0.0, 1.0, 1.0];
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{collections::HashMap, io::Read, sync::Arc};
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use slotmap::{DenseSlotMap, new_key_type};
|
||||
use slotmap::new_key_type;
|
||||
use wayvr_ipc::{packet_client, packet_server};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -98,23 +98,6 @@ impl Drop for WayVRProcess {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_process_env_value(pid: i32, key: &str) -> anyhow::Result<Option<String>> {
|
||||
let path = format!("/proc/{pid}/environ");
|
||||
let mut env_data = String::new();
|
||||
std::fs::File::open(path)?.read_to_string(&mut env_data)?;
|
||||
let lines: Vec<&str> = env_data.split('\0').filter(|s| !s.is_empty()).collect();
|
||||
|
||||
for line in lines {
|
||||
if let Some(cell) = line.split_once('=')
|
||||
&& cell.0 == key
|
||||
{
|
||||
return Ok(Some(String::from(cell.1)));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
impl WayVRProcess {
|
||||
fn is_running(&mut self) -> bool {
|
||||
match self.child.try_wait() {
|
||||
@@ -183,43 +166,6 @@ new_key_type! {
|
||||
pub struct ProcessHandle;
|
||||
}
|
||||
|
||||
pub fn find_by_pid(
|
||||
processes: &DenseSlotMap<ProcessHandle, Process>,
|
||||
pid: u32,
|
||||
) -> Option<ProcessHandle> {
|
||||
log::debug!("Finding process with PID {pid}");
|
||||
|
||||
for (handle, process) in processes {
|
||||
match &process {
|
||||
Process::Managed(wayvr_process) => {
|
||||
if wayvr_process.child.id() == pid {
|
||||
return Some(handle);
|
||||
}
|
||||
}
|
||||
Process::External(external_process) => {
|
||||
if external_process.pid == pid {
|
||||
return Some(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log::debug!("Finding by PID failed, trying WAYVR_DISPLAY_AUTH...");
|
||||
|
||||
if let Ok(Some(value)) = get_process_env_value(pid as i32, "WAYVR_DISPLAY_AUTH") {
|
||||
for (handle, process) in processes {
|
||||
if let Process::Managed(wayvr_process) = &process
|
||||
&& wayvr_process.auth_key == value
|
||||
{
|
||||
return Some(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log::debug!("Process find with PID {pid} failed");
|
||||
None
|
||||
}
|
||||
|
||||
impl ProcessHandle {
|
||||
pub fn from_packet(handle: packet_server::WvrProcessHandle) -> Self {
|
||||
Self::from(slotmap::KeyData::from_ffi(handle.user))
|
||||
|
||||
@@ -0,0 +1,419 @@
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use smithay::{
|
||||
reexports::wayland_server::{
|
||||
Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, WEnum,
|
||||
backend::ObjectId,
|
||||
},
|
||||
wayland::shell::xdg::ToplevelSurface,
|
||||
};
|
||||
|
||||
use super::{
|
||||
WayVRTask,
|
||||
comp::Application,
|
||||
session_protocol::server::{
|
||||
xdg_session_manager_v1::{self, XdgSessionManagerV1},
|
||||
xdg_session_v1::{self, XdgSessionV1},
|
||||
xdg_toplevel_session_v1::{self, XdgToplevelSessionV1},
|
||||
},
|
||||
};
|
||||
|
||||
const SESSION_PREFIX: &str = "wayvr/session/";
|
||||
|
||||
pub(super) fn session_key(session: &str, name: &str) -> Arc<str> {
|
||||
format!("{SESSION_PREFIX}{}:{session}/{name}", session.len()).into()
|
||||
}
|
||||
|
||||
fn session_prefix(session: &str) -> String {
|
||||
format!("{SESSION_PREFIX}{}:{session}/", session.len())
|
||||
}
|
||||
|
||||
pub(super) fn tag_key(app_id: &str, tag: &str) -> Arc<str> {
|
||||
format!("wayvr/tag/{}:{app_id}/{}:{tag}", app_id.len(), tag.len()).into()
|
||||
}
|
||||
|
||||
pub(super) fn app_key(app_id: &str) -> Arc<str> {
|
||||
format!("wayvr/app/{}:{app_id}", app_id.len()).into()
|
||||
}
|
||||
|
||||
pub struct WindowSession {
|
||||
pub key: Arc<str>,
|
||||
pub restore_requested: bool,
|
||||
pub restore_resource: Option<XdgToplevelSessionV1>,
|
||||
session_id: String,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SessionRegistry {
|
||||
sessions: HashMap<String, Option<XdgSessionV1>>,
|
||||
toplevels: HashMap<ObjectId, WindowSession>,
|
||||
pub stored_keys: HashSet<Arc<str>>,
|
||||
pub committed_toplevels: HashSet<ObjectId>,
|
||||
}
|
||||
|
||||
impl SessionRegistry {
|
||||
pub fn new(saved_keys: HashSet<Arc<str>>) -> Self {
|
||||
Self {
|
||||
stored_keys: saved_keys,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_toplevel(&self, toplevel: &ToplevelSurface) -> Option<&WindowSession> {
|
||||
self.toplevels.get(&toplevel.xdg_toplevel().id())
|
||||
}
|
||||
|
||||
pub fn forget_toplevel(&mut self, toplevel: &ToplevelSurface) {
|
||||
self.toplevels.remove(&toplevel.xdg_toplevel().id());
|
||||
self.committed_toplevels
|
||||
.remove(&toplevel.xdg_toplevel().id());
|
||||
}
|
||||
}
|
||||
|
||||
impl Application {
|
||||
fn detach_session(&mut self, session_id: &str, forget: bool) {
|
||||
let detached: Vec<_> = self
|
||||
.sessions
|
||||
.toplevels
|
||||
.iter()
|
||||
.filter(|(_, w)| w.session_id == session_id)
|
||||
.map(|(id, w)| (id.clone(), w.key.clone()))
|
||||
.collect();
|
||||
|
||||
for (id, key) in detached {
|
||||
self.sessions.toplevels.remove(&id);
|
||||
let surface = self
|
||||
.xdg_shell
|
||||
.toplevel_surfaces()
|
||||
.iter()
|
||||
.find(|surface| surface.xdg_toplevel().id() == id)
|
||||
.cloned();
|
||||
|
||||
if forget {
|
||||
self.sessions.stored_keys.remove(&key);
|
||||
} else {
|
||||
self.sessions.stored_keys.insert(key.clone());
|
||||
if let Some(surface) = &surface {
|
||||
self.wayvr_tasks
|
||||
.send(WayVRTask::FreezeWindowState(surface.clone(), key.clone()));
|
||||
}
|
||||
}
|
||||
if let Some(surface) = surface {
|
||||
self.wayvr_tasks
|
||||
.send(WayVRTask::WindowIdentityChanged(surface));
|
||||
}
|
||||
if forget {
|
||||
self.wayvr_tasks.send(WayVRTask::ForgetWindowState(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_session_toplevel(&mut self, session_id: &str, name: &str) {
|
||||
let key = session_key(session_id, name);
|
||||
let live = self
|
||||
.sessions
|
||||
.toplevels
|
||||
.iter()
|
||||
.find(|(_, w)| w.session_id == session_id && w.key == key)
|
||||
.map(|(id, _)| id.clone());
|
||||
if let Some(id) = live {
|
||||
self.sessions.toplevels.remove(&id);
|
||||
if let Some(surface) = self
|
||||
.xdg_shell
|
||||
.toplevel_surfaces()
|
||||
.iter()
|
||||
.find(|surface| surface.xdg_toplevel().id() == id)
|
||||
.cloned()
|
||||
{
|
||||
self.wayvr_tasks
|
||||
.send(WayVRTask::WindowIdentityChanged(surface));
|
||||
}
|
||||
}
|
||||
self.sessions.stored_keys.remove(&key);
|
||||
self.wayvr_tasks.send(WayVRTask::ForgetWindowState(key));
|
||||
}
|
||||
}
|
||||
|
||||
impl GlobalDispatch<XdgSessionManagerV1, ()> for Application {
|
||||
fn bind(
|
||||
_state: &mut Self,
|
||||
_dh: &DisplayHandle,
|
||||
_client: &Client,
|
||||
resource: New<XdgSessionManagerV1>,
|
||||
_data: &(),
|
||||
data_init: &mut DataInit<'_, Self>,
|
||||
) {
|
||||
data_init.init(resource, ());
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<XdgSessionManagerV1, ()> for Application {
|
||||
fn request(
|
||||
state: &mut Self,
|
||||
client: &Client,
|
||||
resource: &XdgSessionManagerV1,
|
||||
request: xdg_session_manager_v1::Request,
|
||||
_data: &(),
|
||||
_dh: &DisplayHandle,
|
||||
data_init: &mut DataInit<'_, Self>,
|
||||
) {
|
||||
match request {
|
||||
xdg_session_manager_v1::Request::GetSession {
|
||||
id,
|
||||
reason,
|
||||
session_id,
|
||||
} => {
|
||||
if let WEnum::Unknown(_) = reason {
|
||||
resource.post_error(
|
||||
xdg_session_manager_v1::Error::InvalidReason,
|
||||
"unrecognized session reason",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let known = session_id.as_ref().is_some_and(|token| {
|
||||
state.sessions.sessions.contains_key(token)
|
||||
|| state
|
||||
.sessions
|
||||
.stored_keys
|
||||
.iter()
|
||||
.any(|key| key.starts_with(session_prefix(token).as_str()))
|
||||
});
|
||||
let token = if known {
|
||||
session_id.unwrap()
|
||||
} else {
|
||||
uuid::Uuid::new_v4().to_string()
|
||||
};
|
||||
|
||||
if let Some(Some(old)) = state.sessions.sessions.get(&token) {
|
||||
if old.client().is_some_and(|c| c.id() == client.id()) {
|
||||
resource.post_error(
|
||||
xdg_session_manager_v1::Error::InUse,
|
||||
"session is already in use by this client",
|
||||
);
|
||||
return;
|
||||
}
|
||||
old.replaced();
|
||||
state.detach_session(&token, false);
|
||||
}
|
||||
|
||||
let session_resource = data_init.init(id, token.clone());
|
||||
if known {
|
||||
session_resource.restored();
|
||||
} else {
|
||||
session_resource.created(token.clone());
|
||||
}
|
||||
state
|
||||
.sessions
|
||||
.sessions
|
||||
.insert(token, Some(session_resource));
|
||||
}
|
||||
xdg_session_manager_v1::Request::Destroy => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<XdgSessionV1, String> for Application {
|
||||
fn request(
|
||||
state: &mut Self,
|
||||
_client: &Client,
|
||||
resource: &XdgSessionV1,
|
||||
request: xdg_session_v1::Request,
|
||||
session_id: &String,
|
||||
_dh: &DisplayHandle,
|
||||
data_init: &mut DataInit<'_, Self>,
|
||||
) {
|
||||
if state
|
||||
.sessions
|
||||
.sessions
|
||||
.get(session_id)
|
||||
.and_then(Option::as_ref)
|
||||
!= Some(resource)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let restore_requested = matches!(&request, xdg_session_v1::Request::RestoreToplevel { .. });
|
||||
match request {
|
||||
xdg_session_v1::Request::AddToplevel { id, toplevel, name }
|
||||
| xdg_session_v1::Request::RestoreToplevel { id, toplevel, name } => {
|
||||
let key = session_key(session_id, &name);
|
||||
if state
|
||||
.sessions
|
||||
.toplevels
|
||||
.values()
|
||||
.any(|w| w.session_id == *session_id && w.key == key)
|
||||
|| (!restore_requested && state.sessions.stored_keys.contains(&key))
|
||||
{
|
||||
resource.post_error(
|
||||
xdg_session_v1::Error::NameInUse,
|
||||
"toplevel name already in use",
|
||||
);
|
||||
return;
|
||||
}
|
||||
let toplevel_id = toplevel.id();
|
||||
if state.sessions.toplevels.contains_key(&toplevel_id) {
|
||||
resource.post_error(
|
||||
xdg_session_v1::Error::AlreadyAdded,
|
||||
"toplevel already belongs to a session",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if restore_requested && state.sessions.committed_toplevels.contains(&toplevel_id) {
|
||||
resource.post_error(
|
||||
xdg_session_v1::Error::AlreadyMapped,
|
||||
"restore_toplevel after first commit",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let can_restore = restore_requested && state.sessions.stored_keys.contains(&key);
|
||||
let session_resource = data_init.init(id, ());
|
||||
state.sessions.toplevels.insert(
|
||||
toplevel_id,
|
||||
WindowSession {
|
||||
key,
|
||||
session_id: session_id.clone(),
|
||||
restore_requested: can_restore,
|
||||
restore_resource: Some(session_resource),
|
||||
},
|
||||
);
|
||||
if let Some(surface) = state.xdg_shell.get_toplevel(&toplevel) {
|
||||
state
|
||||
.wayvr_tasks
|
||||
.send(WayVRTask::WindowIdentityChanged(surface));
|
||||
}
|
||||
}
|
||||
xdg_session_v1::Request::RemoveToplevel { name } => {
|
||||
state.remove_session_toplevel(session_id, &name);
|
||||
}
|
||||
xdg_session_v1::Request::Destroy => {
|
||||
state.detach_session(session_id, false);
|
||||
state.sessions.sessions.insert(session_id.clone(), None);
|
||||
}
|
||||
xdg_session_v1::Request::Remove => {
|
||||
state.detach_session(session_id, true);
|
||||
let prefix = session_prefix(session_id);
|
||||
let keys: Vec<_> = state
|
||||
.sessions
|
||||
.stored_keys
|
||||
.iter()
|
||||
.filter(|key| key.starts_with(prefix.as_str()))
|
||||
.cloned()
|
||||
.collect();
|
||||
for key in keys {
|
||||
state.sessions.stored_keys.remove(&key);
|
||||
state.wayvr_tasks.send(WayVRTask::ForgetWindowState(key));
|
||||
}
|
||||
state.sessions.sessions.remove(session_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
state: &mut Self,
|
||||
_client: smithay::reexports::wayland_server::backend::ClientId,
|
||||
resource: &XdgSessionV1,
|
||||
session_id: &String,
|
||||
) {
|
||||
if state
|
||||
.sessions
|
||||
.sessions
|
||||
.get(session_id)
|
||||
.and_then(Option::as_ref)
|
||||
== Some(resource)
|
||||
{
|
||||
state.detach_session(session_id, false);
|
||||
state.sessions.sessions.insert(session_id.clone(), None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<XdgToplevelSessionV1, ()> for Application {
|
||||
fn request(
|
||||
state: &mut Self,
|
||||
_client: &Client,
|
||||
resource: &XdgToplevelSessionV1,
|
||||
request: xdg_toplevel_session_v1::Request,
|
||||
_data: &(),
|
||||
_dh: &DisplayHandle,
|
||||
_data_init: &mut DataInit<'_, Self>,
|
||||
) {
|
||||
match request {
|
||||
xdg_toplevel_session_v1::Request::Destroy => {
|
||||
for w in state.sessions.toplevels.values_mut() {
|
||||
if w.restore_resource.as_ref() == Some(resource) {
|
||||
w.restore_resource = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
xdg_toplevel_session_v1::Request::Rename { name } => {
|
||||
let entry = state
|
||||
.sessions
|
||||
.toplevels
|
||||
.iter()
|
||||
.find(|(_, w)| w.restore_resource.as_ref() == Some(resource))
|
||||
.map(|(id, w)| (id.clone(), w.session_id.clone(), w.key.clone()));
|
||||
let Some((id, session_id, old_key)) = entry else {
|
||||
return;
|
||||
};
|
||||
let new_key = session_key(&session_id, &name);
|
||||
if old_key == new_key {
|
||||
return;
|
||||
}
|
||||
if state.sessions.stored_keys.contains(&new_key)
|
||||
|| state
|
||||
.sessions
|
||||
.toplevels
|
||||
.values()
|
||||
.any(|w| w.session_id == session_id && w.key == new_key)
|
||||
{
|
||||
if let Some(Some(owner)) = state.sessions.sessions.get(&session_id) {
|
||||
owner.post_error(
|
||||
xdg_session_v1::Error::NameInUse,
|
||||
"toplevel name already in use",
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(w) = state.sessions.toplevels.get_mut(&id) {
|
||||
w.key = new_key.clone();
|
||||
}
|
||||
if state.sessions.stored_keys.remove(&old_key) {
|
||||
state.sessions.stored_keys.insert(new_key.clone());
|
||||
}
|
||||
state
|
||||
.wayvr_tasks
|
||||
.send(WayVRTask::RenameWindowState(old_key, new_key));
|
||||
if let Some(surface) = state
|
||||
.xdg_shell
|
||||
.toplevel_surfaces()
|
||||
.iter()
|
||||
.find(|s| s.xdg_toplevel().id() == id)
|
||||
.cloned()
|
||||
{
|
||||
state
|
||||
.wayvr_tasks
|
||||
.send(WayVRTask::WindowIdentityChanged(surface));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
state: &mut Self,
|
||||
_client: smithay::reexports::wayland_server::backend::ClientId,
|
||||
resource: &XdgToplevelSessionV1,
|
||||
_data: &(),
|
||||
) {
|
||||
for w in state.sessions.toplevels.values_mut() {
|
||||
if w.restore_resource.as_ref() == Some(resource) {
|
||||
w.restore_resource = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#[allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)]
|
||||
#[allow(non_upper_case_globals, non_snake_case, unused_imports)]
|
||||
#[allow(clippy::all)]
|
||||
pub mod server {
|
||||
use smithay::reexports::wayland_server;
|
||||
use wayland_protocols::xdg::shell::server::xdg_toplevel;
|
||||
use wayland_server::protocol::*;
|
||||
|
||||
pub mod __interfaces {
|
||||
use super::wayland_server;
|
||||
use wayland_protocols::xdg::shell::server::__interfaces::{
|
||||
XDG_TOPLEVEL_INTERFACE, xdg_toplevel_interface,
|
||||
};
|
||||
use wayland_server::backend as wayland_backend;
|
||||
use wayland_server::protocol::__interfaces::*;
|
||||
wayland_scanner::generate_interfaces!("protocols/xdg-session-management-v1.xml");
|
||||
}
|
||||
use self::__interfaces::{
|
||||
XDG_SESSION_MANAGER_V1_INTERFACE, XDG_SESSION_V1_INTERFACE,
|
||||
XDG_TOPLEVEL_SESSION_V1_INTERFACE,
|
||||
};
|
||||
wayland_scanner::generate_server_code!("protocols/xdg-session-management-v1.xml");
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
use glam::DVec2;
|
||||
use slotmap::{DenseSlotMap, new_key_type};
|
||||
@@ -24,6 +24,10 @@ pub struct Window {
|
||||
pub visible: bool,
|
||||
pub toplevel: Rc<ToplevelSurface>,
|
||||
pub process: process::ProcessHandle,
|
||||
pub app_id: Option<Arc<str>>,
|
||||
pub parent: Option<WindowHandle>,
|
||||
pub name: Option<Arc<str>>,
|
||||
pub restore_on_spawn: bool,
|
||||
|
||||
pub pending_configure: Option<PendingConfigure>,
|
||||
}
|
||||
@@ -35,6 +39,10 @@ impl Window {
|
||||
bounds: Size<i32, Logical>,
|
||||
min_size: Size<i32, Logical>,
|
||||
max_size: Size<i32, Logical>,
|
||||
app_id: Option<Arc<str>>,
|
||||
parent: Option<WindowHandle>,
|
||||
name: Option<Arc<str>>,
|
||||
restore_on_spawn: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
bounds,
|
||||
@@ -45,6 +53,10 @@ impl Window {
|
||||
visible: true,
|
||||
toplevel,
|
||||
process,
|
||||
app_id,
|
||||
parent,
|
||||
name,
|
||||
restore_on_spawn,
|
||||
pending_configure: None,
|
||||
}
|
||||
}
|
||||
@@ -148,6 +160,10 @@ pub struct CreateWindowParams {
|
||||
pub max_size: Size<i32, Logical>,
|
||||
pub size_x: u32,
|
||||
pub size_y: u32,
|
||||
pub app_id: Option<Arc<str>>,
|
||||
pub parent: Option<WindowHandle>,
|
||||
pub name: Option<Arc<str>>,
|
||||
pub restore_on_spawn: bool,
|
||||
}
|
||||
|
||||
impl WindowManager {
|
||||
@@ -175,6 +191,10 @@ impl WindowManager {
|
||||
par.bounds,
|
||||
par.min_size,
|
||||
par.max_size,
|
||||
par.app_id,
|
||||
par.parent,
|
||||
par.name,
|
||||
par.restore_on_spawn,
|
||||
);
|
||||
window.remember_committed_size(Size::new(par.size_x as i32, par.size_y as i32), None);
|
||||
self.windows.insert(window)
|
||||
@@ -199,4 +219,8 @@ impl WindowHandle {
|
||||
user: self.0.as_ffi(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn transient_name(self) -> Arc<str> {
|
||||
format!("wayvr/volatile/{}", self.as_packet().user).into()
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -9,9 +9,9 @@ use wayvr_ipc::packet_client::WvrProcessLaunchParams;
|
||||
use wlx_common::{
|
||||
astr_containers::AStrMap,
|
||||
config::{
|
||||
AltModifier, CaptureMethod, ChromaKeyParams, DefaultPositioning, GeneralConfig,
|
||||
HandsfreeAltTab, HandsfreePointer, InputCaptureMethod, InputEmulationMethod, PinnedApp,
|
||||
SerializedWindowSet,
|
||||
AltModifier, CONFIG_VERSION, CaptureMethod, ChromaKeyParams, DefaultPositioning,
|
||||
GeneralConfig, HandsfreeAltTab, HandsfreePointer, InputCaptureMethod, InputEmulationMethod,
|
||||
PinnedApp, SerializedWindowSet,
|
||||
},
|
||||
config_io,
|
||||
locale::Language,
|
||||
@@ -200,6 +200,7 @@ pub struct AutoSettings {
|
||||
pub default_opacity: f32,
|
||||
pub default_positioning: DefaultPositioning,
|
||||
pub middle_grabs_single: bool,
|
||||
pub config_version: u32,
|
||||
}
|
||||
|
||||
fn get_settings_path() -> PathBuf {
|
||||
@@ -277,6 +278,7 @@ pub fn save_settings(config: &GeneralConfig) -> anyhow::Result<()> {
|
||||
default_opacity: config.default_opacity,
|
||||
default_positioning: config.default_positioning,
|
||||
middle_grabs_single: config.middle_grabs_single,
|
||||
config_version: CONFIG_VERSION,
|
||||
};
|
||||
|
||||
let json = serde_json::to_string_pretty(&conf).unwrap(); // want panic
|
||||
@@ -294,6 +296,7 @@ pub struct AutoState {
|
||||
pub spawn_overlays: Vec<Arc<str>>,
|
||||
pub last_set: u32,
|
||||
pub attribs: AStrMap<Vec<BackendAttribValue>>,
|
||||
pub state_version: u32,
|
||||
}
|
||||
|
||||
fn get_state_path() -> PathBuf {
|
||||
@@ -308,6 +311,7 @@ pub fn save_state(config: &GeneralConfig) -> anyhow::Result<()> {
|
||||
last_set: config.last_set,
|
||||
spawn_overlays: config.spawn_overlays.clone(),
|
||||
attribs: config.attribs.clone(),
|
||||
state_version: CONFIG_VERSION,
|
||||
};
|
||||
|
||||
let json = serde_json::to_string_pretty(&conf).unwrap(); // want panic
|
||||
|
||||
@@ -116,7 +116,7 @@ impl OverlayList {
|
||||
}
|
||||
|
||||
params.insert_rc("idx", i.to_string().into());
|
||||
params.insert("name", meta.name.as_ref());
|
||||
params.insert("name", meta.title.as_deref().unwrap_or(&meta.name));
|
||||
parser_state
|
||||
.instantiate_template(doc_params, template, layout, root, params)?;
|
||||
let overlay_button = parser_state
|
||||
|
||||
@@ -6,10 +6,7 @@ use wayvr_ipc::packet_server::PacketServer;
|
||||
use wlx_common::config::HandsfreePointer;
|
||||
|
||||
use crate::{
|
||||
backend::{
|
||||
self,
|
||||
task::{InputTask, OverlayTask, TaskType, ToggleMode},
|
||||
},
|
||||
backend::task::{InputTask, OverlayTask, TaskType, ToggleMode},
|
||||
ipc::{signal::WayVRSignal, window_attrib, window_state},
|
||||
state::AppState,
|
||||
windowing::{OverlaySelector, manager::OverlayWindowManager},
|
||||
|
||||
+38
-19
@@ -180,43 +180,37 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
setup_signal_hooks()?;
|
||||
|
||||
let mut used_backend = None;
|
||||
auto_run(args, &mut used_backend);
|
||||
auto_run(&args, &mut used_backend);
|
||||
|
||||
if RESTART.load(Ordering::Relaxed) {
|
||||
log::warn!("Restarting...");
|
||||
let exe = std::env::current_exe()?;
|
||||
let mut args = vec!["--replace", "--show"];
|
||||
|
||||
match used_backend {
|
||||
Some(XrBackend::OpenXR) => args.push("--openxr"),
|
||||
Some(XrBackend::OpenVR) => args.push("--openvr"),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let _ = Command::new(exe).args(args).spawn();
|
||||
let _ = Command::new(exe)
|
||||
.args(restart_args(&args, used_backend))
|
||||
.spawn();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(unused_mut, clippy::similar_names)]
|
||||
fn auto_run(args: Args, used_backend: &mut Option<XrBackend>) {
|
||||
fn auto_run(args: &Args, out_backend: &mut Option<XrBackend>) {
|
||||
let mut tried_xr = false;
|
||||
let mut tried_vr = false;
|
||||
|
||||
loop {
|
||||
#[cfg(feature = "openxr")]
|
||||
if !args_get_openvr(&args) {
|
||||
if !args_get_openvr(args) {
|
||||
use crate::backend::{BackendError, openxr::openxr_run};
|
||||
tried_xr = true;
|
||||
match openxr_run(&args, init_run_params(args.no_audio)) {
|
||||
match openxr_run(args, init_run_params(args.no_audio)) {
|
||||
Ok(()) => {
|
||||
used_backend.replace(XrBackend::OpenXR);
|
||||
out_backend.replace(XrBackend::OpenXR);
|
||||
return;
|
||||
}
|
||||
Err(BackendError::NotSupported) => (),
|
||||
Err(e) => {
|
||||
used_backend.replace(XrBackend::OpenXR);
|
||||
out_backend.replace(XrBackend::OpenXR);
|
||||
log::error!("{e:?}");
|
||||
return;
|
||||
}
|
||||
@@ -224,17 +218,17 @@ fn auto_run(args: Args, used_backend: &mut Option<XrBackend>) {
|
||||
}
|
||||
|
||||
#[cfg(feature = "openvr")]
|
||||
if !args_get_openxr(&args) {
|
||||
if !args_get_openxr(args) {
|
||||
use crate::backend::{BackendError, openvr::openvr_run};
|
||||
tried_vr = true;
|
||||
match openvr_run(&args, init_run_params(args.no_audio)) {
|
||||
match openvr_run(args, init_run_params(args.no_audio)) {
|
||||
Ok(()) => {
|
||||
used_backend.replace(XrBackend::OpenVR);
|
||||
out_backend.replace(XrBackend::OpenVR);
|
||||
return;
|
||||
}
|
||||
Err(BackendError::NotSupported) => (),
|
||||
Err(e) => {
|
||||
used_backend.replace(XrBackend::OpenVR);
|
||||
out_backend.replace(XrBackend::OpenVR);
|
||||
log::error!("{e:?}");
|
||||
return;
|
||||
}
|
||||
@@ -303,6 +297,31 @@ const fn args_get_openxr(args: &Args) -> bool {
|
||||
ret
|
||||
}
|
||||
|
||||
fn restart_args(args: &Args, backend: Option<XrBackend>) -> Vec<&'static str> {
|
||||
let mut flags = vec!["--replace", "--show"];
|
||||
|
||||
match backend {
|
||||
Some(XrBackend::OpenXR) => flags.push("--openxr"),
|
||||
Some(XrBackend::OpenVR) => flags.push("--openvr"),
|
||||
None => {}
|
||||
}
|
||||
|
||||
if args.headless {
|
||||
flags.push("--headless");
|
||||
}
|
||||
if args.no_autostart {
|
||||
flags.push("--no-autostart");
|
||||
}
|
||||
if args.install {
|
||||
flags.push("--install");
|
||||
}
|
||||
if args.no_audio {
|
||||
flags.push("--no-audio");
|
||||
}
|
||||
|
||||
flags
|
||||
}
|
||||
|
||||
#[allow(clippy::single_match_else)]
|
||||
fn setup_signal_hooks() -> anyhow::Result<()> {
|
||||
let mut signals = Signals::new([SIGINT, SIGTERM, SIGUSR1])?;
|
||||
|
||||
@@ -147,6 +147,7 @@ impl ScreenPipeline {
|
||||
|
||||
/// Select normalized rect from backing image
|
||||
pub fn set_source_uv(&mut self, source_uv: [f32; 4]) {
|
||||
#[allow(clippy::float_cmp)]
|
||||
if self.source_uv != source_uv {
|
||||
self.source_uv = source_uv;
|
||||
self.pass.clear();
|
||||
|
||||
+25
-13
@@ -70,6 +70,7 @@ use crate::{
|
||||
#[derive(Clone)]
|
||||
pub enum WvrCommand {
|
||||
ReloadTitle,
|
||||
SetIcon(Arc<str>),
|
||||
CloseWindow,
|
||||
KillProcess(KillSignal),
|
||||
}
|
||||
@@ -88,6 +89,9 @@ const BLEND_WAYLAND_ALPHA: AttachmentBlend = AttachmentBlend {
|
||||
|
||||
pub fn create_wl_window_overlay(
|
||||
name: Arc<str>,
|
||||
title: Arc<str>,
|
||||
persistent: bool,
|
||||
restore_on_spawn: bool,
|
||||
app: &mut AppState,
|
||||
window: wayvr::window::WindowHandle,
|
||||
icon: Arc<str>,
|
||||
@@ -109,7 +113,10 @@ pub fn create_wl_window_overlay(
|
||||
.is_some_and(Window::resizable);
|
||||
|
||||
Ok(OverlayWindowConfig {
|
||||
name: name.clone(),
|
||||
name,
|
||||
title: Some(title.clone()),
|
||||
persistent,
|
||||
restore_on_spawn,
|
||||
default_state: OverlayWindowState {
|
||||
grabbable: true,
|
||||
interactable: true,
|
||||
@@ -131,7 +138,7 @@ pub fn create_wl_window_overlay(
|
||||
category: OverlayCategory::WayVR,
|
||||
show_on_spawn: true,
|
||||
..OverlayWindowConfig::from_backend(Box::new(WvrWindowBackend::new(
|
||||
name,
|
||||
title,
|
||||
app,
|
||||
window,
|
||||
icon,
|
||||
@@ -142,7 +149,7 @@ pub fn create_wl_window_overlay(
|
||||
}
|
||||
|
||||
pub struct WvrWindowBackend {
|
||||
name: Arc<str>,
|
||||
title: Arc<str>,
|
||||
icon: Arc<str>,
|
||||
pipeline: Option<ScreenPipeline>,
|
||||
subsurface_pipeline_opaque: Arc<WGfxPipeline<Vert2Uv>>,
|
||||
@@ -176,7 +183,7 @@ pub struct WvrWindowBackend {
|
||||
|
||||
impl WvrWindowBackend {
|
||||
fn new(
|
||||
name: Arc<str>,
|
||||
title: Arc<str>,
|
||||
app: &mut AppState,
|
||||
window: wayvr::window::WindowHandle,
|
||||
icon: Arc<str>,
|
||||
@@ -243,7 +250,7 @@ impl WvrWindowBackend {
|
||||
NewGuiPanelParams {
|
||||
resize_to_parent: true,
|
||||
on_custom_attrib: Some(on_custom_attrib),
|
||||
extra_vars: [("title".into(), name.as_ref().into())].into(),
|
||||
extra_vars: [("title".into(), title.as_ref().into())].into(),
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
@@ -251,7 +258,7 @@ impl WvrWindowBackend {
|
||||
panel.update_layout(app)?;
|
||||
|
||||
Ok(Self {
|
||||
name,
|
||||
title,
|
||||
icon,
|
||||
pipeline: None,
|
||||
window,
|
||||
@@ -390,6 +397,7 @@ impl WvrWindowBackend {
|
||||
}
|
||||
|
||||
fn update_title(&mut self, new_title: Rc<str>) {
|
||||
self.title = new_title.as_ref().into();
|
||||
let mut common = CallbackDataCommon {
|
||||
state: &self.panel.layout.state,
|
||||
alterables: &mut self.panel.layout.alterables,
|
||||
@@ -568,7 +576,7 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
else {
|
||||
log::debug!(
|
||||
"{:?}: WayVR overlay without matching window entry",
|
||||
self.name
|
||||
self.title
|
||||
);
|
||||
return Ok(ShouldRender::Unable);
|
||||
};
|
||||
@@ -653,10 +661,11 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
let source_uv = surf.source_uv(states);
|
||||
let mut xdg_state = states.cached_state.get::<SurfaceCachedState>();
|
||||
let window_geometry = xdg_state.current().geometry;
|
||||
drop(xdg_state);
|
||||
Some((surf, surface_size, source_uv, window_geometry))
|
||||
})
|
||||
else {
|
||||
log::trace!("{}: no buffer for wl_surface", self.name);
|
||||
log::trace!("{}: no buffer for wl_surface", self.title);
|
||||
return Ok(ShouldRender::Unable);
|
||||
};
|
||||
|
||||
@@ -691,9 +700,9 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
}
|
||||
|
||||
let inner_extent = meta.extent;
|
||||
let committed_window_extent = window_geometry
|
||||
.map(|geometry| [geometry.size.w.max(1) as u32, geometry.size.h.max(1) as u32])
|
||||
.unwrap_or(inner_extent);
|
||||
let committed_window_extent = window_geometry.map_or(inner_extent, |geometry| {
|
||||
[geometry.size.w.max(1) as u32, geometry.size.h.max(1) as u32]
|
||||
});
|
||||
self.sync_committed_toplevel_size(app, committed_window_extent);
|
||||
|
||||
if self.server_side_decorations {
|
||||
@@ -771,7 +780,7 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
{
|
||||
log::trace!(
|
||||
"{}: new {} image",
|
||||
self.name,
|
||||
self.title,
|
||||
if surf.dmabuf { "DMA-buf" } else { "SHM" }
|
||||
);
|
||||
self.cur_image = Some(surf.image);
|
||||
@@ -857,6 +866,9 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
let wvr_server = app.wvr_server.as_mut().unwrap(); //never None
|
||||
wvr_server.overlay_added(oid, self.window);
|
||||
}
|
||||
OverlayEventData::WvrCommand(WvrCommand::SetIcon(icon)) => {
|
||||
self.icon = icon;
|
||||
}
|
||||
OverlayEventData::WvrCommand(WvrCommand::ReloadTitle) => {
|
||||
let wvr_server = app.wvr_server.as_mut().unwrap(); //never None
|
||||
if let Some(window) = wvr_server.wm.windows.get(self.window) {
|
||||
@@ -1161,7 +1173,7 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
match value {
|
||||
BackendAttribValue::Stereo(new) => {
|
||||
if let Some(stereo) = self.stereo.as_mut() {
|
||||
log::debug!("{}: stereo: {stereo:?} → {new:?}", self.name);
|
||||
log::debug!("{}: stereo: {stereo:?} → {new:?}", self.title);
|
||||
*stereo = new;
|
||||
if let Some(meta) = self.meta {
|
||||
let _ = self.apply_extent(app, &meta);
|
||||
|
||||
@@ -223,26 +223,22 @@
|
||||
},
|
||||
{
|
||||
"inputs" : {
|
||||
"scroll" : {
|
||||
"position" : {
|
||||
"output" : "/actions/default/in/scroll"
|
||||
}
|
||||
},
|
||||
"mode" : "scroll",
|
||||
"parameters" : {
|
||||
"scroll_mode" : "smooth"
|
||||
},
|
||||
"mode" : "joystick",
|
||||
"parameters" : {},
|
||||
"path" : "/user/hand/left/input/thumbstick"
|
||||
},
|
||||
{
|
||||
"inputs" : {
|
||||
"scroll" : {
|
||||
"position" : {
|
||||
"output" : "/actions/default/in/scroll"
|
||||
}
|
||||
},
|
||||
"mode" : "scroll",
|
||||
"parameters" : {
|
||||
"scroll_mode" : "smooth"
|
||||
},
|
||||
"mode" : "joystick",
|
||||
"parameters" : {},
|
||||
"path" : "/user/hand/right/input/thumbstick"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -141,26 +141,22 @@
|
||||
},
|
||||
{
|
||||
"inputs" : {
|
||||
"scroll" : {
|
||||
"position" : {
|
||||
"output" : "/actions/default/in/scroll"
|
||||
}
|
||||
},
|
||||
"mode" : "scroll",
|
||||
"parameters" : {
|
||||
"scroll_mode" : "smooth"
|
||||
},
|
||||
"mode" : "joystick",
|
||||
"parameters" : {},
|
||||
"path" : "/user/hand/left/input/thumbstick"
|
||||
},
|
||||
{
|
||||
"inputs" : {
|
||||
"scroll" : {
|
||||
"position" : {
|
||||
"output" : "/actions/default/in/scroll"
|
||||
}
|
||||
},
|
||||
"mode" : "scroll",
|
||||
"parameters" : {
|
||||
"scroll_mode" : "smooth"
|
||||
},
|
||||
"mode" : "joystick",
|
||||
"parameters" : {},
|
||||
"path" : "/user/hand/right/input/thumbstick"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -107,26 +107,22 @@
|
||||
},
|
||||
{
|
||||
"inputs" : {
|
||||
"scroll" : {
|
||||
"position" : {
|
||||
"output" : "/actions/default/in/scroll"
|
||||
}
|
||||
},
|
||||
"mode" : "scroll",
|
||||
"parameters" : {
|
||||
"scroll_mode" : "smooth"
|
||||
},
|
||||
"mode" : "joystick",
|
||||
"parameters" : {},
|
||||
"path" : "/user/hand/left/input/joystick"
|
||||
},
|
||||
{
|
||||
"inputs" : {
|
||||
"scroll" : {
|
||||
"position" : {
|
||||
"output" : "/actions/default/in/scroll"
|
||||
}
|
||||
},
|
||||
"mode" : "scroll",
|
||||
"parameters" : {
|
||||
"scroll_mode" : "smooth"
|
||||
},
|
||||
"mode" : "joystick",
|
||||
"parameters" : {},
|
||||
"path" : "/user/hand/right/input/joystick"
|
||||
}
|
||||
]
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ impl AppState {
|
||||
let wvr_signals = SyncEventQueue::new();
|
||||
|
||||
let wvr_server = {
|
||||
let mut maybe_wvr = WvrServerState::new(gfx.clone(), &gfx_extras)
|
||||
let mut maybe_wvr = WvrServerState::new(gfx.clone(), &gfx_extras, &session.config)
|
||||
.log_err("Could not initialize WayVR Server")
|
||||
.ok();
|
||||
if let Some(wvr) = maybe_wvr.as_mut() {
|
||||
|
||||
@@ -127,6 +127,7 @@ macro_rules! attrib_value {
|
||||
pub struct OverlayMeta {
|
||||
pub id: OverlayID,
|
||||
pub name: Arc<str>,
|
||||
pub title: Option<Arc<str>>,
|
||||
pub category: OverlayCategory,
|
||||
pub visible: bool,
|
||||
pub icon: Option<Arc<str>>,
|
||||
|
||||
+309
-44
@@ -1,6 +1,7 @@
|
||||
use std::{
|
||||
collections::{HashMap, VecDeque},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
sync::atomic::Ordering,
|
||||
};
|
||||
|
||||
@@ -9,9 +10,11 @@ use glam::{Affine3A, Vec3, Vec3A};
|
||||
use slotmap::{Key, SecondaryMap, SlotMap};
|
||||
use wgui::{i18n::Translation, log::LogErr};
|
||||
use wlx_common::{
|
||||
DesktopBackend,
|
||||
astr_containers::{AStrMap, AStrMapExt},
|
||||
config::SerializedWindowSet,
|
||||
overlays::{BackendAttrib, BackendAttribValue, ToastTopic},
|
||||
windowing::{OverlayWindowState, Positioning},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -84,6 +87,8 @@ where
|
||||
};
|
||||
|
||||
if headless {
|
||||
app.screens.clear();
|
||||
app.feats.desktop_backend = DesktopBackend::Headless;
|
||||
log::info!("Running in headless mode; keyboard will be en-US");
|
||||
} else {
|
||||
// create one window set for each screen.
|
||||
@@ -92,12 +97,12 @@ where
|
||||
match create_screens(app) {
|
||||
Ok((data, backend)) => {
|
||||
app.feats.desktop_backend = backend;
|
||||
let last_idx = data.screens.len() - 1;
|
||||
let screen_count = data.screens.len();
|
||||
for (idx, (meta, mut config)) in data.screens.into_iter().enumerate() {
|
||||
config.show_on_spawn = true;
|
||||
me.add(OverlayWindowData::from_config(config), app);
|
||||
|
||||
if idx < last_idx {
|
||||
if idx + 1 < screen_count {
|
||||
me.sets.push(OverlayWindowSet::default());
|
||||
me.switch_to_set(app, Some(me.current_set.unwrap() + 1), false);
|
||||
}
|
||||
@@ -243,6 +248,7 @@ where
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let key = o.config.name.clone();
|
||||
let parent_set = if o.config.global {
|
||||
&mut self.global_set
|
||||
} else {
|
||||
@@ -254,8 +260,8 @@ where
|
||||
|
||||
parent_set
|
||||
.hidden_overlays
|
||||
.arc_set(o.config.name.clone(), active_state);
|
||||
} else if let Some(state) = parent_set.hidden_overlays.arc_rm(&o.config.name) {
|
||||
.arc_set(key.clone(), active_state);
|
||||
} else if let Some(state) = parent_set.hidden_overlays.arc_rm(&key) {
|
||||
let o = &mut self.overlays[id];
|
||||
log::debug!("{}: toggle on", o.config.name);
|
||||
o.config.dirty = true;
|
||||
@@ -387,9 +393,23 @@ where
|
||||
OverlayTask::Modify(sel, f) => {
|
||||
if let Some(o) = self.mut_by_selector(&sel) {
|
||||
let was_visible = o.config.is_active();
|
||||
let old_title = o.config.title.clone();
|
||||
let old_icon = match o.config.backend.get_attrib(BackendAttrib::Icon) {
|
||||
Some(BackendAttribValue::Icon(icon)) => Some(icon),
|
||||
_ => None,
|
||||
};
|
||||
f(app, &mut o.config);
|
||||
let new_icon = match o.config.backend.get_attrib(BackendAttrib::Icon) {
|
||||
Some(BackendAttribValue::Icon(icon)) => Some(icon),
|
||||
_ => None,
|
||||
};
|
||||
let title_changed = old_title != o.config.title || old_icon != new_icon;
|
||||
let visibility_changed = was_visible != o.config.is_active();
|
||||
|
||||
if was_visible != o.config.is_active() {
|
||||
if title_changed {
|
||||
self.overlays_changed(app)?;
|
||||
}
|
||||
if visibility_changed {
|
||||
let _ = self.visible_overlays_changed(app);
|
||||
}
|
||||
} else {
|
||||
@@ -400,65 +420,52 @@ where
|
||||
self.spawn_overlay(app, sel, spawn_pos, f);
|
||||
}
|
||||
OverlayTask::Drop(sel) => {
|
||||
let (id, name) = match &sel {
|
||||
OverlaySelector::Id(id) => {
|
||||
let id = *id;
|
||||
let name = self.overlays.get(id).map(|o| o.config.name.clone());
|
||||
(Some(id), name)
|
||||
}
|
||||
OverlaySelector::Name(name) => {
|
||||
let id = self.lookup(name);
|
||||
(id, Some(name.clone()))
|
||||
}
|
||||
_ => (None, None),
|
||||
};
|
||||
|
||||
let id = self.id_by_selector(&sel);
|
||||
if let Some(o) = self.mut_by_selector(&sel)
|
||||
&& o.birthframe < FRAME_COUNTER.load(Ordering::Relaxed)
|
||||
&& let Some(o) = self.remove_by_selector(&sel, app)
|
||||
{
|
||||
log::debug!("Dropping overlay {}", o.config.name);
|
||||
if let (Some(id), Some(name)) = (id, name) {
|
||||
self.remove_saved_state(id, &name);
|
||||
if let Some(id) = id {
|
||||
self.on_overlay_dropped(id, &o);
|
||||
}
|
||||
self.dropped_overlays.push_back(o);
|
||||
}
|
||||
}
|
||||
OverlayTask::DropImmediate(sel) => {
|
||||
let (id, name) = match &sel {
|
||||
OverlaySelector::Id(id) => {
|
||||
let id = *id;
|
||||
let name = self.overlays.get(id).map(|o| o.config.name.clone());
|
||||
(Some(id), name)
|
||||
}
|
||||
OverlaySelector::Name(name) => {
|
||||
let id = self.lookup(name);
|
||||
(id, Some(name.clone()))
|
||||
}
|
||||
_ => (None, None),
|
||||
};
|
||||
|
||||
let id = self.id_by_selector(&sel);
|
||||
if let Some(o) = self.remove_by_selector(&sel, app) {
|
||||
log::debug!("Dropping overlay {} immediately", o.config.name);
|
||||
if let (Some(id), Some(name)) = (id, name) {
|
||||
self.remove_saved_state(id, &name);
|
||||
if let Some(id) = id {
|
||||
self.on_overlay_dropped(id, &o);
|
||||
}
|
||||
self.dropped_overlays.push_back(o);
|
||||
}
|
||||
}
|
||||
OverlayTask::SetOverlayName(id, name, persistent, restore_on_spawn) => {
|
||||
self.set_window_name(app, id, name, persistent, restore_on_spawn);
|
||||
}
|
||||
OverlayTask::ForgetWindowState(id, key) => {
|
||||
self.freeze_window_state(id, &key);
|
||||
}
|
||||
OverlayTask::RenameWindowState(old, new) => {
|
||||
self.rename_window_state(app, &old, &new);
|
||||
}
|
||||
OverlayTask::ClearWindowState(key) => {
|
||||
self.clear_window_state(app, &key);
|
||||
}
|
||||
OverlayTask::DropExpired(id) => {
|
||||
let should_drop = self
|
||||
.overlays
|
||||
.get(id)
|
||||
.and_then(|overlay| overlay.config.lifetime.as_ref())
|
||||
.is_some_and(|lifetime| lifetime.is_expired());
|
||||
.is_some_and(super::window::OverlayLifetime::is_expired);
|
||||
|
||||
if should_drop
|
||||
&& let Some(o) = self.remove_by_selector(&OverlaySelector::Id(id), app)
|
||||
{
|
||||
log::debug!("Dropping expired overlay {}", o.config.name);
|
||||
let name = o.config.name.clone();
|
||||
self.remove_saved_state(id, &name);
|
||||
self.on_overlay_dropped(id, &o);
|
||||
self.dropped_overlays.push_back(o);
|
||||
}
|
||||
}
|
||||
@@ -532,14 +539,195 @@ impl<T> OverlayWindowManager<T> {
|
||||
self.dropped_overlays.pop_front()
|
||||
}
|
||||
|
||||
fn remove_saved_state(&mut self, id: OverlayID, name: &str) {
|
||||
fn on_overlay_dropped(&mut self, id: OverlayID, overlay: &OverlayWindowData<T>) {
|
||||
let name = &overlay.config.name;
|
||||
let remember_position =
|
||||
overlay.config.category == OverlayCategory::WayVR && overlay.config.can_persist();
|
||||
|
||||
// keep removed overlays by name
|
||||
for set in &mut self.sets {
|
||||
let state = set.overlays.remove(id);
|
||||
let hidden_state = set.hidden_overlays.arc_rm(name);
|
||||
if remember_position {
|
||||
if let Some(state) = state.or(hidden_state) {
|
||||
set.inactive_overlays.arc_set(name.clone(), state);
|
||||
}
|
||||
} else {
|
||||
set.inactive_overlays.arc_rm(name);
|
||||
}
|
||||
}
|
||||
|
||||
let state = self.global_set.overlays.remove(id);
|
||||
let hidden_state = self.global_set.hidden_overlays.arc_rm(name);
|
||||
if remember_position {
|
||||
if let Some(state) = state.or(hidden_state) {
|
||||
self.global_set
|
||||
.inactive_overlays
|
||||
.arc_set(name.clone(), state);
|
||||
}
|
||||
|
||||
if let Some(state) = &overlay.config.active_state {
|
||||
let set = if overlay.config.global {
|
||||
&mut self.global_set
|
||||
} else {
|
||||
&mut self.sets[self.current_set.unwrap_or(self.restore_set)]
|
||||
};
|
||||
set.inactive_overlays.arc_set(name.clone(), state.clone());
|
||||
}
|
||||
} else {
|
||||
// transient overlays (toasts, etc)
|
||||
self.global_set.inactive_overlays.arc_rm(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the name of an existing window, restoring the state associated with the new name
|
||||
fn set_window_name(
|
||||
&mut self,
|
||||
app: &mut AppState,
|
||||
id: OverlayID,
|
||||
name: Arc<str>,
|
||||
persistent: bool,
|
||||
restore_on_spawn: bool,
|
||||
) {
|
||||
let Some(overlay) = self.overlays.get(id) else {
|
||||
return;
|
||||
};
|
||||
if overlay.config.category != OverlayCategory::WayVR
|
||||
|| (overlay.config.name == name
|
||||
&& overlay.config.persistent == persistent
|
||||
&& overlay.config.restore_on_spawn == restore_on_spawn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if self
|
||||
.overlays
|
||||
.iter()
|
||||
.any(|(other_id, other)| other_id != id && other.config.name == name)
|
||||
{
|
||||
log::debug!("Ignoring duplicate WayVR window name {name}");
|
||||
return;
|
||||
}
|
||||
|
||||
let old_name = overlay.config.name.clone();
|
||||
let global = overlay.config.global;
|
||||
if old_name != name {
|
||||
for set in &mut self.sets {
|
||||
if let Some(state) = set.hidden_overlays.arc_rm(&old_name) {
|
||||
set.hidden_overlays.arc_set(name.clone(), state);
|
||||
}
|
||||
}
|
||||
if let Some(state) = self.global_set.hidden_overlays.arc_rm(&old_name) {
|
||||
self.global_set.hidden_overlays.arc_set(name.clone(), state);
|
||||
}
|
||||
}
|
||||
{
|
||||
let config = &mut self.overlays[id].config;
|
||||
config.name = name.clone();
|
||||
config.persistent = persistent;
|
||||
config.restore_on_spawn = restore_on_spawn;
|
||||
}
|
||||
if let Err(err) = self.overlays_changed(app) {
|
||||
log::error!("Unable to update overlay name: {err:?}");
|
||||
}
|
||||
if !persistent || !restore_on_spawn {
|
||||
return;
|
||||
}
|
||||
|
||||
// apply to all saved states
|
||||
if global {
|
||||
if let Some(state) = self.global_set.inactive_overlays.arc_rm(&name) {
|
||||
let o = &mut self.overlays[id];
|
||||
o.config.active_state = Some(state);
|
||||
o.config.reset(app, false);
|
||||
o.config.dirty = true;
|
||||
}
|
||||
} else {
|
||||
for (i, set) in self.sets.iter_mut().enumerate() {
|
||||
let Some(state) = set.inactive_overlays.arc_rm(&name) else {
|
||||
continue;
|
||||
};
|
||||
if self.current_set == Some(i) {
|
||||
let o = &mut self.overlays[id];
|
||||
o.config.active_state = Some(state);
|
||||
o.config.reset(app, false);
|
||||
o.config.dirty = true;
|
||||
} else {
|
||||
set.overlays.insert(id, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn freeze_window_state(&mut self, id: OverlayID, name: &Arc<str>) {
|
||||
let Some(overlay) = self.overlays.get(id) else {
|
||||
return;
|
||||
};
|
||||
if let Some(state) = overlay.config.active_state.clone() {
|
||||
let set = if overlay.config.global {
|
||||
&mut self.global_set
|
||||
} else {
|
||||
&mut self.sets[self.current_set.unwrap_or(self.restore_set)]
|
||||
};
|
||||
set.inactive_overlays.arc_set(name.clone(), state);
|
||||
} else {
|
||||
for set in &mut self.sets {
|
||||
if let Some(state) = set.overlays.get(id) {
|
||||
set.inactive_overlays.arc_set(name.clone(), state.clone());
|
||||
}
|
||||
}
|
||||
if let Some(state) = self.global_set.overlays.get(id) {
|
||||
self.global_set
|
||||
.inactive_overlays
|
||||
.arc_set(name.clone(), state.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rename_window_state(&mut self, app: &mut AppState, old: &Arc<str>, new: &Arc<str>) {
|
||||
if old == new {
|
||||
return;
|
||||
}
|
||||
for set in &mut self.sets {
|
||||
if let Some(state) = set.inactive_overlays.arc_rm(old) {
|
||||
set.inactive_overlays.arc_set(new.clone(), state);
|
||||
}
|
||||
if let Some(state) = set.hidden_overlays.arc_rm(old) {
|
||||
set.hidden_overlays.arc_set(new.clone(), state);
|
||||
}
|
||||
}
|
||||
if let Some(state) = self.global_set.inactive_overlays.arc_rm(old) {
|
||||
self.global_set
|
||||
.inactive_overlays
|
||||
.arc_set(new.clone(), state);
|
||||
}
|
||||
if let Some(state) = self.global_set.hidden_overlays.arc_rm(old) {
|
||||
self.global_set.hidden_overlays.arc_set(new.clone(), state);
|
||||
}
|
||||
if let Some(attrs) = app.session.config.attribs.arc_rm(old) {
|
||||
app.session.config.attribs.arc_set(new.clone(), attrs);
|
||||
}
|
||||
for set in &mut app.session.config.sets {
|
||||
if let Some(state) = set.overlays.remove(old.as_ref()) {
|
||||
set.overlays.insert(new.clone(), state);
|
||||
}
|
||||
if let Some(state) = set.hidden_overlays.remove(old.as_ref()) {
|
||||
set.hidden_overlays.insert(new.clone(), state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn clear_window_state(&mut self, app: &mut AppState, name: &str) {
|
||||
for set in &mut self.sets {
|
||||
set.overlays.retain(|k, _| k != id);
|
||||
set.inactive_overlays.arc_rm(name);
|
||||
set.hidden_overlays.arc_rm(name);
|
||||
}
|
||||
self.global_set.inactive_overlays.arc_rm(name);
|
||||
self.global_set.hidden_overlays.arc_rm(name);
|
||||
app.session.config.attribs.arc_rm(name);
|
||||
for set in &mut app.session.config.sets {
|
||||
set.overlays.remove(name);
|
||||
set.hidden_overlays.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn persist_layout(&mut self, app: &mut AppState) {
|
||||
@@ -561,7 +749,11 @@ impl<T> OverlayWindowManager<T> {
|
||||
.overlays
|
||||
.iter()
|
||||
.filter_map(|(k, v)| {
|
||||
let n = self.overlays.get(k).map(|o| o.config.name.clone())?;
|
||||
let o = self.overlays.get(k)?;
|
||||
if !o.config.can_persist() {
|
||||
return None;
|
||||
}
|
||||
let n = o.config.name.clone();
|
||||
Some((n, v.clone()))
|
||||
})
|
||||
.collect();
|
||||
@@ -604,6 +796,7 @@ impl<T> OverlayWindowManager<T> {
|
||||
for o in self.overlays.values() {
|
||||
if o.config.global
|
||||
&& let Some(state) = &o.config.active_state
|
||||
&& o.config.can_persist()
|
||||
{
|
||||
global_overlays.insert(o.config.name.clone(), state.clone());
|
||||
}
|
||||
@@ -628,7 +821,7 @@ impl<T> OverlayWindowManager<T> {
|
||||
.filter_map(|a| o.config.backend.get_attrib(*a))
|
||||
.filter(|val| !val.is_default())
|
||||
.collect();
|
||||
if !attrs.is_empty() {
|
||||
if !attrs.is_empty() && o.config.can_persist() {
|
||||
app.session
|
||||
.config
|
||||
.attribs
|
||||
@@ -647,6 +840,29 @@ impl<T> OverlayWindowManager<T> {
|
||||
return;
|
||||
}
|
||||
|
||||
// floating transforms in older states are relative to hmd, not anchor
|
||||
if app.session.config.state_version < 1 {
|
||||
let clear_legacy_floating = |state: &mut OverlayWindowState| {
|
||||
if matches!(state.positioning, Positioning::Floating) {
|
||||
state.saved_transform = None;
|
||||
}
|
||||
};
|
||||
|
||||
for set in &mut app.session.config.sets {
|
||||
for state in set
|
||||
.overlays
|
||||
.values_mut()
|
||||
.chain(set.hidden_overlays.values_mut())
|
||||
{
|
||||
clear_legacy_floating(state);
|
||||
}
|
||||
}
|
||||
for state in app.session.config.global_set.values_mut() {
|
||||
clear_legacy_floating(state);
|
||||
}
|
||||
app.session.config.state_version = 1;
|
||||
}
|
||||
|
||||
// only safe to load when current_set is None
|
||||
if self.current_set.is_some() {
|
||||
self.switch_to_set(app, None, false);
|
||||
@@ -973,9 +1189,13 @@ impl<T> OverlayWindowManager<T> {
|
||||
overlay.config.name
|
||||
);
|
||||
overlay.config.name = format!("{}_2", overlay.config.name).into();
|
||||
if overlay.config.category == OverlayCategory::WayVR {
|
||||
overlay.config.persistent = false;
|
||||
}
|
||||
}
|
||||
|
||||
let name = overlay.config.name.clone();
|
||||
let restore = overlay.config.can_persist() && overlay.config.restore_on_spawn;
|
||||
let global = overlay.config.global;
|
||||
let internal = matches!(overlay.config.category, OverlayCategory::Internal);
|
||||
let show_on_spawn = overlay.config.show_on_spawn;
|
||||
@@ -985,6 +1205,14 @@ impl<T> OverlayWindowManager<T> {
|
||||
|
||||
if !global {
|
||||
for (i, set) in self.sets.iter_mut().enumerate() {
|
||||
if !restore {
|
||||
// Explicitly new session window: replace any old slot instead of
|
||||
// accidentally restoring it on a later relaunch.
|
||||
if self.overlays[oid].config.can_persist() {
|
||||
set.inactive_overlays.arc_rm(&name);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let Some(state) = set.inactive_overlays.arc_rm(&name) else {
|
||||
continue;
|
||||
};
|
||||
@@ -999,7 +1227,7 @@ impl<T> OverlayWindowManager<T> {
|
||||
log::debug!("loaded state for {name} to set {i}");
|
||||
}
|
||||
}
|
||||
} else if let Some(state) = self.global_set.inactive_overlays.arc_rm(&name) {
|
||||
} else if restore && let Some(state) = self.global_set.inactive_overlays.arc_rm(&name) {
|
||||
let o = &mut self.overlays[oid];
|
||||
o.config.active_state = Some(state);
|
||||
o.config.reset(app, false);
|
||||
@@ -1007,7 +1235,11 @@ impl<T> OverlayWindowManager<T> {
|
||||
log::debug!("loaded state for {name} from global_set!");
|
||||
}
|
||||
|
||||
let saved_attribs = app.session.config.attribs.arc_get(&name).cloned();
|
||||
let saved_attribs = if restore {
|
||||
app.session.config.attribs.arc_get(&name).cloned()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(attribs) = saved_attribs {
|
||||
for value in attribs {
|
||||
self.overlays[oid].config.backend.set_attrib(app, value);
|
||||
@@ -1049,6 +1281,38 @@ impl<T> OverlayWindowManager<T> {
|
||||
SpawnPos::Parent(parent) => {
|
||||
let _ = self.offset_spawn_from_parent(app, oid, &parent);
|
||||
}
|
||||
SpawnPos::WlDefault(window, fallback_pid) => {
|
||||
let Some((parent, has_app_id)) = app.wvr_server.as_ref().and_then(|wvr| {
|
||||
wvr.wm.windows.get(window).map(|w| {
|
||||
(
|
||||
w.parent.and_then(|p| wvr.get_overlay_id(p)),
|
||||
w.app_id.is_some(),
|
||||
)
|
||||
})
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let parent_id = parent.or_else(|| {
|
||||
if has_app_id {
|
||||
None
|
||||
} else {
|
||||
// legacy pid-based matching
|
||||
fallback_pid.filter(|candidate| *candidate != oid)
|
||||
}
|
||||
});
|
||||
if let Some(parent_id) = parent_id
|
||||
&& self
|
||||
.offset_spawn_from_parent(app, oid, &OverlaySelector::Id(parent_id))
|
||||
.is_some()
|
||||
{
|
||||
return;
|
||||
}
|
||||
if let Some(parent_id) = self.spread_parent_for(oid) {
|
||||
let _ =
|
||||
self.offset_spawn_from_parent(app, oid, &OverlaySelector::Id(parent_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1213,6 +1477,7 @@ impl<T> OverlayWindowManager<T> {
|
||||
meta.push(OverlayMeta {
|
||||
id,
|
||||
name: data.config.name.clone(),
|
||||
title: data.config.title.clone(),
|
||||
category: data.config.category,
|
||||
visible: data.config.is_active(),
|
||||
icon,
|
||||
|
||||
@@ -108,6 +108,10 @@ impl OverlayLifetime {
|
||||
|
||||
pub struct OverlayWindowConfig {
|
||||
pub name: Arc<str>,
|
||||
/// Optional presentation title
|
||||
pub title: Option<Arc<str>>,
|
||||
pub persistent: bool,
|
||||
pub restore_on_spawn: bool,
|
||||
pub backend: Box<dyn OverlayBackend>,
|
||||
/// The default state to show when the overlay is newly spawned.
|
||||
pub default_state: OverlayWindowState,
|
||||
@@ -136,9 +140,16 @@ pub struct OverlayWindowConfig {
|
||||
}
|
||||
|
||||
impl OverlayWindowConfig {
|
||||
pub const fn can_persist(&self) -> bool {
|
||||
self.persistent
|
||||
}
|
||||
|
||||
pub fn from_backend(backend: Box<dyn OverlayBackend>) -> Self {
|
||||
Self {
|
||||
name: "".into(),
|
||||
title: None,
|
||||
persistent: true,
|
||||
restore_on_spawn: true,
|
||||
backend,
|
||||
default_state: OverlayWindowState {
|
||||
transform: Affine3A::from_translation(Vec3::NEG_Z),
|
||||
@@ -275,8 +286,8 @@ impl OverlayWindowConfig {
|
||||
app.input_state.pointers[hand as usize].pose * cur_transform,
|
||||
lerp,
|
||||
),
|
||||
Positioning::Anchored => (app.anchor * cur_transform, 1.0),
|
||||
Positioning::Static | Positioning::Floating => (state.transform, 1.0), // STAGE space
|
||||
Positioning::Anchored | Positioning::Floating => (app.anchor * cur_transform, 1.0),
|
||||
Positioning::Static => (state.transform, 1.0), // STAGE space
|
||||
};
|
||||
|
||||
state.transform = match lerp {
|
||||
@@ -347,9 +358,9 @@ impl OverlayWindowConfig {
|
||||
.unwrap_or(self.default_state.transform);
|
||||
|
||||
let parent_transform = match state.positioning {
|
||||
Positioning::Floating | Positioning::FollowHead { .. } => app.input_state.hmd,
|
||||
Positioning::FollowHead { .. } => app.input_state.hmd,
|
||||
Positioning::FollowHand { hand, .. } => app.input_state.pointers[hand as usize].pose,
|
||||
Positioning::Anchored => app.anchor,
|
||||
Positioning::Anchored | Positioning::Floating => app.anchor,
|
||||
Positioning::Static => {
|
||||
if hard_reset {
|
||||
app.input_state.hmd
|
||||
@@ -437,7 +448,7 @@ pub fn scalar_scale(a: &Affine3A) -> f32 {
|
||||
|
||||
pub fn save_transform(state: &mut OverlayWindowState, app: &mut AppState) {
|
||||
let parent_transform = match state.positioning {
|
||||
Positioning::Floating => snap_upright(app.input_state.hmd, Vec3A::Y),
|
||||
Positioning::Floating => app.anchor,
|
||||
Positioning::FollowHead { .. } => app.input_state.hmd,
|
||||
Positioning::FollowHand { hand, .. } => app.input_state.pointers[hand as usize].pose,
|
||||
Positioning::Anchored => snap_upright(app.anchor, Vec3A::Y),
|
||||
|
||||
+6
-11
@@ -24,17 +24,12 @@ raw-window-handle = "0.6"
|
||||
cosmic-text = "0.19.0"
|
||||
etagere = "0.3.0"
|
||||
flate2 = "1.1.9"
|
||||
image = {
|
||||
version = "0.25.10",
|
||||
default-features = false,
|
||||
features = [
|
||||
"gif",
|
||||
"jpeg",
|
||||
"png",
|
||||
"rayon",
|
||||
"webp",
|
||||
]
|
||||
}
|
||||
image = { workspace = true, features = [
|
||||
"gif",
|
||||
"jpeg",
|
||||
"rayon",
|
||||
"webp",
|
||||
] }
|
||||
lru = "0.18.1"
|
||||
ouroboros = "0.18.5"
|
||||
parking_lot = "0.12.5"
|
||||
|
||||
+1
-1
@@ -218,7 +218,7 @@ impl WGfx {
|
||||
|
||||
/// Submit a non-blocking completion marker to the queue
|
||||
///
|
||||
/// It uses an ALL_COMMANDS to ALL_COMMANDS barrier, so its fence doesn't
|
||||
/// It uses an `ALL_COMMANDS` to `ALL_COMMANDS` barrier, so its fence doesn't
|
||||
/// complete until all earlier work is finished.
|
||||
pub fn submit_graphics_completion_marker(&self) -> anyhow::Result<GpuCompletionMarker> {
|
||||
Ok(GpuCompletionMarker {
|
||||
|
||||
@@ -15,6 +15,7 @@ chrono.workspace = true
|
||||
glam.workspace = true
|
||||
idmap = { workspace = true, features = ["serde"] }
|
||||
idmap-derive.workspace = true
|
||||
libc.workspace = true
|
||||
log.workspace = true
|
||||
serde = { workspace = true, features = ["rc"] }
|
||||
serde_json.workspace = true
|
||||
@@ -34,3 +35,4 @@ rodio = {
|
||||
}
|
||||
walkdir = "2.5.0"
|
||||
wgui = { path = "../wgui/" }
|
||||
inotify = { version = "0.11.5", default-features = false }
|
||||
@@ -14,6 +14,8 @@ use crate::{
|
||||
windowing::OverlayWindowState,
|
||||
};
|
||||
|
||||
pub const CONFIG_VERSION: u32 = 1;
|
||||
|
||||
pub type PwTokenMap = AStrMap<String>;
|
||||
pub type SerializedWindowStates = HashMap<Arc<str>, OverlayWindowState>;
|
||||
|
||||
@@ -562,4 +564,10 @@ pub struct GeneralConfig {
|
||||
|
||||
#[serde(default)]
|
||||
pub middle_grabs_single: bool,
|
||||
|
||||
#[serde(default)]
|
||||
pub state_version: u32,
|
||||
|
||||
#[serde(default)]
|
||||
pub config_version: u32,
|
||||
}
|
||||
+203
-115
@@ -3,14 +3,14 @@ use std::{
|
||||
ffi::OsStr,
|
||||
fmt::Debug,
|
||||
fs::exists,
|
||||
path::Path,
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
thread::JoinHandle,
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use crate::{cache_dir, locale::Language};
|
||||
use crate::{cache_dir, desktop_watcher::DesktopWatcher, locale::Language};
|
||||
use anyhow::Context;
|
||||
use freedesktop_desktop_entry::DesktopEntry as FreedesktopDesktopEntry;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -57,14 +57,32 @@ const CATEGORY_TYPE_BLOCKLIST: [&str; 1] = ["ConsoleOnly"];
|
||||
struct DesktopFinderParams {
|
||||
size_preferences: Vec<&'static OsStr>,
|
||||
icon_folders: Vec<String>,
|
||||
app_folders: Vec<String>,
|
||||
app_folders: Vec<PathBuf>,
|
||||
langs: Vec<String>,
|
||||
}
|
||||
|
||||
struct CachedFileOwned {
|
||||
root_index: usize,
|
||||
entry: DesktopEntryOwned,
|
||||
}
|
||||
|
||||
struct CachedFile {
|
||||
root_index: usize,
|
||||
entry: Rc<DesktopEntry>,
|
||||
}
|
||||
|
||||
struct CacheBuild {
|
||||
files: HashMap<PathBuf, CachedFileOwned>,
|
||||
watcher: Option<DesktopWatcher>,
|
||||
}
|
||||
|
||||
pub struct DesktopFinder {
|
||||
params: Arc<DesktopFinderParams>,
|
||||
// include all desktop files, so that removing a higher-prio one will reveal the lower-prio underneath
|
||||
files: HashMap<PathBuf, CachedFile>,
|
||||
entry_cache: HashMap<String, Rc<DesktopEntry>>,
|
||||
bg_task: Option<JoinHandle<HashMap<String, DesktopEntryOwned>>>,
|
||||
watcher: Option<DesktopWatcher>,
|
||||
bg_task: Option<JoinHandle<CacheBuild>>,
|
||||
}
|
||||
|
||||
impl DesktopFinder {
|
||||
@@ -76,13 +94,8 @@ impl DesktopFinder {
|
||||
let mut icon_folders = vec![];
|
||||
|
||||
if let Some(data_home) = xdg.get_data_home() {
|
||||
app_folders.push(data_home.join("applications").to_string_lossy().to_string());
|
||||
app_folders.push(
|
||||
data_home
|
||||
.join("flatpak/exports/share/applications")
|
||||
.to_string_lossy()
|
||||
.to_string(),
|
||||
);
|
||||
app_folders.push(data_home.join("applications"));
|
||||
app_folders.push(data_home.join("flatpak/exports/share/applications"));
|
||||
icon_folders.push(data_home.join("icons").to_string_lossy().to_string());
|
||||
icon_folders.push(
|
||||
data_home
|
||||
@@ -97,7 +110,7 @@ impl DesktopFinder {
|
||||
|
||||
// /usr/share and such
|
||||
for data_dir in xdg.get_data_dirs() {
|
||||
app_folders.push(data_dir.join("applications").to_string_lossy().to_string());
|
||||
app_folders.push(data_dir.join("applications"));
|
||||
icon_folders.push(data_dir.join("icons").to_string_lossy().to_string());
|
||||
}
|
||||
|
||||
@@ -122,126 +135,117 @@ impl DesktopFinder {
|
||||
size_preferences,
|
||||
langs,
|
||||
}),
|
||||
files: HashMap::new(),
|
||||
entry_cache: HashMap::new(),
|
||||
watcher: None,
|
||||
bg_task: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn build_cache(params: Arc<DesktopFinderParams>) -> HashMap<String, DesktopEntryOwned> {
|
||||
let start = Instant::now();
|
||||
fn read_single(params: &DesktopFinderParams, path: &Path) -> Option<DesktopEntryOwned> {
|
||||
let file_path = path.display();
|
||||
let file_name = path.file_name()?.to_string_lossy();
|
||||
let desktop = match FreedesktopDesktopEntry::from_path(path, Some(¶ms.langs)) {
|
||||
Ok(desktop) => desktop,
|
||||
Err(e) => {
|
||||
log::debug!("Failed to read .desktop file {}: {:?}, skipping", file_path, e);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
let mut known_files = HashSet::new();
|
||||
let mut entries = HashMap::<String, DesktopEntryOwned>::new();
|
||||
if desktop.groups.desktop_entry().is_none() {
|
||||
log::debug!("Failed to get [Desktop Entry] section for file {}, skipping", file_path);
|
||||
return None;
|
||||
}
|
||||
if desktop.only_show_in().is_some() || desktop.terminal() || desktop.no_display() || desktop.hidden() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let exec = desktop.exec()?;
|
||||
if CMD_BLOCKLIST.iter().any(|blocked| exec.contains(blocked)) {
|
||||
return None;
|
||||
}
|
||||
let exec_argv = desktop
|
||||
.parse_exec_with_uris(&[], ¶ms.langs)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|x| x.into_boxed_str())
|
||||
.collect::<Box<[_]>>();
|
||||
if exec_argv.is_empty() {
|
||||
log::debug!("Invalid Exec in desktop file {}, skipping", file_path);
|
||||
return None;
|
||||
}
|
||||
let app_name = desktop.name(¶ms.langs)?;
|
||||
let mut vec_categories = Vec::<Box<str>>::new();
|
||||
for cat in desktop.categories().unwrap_or_default() {
|
||||
if CATEGORY_TYPE_BLOCKLIST.contains(&cat) {
|
||||
return None;
|
||||
}
|
||||
if !cat.is_empty() {
|
||||
vec_categories.push(cat.into());
|
||||
}
|
||||
}
|
||||
|
||||
let icon_path = desktop
|
||||
.icon()
|
||||
.and_then(|icon_name| Self::find_icon(params, icon_name))
|
||||
.or_else(|| Self::create_icon(&file_name).ok());
|
||||
|
||||
Some(DesktopEntryOwned {
|
||||
app_id: desktop.id().into(),
|
||||
app_name: app_name.into(),
|
||||
exec_argv,
|
||||
icon_path: icon_path.map(|i| i.into_boxed_str()),
|
||||
categories: vec_categories.into_boxed_slice(),
|
||||
})
|
||||
}
|
||||
|
||||
fn build_cache_full(params: Arc<DesktopFinderParams>) -> CacheBuild {
|
||||
let start = Instant::now();
|
||||
// install watch before scan so edits during scan remain in inotify event queue
|
||||
let watcher = match DesktopWatcher::new(¶ms.app_folders) {
|
||||
Ok(watcher) => Some(watcher),
|
||||
Err(err) => {
|
||||
log::warn!("Could not watch .desktop files: {err}");
|
||||
None
|
||||
}
|
||||
};
|
||||
let mut files = HashMap::new();
|
||||
|
||||
let icons_folder = cache_dir::get_path("icons");
|
||||
if !std::fs::exists(&icons_folder).unwrap_or(false) {
|
||||
let _ = std::fs::create_dir(&icons_folder);
|
||||
}
|
||||
|
||||
for path in ¶ms.app_folders {
|
||||
log::debug!("Searching desktop entries in path {}", path);
|
||||
|
||||
'entries: for entry in WalkDir::new(path)
|
||||
for (root_index, root) in params.app_folders.iter().enumerate() {
|
||||
log::debug!("Searching desktop entries in path {}", root.display());
|
||||
for entry in WalkDir::new(root)
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
.filter(|e| !e.file_type().is_dir())
|
||||
.filter_map(Result::ok)
|
||||
.filter(|entry| !entry.file_type().is_dir())
|
||||
{
|
||||
let Some(extension) = Path::new(entry.file_name()).extension() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
if extension != "desktop" {
|
||||
continue; // ignore, go on
|
||||
}
|
||||
|
||||
let file_name = entry.file_name().to_string_lossy();
|
||||
let file_path = entry.path().display().to_string();
|
||||
|
||||
let desktop = match FreedesktopDesktopEntry::from_path(entry.path(), Some(¶ms.langs)) {
|
||||
Ok(desktop) => desktop,
|
||||
Err(e) => {
|
||||
log::debug!("Failed to read .desktop file {}: {:?}, skipping", file_path, e);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
if desktop.groups.desktop_entry().is_none() {
|
||||
log::debug!("Failed to get [Desktop Entry] section for file {}, skipping", file_path);
|
||||
let path = entry.path();
|
||||
if path.extension() != Some(OsStr::new("desktop")) || files.contains_key(path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// prefer entries from earlier data directories
|
||||
let app_id = desktop.id();
|
||||
if known_files.contains(app_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if desktop.only_show_in().is_some() || desktop.terminal() || desktop.no_display() || desktop.hidden() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let Some(exec) = desktop.exec() else {
|
||||
log::debug!("Failed to get desktop entry Exec for file {}, skipping", file_path);
|
||||
continue;
|
||||
};
|
||||
|
||||
if CMD_BLOCKLIST.iter().any(|blocked| exec.contains(blocked)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let exec_argv = desktop
|
||||
.parse_exec_with_uris(&[], ¶ms.langs)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|x| x.into_boxed_str())
|
||||
.collect::<Box<[_]>>();
|
||||
|
||||
if exec_argv.is_empty() {
|
||||
log::debug!("Invalid Exec in desktop file {}, skipping", file_path);
|
||||
continue;
|
||||
};
|
||||
|
||||
let Some(app_name) = desktop.name(¶ms.langs) else {
|
||||
log::debug!(
|
||||
"Failed to get desktop entry application name for file {}, skipping",
|
||||
file_path
|
||||
if let Some(parsed) = Self::read_single(¶ms, path) {
|
||||
files.insert(
|
||||
path.to_path_buf(),
|
||||
CachedFileOwned {
|
||||
root_index,
|
||||
entry: parsed,
|
||||
},
|
||||
);
|
||||
continue;
|
||||
};
|
||||
|
||||
let icon_path = desktop
|
||||
.icon()
|
||||
.and_then(|icon_name| Self::find_icon(¶ms, icon_name))
|
||||
.or_else(|| Self::create_icon(&file_name).ok());
|
||||
|
||||
let mut vec_categories = Vec::<Box<str>>::new();
|
||||
for cat in desktop.categories().unwrap_or_default() {
|
||||
if CATEGORY_TYPE_BLOCKLIST.contains(&cat) {
|
||||
continue 'entries;
|
||||
}
|
||||
if !cat.is_empty() {
|
||||
vec_categories.push(cat.into());
|
||||
}
|
||||
}
|
||||
|
||||
known_files.insert(app_id.to_owned());
|
||||
|
||||
entries.insert(
|
||||
app_id.to_owned(),
|
||||
DesktopEntryOwned {
|
||||
app_id: app_id.into(),
|
||||
app_name: app_name.into(),
|
||||
exec_argv,
|
||||
icon_path: icon_path.map(|i| i.into_boxed_str()),
|
||||
categories: vec_categories.into_boxed_slice(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
log::debug!("Desktop entry & icon scan took {:?}", start.elapsed());
|
||||
CacheBuild { files, watcher }
|
||||
}
|
||||
|
||||
entries
|
||||
pub fn resolve_icon(&self, icon_name: &str) -> Option<String> {
|
||||
Self::find_icon(&self.params, icon_name)
|
||||
}
|
||||
|
||||
fn find_icon(params: &DesktopFinderParams, icon_name: &str) -> Option<String> {
|
||||
@@ -306,29 +310,113 @@ impl DesktopFinder {
|
||||
return;
|
||||
};
|
||||
|
||||
let Ok(entries) = bg_task.join() else {
|
||||
let Ok(CacheBuild { files, watcher }) = bg_task.join() else {
|
||||
log::warn!("Desktop entry scan thread panicked");
|
||||
return;
|
||||
};
|
||||
|
||||
self.files = files
|
||||
.into_iter()
|
||||
.map(|(path, file)| {
|
||||
(
|
||||
path,
|
||||
CachedFile {
|
||||
root_index: file.root_index,
|
||||
entry: Rc::new(file.entry.into()),
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
self.watcher = watcher;
|
||||
|
||||
let mut files: Vec<_> = self.files.iter().collect();
|
||||
files.sort_by(|(path_a, a), (path_b, b)| a.root_index.cmp(&b.root_index).then_with(|| path_a.cmp(path_b)));
|
||||
self.entry_cache.clear();
|
||||
for (app_id, entry) in entries {
|
||||
self.entry_cache.insert(app_id, Rc::new(entry.into()));
|
||||
for (_, file) in files {
|
||||
self
|
||||
.entry_cache
|
||||
.entry(file.entry.app_id.to_string())
|
||||
.or_insert_with(|| Rc::clone(&file.entry));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_cached_entry(&self, app_id: &str) -> Option<&Rc<DesktopEntry>> {
|
||||
fn update_app_id(&mut self, app_id: &str) {
|
||||
let best = self
|
||||
.files
|
||||
.iter()
|
||||
.filter(|(_, file)| file.entry.app_id.as_ref() == app_id)
|
||||
.min_by(|(path_a, a), (path_b, b)| a.root_index.cmp(&b.root_index).then_with(|| path_a.cmp(path_b)))
|
||||
.map(|(_, file)| Rc::clone(&file.entry));
|
||||
if let Some(best) = best {
|
||||
self.entry_cache.insert(app_id.to_owned(), best);
|
||||
} else {
|
||||
self.entry_cache.remove(app_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_file_changes(&mut self) {
|
||||
self.wait_for_entries();
|
||||
let Some(watcher) = self.watcher.as_mut() else {
|
||||
return;
|
||||
};
|
||||
let changes = watcher.collect_changes();
|
||||
if changes.overflowed {
|
||||
log::warn!("Desktop file inotify event queue overflowed; rebuilding cache");
|
||||
self.refresh();
|
||||
self.wait_for_entries();
|
||||
return;
|
||||
}
|
||||
|
||||
let mut affected_ids = HashSet::new();
|
||||
if !changes.removed_directories.is_empty() {
|
||||
self.files.retain(|path, file| {
|
||||
let removed = changes
|
||||
.removed_directories
|
||||
.iter()
|
||||
.any(|directory| path.starts_with(directory));
|
||||
if removed {
|
||||
affected_ids.insert(file.entry.app_id.to_string());
|
||||
}
|
||||
!removed
|
||||
});
|
||||
}
|
||||
for path in changes.files {
|
||||
if let Some(previous) = self.files.remove(&path) {
|
||||
affected_ids.insert(previous.entry.app_id.to_string());
|
||||
}
|
||||
let root_index = self.params.app_folders.iter().position(|root| path.starts_with(root));
|
||||
if let Some(root_index) = root_index
|
||||
&& let Some(entry) = Self::read_single(&self.params, &path)
|
||||
{
|
||||
affected_ids.insert(entry.app_id.to_string());
|
||||
self.files.insert(
|
||||
path,
|
||||
CachedFile {
|
||||
root_index,
|
||||
entry: Rc::new(entry.into()),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
for app_id in affected_ids {
|
||||
self.update_app_id(&app_id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_cached_entry(&mut self, app_id: &str) -> Option<&Rc<DesktopEntry>> {
|
||||
self.sync_file_changes();
|
||||
self.entry_cache.get(app_id)
|
||||
}
|
||||
|
||||
pub fn find_entries(&mut self) -> HashMap<String, Rc<DesktopEntry>> {
|
||||
self.wait_for_entries();
|
||||
self.sync_file_changes();
|
||||
self.entry_cache.clone()
|
||||
}
|
||||
|
||||
pub fn refresh(&mut self) {
|
||||
let bg_task = std::thread::spawn({
|
||||
let params = self.params.clone();
|
||||
move || Self::build_cache(params)
|
||||
move || Self::build_cache_full(params)
|
||||
});
|
||||
self.bg_task = Some(bg_task);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
ffi::OsStr,
|
||||
io,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use inotify::{EventMask, Inotify, WatchDescriptor, WatchMask};
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct DesktopChanges {
|
||||
pub files: HashSet<PathBuf>,
|
||||
pub removed_directories: HashSet<PathBuf>,
|
||||
pub overflowed: bool,
|
||||
}
|
||||
|
||||
pub(crate) struct DesktopWatcher {
|
||||
inotify: Inotify,
|
||||
roots: Vec<PathBuf>,
|
||||
by_wd: HashMap<WatchDescriptor, HashSet<PathBuf>>,
|
||||
by_path: HashMap<PathBuf, WatchDescriptor>,
|
||||
}
|
||||
|
||||
impl DesktopWatcher {
|
||||
pub fn new(roots: &[PathBuf]) -> io::Result<Self> {
|
||||
let mut watcher = Self {
|
||||
inotify: Inotify::init()?,
|
||||
roots: roots.to_vec(),
|
||||
by_wd: HashMap::new(),
|
||||
by_path: HashMap::new(),
|
||||
};
|
||||
|
||||
for root in roots {
|
||||
for ancestor in root.ancestors().skip(1) {
|
||||
if ancestor.is_dir() {
|
||||
watcher.watch_directory(ancestor);
|
||||
}
|
||||
}
|
||||
watcher.watch_tree(root, None);
|
||||
}
|
||||
|
||||
Ok(watcher)
|
||||
}
|
||||
|
||||
fn is_related_directory(&self, path: &Path) -> bool {
|
||||
self
|
||||
.roots
|
||||
.iter()
|
||||
.any(|root| path.starts_with(root) || root.starts_with(path))
|
||||
}
|
||||
|
||||
fn is_application_file(&self, path: &Path) -> bool {
|
||||
path.extension() == Some(OsStr::new("desktop")) && self.roots.iter().any(|root| path.starts_with(root))
|
||||
}
|
||||
|
||||
fn watch_directory(&mut self, path: &Path) {
|
||||
if self.by_path.contains_key(path) || !path.is_dir() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mask = WatchMask::CREATE
|
||||
| WatchMask::DELETE
|
||||
| WatchMask::MOVED_FROM
|
||||
| WatchMask::MOVED_TO
|
||||
| WatchMask::MODIFY
|
||||
| WatchMask::CLOSE_WRITE
|
||||
| WatchMask::ATTRIB
|
||||
| WatchMask::DELETE_SELF
|
||||
| WatchMask::MOVE_SELF
|
||||
| WatchMask::ONLYDIR;
|
||||
|
||||
let wd = match self.inotify.watches().add(path, mask) {
|
||||
Ok(wd) => wd,
|
||||
Err(err) => {
|
||||
log::warn!("Unable to watch desktop directory {}: {err}", path.display());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.by_wd.entry(wd.clone()).or_default().insert(path.to_path_buf());
|
||||
self.by_path.insert(path.to_path_buf(), wd);
|
||||
}
|
||||
|
||||
fn watch_tree(&mut self, directory: &Path, mut existing_files: Option<&mut HashSet<PathBuf>>) {
|
||||
let mut pending = vec![directory.to_path_buf()];
|
||||
|
||||
while let Some(dir) = pending.pop() {
|
||||
if !self.is_related_directory(&dir) || !dir.is_dir() {
|
||||
continue;
|
||||
}
|
||||
|
||||
self.watch_directory(&dir);
|
||||
|
||||
let children = match std::fs::read_dir(&dir) {
|
||||
Ok(children) => children,
|
||||
Err(err) => {
|
||||
log::debug!("Cannot read desktop directory {}: {err}", dir.display());
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
for child in children.flatten() {
|
||||
let path = child.path();
|
||||
|
||||
match child.file_type() {
|
||||
Ok(kind) if kind.is_dir() => {
|
||||
if self.is_related_directory(&path) {
|
||||
pending.push(path);
|
||||
}
|
||||
}
|
||||
Ok(_) => {
|
||||
if self.is_application_file(&path)
|
||||
&& let Some(files) = existing_files.as_deref_mut()
|
||||
{
|
||||
files.insert(path);
|
||||
}
|
||||
}
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn unwatch_tree(&mut self, directory: &Path) {
|
||||
let descendants: Vec<_> = self
|
||||
.by_path
|
||||
.iter()
|
||||
.filter(|(path, _)| path.starts_with(directory))
|
||||
.map(|(path, wd)| (path.clone(), wd.clone()))
|
||||
.collect();
|
||||
|
||||
for (path, wd) in descendants {
|
||||
self.by_path.remove(&path);
|
||||
|
||||
if let Some(paths) = self.by_wd.get_mut(&wd) {
|
||||
paths.remove(&path);
|
||||
|
||||
if paths.is_empty() {
|
||||
self.by_wd.remove(&wd);
|
||||
let _ = self.inotify.watches().remove(wd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collect_changes(&mut self) -> DesktopChanges {
|
||||
let mut changes = DesktopChanges::default();
|
||||
let mut buffer = [0u8; 64 * 1024];
|
||||
|
||||
loop {
|
||||
let events = match self.inotify.read_events(&mut buffer) {
|
||||
Ok(events) => events,
|
||||
Err(err) if err.kind() == io::ErrorKind::WouldBlock => break,
|
||||
Err(err) if err.kind() == io::ErrorKind::Interrupted => continue,
|
||||
Err(err) => {
|
||||
log::warn!("Unable to read desktop directory inotify events: {err}");
|
||||
changes.overflowed = true;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
for event in events {
|
||||
if event.mask.contains(EventMask::Q_OVERFLOW) {
|
||||
changes.overflowed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if event.mask.contains(EventMask::IGNORED) {
|
||||
if let Some(paths) = self.by_wd.remove(&event.wd) {
|
||||
for path in paths {
|
||||
self.by_path.remove(&path);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
let Some(directories) = self.by_wd.get(&event.wd).cloned() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
for directory in directories {
|
||||
let path = match event.name {
|
||||
Some(name) => directory.join(name),
|
||||
None => directory,
|
||||
};
|
||||
|
||||
if event.mask.intersects(EventMask::DELETE_SELF | EventMask::MOVE_SELF) {
|
||||
changes.removed_directories.insert(path.clone());
|
||||
self.unwatch_tree(&path);
|
||||
} else if event.mask.contains(EventMask::ISDIR) {
|
||||
if event.mask.intersects(EventMask::DELETE | EventMask::MOVED_FROM) {
|
||||
changes.removed_directories.insert(path.clone());
|
||||
self.unwatch_tree(&path);
|
||||
}
|
||||
|
||||
if event.mask.intersects(EventMask::CREATE | EventMask::MOVED_TO) {
|
||||
self.watch_tree(&path, Some(&mut changes.files));
|
||||
}
|
||||
} else if self.is_application_file(&path) {
|
||||
changes.files.insert(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
changes
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ pub mod dash_interface;
|
||||
pub mod dash_interface_emulated;
|
||||
pub mod data_dir;
|
||||
pub mod desktop_finder;
|
||||
mod desktop_watcher;
|
||||
pub mod locale;
|
||||
pub mod openxr_actions;
|
||||
pub mod openxr_bindings_schema;
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{common::LeftRight, config::DefaultPositioning};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
|
||||
pub enum Positioning {
|
||||
/// Stays in place, recenters relative to HMD
|
||||
/// Freely grabbed, but stored relative to the anchor and moves with it.
|
||||
#[default]
|
||||
Floating,
|
||||
/// Stays in place, recenters relative to anchor. Follows anchor during anchor grab.
|
||||
|
||||
Reference in new issue
Block a user