diff options
author | Matias Linares <matiaslina@openmailbox.org> | 2016-09-04 14:01:37 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@openmailbox.org> | 2016-09-04 14:01:37 -0300 |
commit | 5bcdb566c69523edb1ceb857cbf6d0a676cc318d (patch) | |
tree | d3506fee02510999128fdfb5ec6a84ca99c9962b /src/safe_x11 | |
parent | 67306a1f063f15bc8127cdc2f72f971f2d06dd69 (diff) | |
download | dotwm-5bcdb566c69523edb1ceb857cbf6d0a676cc318d.tar.gz |
Add Mouse drag support.
This concludes the first 'release' :p.
Diffstat (limited to 'src/safe_x11')
-rw-r--r-- | src/safe_x11/mod.rs | 8 | ||||
-rw-r--r-- | src/safe_x11/window.rs | 15 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/safe_x11/mod.rs b/src/safe_x11/mod.rs index 613424a..4a1e029 100644 --- a/src/safe_x11/mod.rs +++ b/src/safe_x11/mod.rs @@ -137,6 +137,14 @@ pub fn grab_button(display: *mut Display, button: u32, modifiers: u32, } } +/// Unregister a combination of keys that will send a `XEvent` +pub fn ungrab_button(display: *mut Display, button: u32, modifiers: u32) { + unsafe { + let default_win = xlib::XDefaultRootWindow(display); + xlib::XUngrabButton(display, button, modifiers, default_win); + } +} + /// Register a combination of keys that will send a `XEvent` /// pub fn grab_key(display: *mut Display, key: u32, modifiers: u32, owner_events: bool, diff --git a/src/safe_x11/window.rs b/src/safe_x11/window.rs index eac4dbd..6c483d9 100644 --- a/src/safe_x11/window.rs +++ b/src/safe_x11/window.rs @@ -41,6 +41,8 @@ pub struct XWindow { // The Application window. pub inner: Window, fullscreen: bool, + // Coordinates relative to the window where the cursor clicked on it. + pub cursor_coords: Option<(i32, i32)>, prev_attribs: XWindowAttributes, } @@ -64,11 +66,11 @@ impl XWindow { pub fn new(d: *mut xlib::Display, w: Window) -> Option<XWindow> { if w != 0 { let attrs: XWindowAttributes = unsafe { uninitialized() }; - println!("Window created!"); Some(XWindow { display: d, inner: w, fullscreen: false, + cursor_coords: None, prev_attribs: attrs, }) } else { @@ -155,8 +157,9 @@ impl XWindow { let s = XDefaultScreenOfDisplay(self.display); ptr::read(s) }; + let attrs = self.attributes(); - if 0 > x && x <= screen.width || 0 > y && y <= screen.height { + if x < -attrs.width && x <= screen.width || -attrs.height > y && y <= screen.height { Err("Cannot move the window outside the screen!") } else { unsafe { @@ -381,6 +384,14 @@ impl XWindow { } } +use std::fmt; + +impl fmt::Display for XWindow { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Window({})", self.inner) + } +} + pub fn change_window_attributes(display: *mut xlib::Display, win: Window, mask: u64, window_attribs: *mut XSetWindowAttributes) { unsafe { |