aboutsummaryrefslogtreecommitdiff
path: root/src/input/mod.rs
diff options
context:
space:
mode:
authorpeelz <peelz.dev@gmail.com>2025-02-05 09:34:25 -0500
committerIvan Molodetskikh <yalterz@gmail.com>2025-03-22 00:03:33 -0700
commitc3609efb7aaa4f118eacdfed7003285f124f6b8a (patch)
tree154241c0942aebcd6d9278896f6b10597bd37595 /src/input/mod.rs
parentfd1f43673cf4d1e84d9da67e294c040934034eda (diff)
downloadniri-c3609efb7aaa4f118eacdfed7003285f124f6b8a.tar.gz
niri-c3609efb7aaa4f118eacdfed7003285f124f6b8a.tar.bz2
niri-c3609efb7aaa4f118eacdfed7003285f124f6b8a.zip
Add mod-key and mod-key-nested settings
Diffstat (limited to 'src/input/mod.rs')
-rw-r--r--src/input/mod.rs134
1 files changed, 50 insertions, 84 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs
index c9677ba2..8fb5acb6 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -6,7 +6,7 @@ use std::time::Duration;
use calloop::timer::{TimeoutAction, Timer};
use input::event::gesture::GestureEventCoordinates as _;
-use niri_config::{Action, Bind, Binds, Key, Modifiers, SwitchBinds, Trigger};
+use niri_config::{Action, Bind, Binds, Key, ModKey, Modifiers, SwitchBinds, Trigger};
use niri_ipc::LayoutSwitchTarget;
use smithay::backend::input::{
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,
@@ -60,12 +60,6 @@ use backend_ext::{NiriInputBackend as InputBackend, NiriInputDevice as _};
pub const DOUBLE_CLICK_TIME: Duration = Duration::from_millis(400);
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum CompositorMod {
- Super,
- Alt,
-}
-
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TabletData {
pub aspect_ratio: f64,
@@ -336,7 +330,7 @@ impl State {
}
fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {
- let comp_mod = self.backend.mod_key();
+ let mod_key = self.backend.mod_key(&self.niri.config.borrow());
let serial = SERIAL_COUNTER.next_serial();
let time = Event::time_msec(&event);
@@ -399,7 +393,7 @@ impl State {
should_intercept_key(
&mut this.niri.suppressed_keys,
bindings,
- comp_mod,
+ mod_key,
key_code,
modified,
raw,
@@ -2118,6 +2112,8 @@ impl State {
let button_state = event.state();
+ let mod_key = self.backend.mod_key(&self.niri.config.borrow());
+
// Ignore release events for mouse clicks that triggered a bind.
if self.niri.suppressed_buttons.remove(&button_code) {
return;
@@ -2128,8 +2124,6 @@ impl State {
let modifiers = modifiers_from_state(mods);
if self.niri.mods_with_mouse_binds.contains(&modifiers) {
- let comp_mod = self.backend.mod_key();
-
if let Some(bind) = match button {
Some(MouseButton::Left) => Some(Trigger::MouseLeft),
Some(MouseButton::Right) => Some(Trigger::MouseRight),
@@ -2141,7 +2135,7 @@ impl State {
.and_then(|trigger| {
let config = self.niri.config.borrow();
let bindings = &config.binds;
- find_configured_bind(bindings, comp_mod, trigger, mods)
+ find_configured_bind(bindings, mod_key, trigger, mods)
}) {
self.niri.suppressed_buttons.insert(button_code);
self.handle_bind(bind.clone());
@@ -2154,10 +2148,7 @@ impl State {
self.niri.tablet_cursor_location = None;
if button == Some(MouseButton::Middle) && !pointer.is_grabbed() {
- let mod_down = match self.backend.mod_key() {
- CompositorMod::Super => mods.logo,
- CompositorMod::Alt => mods.alt,
- };
+ let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());
if mod_down {
if let Some(output) = self.niri.output_under_cursor() {
self.niri.layout.activate_output(&output);
@@ -2189,10 +2180,7 @@ impl State {
// Check if we need to start an interactive move.
if button == Some(MouseButton::Left) && !pointer.is_grabbed() {
- let mod_down = match self.backend.mod_key() {
- CompositorMod::Super => mods.logo,
- CompositorMod::Alt => mods.alt,
- };
+ let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());
if mod_down {
let location = pointer.current_location();
let (output, pos_within_output) = self.niri.output_under(location).unwrap();
@@ -2220,10 +2208,7 @@ impl State {
}
// Check if we need to start an interactive resize.
else if button == Some(MouseButton::Right) && !pointer.is_grabbed() {
- let mod_down = match self.backend.mod_key() {
- CompositorMod::Super => mods.logo,
- CompositorMod::Alt => mods.alt,
- };
+ let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());
if mod_down {
let location = pointer.current_location();
let (output, pos_within_output) = self.niri.output_under(location).unwrap();
@@ -2353,6 +2338,8 @@ impl State {
let source = event.source();
+ let mod_key = self.backend.mod_key(&self.niri.config.borrow());
+
// We received an event for the regular pointer, so show it now. This is also needed for
// update_pointer_contents() below to return the real contents, necessary for the pointer
// axis event to reach the window.
@@ -2369,17 +2356,15 @@ impl State {
let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
let modifiers = modifiers_from_state(mods);
if self.niri.mods_with_wheel_binds.contains(&modifiers) {
- let comp_mod = self.backend.mod_key();
-
let horizontal = horizontal_amount_v120.unwrap_or(0.);
let ticks = self.niri.horizontal_wheel_tracker.accumulate(horizontal);
if ticks != 0 {
let config = self.niri.config.borrow();
let bindings = &config.binds;
let bind_left =
- find_configured_bind(bindings, comp_mod, Trigger::WheelScrollLeft, mods);
+ find_configured_bind(bindings, mod_key, Trigger::WheelScrollLeft, mods);
let bind_right =
- find_configured_bind(bindings, comp_mod, Trigger::WheelScrollRight, mods);
+ find_configured_bind(bindings, mod_key, Trigger::WheelScrollRight, mods);
drop(config);
if let Some(right) = bind_right {
@@ -2400,9 +2385,9 @@ impl State {
let config = self.niri.config.borrow();
let bindings = &config.binds;
let bind_up =
- find_configured_bind(bindings, comp_mod, Trigger::WheelScrollUp, mods);
+ find_configured_bind(bindings, mod_key, Trigger::WheelScrollUp, mods);
let bind_down =
- find_configured_bind(bindings, comp_mod, Trigger::WheelScrollDown, mods);
+ find_configured_bind(bindings, mod_key, Trigger::WheelScrollDown, mods);
drop(config);
if let Some(down) = bind_down {
@@ -2432,8 +2417,6 @@ impl State {
let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
let modifiers = modifiers_from_state(mods);
if self.niri.mods_with_finger_scroll_binds.contains(&modifiers) {
- let comp_mod = self.backend.mod_key();
-
let horizontal = horizontal_amount.unwrap_or(0.);
let ticks = self
.niri
@@ -2443,13 +2426,9 @@ impl State {
let config = self.niri.config.borrow();
let bindings = &config.binds;
let bind_left =
- find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollLeft, mods);
- let bind_right = find_configured_bind(
- bindings,
- comp_mod,
- Trigger::TouchpadScrollRight,
- mods,
- );
+ find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollLeft, mods);
+ let bind_right =
+ find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollRight, mods);
drop(config);
if let Some(right) = bind_right {
@@ -2473,9 +2452,9 @@ impl State {
let config = self.niri.config.borrow();
let bindings = &config.binds;
let bind_up =
- find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollUp, mods);
+ find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollUp, mods);
let bind_down =
- find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollDown, mods);
+ find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollDown, mods);
drop(config);
if let Some(down) = bind_down {
@@ -2987,16 +2966,15 @@ impl State {
let under = self.niri.contents_under(touch_location);
+ let mod_key = self.backend.mod_key(&self.niri.config.borrow());
+
if !handle.is_grabbed() {
if let Some((window, _)) = under.window {
self.niri.layout.activate_window(&window);
// Check if we need to start an interactive move.
let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
- let mod_down = match self.backend.mod_key() {
- CompositorMod::Super => mods.logo,
- CompositorMod::Alt => mods.alt,
- };
+ let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());
if mod_down {
let (output, pos_within_output) =
self.niri.output_under(touch_location).unwrap();
@@ -3129,7 +3107,7 @@ impl State {
fn should_intercept_key(
suppressed_keys: &mut HashSet<Keycode>,
bindings: &Binds,
- comp_mod: CompositorMod,
+ mod_key: ModKey,
key_code: Keycode,
modified: Keysym,
raw: Option<Keysym>,
@@ -3148,7 +3126,7 @@ fn should_intercept_key(
let mut final_bind = find_bind(
bindings,
- comp_mod,
+ mod_key,
modified,
raw,
mods,
@@ -3212,7 +3190,7 @@ fn should_intercept_key(
fn find_bind(
bindings: &Binds,
- comp_mod: CompositorMod,
+ mod_key: ModKey,
modified: Keysym,
raw: Option<Keysym>,
mods: ModifiersState,
@@ -3253,22 +3231,19 @@ fn find_bind(
}
let trigger = Trigger::Keysym(raw?);
- find_configured_bind(bindings, comp_mod, trigger, mods)
+ find_configured_bind(bindings, mod_key, trigger, mods)
}
fn find_configured_bind(
bindings: &Binds,
- comp_mod: CompositorMod,
+ mod_key: ModKey,
trigger: Trigger,
mods: ModifiersState,
) -> Option<Bind> {
// Handle configured binds.
let mut modifiers = modifiers_from_state(mods);
- let (mod_down, comp_mod) = match comp_mod {
- CompositorMod::Super => (mods.logo, Modifiers::SUPER),
- CompositorMod::Alt => (mods.alt, Modifiers::ALT),
- };
+ let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());
if mod_down {
modifiers |= Modifiers::COMPOSITOR;
}
@@ -3280,8 +3255,8 @@ fn find_configured_bind(
let mut bind_modifiers = bind.key.modifiers;
if bind_modifiers.contains(Modifiers::COMPOSITOR) {
- bind_modifiers |= comp_mod;
- } else if bind_modifiers.contains(comp_mod) {
+ bind_modifiers |= mod_key.to_modifiers();
+ } else if bind_modifiers.contains(mod_key.to_modifiers()) {
bind_modifiers |= Modifiers::COMPOSITOR;
}
@@ -3661,16 +3636,7 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input::
}
}
-pub fn mods_with_binds(
- comp_mod: CompositorMod,
- binds: &Binds,
- triggers: &[Trigger],
-) -> HashSet<Modifiers> {
- let comp_mod = match comp_mod {
- CompositorMod::Super => Modifiers::SUPER,
- CompositorMod::Alt => Modifiers::ALT,
- };
-
+pub fn mods_with_binds(mod_key: ModKey, binds: &Binds, triggers: &[Trigger]) -> HashSet<Modifiers> {
let mut rv = HashSet::new();
for bind in &binds.0 {
if !triggers.iter().any(|trigger| bind.key.trigger == *trigger) {
@@ -3680,7 +3646,7 @@ pub fn mods_with_binds(
let mut mods = bind.key.modifiers;
if mods.contains(Modifiers::COMPOSITOR) {
mods.remove(Modifiers::COMPOSITOR);
- mods.insert(comp_mod);
+ mods.insert(mod_key.to_modifiers());
}
rv.insert(mods);
@@ -3689,9 +3655,9 @@ pub fn mods_with_binds(
rv
}
-pub fn mods_with_mouse_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<Modifiers> {
+pub fn mods_with_mouse_binds(mod_key: ModKey, binds: &Binds) -> HashSet<Modifiers> {
mods_with_binds(
- comp_mod,
+ mod_key,
binds,
&[
Trigger::MouseLeft,
@@ -3703,9 +3669,9 @@ pub fn mods_with_mouse_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<
)
}
-pub fn mods_with_wheel_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<Modifiers> {
+pub fn mods_with_wheel_binds(mod_key: ModKey, binds: &Binds) -> HashSet<Modifiers> {
mods_with_binds(
- comp_mod,
+ mod_key,
binds,
&[
Trigger::WheelScrollUp,
@@ -3716,9 +3682,9 @@ pub fn mods_with_wheel_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<
)
}
-pub fn mods_with_finger_scroll_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<Modifiers> {
+pub fn mods_with_finger_scroll_binds(mod_key: ModKey, binds: &Binds) -> HashSet<Modifiers> {
mods_with_binds(
- comp_mod,
+ mod_key,
binds,
&[
Trigger::TouchpadScrollUp,
@@ -3752,7 +3718,7 @@ mod tests {
hotkey_overlay_title: None,
}]);
- let comp_mod = CompositorMod::Super;
+ let comp_mod = ModKey::Super;
let mut suppressed_keys = HashSet::new();
let screenshot_ui = ScreenshotUi::new(Clock::default(), Default::default());
@@ -3990,7 +3956,7 @@ mod tests {
assert_eq!(
find_configured_bind(
&bindings,
- CompositorMod::Super,
+ ModKey::Super,
Trigger::Keysym(Keysym::q),
ModifiersState {
logo: true,
@@ -4003,7 +3969,7 @@ mod tests {
assert_eq!(
find_configured_bind(
&bindings,
- CompositorMod::Super,
+ ModKey::Super,
Trigger::Keysym(Keysym::q),
ModifiersState::default(),
),
@@ -4013,7 +3979,7 @@ mod tests {
assert_eq!(
find_configured_bind(
&bindings,
- CompositorMod::Super,
+ ModKey::Super,
Trigger::Keysym(Keysym::h),
ModifiersState {
logo: true,
@@ -4026,7 +3992,7 @@ mod tests {
assert_eq!(
find_configured_bind(
&bindings,
- CompositorMod::Super,
+ ModKey::Super,
Trigger::Keysym(Keysym::h),
ModifiersState::default(),
),
@@ -4036,7 +4002,7 @@ mod tests {
assert_eq!(
find_configured_bind(
&bindings,
- CompositorMod::Super,
+ ModKey::Super,
Trigger::Keysym(Keysym::j),
ModifiersState {
logo: true,
@@ -4048,7 +4014,7 @@ mod tests {
assert_eq!(
find_configured_bind(
&bindings,
- CompositorMod::Super,
+ ModKey::Super,
Trigger::Keysym(Keysym::j),
ModifiersState::default(),
)
@@ -4059,7 +4025,7 @@ mod tests {
assert_eq!(
find_configured_bind(
&bindings,
- CompositorMod::Super,
+ ModKey::Super,
Trigger::Keysym(Keysym::k),
ModifiersState {
logo: true,
@@ -4072,7 +4038,7 @@ mod tests {
assert_eq!(
find_configured_bind(
&bindings,
- CompositorMod::Super,
+ ModKey::Super,
Trigger::Keysym(Keysym::k),
ModifiersState::default(),
),
@@ -4082,7 +4048,7 @@ mod tests {
assert_eq!(
find_configured_bind(
&bindings,
- CompositorMod::Super,
+ ModKey::Super,
Trigger::Keysym(Keysym::l),
ModifiersState {
logo: true,
@@ -4096,7 +4062,7 @@ mod tests {
assert_eq!(
find_configured_bind(
&bindings,
- CompositorMod::Super,
+ ModKey::Super,
Trigger::Keysym(Keysym::l),
ModifiersState {
logo: true,