Make size/position types generic over pixel type (#1277)
* Begin implementing DPI generics * Fix multithreaded example * Format * Fix serde test * hopefully fix most of the errors * Fix dpi module errors * More error fixings * Format * fix macos errors * Another error pass * Replace bad type signatures * more fixins
This commit is contained in:
parent
b16042a047
commit
3a1e694c2f
40 changed files with 388 additions and 336 deletions
|
|
@ -132,7 +132,7 @@ impl MonitorHandle {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn size(&self) -> PhysicalSize {
|
||||
pub fn size(&self) -> PhysicalSize<u32> {
|
||||
match self {
|
||||
&MonitorHandle::X(ref m) => m.size(),
|
||||
&MonitorHandle::Wayland(ref m) => m.size(),
|
||||
|
|
@ -140,7 +140,7 @@ impl MonitorHandle {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn position(&self) -> PhysicalPosition {
|
||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
||||
match self {
|
||||
&MonitorHandle::X(ref m) => m.position(),
|
||||
&MonitorHandle::Wayland(ref m) => m.position(),
|
||||
|
|
@ -172,7 +172,7 @@ pub enum VideoMode {
|
|||
|
||||
impl VideoMode {
|
||||
#[inline]
|
||||
pub fn size(&self) -> PhysicalSize {
|
||||
pub fn size(&self) -> PhysicalSize<u32> {
|
||||
match self {
|
||||
&VideoMode::X(ref m) => m.size(),
|
||||
&VideoMode::Wayland(ref m) => m.size(),
|
||||
|
|
@ -246,7 +246,7 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn outer_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
|
||||
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
||||
match self {
|
||||
&Window::X(ref w) => w.outer_position(),
|
||||
&Window::Wayland(ref w) => w.outer_position(),
|
||||
|
|
@ -254,7 +254,7 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inner_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
|
||||
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
||||
match self {
|
||||
&Window::X(ref m) => m.inner_position(),
|
||||
&Window::Wayland(ref m) => m.inner_position(),
|
||||
|
|
@ -270,7 +270,7 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inner_size(&self) -> PhysicalSize {
|
||||
pub fn inner_size(&self) -> PhysicalSize<u32> {
|
||||
match self {
|
||||
&Window::X(ref w) => w.inner_size(),
|
||||
&Window::Wayland(ref w) => w.inner_size(),
|
||||
|
|
@ -278,7 +278,7 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn outer_size(&self) -> PhysicalSize {
|
||||
pub fn outer_size(&self) -> PhysicalSize<u32> {
|
||||
match self {
|
||||
&Window::X(ref w) => w.outer_size(),
|
||||
&Window::Wayland(ref w) => w.outer_size(),
|
||||
|
|
|
|||
|
|
@ -729,7 +729,7 @@ impl<T> EventLoop<T> {
|
|||
|
||||
if let Some(dpi) = window.new_dpi {
|
||||
let dpi = dpi as f64;
|
||||
let logical_size = LogicalSize::from(*window.size);
|
||||
let logical_size = LogicalSize::<f64>::from(*window.size);
|
||||
let mut new_inner_size = Some(logical_size.to_physical(dpi));
|
||||
|
||||
callback(Event::WindowEvent {
|
||||
|
|
@ -741,7 +741,7 @@ impl<T> EventLoop<T> {
|
|||
});
|
||||
|
||||
if let Some(new_size) = new_inner_size {
|
||||
let (w, h) = new_size.to_logical(dpi).into();
|
||||
let (w, h) = new_size.to_logical::<u32>(dpi).into();
|
||||
frame.resize(w, h);
|
||||
*window.size = (w, h);
|
||||
}
|
||||
|
|
@ -947,7 +947,7 @@ pub struct VideoMode {
|
|||
|
||||
impl VideoMode {
|
||||
#[inline]
|
||||
pub fn size(&self) -> PhysicalSize {
|
||||
pub fn size(&self) -> PhysicalSize<u32> {
|
||||
self.size.into()
|
||||
}
|
||||
|
||||
|
|
@ -1007,8 +1007,8 @@ impl fmt::Debug for MonitorHandle {
|
|||
struct MonitorHandle {
|
||||
name: Option<String>,
|
||||
native_identifier: u32,
|
||||
size: PhysicalSize,
|
||||
position: PhysicalPosition,
|
||||
size: PhysicalSize<u32>,
|
||||
position: PhysicalPosition<i32>,
|
||||
hidpi_factor: i32,
|
||||
}
|
||||
|
||||
|
|
@ -1036,7 +1036,7 @@ impl MonitorHandle {
|
|||
self.mgr.with_info(&self.proxy, |id, _| id).unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn size(&self) -> PhysicalSize {
|
||||
pub fn size(&self) -> PhysicalSize<u32> {
|
||||
match self.mgr.with_info(&self.proxy, |_, info| {
|
||||
info.modes
|
||||
.iter()
|
||||
|
|
@ -1049,7 +1049,7 @@ impl MonitorHandle {
|
|||
.into()
|
||||
}
|
||||
|
||||
pub fn position(&self) -> PhysicalPosition {
|
||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
||||
self.mgr
|
||||
.with_info(&self.proxy, |_, info| info.location)
|
||||
.unwrap_or((0, 0))
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ impl Window {
|
|||
let dpi = get_dpi_factor(&surface) as f64;
|
||||
let (width, height) = attributes
|
||||
.inner_size
|
||||
.map(|size| size.to_logical(dpi).into())
|
||||
.map(|size| size.to_logical::<f64>(dpi).into())
|
||||
.unwrap_or((800, 600));
|
||||
|
||||
// Create the window
|
||||
|
|
@ -147,12 +147,12 @@ impl Window {
|
|||
frame.set_min_size(
|
||||
attributes
|
||||
.min_inner_size
|
||||
.map(|size| size.to_logical(dpi).into()),
|
||||
.map(|size| size.to_logical::<f64>(dpi).into()),
|
||||
);
|
||||
frame.set_max_size(
|
||||
attributes
|
||||
.max_inner_size
|
||||
.map(|size| size.to_logical(dpi).into()),
|
||||
.map(|size| size.to_logical::<f64>(dpi).into()),
|
||||
);
|
||||
|
||||
let kill_switch = Arc::new(Mutex::new(false));
|
||||
|
|
@ -206,12 +206,12 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn outer_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
|
||||
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
||||
Err(NotSupportedError::new())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inner_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
|
||||
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
||||
Err(NotSupportedError::new())
|
||||
}
|
||||
|
||||
|
|
@ -220,9 +220,9 @@ impl Window {
|
|||
// Not possible with wayland
|
||||
}
|
||||
|
||||
pub fn inner_size(&self) -> PhysicalSize {
|
||||
pub fn inner_size(&self) -> PhysicalSize<u32> {
|
||||
let dpi = self.hidpi_factor() as f64;
|
||||
let size = LogicalSize::from(*self.size.lock().unwrap());
|
||||
let size = LogicalSize::<f64>::from(*self.size.lock().unwrap());
|
||||
size.to_physical(dpi)
|
||||
}
|
||||
|
||||
|
|
@ -231,11 +231,11 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn outer_size(&self) -> PhysicalSize {
|
||||
pub fn outer_size(&self) -> PhysicalSize<u32> {
|
||||
let dpi = self.hidpi_factor() as f64;
|
||||
let (w, h) = self.size.lock().unwrap().clone();
|
||||
// let (w, h) = super::wayland_window::add_borders(w as i32, h as i32);
|
||||
let size = LogicalSize::from((w, h));
|
||||
let size = LogicalSize::<f64>::from((w, h));
|
||||
size.to_physical(dpi)
|
||||
}
|
||||
|
||||
|
|
@ -243,7 +243,7 @@ impl Window {
|
|||
// NOTE: This will only resize the borders, the contents must be updated by the user
|
||||
pub fn set_inner_size(&self, size: Size) {
|
||||
let dpi = self.hidpi_factor() as f64;
|
||||
let (w, h) = size.to_logical(dpi).into();
|
||||
let (w, h) = size.to_logical::<u32>(dpi).into();
|
||||
self.frame.lock().unwrap().resize(w, h);
|
||||
*(self.size.lock().unwrap()) = (w, h);
|
||||
}
|
||||
|
|
@ -254,7 +254,7 @@ impl Window {
|
|||
self.frame
|
||||
.lock()
|
||||
.unwrap()
|
||||
.set_min_size(dimensions.map(|dim| dim.to_logical(dpi).into()));
|
||||
.set_min_size(dimensions.map(|dim| dim.to_logical::<f64>(dpi).into()));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -263,7 +263,7 @@ impl Window {
|
|||
self.frame
|
||||
.lock()
|
||||
.unwrap()
|
||||
.set_max_size(dimensions.map(|dim| dim.to_logical(dpi).into()));
|
||||
.set_max_size(dimensions.map(|dim| dim.to_logical::<f64>(dpi).into()));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -707,7 +707,7 @@ impl<T: 'static> EventProcessor<T> {
|
|||
});
|
||||
if cursor_moved == Some(true) {
|
||||
let position =
|
||||
PhysicalPosition::new(xev.event_x as f64, xev.event_y as f64);
|
||||
PhysicalPosition::new(xev.event_x as i32, xev.event_y as i32);
|
||||
|
||||
callback(Event::WindowEvent {
|
||||
window_id,
|
||||
|
|
@ -814,7 +814,7 @@ impl<T: 'static> EventProcessor<T> {
|
|||
});
|
||||
|
||||
let position =
|
||||
PhysicalPosition::new(xev.event_x as f64, xev.event_y as f64);
|
||||
PhysicalPosition::new(xev.event_x as i32, xev.event_y as i32);
|
||||
|
||||
// The mods field on this event isn't actually populated, so query the
|
||||
// pointer device. In the future, we can likely remove this round-trip by
|
||||
|
|
@ -883,7 +883,7 @@ impl<T: 'static> EventProcessor<T> {
|
|||
.unwrap_or(2);
|
||||
|
||||
let position =
|
||||
PhysicalPosition::new(xev.event_x as f64, xev.event_y as f64);
|
||||
PhysicalPosition::new(xev.event_x as i32, xev.event_y as i32);
|
||||
|
||||
callback(Event::WindowEvent {
|
||||
window_id,
|
||||
|
|
@ -941,7 +941,7 @@ impl<T: 'static> EventProcessor<T> {
|
|||
window_id,
|
||||
event: WindowEvent::CursorMoved {
|
||||
device_id: mkdid(util::VIRTUAL_CORE_POINTER),
|
||||
position: location,
|
||||
position: location.cast(),
|
||||
modifiers,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ pub struct VideoMode {
|
|||
|
||||
impl VideoMode {
|
||||
#[inline]
|
||||
pub fn size(&self) -> PhysicalSize {
|
||||
pub fn size(&self) -> PhysicalSize<u32> {
|
||||
self.size.into()
|
||||
}
|
||||
|
||||
|
|
@ -157,11 +157,11 @@ impl MonitorHandle {
|
|||
self.id as u32
|
||||
}
|
||||
|
||||
pub fn size(&self) -> PhysicalSize {
|
||||
pub fn size(&self) -> PhysicalSize<u32> {
|
||||
self.dimensions.into()
|
||||
}
|
||||
|
||||
pub fn position(&self) -> PhysicalPosition {
|
||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
||||
self.position.into()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,9 +137,9 @@ impl FrameExtentsHeuristic {
|
|||
|
||||
pub fn inner_pos_to_outer_logical(
|
||||
&self,
|
||||
mut logical: LogicalPosition,
|
||||
mut logical: LogicalPosition<f64>,
|
||||
factor: f64,
|
||||
) -> LogicalPosition {
|
||||
) -> LogicalPosition<f64> {
|
||||
use self::FrameExtentsHeuristicPath::*;
|
||||
if self.heuristic_path != UnsupportedBordered {
|
||||
let frame_extents = self.frame_extents.as_logical(factor);
|
||||
|
|
@ -166,9 +166,9 @@ impl FrameExtentsHeuristic {
|
|||
|
||||
pub fn inner_size_to_outer_logical(
|
||||
&self,
|
||||
mut logical: LogicalSize,
|
||||
mut logical: LogicalSize<f64>,
|
||||
factor: f64,
|
||||
) -> LogicalSize {
|
||||
) -> LogicalSize<f64> {
|
||||
let frame_extents = self.frame_extents.as_logical(factor);
|
||||
logical.width += frame_extents.left + frame_extents.right;
|
||||
logical.height += frame_extents.top + frame_extents.bottom;
|
||||
|
|
|
|||
|
|
@ -138,17 +138,17 @@ impl UnownedWindow {
|
|||
|
||||
let max_inner_size: Option<(u32, u32)> = window_attrs
|
||||
.max_inner_size
|
||||
.map(|size| size.to_physical(dpi_factor).into());
|
||||
.map(|size| size.to_physical::<u32>(dpi_factor).into());
|
||||
let min_inner_size: Option<(u32, u32)> = window_attrs
|
||||
.min_inner_size
|
||||
.map(|size| size.to_physical(dpi_factor).into());
|
||||
.map(|size| size.to_physical::<u32>(dpi_factor).into());
|
||||
|
||||
let dimensions = {
|
||||
// x11 only applies constraints when the window is actively resized
|
||||
// by the user, so we have to manually apply the initial constraints
|
||||
let mut dimensions: (u32, u32) = window_attrs
|
||||
.inner_size
|
||||
.map(|size| size.to_physical(dpi_factor))
|
||||
.map(|size| size.to_physical::<u32>(dpi_factor))
|
||||
.or_else(|| Some((800, 600).into()))
|
||||
.map(Into::into)
|
||||
.unwrap();
|
||||
|
|
@ -320,10 +320,10 @@ impl UnownedWindow {
|
|||
{
|
||||
let mut min_inner_size = window_attrs
|
||||
.min_inner_size
|
||||
.map(|size| size.to_physical(dpi_factor));
|
||||
.map(|size| size.to_physical::<u32>(dpi_factor));
|
||||
let mut max_inner_size = window_attrs
|
||||
.max_inner_size
|
||||
.map(|size| size.to_physical(dpi_factor));
|
||||
.map(|size| size.to_physical::<u32>(dpi_factor));
|
||||
if !window_attrs.resizable {
|
||||
if util::wm_name_is_one_of(&["Xfwm4"]) {
|
||||
warn!("To avoid a WM bug, disabling resizing has no effect on Xfwm4");
|
||||
|
|
@ -941,7 +941,7 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn outer_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
|
||||
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
||||
let extents = (*self.shared_state.lock()).frame_extents.clone();
|
||||
if let Some(extents) = extents {
|
||||
let (x, y) = self.inner_position_physical();
|
||||
|
|
@ -962,7 +962,7 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inner_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
|
||||
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
||||
Ok(self.inner_position_physical().into())
|
||||
}
|
||||
|
||||
|
|
@ -993,7 +993,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
pub fn set_outer_position(&self, position: Position) {
|
||||
let (x, y) = position.to_physical(self.hidpi_factor()).into();
|
||||
let (x, y) = position.to_physical::<i32>(self.hidpi_factor()).into();
|
||||
self.set_position_physical(x, y);
|
||||
}
|
||||
|
||||
|
|
@ -1007,12 +1007,12 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inner_size(&self) -> PhysicalSize {
|
||||
pub fn inner_size(&self) -> PhysicalSize<u32> {
|
||||
self.inner_size_physical().into()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn outer_size(&self) -> PhysicalSize {
|
||||
pub fn outer_size(&self) -> PhysicalSize<u32> {
|
||||
let extents = self.shared_state.lock().frame_extents.clone();
|
||||
if let Some(extents) = extents {
|
||||
let (width, height) = self.inner_size_physical();
|
||||
|
|
@ -1039,7 +1039,7 @@ impl UnownedWindow {
|
|||
#[inline]
|
||||
pub fn set_inner_size(&self, size: Size) {
|
||||
let dpi_factor = self.hidpi_factor();
|
||||
let (width, height) = size.to_physical(dpi_factor).into();
|
||||
let (width, height) = size.to_physical::<u32>(dpi_factor).into();
|
||||
self.set_inner_size_physical(width, height);
|
||||
}
|
||||
|
||||
|
|
@ -1063,7 +1063,7 @@ impl UnownedWindow {
|
|||
pub fn set_min_inner_size(&self, dimensions: Option<Size>) {
|
||||
self.shared_state.lock().min_inner_size = dimensions;
|
||||
let physical_dimensions =
|
||||
dimensions.map(|dimensions| dimensions.to_physical(self.hidpi_factor()).into());
|
||||
dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.hidpi_factor()).into());
|
||||
self.set_min_inner_size_physical(physical_dimensions);
|
||||
}
|
||||
|
||||
|
|
@ -1076,7 +1076,7 @@ impl UnownedWindow {
|
|||
pub fn set_max_inner_size(&self, dimensions: Option<Size>) {
|
||||
self.shared_state.lock().max_inner_size = dimensions;
|
||||
let physical_dimensions =
|
||||
dimensions.map(|dimensions| dimensions.to_physical(self.hidpi_factor()).into());
|
||||
dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.hidpi_factor()).into());
|
||||
self.set_max_inner_size_physical(physical_dimensions);
|
||||
}
|
||||
|
||||
|
|
@ -1135,10 +1135,10 @@ impl UnownedWindow {
|
|||
|
||||
let dpi_factor = self.hidpi_factor();
|
||||
let min_inner_size = min_size
|
||||
.map(|size| size.to_physical(dpi_factor))
|
||||
.map(|size| size.to_physical::<u32>(dpi_factor))
|
||||
.map(Into::into);
|
||||
let max_inner_size = max_size
|
||||
.map(|size| size.to_physical(dpi_factor))
|
||||
.map(|size| size.to_physical::<u32>(dpi_factor))
|
||||
.map(Into::into);
|
||||
self.update_normal_hints(|normal_hints| {
|
||||
normal_hints.set_min_size(min_inner_size);
|
||||
|
|
@ -1274,7 +1274,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
pub fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError> {
|
||||
let (x, y) = position.to_physical(self.hidpi_factor()).into();
|
||||
let (x, y) = position.to_physical::<i32>(self.hidpi_factor()).into();
|
||||
self.set_cursor_position_physical(x, y)
|
||||
}
|
||||
|
||||
|
|
@ -1287,7 +1287,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
pub fn set_ime_position(&self, spot: Position) {
|
||||
let (x, y) = spot.to_physical(self.hidpi_factor()).into();
|
||||
let (x, y) = spot.to_physical::<i32>(self.hidpi_factor()).into();
|
||||
self.set_ime_position_physical(x, y);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue