From c814c656c53ea9d69f5afb45c88f4dc4d25338cd Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 17 Apr 2026 16:21:09 +0300 Subject: [PATCH] Dlsym set_default_max_buffer_size() to avoid wayland-server 1.23 requirement Ubuntu 24.04 users rejoice --- .github/workflows/ci.yml | 14 ++++---------- Cargo.toml | 2 +- src/main.rs | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3700819..bb231775 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,9 +20,6 @@ jobs: name: test runs-on: ubuntu-24.04 - # FIXME: remove once it's available in runs-on. - # This is necessary for libwayland-server v1.23. - container: ubuntu:26.04 steps: - uses: actions/checkout@v6 @@ -31,8 +28,8 @@ jobs: - name: Install dependencies run: | - apt-get update -y - apt-get install -y ${{ env.DEPS_APT }} + sudo apt-get update -y + sudo apt-get install -y ${{ env.DEPS_APT }} - uses: dtolnay/rust-toolchain@stable @@ -114,9 +111,6 @@ jobs: name: randomized and slow tests runs-on: ubuntu-24.04 - # FIXME: remove once it's available in runs-on. - # This is necessary for libwayland-server v1.23. - container: ubuntu:26.04 env: RUST_BACKTRACE: 1 @@ -133,8 +127,8 @@ jobs: - name: Install dependencies run: | - apt-get update -y - apt-get install -y ${{ env.DEPS_APT }} + sudo apt-get update -y + sudo apt-get install -y ${{ env.DEPS_APT }} - uses: dtolnay/rust-toolchain@stable diff --git a/Cargo.toml b/Cargo.toml index 80d48f54..b1cf2464 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,7 +96,7 @@ tracing.workspace = true tracy-client.workspace = true wayland-backend = "0.3.15" wayland-scanner = "0.31.10" -wayland-server = { version = "0.31.13", features = ["libwayland_1_23"] } +wayland-server = "0.31.13" xcursor = "0.3.10" zbus = { version = "5.13.2", optional = true } diff --git a/src/main.rs b/src/main.rs index 5ccc414b..4008e004 100644 --- a/src/main.rs +++ b/src/main.rs @@ -172,7 +172,7 @@ fn main() -> Result<(), Box> { let display = Display::new().unwrap(); // Increase the buffer size so that it's harder to crash a frozen client with a 1000 Hz mouse. - display.handle().set_default_max_buffer_size(1024 * 1024); + set_default_max_buffer_size(&display, 1024 * 1024); let mut state = State::new( config, @@ -374,3 +374,38 @@ fn notify_fd() -> anyhow::Result<()> { notif.write_all(b"READY=1\n")?; Ok(()) } + +// The wayland-server crate has set_default_max_buffer_size() under a libwayland_1_23 feature, but +// this hard-requires libwayland-server >= 1.23 which is not present on e.g. Ubuntu 24.04. Since +// calling this is an optional enhancement, do it optionally at runtime. +fn set_default_max_buffer_size(display: &Display, size: usize) { + use std::ffi::c_void; + + unsafe { + // RTLD_NOLOAD ensures we only get a handle to the libwayland-server that wayland-rs has + // already loaded into this process, rather than potentially pulling in a different copy. + let lib = libc::dlopen( + c"libwayland-server.so.0".as_ptr(), + libc::RTLD_LAZY | libc::RTLD_NOLOAD, + ); + if lib.is_null() { + // It's not really expected that this can happen, maybe if some distro changes the + // library name? + warn!("cannot set default max buffer size: libwayland-server.so.0 is not loaded"); + return; + } + + let sym = libc::dlsym(lib, c"wl_display_set_default_max_buffer_size".as_ptr()); + if sym.is_null() { + // Expected on libwayland-server < 1.23. + trace!("wl_display_set_default_max_buffer_size is missing; skipping"); + return; + } else { + let func: unsafe extern "C" fn(*mut c_void, libc::size_t) = std::mem::transmute(sym); + let display_ptr = display.handle().backend_handle().display_ptr(); + func(display_ptr.cast(), size); + } + + libc::dlclose(lib); + } +}