Skip to content

Commit

Permalink
fixing floating actions broken by recent change to use relative rects
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Nov 9, 2022
1 parent a73c277 commit 154b29f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/builtin/actions/floating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ pub fn resize<X: XConn>(dw: i32, dh: i32) -> Box<dyn KeyEventHandler<X>> {
None => return,
};

if let Some(r) = cs.floating.get_mut(&id) {
r.apply_as_rect(&cs.screens.focus.r, |mut r| {
cs.floating.entry(id).and_modify(|r| {
*r = r.apply_as_rect(&cs.screens.focus.r, |mut r| {
r.resize(dw, dh);
r
});
}
});
})
}

Expand All @@ -34,12 +34,12 @@ pub fn reposition<X: XConn>(dx: i32, dy: i32) -> Box<dyn KeyEventHandler<X>> {
None => return,
};

if let Some(r) = cs.floating.get_mut(&id) {
r.apply_as_rect(&cs.screens.focus.r, |mut r| {
cs.floating.entry(id).and_modify(|r| {
*r = r.apply_as_rect(&cs.screens.focus.r, |mut r| {
r.reposition(dx, dy);
r
});
}
});
})
}

Expand Down
26 changes: 26 additions & 0 deletions src/pure/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,30 @@ mod tests {

assert_eq!(relative, expected);
}

#[test]
fn apply_as_rect_resize() {
let relative = rr(0.0, 0.0, 0.8, 0.8);
let reference = r(0, 0, 2000, 1000);

let res = relative.apply_as_rect(&reference, |mut r| {
r.resize(-10, 0);
r
});

assert_eq!(res, rr(0.0, 0.0, 0.795, 0.8));
}

#[test]
fn apply_as_rect_reposition() {
let relative = rr(0.0, 0.0, 0.8, 0.8);
let reference = r(0, 0, 2000, 1000);

let res = relative.apply_as_rect(&reference, |mut r| {
r.reposition(10, 0);
r
});

assert_eq!(res, rr(0.005, 0.0, 0.8, 0.8));
}
}

0 comments on commit 154b29f

Please sign in to comment.