Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions docs/wiki/Configuration:-Input.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,30 @@ input {
touch {
// off
map-to-output "eDP-1"
// natural-scroll
// calibration-matrix 1.0 0.0 0.0 0.0 1.0 0.0

gestures {
workspace-switch {
// off
// finger-count 3
// sensitivity 0.4
// natural-scroll
}
view-scroll {
// off
// finger-count 3
// sensitivity 0.4
// natural-scroll
}
overview-toggle {
// off
// finger-count 4
// sensitivity 0.4
// natural-scroll
}
// recognition-threshold 16.0
}
}

// disable-power-key-handling
Expand Down Expand Up @@ -263,6 +286,27 @@ Settings specific to `tablet` and `touch`:
- <sup>Since: 25.02</sup> for `tablet`
- <sup>Since: 25.11</sup> for `touch`

Settings specific to `touch`:

- `natural-scroll`: <sup>Since: next</sup> if set, inverts the scrolling direction for touchscreen gestures (workspace switching and view scrolling).
- `gestures {}`: <sup>Since: next</sup> configure touchscreen multi-finger gestures:
- `workspace-switch {}`: 3-finger vertical swipe to switch workspaces.
- `off`: disable this gesture.
- `finger-count <int>`: number of fingers required (default: 3).
- `sensitivity <float>`: speed multiplier (default: 0.4).
- `natural-scroll`: if set, inverts direction for this gesture (inherits from touch-level `natural-scroll` if not set).
- `view-scroll {}`: 3-finger horizontal swipe to scroll between columns.
- `off`: disable this gesture.
- `finger-count <int>`: number of fingers required (default: 3).
- `sensitivity <float>`: speed multiplier (default: 0.4).
- `natural-scroll`: if set, inverts direction for this gesture (inherits from touch-level `natural-scroll` if not set).
- `overview-toggle {}`: 4-finger vertical swipe to toggle the overview.
- `off`: disable this gesture.
- `finger-count <int>`: number of fingers required (default: 4).
- `sensitivity <float>`: speed multiplier (default: 0.4).
- `natural-scroll`: if set, inverts direction for this gesture (inherits from touch-level `natural-scroll` if not set).
- `recognition-threshold <float>`: distance in pixels before a gesture direction is locked (default: 16.0).

Tablets and touchscreens are absolute pointing devices that can be mapped to a specific output like so:

```kdl
Expand Down
129 changes: 128 additions & 1 deletion niri-config/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub struct ScrollFactor {

impl ScrollFactor {
pub fn h_v_factors(&self) -> (f64, f64) {
let base_value = self.base.map(|f| f.0).unwrap_or(1.0);
let base_value = self.base.map(|f| f.0).unwrap_or(0.4);
let h = self.horizontal.map(|f| f.0).unwrap_or(base_value);
let v = self.vertical.map(|f| f.0).unwrap_or(base_value);
(h, v)
Expand Down Expand Up @@ -371,10 +371,137 @@ pub struct Tablet {
pub struct Touch {
#[knuffel(child)]
pub off: bool,
#[knuffel(child)]
pub natural_scroll: bool,
#[knuffel(child, unwrap(arguments))]
pub calibration_matrix: Option<Vec<f32>>,
#[knuffel(child, unwrap(argument))]
pub map_to_output: Option<String>,
#[knuffel(child)]
pub gestures: Option<TouchGesturesConfig>,
}

impl Touch {
pub fn gesture_threshold(&self) -> f64 {
self.gestures
.as_ref()
.and_then(|g| g.recognition_threshold)
.unwrap_or(16.0)
}

pub fn workspace_switch_enabled(&self) -> bool {
self.gestures
.as_ref()
.and_then(|g| g.workspace_switch.as_ref())
.map_or(true, |a| !a.off)
}

pub fn workspace_switch_fingers(&self) -> usize {
self.gestures
.as_ref()
.and_then(|g| g.workspace_switch.as_ref())
.and_then(|a| a.finger_count)
.unwrap_or(3) as usize
}

pub fn workspace_switch_sensitivity(&self) -> f64 {
self.gestures
.as_ref()
.and_then(|g| g.workspace_switch.as_ref())
.and_then(|a| a.sensitivity)
.unwrap_or(0.4)
}

pub fn workspace_switch_natural_scroll(&self) -> bool {
self.gestures
.as_ref()
.and_then(|g| g.workspace_switch.as_ref())
.map_or(self.natural_scroll, |a| a.natural_scroll || self.natural_scroll)
}

pub fn view_scroll_enabled(&self) -> bool {
self.gestures
.as_ref()
.and_then(|g| g.view_scroll.as_ref())
.map_or(true, |a| !a.off)
}

pub fn view_scroll_fingers(&self) -> usize {
self.gestures
.as_ref()
.and_then(|g| g.view_scroll.as_ref())
.and_then(|a| a.finger_count)
.unwrap_or(3) as usize
}

pub fn view_scroll_sensitivity(&self) -> f64 {
self.gestures
.as_ref()
.and_then(|g| g.view_scroll.as_ref())
.and_then(|a| a.sensitivity)
.unwrap_or(0.4)
}

pub fn view_scroll_natural_scroll(&self) -> bool {
self.gestures
.as_ref()
.and_then(|g| g.view_scroll.as_ref())
.map_or(self.natural_scroll, |a| a.natural_scroll || self.natural_scroll)
}

pub fn overview_toggle_enabled(&self) -> bool {
self.gestures
.as_ref()
.and_then(|g| g.overview_toggle.as_ref())
.map_or(true, |a| !a.off)
}

pub fn overview_toggle_fingers(&self) -> usize {
self.gestures
.as_ref()
.and_then(|g| g.overview_toggle.as_ref())
.and_then(|a| a.finger_count)
.unwrap_or(4) as usize
}

pub fn overview_toggle_sensitivity(&self) -> f64 {
self.gestures
.as_ref()
.and_then(|g| g.overview_toggle.as_ref())
.and_then(|a| a.sensitivity)
.unwrap_or(0.4)
}

pub fn overview_toggle_natural_scroll(&self) -> bool {
self.gestures
.as_ref()
.and_then(|g| g.overview_toggle.as_ref())
.map_or(self.natural_scroll, |a| a.natural_scroll || self.natural_scroll)
}
}

#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
pub struct TouchGesturesConfig {
#[knuffel(child)]
pub workspace_switch: Option<TouchGestureActionConfig>,
#[knuffel(child)]
pub view_scroll: Option<TouchGestureActionConfig>,
#[knuffel(child)]
pub overview_toggle: Option<TouchGestureActionConfig>,
#[knuffel(child, unwrap(argument))]
pub recognition_threshold: Option<f64>,
}

#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
pub struct TouchGestureActionConfig {
#[knuffel(child)]
pub off: bool,
#[knuffel(child, unwrap(argument))]
pub finger_count: Option<u8>,
#[knuffel(child, unwrap(argument))]
pub sensitivity: Option<f64>,
#[knuffel(child)]
pub natural_scroll: bool,
}

#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
Expand Down
24 changes: 24 additions & 0 deletions resources/default-config.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ input {
// middle-emulation
}

// touch {
// // off
// // natural-scroll
// // map-to-output "eDP-1"
// // gestures {
// // workspace-switch {
// // // off
// // finger-count 3
// // sensitivity 0.4
// // }
// // view-scroll {
// // // off
// // finger-count 3
// // sensitivity 0.4
// // }
// // overview-toggle {
// // // off
// // finger-count 4
// // sensitivity 0.4
// // }
// // recognition-threshold 16.0
// // }
// }

// Uncomment this to make the mouse warp to the center of newly focused windows.
// warp-mouse-to-focus

Expand Down
Loading