Skip to content

Commit f91115f

Browse files
ids1024Drakulix
authored andcommitted
Replace privileged field with a not_sandboxed() method
`privileged` now only indicates if a client is "sandboxed", i.e. it has a security context, where the sandbox engine isn't cosmic-panel. So replace the field with a method that's a bit more descriptive.
1 parent 1bea97d commit f91115f

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/state.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,22 @@ macro_rules! fl {
146146
pub struct ClientState {
147147
pub compositor_client_state: CompositorClientState,
148148
pub advertised_drm_node: Option<DrmNode>,
149-
pub privileged: bool,
150149
pub evls: LoopSignal,
151150
pub security_context: Option<SecurityContext>,
152151
}
152+
153+
impl ClientState {
154+
/// We treat a client as "sandboxed" if it has a security context for any sandbox engine
155+
/// other than `com.system76.CosmicPanel`
156+
pub fn not_sandboxed(&self) -> bool {
157+
self.security_context
158+
.as_ref()
159+
.is_none_or(|security_context| {
160+
security_context.sandbox_engine.as_deref() == Some("com.system76.CosmicPanel")
161+
})
162+
}
163+
}
164+
153165
impl ClientData for ClientState {
154166
fn initialized(&self, _client_id: ClientId) {}
155167
fn disconnected(&self, _client_id: ClientId, _reason: DisconnectReason) {
@@ -575,10 +587,10 @@ pub fn client_has_no_security_context(client: &Client) -> bool {
575587
.is_none_or(|client_state| client_state.security_context.is_none())
576588
}
577589

578-
pub fn client_is_privileged(client: &Client) -> bool {
590+
fn client_not_sandboxed(client: &Client) -> bool {
579591
client
580592
.get_data::<ClientState>()
581-
.is_some_and(|client_state| client_state.privileged)
593+
.is_some_and(|client_state| client_state.not_sandboxed())
582594
}
583595

584596
impl State {
@@ -604,15 +616,15 @@ impl State {
604616
let keyboard_shortcuts_inhibit_state = KeyboardShortcutsInhibitState::new::<Self>(dh);
605617
let output_state = OutputManagerState::new_with_xdg_output::<Self>(dh);
606618
let output_configuration_state =
607-
OutputConfigurationState::new(dh, handle.clone(), client_is_privileged);
608-
let output_power_state = OutputPowerState::new::<Self, _>(dh, client_is_privileged);
619+
OutputConfigurationState::new(dh, handle.clone(), client_not_sandboxed);
620+
let output_power_state = OutputPowerState::new::<Self, _>(dh, client_not_sandboxed);
609621
let overlap_notify_state =
610622
OverlapNotifyState::new::<Self, _>(dh, client_has_no_security_context);
611623
let presentation_state = PresentationState::new::<Self>(dh, clock.id() as u32);
612624
let primary_selection_state = PrimarySelectionState::new::<Self>(dh);
613625
let image_capture_source_state =
614-
ImageCaptureSourceState::new::<Self, _>(dh, client_is_privileged);
615-
let screencopy_state = ScreencopyState::new::<Self, _>(dh, client_is_privileged);
626+
ImageCaptureSourceState::new::<Self, _>(dh, client_not_sandboxed);
627+
let screencopy_state = ScreencopyState::new::<Self, _>(dh, client_not_sandboxed);
616628
let shm_state =
617629
ShmState::new::<Self>(dh, vec![wl_shm::Format::Xbgr8888, wl_shm::Format::Abgr8888]);
618630
let cursor_shape_manager_state = CursorShapeManagerState::new::<State>(dh);
@@ -622,16 +634,16 @@ impl State {
622634
let kde_decoration_state = KdeDecorationState::new::<Self>(dh, Mode::Client);
623635
let xdg_decoration_state = XdgDecorationState::new::<Self>(dh);
624636
let session_lock_manager_state =
625-
SessionLockManagerState::new::<Self, _>(dh, client_is_privileged);
637+
SessionLockManagerState::new::<Self, _>(dh, client_not_sandboxed);
626638
XWaylandKeyboardGrabState::new::<Self>(dh);
627639
let xwayland_shell_state = XWaylandShellState::new::<Self>(dh);
628640
PointerConstraintsState::new::<Self>(dh);
629641
PointerGesturesState::new::<Self>(dh);
630642
TabletManagerState::new::<Self>(dh);
631643
SecurityContextState::new::<Self, _>(dh, client_has_no_security_context);
632-
InputMethodManagerState::new::<Self, _>(dh, client_is_privileged);
644+
InputMethodManagerState::new::<Self, _>(dh, client_not_sandboxed);
633645
TextInputManagerState::new::<Self>(dh);
634-
VirtualKeyboardManagerState::new::<State, _>(dh, client_is_privileged);
646+
VirtualKeyboardManagerState::new::<State, _>(dh, client_not_sandboxed);
635647
AlphaModifierState::new::<Self>(dh);
636648
SinglePixelBufferState::new::<Self>(dh);
637649

@@ -648,7 +660,7 @@ impl State {
648660
let shell = Arc::new(parking_lot::RwLock::new(Shell::new(&config)));
649661

650662
let layer_shell_state =
651-
WlrLayerShellState::new_with_filter::<State, _>(dh, client_is_privileged);
663+
WlrLayerShellState::new_with_filter::<State, _>(dh, client_not_sandboxed);
652664
let xdg_shell_state = XdgShellState::new_with_capabilities::<State>(
653665
dh,
654666
[
@@ -660,7 +672,7 @@ impl State {
660672
);
661673
let xdg_activation_state = XdgActivationState::new::<State>(dh);
662674
let xdg_foreign_state = XdgForeignState::new::<State>(dh);
663-
let toplevel_info_state = ToplevelInfoState::new(dh, client_is_privileged);
675+
let toplevel_info_state = ToplevelInfoState::new(dh, client_not_sandboxed);
664676
let toplevel_management_state = ToplevelManagementState::new::<State, _>(
665677
dh,
666678
vec![
@@ -670,15 +682,15 @@ impl State {
670682
ManagementCapabilities::Minimize,
671683
ManagementCapabilities::MoveToWorkspace,
672684
],
673-
client_is_privileged,
685+
client_not_sandboxed,
674686
);
675-
let workspace_state = WorkspaceState::new(dh, client_is_privileged);
687+
let workspace_state = WorkspaceState::new(dh, client_not_sandboxed);
676688

677689
if let Err(err) = crate::dbus::init(&handle) {
678690
tracing::warn!(?err, "Failed to initialize dbus handlers");
679691
}
680692

681-
let a11y_state = A11yState::new::<State, _>(dh, client_is_privileged);
693+
let a11y_state = A11yState::new::<State, _>(dh, client_not_sandboxed);
682694

683695
// TODO: Restrict to only specific client?
684696
let atspi_state = AtspiState::new::<State, _>(dh, |_| true);
@@ -762,7 +774,6 @@ impl State {
762774
BackendData::Kms(kms_state) => *kms_state.primary_node.read().unwrap(),
763775
_ => None,
764776
},
765-
privileged: true,
766777
evls: self.common.event_loop_signal.clone(),
767778
security_context: None,
768779
}

src/wayland/handlers/security_context.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ impl SecurityContextHandler for State {
4444
client_stream,
4545
Arc::new(ClientState {
4646
security_context: Some(security_context.clone()),
47-
privileged: security_context.sandbox_engine.as_deref()
48-
== Some("com.system76.CosmicPanel"),
4947
advertised_drm_node: drm_node,
5048
..new_state
5149
}),

src/wayland/handlers/xdg_activation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl XdgActivationHandler for State {
3939
})
4040
.and_then(|data| {
4141
data.downcast_ref::<ClientState>()
42-
.map(|data| data.privileged)
42+
.map(|data| data.not_sandboxed())
4343
})
4444
.unwrap_or(false)
4545
{

0 commit comments

Comments
 (0)