diff --git a/src/window.rs b/src/window.rs index a0d91f6..237e8b6 100644 --- a/src/window.rs +++ b/src/window.rs @@ -4,6 +4,7 @@ use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use crate::event::{Event, EventStatus}; use crate::window_open_options::WindowOpenOptions; +use crate::Size; #[cfg(target_os = "macos")] use crate::macos as platform; @@ -98,6 +99,16 @@ impl<'a> Window<'a> { self.window.close(); } + /// Resize the window to the given size. + /// + /// # TODO + /// + /// This is currently only supported on Linux. + #[cfg(target_os = "linux")] + pub fn resize(&mut self, size: Size) { + self.window.resize(size); + } + /// If provided, then an OpenGL context will be created for this window. You'll be able to /// access this context through [crate::Window::gl_context]. #[cfg(feature = "opengl")] diff --git a/src/x11/window.rs b/src/x11/window.rs index 2ad0cad..faebe44 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -12,7 +12,7 @@ use xcb::StructPtr; use super::XcbConnection; use crate::{ - Event, MouseButton, MouseCursor, MouseEvent, PhyPoint, PhySize, ScrollDelta, WindowEvent, + Event, MouseButton, MouseCursor, MouseEvent, PhyPoint, PhySize, ScrollDelta, Size, WindowEvent, WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy, }; @@ -389,6 +389,18 @@ impl Window { self.close_requested = true; } + pub fn resize(&mut self, size: Size) { + xcb::configure_window( + &self.xcb_connection.conn, + self.window_id, + &[ + (xcb::CONFIG_WINDOW_WIDTH as u16, size.width.round() as u32), + (xcb::CONFIG_WINDOW_HEIGHT as u16, size.height.round() as u32), + ], + ); + self.xcb_connection.conn.flush(); + } + #[cfg(feature = "opengl")] pub fn gl_context(&self) -> Option<&crate::gl::GlContext> { self.gl_context.as_ref()