Skip to content

Commit

Permalink
Add clipboard disable-primary setting
Browse files Browse the repository at this point in the history
  • Loading branch information
notpeelz committed Jan 22, 2025
1 parent 7f025da commit 257353e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
15 changes: 15 additions & 0 deletions niri-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct Config {
]
pub screenshot_path: Option<String>,
#[knuffel(child, default)]
pub clipboard: Clipboard,
#[knuffel(child, default)]
pub hotkey_overlay: HotkeyOverlay,
#[knuffel(child, default)]
pub animations: Animations,
Expand Down Expand Up @@ -785,6 +787,12 @@ pub struct HotkeyOverlay {
pub skip_at_startup: bool,
}

#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Clipboard {
#[knuffel(child)]
pub disable_primary: bool,
}

#[derive(knuffel::Decode, Debug, Clone, PartialEq)]
pub struct Animations {
#[knuffel(child)]
Expand Down Expand Up @@ -3423,6 +3431,10 @@ mod tests {
screenshot-path "~/Screenshots/screenshot.png"
clipboard {
disable-primary
}
hotkey-overlay {
skip-at-startup
}
Expand Down Expand Up @@ -3677,6 +3689,9 @@ mod tests {
hide_after_inactive_ms: Some(3000),
},
screenshot_path: Some(String::from("~/Screenshots/screenshot.png")),
clipboard: Clipboard {
disable_primary: true,
},
hotkey_overlay: HotkeyOverlay {
skip_at_startup: true,
},
Expand Down
1 change: 1 addition & 0 deletions src/dbus/mutter_service_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl ServiceChannel {
compositor_state: Default::default(),
// Would be nice to thread config here but for now it's fine.
can_view_decoration_globals: false,
primary_selection_disabled: false,
restricted: false,
// FIXME: maybe you can get the PID from D-Bus somehow?
credentials_unknown: true,
Expand Down
1 change: 1 addition & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ impl SecurityContextHandler for State {
let data = Arc::new(ClientState {
compositor_state: Default::default(),
can_view_decoration_globals: config.prefer_no_csd,
primary_selection_disabled: config.clipboard.disable_primary,
restricted: true,
credentials_unknown: false,
});
Expand Down
11 changes: 10 additions & 1 deletion src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,12 +1807,19 @@ impl Niri {
let idle_notifier_state = IdleNotifierState::new(&display_handle, event_loop.clone());
let idle_inhibit_manager_state = IdleInhibitManagerState::new::<State>(&display_handle);
let data_device_state = DataDeviceState::new::<State>(&display_handle);
let primary_selection_state = PrimarySelectionState::new::<State>(&display_handle);
let primary_selection_state =
PrimarySelectionState::new::<State, _>(&display_handle, |client| {
!client
.get_data::<ClientState>()
.unwrap()
.primary_selection_disabled
});
let data_control_state = DataControlState::new::<State, _>(
&display_handle,
Some(&primary_selection_state),
|client| !client.get_data::<ClientState>().unwrap().restricted,
);

let presentation_state =
PresentationState::new::<State>(&display_handle, Monotonic::ID as u32);
let security_context_state =
Expand Down Expand Up @@ -1927,6 +1934,7 @@ impl Niri {
let data = Arc::new(ClientState {
compositor_state: Default::default(),
can_view_decoration_globals: config.prefer_no_csd,
primary_selection_disabled: config.clipboard.disable_primary,
restricted: false,
credentials_unknown: false,
});
Expand Down Expand Up @@ -5126,6 +5134,7 @@ impl Niri {
pub struct ClientState {
pub compositor_state: CompositorClientState,
pub can_view_decoration_globals: bool,
pub primary_selection_disabled: bool,
/// Whether this client is denied from the restricted protocols such as security-context.
pub restricted: bool,
/// We cannot retrieve this client's socket credentials.
Expand Down

0 comments on commit 257353e

Please sign in to comment.