diff --git a/src/lib.rs b/src/lib.rs index 2a5085e5..939758b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -253,7 +253,7 @@ pub mod window { /// Get the position of the window. /// TODO: implement for other platforms - #[cfg(target_os = "windows")] + #[cfg(any(target_os = "windows", target_os = "linux"))] pub fn get_window_position() -> (u32, u32) { let d = native_display().lock().unwrap(); d.screen_position diff --git a/src/native/linux_x11.rs b/src/native/linux_x11.rs index 4058018c..12aeea03 100644 --- a/src/native/linux_x11.rs +++ b/src/native/linux_x11.rs @@ -133,6 +133,9 @@ impl X11Display { } 22 => { let mut d = crate::native_display().try_lock().unwrap(); + let left = (*event).xconfigure.x; + let top = (*event).xconfigure.y; + d.screen_position = (left as _, top as _); if (*event).xconfigure.width != d.screen_width || (*event).xconfigure.height != d.screen_height { @@ -263,6 +266,11 @@ impl X11Display { (self.libx11.XFlush)(self.display); } + /// Set the window position in screen coordinates. + unsafe fn set_window_position(&mut self, window: Window, new_x: i32, new_y: i32) { + (self.libx11.XMoveWindow)(self.display, window, new_x, new_y); + } + fn show_mouse(&mut self, shown: bool) { unsafe { if shown { @@ -347,8 +355,8 @@ impl X11Display { new_width, new_height, } => self.set_window_size(self.window, new_width as _, new_height as _), - SetWindowPosition { .. } => { - eprintln!("Not implemented for X11") + SetWindowPosition { new_x, new_y } => { + self.set_window_position(self.window, new_x as _, new_y as _) } SetFullscreen(fullscreen) => self.set_fullscreen(self.window, fullscreen), ShowKeyboard(..) => { diff --git a/src/native/linux_x11/libx11.rs b/src/native/linux_x11/libx11.rs index e9c45e71..8000b342 100644 --- a/src/native/linux_x11/libx11.rs +++ b/src/native/linux_x11/libx11.rs @@ -858,6 +858,8 @@ pub type XLowerWindow = unsafe extern "C" fn(_: *mut Display, _: Window) -> libc pub type XRaiseWindow = unsafe extern "C" fn(_: *mut Display, _: Window) -> libc::c_int; pub type XResizeWindow = unsafe extern "C" fn(_: *mut Display, _: Window, _: libc::c_int, _: libc::c_int) -> libc::c_int; +pub type XMoveWindow = + unsafe extern "C" fn(_: *mut Display, _: Window, _: libc::c_int, _: libc::c_int) -> libc::c_int; pub type XPending = unsafe extern "C" fn(_: *mut Display) -> libc::c_int; pub type XNextEvent = unsafe extern "C" fn(_: *mut Display, _: *mut XEvent) -> libc::c_int; pub type XGetKeyboardMapping = unsafe extern "C" fn( @@ -1013,6 +1015,7 @@ pub struct LibX11 { pub XLowerWindow: XLowerWindow, pub XRaiseWindow: XRaiseWindow, pub XResizeWindow: XResizeWindow, + pub XMoveWindow: XMoveWindow, pub XPending: XPending, pub XNextEvent: XNextEvent, pub XGetKeyboardMapping: XGetKeyboardMapping, @@ -1065,6 +1068,7 @@ impl LibX11 { XLowerWindow: module.get_symbol("XLowerWindow").unwrap(), XRaiseWindow: module.get_symbol("XRaiseWindow").unwrap(), XResizeWindow: module.get_symbol("XResizeWindow").unwrap(), + XMoveWindow: module.get_symbol("XMoveWindow").unwrap(), XPending: module.get_symbol("XPending").unwrap(), XNextEvent: module.get_symbol("XNextEvent").unwrap(), XGetKeyboardMapping: module.get_symbol("XGetKeyboardMapping").unwrap(),