From 5bcdb566c69523edb1ceb857cbf6d0a676cc318d Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 4 Sep 2016 14:01:37 -0300 Subject: Add Mouse drag support. This concludes the first 'release' :p. --- src/safe_x11/mod.rs | 8 ++++++++ src/safe_x11/window.rs | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'src/safe_x11') 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 { 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 { -- cgit v1.2.3-70-g09d2