smithay/examples/simple.rs

37 lines
1.2 KiB
Rust
Raw Normal View History

2017-03-07 10:53:57 +00:00
extern crate wayland_server;
extern crate smithay;
2017-03-19 20:56:10 +00:00
use smithay::backend::input::InputBackend;
2017-05-21 20:51:38 +00:00
use smithay::backend::winit;
2017-03-20 13:33:27 +00:00
use smithay::shm::ShmGlobal;
2017-03-07 10:53:57 +00:00
use wayland_server::protocol::wl_shm;
fn main() {
2017-05-21 20:40:15 +00:00
// Initialize a simple backend for testing
let (mut renderer, mut input) = winit::init().unwrap();
2017-03-07 10:53:57 +00:00
let (_, mut event_loop) = wayland_server::create_display();
// Insert the ShmGlobal as a handler to your event loop
// Here, we specify tha the standard Argb8888 and Xrgb8888 is the only supported.
2017-03-20 13:33:27 +00:00
let handler_id =
2017-03-20 14:53:45 +00:00
event_loop.add_handler_with_init(ShmGlobal::new(vec![],
None /* we don't provide a logger here */));
2017-03-07 10:53:57 +00:00
// Register this handler to advertise a wl_shm global of version 1
2017-03-20 13:33:27 +00:00
let shm_global = event_loop.register_global::<wl_shm::WlShm, ShmGlobal>(handler_id, 1);
2017-03-07 10:53:57 +00:00
// Retrieve the shm token for later use to access the buffers
let shm_token = {
let state = event_loop.state();
state.get_handler::<ShmGlobal>(handler_id).get_token()
};
2017-03-20 13:33:27 +00:00
// TODO render stuff
2017-03-07 10:53:57 +00:00
2017-03-20 13:33:27 +00:00
// TODO put input handling on the event loop
2017-03-19 20:56:10 +00:00
input.dispatch_new_events().unwrap();
2017-03-07 10:53:57 +00:00
2017-03-19 20:56:10 +00:00
event_loop.run().unwrap();
2017-03-07 10:53:57 +00:00
}