Skip to content

Commit

Permalink
feat: support for window lifecycle events and deprecate window create…
Browse files Browse the repository at this point in the history
…d event (#12)

* feat: support for window lifecycle events and deprecate window created event

- also added some error handling

* address commemnts

---------

Co-authored-by: Ericky Dos Santos <ericky@playtron.one>
  • Loading branch information
Ericky14 and Ericky Dos Santos authored Nov 11, 2024
1 parent c49949b commit 40befd1
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 25 deletions.
33 changes: 17 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ zbus = { version = "3.15.2", default-features = false, features = ["tokio"] }
zbus_macros = "3.15.2"
inotify = "0.11.0"
gamescope-wayland-client = { git = "https://github.com/ShadowBlip/gamescope-wayland-client.git", version = "0.1.0" }
gamescope-x11-client = { git = "https://github.com/ShadowBlip/gamescope-x11-client.git", rev = "deeab5be067bfbb2add2446d8c7fbcbeba7c8c7f" }
gamescope-x11-client = { git = "https://github.com/ShadowBlip/gamescope-x11-client.git", rev = "9526a6e0d684d9530e8705f7f1a53efa401350f3" }
serde = "1.0.214"
18 changes: 16 additions & 2 deletions src/gamescope/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Manager {

// Create any xwaylands that don't exist
for (i, name) in current_xwaylands.into_iter().enumerate() {
if self.xwaylands.get(&name).is_some() {
if self.xwaylands.contains_key(&name) {
log::debug!("XWayland is already managed for {}. Skipping.", name);
continue;
}
Expand All @@ -193,10 +193,22 @@ impl Manager {
let path = format!("/org/shadowblip/Gamescope/XWayland{}", i);
let instance =
xwayland::DBusInterface::new(name.clone(), path.clone(), self.dbus.clone())?;
let is_primary = instance.primary().await?;

// Listen for new windows lifecycle
let window_lifecycle_rx = instance.listen_for_window_lifecycle()?;
// Propagate gamescope changes to DBus signals
xwayland::dispatch_window_lifecycle(
self.dbus.clone(),
path.clone(),
window_lifecycle_rx,
is_primary,
)
.await?;

// Check to see if this is a primary xwayland instance. If it is,
// also attach the dbus interface with extra methods
if instance.primary().await? {
if is_primary {
log::debug!("Discovered XWayland {} is primary", name);

// Property changes events
Expand All @@ -206,6 +218,7 @@ impl Manager {
self.dbus.clone(),
)?;
let property_changes_rx = primary.listen_for_property_changes()?;
#[allow(deprecated)]
let window_created_rx = primary.listen_for_window_created()?;
self.dbus.object_server().at(path.clone(), primary).await?;

Expand All @@ -218,6 +231,7 @@ impl Manager {
.await?;

// Propagate gamescope changes to DBus signals
#[allow(deprecated)]
xwayland::dispatch_primary_window_created(
self.dbus.clone(),
path.clone(),
Expand Down
Loading

0 comments on commit 40befd1

Please sign in to comment.