remove min/max resize policy
This commit is contained in:
parent
61ef63409b
commit
3fe752ca80
|
@ -21,12 +21,7 @@ impl WindowHandler for OpenWindowExample {
|
|||
fn main() {
|
||||
let window_open_options = baseview::WindowOpenOptions {
|
||||
title: "baseview".into(),
|
||||
size: WindowSize::MinMaxLogical {
|
||||
initial_size: baseview::Size::new(512.0, 512.0),
|
||||
min_size: baseview::Size::new(200.0, 200.0),
|
||||
max_size: baseview::Size::new(1024.0, 1024.0),
|
||||
keep_aspect: false,
|
||||
},
|
||||
size: WindowSize::Logical(baseview::Size::new(512.0, 512.0)),
|
||||
scale: WindowScalePolicy::TrySystemScaleFactor,
|
||||
parent: baseview::Parent::None,
|
||||
};
|
||||
|
|
|
@ -35,8 +35,6 @@ pub enum Parent {
|
|||
|
||||
unsafe impl Send for Parent {}
|
||||
|
||||
type WindowOpenResult = Result<WindowInfo, ()>;
|
||||
|
||||
pub trait WindowHandler {
|
||||
type Message;
|
||||
|
||||
|
|
|
@ -7,28 +7,6 @@ pub enum WindowSize {
|
|||
Logical(Size),
|
||||
/// Use physical width and height
|
||||
Physical(PhySize),
|
||||
/// Use minimum and maximum logical width and height
|
||||
MinMaxLogical {
|
||||
/// The initial logical width and height
|
||||
initial_size: Size,
|
||||
/// The minimum logical width and height
|
||||
min_size: Size,
|
||||
/// The maximum logical width and height
|
||||
max_size: Size,
|
||||
/// Whether to keep the aspect ratio when resizing (true), or not (false)
|
||||
keep_aspect: bool,
|
||||
},
|
||||
/// Use minimum and maximum physical width and height
|
||||
MinMaxPhysical {
|
||||
/// The initial physical width and height
|
||||
initial_size: PhySize,
|
||||
/// The minimum physical width and height
|
||||
min_size: PhySize,
|
||||
/// The maximum physical width and height
|
||||
max_size: PhySize,
|
||||
/// Whether to keep the aspect ratio when resizing (true), or not (false)
|
||||
keep_aspect: bool,
|
||||
},
|
||||
}
|
||||
|
||||
/// The dpi scaling policy of the window
|
||||
|
@ -63,12 +41,6 @@ impl WindowOpenOptions {
|
|||
match self.size {
|
||||
WindowSize::Logical(size) => WindowInfo::from_logical_size(size, scale),
|
||||
WindowSize::Physical(size) => WindowInfo::from_physical_size(size, scale),
|
||||
WindowSize::MinMaxLogical { initial_size, .. } => {
|
||||
WindowInfo::from_logical_size(initial_size, scale)
|
||||
},
|
||||
WindowSize::MinMaxPhysical { initial_size, .. } => {
|
||||
WindowInfo::from_physical_size(initial_size, scale)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,8 +12,7 @@ use raw_window_handle::{
|
|||
use super::XcbConnection;
|
||||
use crate::{
|
||||
Event, KeyboardEvent, MouseButton, MouseCursor, MouseEvent, Parent, ScrollDelta, WindowEvent,
|
||||
WindowHandler, WindowInfo, WindowOpenOptions, WindowOpenResult,
|
||||
WindowScalePolicy, PhyPoint, PhySize,
|
||||
WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy, PhyPoint, PhySize,
|
||||
};
|
||||
|
||||
pub struct Window {
|
||||
|
@ -39,6 +38,8 @@ impl WindowHandle {
|
|||
}
|
||||
}
|
||||
|
||||
type WindowOpenResult = Result<(), ()>;
|
||||
|
||||
impl Window {
|
||||
pub fn open<H, B>(options: WindowOpenOptions, build: B) -> WindowHandle
|
||||
where H: WindowHandler,
|
||||
|
@ -54,9 +55,9 @@ impl Window {
|
|||
});
|
||||
|
||||
// FIXME: placeholder types for returning errors in the future
|
||||
let window_info = rx.recv().unwrap().unwrap();
|
||||
let _ = rx.recv();
|
||||
|
||||
Ok((WindowHandle { thread }, window_info))
|
||||
WindowHandle { thread }
|
||||
}
|
||||
|
||||
fn window_thread<H, B>(options: WindowOpenOptions, build: B,
|
||||
|
@ -159,8 +160,6 @@ impl Window {
|
|||
);
|
||||
});
|
||||
|
||||
xcb_connection.set_resize_policy(window_id, &options.size, scaling);
|
||||
|
||||
xcb_connection.conn.flush();
|
||||
|
||||
let mut window = Self {
|
||||
|
@ -177,10 +176,10 @@ impl Window {
|
|||
|
||||
let mut handler = build(&mut window);
|
||||
|
||||
let _ = tx.send(Ok(window_info));
|
||||
let _ = tx.send(Ok(()));
|
||||
|
||||
window.run_event_loop(&mut handler);
|
||||
Ok(window_info)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn window_info(&self) -> &WindowInfo {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use std::ffi::{CStr, CString};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{MouseCursor, WindowSize};
|
||||
use crate::MouseCursor;
|
||||
|
||||
use super::cursor;
|
||||
|
||||
|
@ -154,69 +154,4 @@ impl XcbConnection {
|
|||
.entry(cursor)
|
||||
.or_insert_with(|| cursor::get_xcursor(dpy, cursor))
|
||||
}
|
||||
|
||||
pub fn set_resize_policy(&self, window_id: u32, size: &WindowSize, scale: f64) {
|
||||
match size {
|
||||
WindowSize::MinMaxLogical { min_size, max_size, keep_aspect, .. } => {
|
||||
let min_physical_width = (min_size.width as f64 * scale).round() as i32;
|
||||
let min_physical_height = (min_size.height as f64 * scale).round() as i32;
|
||||
let max_physical_width = (max_size.width as f64 * scale).round() as i32;
|
||||
let max_physical_height = (max_size.height as f64 * scale).round() as i32;
|
||||
|
||||
let size_hints = if *keep_aspect {
|
||||
xcb_util::icccm::SizeHints::empty()
|
||||
.min_size(min_physical_width, min_physical_height)
|
||||
.max_size(max_physical_width, max_physical_height)
|
||||
.aspect(
|
||||
(min_physical_width, min_physical_height),
|
||||
(max_physical_width, max_physical_height),
|
||||
)
|
||||
.build()
|
||||
} else {
|
||||
xcb_util::icccm::SizeHints::empty()
|
||||
.min_size(min_physical_width, min_physical_height)
|
||||
.max_size(max_physical_width, max_physical_height)
|
||||
.build()
|
||||
};
|
||||
|
||||
self.atoms.wm_normal_hints
|
||||
.map(|wm_normal_hints| {
|
||||
xcb_util::icccm::set_wm_size_hints(
|
||||
&self.conn,
|
||||
window_id,
|
||||
wm_normal_hints,
|
||||
&size_hints,
|
||||
);
|
||||
});
|
||||
}
|
||||
WindowSize::MinMaxPhysical { min_size, max_size, keep_aspect, .. } => {
|
||||
let size_hints = if *keep_aspect {
|
||||
xcb_util::icccm::SizeHints::empty()
|
||||
.min_size(min_size.width as i32, min_size.height as i32)
|
||||
.max_size(max_size.width as i32, max_size.height as i32)
|
||||
.aspect(
|
||||
(min_size.width as i32, min_size.height as i32),
|
||||
(max_size.width as i32, max_size.height as i32),
|
||||
)
|
||||
.build()
|
||||
} else {
|
||||
xcb_util::icccm::SizeHints::empty()
|
||||
.min_size(min_size.width as i32, min_size.height as i32)
|
||||
.max_size(max_size.width as i32, max_size.height as i32)
|
||||
.build()
|
||||
};
|
||||
|
||||
self.atoms.wm_normal_hints
|
||||
.map(|wm_normal_hints| {
|
||||
xcb_util::icccm::set_wm_size_hints(
|
||||
&self.conn,
|
||||
window_id,
|
||||
wm_normal_hints,
|
||||
&size_hints,
|
||||
);
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue