forge
Explore
Log in

Don't you dare go Hollow

Make DnD edge view scroll configurable

Browse files at this commit

f2b1fc66f21f720ba85a4c218546298e527ba8b9Ivan MolodetskikhParent: 22302bf
niri-config/src/lib.rsmodified+46 -0
@@ -59,6 +59,8 @@ pub struct Config {
5959 #[knuffel(child, default)]
6060 pub animations: Animations,
6161 #[knuffel(child, default)]
62+ pub gestures: Gestures,
63+ #[knuffel(child, default)]
6264 pub environment: Environment,
6365 #[knuffel(children(name = "window-rule"))]
6466 pub window_rules: Vec<WindowRule>,
@@ -1115,6 +1117,32 @@ pub struct SpringParams {
11151117 pub epsilon: f64,
11161118 }
11171119
1120+#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq)]
1121+pub struct Gestures {
1122+ #[knuffel(child, default)]
1123+ pub dnd_edge_view_scroll: DndEdgeViewScroll,
1124+}
1125+
1126+#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
1127+pub struct DndEdgeViewScroll {
1128+ #[knuffel(child, unwrap(argument), default = Self::default().trigger_width)]
1129+ pub trigger_width: FloatOrInt<0, 65535>,
1130+ #[knuffel(child, unwrap(argument), default = Self::default().delay_ms)]
1131+ pub delay_ms: u16,
1132+ #[knuffel(child, unwrap(argument), default = Self::default().max_speed)]
1133+ pub max_speed: FloatOrInt<0, 1_000_000>,
1134+}
1135+
1136+impl Default for DndEdgeViewScroll {
1137+ fn default() -> Self {
1138+ Self {
1139+ trigger_width: FloatOrInt(30.), // Taken from GTK 4.
1140+ delay_ms: 50,
1141+ max_speed: FloatOrInt(1500.),
1142+ }
1143+ }
1144+}
1145+
11181146 #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq, Eq)]
11191147 pub struct Environment(#[knuffel(children)] pub Vec<EnvironmentVariable>);
11201148
@@ -3679,6 +3707,13 @@ mod tests {
36793707 window-open { off; }
36803708 }
36813709
3710+ gestures {
3711+ dnd-edge-view-scroll {
3712+ trigger-width 10
3713+ max-speed 50
3714+ }
3715+ }
3716+
36823717 environment {
36833718 QT_QPA_PLATFORM "wayland"
36843719 DISPLAY null
@@ -4252,6 +4287,17 @@ mod tests {
42524287 },
42534288 ),
42544289 },
4290+ gestures: Gestures {
4291+ dnd_edge_view_scroll: DndEdgeViewScroll {
4292+ trigger_width: FloatOrInt(
4293+ 10.0,
4294+ ),
4295+ delay_ms: 50,
4296+ max_speed: FloatOrInt(
4297+ 50.0,
4298+ ),
4299+ },
4300+ },
42554301 environment: Environment(
42564302 [
42574303 EnvironmentVariable {
src/layout/mod.rsmodified+3 -0
@@ -328,6 +328,7 @@ pub struct Options {
328328 /// Window height that `toggle_window_height()` switches between.
329329 pub preset_window_heights: Vec<PresetSize>,
330330 pub animations: niri_config::Animations,
331+ pub gestures: niri_config::Gestures,
331332 // Debug flags.
332333 pub disable_resize_throttling: bool,
333334 pub disable_transactions: bool,
@@ -354,6 +355,7 @@ impl Default for Options {
354355 ],
355356 default_column_width: None,
356357 animations: Default::default(),
358+ gestures: Default::default(),
357359 disable_resize_throttling: false,
358360 disable_transactions: false,
359361 preset_window_heights: vec![
@@ -582,6 +584,7 @@ impl Options {
582584 preset_column_widths,
583585 default_column_width,
584586 animations: config.animations.clone(),
587+ gestures: config.gestures,
585588 disable_resize_throttling: config.debug.disable_resize_throttling,
586589 disable_transactions: config.debug.disable_transactions,
587590 preset_window_heights,
src/layout/scrolling.rsmodified+5 -2
@@ -2806,6 +2806,8 @@ impl<W: LayoutElement> ScrollingSpace<W> {
28062806 return;
28072807 };
28082808
2809+ let config = &self.options.gestures.dnd_edge_view_scroll;
2810+
28092811 let now = self.clock.now_unadjusted();
28102812 gesture.dnd_last_event_time = Some(now);
28112813
@@ -2819,13 +2821,14 @@ impl<W: LayoutElement> ScrollingSpace<W> {
28192821
28202822 // Delay starting the gesture a bit to avoid unwanted movement when dragging across
28212823 // monitors.
2822- if now.saturating_sub(nonzero_start) < Duration::from_millis(50) {
2824+ let delay = Duration::from_millis(u64::from(config.delay_ms));
2825+ if now.saturating_sub(nonzero_start) < delay {
28232826 return;
28242827 }
28252828
28262829 let time_delta = now.saturating_sub(last_time).as_secs_f64();
28272830
2828- let delta = delta * time_delta * 50.;
2831+ let delta = delta * time_delta * config.max_speed.0;
28292832
28302833 gesture.tracker.push(delta, now);
28312834
src/layout/workspace.rsmodified+16 -6
@@ -1614,22 +1614,32 @@ impl<W: LayoutElement> Workspace<W> {
16141614 }
16151615
16161616 pub fn dnd_scroll_gesture_scroll(&mut self, pos: Point<f64, Logical>) {
1617- // Taken from GTK 4.
1618- const SCROLL_EDGE_SIZE: f64 = 30.;
1617+ let config = &self.options.gestures.dnd_edge_view_scroll;
1618+ let trigger_width = config.trigger_width.0;
16191619
16201620 // This working area intentionally does not include extra struts from Options.
16211621 let x = pos.x - self.working_area.loc.x;
16221622 let width = self.working_area.size.w;
1623+
16231624 let x = x.clamp(0., width);
1625+ let trigger_width = trigger_width.clamp(0., width / 2.);
16241626
1625- let delta = if x < SCROLL_EDGE_SIZE {
1626- -(SCROLL_EDGE_SIZE - x)
1627- } else if width - x < SCROLL_EDGE_SIZE {
1628- SCROLL_EDGE_SIZE - (width - x)
1627+ let delta = if x < trigger_width {
1628+ -(trigger_width - x)
1629+ } else if width - x < trigger_width {
1630+ trigger_width - (width - x)
16291631 } else {
16301632 0.
16311633 };
16321634
1635+ let delta = if trigger_width < 0.01 {
1636+ // Sanity check for trigger-width 0 or small window sizes.
1637+ 0.
1638+ } else {
1639+ // Normalize to [0, 1].
1640+ delta / trigger_width
1641+ };
1642+
16331643 self.scrolling.dnd_scroll_gesture_scroll(delta);
16341644 }
16351645