Fuse CompositorGlobal and CompositorHandler
This commit is contained in:
parent
13d0479264
commit
8809f182b5
|
@ -1,58 +1,20 @@
|
|||
use super::CompositorToken;
|
||||
use super::handlers::CompositorHandler;
|
||||
use super::CompositorHandler;
|
||||
|
||||
use wayland_server::{Client, EventLoopHandle, GlobalHandler, Init};
|
||||
use wayland_server::protocol::{wl_compositor, wl_subcompositor};
|
||||
|
||||
pub struct CompositorGlobal<U> {
|
||||
handler_id: Option<usize>,
|
||||
log: ::slog::Logger,
|
||||
_data: ::std::marker::PhantomData<*mut U>,
|
||||
}
|
||||
|
||||
impl<U> CompositorGlobal<U> {
|
||||
pub fn new<L>(logger: L) -> CompositorGlobal<U>
|
||||
where L: Into<Option<::slog::Logger>>
|
||||
{
|
||||
let log = ::slog_or_stdlog(logger);
|
||||
CompositorGlobal {
|
||||
handler_id: None,
|
||||
log: log.new(o!("smithay_module" => "wompositor_handler")),
|
||||
_data: ::std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_token(&self) -> CompositorToken<U> {
|
||||
super::make_token(self.handler_id
|
||||
.expect("CompositorGlobal was not initialized."))
|
||||
}
|
||||
}
|
||||
|
||||
impl<U> Init for CompositorGlobal<U>
|
||||
where U: Send + Sync + 'static
|
||||
{
|
||||
fn init(&mut self, evlh: &mut EventLoopHandle, _index: usize) {
|
||||
let id = evlh.add_handler_with_init(CompositorHandler::<U>::new(self.log.clone()));
|
||||
self.handler_id = Some(id);
|
||||
}
|
||||
}
|
||||
|
||||
impl<U: Default> GlobalHandler<wl_compositor::WlCompositor> for CompositorGlobal<U>
|
||||
impl<U: Default> GlobalHandler<wl_compositor::WlCompositor> for CompositorHandler<U>
|
||||
where U: Send + Sync + 'static
|
||||
{
|
||||
fn bind(&mut self, evlh: &mut EventLoopHandle, _: &Client, global: wl_compositor::WlCompositor) {
|
||||
let hid = self.handler_id
|
||||
.expect("CompositorGlobal was not initialized.");
|
||||
evlh.register::<_, CompositorHandler<U>>(&global, hid);
|
||||
evlh.register::<_, CompositorHandler<U>>(&global, self.my_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl<U> GlobalHandler<wl_subcompositor::WlSubcompositor> for CompositorGlobal<U>
|
||||
impl<U> GlobalHandler<wl_subcompositor::WlSubcompositor> for CompositorHandler<U>
|
||||
where U: Send + Sync + 'static
|
||||
{
|
||||
fn bind(&mut self, evlh: &mut EventLoopHandle, _: &Client, global: wl_subcompositor::WlSubcompositor) {
|
||||
let hid = self.handler_id
|
||||
.expect("CompositorGlobal was not initialized.");
|
||||
evlh.register::<_, CompositorHandler<U>>(&global, hid);
|
||||
evlh.register::<_, CompositorHandler<U>>(&global, self.my_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +1,15 @@
|
|||
use super::{Rectangle, RectangleKind, SubsurfaceAttributes, Damage};
|
||||
use super::{Rectangle, RectangleKind, SubsurfaceAttributes, Damage, CompositorHandler};
|
||||
use super::region::RegionData;
|
||||
use super::tree::SurfaceData;
|
||||
use super::CompositorToken;
|
||||
use wayland_server::{Client, Destroy, EventLoopHandle, Init, Resource};
|
||||
use wayland_server::protocol::{wl_buffer, wl_callback, wl_compositor, wl_output, wl_region,
|
||||
wl_subcompositor, wl_subsurface, wl_surface};
|
||||
|
||||
pub struct CompositorHandler<U> {
|
||||
my_id: usize,
|
||||
log: ::slog::Logger,
|
||||
_data: ::std::marker::PhantomData<U>,
|
||||
}
|
||||
|
||||
struct CompositorDestructor<U> {
|
||||
_t: ::std::marker::PhantomData<U>,
|
||||
}
|
||||
|
||||
impl<U> Init for CompositorHandler<U> {
|
||||
fn init(&mut self, _evqh: &mut EventLoopHandle, index: usize) {
|
||||
self.my_id = index;
|
||||
debug!(self.log, "Init finished")
|
||||
}
|
||||
}
|
||||
|
||||
impl<U> CompositorHandler<U> {
|
||||
pub fn new(log: ::slog::Logger) -> CompositorHandler<U> {
|
||||
CompositorHandler {
|
||||
my_id: ::std::usize::MAX,
|
||||
log: log,
|
||||
_data: ::std::marker::PhantomData::<U>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* wl_compositor
|
||||
*/
|
||||
|
|
|
@ -3,13 +3,11 @@ mod handlers;
|
|||
mod tree;
|
||||
mod region;
|
||||
|
||||
pub use self::global::CompositorGlobal;
|
||||
use self::handlers::CompositorHandler;
|
||||
pub use self::tree::RoleStatus;
|
||||
use self::tree::SurfaceData;
|
||||
|
||||
use wayland_server::protocol::{wl_buffer, wl_output, wl_surface};
|
||||
use wayland_server::resource_is_registered;
|
||||
use wayland_server::{EventLoopHandle, resource_is_registered, Init};
|
||||
|
||||
/// Description of which part of a surface
|
||||
/// should be considered damaged and needs to be redrawn
|
||||
|
@ -173,13 +171,6 @@ pub struct CompositorToken<U> {
|
|||
_data: ::std::marker::PhantomData<*mut U>,
|
||||
}
|
||||
|
||||
fn make_token<U>(hid: usize) -> CompositorToken<U> {
|
||||
CompositorToken {
|
||||
hid: hid,
|
||||
_data: ::std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
impl<U: Send + 'static> CompositorToken<U> {
|
||||
/// Access the data of a surface
|
||||
///
|
||||
|
@ -274,3 +265,36 @@ impl<U: Send + 'static> CompositorToken<U> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CompositorHandler<U> {
|
||||
my_id: usize,
|
||||
log: ::slog::Logger,
|
||||
_data: ::std::marker::PhantomData<U>,
|
||||
}
|
||||
|
||||
impl<U> Init for CompositorHandler<U> {
|
||||
fn init(&mut self, _evqh: &mut EventLoopHandle, index: usize) {
|
||||
self.my_id = index;
|
||||
debug!(self.log, "Init finished")
|
||||
}
|
||||
}
|
||||
|
||||
impl<U> CompositorHandler<U> {
|
||||
pub fn new<L>(logger: L) -> CompositorHandler<U>
|
||||
where L: Into<Option<::slog::Logger>>
|
||||
{
|
||||
let log = ::slog_or_stdlog(logger);
|
||||
CompositorHandler {
|
||||
my_id: ::std::usize::MAX,
|
||||
log: log.new(o!("smithay_module" => "compositor_handler")),
|
||||
_data: ::std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_token(&self) -> CompositorToken<U> {
|
||||
CompositorToken {
|
||||
hid: self.my_id,
|
||||
_data: ::std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue