From 6d54483c6f86f42405cf6db9d8fdb19e9397267b Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Wed, 27 Jan 2016 18:49:01 -0300 Subject: Refactor resize sticky code --- src/safe_x11/window.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/safe_x11') diff --git a/src/safe_x11/window.rs b/src/safe_x11/window.rs index c889dfc..6d1e54e 100644 --- a/src/safe_x11/window.rs +++ b/src/safe_x11/window.rs @@ -252,6 +252,56 @@ impl XWindow { } } + pub fn resize_sticky_left(&self, boundaries: &[i32]) { + let attrs = self.attributes(); + + if let Some(v) = boundaries.iter() + .skip_while(|&a| *a >= attrs.x + attrs.width) + .next() { + let diff = attrs.width - (*v - attrs.x); + if *v - attrs.x > 0 { + let _ = self.resize_to(attrs.width - diff, attrs.height); + } + } + } + + pub fn resize_sticky_right(&self, boundaries: &[i32]) { + let attrs = self.attributes(); + let win_bound = attrs.x + attrs.width; + + if let Some(v) = boundaries.iter() + .skip_while(|&a| *a <= win_bound) + .next() { + let new_width = *v - attrs.x; + let _ = self.resize_to(new_width, attrs.height); + } + } + + pub fn resize_sticky_up(&self, boundaries: &[i32]) { + let attrs = self.attributes(); + + if let Some(v) = boundaries.iter() + .skip_while(|&a| *a >= attrs.y + attrs.height) + .next() { + let diff = attrs.height - (*v - attrs.y); + if *v - attrs.y > 0 { + let _ = self.resize_to(attrs.width, attrs.height - diff); + } + } + } + + pub fn resize_sticky_down(&self, boundaries: &[i32]) { + let attrs = self.attributes(); + let win_bound = attrs.y + attrs.height; + + if let Some(v) = boundaries.iter() + .skip_while(|&a| *a <= win_bound) + .next() { + let new_height = *v - attrs.y; + let _ = self.resize_to(attrs.width, new_height); + } + } + /// Raise the focus of the window and set a border. pub fn focus(&self) { let attrs = self.attributes(); -- cgit v1.2.3-70-g09d2