aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-10-03 17:02:07 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-10-03 17:02:07 +0400
commit1bcc889e6232515a12f38738418586f03ea8c8c6 (patch)
tree7d48643d6a1656b01b78dd26883f3b39dbe95bdf
parent7bb1c114a2f29f339f547e226cfd7d3af47f414f (diff)
downloadniri-1bcc889e6232515a12f38738418586f03ea8c8c6.tar.gz
niri-1bcc889e6232515a12f38738418586f03ea8c8c6.tar.bz2
niri-1bcc889e6232515a12f38738418586f03ea8c8c6.zip
Add tablet map-to-output setting
-rw-r--r--resources/default-config.kdl9
-rw-r--r--src/config.rs15
-rw-r--r--src/input.rs6
-rw-r--r--src/niri.rs16
4 files changed, 40 insertions, 6 deletions
diff --git a/resources/default-config.kdl b/resources/default-config.kdl
index a6e3667e..11d225cb 100644
--- a/resources/default-config.kdl
+++ b/resources/default-config.kdl
@@ -18,13 +18,20 @@ input {
// repeat-rate 25
}
- // Next sections contain libinput settings.
+ // Next sections include libinput settings.
// Omitting settings disables them, or leaves them at their default values.
touchpad {
tap
natural-scroll
// accel-speed 0.2
}
+
+ tablet {
+ // Set the name of the output (see below) which the tablet will map to.
+ // If this is unset or the output doesn't exist, the tablet maps to one of the
+ // existing outputs.
+ map-to-output "eDP-1"
+ }
}
// You can configure outputs by their name, which you can find with wayland-info(1).
diff --git a/src/config.rs b/src/config.rs
index 9f73518b..730a0f4b 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -35,6 +35,8 @@ pub struct Input {
pub keyboard: Keyboard,
#[knuffel(child, default)]
pub touchpad: Touchpad,
+ #[knuffel(child, default)]
+ pub tablet: Tablet,
}
#[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)]
@@ -73,6 +75,12 @@ pub struct Touchpad {
pub accel_speed: f64,
}
+#[derive(knuffel::Decode, Debug, Default, PartialEq)]
+pub struct Tablet {
+ #[knuffel(child, unwrap(argument))]
+ pub map_to_output: Option<String>,
+}
+
#[derive(knuffel::Decode, Debug, Clone, PartialEq)]
pub struct Output {
#[knuffel(argument)]
@@ -478,6 +486,10 @@ mod tests {
tap
accel-speed 0.2
}
+
+ tablet {
+ map-to-output "eDP-1"
+ }
}
output "eDP-1" {
@@ -530,6 +542,9 @@ mod tests {
natural_scroll: false,
accel_speed: 0.2,
},
+ tablet: Tablet {
+ map_to_output: Some("eDP-1".to_owned()),
+ },
},
outputs: vec![Output {
name: "eDP-1".to_owned(),
diff --git a/src/input.rs b/src/input.rs
index d40221b8..b76a98af 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -472,8 +472,7 @@ impl State {
pointer.frame(self);
}
InputEvent::TabletToolAxis { event, .. } => {
- // FIXME: allow mapping tablet to different outputs.
- let Some(output) = self.niri.global_space.outputs().next() else {
+ let Some(output) = self.niri.output_for_tablet() else {
return;
};
@@ -560,8 +559,7 @@ impl State {
}
}
InputEvent::TabletToolProximity { event, .. } => {
- // FIXME: allow mapping tablet to different outputs.
- let Some(output) = self.niri.global_space.outputs().next() else {
+ let Some(output) = self.niri.output_for_tablet() else {
return;
};
diff --git a/src/niri.rs b/src/niri.rs
index 45c01d7b..68ce44e2 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -105,6 +105,7 @@ pub struct Niri {
pub unmapped_windows: HashMap<WlSurface, Window>,
pub output_state: HashMap<Output, OutputState>,
+ pub output_by_name: HashMap<String, Output>,
// Smithay state.
pub compositor_state: CompositorState,
@@ -679,6 +680,7 @@ impl Niri {
monitor_set: MonitorSet::new(),
global_space: Space::default(),
output_state: HashMap::new(),
+ output_by_name: HashMap::new(),
unmapped_windows: HashMap::new(),
compositor_state,
@@ -787,7 +789,9 @@ impl Niri {
frame_clock: FrameClock::new(refresh_interval),
current_estimated_sequence: None,
};
- let rv = self.output_state.insert(output, state);
+ let rv = self.output_state.insert(output.clone(), state);
+ assert!(rv.is_none(), "output was already tracked");
+ let rv = self.output_by_name.insert(name, output);
assert!(rv.is_none(), "output was already tracked");
}
@@ -797,6 +801,8 @@ impl Niri {
// FIXME: reposition outputs so they are adjacent.
let state = self.output_state.remove(output).unwrap();
+ self.output_by_name.remove(&output.name()).unwrap();
+
match state.redraw_state {
RedrawState::Idle => (),
RedrawState::Queued(idle) => idle.cancel(),
@@ -950,6 +956,14 @@ impl Niri {
.cloned()
}
+ pub fn output_for_tablet(&self) -> Option<&Output> {
+ let config = self.config.borrow();
+ let map_to_output = config.input.tablet.map_to_output.as_ref();
+ map_to_output
+ .and_then(|name| self.output_by_name.get(name))
+ .or_else(|| self.global_space.outputs().next())
+ }
+
fn layer_surface_focus(&self) -> Option<WlSurface> {
let output = self.monitor_set.active_output()?;
let layers = layer_map_for_output(output);