From 42551d20fdab796548e42e8699ba7d905417d257 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Tue, 22 Dec 2015 14:35:15 +0100 Subject: api/wayland: output and fullscreen handling. --- src/api/wayland/monitor.rs | 59 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) (limited to 'src/api/wayland/monitor.rs') diff --git a/src/api/wayland/monitor.rs b/src/api/wayland/monitor.rs index 3a42f1f..d87d4b6 100644 --- a/src/api/wayland/monitor.rs +++ b/src/api/wayland/monitor.rs @@ -1,28 +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; +pub struct MonitorId(ProxyId); #[inline] pub fn get_available_monitors() -> VecDeque { - unimplemented!() + 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 { - unimplemented!() + 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 { - unimplemented!() + WAYLAND_CONTEXT.as_ref().and_then(|ctxt| ctxt.monitor_name(self.0)) } #[inline] pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId { - unimplemented!() + ::native_monitor::NativeMonitorId::Unavailable } pub fn get_dimensions(&self) -> (u32, u32) { - unimplemented!() + 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 -- cgit v1.2.3