1
0
Fork 0
forked from wry/wry

Merge pull request #525 from mahkoh/jorth/disable-primary-selection

config: allow disabling the primary selection
This commit is contained in:
mahkoh 2025-07-20 11:22:26 +02:00 committed by GitHub
commit e30e2595a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 63 additions and 2 deletions

View file

@ -983,6 +983,10 @@ impl ConfigClient {
show
}
pub fn set_middle_click_paste_enabled(&self, enabled: bool) {
self.send(&ClientMessage::SetMiddleClickPasteEnabled { enabled });
}
pub fn set_show_float_pin_icon(&self, show: bool) {
self.send(&ClientMessage::SetShowFloatPinIcon { show });
}

View file

@ -744,6 +744,9 @@ pub enum ClientMessage<'a> {
SeatFocusTiles {
seat: Seat,
},
SetMiddleClickPasteEnabled {
enabled: bool,
},
}
#[derive(Serialize, Deserialize, Debug)]

View file

@ -343,3 +343,13 @@ pub fn toggle_show_bar() {
pub fn on_unload(f: impl FnOnce() + 'static) {
get!().on_unload(f);
}
/// Enables or disables middle-click pasting.
///
/// This has no effect on applications that are already running.
///
/// The default is `true`.
#[doc(alias("primary-selection", "primary_selection"))]
pub fn set_middle_click_paste_enabled(enabled: bool) {
get!().set_middle_click_paste_enabled(enabled);
}

View file

@ -352,6 +352,7 @@ fn start_compositor2(
head_managers: Default::default(),
head_managers_async: Default::default(),
show_bar: Cell::new(true),
enable_primary_selection: Cell::new(true),
});
state.tracker.register(ClientId::from_raw(0));
create_dummy_output(&state);

View file

@ -2204,6 +2204,10 @@ impl ConfigProxyHandler {
Ok(())
}
fn handle_set_middle_click_paste_enabled(&self, enabled: bool) {
self.state.enable_primary_selection.set(enabled);
}
fn spaces_change(&self) {
struct V;
impl NodeVisitorBase for V {
@ -3064,6 +3068,9 @@ impl ConfigProxyHandler {
ClientMessage::SeatFocusTiles { seat } => {
self.handle_seat_focus_tiles(seat).wrn("seat_focus_tiles")?
}
ClientMessage::SetMiddleClickPasteEnabled { enabled } => {
self.handle_set_middle_click_paste_enabled(enabled)
}
}
Ok(())
}

View file

@ -8,6 +8,7 @@ use {
},
leaks::Tracker,
object::{Object, Version},
state::State,
wire::{ZwpPrimarySelectionDeviceManagerV1Id, zwp_primary_selection_device_manager_v1::*},
},
std::rc::Rc,
@ -96,6 +97,10 @@ impl Global for ZwpPrimarySelectionDeviceManagerV1Global {
fn version(&self) -> u32 {
1
}
fn exposed(&self, state: &State) -> bool {
state.enable_primary_selection.get()
}
}
simple_add_global!(ZwpPrimarySelectionDeviceManagerV1Global);

View file

@ -272,6 +272,7 @@ pub struct State {
CopyHashMap<(ClientId, JayHeadManagerSessionV1Id), Rc<JayHeadManagerSessionV1>>,
pub head_managers_async: AsyncQueue<HeadManagerEvent>,
pub show_bar: Cell<bool>,
pub enable_primary_selection: Cell<bool>,
}
// impl Drop for State {

View file

@ -494,6 +494,7 @@ pub struct Config {
pub use_hardware_cursor: Option<bool>,
pub show_bar: Option<bool>,
pub focus_history: Option<FocusHistory>,
pub middle_click_paste: Option<bool>,
}
#[derive(Debug, Error)]

View file

@ -136,6 +136,7 @@ impl Parser for ConfigParser<'_> {
show_bar,
focus_history_val,
),
(middle_click_paste,),
) = ext.extract((
(
opt(val("keymap")),
@ -185,6 +186,7 @@ impl Parser for ConfigParser<'_> {
recover(opt(bol("show-bar"))),
opt(val("focus-history")),
),
(recover(opt(bol("middle-click-paste"))),),
))?;
let mut keymap = None;
if let Some(value) = keymap_val {
@ -513,6 +515,7 @@ impl Parser for ConfigParser<'_> {
use_hardware_cursor: use_hardware_cursor.despan(),
show_bar: show_bar.despan(),
focus_history,
middle_click_paste: middle_click_paste.despan(),
})
}
}

View file

@ -35,8 +35,8 @@ use {
logging::set_log_level,
on_devices_enumerated, on_idle, on_unload, quit, reload, set_color_management_enabled,
set_default_workspace_capture, set_explicit_sync_enabled, set_float_above_fullscreen,
set_idle, set_idle_grace_period, set_show_bar, set_show_float_pin_icon,
set_ui_drag_enabled, set_ui_drag_threshold,
set_idle, set_idle_grace_period, set_middle_click_paste_enabled, set_show_bar,
set_show_float_pin_icon, set_ui_drag_enabled, set_ui_drag_threshold,
status::{set_i3bar_separator, set_status, set_status_command, unset_status_command},
switch_to_vt,
theme::{reset_colors, reset_font, reset_sizes, set_font},
@ -1272,6 +1272,9 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
persistent.seat.focus_history_set_same_workspace(v);
}
}
if let Some(v) = config.middle_click_paste {
set_middle_click_paste_enabled(v);
}
}
fn create_command(exec: &Exec) -> Command {

View file

@ -891,6 +891,10 @@
"focus-history": {
"description": "Configures the focus-history settings.\n\n- Example:\n\n ```toml\n [focus-history]\n only-visible: true\n same-workspace: true\n ```\n",
"$ref": "#/$defs/FocusHistory"
},
"middle-click-paste": {
"type": "boolean",
"description": "Configures whether middle-click pasting is enabled.\n\nChanging this has no effect on running applications.\n\nThe default is `true`.\n"
}
},
"required": []

View file

@ -1816,6 +1816,16 @@ The table has the following fields:
The value of this field should be a [FocusHistory](#types-FocusHistory).
- `middle-click-paste` (optional):
Configures whether middle-click pasting is enabled.
Changing this has no effect on running applications.
The default is `true`.
The value of this field should be a boolean.
<a name="types-Connector"></a>
### `Connector`

View file

@ -2650,6 +2650,15 @@ Config:
only-visible: true
same-workspace: true
```
middle-click-paste:
kind: boolean
required: false
description: |
Configures whether middle-click pasting is enabled.
Changing this has no effect on running applications.
The default is `true`.
Idle: