diff options
Diffstat (limited to 'src/safe_x11/window.rs')
-rw-r--r-- | src/safe_x11/window.rs | 15 |
1 files changed, 13 insertions, 2 deletions
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 { |