Add tablet map-to-output setting

This commit is contained in:
Ivan Molodetskikh
2023-10-03 17:02:07 +04:00
parent 7bb1c114a2
commit 1bcc889e62
4 changed files with 40 additions and 6 deletions
+8 -1
View File
@@ -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).
+15
View File
@@ -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(),
+2 -4
View File
@@ -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;
};
+15 -1
View File
@@ -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);