Skip to content

Commit

Permalink
floating: Implement directional move
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Dec 15, 2024
1 parent 4ae4bb0 commit b828cda
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
29 changes: 29 additions & 0 deletions src/layout/floating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 16 additions & 8 deletions src/layout/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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>) {
Expand Down

0 comments on commit b828cda

Please sign in to comment.