2023-08-29 17:00:11 -07:00
|
|
|
use crate::state::{ClientState, State};
|
|
|
|
|
use smithay::{
|
2023-11-06 18:35:47 +01:00
|
|
|
backend::drm::DrmNode,
|
2023-08-29 17:00:11 -07:00
|
|
|
delegate_security_context,
|
|
|
|
|
wayland::security_context::{
|
|
|
|
|
SecurityContext, SecurityContextHandler, SecurityContextListenerSource,
|
|
|
|
|
},
|
2023-11-06 18:35:47 +01:00
|
|
|
xwayland::XWaylandClientData,
|
2023-08-29 17:00:11 -07:00
|
|
|
};
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use tracing::warn;
|
|
|
|
|
|
|
|
|
|
impl SecurityContextHandler for State {
|
|
|
|
|
fn context_created(
|
|
|
|
|
&mut self,
|
|
|
|
|
source: SecurityContextListenerSource,
|
|
|
|
|
security_context: SecurityContext,
|
|
|
|
|
) {
|
|
|
|
|
self.common
|
|
|
|
|
.event_loop_handle
|
2023-09-29 21:33:16 +02:00
|
|
|
.insert_source(source, move |client_stream, _, state| {
|
2023-11-06 18:35:47 +01:00
|
|
|
let client_data = state
|
|
|
|
|
.common
|
|
|
|
|
.display_handle
|
|
|
|
|
.backend_handle()
|
|
|
|
|
.get_client_data(security_context.creator_client_id.clone())
|
|
|
|
|
.ok();
|
|
|
|
|
|
|
|
|
|
let privileged = client_data
|
|
|
|
|
.as_ref()
|
|
|
|
|
.and_then(|data| data.downcast_ref::<ClientState>())
|
|
|
|
|
.map(|data| data.privileged)
|
|
|
|
|
.unwrap_or(false);
|
|
|
|
|
|
|
|
|
|
let drm_node = client_data
|
|
|
|
|
.as_ref()
|
|
|
|
|
.and_then(|data| data.downcast_ref::<ClientState>())
|
|
|
|
|
.and_then(|data| data.drm_node.clone())
|
|
|
|
|
.or_else(|| {
|
|
|
|
|
client_data
|
|
|
|
|
.as_ref()
|
|
|
|
|
.and_then(|data| data.downcast_ref::<XWaylandClientData>())
|
|
|
|
|
.and_then(|data| data.user_data().get::<DrmNode>().cloned())
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-29 21:33:16 +02:00
|
|
|
if let Err(err) = state.common.display_handle.insert_client(
|
2023-08-29 17:00:11 -07:00
|
|
|
client_stream,
|
|
|
|
|
Arc::new(ClientState {
|
|
|
|
|
security_context: Some(security_context.clone()),
|
2023-11-06 18:35:47 +01:00
|
|
|
privileged: privileged
|
|
|
|
|
&& security_context.sandbox_engine.as_deref()
|
|
|
|
|
== Some("com.system76.CosmicPanel"),
|
|
|
|
|
drm_node,
|
2023-09-29 21:33:16 +02:00
|
|
|
..state.new_client_state()
|
2023-08-29 17:00:11 -07:00
|
|
|
}),
|
|
|
|
|
) {
|
|
|
|
|
warn!(?err, "Error adding wayland client");
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
.expect("Failed to init the wayland socket source.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delegate_security_context!(State);
|