aboutsummaryrefslogtreecommitdiff
path: root/src/command.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/command.rs')
-rw-r--r--src/command.rs66
1 files changed, 65 insertions, 1 deletions
diff --git a/src/command.rs b/src/command.rs
index 78b9e5a..f351e14 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -17,7 +17,7 @@ use x11::xlib::{XEvent, GrabModeAsync};
use dotwm::DotWM;
use dotwm::NetAtom;
-use safe_x11::grab_key;
+use safe_x11::{grab_key,ungrab_key};
const WNOHANG: c_int = 0x00000001;
@@ -166,6 +166,69 @@ pub fn resize_win(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool {
true
}
+/// Resizes the window sticking with other windows.
+///
+/// The movement of the `right` command is the same logic as the `down`, idem to the
+/// 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();
+
+ 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);
+ }
+ }
+ },
+ "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);
+ }
+ },
+ "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);
+ println!("Resizing to {}x{}", attrs.width, diff);
+ if *v - attrs.y > 0 {
+ let _ = win.resize_to(attrs.width, attrs.height - diff);
+ }
+ }
+ },
+ "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;
+ println!("Resizing to {}x{}", attrs.width, new_height);
+ let _ = win.resize_to(attrs.width, new_height);
+ }
+ },
+ _ => (),
+ }
+ }
+ true
+}
+
/// Close the current window
pub fn close_win(wm: &mut DotWM, _: xlib::XEvent, _: &[String]) -> bool {
if let Some(ref win) = wm.current_window() {
@@ -203,6 +266,7 @@ pub fn quit_dotwm(wm: &mut DotWM, _: xlib::XEvent, _: &[String]) -> bool {
/// ```
pub fn add_binding(wm: &mut DotWM, bindings: &mut BindingHash,
key: u32, modifiers: u32, func: ExecFn, args: &[&str]) {
+ ungrab_key(wm.display, key, modifiers);
grab_key(wm.display, key, modifiers, true, GrabModeAsync, GrabModeAsync);
let mut v = vec![];
for arg in args {