From 17e7c7e89f2cce5ba2843d2f0676e8c107e02b1a Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Sun, 9 Jun 2024 01:15:21 +0200 Subject: [PATCH 1/2] wayland-backend: Add getter for global name --- wayland-backend/src/rs/server_impl/handle.rs | 22 ++++++++++++++++- wayland-backend/src/server_api.rs | 9 +++++++ wayland-backend/src/sys/server_impl/mod.rs | 25 ++++++++++++++++++++ wayland-sys/src/server.rs | 1 + 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/wayland-backend/src/rs/server_impl/handle.rs b/wayland-backend/src/rs/server_impl/handle.rs index 7d1cff1ce08..cd52682ed83 100644 --- a/wayland-backend/src/rs/server_impl/handle.rs +++ b/wayland-backend/src/rs/server_impl/handle.rs @@ -14,7 +14,7 @@ use crate::{ use super::{ client::ClientStore, registry::Registry, ClientData, ClientId, Credentials, GlobalHandler, - InnerClientId, InnerGlobalId, InnerObjectId, ObjectData, ObjectId, + GlobalId, InnerClientId, InnerGlobalId, InnerObjectId, ObjectData, ObjectId, }; pub(crate) type PendingDestructor = (Arc>, InnerClientId, InnerObjectId); @@ -252,6 +252,10 @@ impl InnerHandle { self.state.lock().unwrap().global_info(id) } + pub fn global_name(&self, global: InnerGlobalId, client: InnerClientId) -> Option { + self.state.lock().unwrap().global_name(global, client) + } + pub fn get_global_handler( &self, id: InnerGlobalId, @@ -298,6 +302,7 @@ pub(crate) trait ErasedState: downcast_rs::Downcast { fn post_error(&mut self, object_id: InnerObjectId, error_code: u32, message: CString); fn kill_client(&mut self, client_id: InnerClientId, reason: DisconnectReason); fn global_info(&self, id: InnerGlobalId) -> Result; + fn global_name(&self, global: InnerGlobalId, client: InnerClientId) -> Option; fn flush(&mut self, client: Option) -> std::io::Result<()>; } @@ -440,6 +445,21 @@ impl ErasedState for State { self.registry.get_info(id) } + fn global_name(&self, global_id: InnerGlobalId, client_id: InnerClientId) -> Option { + let client = self.clients.get_client(client_id.clone()).ok()?; + let handler = self.registry.get_handler(global_id.clone()).ok()?; + let name = global_id.id; + + let can_view = + handler.can_view(ClientId { id: client_id }, &client.data, GlobalId { id: global_id }); + + if can_view { + Some(name) + } else { + None + } + } + fn flush(&mut self, client: Option) -> std::io::Result<()> { self.flush(client) } diff --git a/wayland-backend/src/server_api.rs b/wayland-backend/src/server_api.rs index 07c7a529693..bcb6574e759 100644 --- a/wayland-backend/src/server_api.rs +++ b/wayland-backend/src/server_api.rs @@ -481,6 +481,15 @@ impl Handle { self.handle.global_info(id.id) } + /// Get the name of the global. + /// + /// - `client` Client for which to look up the global. + #[doc(alias = "wl_global_get_name")] + #[inline] + pub fn global_name(&self, global: GlobalId, client: ClientId) -> Option { + self.handle.global_name(global.id, client.id) + } + /// Returns the handler which manages the visibility and notifies when a client has bound the global. #[inline] pub fn get_global_handler( diff --git a/wayland-backend/src/sys/server_impl/mod.rs b/wayland-backend/src/sys/server_impl/mod.rs index 0b90201f46a..78d255fba1f 100644 --- a/wayland-backend/src/sys/server_impl/mod.rs +++ b/wayland-backend/src/sys/server_impl/mod.rs @@ -791,6 +791,10 @@ impl InnerHandle { self.state.lock().unwrap().global_info(id) } + pub fn global_name(&self, global: InnerGlobalId, client: InnerClientId) -> Option { + self.state.lock().unwrap().global_name(global, client) + } + /// Returns the handler which manages the visibility and notifies when a client has bound the global. pub fn get_global_handler( &self, @@ -852,6 +856,7 @@ pub(crate) trait ErasedState: downcast_rs::Downcast { fn post_error(&mut self, object_id: InnerObjectId, error_code: u32, message: CString); fn kill_client(&mut self, client_id: InnerClientId, reason: DisconnectReason); fn global_info(&self, id: InnerGlobalId) -> Result; + fn global_name(&self, global: InnerGlobalId, client: InnerClientId) -> Option; fn is_known_global(&self, global_ptr: *const wl_global) -> bool; fn flush(&mut self, client: Option) -> std::io::Result<()>; fn display_ptr(&self) -> *mut wl_display; @@ -1225,6 +1230,26 @@ impl ErasedState for State { }) } + fn global_name(&self, global: InnerGlobalId, client: InnerClientId) -> Option { + if !global.alive.load(Ordering::Acquire) { + return None; + } + + if !client.alive.load(Ordering::Acquire) { + return None; + } + + let name = unsafe { + ffi_dispatch!(wayland_server_handle(), wl_global_get_name, global.ptr, client.ptr) + }; + + if name == 0 { + None + } else { + Some(name) + } + } + fn is_known_global(&self, global_ptr: *const wl_global) -> bool { self.known_globals.iter().any(|ginfo| (ginfo.ptr as *const wl_global) == global_ptr) } diff --git a/wayland-sys/src/server.rs b/wayland-sys/src/server.rs index b11e8ed7060..a205bdaa43c 100644 --- a/wayland-sys/src/server.rs +++ b/wayland-sys/src/server.rs @@ -102,6 +102,7 @@ external_library!(WaylandServer, "wayland-server", // wl_global fn wl_global_remove(*mut wl_global) -> (), fn wl_global_destroy(*mut wl_global) -> (), + fn wl_global_get_name(*mut wl_global, *mut wl_client) -> u32, fn wl_global_get_user_data(*const wl_global) -> *mut c_void, // wl_resource fn wl_resource_post_event_array(*mut wl_resource, u32, *mut wl_argument) -> (), From fc9c41819e8e8762924d29e64fc496813919f820 Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Mon, 26 Aug 2024 02:28:51 +0200 Subject: [PATCH 2/2] [CI] Bump ubuntu version --- .github/workflows/ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8396acde2e..00b44ddc81d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ on: jobs: format: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout sources uses: actions/checkout@v2 @@ -33,7 +33,7 @@ jobs: args: --all -- --check clippy-check: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout sources uses: actions/checkout@v2 @@ -108,7 +108,7 @@ jobs: args: --all --all-features --all-targets -- -D warnings cargo-deny: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout sources @@ -124,7 +124,7 @@ jobs: - clippy-check env: RUSTFLAGS: "-D warnings" - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout sources uses: actions/checkout@v2 @@ -171,7 +171,7 @@ jobs: needs: - format - clippy-check - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout sources uses: actions/checkout@v2 @@ -223,7 +223,7 @@ jobs: - format - clippy-check - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout sources @@ -301,7 +301,7 @@ jobs: - format - clippy-check - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 strategy: fail-fast: false @@ -382,7 +382,7 @@ jobs: doc: name: Documentation on Github Pages - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 needs: - format - clippy-check