diff --git a/Cargo.toml b/Cargo.toml index aa8598f..772bdd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,8 @@ rental = "0.4.11" gl_generator = "0.5" [dev-dependencies] -slog-term = "~1.5" +slog-term = "2.0" +slog-async = "2.0" [features] default = ["backend_winit", "backend_libinput", "renderer_glium"] diff --git a/examples/simple.rs b/examples/simple.rs index ef264ef..29a1f97 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -2,36 +2,70 @@ extern crate wayland_server; extern crate smithay; extern crate glium; +#[macro_use] +extern crate slog; +extern crate slog_async; +extern crate slog_term; + +use slog::*; + use glium::Surface; + use smithay::backend::graphics::glium::IntoGlium; use smithay::backend::input::InputBackend; use smithay::backend::winit; use smithay::shm::ShmGlobal; -use wayland_server::protocol::wl_shm; +use smithay::compositor::{CompositorHandler, self}; + +use wayland_server::protocol::{wl_compositor, wl_shm, wl_subcompositor}; + +struct SurfaceHandler; + +impl compositor::Handler for SurfaceHandler { +} fn main() { + // A logger facility, here we use the terminal for this example + let log = Logger::root(slog_async::Async::default(slog_term::term_full().fuse()).fuse(), o!()); + // Initialize a simple backend for testing - let (renderer, mut input) = winit::init().unwrap(); + let (renderer, mut input) = winit::init(log.clone()).unwrap(); let (_display, mut event_loop) = wayland_server::create_display(); + /* + * Initialize wl_shm global + */ // Insert the ShmGlobal as a handler to your event loop // Here, we specify tha the standard Argb8888 and Xrgb8888 is the only supported. - let handler_id = event_loop.add_handler_with_init(ShmGlobal::new( - vec![], - None, /* we don't provide a logger here */ - )); - + let shm_handler_id = + event_loop.add_handler_with_init(ShmGlobal::new(vec![], log.clone())); // Register this handler to advertise a wl_shm global of version 1 - let shm_global = event_loop.register_global::(handler_id, 1); + event_loop.register_global::(shm_handler_id, 1); - // Retrieve the shm token for later use to access the buffers - let shm_token = { + /* + * Initialize the compositor global + */ + let compositor_handler_id = + event_loop.add_handler_with_init(CompositorHandler::<(),_>::new(SurfaceHandler, log.clone())); + // register it to handle wl_compositor and wl_subcompositor + event_loop.register_global::>(compositor_handler_id, 4); + event_loop.register_global::>(compositor_handler_id, 1); + + /* + * retrieve the tokens + */ + let (shm_token, compositor_token) = { let state = event_loop.state(); - state.get_handler::(handler_id).get_token() + ( + state.get_handler::(shm_handler_id).get_token(), + state.get_handler::>(compositor_handler_id).get_token() + ) }; - // Init glium + /* + * Initialize glium + */ let context = renderer.into_glium();