2018-06-17 00:14:12 +10:00
|
|
|
use std::collections::VecDeque;
|
2017-10-20 18:46:42 +11:00
|
|
|
use std::sync::{Arc, Mutex, Weak};
|
2015-12-13 21:43:39 +11:00
|
|
|
|
2018-06-19 02:32:18 +10:00
|
|
|
use {CreationError, MouseCursor, WindowAttributes};
|
|
|
|
use dpi::{LogicalPosition, LogicalSize};
|
2016-10-08 23:51:29 +11:00
|
|
|
use platform::MonitorId as PlatformMonitorId;
|
2017-08-29 11:08:12 +10:00
|
|
|
use window::MonitorId as RootMonitorId;
|
2015-12-09 08:54:06 +11:00
|
|
|
|
2018-10-15 10:15:43 +11:00
|
|
|
use sctk::window::{ConceptFrame, Event as WEvent, Window as SWindow};
|
2018-05-06 03:36:34 +10:00
|
|
|
use sctk::reexports::client::{Display, Proxy};
|
2018-06-15 09:42:18 +10:00
|
|
|
use sctk::reexports::client::protocol::{wl_seat, wl_surface, wl_output};
|
2018-05-06 03:36:34 +10:00
|
|
|
use sctk::reexports::client::protocol::wl_compositor::RequestsTrait as CompositorRequests;
|
|
|
|
use sctk::reexports::client::protocol::wl_surface::RequestsTrait as SurfaceRequests;
|
2018-06-17 00:14:12 +10:00
|
|
|
use sctk::output::OutputMgr;
|
2018-05-06 03:36:34 +10:00
|
|
|
|
|
|
|
use super::{make_wid, EventsLoop, MonitorId, WindowId};
|
2018-06-17 00:14:12 +10:00
|
|
|
use platform::platform::wayland::event_loop::{get_available_monitors, get_primary_monitor};
|
2015-12-09 08:54:06 +11:00
|
|
|
|
|
|
|
pub struct Window {
|
2018-05-06 03:36:34 +10:00
|
|
|
surface: Proxy<wl_surface::WlSurface>,
|
2018-10-15 10:15:43 +11:00
|
|
|
frame: Arc<Mutex<SWindow<ConceptFrame>>>,
|
2018-06-17 00:14:12 +10:00
|
|
|
monitors: Arc<Mutex<MonitorList>>, // Monitors this window is currently on
|
|
|
|
outputs: OutputMgr, // Access to info for all monitors
|
2017-10-20 18:46:42 +11:00
|
|
|
size: Arc<Mutex<(u32, u32)>>,
|
|
|
|
kill_switch: (Arc<Mutex<bool>>, Arc<Mutex<bool>>),
|
2018-05-06 03:36:34 +10:00
|
|
|
display: Arc<Display>,
|
|
|
|
need_frame_refresh: Arc<Mutex<bool>>,
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Window {
|
2018-05-08 07:36:21 +10:00
|
|
|
pub fn new(evlp: &EventsLoop, attributes: WindowAttributes) -> Result<Window, CreationError> {
|
2018-06-24 22:28:57 +10:00
|
|
|
let (width, height) = attributes.dimensions.map(Into::into).unwrap_or((800, 600));
|
2018-05-06 03:36:34 +10:00
|
|
|
// Create the window
|
2017-10-20 18:46:42 +11:00
|
|
|
let size = Arc::new(Mutex::new((width, height)));
|
2018-05-06 03:36:34 +10:00
|
|
|
|
|
|
|
// monitor tracking
|
2018-06-15 09:42:18 +10:00
|
|
|
let monitor_list = Arc::new(Mutex::new(MonitorList::new()));
|
2018-05-06 03:36:34 +10:00
|
|
|
|
2018-10-15 10:15:43 +11:00
|
|
|
let surface = evlp.env.compositor.create_surface(|surface| {
|
2018-05-06 03:36:34 +10:00
|
|
|
let list = monitor_list.clone();
|
|
|
|
let omgr = evlp.env.outputs.clone();
|
2018-06-15 09:42:18 +10:00
|
|
|
let window_store = evlp.store.clone();
|
2018-10-15 10:15:43 +11:00
|
|
|
surface.implement(move |event, surface| match event {
|
2018-06-15 09:42:18 +10:00
|
|
|
wl_surface::Event::Enter { output } => {
|
|
|
|
let dpi_change = list.lock().unwrap().add_output(MonitorId {
|
|
|
|
proxy: output,
|
|
|
|
mgr: omgr.clone(),
|
|
|
|
});
|
|
|
|
if let Some(dpi) = dpi_change {
|
|
|
|
if surface.version() >= 3 {
|
|
|
|
// without version 3 we can't be dpi aware
|
|
|
|
window_store.lock().unwrap().dpi_change(&surface, dpi);
|
|
|
|
surface.set_buffer_scale(dpi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-05-06 03:36:34 +10:00
|
|
|
wl_surface::Event::Leave { output } => {
|
2018-06-15 09:42:18 +10:00
|
|
|
let dpi_change = list.lock().unwrap().del_output(&output);
|
|
|
|
if let Some(dpi) = dpi_change {
|
|
|
|
if surface.version() >= 3 {
|
|
|
|
// without version 3 we can't be dpi aware
|
|
|
|
window_store.lock().unwrap().dpi_change(&surface, dpi);
|
|
|
|
surface.set_buffer_scale(dpi);
|
|
|
|
}
|
|
|
|
}
|
2018-05-06 03:36:34 +10:00
|
|
|
}
|
2018-10-15 10:15:43 +11:00
|
|
|
}, ())
|
|
|
|
}).unwrap();
|
2018-05-06 03:36:34 +10:00
|
|
|
|
|
|
|
let window_store = evlp.store.clone();
|
|
|
|
let my_surface = surface.clone();
|
2018-10-15 10:15:43 +11:00
|
|
|
let mut frame = SWindow::<ConceptFrame>::init_from_env(
|
2018-09-21 03:48:36 +10:00
|
|
|
&evlp.env,
|
2018-05-06 03:36:34 +10:00
|
|
|
surface.clone(),
|
|
|
|
(width, height),
|
2018-10-15 10:15:43 +11:00
|
|
|
move |event| match event {
|
2018-05-06 03:36:34 +10:00
|
|
|
WEvent::Configure { new_size, .. } => {
|
|
|
|
let mut store = window_store.lock().unwrap();
|
|
|
|
for window in &mut store.windows {
|
|
|
|
if window.surface.equals(&my_surface) {
|
2018-06-15 09:42:18 +10:00
|
|
|
window.newsize = new_size;
|
2018-05-06 03:36:34 +10:00
|
|
|
window.need_refresh = true;
|
|
|
|
*(window.need_frame_refresh.lock().unwrap()) = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WEvent::Refresh => {
|
|
|
|
let store = window_store.lock().unwrap();
|
|
|
|
for window in &store.windows {
|
|
|
|
if window.surface.equals(&my_surface) {
|
|
|
|
*(window.need_frame_refresh.lock().unwrap()) = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WEvent::Close => {
|
|
|
|
let mut store = window_store.lock().unwrap();
|
|
|
|
for window in &mut store.windows {
|
|
|
|
if window.surface.equals(&my_surface) {
|
|
|
|
window.closed = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
for &(_, ref seat) in evlp.seats.lock().unwrap().iter() {
|
|
|
|
frame.new_seat(seat);
|
|
|
|
}
|
|
|
|
|
2017-10-20 18:46:42 +11:00
|
|
|
// Check for fullscreen requirements
|
2018-05-06 03:36:34 +10:00
|
|
|
if let Some(RootMonitorId {
|
|
|
|
inner: PlatformMonitorId::Wayland(ref monitor_id),
|
|
|
|
}) = attributes.fullscreen
|
|
|
|
{
|
|
|
|
frame.set_fullscreen(Some(&monitor_id.proxy));
|
2017-11-04 03:35:29 +11:00
|
|
|
} else if attributes.maximized {
|
2018-05-06 03:36:34 +10:00
|
|
|
frame.set_maximized();
|
2017-09-28 00:31:46 +10:00
|
|
|
}
|
2017-11-04 03:35:29 +11:00
|
|
|
|
2018-06-14 01:18:44 +10:00
|
|
|
frame.set_resizable(attributes.resizable);
|
|
|
|
|
2017-11-04 03:35:29 +11:00
|
|
|
// set decorations
|
|
|
|
frame.set_decorate(attributes.decorations);
|
|
|
|
|
|
|
|
// min-max dimensions
|
2018-06-24 22:28:57 +10:00
|
|
|
frame.set_min_size(attributes.min_dimensions.map(Into::into));
|
|
|
|
frame.set_max_size(attributes.max_dimensions.map(Into::into));
|
2016-10-08 23:51:29 +11:00
|
|
|
|
2017-10-20 18:46:42 +11:00
|
|
|
let kill_switch = Arc::new(Mutex::new(false));
|
2018-01-13 16:38:12 +11:00
|
|
|
let need_frame_refresh = Arc::new(Mutex::new(true));
|
2017-11-04 03:35:29 +11:00
|
|
|
let frame = Arc::new(Mutex::new(frame));
|
2017-10-20 18:46:42 +11:00
|
|
|
|
2018-05-06 03:36:34 +10:00
|
|
|
evlp.store.lock().unwrap().windows.push(InternalWindow {
|
|
|
|
closed: false,
|
|
|
|
newsize: None,
|
2018-06-15 09:42:18 +10:00
|
|
|
size: size.clone(),
|
2018-05-06 03:36:34 +10:00
|
|
|
need_refresh: false,
|
|
|
|
need_frame_refresh: need_frame_refresh.clone(),
|
|
|
|
surface: surface.clone(),
|
|
|
|
kill_switch: kill_switch.clone(),
|
|
|
|
frame: Arc::downgrade(&frame),
|
2018-06-15 09:42:18 +10:00
|
|
|
current_dpi: 1,
|
|
|
|
new_dpi: None,
|
2018-05-06 03:36:34 +10:00
|
|
|
});
|
|
|
|
evlp.evq.borrow_mut().sync_roundtrip().unwrap();
|
2016-10-08 23:51:29 +11:00
|
|
|
|
2017-10-20 18:46:42 +11:00
|
|
|
Ok(Window {
|
|
|
|
display: evlp.display.clone(),
|
|
|
|
surface: surface,
|
2017-11-04 03:35:29 +11:00
|
|
|
frame: frame,
|
2017-10-20 18:46:42 +11:00
|
|
|
monitors: monitor_list,
|
2018-06-17 00:14:12 +10:00
|
|
|
outputs: evlp.env.outputs.clone(),
|
2017-10-20 18:46:42 +11:00
|
|
|
size: size,
|
2018-01-13 16:38:12 +11:00
|
|
|
kill_switch: (kill_switch, evlp.cleanup_needed.clone()),
|
2018-05-06 03:36:34 +10:00
|
|
|
need_frame_refresh: need_frame_refresh,
|
2017-10-20 18:46:42 +11:00
|
|
|
})
|
2017-03-05 00:04:01 +11:00
|
|
|
}
|
2016-10-08 23:51:29 +11:00
|
|
|
|
2017-03-05 00:04:01 +11:00
|
|
|
#[inline]
|
|
|
|
pub fn id(&self) -> WindowId {
|
|
|
|
make_wid(&self.surface)
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_title(&self, title: &str) {
|
2017-11-04 03:35:29 +11:00
|
|
|
self.frame.lock().unwrap().set_title(title.into());
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn show(&self) {
|
2015-12-13 21:43:39 +11:00
|
|
|
// TODO
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn hide(&self) {
|
2015-12-13 21:43:39 +11:00
|
|
|
// TODO
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2018-06-15 09:42:18 +10:00
|
|
|
pub fn get_position(&self) -> Option<LogicalPosition> {
|
2015-12-13 21:43:39 +11:00
|
|
|
// Not possible with wayland
|
|
|
|
None
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
2018-04-17 11:40:30 +10:00
|
|
|
#[inline]
|
2018-06-15 09:42:18 +10:00
|
|
|
pub fn get_inner_position(&self) -> Option<LogicalPosition> {
|
2018-04-17 11:40:30 +10:00
|
|
|
// Not possible with wayland
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2015-12-09 08:54:06 +11:00
|
|
|
#[inline]
|
2018-06-15 09:42:18 +10:00
|
|
|
pub fn set_position(&self, _pos: LogicalPosition) {
|
2015-12-13 21:43:39 +11:00
|
|
|
// Not possible with wayland
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
2018-06-15 09:42:18 +10:00
|
|
|
pub fn get_inner_size(&self) -> Option<LogicalSize> {
|
|
|
|
Some(self.size.lock().unwrap().clone().into())
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2018-06-15 09:42:18 +10:00
|
|
|
pub fn get_outer_size(&self) -> Option<LogicalSize> {
|
2016-10-10 01:19:06 +11:00
|
|
|
let (w, h) = self.size.lock().unwrap().clone();
|
2018-05-06 03:36:34 +10:00
|
|
|
// let (w, h) = super::wayland_window::add_borders(w as i32, h as i32);
|
2018-06-15 09:42:18 +10:00
|
|
|
Some((w, h).into())
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2016-10-10 01:19:06 +11:00
|
|
|
// NOTE: This will only resize the borders, the contents must be updated by the user
|
2018-06-15 09:42:18 +10:00
|
|
|
pub fn set_inner_size(&self, size: LogicalSize) {
|
|
|
|
let (w, h) = size.into();
|
|
|
|
self.frame.lock().unwrap().resize(w, h);
|
|
|
|
*(self.size.lock().unwrap()) = (w, h);
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
2018-03-23 20:35:35 +11:00
|
|
|
#[inline]
|
2018-06-15 09:42:18 +10:00
|
|
|
pub fn set_min_dimensions(&self, dimensions: Option<LogicalSize>) {
|
|
|
|
self.frame.lock().unwrap().set_min_size(dimensions.map(Into::into));
|
2018-03-23 20:35:35 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2018-06-15 09:42:18 +10:00
|
|
|
pub fn set_max_dimensions(&self, dimensions: Option<LogicalSize>) {
|
|
|
|
self.frame.lock().unwrap().set_max_size(dimensions.map(Into::into));
|
2018-03-23 20:35:35 +11:00
|
|
|
}
|
|
|
|
|
2018-06-14 01:18:44 +10:00
|
|
|
#[inline]
|
|
|
|
pub fn set_resizable(&self, resizable: bool) {
|
|
|
|
self.frame.lock().unwrap().set_resizable(resizable);
|
|
|
|
}
|
|
|
|
|
2015-12-09 08:54:06 +11:00
|
|
|
#[inline]
|
2018-06-15 09:42:18 +10:00
|
|
|
pub fn hidpi_factor(&self) -> i32 {
|
|
|
|
self.monitors.lock().unwrap().compute_hidpi_factor()
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
2018-01-13 16:38:12 +11:00
|
|
|
pub fn set_decorations(&self, decorate: bool) {
|
|
|
|
self.frame.lock().unwrap().set_decorate(decorate);
|
|
|
|
*(self.need_frame_refresh.lock().unwrap()) = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_maximized(&self, maximized: bool) {
|
|
|
|
if maximized {
|
2018-05-06 03:36:34 +10:00
|
|
|
self.frame.lock().unwrap().set_maximized();
|
2018-01-13 16:38:12 +11:00
|
|
|
} else {
|
2018-05-06 03:36:34 +10:00
|
|
|
self.frame.lock().unwrap().unset_maximized();
|
2018-01-13 16:38:12 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
|
2018-05-06 03:36:34 +10:00
|
|
|
if let Some(RootMonitorId {
|
|
|
|
inner: PlatformMonitorId::Wayland(ref monitor_id),
|
|
|
|
}) = monitor
|
|
|
|
{
|
|
|
|
self.frame
|
|
|
|
.lock()
|
|
|
|
.unwrap()
|
|
|
|
.set_fullscreen(Some(&monitor_id.proxy));
|
2018-01-13 16:38:12 +11:00
|
|
|
} else {
|
2018-05-06 03:36:34 +10:00
|
|
|
self.frame.lock().unwrap().unset_fullscreen();
|
2018-01-13 16:38:12 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-09 08:54:06 +11:00
|
|
|
#[inline]
|
2018-06-20 00:30:15 +10:00
|
|
|
pub fn set_cursor(&self, _cursor: MouseCursor) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn hide_cursor(&self, _hide: bool) {
|
|
|
|
// TODO: This isn't possible on Wayland yet
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn grab_cursor(&self, _grab: bool) -> Result<(), String> {
|
|
|
|
Err("Cursor grabbing is not yet possible on Wayland.".to_owned())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn set_cursor_position(&self, _pos: LogicalPosition) -> Result<(), String> {
|
|
|
|
Err("Setting the cursor position is not yet possible on Wayland.".to_owned())
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
2018-03-23 20:35:35 +11:00
|
|
|
|
2018-05-06 03:36:34 +10:00
|
|
|
pub fn get_display(&self) -> &Display {
|
2017-10-20 18:46:42 +11:00
|
|
|
&*self.display
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
2018-03-23 20:35:35 +11:00
|
|
|
|
2018-05-06 03:36:34 +10:00
|
|
|
pub fn get_surface(&self) -> &Proxy<wl_surface::WlSurface> {
|
2016-10-08 23:51:29 +11:00
|
|
|
&self.surface
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
2017-09-07 18:33:46 +10:00
|
|
|
|
2017-10-20 18:46:42 +11:00
|
|
|
pub fn get_current_monitor(&self) -> MonitorId {
|
|
|
|
// we don't know how much each monitor sees us so...
|
|
|
|
// just return the most recent one ?
|
|
|
|
let guard = self.monitors.lock().unwrap();
|
2018-06-15 09:42:18 +10:00
|
|
|
guard.monitors.last().unwrap().clone()
|
2017-09-07 18:33:46 +10:00
|
|
|
}
|
2018-06-17 00:14:12 +10:00
|
|
|
|
|
|
|
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
|
|
|
|
get_available_monitors(&self.outputs)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_primary_monitor(&self) -> MonitorId {
|
|
|
|
get_primary_monitor(&self.outputs)
|
|
|
|
}
|
2015-12-09 08:54:06 +11:00
|
|
|
}
|
|
|
|
|
2015-12-13 21:43:39 +11:00
|
|
|
impl Drop for Window {
|
|
|
|
fn drop(&mut self) {
|
2017-10-20 18:46:42 +11:00
|
|
|
*(self.kill_switch.0.lock().unwrap()) = true;
|
|
|
|
*(self.kill_switch.1.lock().unwrap()) = true;
|
2016-10-08 23:51:29 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-20 18:46:42 +11:00
|
|
|
/*
|
|
|
|
* Internal store for windows
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct InternalWindow {
|
2018-05-06 03:36:34 +10:00
|
|
|
surface: Proxy<wl_surface::WlSurface>,
|
2018-06-15 09:42:18 +10:00
|
|
|
newsize: Option<(u32, u32)>,
|
|
|
|
size: Arc<Mutex<(u32, u32)>>,
|
2017-10-20 18:46:42 +11:00
|
|
|
need_refresh: bool,
|
2018-01-13 16:38:12 +11:00
|
|
|
need_frame_refresh: Arc<Mutex<bool>>,
|
2017-07-06 00:23:10 +10:00
|
|
|
closed: bool,
|
2017-10-20 18:46:42 +11:00
|
|
|
kill_switch: Arc<Mutex<bool>>,
|
2018-10-15 10:15:43 +11:00
|
|
|
frame: Weak<Mutex<SWindow<ConceptFrame>>>,
|
2018-06-15 09:42:18 +10:00
|
|
|
current_dpi: i32,
|
|
|
|
new_dpi: Option<i32>
|
2016-10-08 23:51:29 +11:00
|
|
|
}
|
|
|
|
|
2017-10-20 18:46:42 +11:00
|
|
|
pub struct WindowStore {
|
2018-05-06 03:36:34 +10:00
|
|
|
windows: Vec<InternalWindow>,
|
2017-10-20 18:46:42 +11:00
|
|
|
}
|
2017-03-05 00:04:01 +11:00
|
|
|
|
2017-10-20 18:46:42 +11:00
|
|
|
impl WindowStore {
|
|
|
|
pub fn new() -> WindowStore {
|
2018-05-06 03:36:34 +10:00
|
|
|
WindowStore {
|
|
|
|
windows: Vec::new(),
|
|
|
|
}
|
2016-10-08 23:51:29 +11:00
|
|
|
}
|
2017-07-06 00:23:10 +10:00
|
|
|
|
2018-05-06 03:36:34 +10:00
|
|
|
pub fn find_wid(&self, surface: &Proxy<wl_surface::WlSurface>) -> Option<WindowId> {
|
2017-10-20 18:46:42 +11:00
|
|
|
for window in &self.windows {
|
|
|
|
if surface.equals(&window.surface) {
|
|
|
|
return Some(make_wid(surface));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None
|
2017-09-28 00:31:46 +10:00
|
|
|
}
|
|
|
|
|
2018-04-25 06:20:40 +10:00
|
|
|
pub fn cleanup(&mut self) -> Vec<WindowId> {
|
|
|
|
let mut pruned = Vec::new();
|
2017-10-20 18:46:42 +11:00
|
|
|
self.windows.retain(|w| {
|
|
|
|
if *w.kill_switch.lock().unwrap() {
|
|
|
|
// window is dead, cleanup
|
2018-04-25 06:20:40 +10:00
|
|
|
pruned.push(make_wid(&w.surface));
|
2017-10-20 18:46:42 +11:00
|
|
|
w.surface.destroy();
|
|
|
|
false
|
|
|
|
} else {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
});
|
2018-04-25 06:20:40 +10:00
|
|
|
pruned
|
2017-10-20 18:46:42 +11:00
|
|
|
}
|
2016-10-08 23:51:29 +11:00
|
|
|
|
2018-05-06 03:36:34 +10:00
|
|
|
pub fn new_seat(&self, seat: &Proxy<wl_seat::WlSeat>) {
|
|
|
|
for window in &self.windows {
|
|
|
|
if let Some(w) = window.frame.upgrade() {
|
|
|
|
w.lock().unwrap().new_seat(seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-15 09:42:18 +10:00
|
|
|
fn dpi_change(&mut self, surface: &Proxy<wl_surface::WlSurface>, new: i32) {
|
|
|
|
for window in &mut self.windows {
|
|
|
|
if surface.equals(&window.surface) {
|
|
|
|
window.new_dpi = Some(new);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-20 18:46:42 +11:00
|
|
|
pub fn for_each<F>(&mut self, mut f: F)
|
2018-05-06 03:36:34 +10:00
|
|
|
where
|
2018-10-15 10:15:43 +11:00
|
|
|
F: FnMut(Option<(u32, u32)>, &mut (u32, u32), Option<i32>, bool, bool, bool, WindowId, Option<&mut SWindow<ConceptFrame>>),
|
2016-10-08 23:51:29 +11:00
|
|
|
{
|
2017-10-20 18:46:42 +11:00
|
|
|
for window in &mut self.windows {
|
2017-11-04 03:35:29 +11:00
|
|
|
let opt_arc = window.frame.upgrade();
|
2017-10-20 18:46:42 +11:00
|
|
|
let mut opt_mutex_lock = opt_arc.as_ref().map(|m| m.lock().unwrap());
|
|
|
|
f(
|
|
|
|
window.newsize.take(),
|
2018-06-15 09:42:18 +10:00
|
|
|
&mut *(window.size.lock().unwrap()),
|
|
|
|
window.new_dpi,
|
2017-10-20 18:46:42 +11:00
|
|
|
window.need_refresh,
|
2018-01-13 16:38:12 +11:00
|
|
|
::std::mem::replace(&mut *window.need_frame_refresh.lock().unwrap(), false),
|
2017-10-20 18:46:42 +11:00
|
|
|
window.closed,
|
|
|
|
make_wid(&window.surface),
|
2018-05-06 03:36:34 +10:00
|
|
|
opt_mutex_lock.as_mut().map(|m| &mut **m),
|
2017-10-20 18:46:42 +11:00
|
|
|
);
|
2018-06-15 09:42:18 +10:00
|
|
|
if let Some(dpi) = window.new_dpi.take() {
|
|
|
|
window.current_dpi = dpi;
|
|
|
|
}
|
2017-10-20 18:46:42 +11:00
|
|
|
window.need_refresh = false;
|
|
|
|
// avoid re-spamming the event
|
|
|
|
window.closed = false;
|
|
|
|
}
|
2016-10-08 23:51:29 +11:00
|
|
|
}
|
2017-10-20 18:46:42 +11:00
|
|
|
}
|
2018-06-15 09:42:18 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Monitor list with some covenience method to compute DPI
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct MonitorList {
|
|
|
|
monitors: Vec<MonitorId>
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MonitorList {
|
|
|
|
fn new() -> MonitorList {
|
|
|
|
MonitorList {
|
|
|
|
monitors: Vec::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compute_hidpi_factor(&self) -> i32 {
|
|
|
|
let mut factor = 1;
|
|
|
|
for monitor_id in &self.monitors {
|
|
|
|
let monitor_dpi = monitor_id.get_hidpi_factor();
|
|
|
|
if monitor_dpi > factor { factor = monitor_dpi; }
|
|
|
|
}
|
|
|
|
factor
|
|
|
|
}
|
|
|
|
|
|
|
|
fn add_output(&mut self, monitor: MonitorId) -> Option<i32> {
|
|
|
|
let old_dpi = self.compute_hidpi_factor();
|
|
|
|
let monitor_dpi = monitor.get_hidpi_factor();
|
|
|
|
self.monitors.push(monitor);
|
|
|
|
if monitor_dpi > old_dpi {
|
|
|
|
Some(monitor_dpi)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn del_output(&mut self, output: &Proxy<wl_output::WlOutput>) -> Option<i32> {
|
|
|
|
let old_dpi = self.compute_hidpi_factor();
|
|
|
|
self.monitors.retain(|m| !m.proxy.equals(output));
|
|
|
|
let new_dpi = self.compute_hidpi_factor();
|
|
|
|
if new_dpi != old_dpi {
|
|
|
|
Some(new_dpi)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|