Add subhandler for wl_surface.{commit,frame}
This commit is contained in:
parent
8809f182b5
commit
1e960af5f2
|
@ -1,20 +1,22 @@
|
||||||
use super::CompositorHandler;
|
use super::{CompositorHandler, Handler as UserHandler};
|
||||||
|
|
||||||
use wayland_server::{Client, EventLoopHandle, GlobalHandler, Init};
|
use wayland_server::{Client, EventLoopHandle, GlobalHandler};
|
||||||
use wayland_server::protocol::{wl_compositor, wl_subcompositor};
|
use wayland_server::protocol::{wl_compositor, wl_subcompositor};
|
||||||
|
|
||||||
impl<U: Default> GlobalHandler<wl_compositor::WlCompositor> for CompositorHandler<U>
|
impl<U: Default, H: UserHandler> GlobalHandler<wl_compositor::WlCompositor> for CompositorHandler<U, H>
|
||||||
where U: Send + Sync + 'static
|
where U: Send + 'static,
|
||||||
|
H: Send + 'static
|
||||||
{
|
{
|
||||||
fn bind(&mut self, evlh: &mut EventLoopHandle, _: &Client, global: wl_compositor::WlCompositor) {
|
fn bind(&mut self, evlh: &mut EventLoopHandle, _: &Client, global: wl_compositor::WlCompositor) {
|
||||||
evlh.register::<_, CompositorHandler<U>>(&global, self.my_id);
|
evlh.register::<_, CompositorHandler<U, H>>(&global, self.my_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U> GlobalHandler<wl_subcompositor::WlSubcompositor> for CompositorHandler<U>
|
impl<U, H> GlobalHandler<wl_subcompositor::WlSubcompositor> for CompositorHandler<U, H>
|
||||||
where U: Send + Sync + 'static
|
where U: Send + 'static,
|
||||||
|
H: Send + 'static
|
||||||
{
|
{
|
||||||
fn bind(&mut self, evlh: &mut EventLoopHandle, _: &Client, global: wl_subcompositor::WlSubcompositor) {
|
fn bind(&mut self, evlh: &mut EventLoopHandle, _: &Client, global: wl_subcompositor::WlSubcompositor) {
|
||||||
evlh.register::<_, CompositorHandler<U>>(&global, self.my_id);
|
evlh.register::<_, CompositorHandler<U, H>>(&global, self.my_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use super::{Rectangle, RectangleKind, SubsurfaceAttributes, Damage, CompositorHandler};
|
use super::{CompositorHandler, Damage, Handler as UserHandler, Rectangle, RectangleKind,
|
||||||
|
SubsurfaceAttributes};
|
||||||
use super::region::RegionData;
|
use super::region::RegionData;
|
||||||
use super::tree::SurfaceData;
|
use super::tree::SurfaceData;
|
||||||
use super::CompositorToken;
|
use wayland_server::{Client, Destroy, EventLoopHandle, Resource};
|
||||||
use wayland_server::{Client, Destroy, EventLoopHandle, Init, Resource};
|
|
||||||
use wayland_server::protocol::{wl_buffer, wl_callback, wl_compositor, wl_output, wl_region,
|
use wayland_server::protocol::{wl_buffer, wl_callback, wl_compositor, wl_output, wl_region,
|
||||||
wl_subcompositor, wl_subsurface, wl_surface};
|
wl_subcompositor, wl_subsurface, wl_surface};
|
||||||
|
|
||||||
|
@ -14,26 +14,31 @@ struct CompositorDestructor<U> {
|
||||||
* wl_compositor
|
* wl_compositor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
impl<U: Default + Send + 'static> wl_compositor::Handler for CompositorHandler<U> {
|
impl<U, H> wl_compositor::Handler for CompositorHandler<U, H>
|
||||||
fn create_surface(&mut self, evqh: &mut EventLoopHandle, _: &Client,
|
where U: Default + Send + 'static,
|
||||||
_: &wl_compositor::WlCompositor, id: wl_surface::WlSurface) {
|
H: UserHandler + Send + 'static
|
||||||
|
{
|
||||||
|
fn create_surface(&mut self, evqh: &mut EventLoopHandle, _: &Client, _: &wl_compositor::WlCompositor,
|
||||||
|
id: wl_surface::WlSurface) {
|
||||||
unsafe { SurfaceData::<U>::init(&id) };
|
unsafe { SurfaceData::<U>::init(&id) };
|
||||||
evqh.register_with_destructor::<_, CompositorHandler<U>, CompositorDestructor<U>>(&id, self.my_id);
|
evqh.register_with_destructor::<_, CompositorHandler<U, H>, CompositorDestructor<U>>(&id, self.my_id);
|
||||||
}
|
}
|
||||||
fn create_region(&mut self, evqh: &mut EventLoopHandle, _: &Client,
|
fn create_region(&mut self, evqh: &mut EventLoopHandle, _: &Client, _: &wl_compositor::WlCompositor,
|
||||||
_: &wl_compositor::WlCompositor, id: wl_region::WlRegion) {
|
id: wl_region::WlRegion) {
|
||||||
unsafe { RegionData::init(&id) };
|
unsafe { RegionData::init(&id) };
|
||||||
evqh.register_with_destructor::<_, CompositorHandler<U>, CompositorDestructor<U>>(&id, self.my_id);
|
evqh.register_with_destructor::<_, CompositorHandler<U, H>, CompositorDestructor<U>>(&id, self.my_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<U: Default + Send + 'static> ::wayland_server::Handler<wl_compositor::WlCompositor>
|
unsafe impl<U, H> ::wayland_server::Handler<wl_compositor::WlCompositor> for CompositorHandler<U, H>
|
||||||
for CompositorHandler<U> {
|
where U: Default + Send + 'static,
|
||||||
|
H: UserHandler + Send + 'static
|
||||||
|
{
|
||||||
unsafe fn message(&mut self, evq: &mut EventLoopHandle, client: &Client,
|
unsafe fn message(&mut self, evq: &mut EventLoopHandle, client: &Client,
|
||||||
resource: &wl_compositor::WlCompositor, opcode: u32,
|
resource: &wl_compositor::WlCompositor, opcode: u32,
|
||||||
args: *const ::wayland_server::sys::wl_argument)
|
args: *const ::wayland_server::sys::wl_argument)
|
||||||
-> Result<(), ()> {
|
-> Result<(), ()> {
|
||||||
<CompositorHandler<U> as ::wayland_server::protocol::wl_compositor::Handler>::__message(self, evq, client, resource, opcode, args)
|
<CompositorHandler<U, H> as ::wayland_server::protocol::wl_compositor::Handler>::__message(self, evq, client, resource, opcode, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +46,7 @@ unsafe impl<U: Default + Send + 'static> ::wayland_server::Handler<wl_compositor
|
||||||
* wl_surface
|
* wl_surface
|
||||||
*/
|
*/
|
||||||
|
|
||||||
impl<U> wl_surface::Handler for CompositorHandler<U> {
|
impl<U, H: UserHandler> wl_surface::Handler for CompositorHandler<U, H> {
|
||||||
fn attach(&mut self, _: &mut EventLoopHandle, _: &Client, surface: &wl_surface::WlSurface,
|
fn attach(&mut self, _: &mut EventLoopHandle, _: &Client, surface: &wl_surface::WlSurface,
|
||||||
buffer: Option<&wl_buffer::WlBuffer>, x: i32, y: i32) {
|
buffer: Option<&wl_buffer::WlBuffer>, x: i32, y: i32) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -52,13 +57,19 @@ impl<U> wl_surface::Handler for CompositorHandler<U> {
|
||||||
fn damage(&mut self, _: &mut EventLoopHandle, _: &Client, surface: &wl_surface::WlSurface, x: i32,
|
fn damage(&mut self, _: &mut EventLoopHandle, _: &Client, surface: &wl_surface::WlSurface, x: i32,
|
||||||
y: i32, width: i32, height: i32) {
|
y: i32, width: i32, height: i32) {
|
||||||
unsafe {
|
unsafe {
|
||||||
SurfaceData::<U>::with_data(surface,
|
SurfaceData::<U>::with_data(surface, |d| {
|
||||||
|d| d.damage = Damage::Surface(Rectangle { x, y, width, height }));
|
d.damage = Damage::Surface(Rectangle {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn frame(&mut self, _: &mut EventLoopHandle, _: &Client, surface: &wl_surface::WlSurface,
|
fn frame(&mut self, evlh: &mut EventLoopHandle, client: &Client, surface: &wl_surface::WlSurface,
|
||||||
callback: wl_callback::WlCallback) {
|
callback: wl_callback::WlCallback) {
|
||||||
unimplemented!()
|
UserHandler::frame(&mut self.handler, evlh, client, surface, callback);
|
||||||
}
|
}
|
||||||
fn set_opaque_region(&mut self, _: &mut EventLoopHandle, _: &Client, surface: &wl_surface::WlSurface,
|
fn set_opaque_region(&mut self, _: &mut EventLoopHandle, _: &Client, surface: &wl_surface::WlSurface,
|
||||||
region: Option<&wl_region::WlRegion>) {
|
region: Option<&wl_region::WlRegion>) {
|
||||||
|
@ -74,8 +85,8 @@ impl<U> wl_surface::Handler for CompositorHandler<U> {
|
||||||
SurfaceData::<U>::with_data(surface, |d| d.input_region = attributes);
|
SurfaceData::<U>::with_data(surface, |d| d.input_region = attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn commit(&mut self, _: &mut EventLoopHandle, _: &Client, surface: &wl_surface::WlSurface) {
|
fn commit(&mut self, evlh: &mut EventLoopHandle, client: &Client, surface: &wl_surface::WlSurface) {
|
||||||
unimplemented!()
|
UserHandler::commit(&mut self.handler, evlh, client, surface);
|
||||||
}
|
}
|
||||||
fn set_buffer_transform(&mut self, _: &mut EventLoopHandle, _: &Client,
|
fn set_buffer_transform(&mut self, _: &mut EventLoopHandle, _: &Client,
|
||||||
surface: &wl_surface::WlSurface, transform: wl_output::Transform) {
|
surface: &wl_surface::WlSurface, transform: wl_output::Transform) {
|
||||||
|
@ -92,18 +103,24 @@ impl<U> wl_surface::Handler for CompositorHandler<U> {
|
||||||
fn damage_buffer(&mut self, _: &mut EventLoopHandle, _: &Client, surface: &wl_surface::WlSurface,
|
fn damage_buffer(&mut self, _: &mut EventLoopHandle, _: &Client, surface: &wl_surface::WlSurface,
|
||||||
x: i32, y: i32, width: i32, height: i32) {
|
x: i32, y: i32, width: i32, height: i32) {
|
||||||
unsafe {
|
unsafe {
|
||||||
SurfaceData::<U>::with_data(surface,
|
SurfaceData::<U>::with_data(surface, |d| {
|
||||||
|d| d.damage = Damage::Buffer(Rectangle { x, y, width, height }));
|
d.damage = Damage::Buffer(Rectangle {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<U> ::wayland_server::Handler<wl_surface::WlSurface> for CompositorHandler<U> {
|
unsafe impl<U, H: UserHandler> ::wayland_server::Handler<wl_surface::WlSurface> for CompositorHandler<U, H> {
|
||||||
unsafe fn message(&mut self, evq: &mut EventLoopHandle, client: &Client,
|
unsafe fn message(&mut self, evq: &mut EventLoopHandle, client: &Client,
|
||||||
resource: &wl_surface::WlSurface, opcode: u32,
|
resource: &wl_surface::WlSurface, opcode: u32,
|
||||||
args: *const ::wayland_server::sys::wl_argument)
|
args: *const ::wayland_server::sys::wl_argument)
|
||||||
-> Result<(), ()> {
|
-> Result<(), ()> {
|
||||||
<CompositorHandler<U> as ::wayland_server::protocol::wl_surface::Handler>::__message(self, evq, client, resource, opcode, args)
|
<CompositorHandler<U, H> as ::wayland_server::protocol::wl_surface::Handler>::__message(self, evq, client, resource, opcode, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,11 +134,12 @@ impl<U> Destroy<wl_surface::WlSurface> for CompositorDestructor<U> {
|
||||||
* wl_region
|
* wl_region
|
||||||
*/
|
*/
|
||||||
|
|
||||||
impl<U> wl_region::Handler for CompositorHandler<U> {
|
impl<U, H> wl_region::Handler for CompositorHandler<U, H> {
|
||||||
fn add(&mut self, _: &mut EventLoopHandle, _: &Client, region: &wl_region::WlRegion, x: i32, y: i32,
|
fn add(&mut self, _: &mut EventLoopHandle, _: &Client, region: &wl_region::WlRegion, x: i32, y: i32,
|
||||||
width: i32, height: i32) {
|
width: i32, height: i32) {
|
||||||
unsafe {
|
unsafe {
|
||||||
RegionData::add_rectangle(region, RectangleKind::Add,
|
RegionData::add_rectangle(region,
|
||||||
|
RectangleKind::Add,
|
||||||
Rectangle {
|
Rectangle {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
|
@ -133,7 +151,8 @@ impl<U> wl_region::Handler for CompositorHandler<U> {
|
||||||
fn subtract(&mut self, _: &mut EventLoopHandle, _: &Client, region: &wl_region::WlRegion, x: i32,
|
fn subtract(&mut self, _: &mut EventLoopHandle, _: &Client, region: &wl_region::WlRegion, x: i32,
|
||||||
y: i32, width: i32, height: i32) {
|
y: i32, width: i32, height: i32) {
|
||||||
unsafe {
|
unsafe {
|
||||||
RegionData::add_rectangle(region, RectangleKind::Subtract,
|
RegionData::add_rectangle(region,
|
||||||
|
RectangleKind::Subtract,
|
||||||
Rectangle {
|
Rectangle {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
|
@ -144,12 +163,12 @@ impl<U> wl_region::Handler for CompositorHandler<U> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<U> ::wayland_server::Handler<wl_region::WlRegion> for CompositorHandler<U> {
|
unsafe impl<U, H> ::wayland_server::Handler<wl_region::WlRegion> for CompositorHandler<U, H> {
|
||||||
unsafe fn message(&mut self, evq: &mut EventLoopHandle, client: &Client,
|
unsafe fn message(&mut self, evq: &mut EventLoopHandle, client: &Client,
|
||||||
resource: &wl_region::WlRegion, opcode: u32,
|
resource: &wl_region::WlRegion, opcode: u32,
|
||||||
args: *const ::wayland_server::sys::wl_argument)
|
args: *const ::wayland_server::sys::wl_argument)
|
||||||
-> Result<(), ()> {
|
-> Result<(), ()> {
|
||||||
<CompositorHandler<U> as ::wayland_server::protocol::wl_region::Handler>::__message(self, evq, client, resource, opcode, args)
|
<CompositorHandler<U, H> as ::wayland_server::protocol::wl_region::Handler>::__message(self, evq, client, resource, opcode, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +182,10 @@ impl<U> Destroy<wl_region::WlRegion> for CompositorDestructor<U> {
|
||||||
* wl_subcompositor
|
* wl_subcompositor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
impl<U: Send + 'static> wl_subcompositor::Handler for CompositorHandler<U> {
|
impl<U, H> wl_subcompositor::Handler for CompositorHandler<U, H>
|
||||||
|
where U: Send + 'static,
|
||||||
|
H: Send + 'static
|
||||||
|
{
|
||||||
fn get_subsurface(&mut self, evqh: &mut EventLoopHandle, _: &Client,
|
fn get_subsurface(&mut self, evqh: &mut EventLoopHandle, _: &Client,
|
||||||
resource: &wl_subcompositor::WlSubcompositor, id: wl_subsurface::WlSubsurface,
|
resource: &wl_subcompositor::WlSubcompositor, id: wl_subsurface::WlSubsurface,
|
||||||
surface: &wl_surface::WlSurface, parent: &wl_surface::WlSurface) {
|
surface: &wl_surface::WlSurface, parent: &wl_surface::WlSurface) {
|
||||||
|
@ -176,17 +198,19 @@ impl<U: Send + 'static> wl_subcompositor::Handler for CompositorHandler<U> {
|
||||||
SurfaceData::<U>::with_data(surface,
|
SurfaceData::<U>::with_data(surface,
|
||||||
|d| d.subsurface_attributes = Some(Default::default()));
|
|d| d.subsurface_attributes = Some(Default::default()));
|
||||||
}
|
}
|
||||||
evqh.register_with_destructor::<_, CompositorHandler<U>, CompositorDestructor<U>>(&id, self.my_id);
|
evqh.register_with_destructor::<_, CompositorHandler<U, H>, CompositorDestructor<U>>(&id, self.my_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<U: Send + 'static> ::wayland_server::Handler<wl_subcompositor::WlSubcompositor>
|
unsafe impl<U, H> ::wayland_server::Handler<wl_subcompositor::WlSubcompositor> for CompositorHandler<U, H>
|
||||||
for CompositorHandler<U> {
|
where U: Send + 'static,
|
||||||
|
H: Send + 'static
|
||||||
|
{
|
||||||
unsafe fn message(&mut self, evq: &mut EventLoopHandle, client: &Client,
|
unsafe fn message(&mut self, evq: &mut EventLoopHandle, client: &Client,
|
||||||
resource: &wl_subcompositor::WlSubcompositor, opcode: u32,
|
resource: &wl_subcompositor::WlSubcompositor, opcode: u32,
|
||||||
args: *const ::wayland_server::sys::wl_argument)
|
args: *const ::wayland_server::sys::wl_argument)
|
||||||
-> Result<(), ()> {
|
-> Result<(), ()> {
|
||||||
<CompositorHandler<U> as ::wayland_server::protocol::wl_subcompositor::Handler>::__message(self, evq, client, resource, opcode, args)
|
<CompositorHandler<U, H> as ::wayland_server::protocol::wl_subcompositor::Handler>::__message(self, evq, client, resource, opcode, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,9 +226,9 @@ unsafe fn with_subsurface_attributes<U, F>(subsurface: &wl_subsurface::WlSubsurf
|
||||||
SurfaceData::<U>::with_data(surface, |d| f(d.subsurface_attributes.as_mut().unwrap()));
|
SurfaceData::<U>::with_data(surface, |d| f(d.subsurface_attributes.as_mut().unwrap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U> wl_subsurface::Handler for CompositorHandler<U> {
|
impl<U, H> wl_subsurface::Handler for CompositorHandler<U, H> {
|
||||||
fn set_position(&mut self, _: &mut EventLoopHandle, _: &Client,
|
fn set_position(&mut self, _: &mut EventLoopHandle, _: &Client, resource: &wl_subsurface::WlSubsurface,
|
||||||
resource: &wl_subsurface::WlSubsurface, x: i32, y: i32) {
|
x: i32, y: i32) {
|
||||||
unsafe {
|
unsafe {
|
||||||
with_subsurface_attributes::<U, _>(resource, |attrs| {
|
with_subsurface_attributes::<U, _>(resource, |attrs| {
|
||||||
attrs.x = x;
|
attrs.x = x;
|
||||||
|
@ -212,34 +236,32 @@ impl<U> wl_subsurface::Handler for CompositorHandler<U> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn place_above(&mut self, _: &mut EventLoopHandle, _: &Client,
|
fn place_above(&mut self, _: &mut EventLoopHandle, _: &Client, resource: &wl_subsurface::WlSubsurface,
|
||||||
resource: &wl_subsurface::WlSubsurface, sibling: &wl_surface::WlSurface) {
|
sibling: &wl_surface::WlSurface) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
fn place_below(&mut self, _: &mut EventLoopHandle, _: &Client,
|
fn place_below(&mut self, _: &mut EventLoopHandle, _: &Client, resource: &wl_subsurface::WlSubsurface,
|
||||||
resource: &wl_subsurface::WlSubsurface, sibling: &wl_surface::WlSurface) {
|
sibling: &wl_surface::WlSurface) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
fn set_sync(&mut self, _: &mut EventLoopHandle, _: &Client,
|
fn set_sync(&mut self, _: &mut EventLoopHandle, _: &Client, resource: &wl_subsurface::WlSubsurface) {
|
||||||
resource: &wl_subsurface::WlSubsurface) {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
with_subsurface_attributes::<U, _>(resource, |attrs| { attrs.sync = true; });
|
with_subsurface_attributes::<U, _>(resource, |attrs| { attrs.sync = true; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn set_desync(&mut self, _: &mut EventLoopHandle, _: &Client,
|
fn set_desync(&mut self, _: &mut EventLoopHandle, _: &Client, resource: &wl_subsurface::WlSubsurface) {
|
||||||
resource: &wl_subsurface::WlSubsurface) {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
with_subsurface_attributes::<U, _>(resource, |attrs| { attrs.sync = false; });
|
with_subsurface_attributes::<U, _>(resource, |attrs| { attrs.sync = false; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<U> ::wayland_server::Handler<wl_subsurface::WlSubsurface> for CompositorHandler<U> {
|
unsafe impl<U, H> ::wayland_server::Handler<wl_subsurface::WlSubsurface> for CompositorHandler<U, H> {
|
||||||
unsafe fn message(&mut self, evq: &mut EventLoopHandle, client: &Client,
|
unsafe fn message(&mut self, evq: &mut EventLoopHandle, client: &Client,
|
||||||
resource: &wl_subsurface::WlSubsurface, opcode: u32,
|
resource: &wl_subsurface::WlSubsurface, opcode: u32,
|
||||||
args: *const ::wayland_server::sys::wl_argument)
|
args: *const ::wayland_server::sys::wl_argument)
|
||||||
-> Result<(), ()> {
|
-> Result<(), ()> {
|
||||||
<CompositorHandler<U> as ::wayland_server::protocol::wl_subsurface::Handler>::__message(self, evq, client, resource, opcode, args)
|
<CompositorHandler<U, H> as ::wayland_server::protocol::wl_subsurface::Handler>::__message(self, evq, client, resource, opcode, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,9 @@ mod region;
|
||||||
|
|
||||||
pub use self::tree::RoleStatus;
|
pub use self::tree::RoleStatus;
|
||||||
use self::tree::SurfaceData;
|
use self::tree::SurfaceData;
|
||||||
|
use wayland_server::{Client, EventLoopHandle, Init, resource_is_registered};
|
||||||
|
|
||||||
use wayland_server::protocol::{wl_buffer, wl_output, wl_surface};
|
use wayland_server::protocol::{wl_buffer, wl_callback, wl_output, wl_surface};
|
||||||
use wayland_server::{EventLoopHandle, resource_is_registered, Init};
|
|
||||||
|
|
||||||
/// Description of which part of a surface
|
/// Description of which part of a surface
|
||||||
/// should be considered damaged and needs to be redrawn
|
/// should be considered damaged and needs to be redrawn
|
||||||
|
@ -19,7 +19,7 @@ pub enum Damage {
|
||||||
/// A rectangle containing the smaazed zone, in buffer coordinates
|
/// A rectangle containing the smaazed zone, in buffer coordinates
|
||||||
///
|
///
|
||||||
/// Note: Buffer scaling must be taken into consideration
|
/// Note: Buffer scaling must be taken into consideration
|
||||||
Buffer(Rectangle)
|
Buffer(Rectangle),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Data associated with a surface, aggreged by the handlers
|
/// Data associated with a surface, aggreged by the handlers
|
||||||
|
@ -166,12 +166,13 @@ impl Default for RegionAttributes {
|
||||||
/// access data associated with the wl_surface and wl_region managed
|
/// access data associated with the wl_surface and wl_region managed
|
||||||
/// by the `CompositorGlobal` that provided it.
|
/// by the `CompositorGlobal` that provided it.
|
||||||
#[derive(Copy,Clone)]
|
#[derive(Copy,Clone)]
|
||||||
pub struct CompositorToken<U> {
|
pub struct CompositorToken<U, H> {
|
||||||
hid: usize,
|
hid: usize,
|
||||||
_data: ::std::marker::PhantomData<*mut U>,
|
_data: ::std::marker::PhantomData<*mut U>,
|
||||||
|
_handler: ::std::marker::PhantomData<*mut H>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: Send + 'static> CompositorToken<U> {
|
impl<U: Send + 'static, H: Handler + Send + 'static> CompositorToken<U, H> {
|
||||||
/// Access the data of a surface
|
/// Access the data of a surface
|
||||||
///
|
///
|
||||||
/// The closure will be called with the contents of the data associated with this surface.
|
/// The closure will be called with the contents of the data associated with this surface.
|
||||||
|
@ -181,7 +182,7 @@ impl<U: Send + 'static> CompositorToken<U> {
|
||||||
pub fn with_surface_data<F>(&self, surface: &wl_surface::WlSurface, f: F)
|
pub fn with_surface_data<F>(&self, surface: &wl_surface::WlSurface, f: F)
|
||||||
where F: FnOnce(&mut SurfaceAttributes<U>)
|
where F: FnOnce(&mut SurfaceAttributes<U>)
|
||||||
{
|
{
|
||||||
assert!(resource_is_registered::<_, CompositorHandler<U>>(surface, self.hid),
|
assert!(resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
"Accessing the data of foreign surfaces is not supported.");
|
||||||
unsafe {
|
unsafe {
|
||||||
SurfaceData::<U>::with_data(surface, f);
|
SurfaceData::<U>::with_data(surface, f);
|
||||||
|
@ -198,7 +199,7 @@ impl<U: Send + 'static> CompositorToken<U> {
|
||||||
pub fn with_surface_tree<F>(&self, surface: &wl_surface::WlSurface, f: F) -> Result<(), ()>
|
pub fn with_surface_tree<F>(&self, surface: &wl_surface::WlSurface, f: F) -> Result<(), ()>
|
||||||
where F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>) -> bool
|
where F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>) -> bool
|
||||||
{
|
{
|
||||||
assert!(resource_is_registered::<_, CompositorHandler<U>>(surface, self.hid),
|
assert!(resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
"Accessing the data of foreign surfaces is not supported.");
|
||||||
unsafe {
|
unsafe {
|
||||||
SurfaceData::<U>::map_tree(surface, f);
|
SurfaceData::<U>::map_tree(surface, f);
|
||||||
|
@ -213,23 +214,19 @@ impl<U: Send + 'static> CompositorToken<U> {
|
||||||
/// If the surface is not managed by the CompositorGlobal that provided this token, this
|
/// If the surface is not managed by the CompositorGlobal that provided this token, this
|
||||||
/// will panic (having more than one compositor is not supported).
|
/// will panic (having more than one compositor is not supported).
|
||||||
pub fn get_parent(&self, surface: &wl_surface::WlSurface) -> Option<wl_surface::WlSurface> {
|
pub fn get_parent(&self, surface: &wl_surface::WlSurface) -> Option<wl_surface::WlSurface> {
|
||||||
assert!(resource_is_registered::<_, CompositorHandler<U>>(surface, self.hid),
|
assert!(resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
"Accessing the data of foreign surfaces is not supported.");
|
||||||
unsafe {
|
unsafe { SurfaceData::<U>::get_parent(surface) }
|
||||||
SurfaceData::<U>::get_parent(surface)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the role status this surface
|
/// Retrieve the role status this surface
|
||||||
///
|
///
|
||||||
/// If the surface is not managed by the CompositorGlobal that provided this token, this
|
/// If the surface is not managed by the CompositorGlobal that provided this token, this
|
||||||
/// will panic (having more than one compositor is not supported).
|
/// will panic (having more than one compositor is not supported).
|
||||||
pub fn role_status(&self, surface: &wl_surface::WlSurface) -> RoleStatus {
|
pub fn role_status(&self, surface: &wl_surface::WlSurface) -> RoleStatus {
|
||||||
assert!(resource_is_registered::<_, CompositorHandler<U>>(surface, self.hid),
|
assert!(resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
"Accessing the data of foreign surfaces is not supported.");
|
||||||
unsafe {
|
unsafe { SurfaceData::<U>::role_status(surface) }
|
||||||
SurfaceData::<U>::role_status(surface)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register that this surface has a role
|
/// Register that this surface has a role
|
||||||
|
@ -241,12 +238,10 @@ impl<U: Send + 'static> CompositorToken<U> {
|
||||||
///
|
///
|
||||||
/// If the surface is not managed by the CompositorGlobal that provided this token, this
|
/// If the surface is not managed by the CompositorGlobal that provided this token, this
|
||||||
/// will panic (having more than one compositor is not supported).
|
/// will panic (having more than one compositor is not supported).
|
||||||
pub fn give_role(&self, surface: &wl_surface::WlSurface) -> Result<(),()> {
|
pub fn give_role(&self, surface: &wl_surface::WlSurface) -> Result<(), ()> {
|
||||||
assert!(resource_is_registered::<_, CompositorHandler<U>>(surface, self.hid),
|
assert!(resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
"Accessing the data of foreign surfaces is not supported.");
|
||||||
unsafe {
|
unsafe { SurfaceData::<U>::give_role(surface) }
|
||||||
SurfaceData::<U>::give_role(surface)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register that this surface has no role
|
/// Register that this surface has no role
|
||||||
|
@ -257,44 +252,67 @@ impl<U: Send + 'static> CompositorToken<U> {
|
||||||
///
|
///
|
||||||
/// If the surface is not managed by the CompositorGlobal that provided this token, this
|
/// If the surface is not managed by the CompositorGlobal that provided this token, this
|
||||||
/// will panic (having more than one compositor is not supported).
|
/// will panic (having more than one compositor is not supported).
|
||||||
pub fn remove_role(&self, surface: &wl_surface::WlSurface) -> Result<(),()> {
|
pub fn remove_role(&self, surface: &wl_surface::WlSurface) -> Result<(), ()> {
|
||||||
assert!(resource_is_registered::<_, CompositorHandler<U>>(surface, self.hid),
|
assert!(resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
"Accessing the data of foreign surfaces is not supported.");
|
||||||
unsafe {
|
unsafe { SurfaceData::<U>::remove_role(surface) }
|
||||||
SurfaceData::<U>::remove_role(surface)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CompositorHandler<U> {
|
pub struct CompositorHandler<U, H> {
|
||||||
my_id: usize,
|
my_id: usize,
|
||||||
log: ::slog::Logger,
|
log: ::slog::Logger,
|
||||||
|
handler: H,
|
||||||
_data: ::std::marker::PhantomData<U>,
|
_data: ::std::marker::PhantomData<U>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U> Init for CompositorHandler<U> {
|
impl<U, H> Init for CompositorHandler<U, H> {
|
||||||
fn init(&mut self, _evqh: &mut EventLoopHandle, index: usize) {
|
fn init(&mut self, _evqh: &mut EventLoopHandle, index: usize) {
|
||||||
self.my_id = index;
|
self.my_id = index;
|
||||||
debug!(self.log, "Init finished")
|
debug!(self.log, "Init finished")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U> CompositorHandler<U> {
|
impl<U, H> CompositorHandler<U, H> {
|
||||||
pub fn new<L>(logger: L) -> CompositorHandler<U>
|
/// Create a new CompositorHandler
|
||||||
|
pub fn new<L>(handler: H, logger: L) -> CompositorHandler<U, H>
|
||||||
where L: Into<Option<::slog::Logger>>
|
where L: Into<Option<::slog::Logger>>
|
||||||
{
|
{
|
||||||
let log = ::slog_or_stdlog(logger);
|
let log = ::slog_or_stdlog(logger);
|
||||||
CompositorHandler {
|
CompositorHandler {
|
||||||
my_id: ::std::usize::MAX,
|
my_id: ::std::usize::MAX,
|
||||||
log: log.new(o!("smithay_module" => "compositor_handler")),
|
log: log.new(o!("smithay_module" => "compositor_handler")),
|
||||||
|
handler: handler,
|
||||||
_data: ::std::marker::PhantomData,
|
_data: ::std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_token(&self) -> CompositorToken<U> {
|
/// Create a token to access the data associated to the objects managed by this handler.
|
||||||
|
pub fn get_token(&self) -> CompositorToken<U, H> {
|
||||||
|
assert!(self.my_id != ::std::usize::MAX,
|
||||||
|
"CompositorHandler is not initialized yet.");
|
||||||
CompositorToken {
|
CompositorToken {
|
||||||
hid: self.my_id,
|
hid: self.my_id,
|
||||||
_data: ::std::marker::PhantomData,
|
_data: ::std::marker::PhantomData,
|
||||||
|
_handler: ::std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Access the underlying sub-handler
|
||||||
|
pub fn get_handler(&mut self) -> &mut H {
|
||||||
|
&mut self.handler
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sub-handler trait for surface event handling
|
||||||
|
///
|
||||||
|
/// The global provided by Smithay cannot process these events for you, so they
|
||||||
|
/// are forwarded directly to a handler implementing this trait that you must provide
|
||||||
|
/// at creation of the `CompositorHandler`.
|
||||||
|
pub trait Handler {
|
||||||
|
/// See `wayland_server::protocol::wl_surface::Handler::commit`
|
||||||
|
fn commit(&mut self, evlh: &mut EventLoopHandle, client: &Client, surface: &wl_surface::WlSurface);
|
||||||
|
/// See `wayland_server::protocol::wl_surface::Handler::frame`
|
||||||
|
fn frame(&mut self, evlh: &mut EventLoopHandle, client: &Client, surface: &wl_surface::WlSurface,
|
||||||
|
callback: wl_callback::WlCallback);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{Rectangle, RegionAttributes, RectangleKind};
|
use super::{Rectangle, RectangleKind, RegionAttributes};
|
||||||
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use wayland_server::Resource;
|
use wayland_server::Resource;
|
||||||
|
|
Loading…
Reference in New Issue