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-backend: Add getter for global name #735

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
format:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -223,7 +223,7 @@ jobs:
- format
- clippy-check

runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- name: Checkout sources
Expand Down Expand Up @@ -301,7 +301,7 @@ jobs:
- format
- clippy-check

runs-on: ubuntu-latest
runs-on: ubuntu-24.04

strategy:
fail-fast: false
Expand Down Expand Up @@ -382,7 +382,7 @@ jobs:

doc:
name: Documentation on Github Pages
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs:
- format
- clippy-check
Expand Down
22 changes: 21 additions & 1 deletion wayland-backend/src/rs/server_impl/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D> = (Arc<dyn ObjectData<D>>, InnerClientId, InnerObjectId);
Expand Down Expand Up @@ -252,6 +252,10 @@ impl InnerHandle {
self.state.lock().unwrap().global_info(id)
}

pub fn global_name(&self, global: InnerGlobalId, client: InnerClientId) -> Option<u32> {
self.state.lock().unwrap().global_name(global, client)
}

pub fn get_global_handler<D: 'static>(
&self,
id: InnerGlobalId,
Expand Down Expand Up @@ -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<GlobalInfo, InvalidId>;
fn global_name(&self, global: InnerGlobalId, client: InnerClientId) -> Option<u32>;
fn flush(&mut self, client: Option<ClientId>) -> std::io::Result<()>;
}

Expand Down Expand Up @@ -440,6 +445,21 @@ impl<D> ErasedState for State<D> {
self.registry.get_info(id)
}

fn global_name(&self, global_id: InnerGlobalId, client_id: InnerClientId) -> Option<u32> {
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<ClientId>) -> std::io::Result<()> {
self.flush(client)
}
Expand Down
9 changes: 9 additions & 0 deletions wayland-backend/src/server_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
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<D: 'static>(
Expand Down
25 changes: 25 additions & 0 deletions wayland-backend/src/sys/server_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,10 @@ impl InnerHandle {
self.state.lock().unwrap().global_info(id)
}

pub fn global_name(&self, global: InnerGlobalId, client: InnerClientId) -> Option<u32> {
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<D: 'static>(
&self,
Expand Down Expand Up @@ -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<GlobalInfo, InvalidId>;
fn global_name(&self, global: InnerGlobalId, client: InnerClientId) -> Option<u32>;
fn is_known_global(&self, global_ptr: *const wl_global) -> bool;
fn flush(&mut self, client: Option<ClientId>) -> std::io::Result<()>;
fn display_ptr(&self) -> *mut wl_display;
Expand Down Expand Up @@ -1225,6 +1230,26 @@ impl<D: 'static> ErasedState for State<D> {
})
}

fn global_name(&self, global: InnerGlobalId, client: InnerClientId) -> Option<u32> {
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)
}
Expand Down
1 change: 1 addition & 0 deletions wayland-sys/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> (),
Expand Down
Loading