From 8809f182b5a589aa8c000aeb9d56240f63a0c996 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sun, 4 Jun 2017 21:36:18 +0200 Subject: [PATCH] Fuse CompositorGlobal and CompositorHandler --- src/compositor/global.rs | 48 ++++---------------------------------- src/compositor/handlers.rs | 26 ++------------------- src/compositor/mod.rs | 44 ++++++++++++++++++++++++++-------- 3 files changed, 41 insertions(+), 77 deletions(-) diff --git a/src/compositor/global.rs b/src/compositor/global.rs index 96864bf..788e12e 100644 --- a/src/compositor/global.rs +++ b/src/compositor/global.rs @@ -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 { - handler_id: Option, - log: ::slog::Logger, - _data: ::std::marker::PhantomData<*mut U>, -} - -impl CompositorGlobal { - pub fn new(logger: L) -> CompositorGlobal - where L: Into> - { - 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 { - super::make_token(self.handler_id - .expect("CompositorGlobal was not initialized.")) - } -} - -impl Init for CompositorGlobal - where U: Send + Sync + 'static -{ - fn init(&mut self, evlh: &mut EventLoopHandle, _index: usize) { - let id = evlh.add_handler_with_init(CompositorHandler::::new(self.log.clone())); - self.handler_id = Some(id); - } -} - -impl GlobalHandler for CompositorGlobal +impl GlobalHandler for CompositorHandler 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>(&global, hid); + evlh.register::<_, CompositorHandler>(&global, self.my_id); } } -impl GlobalHandler for CompositorGlobal +impl GlobalHandler for CompositorHandler 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>(&global, hid); + evlh.register::<_, CompositorHandler>(&global, self.my_id); } } diff --git a/src/compositor/handlers.rs b/src/compositor/handlers.rs index e8b017b..b52d76f 100644 --- a/src/compositor/handlers.rs +++ b/src/compositor/handlers.rs @@ -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 { - my_id: usize, - log: ::slog::Logger, - _data: ::std::marker::PhantomData, -} - struct CompositorDestructor { _t: ::std::marker::PhantomData, } -impl Init for CompositorHandler { - fn init(&mut self, _evqh: &mut EventLoopHandle, index: usize) { - self.my_id = index; - debug!(self.log, "Init finished") - } -} - -impl CompositorHandler { - pub fn new(log: ::slog::Logger) -> CompositorHandler { - CompositorHandler { - my_id: ::std::usize::MAX, - log: log, - _data: ::std::marker::PhantomData::, - } - } -} - /* * wl_compositor */ diff --git a/src/compositor/mod.rs b/src/compositor/mod.rs index 064afbd..bd245e6 100644 --- a/src/compositor/mod.rs +++ b/src/compositor/mod.rs @@ -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 { _data: ::std::marker::PhantomData<*mut U>, } -fn make_token(hid: usize) -> CompositorToken { - CompositorToken { - hid: hid, - _data: ::std::marker::PhantomData, - } -} - impl CompositorToken { /// Access the data of a surface /// @@ -274,3 +265,36 @@ impl CompositorToken { } } } + +pub struct CompositorHandler { + my_id: usize, + log: ::slog::Logger, + _data: ::std::marker::PhantomData, +} + +impl Init for CompositorHandler { + fn init(&mut self, _evqh: &mut EventLoopHandle, index: usize) { + self.my_id = index; + debug!(self.log, "Init finished") + } +} + +impl CompositorHandler { + pub fn new(logger: L) -> CompositorHandler + where L: Into> + { + 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 { + CompositorToken { + hid: self.my_id, + _data: ::std::marker::PhantomData, + } + } +}