remove min/max resize policy
This commit is contained in:
parent
61ef63409b
commit
3fe752ca80
5 changed files with 9 additions and 110 deletions
|
@ -21,12 +21,7 @@ impl WindowHandler for OpenWindowExample {
|
||||||
fn main() {
|
fn main() {
|
||||||
let window_open_options = baseview::WindowOpenOptions {
|
let window_open_options = baseview::WindowOpenOptions {
|
||||||
title: "baseview".into(),
|
title: "baseview".into(),
|
||||||
size: WindowSize::MinMaxLogical {
|
size: WindowSize::Logical(baseview::Size::new(512.0, 512.0)),
|
||||||
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,
|
|
||||||
},
|
|
||||||
scale: WindowScalePolicy::TrySystemScaleFactor,
|
scale: WindowScalePolicy::TrySystemScaleFactor,
|
||||||
parent: baseview::Parent::None,
|
parent: baseview::Parent::None,
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,8 +35,6 @@ pub enum Parent {
|
||||||
|
|
||||||
unsafe impl Send for Parent {}
|
unsafe impl Send for Parent {}
|
||||||
|
|
||||||
type WindowOpenResult = Result<WindowInfo, ()>;
|
|
||||||
|
|
||||||
pub trait WindowHandler {
|
pub trait WindowHandler {
|
||||||
type Message;
|
type Message;
|
||||||
|
|
||||||
|
|
|
@ -7,28 +7,6 @@ pub enum WindowSize {
|
||||||
Logical(Size),
|
Logical(Size),
|
||||||
/// Use physical width and height
|
/// Use physical width and height
|
||||||
Physical(PhySize),
|
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
|
/// The dpi scaling policy of the window
|
||||||
|
@ -63,12 +41,6 @@ impl WindowOpenOptions {
|
||||||
match self.size {
|
match self.size {
|
||||||
WindowSize::Logical(size) => WindowInfo::from_logical_size(size, scale),
|
WindowSize::Logical(size) => WindowInfo::from_logical_size(size, scale),
|
||||||
WindowSize::Physical(size) => WindowInfo::from_physical_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 super::XcbConnection;
|
||||||
use crate::{
|
use crate::{
|
||||||
Event, KeyboardEvent, MouseButton, MouseCursor, MouseEvent, Parent, ScrollDelta, WindowEvent,
|
Event, KeyboardEvent, MouseButton, MouseCursor, MouseEvent, Parent, ScrollDelta, WindowEvent,
|
||||||
WindowHandler, WindowInfo, WindowOpenOptions, WindowOpenResult,
|
WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy, PhyPoint, PhySize,
|
||||||
WindowScalePolicy, PhyPoint, PhySize,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
|
@ -39,6 +38,8 @@ impl WindowHandle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WindowOpenResult = Result<(), ()>;
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn open<H, B>(options: WindowOpenOptions, build: B) -> WindowHandle
|
pub fn open<H, B>(options: WindowOpenOptions, build: B) -> WindowHandle
|
||||||
where H: WindowHandler,
|
where H: WindowHandler,
|
||||||
|
@ -54,9 +55,9 @@ impl Window {
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME: placeholder types for returning errors in the future
|
// 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,
|
fn window_thread<H, B>(options: WindowOpenOptions, build: B,
|
||||||
|
@ -158,8 +159,6 @@ impl Window {
|
||||||
&[wm_delete_window],
|
&[wm_delete_window],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
xcb_connection.set_resize_policy(window_id, &options.size, scaling);
|
|
||||||
|
|
||||||
xcb_connection.conn.flush();
|
xcb_connection.conn.flush();
|
||||||
|
|
||||||
|
@ -177,10 +176,10 @@ impl Window {
|
||||||
|
|
||||||
let mut handler = build(&mut window);
|
let mut handler = build(&mut window);
|
||||||
|
|
||||||
let _ = tx.send(Ok(window_info));
|
let _ = tx.send(Ok(()));
|
||||||
|
|
||||||
window.run_event_loop(&mut handler);
|
window.run_event_loop(&mut handler);
|
||||||
Ok(window_info)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn window_info(&self) -> &WindowInfo {
|
pub fn window_info(&self) -> &WindowInfo {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{MouseCursor, WindowSize};
|
use crate::MouseCursor;
|
||||||
|
|
||||||
use super::cursor;
|
use super::cursor;
|
||||||
|
|
||||||
|
@ -154,69 +154,4 @@ impl XcbConnection {
|
||||||
.entry(cursor)
|
.entry(cursor)
|
||||||
.or_insert_with(|| cursor::get_xcursor(dpy, 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…
Add table
Reference in a new issue