diff options
author | Victor Berger <vberger@users.noreply.github.com> | 2015-12-22 15:43:23 +0100 |
---|---|---|
committer | Victor Berger <vberger@users.noreply.github.com> | 2015-12-22 15:43:23 +0100 |
commit | f76aba3d3778978bef0087f830ebf69954110233 (patch) | |
tree | 8a8990feee469c9df332d2029e6022aa7bc448a8 /src/api/wayland/monitor.rs | |
parent | ae7638b995e850a465a8642586f5819cb0b56975 (diff) | |
parent | 83e2924ac2c438c41e35b60174844d26ae51da82 (diff) | |
download | glutin-f76aba3d3778978bef0087f830ebf69954110233.tar.gz glutin-f76aba3d3778978bef0087f830ebf69954110233.zip |
Merge pull request #674 from vberger/master
Wayland backend rewrite and activation.
Diffstat (limited to 'src/api/wayland/monitor.rs')
-rw-r--r-- | src/api/wayland/monitor.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/api/wayland/monitor.rs b/src/api/wayland/monitor.rs new file mode 100644 index 0000000..d87d4b6 --- /dev/null +++ b/src/api/wayland/monitor.rs @@ -0,0 +1,75 @@ +use std::collections::VecDeque; + +use wayland_client::{ProxyId, EventIterator}; +use wayland_client::wayland::output::WlOutput; + +use super::context::WAYLAND_CONTEXT; + +#[derive(Clone)] +pub struct MonitorId(ProxyId); + +#[inline] +pub fn get_available_monitors() -> VecDeque<MonitorId> { + WAYLAND_CONTEXT.as_ref().map(|ctxt| + ctxt.monitor_ids().into_iter().map(MonitorId).collect() + ).unwrap_or(VecDeque::new()) +} +#[inline] +pub fn get_primary_monitor() -> MonitorId { + WAYLAND_CONTEXT.as_ref().and_then(|ctxt| + ctxt.monitor_ids().into_iter().next().map(MonitorId) + ).expect("wayland: No monitor available.") +} + +impl MonitorId { + pub fn get_name(&self) -> Option<String> { + WAYLAND_CONTEXT.as_ref().and_then(|ctxt| ctxt.monitor_name(self.0)) + } + + #[inline] + pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId { + ::native_monitor::NativeMonitorId::Unavailable + } + + pub fn get_dimensions(&self) -> (u32, u32) { + WAYLAND_CONTEXT.as_ref().and_then(|ctxt| ctxt.monitor_dimensions(self.0)).unwrap() + } +} + +pub fn proxid_from_monitorid(x: &MonitorId) -> ProxyId { + x.0 +} + +pub fn init_monitors(outputs: &mut Vec<(WlOutput, u32, u32, String)>, evts: EventIterator) { + use wayland_client::{Event, Proxy}; + use wayland_client::wayland::WaylandProtocolEvent; + use wayland_client::wayland::output::{WlOutputEvent, WlOutputMode}; + + for evt in evts { + match evt { + Event::Wayland(WaylandProtocolEvent::WlOutput(pid, oevt)) => match oevt { + WlOutputEvent::Geometry(_, _, _, _, _, maker, model, _) => { + for o in outputs.iter_mut() { + if o.0.id() == pid { + o.3 = format!("{} - {}", maker, model); + break + } + } + }, + WlOutputEvent::Mode(flags, width, height, _) => { + if flags.contains(WlOutputMode::Current) { + for o in outputs.iter_mut() { + if o.0.id() == pid { + o.1 = width as u32; + o.2 = height as u32; + break + } + } + } + }, + _ => {} + }, + _ => {} + } + } +}
\ No newline at end of file |