Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wayland: Use wl_fixes to free registry #218

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,11 @@ targets = [
"x86_64-unknown-linux-gnu",
"wasm32-unknown-unknown",
]

[patch.crates-io]
wayland-protocols = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" }
wayland-protocols-wlr = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" }
wayland-client = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" }
wayland-sys = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" }
wayland-backend = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" }
wayland-scanner = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" }
28 changes: 27 additions & 1 deletion src/backends/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
use wayland_client::{
backend::{Backend, ObjectId},
globals::{registry_queue_init, GlobalListContents},
protocol::{wl_registry, wl_shm, wl_surface},
protocol::{wl_fixes, wl_registry, wl_shm, wl_surface},
Connection, Dispatch, EventQueue, Proxy, QueueHandle,
};

Expand Down Expand Up @@ -59,6 +59,17 @@ impl<D: HasDisplayHandle + ?Sized> ContextInterface<D> for Rc<WaylandDisplayImpl
let shm: wl_shm::WlShm = globals
.bind(&qh, 1..=1, ())
.swbuf_err("Failed to instantiate Wayland Shm")?;

// If `wl_fixes` is supported, destroy registry using it.
// We don't need the registry anymore.
if let Ok(fixes) = globals.bind::<wl_fixes::WlFixes, _, ()>(&qh, 1..=1, ()) {
fixes.destroy_registry(globals.registry());
conn.backend()
.destroy_object(&globals.registry().id())
.unwrap();
fixes.destroy();
}

Ok(Rc::new(WaylandDisplayImpl {
conn: Some(conn),
event_queue: RefCell::new(event_queue),
Expand All @@ -71,6 +82,9 @@ impl<D: HasDisplayHandle + ?Sized> ContextInterface<D> for Rc<WaylandDisplayImpl

impl<D: ?Sized> Drop for WaylandDisplayImpl<D> {
fn drop(&mut self) {
if self.shm.version() >= 2 {
self.shm.release();
}
// Make sure the connection is dropped first.
self.conn = None;
}
Expand Down Expand Up @@ -312,3 +326,15 @@ impl Dispatch<wl_shm::WlShm, ()> for State {
) {
}
}

impl Dispatch<wl_fixes::WlFixes, ()> for State {
fn event(
_: &mut State,
_: &wl_fixes::WlFixes,
_: wl_fixes::Event,
_: &(),
_: &Connection,
_: &QueueHandle<State>,
) {
}
}