Skip to content

Commit

Permalink
X11 fully uses the new API
Browse files Browse the repository at this point in the history
  • Loading branch information
francesca64 committed Jun 3, 2018
1 parent caba966 commit 2dbe28e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
14 changes: 9 additions & 5 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use {
LogicalPosition,
LogicalSize,
MouseCursor,
PhysicalPosition,
PhysicalSize,
ControlFlow,
WindowAttributes,
};
Expand Down Expand Up @@ -95,26 +97,28 @@ impl MonitorId {
}

#[inline]
pub fn get_dimensions(&self) -> (u32, u32) {
pub fn get_dimensions(&self) -> PhysicalSize {
match self {
&MonitorId::X(ref m) => m.get_dimensions(),
&MonitorId::Wayland(ref m) => m.get_dimensions(),
//&MonitorId::Wayland(ref m) => m.get_dimensions(),
_ => unimplemented!(),
}
}

#[inline]
pub fn get_position(&self) -> (i32, i32) {
pub fn get_position(&self) -> PhysicalPosition {
match self {
&MonitorId::X(ref m) => m.get_position(),
&MonitorId::Wayland(ref m) => m.get_position(),
//&MonitorId::Wayland(ref m) => m.get_position(),
_ => unimplemented!(),
}
}

#[inline]
pub fn get_hidpi_factor(&self) -> f64 {
match self {
&MonitorId::X(ref m) => m.get_hidpi_factor(),
&MonitorId::Wayland(ref m) => m.get_hidpi_factor(),
&MonitorId::Wayland(ref m) => m.get_hidpi_factor() as f64,
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/platform/linux/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ pub struct Window {

impl Window {
pub fn new(evlp: &EventsLoop, attributes: WindowAttributes) -> Result<Window, CreationError> {
let (width, height) = attributes.dimensions.unwrap_or((800, 600));
// TODO: Update for new DPI API
//let (width, height) = attributes.dimensions.unwrap_or((800, 600));
let (width, height) = (64, 64);
// Create the window
let size = Arc::new(Mutex::new((width, height)));

Expand Down Expand Up @@ -105,8 +107,9 @@ impl Window {
frame.set_decorate(attributes.decorations);

// min-max dimensions
frame.set_min_size(attributes.min_dimensions);
frame.set_max_size(attributes.max_dimensions);
// TODO: Update for new DPI API
//frame.set_min_size(attributes.min_dimensions);
//frame.set_max_size(attributes.max_dimensions);

let kill_switch = Arc::new(Mutex::new(false));
let need_frame_refresh = Arc::new(Mutex::new(true));
Expand Down
15 changes: 8 additions & 7 deletions src/platform/linux/x11/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::os::raw::*;

use parking_lot::Mutex;

use {PhysicalPosition, PhysicalSize};
use super::{util, XConnection, XError};
use super::ffi::{
RRCrtcChangeNotifyMask,
RROutputPropertyNotifyMask,
Expand All @@ -10,7 +12,6 @@ use super::ffi::{
Window,
XRRScreenResources,
};
use super::{util, XConnection, XError};

// Used to test XRandR < 1.5 code path. This should always be committed as false.
const FORCE_RANDR_COMPAT: bool = false;
Expand Down Expand Up @@ -88,17 +89,17 @@ impl MonitorId {
self.id as u32
}

pub fn get_dimensions(&self) -> (u32, u32) {
self.dimensions
pub fn get_dimensions(&self) -> PhysicalSize {
self.dimensions.into()
}

pub fn get_position(&self) -> (i32, i32) {
self.position
pub fn get_position(&self) -> PhysicalPosition {
self.position.into()
}

#[inline]
pub fn get_hidpi_factor(&self) -> f32 {
self.hidpi_factor as f32
pub fn get_hidpi_factor(&self) -> f64 {
self.hidpi_factor
}
}

Expand Down
19 changes: 12 additions & 7 deletions src/platform/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@ impl UnownedWindow {
let xconn = &event_loop.xconn;
let root = event_loop.root;

let max_dimensions: Option<(u32, u32)> = window_attrs.max_dimensions.map(Into::into);
let min_dimensions: Option<(u32, u32)> = window_attrs.min_dimensions.map(Into::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 = window_attrs.dimensions.unwrap_or((800, 600));
if let Some(max) = window_attrs.max_dimensions {
let mut dimensions = window_attrs.dimensions
.map(Into::into)
.unwrap_or((800, 600));
if let Some(max) = max_dimensions {
dimensions.0 = cmp::min(dimensions.0, max.0);
dimensions.1 = cmp::min(dimensions.1, max.1);
}
if let Some(min) = window_attrs.min_dimensions {
if let Some(min) = min_dimensions {
dimensions.0 = cmp::max(dimensions.0, min.0);
dimensions.1 = cmp::max(dimensions.1, min.1);
}
Expand Down Expand Up @@ -237,8 +242,8 @@ impl UnownedWindow {
{
let mut normal_hints = util::NormalHints::new(xconn);
normal_hints.set_size(Some(dimensions));
normal_hints.set_min_size(window_attrs.min_dimensions);
normal_hints.set_max_size(window_attrs.max_dimensions);
normal_hints.set_min_size(min_dimensions);
normal_hints.set_max_size(max_dimensions);
normal_hints.set_resize_increments(pl_attribs.resize_increments);
normal_hints.set_base_size(pl_attribs.base_size);
xconn.set_normal_hints(window.xwindow, normal_hints).queue();
Expand Down Expand Up @@ -452,8 +457,8 @@ impl UnownedWindow {
Some(RootMonitorId { inner: PlatformMonitorId::X(monitor) }) => {
let window_position = self.get_position_physical();
self.shared_state.lock().restore_position = window_position;
let monitor_origin = monitor.get_position();
self.set_position_inner(monitor_origin.0 as i32, monitor_origin.1 as i32).queue();
let monitor_origin: (i32, i32) = monitor.get_position().into();
self.set_position_inner(monitor_origin.0, monitor_origin.1).queue();
self.set_fullscreen_hint(true)
}
_ => unreachable!(),
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use winapi::um::winuser;
use std::{mem, ptr};
use std::collections::VecDeque;

use super::{EventsLoop, util};
use {PhysicalPosition, PhysicalSize};
use super::{EventsLoop, util};
use platform::platform::dpi::{dpi_to_scale_factor, get_monitor_dpi};

/// Win32 implementation of the main `MonitorId` object.
Expand Down
1 change: 0 additions & 1 deletion src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use {
PhysicalSize,
WindowAttributes,
};

use platform::platform::{Cursor, EventsLoop, PlatformSpecificWindowBuilderAttributes, WindowId};
use platform::platform::dpi::{BASE_DPI, dpi_to_scale_factor, get_window_dpi, get_window_scale_factor};
use platform::platform::events_loop::{self, DESTROY_MSG_ID, INITIAL_DPI_MSG_ID};
Expand Down

0 comments on commit 2dbe28e

Please sign in to comment.