Define a advertised_node_for_client instead of duplicating code

Can't use this in `SecurityContextHandler` since it only has a `ClientId`,
not a `Client`.
This commit is contained in:
Ian Douglas Scott 2024-05-14 12:14:04 -07:00 • committed by Victoria Brekenfeld
parent 99fa371ffa
commit 47f8c1da38
2 changed files with 8 additions and 15 deletions

View file

@ -14,12 +14,11 @@ use smithay::{
dmabuf::{DmabufFeedbackBuilder, DmabufGlobal}, dmabuf::{DmabufFeedbackBuilder, DmabufGlobal},
socket::ListeningSocketSource, socket::ListeningSocketSource,
}, },
xwayland::XWaylandClientData,
}; };
use std::sync::Arc; use std::sync::Arc;
use tracing::{info, warn}; use tracing::{info, warn};
use crate::state::{ClientState, State}; use crate::state::{advertised_node_for_client, ClientState, State};
#[derive(Debug)] #[derive(Debug)]
pub struct Socket { pub struct Socket {
@ -48,17 +47,7 @@ impl State {
); );
// initialize globals // initialize globals
let filter = move |client: &Client| { let filter = move |client: &Client| advertised_node_for_client(client) == Some(render_node);
if let Some(normal_client) = client.get_data::<ClientState>() {
let dev_id = normal_client.advertised_drm_node.unwrap();
return dev_id == render_node;
}
if let Some(xwayland_client) = client.get_data::<XWaylandClientData>() {
let dev_id = xwayland_client.user_data().get::<DrmNode>().unwrap();
return *dev_id == render_node;
}
false
};
let feedback = DmabufFeedbackBuilder::new(render_node.dev_id(), formats.clone()) let feedback = DmabufFeedbackBuilder::new(render_node.dev_id(), formats.clone())
.build() .build()

View file

@ -140,9 +140,8 @@ impl ClientData for ClientState {
} }
} }
pub fn advertised_node_for_surface(w: &WlSurface, dh: &DisplayHandle) -> Option<DrmNode> { pub fn advertised_node_for_client(client: &Client) -> Option<DrmNode> {
// Lets check the global drm-node the client got either through default-feedback or wl_drm // Lets check the global drm-node the client got either through default-feedback or wl_drm
let client = dh.get_client(w.id()).ok()?;
if let Some(normal_client) = client.get_data::<ClientState>() { if let Some(normal_client) = client.get_data::<ClientState>() {
return normal_client.advertised_drm_node.clone(); return normal_client.advertised_drm_node.clone();
} }
@ -153,6 +152,11 @@ pub fn advertised_node_for_surface(w: &WlSurface, dh: &DisplayHandle) -> Option<
None None
} }
pub fn advertised_node_for_surface(w: &WlSurface, dh: &DisplayHandle) -> Option<DrmNode> {
let client = dh.get_client(w.id()).ok()?;
advertised_node_for_client(&client)
}
#[derive(Debug)] #[derive(Debug)]
pub struct State { pub struct State {
pub backend: BackendData, pub backend: BackendData,