aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-12-15 10:53:15 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-12-30 20:12:37 +0300
commit3c67b08488789d5781a4b58d4503559145755ba7 (patch)
tree9391aa4bb4c242cb94e8dc3d4df21da0284727e5 /src
parent4add755a4d72132324be5cfd04fd119850519b5b (diff)
downloadniri-3c67b08488789d5781a4b58d4503559145755ba7.tar.gz
niri-3c67b08488789d5781a4b58d4503559145755ba7.tar.bz2
niri-3c67b08488789d5781a4b58d4503559145755ba7.zip
floating: Implement directional move
Diffstat (limited to 'src')
-rw-r--r--src/layout/floating.rs29
-rw-r--r--src/layout/workspace.rs24
2 files changed, 45 insertions, 8 deletions
diff --git a/src/layout/floating.rs b/src/layout/floating.rs
index c3cf8831..2d7d0457 100644
--- a/src/layout/floating.rs
+++ b/src/layout/floating.rs
@@ -22,6 +22,9 @@ use crate::utils::{
};
use crate::window::ResolvedWindowRules;
+/// By how many logical pixels the directional move commands move floating windows.
+const DIRECTIONAL_MOVE_PX: f64 = 50.;
+
/// Space for floating windows.
#[derive(Debug)]
pub struct FloatingSpace<W: LayoutElement> {
@@ -691,6 +694,32 @@ impl<W: LayoutElement> FloatingSpace<W> {
}
}
+ fn move_by(&mut self, amount: Point<f64, Logical>) {
+ let Some(active_id) = &self.active_window_id else {
+ return;
+ };
+ let active_idx = self.idx_of(active_id).unwrap();
+
+ let new_pos = self.data[active_idx].logical_pos + amount;
+ self.move_and_animate(active_idx, new_pos);
+ }
+
+ pub fn move_left(&mut self) {
+ self.move_by(Point::from((-DIRECTIONAL_MOVE_PX, 0.)));
+ }
+
+ pub fn move_right(&mut self) {
+ self.move_by(Point::from((DIRECTIONAL_MOVE_PX, 0.)));
+ }
+
+ pub fn move_up(&mut self) {
+ self.move_by(Point::from((0., -DIRECTIONAL_MOVE_PX)));
+ }
+
+ pub fn move_down(&mut self) {
+ self.move_by(Point::from((0., DIRECTIONAL_MOVE_PX)));
+ }
+
pub fn center_window(&mut self) {
let Some(active_id) = &self.active_window_id else {
return;
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index 46ed669e..b5d0f894 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -840,16 +840,20 @@ impl<W: LayoutElement> Workspace<W> {
pub fn move_left(&mut self) -> bool {
if self.floating_is_active {
- return true;
+ self.floating.move_left();
+ true
+ } else {
+ self.scrolling.move_left()
}
- self.scrolling.move_left()
}
pub fn move_right(&mut self) -> bool {
if self.floating_is_active {
- return true;
+ self.floating.move_right();
+ true
+ } else {
+ self.scrolling.move_right()
}
- self.scrolling.move_right()
}
pub fn move_column_to_first(&mut self) {
@@ -868,16 +872,20 @@ impl<W: LayoutElement> Workspace<W> {
pub fn move_down(&mut self) -> bool {
if self.floating_is_active {
- return true;
+ self.floating.move_down();
+ true
+ } else {
+ self.scrolling.move_down()
}
- self.scrolling.move_down()
}
pub fn move_up(&mut self) -> bool {
if self.floating_is_active {
- return true;
+ self.floating.move_up();
+ true
+ } else {
+ self.scrolling.move_up()
}
- self.scrolling.move_up()
}
pub fn consume_or_expel_window_left(&mut self, window: Option<&W::Id>) {