diff options
author | Matias Linares <matiaslina@openmailbox.org> | 2016-01-27 18:49:01 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@openmailbox.org> | 2016-01-27 18:49:01 -0300 |
commit | 6d54483c6f86f42405cf6db9d8fdb19e9397267b (patch) | |
tree | 4205f07a8732f60d9c6f6cf8544bd34102ff8221 /src/safe_x11 | |
parent | 5d7d8a19f6364dfb6e6583125ced3103d069f2b3 (diff) | |
download | dotwm-6d54483c6f86f42405cf6db9d8fdb19e9397267b.tar.gz |
Refactor resize sticky code
Diffstat (limited to 'src/safe_x11')
-rw-r--r-- | src/safe_x11/window.rs | 50 |
1 files changed, 50 insertions, 0 deletions
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(); |