Make MonitorId::get_position() return (i32, i32) instead of (u32, u32) because it can be negative on Windows (#324)

This commit is contained in:
kryptan 2017-10-19 20:08:05 +03:00 committed by tomaka
parent 229029f2da
commit 4e4db1749d
12 changed files with 27 additions and 19 deletions

View file

@ -6,6 +6,7 @@
`get_inner_size`.
- **Breaking:** `EventsLoop` is `!Send` and `!Sync` because of platform-dependant constraints,
but `Window`, `WindowId`, `DeviceId` and `MonitorId` guaranteed to be `Send`.
- `MonitorId::get_position` now returns `(i32, i32)` instead of `(u32, u32)`.
# Version 0.8.3 (2017-10-11)

View file

@ -160,7 +160,7 @@ impl MonitorId {
}
#[inline]
pub fn get_position(&self) -> (u32, u32) {
pub fn get_position(&self) -> (i32, i32) {
// Android assumes single screen
(0, 0)
}

View file

@ -34,7 +34,7 @@ impl MonitorId {
}
#[inline]
pub fn get_position(&self) -> (u32, u32) {
pub fn get_position(&self) -> (i32, i32) {
unimplemented!()
}

View file

@ -141,7 +141,7 @@ impl MonitorId {
}
#[inline]
pub fn get_position(&self) -> (u32, u32) {
pub fn get_position(&self) -> (i32, i32) {
// iOS assumes single screen
(0, 0)
}

View file

@ -88,7 +88,7 @@ impl MonitorId {
}
#[inline]
pub fn get_position(&self) -> (u32, u32) {
pub fn get_position(&self) -> (i32, i32) {
match self {
&MonitorId::X(ref m) => m.get_position(),
&MonitorId::Wayland(ref m) => m.get_position(),
@ -97,7 +97,10 @@ impl MonitorId {
#[inline]
pub fn get_hidpi_factor(&self) -> f32 {
1.0
match self {
&MonitorId::X(ref m) => m.get_hidpi_factor(),
&MonitorId::Wayland(ref m) => m.get_hidpi_factor(),
}
}
}

View file

@ -37,7 +37,7 @@ struct OutputInfo {
id: u32,
scale: f32,
pix_size: (u32, u32),
pix_pos: (u32, u32),
pix_pos: (i32, i32),
name: String
}
@ -162,7 +162,7 @@ impl wl_output::Handler for WaylandEnv {
{
for m in self.monitors.iter_mut().filter(|m| m.output.equals(proxy)) {
m.name = format!("{} ({})", model, make);
m.pix_pos = (x as u32, y as u32);
m.pix_pos = (x, y);
break;
}
}
@ -397,7 +397,7 @@ impl MonitorId {
(0,0)
}
pub fn get_position(&self) -> (u32, u32) {
pub fn get_position(&self) -> (i32, i32) {
let mut guard = self.ctxt.evq.lock().unwrap();
let state = guard.state();
let env = state.get_handler::<WaylandEnv>(self.ctxt.env_id);

View file

@ -204,6 +204,8 @@ impl Window {
let mut find = default;
for monitor in monitors {
let (mx, my) = monitor.get_position();
let mx = mx as u32;
let my = my as u32;
let (mw, mh) = monitor.get_dimensions();
let (mxo, myo) = (mx+mw-1, my+mh-1);
let (ox, oy) = (cmp::max(wx, mx), cmp::max(wy, my));

View file

@ -12,7 +12,7 @@ pub struct MonitorId {
/// The size of the monitor
dimensions: (u32, u32),
/// The position of the monitor in the X screen
position: (u32, u32),
position: (i32, i32),
/// If the monitor is the primary one
primary: bool,
}
@ -40,7 +40,7 @@ pub fn get_available_monitors(x: &Arc<XConnection>) -> Vec<MonitorId> {
id: i as u32,
name,
dimensions: (monitor.width as u32, monitor.height as u32),
position: (monitor.x as u32, monitor.y as u32),
position: (monitor.x as i32, monitor.y as i32),
primary: (monitor.primary != 0),
});
}
@ -61,7 +61,7 @@ pub fn get_available_monitors(x: &Arc<XConnection>) -> Vec<MonitorId> {
id: crtcid as u32,
name,
dimensions: ((*crtc).width as u32, (*crtc).height as u32),
position: ((*crtc).x as u32, (*crtc).y as u32),
position: ((*crtc).x as i32, (*crtc).y as i32),
primary: true,
});
}
@ -98,7 +98,7 @@ impl MonitorId {
self.dimensions
}
pub fn get_position(&self) -> (u32, u32) {
pub fn get_position(&self) -> (i32, i32) {
self.position
}

View file

@ -332,6 +332,8 @@ impl Window2 {
let mut find = default;
for monitor in monitors {
let (mx, my) = monitor.get_position();
let mx = mx as u32;
let my = my as u32;
let (mw, mh) = monitor.get_dimensions();
let (mxo, myo) = (mx+mw-1, my+mh-1);
let (ox, oy) = (cmp::max(wx, mx), cmp::max(wy, my));

View file

@ -50,7 +50,7 @@ impl MonitorId {
}
#[inline]
pub fn get_position(&self) -> (u32, u32) {
pub fn get_position(&self) -> (i32, i32) {
unimplemented!()
}

View file

@ -27,8 +27,8 @@ pub struct MonitorId {
/// The position of the monitor in pixels on the desktop.
///
/// A window that is positionned at these coordinates will overlap the monitor.
position: (u32, u32),
/// A window that is positioned at these coordinates will overlap the monitor.
position: (i32, i32),
/// The current resolution in pixels on the monitor.
dimensions: (u32, u32),
@ -111,7 +111,7 @@ impl EventsLoop {
}
let point: &winapi::POINTL = mem::transmute(&dev.union1);
let position = (point.x as u32, point.y as u32);
let position = (point.x as i32, point.y as i32);
let dimensions = (dev.dmPelsWidth as u32, dev.dmPelsHeight as u32);
@ -176,9 +176,9 @@ impl MonitorId {
&self.adapter_name
}
/// A window that is positionned at these coordinates will overlap the monitor.
/// A window that is positioned at these coordinates will overlap the monitor.
#[inline]
pub fn get_position(&self) -> (u32, u32) {
pub fn get_position(&self) -> (i32, i32) {
self.position
}

View file

@ -370,7 +370,7 @@ impl MonitorId {
/// Returns the top-left corner position of the monitor relative to the larger full
/// screen area.
#[inline]
pub fn get_position(&self) -> (u32, u32) {
pub fn get_position(&self) -> (i32, i32) {
self.inner.get_position()
}