aboutsummaryrefslogtreecommitdiff
path: root/src/command.rs
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2016-09-04 14:01:37 -0300
committerMatias Linares <matiaslina@openmailbox.org>2016-09-04 14:01:37 -0300
commit5bcdb566c69523edb1ceb857cbf6d0a676cc318d (patch)
treed3506fee02510999128fdfb5ec6a84ca99c9962b /src/command.rs
parent67306a1f063f15bc8127cdc2f72f971f2d06dd69 (diff)
downloaddotwm-5bcdb566c69523edb1ceb857cbf6d0a676cc318d.tar.gz
Add Mouse drag support.
This concludes the first 'release' :p.
Diffstat (limited to 'src/command.rs')
-rw-r--r--src/command.rs38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/command.rs b/src/command.rs
index f5e3e83..eaadf77 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,ungrab_key};
+use safe_x11::{grab_key,ungrab_key,grab_button,ungrab_button};
const WNOHANG: c_int = 0x00000001;
@@ -132,6 +132,25 @@ pub fn move_win_sticky(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool
true
}
+/// Drag the window. for now the dragging is relative to the center of the
+/// window because win.cursor_coords is always `None`. Later we should
+/// be able to `XGrabButton` on the child windows (not only on the root) and
+/// set `win.cursor_coords` respectively.
+pub fn move_win_drag(wm: &mut DotWM, e: xlib::XEvent, _: &[String]) -> bool {
+ let ev = xlib::XMotionEvent::from(e);
+ if let Some(ref win) = wm.current_window() {
+ let attr = win.attributes();
+ let (x0, y0) = win.cursor_coords.unwrap_or((attr.width/2, attr.height/2));
+ // Move around the center of the cursor.
+ let x = ev.x - x0;
+ let y = ev.y - y0;
+ win.move_to(x, y).is_ok()
+ } else {
+ println!("move_win_drag - nop");
+ false
+ }
+}
+
/// 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();
@@ -222,6 +241,23 @@ pub fn add_binding(wm: &mut DotWM, bindings: &mut BindingHash,
bindings.insert((key, modifiers), (func, v));
}
+/// Add a button binding to the WM.
+pub fn add_button_binding(wm: &mut DotWM, bindings: &mut BindingHash,
+ button: u32, modifiers: u32, func: ExecFn, args: &[&str]) {
+ ungrab_button(wm.display, button, modifiers);
+ grab_button(wm.display, button, modifiers, true,
+ xlib::ButtonPressMask|xlib::ButtonReleaseMask|xlib::PointerMotionMask,
+ GrabModeAsync, GrabModeAsync, 0, 0);
+ let mut v = vec![];
+ for arg in args {
+ v.push(arg.to_string());
+ }
+ // for now we need the button1Mask here
+ bindings.insert((button, modifiers | xlib::Button1Mask), (func, v));
+}
+
+/// Change the desktop, args parameter only have one usize on it that is the
+/// index of the desktop (i.e.: 0 for the first, 1 for the second, etc).
pub fn change_desktop(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool {
let num = args[0].parse::<usize>().unwrap();
wm.change_desktop(num);