From fad2e77a36e79594de5e13072e6273f671154b9e Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 4 Dec 2015 20:39:52 +0100 Subject: api/wayland: Reset to empty API. In order to build the whole new structure. --- src/api/wayland/mod.rs | 319 ++++--------------------------------------------- 1 file changed, 26 insertions(+), 293 deletions(-) (limited to 'src/api/wayland/mod.rs') diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index ab71ffa..86bd749 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -1,17 +1,6 @@ #![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] -#![allow(unused_variables, dead_code)] -use self::wayland::egl::{EGLSurface, is_egl_available}; -use self::wayland::core::Surface; -use self::wayland::core::output::Output; -use self::wayland::core::shell::{ShellSurface, ShellFullscreenMethod}; - -use self::wayland_window::{DecoratedSurface, SurfaceGuard, substract_borders}; - -use libc; -use api::dlopen; -use api::egl; -use api::egl::Context as EglContext; +use std::collections::VecDeque; use ContextError; use CreationError; @@ -24,187 +13,56 @@ use GlContext; use PixelFormatRequirements; use WindowAttributes; -use std::collections::VecDeque; -use std::ops::{Deref, DerefMut}; -use std::sync::{Arc, Mutex}; -use std::ffi::CString; - +use api::egl::Context as EglContext; +use libc; use platform::MonitorId as PlatformMonitorId; -use self::context::WaylandContext; - -extern crate wayland_client as wayland; extern crate wayland_kbd; extern crate wayland_window; -mod context; -mod keyboard; - -lazy_static! { - static ref WAYLAND_CONTEXT: Option = { - WaylandContext::new() - }; -} - #[inline] pub fn is_available() -> bool { - WAYLAND_CONTEXT.is_some() -} - -enum ShellWindow { - Plain(ShellSurface), - Decorated(DecoratedSurface) -} - -impl ShellWindow { - #[inline] - fn get_shell(&mut self) -> ShellGuard { - match self { - &mut ShellWindow::Plain(ref mut s) => { - ShellGuard::Plain(s) - }, - &mut ShellWindow::Decorated(ref mut s) => { - ShellGuard::Decorated(s.get_shell()) - } - } - } - - fn resize(&mut self, w: i32, h: i32, x: i32, y: i32) { - match self { - &mut ShellWindow::Plain(ref s) => s.resize(w, h, x, y), - &mut ShellWindow::Decorated(ref mut s) => { - s.resize(w, h); - s.get_shell().resize(w, h, x, y); - } - } - } - - fn set_cfg_callback(&mut self, arc: Arc>) { - match self { - &mut ShellWindow::Decorated(ref mut s) => { - s.get_shell().set_configure_callback(move |_, w, h| { - let (w, h) = substract_borders(w, h); - let mut guard = arc.lock().unwrap(); - *guard = (w, h, true); - }) - } - _ => {} - } - } -} - -enum ShellGuard<'a> { - Plain(&'a mut ShellSurface), - Decorated(SurfaceGuard<'a, EGLSurface>) -} - -impl<'a> Deref for ShellGuard<'a> { - type Target = ShellSurface; - - #[inline] - fn deref(&self) -> &ShellSurface { - match self { - &ShellGuard::Plain(ref s) => s, - &ShellGuard::Decorated(ref s) => s.deref() - } - } -} - -impl<'a> DerefMut for ShellGuard<'a> { - #[inline] - fn deref_mut(&mut self) -> &mut ShellSurface { - match self { - &mut ShellGuard::Plain(ref mut s) => s, - &mut ShellGuard::Decorated(ref mut s) => s.deref_mut() - } - } + false } pub struct Window { - shell_window: Mutex, - pending_events: Arc>>, - need_resize: Arc>, - resize_callback: Option, pub context: EglContext, } -// private methods of wayalnd windows - -impl Window { - fn resize_if_needed(&self) -> bool { - let mut guard = self.need_resize.lock().unwrap(); - let (w, h, b) = *guard; - *guard = (0, 0, false); - if b { - let mut guard = self.shell_window.lock().unwrap(); - guard.resize(w, h, 0, 0); - if let Some(f) = self.resize_callback { - f(w as u32, h as u32); - } - if let Some(ref ctxt) = *WAYLAND_CONTEXT { - let mut window_guard = self.shell_window.lock().unwrap(); - ctxt.push_event_for( - window_guard.get_shell().get_wsurface().get_id(), - Event::Resized(w as u32, h as u32) - ); - } - } - b - } -} - #[derive(Clone)] pub struct WindowProxy; impl WindowProxy { #[inline] pub fn wakeup_event_loop(&self) { - if let Some(ref ctxt) = *WAYLAND_CONTEXT { - ctxt.display.sync(); - } + unimplemented!() } } #[derive(Clone)] -pub struct MonitorId { - output: Arc -} +pub struct MonitorId; #[inline] pub fn get_available_monitors() -> VecDeque { - WAYLAND_CONTEXT.as_ref().unwrap().outputs.iter().map(|o| MonitorId::new(o.clone())).collect() + unimplemented!() } #[inline] pub fn get_primary_monitor() -> MonitorId { - match WAYLAND_CONTEXT.as_ref().unwrap().outputs.iter().next() { - Some(o) => MonitorId::new(o.clone()), - None => panic!("No monitor is available.") - } + unimplemented!() } impl MonitorId { - fn new(output: Arc) -> MonitorId { - MonitorId { - output: output - } - } - pub fn get_name(&self) -> Option { - Some(format!("{} - {}", self.output.manufacturer(), self.output.model())) + unimplemented!() } #[inline] pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId { - ::native_monitor::NativeMonitorId::Unavailable + unimplemented!() } pub fn get_dimensions(&self) -> (u32, u32) { - let (w, h) = self.output.modes() - .into_iter() - .find(|m| m.is_current()) - .map(|m| (m.width, m.height)) - .unwrap(); - (w as u32, h as u32) + unimplemented!() } } @@ -217,14 +75,7 @@ impl<'a> Iterator for PollEventsIterator<'a> { type Item = Event; fn next(&mut self) -> Option { - if let Some(ref ctxt) = *WAYLAND_CONTEXT { - ctxt.display.dispatch_pending(); - } - if self.window.resize_if_needed() { - Some(Event::Refresh) - } else { - self.window.pending_events.lock().unwrap().pop_front() - } + unimplemented!() } } @@ -236,18 +87,7 @@ impl<'a> Iterator for WaitEventsIterator<'a> { type Item = Event; fn next(&mut self) -> Option { - let mut evt = None; - while evt.is_none() { - if let Some(ref ctxt) = *WAYLAND_CONTEXT { - ctxt.display.dispatch(); - } - evt = if self.window.resize_if_needed() { - Some(Event::Refresh) - } else { - self.window.pending_events.lock().unwrap().pop_front() - }; - } - evt + unimplemented!() } } @@ -255,140 +95,49 @@ impl Window { pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements, opengl: &GlAttributes<&Window>) -> Result { - use self::wayland::internals::FFI; - // not implemented assert!(window.min_dimensions.is_none()); assert!(window.max_dimensions.is_none()); - let wayland_context = match *WAYLAND_CONTEXT { - Some(ref c) => c, - None => return Err(CreationError::NotSupported), - }; - - if !is_egl_available() { return Err(CreationError::NotSupported) } - - let (w, h) = window.dimensions.unwrap_or((800, 600)); - - let surface = EGLSurface::new( - wayland_context.compositor.create_surface(), - w as i32, - h as i32 - ); - - let mut shell_window = if let Some(PlatformMonitorId::Wayland(ref monitor)) = window.monitor { - let shell_surface = wayland_context.shell.get_shell_surface(surface); - shell_surface.set_fullscreen(ShellFullscreenMethod::Default, Some(&monitor.output)); - ShellWindow::Plain(shell_surface) - } else { - if window.decorations { - ShellWindow::Decorated(match DecoratedSurface::new( - surface, - w as i32, - h as i32, - &wayland_context.registry, - Some(&wayland_context.seat) - ) { - Ok(s) => s, - Err(_) => return Err(CreationError::NotSupported) - }) - } else { - ShellWindow::Plain(wayland_context.shell.get_shell_surface(surface)) - } - }; - - let context = { - let libegl = unsafe { dlopen::dlopen(b"libEGL.so\0".as_ptr() as *const _, dlopen::RTLD_NOW) }; - if libegl.is_null() { - return Err(CreationError::NotSupported); - } - let egl = ::api::egl::ffi::egl::Egl::load_with(|sym| { - let sym = CString::new(sym).unwrap(); - unsafe { dlopen::dlsym(libegl, sym.as_ptr()) } - }); - try!(EglContext::new( - egl, - pf_reqs, &opengl.clone().map_sharing(|_| unimplemented!()), // TODO: - egl::NativeDisplay::Wayland(Some(wayland_context.display.ptr() as *const _))) - .and_then(|p| p.finish((**shell_window.get_shell()).ptr() as *const _)) - ) - }; - - // create a queue already containing a refresh event to trigger first draw - // it's harmless and a removes the need to do a first swap_buffers() before - // starting the event loop - let events = Arc::new(Mutex::new({ - let mut v = VecDeque::new(); - v.push_back(Event::Refresh); - v - })); - - wayland_context.register_surface(shell_window.get_shell().get_wsurface().get_id(), - events.clone()); - - let need_resize = Arc::new(Mutex::new((0, 0, false))); - - shell_window.set_cfg_callback(need_resize.clone()); - - wayland_context.display.flush().unwrap(); - - Ok(Window { - shell_window: Mutex::new(shell_window), - pending_events: events, - need_resize: need_resize, - resize_callback: None, - context: context - }) + unimplemented!() } pub fn set_title(&self, title: &str) { - let ctitle = CString::new(title).unwrap(); - // intermediate variable is forced, - // see https://github.com/rust-lang/rust/issues/22921 - let mut guard = self.shell_window.lock().unwrap(); - guard.get_shell().set_title(&ctitle); + unimplemented!() } #[inline] pub fn show(&self) { - // TODO + unimplemented!() } #[inline] pub fn hide(&self) { - // TODO + unimplemented!() } #[inline] pub fn get_position(&self) -> Option<(i32, i32)> { - // not available with wayland - None + unimplemented!() } #[inline] pub fn set_position(&self, _x: i32, _y: i32) { - // not available with wayland + unimplemented!() } pub fn get_inner_size(&self) -> Option<(u32, u32)> { - // intermediate variables are forced, - // see https://github.com/rust-lang/rust/issues/22921 - let mut guard = self.shell_window.lock().unwrap(); - let shell = guard.get_shell(); - let (w, h) = shell.get_attached_size(); - Some((w as u32, h as u32)) + unimplemented!() } #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { - // maybe available if we draw the border ourselves ? - // but for now, no. - None + unimplemented!() } #[inline] pub fn set_inner_size(&self, x: u32, y: u32) { - self.shell_window.lock().unwrap().resize(x as i32, y as i32, 0, 0) + unimplemented!() } #[inline] @@ -412,18 +161,17 @@ impl Window { #[inline] pub fn set_window_resize_callback(&mut self, callback: Option) { - self.resize_callback = callback; + unimplemented!() } #[inline] pub fn set_cursor(&self, cursor: MouseCursor) { - // TODO + unimplemented!() } #[inline] pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { - // TODO - Ok(()) + unimplemented!() } #[inline] @@ -433,8 +181,7 @@ impl Window { #[inline] pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { - // TODO - Ok(()) + unimplemented!() } #[inline] @@ -479,17 +226,3 @@ impl GlContext for Window { self.context.get_pixel_format().clone() } } - -impl Drop for Window { - fn drop(&mut self) { - if let Some(ref ctxt) = *WAYLAND_CONTEXT { - // intermediate variable is forced, - // see https://github.com/rust-lang/rust/issues/22921 - let mut guard = self.shell_window.lock().unwrap(); - let shell = guard.get_shell(); - ctxt.deregister_surface( - shell.get_wsurface().get_id() - ) - } - } -} -- cgit v1.2.3 From 1b25d705ce2110b097b98f37f5e7dd9dc3a9d82c Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Tue, 8 Dec 2015 22:54:06 +0100 Subject: api/wayland: move window and monitor to mods. --- src/api/wayland/mod.rs | 223 +-------------------------------------------- src/api/wayland/monitor.rs | 28 ++++++ src/api/wayland/window.rs | 180 ++++++++++++++++++++++++++++++++++++ 3 files changed, 213 insertions(+), 218 deletions(-) create mode 100644 src/api/wayland/monitor.rs create mode 100644 src/api/wayland/window.rs (limited to 'src/api/wayland/mod.rs') diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index 86bd749..246a9e4 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -1,228 +1,15 @@ #![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] -use std::collections::VecDeque; - -use ContextError; -use CreationError; -use Event; -use PixelFormat; -use CursorState; -use MouseCursor; -use GlAttributes; -use GlContext; -use PixelFormatRequirements; -use WindowAttributes; - -use api::egl::Context as EglContext; -use libc; -use platform::MonitorId as PlatformMonitorId; +pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor}; +pub use self::window::{PollEventsIterator, WaitEventsIterator, Window, WindowProxy}; extern crate wayland_kbd; extern crate wayland_window; +mod monitor; +mod window; + #[inline] pub fn is_available() -> bool { false } - -pub struct Window { - pub context: EglContext, -} - -#[derive(Clone)] -pub struct WindowProxy; - -impl WindowProxy { - #[inline] - pub fn wakeup_event_loop(&self) { - unimplemented!() - } -} - -#[derive(Clone)] -pub struct MonitorId; - -#[inline] -pub fn get_available_monitors() -> VecDeque { - unimplemented!() -} -#[inline] -pub fn get_primary_monitor() -> MonitorId { - unimplemented!() -} - -impl MonitorId { - pub fn get_name(&self) -> Option { - unimplemented!() - } - - #[inline] - pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId { - unimplemented!() - } - - pub fn get_dimensions(&self) -> (u32, u32) { - unimplemented!() - } -} - - -pub struct PollEventsIterator<'a> { - window: &'a Window, -} - -impl<'a> Iterator for PollEventsIterator<'a> { - type Item = Event; - - fn next(&mut self) -> Option { - unimplemented!() - } -} - -pub struct WaitEventsIterator<'a> { - window: &'a Window, -} - -impl<'a> Iterator for WaitEventsIterator<'a> { - type Item = Event; - - fn next(&mut self) -> Option { - unimplemented!() - } -} - -impl Window { - pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements, - opengl: &GlAttributes<&Window>) -> Result - { - // not implemented - assert!(window.min_dimensions.is_none()); - assert!(window.max_dimensions.is_none()); - - unimplemented!() - } - - pub fn set_title(&self, title: &str) { - unimplemented!() - } - - #[inline] - pub fn show(&self) { - unimplemented!() - } - - #[inline] - pub fn hide(&self) { - unimplemented!() - } - - #[inline] - pub fn get_position(&self) -> Option<(i32, i32)> { - unimplemented!() - } - - #[inline] - pub fn set_position(&self, _x: i32, _y: i32) { - unimplemented!() - } - - pub fn get_inner_size(&self) -> Option<(u32, u32)> { - unimplemented!() - } - - #[inline] - pub fn get_outer_size(&self) -> Option<(u32, u32)> { - unimplemented!() - } - - #[inline] - pub fn set_inner_size(&self, x: u32, y: u32) { - unimplemented!() - } - - #[inline] - pub fn create_window_proxy(&self) -> WindowProxy { - WindowProxy - } - - #[inline] - pub fn poll_events(&self) -> PollEventsIterator { - PollEventsIterator { - window: self - } - } - - #[inline] - pub fn wait_events(&self) -> WaitEventsIterator { - WaitEventsIterator { - window: self - } - } - - #[inline] - pub fn set_window_resize_callback(&mut self, callback: Option) { - unimplemented!() - } - - #[inline] - pub fn set_cursor(&self, cursor: MouseCursor) { - unimplemented!() - } - - #[inline] - pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { - unimplemented!() - } - - #[inline] - pub fn hidpi_factor(&self) -> f32 { - 1.0 - } - - #[inline] - pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { - unimplemented!() - } - - #[inline] - pub fn platform_display(&self) -> *mut libc::c_void { - unimplemented!() - } - - #[inline] - pub fn platform_window(&self) -> *mut libc::c_void { - unimplemented!() - } -} - -impl GlContext for Window { - #[inline] - unsafe fn make_current(&self) -> Result<(), ContextError> { - self.context.make_current() - } - - #[inline] - fn is_current(&self) -> bool { - self.context.is_current() - } - - #[inline] - fn get_proc_address(&self, addr: &str) -> *const () { - self.context.get_proc_address(addr) - } - - #[inline] - fn swap_buffers(&self) -> Result<(), ContextError> { - self.context.swap_buffers() - } - - #[inline] - fn get_api(&self) -> ::Api { - self.context.get_api() - } - - #[inline] - fn get_pixel_format(&self) -> PixelFormat { - self.context.get_pixel_format().clone() - } -} diff --git a/src/api/wayland/monitor.rs b/src/api/wayland/monitor.rs new file mode 100644 index 0000000..3a42f1f --- /dev/null +++ b/src/api/wayland/monitor.rs @@ -0,0 +1,28 @@ +use std::collections::VecDeque; + +#[derive(Clone)] +pub struct MonitorId; + +#[inline] +pub fn get_available_monitors() -> VecDeque { + unimplemented!() +} +#[inline] +pub fn get_primary_monitor() -> MonitorId { + unimplemented!() +} + +impl MonitorId { + pub fn get_name(&self) -> Option { + unimplemented!() + } + + #[inline] + pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId { + unimplemented!() + } + + pub fn get_dimensions(&self) -> (u32, u32) { + unimplemented!() + } +} \ No newline at end of file diff --git a/src/api/wayland/window.rs b/src/api/wayland/window.rs new file mode 100644 index 0000000..df50731 --- /dev/null +++ b/src/api/wayland/window.rs @@ -0,0 +1,180 @@ +use {ContextError, CreationError, CursorState, Event, GlAttributes, GlContext, + MouseCursor, PixelFormat, PixelFormatRequirements, WindowAttributes}; + +use api::egl::Context as EglContext; + +use libc; + +#[derive(Clone)] +pub struct WindowProxy; + +impl WindowProxy { + #[inline] + pub fn wakeup_event_loop(&self) { + unimplemented!() + } +} + +pub struct Window { + pub context: EglContext, +} + +pub struct PollEventsIterator<'a> { + window: &'a Window, +} + +impl<'a> Iterator for PollEventsIterator<'a> { + type Item = Event; + + fn next(&mut self) -> Option { + unimplemented!() + } +} + +pub struct WaitEventsIterator<'a> { + window: &'a Window, +} + +impl<'a> Iterator for WaitEventsIterator<'a> { + type Item = Event; + + fn next(&mut self) -> Option { + unimplemented!() + } +} + +impl Window { + pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements, + opengl: &GlAttributes<&Window>) -> Result + { + // not implemented + assert!(window.min_dimensions.is_none()); + assert!(window.max_dimensions.is_none()); + + unimplemented!() + } + + pub fn set_title(&self, title: &str) { + unimplemented!() + } + + #[inline] + pub fn show(&self) { + unimplemented!() + } + + #[inline] + pub fn hide(&self) { + unimplemented!() + } + + #[inline] + pub fn get_position(&self) -> Option<(i32, i32)> { + unimplemented!() + } + + #[inline] + pub fn set_position(&self, _x: i32, _y: i32) { + unimplemented!() + } + + pub fn get_inner_size(&self) -> Option<(u32, u32)> { + unimplemented!() + } + + #[inline] + pub fn get_outer_size(&self) -> Option<(u32, u32)> { + unimplemented!() + } + + #[inline] + pub fn set_inner_size(&self, x: u32, y: u32) { + unimplemented!() + } + + #[inline] + pub fn create_window_proxy(&self) -> WindowProxy { + WindowProxy + } + + #[inline] + pub fn poll_events(&self) -> PollEventsIterator { + PollEventsIterator { + window: self + } + } + + #[inline] + pub fn wait_events(&self) -> WaitEventsIterator { + WaitEventsIterator { + window: self + } + } + + #[inline] + pub fn set_window_resize_callback(&mut self, callback: Option) { + unimplemented!() + } + + #[inline] + pub fn set_cursor(&self, cursor: MouseCursor) { + unimplemented!() + } + + #[inline] + pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { + unimplemented!() + } + + #[inline] + pub fn hidpi_factor(&self) -> f32 { + 1.0 + } + + #[inline] + pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { + unimplemented!() + } + + #[inline] + pub fn platform_display(&self) -> *mut libc::c_void { + unimplemented!() + } + + #[inline] + pub fn platform_window(&self) -> *mut libc::c_void { + unimplemented!() + } +} + +impl GlContext for Window { + #[inline] + unsafe fn make_current(&self) -> Result<(), ContextError> { + self.context.make_current() + } + + #[inline] + fn is_current(&self) -> bool { + self.context.is_current() + } + + #[inline] + fn get_proc_address(&self, addr: &str) -> *const () { + self.context.get_proc_address(addr) + } + + #[inline] + fn swap_buffers(&self) -> Result<(), ContextError> { + self.context.swap_buffers() + } + + #[inline] + fn get_api(&self) -> ::Api { + self.context.get_api() + } + + #[inline] + fn get_pixel_format(&self) -> PixelFormat { + self.context.get_pixel_format().clone() + } +} -- cgit v1.2.3 From 741311b619c9738b3adb15213c442e47834a1c98 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Tue, 8 Dec 2015 23:30:17 +0100 Subject: api/wayland: core context --- src/api/wayland/context.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ src/api/wayland/mod.rs | 3 ++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/api/wayland/context.rs (limited to 'src/api/wayland/mod.rs') diff --git a/src/api/wayland/context.rs b/src/api/wayland/context.rs new file mode 100644 index 0000000..4fc743b --- /dev/null +++ b/src/api/wayland/context.rs @@ -0,0 +1,42 @@ +use wayland_client::EventIterator; +use wayland_client::wayland::get_display; +use wayland_client::wayland::compositor::WlCompositor; +use wayland_client::wayland::seat::WlSeat; +use wayland_client::wayland::shell::WlShell; +use wayland_client::wayland::shm::WlShm; +use wayland_client::wayland::subcompositor::WlSubcompositor; + +lazy_static! { + pub static ref WAYLAND_CONTEXT: Option = { + WaylandContext::init() + }; +} + +wayland_env!(InnerEnv, + compositor: WlCompositor, + seat: WlSeat, + shell: WlShell, + shm: WlShm, + subcompositor: WlSubcompositor +); + +pub struct WaylandContext { + inner: InnerEnv, + iterator: EventIterator +} + +impl WaylandContext { + fn init() -> Option { + let display = match get_display() { + Some(display) => display, + None => return None + }; + + let (inner_env, iterator) = InnerEnv::init(display); + + Some(WaylandContext { + inner: inner_env, + iterator: iterator + }) + } +} \ No newline at end of file diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index 246a9e4..f30389c 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -6,10 +6,11 @@ pub use self::window::{PollEventsIterator, WaitEventsIterator, Window, WindowPro extern crate wayland_kbd; extern crate wayland_window; +mod context; mod monitor; mod window; #[inline] pub fn is_available() -> bool { - false + context::WAYLAND_CONTEXT.is_some() } -- cgit v1.2.3 From 6294d3c7ddc303913c83fd74d14c7a801d496c9e Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sun, 13 Dec 2015 11:43:39 +0100 Subject: api/wayland: core windows and events structure. --- src/api/wayland/context.rs | 94 ++++++++++++++++++++++++++-- src/api/wayland/events.rs | 10 +++ src/api/wayland/mod.rs | 1 + src/api/wayland/window.rs | 153 +++++++++++++++++++++++++++++++++++++++------ 4 files changed, 234 insertions(+), 24 deletions(-) create mode 100644 src/api/wayland/events.rs (limited to 'src/api/wayland/mod.rs') diff --git a/src/api/wayland/context.rs b/src/api/wayland/context.rs index 4fc743b..8e1196d 100644 --- a/src/api/wayland/context.rs +++ b/src/api/wayland/context.rs @@ -1,11 +1,21 @@ -use wayland_client::EventIterator; +use Event as GlutinEvent; + +use std::collections::{HashMap, VecDeque}; +use std::sync::{Arc, Mutex}; + +use libc::c_void; + +use wayland_client::{EventIterator, Proxy, ProxyId}; use wayland_client::wayland::get_display; -use wayland_client::wayland::compositor::WlCompositor; +use wayland_client::wayland::compositor::{WlCompositor, WlSurface}; +use wayland_client::wayland::output::WlOutput; use wayland_client::wayland::seat::WlSeat; use wayland_client::wayland::shell::WlShell; use wayland_client::wayland::shm::WlShm; use wayland_client::wayland::subcompositor::WlSubcompositor; +use super::wayland_window::DecoratedSurface; + lazy_static! { pub static ref WAYLAND_CONTEXT: Option = { WaylandContext::init() @@ -22,7 +32,9 @@ wayland_env!(InnerEnv, pub struct WaylandContext { inner: InnerEnv, - iterator: EventIterator + iterator: Mutex, + monitors: Vec, + queues: Mutex>>>> } impl WaylandContext { @@ -32,11 +44,81 @@ impl WaylandContext { None => return None }; - let (inner_env, iterator) = InnerEnv::init(display); + let (mut inner_env, iterator) = InnerEnv::init(display); + + let monitors = inner_env.globals.iter() + .flat_map(|&(id, _, _)| inner_env.rebind_id::(id)) + .map(|(monitor, _)| monitor) + .collect(); + + inner_env.display.sync_roundtrip().unwrap(); Some(WaylandContext { inner: inner_env, - iterator: iterator + iterator: Mutex::new(iterator), + monitors: monitors, + queues: Mutex::new(HashMap::new()) }) } -} \ No newline at end of file + + pub fn new_surface(&self) -> Option<(WlSurface, Arc>>)> { + self.inner.compositor.as_ref().map(|c| { + let s = c.0.create_surface(); + let id = s.id(); + let queue = { + let mut q = VecDeque::new(); + q.push_back(GlutinEvent::Refresh); + Arc::new(Mutex::new(q)) + }; + self.queues.lock().unwrap().insert(id, queue.clone()); + (s, queue) + }) + } + + pub fn dropped_surface(&self, id: ProxyId) { + self.queues.lock().unwrap().remove(&id); + } + + pub fn decorated_from(&self, surface: &WlSurface, width: i32, height: i32) -> Option { + let inner = &self.inner; + match (&inner.compositor, &inner.subcompositor, &inner.shm, &inner.shell) { + (&Some(ref compositor), &Some(ref subcompositor), &Some(ref shm), &Some(ref shell)) => { + DecoratedSurface::new( + surface, width, height, + &compositor.0, &subcompositor.0, &shm.0, &shell.0, + self.inner.rebind::().map(|(seat, _)| seat) + ).ok() + } + _ => None + } + } + + pub fn display_ptr(&self) -> *const c_void { + self.inner.display.ptr() as *const _ + } + + pub fn dispatch_events(&self) { + self.inner.display.dispatch_pending().unwrap(); + let mut iterator = self.iterator.lock().unwrap(); + let queues = self.queues.lock().unwrap(); + for evt in &mut *iterator { + if let Some((evt, id)) = super::events::translate_event(evt) { + if let Some(q) = queues.get(&id) { + q.lock().unwrap().push_back(evt); + } + } + } + } + + pub fn flush_events(&self) -> ::std::io::Result { + self.inner.display.flush() + } + + pub fn read_events(&self) -> ::std::io::Result> { + let guard = match self.inner.display.prepare_read() { + Some(g) => g, + None => return Ok(None) + }; + return guard.read_events().map(|i| Some(i)); + } +} diff --git a/src/api/wayland/events.rs b/src/api/wayland/events.rs new file mode 100644 index 0000000..86f0575 --- /dev/null +++ b/src/api/wayland/events.rs @@ -0,0 +1,10 @@ +use Event as GlutinEvent; + +use wayland_client::Event as WaylandEvent; +use wayland_client::ProxyId; + +pub fn translate_event(evt: WaylandEvent) -> Option<(GlutinEvent, ProxyId)> { + match evt { + _ => None + } +} \ No newline at end of file diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index f30389c..f2e3b2f 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -7,6 +7,7 @@ extern crate wayland_kbd; extern crate wayland_window; mod context; +mod events; mod monitor; mod window; diff --git a/src/api/wayland/window.rs b/src/api/wayland/window.rs index df50731..7532443 100644 --- a/src/api/wayland/window.rs +++ b/src/api/wayland/window.rs @@ -1,9 +1,18 @@ +use std::collections::VecDeque; +use std::ffi::CString; +use std::sync::{Arc, Mutex}; + +use libc; + use {ContextError, CreationError, CursorState, Event, GlAttributes, GlContext, MouseCursor, PixelFormat, PixelFormatRequirements, WindowAttributes}; - +use api::dlopen; +use api::egl; use api::egl::Context as EglContext; -use libc; +use wayland_client::egl as wegl; +use super::wayland_window::{DecoratedSurface, add_borders, substract_borders}; +use super::context::{WaylandContext, WAYLAND_CONTEXT}; #[derive(Clone)] pub struct WindowProxy; @@ -16,9 +25,36 @@ impl WindowProxy { } pub struct Window { + wayland_context: &'static WaylandContext, + egl_surface: wegl::WlEglSurface, + decorated_surface: Mutex, + evt_queue: Arc>>, + inner_size: Mutex<(i32, i32)>, + resize_callback: Option, pub context: EglContext, } +impl Window { + fn next_event(&self) -> Option { + let mut newsize = None; + for (_, w, h) in &mut *self.decorated_surface.lock().unwrap() { + newsize = Some((w, h)); + } + if let Some((w, h)) = newsize { + let (w, h) = substract_borders(w, h); + *self.inner_size.lock().unwrap() = (w, h); + self.decorated_surface.lock().unwrap().resize(w, h); + self.egl_surface.resize(w, h, 0, 0); + if let Some(f) = self.resize_callback { + f(w as u32, h as u32); + } + Some(Event::Resized(w as u32, h as u32)) + } else { + self.evt_queue.lock().unwrap().pop_front() + } + } +} + pub struct PollEventsIterator<'a> { window: &'a Window, } @@ -27,7 +63,13 @@ impl<'a> Iterator for PollEventsIterator<'a> { type Item = Event; fn next(&mut self) -> Option { - unimplemented!() + match self.window.next_event() { + Some(evt) => return Some(evt), + None => {} + } + // the queue was empty, try a dispatch and see the result + self.window.wayland_context.dispatch_events(); + return self.window.next_event(); } } @@ -39,7 +81,21 @@ impl<'a> Iterator for WaitEventsIterator<'a> { type Item = Event; fn next(&mut self) -> Option { - unimplemented!() + loop { + match self.window.next_event() { + Some(evt) => return Some(evt), + None => {} + } + // the queue was empty, try a dispatch & read and see the result + self.window.wayland_context.flush_events().expect("Connexion with the wayland compositor lost."); + match self.window.wayland_context.read_events() { + Ok(_) => { + // events were read or dispatch is needed, in both cases, we dispatch + self.window.wayland_context.dispatch_events() + } + Err(_) => panic!("Connexion with the wayland compositor lost.") + } + } } } @@ -51,45 +107,97 @@ impl Window { assert!(window.min_dimensions.is_none()); assert!(window.max_dimensions.is_none()); - unimplemented!() + let wayland_context = match *WAYLAND_CONTEXT { + Some(ref c) => c, + None => return Err(CreationError::NotSupported), + }; + + if !wegl::is_available() { + return Err(CreationError::NotSupported) + } + + let (w, h) = window.dimensions.unwrap_or((800, 600)); + + let (surface, evt_queue) = match wayland_context.new_surface() { + Some(t) => t, + None => return Err(CreationError::NotSupported) + }; + + let egl_surface = wegl::WlEglSurface::new(surface, w as i32, h as i32); + + let context = { + let libegl = unsafe { dlopen::dlopen(b"libEGL.so\0".as_ptr() as *const _, dlopen::RTLD_NOW) }; + if libegl.is_null() { + return Err(CreationError::NotSupported); + } + let egl = ::api::egl::ffi::egl::Egl::load_with(|sym| { + let sym = CString::new(sym).unwrap(); + unsafe { dlopen::dlsym(libegl, sym.as_ptr()) } + }); + try!(EglContext::new( + egl, + pf_reqs, &opengl.clone().map_sharing(|_| unimplemented!()), // TODO: + egl::NativeDisplay::Wayland(Some(wayland_context.display_ptr() as *const _))) + .and_then(|p| p.finish(unsafe { egl_surface.egl_surfaceptr() } as *const _)) + ) + }; + + let decorated_surface = match wayland_context.decorated_from(&egl_surface, w as i32, h as i32) { + Some(s) => s, + None => return Err(CreationError::NotSupported) + }; + + Ok(Window { + wayland_context: wayland_context, + egl_surface: egl_surface, + decorated_surface: Mutex::new(decorated_surface), + evt_queue: evt_queue, + inner_size: Mutex::new((w as i32, h as i32)), + resize_callback: None, + context: context + }) } pub fn set_title(&self, title: &str) { - unimplemented!() + self.decorated_surface.lock().unwrap().set_title(title.into()) } #[inline] pub fn show(&self) { - unimplemented!() + // TODO } #[inline] pub fn hide(&self) { - unimplemented!() + // TODO } #[inline] pub fn get_position(&self) -> Option<(i32, i32)> { - unimplemented!() + // Not possible with wayland + None } #[inline] pub fn set_position(&self, _x: i32, _y: i32) { - unimplemented!() + // Not possible with wayland } pub fn get_inner_size(&self) -> Option<(u32, u32)> { - unimplemented!() + let (w, h) = *self.inner_size.lock().unwrap(); + Some((w as u32, h as u32)) } #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { - unimplemented!() + let (w, h) = *self.inner_size.lock().unwrap(); + let (w, h) = add_borders(w, h); + Some((w as u32, h as u32)) } #[inline] pub fn set_inner_size(&self, x: u32, y: u32) { - unimplemented!() + self.decorated_surface.lock().unwrap().resize(x as i32, y as i32) } #[inline] @@ -113,17 +221,18 @@ impl Window { #[inline] pub fn set_window_resize_callback(&mut self, callback: Option) { - unimplemented!() + self.resize_callback = callback; } #[inline] pub fn set_cursor(&self, cursor: MouseCursor) { - unimplemented!() + // TODO } #[inline] pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { - unimplemented!() + // TODO + Ok(()) } #[inline] @@ -132,8 +241,9 @@ impl Window { } #[inline] - pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { - unimplemented!() + pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> { + // TODO: not yet possible on wayland + Ok(()) } #[inline] @@ -178,3 +288,10 @@ impl GlContext for Window { self.context.get_pixel_format().clone() } } + +impl Drop for Window { + fn drop(&mut self) { + use wayland_client::Proxy; + self.wayland_context.dropped_surface((*self.egl_surface).id()) + } +} \ No newline at end of file -- cgit v1.2.3 From 84f1aef100c5f60cfb9086ca872cbf274092696c Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sun, 13 Dec 2015 15:13:23 +0100 Subject: api/wayland: add keyboard support. --- Cargo.toml | 12 +-- src/api/wayland/context.rs | 15 ++- src/api/wayland/events.rs | 12 +++ src/api/wayland/keyboard.rs | 229 ++++++++++++++++++++++++++++++++++++++++++++ src/api/wayland/mod.rs | 1 + 5 files changed, 261 insertions(+), 8 deletions(-) create mode 100644 src/api/wayland/keyboard.rs (limited to 'src/api/wayland/mod.rs') diff --git a/Cargo.toml b/Cargo.toml index d0ee1fb..42765c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,41 +83,41 @@ dwmapi-sys = "0.1" [target.i686-unknown-linux-gnu.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.3", features = ["egl", "dlopen"] } -wayland-kbd = "0.3.2" +wayland-kbd = "0.3.3" wayland-window = "0.2.2" x11-dl = "~2.2" [target.x86_64-unknown-linux-gnu.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.3", features = ["egl", "dlopen"] } -wayland-kbd = "0.3.2" +wayland-kbd = "0.3.3" wayland-window = "0.2.2" x11-dl = "~2.2" [target.arm-unknown-linux-gnueabihf.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.3", features = ["egl", "dlopen"] } -wayland-kbd = "0.3.2" +wayland-kbd = "0.3.3" wayland-window = "0.2.2" x11-dl = "~2.2" [target.aarch64-unknown-linux-gnu.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.3", features = ["egl", "dlopen"] } -wayland-kbd = "0.3.2" +wayland-kbd = "0.3.3" wayland-window = "0.2.2" x11-dl = "~2.2" [target.x86_64-unknown-dragonfly.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.3", features = ["egl", "dlopen"] } -wayland-kbd = "0.3.2" +wayland-kbd = "0.3.3" wayland-window = "0.2.2" x11-dl = "~2.2" [target.x86_64-unknown-freebsd.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.3", features = ["egl", "dlopen"] } -wayland-kbd = "0.3.2" +wayland-kbd = "0.3.3" wayland-window = "0.2.2" x11-dl = "~2.2" diff --git a/src/api/wayland/context.rs b/src/api/wayland/context.rs index 4b39d85..285f50c 100644 --- a/src/api/wayland/context.rs +++ b/src/api/wayland/context.rs @@ -14,6 +14,7 @@ use wayland_client::wayland::shell::WlShell; use wayland_client::wayland::shm::WlShm; use wayland_client::wayland::subcompositor::WlSubcompositor; +use super::wayland_kbd::MappedKeyboard; use super::wayland_window::DecoratedSurface; lazy_static! { @@ -34,6 +35,7 @@ pub struct WaylandFocuses { pub pointer: Option, pub pointer_on: Option, pub pointer_at: Option<(f64, f64)>, + pub keyboard: Option, pub keyboard_on: Option } @@ -72,6 +74,7 @@ impl WaylandContext { pointer: None, pointer_on: None, pointer_at: None, + keyboard: None, keyboard_on: None }) }) @@ -119,11 +122,19 @@ impl WaylandContext { self.inner.display.dispatch_pending().unwrap(); let mut iterator = self.iterator.lock().unwrap(); let mut focuses = self.focuses.lock().unwrap(); - let known_ids = self.known_surfaces.lock().unwrap(); + let known_surfaces = self.known_surfaces.lock().unwrap(); let queues = self.queues.lock().unwrap(); + // first, keyboard events + let kdb_evts = super::keyboard::translate_kbd_events(&mut *focuses, &known_surfaces); + for (evt, id) in kdb_evts { + if let Some(q) = queues.get(&id) { + q.lock().unwrap().push_back(evt); + } + } + // then, the rest for evt in &mut *iterator { if let Some((evt, id)) = super::events::translate_event( - evt, &mut *focuses, &known_ids, + evt, &mut *focuses, &known_surfaces, self.inner.seat.as_ref().map(|s| &s.0)) { if let Some(q) = queues.get(&id) { diff --git a/src/api/wayland/events.rs b/src/api/wayland/events.rs index 6a7a2e7..8aeddac 100644 --- a/src/api/wayland/events.rs +++ b/src/api/wayland/events.rs @@ -12,6 +12,8 @@ use wayland_client::wayland::seat::{WlSeat, WlSeatEvent, WlPointerEvent, WlPointerButtonState, WlPointerAxis, WlSeatCapability}; +use super::wayland_kbd::MappedKeyboard; + use super::context::WaylandFocuses; pub fn translate_event( @@ -29,6 +31,16 @@ pub fn translate_event( focuses.pointer = Some(seat.get_pointer()); } } + if cap.contains(WlSeatCapability::Keyboard) && focuses.keyboard.is_none() { + if let Some(seat) = seat { + match MappedKeyboard::new(seat) { + Ok(mk) => { + focuses.keyboard = Some(mk) + }, + Err(_) => {} + } + } + } None }, _ => None diff --git a/src/api/wayland/keyboard.rs b/src/api/wayland/keyboard.rs new file mode 100644 index 0000000..3190b87 --- /dev/null +++ b/src/api/wayland/keyboard.rs @@ -0,0 +1,229 @@ +use std::collections::HashSet; + +use Event as GlutinEvent; +use ElementState; +use VirtualKeyCode; + +use wayland_client::ProxyId; +use wayland_client::wayland::seat::{WlKeyboardEvent,WlKeyboardKeyState}; + +use super::wayland_kbd::MappedKeyboardEvent; + +use super::context::WaylandFocuses; + +pub fn translate_kbd_events( + focuses: &mut WaylandFocuses, + known_surfaces: &HashSet, +) -> Vec<(GlutinEvent, ProxyId)> { + let mut out = Vec::new(); + if let Some(mkbd) = focuses.keyboard.as_mut() { + for evt in mkbd { + match evt { + MappedKeyboardEvent::KeyEvent(kevt) => { + if let Some(surface) = focuses.keyboard_on { + let vkcode = match kevt.keycode { + 1 => Some(VirtualKeyCode::Escape), + 2 => Some(VirtualKeyCode::Key1), + 3 => Some(VirtualKeyCode::Key2), + 4 => Some(VirtualKeyCode::Key3), + 5 => Some(VirtualKeyCode::Key4), + 6 => Some(VirtualKeyCode::Key5), + 7 => Some(VirtualKeyCode::Key6), + 8 => Some(VirtualKeyCode::Key7), + 9 => Some(VirtualKeyCode::Key8), + 10 => Some(VirtualKeyCode::Key9), + 11 => Some(VirtualKeyCode::Key0), + _ => kevt.as_symbol().and_then(keysym_to_vkey) + }; + let text = kevt.as_utf8(); + out.push(( + GlutinEvent::KeyboardInput( + match kevt.keystate { + WlKeyboardKeyState::Pressed => ElementState::Pressed, + WlKeyboardKeyState::Released =>ElementState::Released + }, + (kevt.keycode & 0xff) as u8, + vkcode + ), + surface + )); + if let Some(c) = text.and_then(|s| s.chars().next()) { + out.push(( + GlutinEvent::ReceivedCharacter(c), + surface + )); + } + } + + } + MappedKeyboardEvent::Other(oevt) => match oevt { + WlKeyboardEvent::Enter(_, surface, _) => { + if known_surfaces.contains(&surface) { + focuses.keyboard_on = Some(surface); + out.push((GlutinEvent::Focused(true), surface)); + } + }, + WlKeyboardEvent::Leave(_, surface) => { + if known_surfaces.contains(&surface) { + focuses.keyboard_on = None; + out.push((GlutinEvent::Focused(false), surface)); + } + } + _ => {} + } + } + } + } + out +} + +pub fn keysym_to_vkey(keysym: u32) -> Option { + use super::wayland_kbd::keysyms; + match keysym { + // letters + keysyms::XKB_KEY_A | keysyms::XKB_KEY_a => Some(VirtualKeyCode::A), + keysyms::XKB_KEY_B | keysyms::XKB_KEY_b => Some(VirtualKeyCode::B), + keysyms::XKB_KEY_C | keysyms::XKB_KEY_c => Some(VirtualKeyCode::C), + keysyms::XKB_KEY_D | keysyms::XKB_KEY_d => Some(VirtualKeyCode::D), + keysyms::XKB_KEY_E | keysyms::XKB_KEY_e => Some(VirtualKeyCode::E), + keysyms::XKB_KEY_F | keysyms::XKB_KEY_f => Some(VirtualKeyCode::F), + keysyms::XKB_KEY_G | keysyms::XKB_KEY_g => Some(VirtualKeyCode::G), + keysyms::XKB_KEY_H | keysyms::XKB_KEY_h => Some(VirtualKeyCode::H), + keysyms::XKB_KEY_I | keysyms::XKB_KEY_i => Some(VirtualKeyCode::I), + keysyms::XKB_KEY_J | keysyms::XKB_KEY_j => Some(VirtualKeyCode::J), + keysyms::XKB_KEY_K | keysyms::XKB_KEY_k => Some(VirtualKeyCode::K), + keysyms::XKB_KEY_L | keysyms::XKB_KEY_l => Some(VirtualKeyCode::L), + keysyms::XKB_KEY_M | keysyms::XKB_KEY_m => Some(VirtualKeyCode::M), + keysyms::XKB_KEY_N | keysyms::XKB_KEY_n => Some(VirtualKeyCode::N), + keysyms::XKB_KEY_O | keysyms::XKB_KEY_o => Some(VirtualKeyCode::O), + keysyms::XKB_KEY_P | keysyms::XKB_KEY_p => Some(VirtualKeyCode::P), + keysyms::XKB_KEY_Q | keysyms::XKB_KEY_q => Some(VirtualKeyCode::Q), + keysyms::XKB_KEY_R | keysyms::XKB_KEY_r => Some(VirtualKeyCode::R), + keysyms::XKB_KEY_S | keysyms::XKB_KEY_s => Some(VirtualKeyCode::S), + keysyms::XKB_KEY_T | keysyms::XKB_KEY_t => Some(VirtualKeyCode::T), + keysyms::XKB_KEY_U | keysyms::XKB_KEY_u => Some(VirtualKeyCode::U), + keysyms::XKB_KEY_V | keysyms::XKB_KEY_v => Some(VirtualKeyCode::V), + keysyms::XKB_KEY_W | keysyms::XKB_KEY_w => Some(VirtualKeyCode::W), + keysyms::XKB_KEY_X | keysyms::XKB_KEY_x => Some(VirtualKeyCode::X), + keysyms::XKB_KEY_Y | keysyms::XKB_KEY_y => Some(VirtualKeyCode::Y), + keysyms::XKB_KEY_Z | keysyms::XKB_KEY_z => Some(VirtualKeyCode::Z), + // F-- + keysyms::XKB_KEY_F1 => Some(VirtualKeyCode::F1), + keysyms::XKB_KEY_F2 => Some(VirtualKeyCode::F2), + keysyms::XKB_KEY_F3 => Some(VirtualKeyCode::F3), + keysyms::XKB_KEY_F4 => Some(VirtualKeyCode::F4), + keysyms::XKB_KEY_F5 => Some(VirtualKeyCode::F5), + keysyms::XKB_KEY_F6 => Some(VirtualKeyCode::F6), + keysyms::XKB_KEY_F7 => Some(VirtualKeyCode::F7), + keysyms::XKB_KEY_F8 => Some(VirtualKeyCode::F8), + keysyms::XKB_KEY_F9 => Some(VirtualKeyCode::F9), + keysyms::XKB_KEY_F10 => Some(VirtualKeyCode::F10), + keysyms::XKB_KEY_F11 => Some(VirtualKeyCode::F11), + keysyms::XKB_KEY_F12 => Some(VirtualKeyCode::F12), + keysyms::XKB_KEY_F13 => Some(VirtualKeyCode::F13), + keysyms::XKB_KEY_F14 => Some(VirtualKeyCode::F14), + keysyms::XKB_KEY_F15 => Some(VirtualKeyCode::F15), + // flow control + keysyms::XKB_KEY_Print => Some(VirtualKeyCode::Snapshot), + keysyms::XKB_KEY_Scroll_Lock => Some(VirtualKeyCode::Scroll), + keysyms::XKB_KEY_Pause => Some(VirtualKeyCode::Pause), + keysyms::XKB_KEY_Insert => Some(VirtualKeyCode::Insert), + keysyms::XKB_KEY_Home => Some(VirtualKeyCode::Home), + keysyms::XKB_KEY_Delete => Some(VirtualKeyCode::Delete), + keysyms::XKB_KEY_End => Some(VirtualKeyCode::End), + keysyms::XKB_KEY_Page_Down => Some(VirtualKeyCode::PageDown), + keysyms::XKB_KEY_Page_Up => Some(VirtualKeyCode::PageUp), + // arrows + keysyms::XKB_KEY_Left => Some(VirtualKeyCode::Left), + keysyms::XKB_KEY_Up => Some(VirtualKeyCode::Up), + keysyms::XKB_KEY_Right => Some(VirtualKeyCode::Right), + keysyms::XKB_KEY_Down => Some(VirtualKeyCode::Down), + // + keysyms::XKB_KEY_BackSpace => Some(VirtualKeyCode::Back), + keysyms::XKB_KEY_Return => Some(VirtualKeyCode::Return), + keysyms::XKB_KEY_space => Some(VirtualKeyCode::Space), + // keypad + keysyms::XKB_KEY_Num_Lock => Some(VirtualKeyCode::Numlock), + keysyms::XKB_KEY_KP_0 => Some(VirtualKeyCode::Numpad0), + keysyms::XKB_KEY_KP_1 => Some(VirtualKeyCode::Numpad1), + keysyms::XKB_KEY_KP_2 => Some(VirtualKeyCode::Numpad2), + keysyms::XKB_KEY_KP_3 => Some(VirtualKeyCode::Numpad3), + keysyms::XKB_KEY_KP_4 => Some(VirtualKeyCode::Numpad4), + keysyms::XKB_KEY_KP_5 => Some(VirtualKeyCode::Numpad5), + keysyms::XKB_KEY_KP_6 => Some(VirtualKeyCode::Numpad6), + keysyms::XKB_KEY_KP_7 => Some(VirtualKeyCode::Numpad7), + keysyms::XKB_KEY_KP_8 => Some(VirtualKeyCode::Numpad8), + keysyms::XKB_KEY_KP_9 => Some(VirtualKeyCode::Numpad9), + // misc + // => Some(VirtualKeyCode::AbntC1), + // => Some(VirtualKeyCode::AbntC2), + keysyms::XKB_KEY_plus => Some(VirtualKeyCode::Add), + keysyms::XKB_KEY_apostrophe => Some(VirtualKeyCode::Apostrophe), + // => Some(VirtualKeyCode::Apps), + // => Some(VirtualKeyCode::At), + // => Some(VirtualKeyCode::Ax), + keysyms::XKB_KEY_backslash => Some(VirtualKeyCode::Backslash), + // => Some(VirtualKeyCode::Calculator), + // => Some(VirtualKeyCode::Capital), + keysyms::XKB_KEY_colon => Some(VirtualKeyCode::Colon), + keysyms::XKB_KEY_comma => Some(VirtualKeyCode::Comma), + // => Some(VirtualKeyCode::Convert), + // => Some(VirtualKeyCode::Decimal), + // => Some(VirtualKeyCode::Divide), + keysyms::XKB_KEY_equal => Some(VirtualKeyCode::Equals), + // => Some(VirtualKeyCode::Grave), + // => Some(VirtualKeyCode::Kana), + // => Some(VirtualKeyCode::Kanji), + keysyms::XKB_KEY_Alt_L => Some(VirtualKeyCode::LAlt), + // => Some(VirtualKeyCode::LBracket), + keysyms::XKB_KEY_Control_L => Some(VirtualKeyCode::LControl), + // => Some(VirtualKeyCode::LMenu), + keysyms::XKB_KEY_Shift_L => Some(VirtualKeyCode::LShift), + // => Some(VirtualKeyCode::LWin), + // => Some(VirtualKeyCode::Mail), + // => Some(VirtualKeyCode::MediaSelect), + // => Some(VirtualKeyCode::MediaStop), + keysyms::XKB_KEY_minus => Some(VirtualKeyCode::Minus), + keysyms::XKB_KEY_asterisk => Some(VirtualKeyCode::Multiply), + // => Some(VirtualKeyCode::Mute), + // => Some(VirtualKeyCode::MyComputer), + // => Some(VirtualKeyCode::NextTrack), + // => Some(VirtualKeyCode::NoConvert), + keysyms::XKB_KEY_KP_Separator => Some(VirtualKeyCode::NumpadComma), + keysyms::XKB_KEY_KP_Enter => Some(VirtualKeyCode::NumpadEnter), + keysyms::XKB_KEY_KP_Equal => Some(VirtualKeyCode::NumpadEquals), + // => Some(VirtualKeyCode::OEM102), + // => Some(VirtualKeyCode::Period), + // => Some(VirtualKeyCode::Playpause), + // => Some(VirtualKeyCode::Power), + // => Some(VirtualKeyCode::Prevtrack), + keysyms::XKB_KEY_Alt_R => Some(VirtualKeyCode::RAlt), + // => Some(VirtualKeyCode::RBracket), + keysyms::XKB_KEY_Control_R => Some(VirtualKeyCode::RControl), + // => Some(VirtualKeyCode::RMenu), + keysyms::XKB_KEY_Shift_R => Some(VirtualKeyCode::RShift), + // => Some(VirtualKeyCode::RWin), + keysyms::XKB_KEY_semicolon => Some(VirtualKeyCode::Semicolon), + keysyms::XKB_KEY_slash => Some(VirtualKeyCode::Slash), + // => Some(VirtualKeyCode::Sleep), + // => Some(VirtualKeyCode::Stop), + // => Some(VirtualKeyCode::Subtract), + // => Some(VirtualKeyCode::Sysrq), + keysyms::XKB_KEY_Tab => Some(VirtualKeyCode::Tab), + // => Some(VirtualKeyCode::Underline), + // => Some(VirtualKeyCode::Unlabeled), + keysyms::XKB_KEY_XF86AudioLowerVolume => Some(VirtualKeyCode::VolumeDown), + keysyms::XKB_KEY_XF86AudioRaiseVolume => Some(VirtualKeyCode::VolumeUp), + // => Some(VirtualKeyCode::Wake), + // => Some(VirtualKeyCode::Webback), + // => Some(VirtualKeyCode::WebFavorites), + // => Some(VirtualKeyCode::WebForward), + // => Some(VirtualKeyCode::WebHome), + // => Some(VirtualKeyCode::WebRefresh), + // => Some(VirtualKeyCode::WebSearch), + // => Some(VirtualKeyCode::WebStop), + // => Some(VirtualKeyCode::Yen), + // fallback + _ => None + } +} \ No newline at end of file diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index f2e3b2f..b6a2602 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -8,6 +8,7 @@ extern crate wayland_window; mod context; mod events; +mod keyboard; mod monitor; mod window; -- cgit v1.2.3