diff options
Diffstat (limited to 'src/command.rs')
-rw-r--r-- | src/command.rs | 49 |
1 files changed, 10 insertions, 39 deletions
diff --git a/src/command.rs b/src/command.rs index 74a7255..f5e3e83 100644 --- a/src/command.rs +++ b/src/command.rs @@ -150,54 +150,25 @@ pub fn resize_win(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool { /// movement between `left` and `up` pub fn resize_win_sticky(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool { if let Some(ref win) = wm.current_window() { - let attrs = win.attributes(); + let mut xgeometries = wm.x_geometries(); + let mut ygeometries = wm.y_geometries(); match &*args[0] { "left" => { - let mut xgeo = wm.x_geometries(); - xgeo.sort_by(|a,b| b.cmp(a)); - - let val = xgeo.iter().skip_while(|&a| *a >= attrs.x + attrs.width).next(); - if let Some(v) = val { - let diff = attrs.width - (*v - attrs.x); - if *v - attrs.x > 0 { - let _ = win.resize_to(attrs.width - diff, attrs.height); - } - } + xgeometries.sort_by(|a,b| b.cmp(a)); + win.resize_sticky_left(&xgeometries); }, "right" => { - let mut xgeo = wm.x_geometries(); - let win_right = attrs.x + attrs.width; - xgeo.sort_by(|a,b| a.cmp(b)); - - let val = xgeo.iter().skip_while(|&a| *a <= win_right).next(); - if let Some(xpoint) = val { - let new_width = *xpoint - attrs.x; - let _ = win.resize_to(new_width, attrs.height); - } + xgeometries.sort_by(|a,b| a.cmp(b)); + win.resize_sticky_right(&xgeometries); }, "up" => { - let mut ygeo = wm.y_geometries(); - ygeo.sort_by(|a,b| b.cmp(a)); - - let val = ygeo.iter().skip_while(|&a| *a >= attrs.y + attrs.height).next(); - if let Some(v) = val { - let diff = attrs.height - (*v - attrs.y); - if *v - attrs.y > 0 { - let _ = win.resize_to(attrs.width, attrs.height - diff); - } - } + ygeometries.sort_by(|a,b| b.cmp(a)); + win.resize_sticky_up(&ygeometries); }, "down" => { - let mut ygeo = wm.y_geometries(); - let win_bot = attrs.y + attrs.height; - ygeo.sort_by(|a,b| a.cmp(b)); - - let val = ygeo.iter().skip_while(|&a| *a <= win_bot).next(); - if let Some(v) = val { - let new_height = *v - attrs.y; - let _ = win.resize_to(attrs.width, new_height); - } + ygeometries.sort_by(|a,b| a.cmp(b)); + win.resize_sticky_down(&ygeometries); }, _ => (), } |