1
0
Fork 0

Add window resizing for X11

This commit is contained in:
Robbert van der Helm 2022-03-27 16:01:58 +02:00
parent ee156fb884
commit d61f21666c
2 changed files with 24 additions and 1 deletions

View file

@ -4,6 +4,7 @@ use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use crate::event::{Event, EventStatus}; use crate::event::{Event, EventStatus};
use crate::window_open_options::WindowOpenOptions; use crate::window_open_options::WindowOpenOptions;
use crate::Size;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use crate::macos as platform; use crate::macos as platform;
@ -98,6 +99,16 @@ impl<'a> Window<'a> {
self.window.close(); 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 /// 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]. /// access this context through [crate::Window::gl_context].
#[cfg(feature = "opengl")] #[cfg(feature = "opengl")]

View file

@ -12,7 +12,7 @@ use xcb::StructPtr;
use super::XcbConnection; use super::XcbConnection;
use crate::{ use crate::{
Event, MouseButton, MouseCursor, MouseEvent, PhyPoint, PhySize, ScrollDelta, WindowEvent, Event, MouseButton, MouseCursor, MouseEvent, PhyPoint, PhySize, ScrollDelta, Size, WindowEvent,
WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy, WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy,
}; };
@ -389,6 +389,18 @@ impl Window {
self.close_requested = true; 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")] #[cfg(feature = "opengl")]
pub fn gl_context(&self) -> Option<&crate::gl::GlContext> { pub fn gl_context(&self) -> Option<&crate::gl::GlContext> {
self.gl_context.as_ref() self.gl_context.as_ref()