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 {
59 #[knuffel(child, default)]59 #[knuffel(child, default)]
60 pub animations: Animations,60 pub animations: Animations,
61 #[knuffel(child, default)]61 #[knuffel(child, default)]
62+ pub gestures: Gestures,
63+ #[knuffel(child, default)]
62 pub environment: Environment,64 pub environment: Environment,
63 #[knuffel(children(name = "window-rule"))]65 #[knuffel(children(name = "window-rule"))]
64 pub window_rules: Vec<WindowRule>,66 pub window_rules: Vec<WindowRule>,
@@ -1115,6 +1117,32 @@ pub struct SpringParams {
1115 pub epsilon: f64,1117 pub epsilon: f64,
1116 }1118 }
1117 1119
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+
1118 #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq, Eq)]1146 #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq, Eq)]
1119 pub struct Environment(#[knuffel(children)] pub Vec<EnvironmentVariable>);1147 pub struct Environment(#[knuffel(children)] pub Vec<EnvironmentVariable>);
1120 1148
@@ -3679,6 +3707,13 @@ mod tests {
3679 window-open { off; }3707 window-open { off; }
3680 }3708 }
3681 3709
3710+ gestures {
3711+ dnd-edge-view-scroll {
3712+ trigger-width 10
3713+ max-speed 50
3714+ }
3715+ }
3716+
3682 environment {3717 environment {
3683 QT_QPA_PLATFORM "wayland"3718 QT_QPA_PLATFORM "wayland"
3684 DISPLAY null3719 DISPLAY null
@@ -4252,6 +4287,17 @@ mod tests {
4252 },4287 },
4253 ),4288 ),
4254 },4289 },
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+ },
4255 environment: Environment(4301 environment: Environment(
4256 [4302 [
4257 EnvironmentVariable {4303 EnvironmentVariable {
src/layout/mod.rsmodified+3 -0
@@ -328,6 +328,7 @@ pub struct Options {
328 /// Window height that `toggle_window_height()` switches between.328 /// Window height that `toggle_window_height()` switches between.
329 pub preset_window_heights: Vec<PresetSize>,329 pub preset_window_heights: Vec<PresetSize>,
330 pub animations: niri_config::Animations,330 pub animations: niri_config::Animations,
331+ pub gestures: niri_config::Gestures,
331 // Debug flags.332 // Debug flags.
332 pub disable_resize_throttling: bool,333 pub disable_resize_throttling: bool,
333 pub disable_transactions: bool,334 pub disable_transactions: bool,
@@ -354,6 +355,7 @@ impl Default for Options {
354 ],355 ],
355 default_column_width: None,356 default_column_width: None,
356 animations: Default::default(),357 animations: Default::default(),
358+ gestures: Default::default(),
357 disable_resize_throttling: false,359 disable_resize_throttling: false,
358 disable_transactions: false,360 disable_transactions: false,
359 preset_window_heights: vec![361 preset_window_heights: vec![
@@ -582,6 +584,7 @@ impl Options {
582 preset_column_widths,584 preset_column_widths,
583 default_column_width,585 default_column_width,
584 animations: config.animations.clone(),586 animations: config.animations.clone(),
587+ gestures: config.gestures,
585 disable_resize_throttling: config.debug.disable_resize_throttling,588 disable_resize_throttling: config.debug.disable_resize_throttling,
586 disable_transactions: config.debug.disable_transactions,589 disable_transactions: config.debug.disable_transactions,
587 preset_window_heights,590 preset_window_heights,
src/layout/scrolling.rsmodified+5 -2
@@ -2806,6 +2806,8 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2806 return;2806 return;
2807 };2807 };
2808 2808
2809+ let config = &self.options.gestures.dnd_edge_view_scroll;
2810+
2809 let now = self.clock.now_unadjusted();2811 let now = self.clock.now_unadjusted();
2810 gesture.dnd_last_event_time = Some(now);2812 gesture.dnd_last_event_time = Some(now);
2811 2813
@@ -2819,13 +2821,14 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2819 2821
2820 // Delay starting the gesture a bit to avoid unwanted movement when dragging across2822 // Delay starting the gesture a bit to avoid unwanted movement when dragging across
2821 // monitors.2823 // 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 {
2823 return;2826 return;
2824 }2827 }
2825 2828
2826 let time_delta = now.saturating_sub(last_time).as_secs_f64();2829 let time_delta = now.saturating_sub(last_time).as_secs_f64();
2827 2830
2828- let delta = delta * time_delta * 50.;2831+ let delta = delta * time_delta * config.max_speed.0;
2829 2832
2830 gesture.tracker.push(delta, now);2833 gesture.tracker.push(delta, now);
2831 2834
src/layout/workspace.rsmodified+16 -6
@@ -1614,22 +1614,32 @@ impl<W: LayoutElement> Workspace<W> {
1614 }1614 }
1615 1615
1616 pub fn dnd_scroll_gesture_scroll(&mut self, pos: Point<f64, Logical>) {1616 pub fn dnd_scroll_gesture_scroll(&mut self, pos: Point<f64, Logical>) {
1617- // Taken from GTK 4.1617+ let config = &self.options.gestures.dnd_edge_view_scroll;
1618- const SCROLL_EDGE_SIZE: f64 = 30.;1618+ let trigger_width = config.trigger_width.0;
1619 1619
1620 // This working area intentionally does not include extra struts from Options.1620 // This working area intentionally does not include extra struts from Options.
1621 let x = pos.x - self.working_area.loc.x;1621 let x = pos.x - self.working_area.loc.x;
1622 let width = self.working_area.size.w;1622 let width = self.working_area.size.w;
1623+
1623 let x = x.clamp(0., width);1624 let x = x.clamp(0., width);
1625+ let trigger_width = trigger_width.clamp(0., width / 2.);
1624 1626
1625- let delta = if x < SCROLL_EDGE_SIZE {1627+ let delta = if x < trigger_width {
1626- -(SCROLL_EDGE_SIZE - x)1628+ -(trigger_width - x)
1627- } else if width - x < SCROLL_EDGE_SIZE {1629+ } else if width - x < trigger_width {
1628- SCROLL_EDGE_SIZE - (width - x)1630+ trigger_width - (width - x)
1629 } else {1631 } else {
1630 0.1632 0.
1631 };1633 };
1632 1634
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+
1633 self.scrolling.dnd_scroll_gesture_scroll(delta);1643 self.scrolling.dnd_scroll_gesture_scroll(delta);
1634 }1644 }
1635 1645