summaryrefslogtreecommitdiff
path: root/src/command.rs
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2015-11-29 11:57:19 -0300
committerMatias Linares <matiaslina@openmailbox.org>2015-11-29 11:57:48 -0300
commitd5e55aab6499a89e9dfaf5b976938bfe3e2f6aee (patch)
tree52efc28076c31fdd2522ed8b7871a7dd99ad0c87 /src/command.rs
parente1ec354306742a5804a20e2651cf49945cd17287 (diff)
downloaddotwm-d5e55aab6499a89e9dfaf5b976938bfe3e2f6aee.tar.gz
Begin ef EWMH support and sticky movement
The implementationn of the EWMH and ICCCM support is incomplete. I need to check how to implement on the right way.
Diffstat (limited to 'src/command.rs')
-rw-r--r--src/command.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/command.rs b/src/command.rs
index 0ccee17..78b9e5a 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -16,6 +16,7 @@ use x11::xlib;
use x11::xlib::{XEvent, GrabModeAsync};
use dotwm::DotWM;
+use dotwm::NetAtom;
use safe_x11::grab_key;
const WNOHANG: c_int = 0x00000001;
@@ -66,6 +67,17 @@ pub fn exec(_: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool {
true
}
+/// Toggles the fullscreen of the current window
+pub fn fullscreen(wm: &mut DotWM, _: xlib::XEvent, _: &[String]) -> bool {
+ let wmstate = wm.netatoms[&NetAtom::NetWmState];
+ let fs_atom = wm.netatoms[&NetAtom::NetFullscreen];
+
+ if let Some(win) = wm.current_window_mut() {
+ win.toggle_fullscreen(wmstate, fs_atom, true);
+ };
+ true
+}
+
/// Move the window to a relative position
pub fn move_win(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool {
let x = args[0].parse::<i32>().unwrap();
@@ -93,6 +105,55 @@ pub fn move_win_to(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool {
}
}
+pub fn move_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).next();
+ if let Some(v) = val {
+ let _ = win.move_to(*v, attrs.y);
+ }
+ },
+ "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(v) = val {
+ let _ = win.move_to(*v - attrs.width, attrs.y);
+ }
+ },
+ "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).next();
+ if let Some(v) = val {
+ let _ = win.move_to(attrs.x, *v);
+ }
+ },
+ "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 _ = win.move_to(attrs.x, *v - attrs.height);
+ }
+ },
+ _ => (),
+ }
+ }
+ true
+}
+
/// Resize the window certain amount in x and y.
pub fn resize_win(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool {
let w = args[0].parse::<i32>().unwrap();
@@ -105,6 +166,15 @@ pub fn resize_win(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool {
true
}
+/// Close the current window
+pub fn close_win(wm: &mut DotWM, _: xlib::XEvent, _: &[String]) -> bool {
+ if let Some(ref win) = wm.current_window() {
+ win.delete();
+ };
+
+ true
+}
+
/// Focus the next window on the list
pub fn focus_next(wm: &mut DotWM, _: xlib::XEvent, _: &[String]) -> bool {
wm.focus_next();