wayland: Initially paint the window white so that they always exist

This commit is contained in:
Victor Berger 2017-05-23 21:53:17 +02:00
parent 96a90d0ec6
commit 148c751f32
4 changed files with 63 additions and 9 deletions

View file

@ -1,8 +1,9 @@
use std::fs::File;
use std::sync::{Arc, Mutex};
use std::sync::atomic::AtomicBool;
use wayland_client::{EventQueue, EventQueueHandle, Proxy};
use wayland_client::protocol::{wl_display,wl_surface,wl_shell_surface};
use wayland_client::protocol::{wl_display,wl_surface,wl_shell_surface,wl_buffer};
use {CreationError, MouseCursor, CursorState, WindowAttributes};
use platform::MonitorId as PlatformMonitorId;
@ -39,16 +40,27 @@ impl Window {
{
let (width, height) = attributes.dimensions.unwrap_or((800,600));
let (surface, decorated) = ctxt.create_window::<DecoratedHandler>();
let (surface, decorated, buffer, tmpfile) = ctxt.create_window::<DecoratedHandler>(width, height);
// init DecoratedSurface
let (evq, cleanup_signal) = evlp.get_window_init();
let decorated_id = {
let mut evq_guard = evq.lock().unwrap();
// create a handler to clean up initial buffer
let initial_buffer_handler_id = evq_guard.add_handler(InitialBufferHandler::new());
// register the buffer to it
evq_guard.register::<_, InitialBufferHandler>(&buffer, initial_buffer_handler_id);
// store the DecoratedSurface handler
let decorated_id = evq_guard.add_handler_with_init(decorated);
{
// initialize the DecoratedHandler
let mut state = evq_guard.state();
{
// store the buffer and tempfile in the handler, to be cleanded up at the right
// time
let initial_buffer_h = state.get_mut_handler::<InitialBufferHandler>(initial_buffer_handler_id);
initial_buffer_h.initial_buffer = Some((buffer, tmpfile));
}
// initialize the DecoratedHandler
let decorated = state.get_mut_handler::<DecoratedSurface<DecoratedHandler>>(decorated_id);
*(decorated.handler()) = Some(DecoratedHandler::new());
@ -203,3 +215,29 @@ impl wayland_window::Handler for DecoratedHandler {
self.newsize = Some((max(width,1) as u32, max(height,1) as u32));
}
}
// a handler to release the ressources acquired to draw the initial white screen as soon as
// the compositor does not use them any more
pub struct InitialBufferHandler {
initial_buffer: Option<(wl_buffer::WlBuffer, File)>
}
impl InitialBufferHandler {
fn new() -> InitialBufferHandler {
InitialBufferHandler {
initial_buffer: None,
}
}
}
impl wl_buffer::Handler for InitialBufferHandler {
fn release(&mut self, _: &mut EventQueueHandle, buffer: &wl_buffer::WlBuffer) {
// release the ressources we've acquired for initial white window
buffer.destroy();
self.initial_buffer = None;
}
}
declare_handler!(InitialBufferHandler, wl_buffer::Handler, wl_buffer::WlBuffer);