cargo fmt
This commit is contained in:
parent
9d2f03943e
commit
4f6a852652
|
@ -21,23 +21,27 @@ impl<'a, F: glium::backend::Facade + 'a> GliumDrawer<'a, F> {
|
||||||
pub fn new(display: &'a F) -> GliumDrawer<'a, F> {
|
pub fn new(display: &'a F) -> GliumDrawer<'a, F> {
|
||||||
|
|
||||||
// building the vertex buffer, which contains all the vertices that we will draw
|
// building the vertex buffer, which contains all the vertices that we will draw
|
||||||
let vertex_buffer = glium::VertexBuffer::new(display,
|
let vertex_buffer = glium::VertexBuffer::new(
|
||||||
&[Vertex {
|
display,
|
||||||
position: [0.0, 0.0],
|
&[
|
||||||
tex_coords: [0.0, 0.0],
|
Vertex {
|
||||||
},
|
position: [0.0, 0.0],
|
||||||
Vertex {
|
tex_coords: [0.0, 0.0],
|
||||||
position: [0.0, 1.0],
|
},
|
||||||
tex_coords: [0.0, 1.0],
|
Vertex {
|
||||||
},
|
position: [0.0, 1.0],
|
||||||
Vertex {
|
tex_coords: [0.0, 1.0],
|
||||||
position: [1.0, 1.0],
|
},
|
||||||
tex_coords: [1.0, 1.0],
|
Vertex {
|
||||||
},
|
position: [1.0, 1.0],
|
||||||
Vertex {
|
tex_coords: [1.0, 1.0],
|
||||||
position: [1.0, 0.0],
|
},
|
||||||
tex_coords: [1.0, 0.0],
|
Vertex {
|
||||||
}]).unwrap();
|
position: [1.0, 0.0],
|
||||||
|
tex_coords: [1.0, 0.0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
// building the index buffer
|
// building the index buffer
|
||||||
let index_buffer =
|
let index_buffer =
|
||||||
|
@ -110,11 +114,13 @@ impl<'a, F: glium::backend::Facade + 'a> GliumDrawer<'a, F> {
|
||||||
};
|
};
|
||||||
|
|
||||||
target
|
target
|
||||||
.draw(&self.vertex_buffer,
|
.draw(
|
||||||
&self.index_buffer,
|
&self.vertex_buffer,
|
||||||
&self.program,
|
&self.index_buffer,
|
||||||
&uniforms,
|
&self.program,
|
||||||
&Default::default())
|
&uniforms,
|
||||||
|
&Default::default(),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,17 +49,22 @@ impl<U, H> GlobalHandler<wl_shell::WlShell> for WlShellStubHandler<U, H>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U, H> wl_shell::Handler for WlShellStubHandler<U, H>
|
impl<U, H> wl_shell::Handler for WlShellStubHandler<U, H>
|
||||||
where U: Send + 'static,
|
where
|
||||||
H: CompositorHandler<U> + Send + 'static
|
U: Send + 'static,
|
||||||
|
H: CompositorHandler<U> + Send + 'static,
|
||||||
{
|
{
|
||||||
fn get_shell_surface(&mut self, evqh: &mut EventLoopHandle, client: &Client,
|
fn get_shell_surface(&mut self, evqh: &mut EventLoopHandle, client: &Client,
|
||||||
resource: &wl_shell::WlShell, id: wl_shell_surface::WlShellSurface,
|
resource: &wl_shell::WlShell, id: wl_shell_surface::WlShellSurface,
|
||||||
surface: &wl_surface::WlSurface) {
|
surface: &wl_surface::WlSurface) {
|
||||||
let surface = surface.clone().expect("WlShellStubHandler can only manage surfaces managed by Smithay's CompositorHandler.");
|
let surface = surface.clone().expect(
|
||||||
|
"WlShellStubHandler can only manage surfaces managed by Smithay's CompositorHandler.",
|
||||||
|
);
|
||||||
if self.token.give_role(&surface).is_err() {
|
if self.token.give_role(&surface).is_err() {
|
||||||
// This surface already has a role, and thus cannot be given one!
|
// This surface already has a role, and thus cannot be given one!
|
||||||
resource.post_error(wl_shell::Error::Role as u32,
|
resource.post_error(
|
||||||
"Surface already has a role.".into());
|
wl_shell::Error::Role as u32,
|
||||||
|
"Surface already has a role.".into(),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
evqh.register::<_, Self>(&id, self.my_id.unwrap());
|
evqh.register::<_, Self>(&id, self.my_id.unwrap());
|
||||||
|
@ -70,8 +75,9 @@ impl<U, H> wl_shell::Handler for WlShellStubHandler<U, H>
|
||||||
server_declare_handler!(WlShellStubHandler<U: [Send], H: [CompositorHandler<U>, Send]>, wl_shell::Handler, wl_shell::WlShell);
|
server_declare_handler!(WlShellStubHandler<U: [Send], H: [CompositorHandler<U>, Send]>, wl_shell::Handler, wl_shell::WlShell);
|
||||||
|
|
||||||
impl<U, H> wl_shell_surface::Handler for WlShellStubHandler<U, H>
|
impl<U, H> wl_shell_surface::Handler for WlShellStubHandler<U, H>
|
||||||
where U: Send + 'static,
|
where
|
||||||
H: CompositorHandler<U> + Send + 'static
|
U: Send + 'static,
|
||||||
|
H: CompositorHandler<U> + Send + 'static,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,10 +48,12 @@ impl compositor::Handler<SurfaceData> for SurfaceHandler {
|
||||||
let height = data.height as usize;
|
let height = data.height as usize;
|
||||||
let mut new_vec = Vec::with_capacity(width * height * 4);
|
let mut new_vec = Vec::with_capacity(width * height * 4);
|
||||||
for i in 0..height {
|
for i in 0..height {
|
||||||
new_vec.extend(&slice[(offset + i * stride)..(offset + i * stride + width * 4)]);
|
new_vec.extend(
|
||||||
|
&slice[(offset + i * stride)..(offset + i * stride + width * 4)],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
attributes.user_data.buffer = Some((new_vec,
|
attributes.user_data.buffer =
|
||||||
(data.width as u32, data.height as u32)));
|
Some((new_vec, (data.width as u32, data.height as u32)));
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,8 +69,10 @@ impl compositor::Handler<SurfaceData> for SurfaceHandler {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// A logger facility, here we use the terminal for this example
|
// A logger facility, here we use the terminal for this example
|
||||||
let log = Logger::root(slog_async::Async::default(slog_term::term_full().fuse()).fuse(),
|
let log = Logger::root(
|
||||||
o!());
|
slog_async::Async::default(slog_term::term_full().fuse()).fuse(),
|
||||||
|
o!(),
|
||||||
|
);
|
||||||
|
|
||||||
// Initialize a simple backend for testing
|
// Initialize a simple backend for testing
|
||||||
let (renderer, mut input) = winit::init(log.clone()).unwrap();
|
let (renderer, mut input) = winit::init(log.clone()).unwrap();
|
||||||
|
@ -93,14 +97,16 @@ fn main() {
|
||||||
/*
|
/*
|
||||||
* Initialize the compositor global
|
* Initialize the compositor global
|
||||||
*/
|
*/
|
||||||
let compositor_handler_id =
|
let compositor_handler_id = event_loop.add_handler_with_init(CompositorHandler::<SurfaceData, _>::new(
|
||||||
event_loop.add_handler_with_init(CompositorHandler::<SurfaceData, _>::new(SurfaceHandler {
|
SurfaceHandler { shm_token: shm_token.clone() },
|
||||||
shm_token: shm_token
|
log.clone(),
|
||||||
.clone(),
|
));
|
||||||
},
|
|
||||||
log.clone()));
|
|
||||||
// register it to handle wl_compositor and wl_subcompositor
|
// register it to handle wl_compositor and wl_subcompositor
|
||||||
event_loop.register_global::<wl_compositor::WlCompositor, CompositorHandler<SurfaceData,SurfaceHandler>>(compositor_handler_id, 4);
|
event_loop
|
||||||
|
.register_global::<wl_compositor::WlCompositor, CompositorHandler<SurfaceData, SurfaceHandler>>(
|
||||||
|
compositor_handler_id,
|
||||||
|
4,
|
||||||
|
);
|
||||||
event_loop.register_global::<wl_subcompositor::WlSubcompositor, CompositorHandler<SurfaceData,SurfaceHandler>>(compositor_handler_id, 1);
|
event_loop.register_global::<wl_subcompositor::WlSubcompositor, CompositorHandler<SurfaceData,SurfaceHandler>>(compositor_handler_id, 1);
|
||||||
// retrieve the tokens
|
// retrieve the tokens
|
||||||
let compositor_token = {
|
let compositor_token = {
|
||||||
|
@ -113,10 +119,12 @@ fn main() {
|
||||||
/*
|
/*
|
||||||
* Initialize the shell stub global
|
* Initialize the shell stub global
|
||||||
*/
|
*/
|
||||||
let shell_handler_id = event_loop
|
let shell_handler_id =
|
||||||
.add_handler_with_init(WlShellStubHandler::new(compositor_token.clone()));
|
event_loop.add_handler_with_init(WlShellStubHandler::new(compositor_token.clone()));
|
||||||
event_loop.register_global::<wl_shell::WlShell, WlShellStubHandler<SurfaceData, SurfaceHandler>>(shell_handler_id,
|
event_loop.register_global::<wl_shell::WlShell, WlShellStubHandler<SurfaceData, SurfaceHandler>>(
|
||||||
1);
|
shell_handler_id,
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize glium
|
* Initialize glium
|
||||||
|
@ -143,27 +151,30 @@ fn main() {
|
||||||
for &(_, ref surface) in
|
for &(_, ref surface) in
|
||||||
state
|
state
|
||||||
.get_handler::<WlShellStubHandler<SurfaceData, SurfaceHandler>>(shell_handler_id)
|
.get_handler::<WlShellStubHandler<SurfaceData, SurfaceHandler>>(shell_handler_id)
|
||||||
.surfaces() {
|
.surfaces()
|
||||||
|
{
|
||||||
if surface.status() != Liveness::Alive {
|
if surface.status() != Liveness::Alive {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// this surface is a root of a subsurface tree that needs to be drawn
|
// this surface is a root of a subsurface tree that needs to be drawn
|
||||||
compositor_token.with_surface_tree(surface, (100, 100), |surface,
|
compositor_token.with_surface_tree(
|
||||||
attributes,
|
surface,
|
||||||
&(mut x, mut y)| {
|
(100, 100),
|
||||||
if let Some((ref contents, (w, h))) = attributes.user_data.buffer {
|
|surface, attributes, &(mut x, mut y)| {
|
||||||
// there is actually something to draw !
|
if let Some((ref contents, (w, h))) = attributes.user_data.buffer {
|
||||||
if let Some(ref subdata) = attributes.subsurface_attributes {
|
// there is actually something to draw !
|
||||||
x += subdata.x;
|
if let Some(ref subdata) = attributes.subsurface_attributes {
|
||||||
y += subdata.y;
|
x += subdata.x;
|
||||||
|
y += subdata.y;
|
||||||
|
}
|
||||||
|
drawer.draw(&mut frame, contents, (w, h), (x, y), screen_dimensions);
|
||||||
|
TraversalAction::DoChildren((x, y))
|
||||||
|
} else {
|
||||||
|
// we are not display, so our children are neither
|
||||||
|
TraversalAction::SkipChildren
|
||||||
}
|
}
|
||||||
drawer.draw(&mut frame, contents, (w, h), (x, y), screen_dimensions);
|
},
|
||||||
TraversalAction::DoChildren((x, y))
|
);
|
||||||
} else {
|
|
||||||
// we are not display, so our children are neither
|
|
||||||
TraversalAction::SkipChildren
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
frame.finish().unwrap();
|
frame.finish().unwrap();
|
||||||
|
|
|
@ -14,8 +14,9 @@ impl<U: Default, H: UserHandler<U>> GlobalHandler<wl_compositor::WlCompositor> f
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U, H> GlobalHandler<wl_subcompositor::WlSubcompositor> for CompositorHandler<U, H>
|
impl<U, H> GlobalHandler<wl_subcompositor::WlSubcompositor> for CompositorHandler<U, H>
|
||||||
where U: Send + 'static,
|
where
|
||||||
H: Send + 'static
|
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) {
|
||||||
debug!(self.log, "New subcompositor global binded.");
|
debug!(self.log, "New subcompositor global binded.");
|
||||||
|
|
|
@ -15,8 +15,9 @@ struct CompositorDestructor<U> {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
impl<U, H> wl_compositor::Handler for CompositorHandler<U, H>
|
impl<U, H> wl_compositor::Handler for CompositorHandler<U, H>
|
||||||
where U: Default + Send + 'static,
|
where
|
||||||
H: UserHandler<U> + Send + 'static
|
U: Default + Send + 'static,
|
||||||
|
H: UserHandler<U> + Send + 'static,
|
||||||
{
|
{
|
||||||
fn create_surface(&mut self, evqh: &mut EventLoopHandle, _: &Client, _: &wl_compositor::WlCompositor,
|
fn create_surface(&mut self, evqh: &mut EventLoopHandle, _: &Client, _: &wl_compositor::WlCompositor,
|
||||||
id: wl_surface::WlSurface) {
|
id: wl_surface::WlSurface) {
|
||||||
|
@ -54,11 +55,11 @@ impl<U, H: UserHandler<U>> wl_surface::Handler for CompositorHandler<U, H> {
|
||||||
unsafe {
|
unsafe {
|
||||||
SurfaceData::<U>::with_data(surface, |d| {
|
SurfaceData::<U>::with_data(surface, |d| {
|
||||||
d.damage = Damage::Surface(Rectangle {
|
d.damage = Damage::Surface(Rectangle {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,16 +106,18 @@ impl<U, H: UserHandler<U>> wl_surface::Handler for CompositorHandler<U, H> {
|
||||||
}
|
}
|
||||||
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) {
|
||||||
trace!(self.log,
|
trace!(
|
||||||
"Registering damage to surface (buffer coordinates).");
|
self.log,
|
||||||
|
"Registering damage to surface (buffer coordinates)."
|
||||||
|
);
|
||||||
unsafe {
|
unsafe {
|
||||||
SurfaceData::<U>::with_data(surface, |d| {
|
SurfaceData::<U>::with_data(surface, |d| {
|
||||||
d.damage = Damage::Buffer(Rectangle {
|
d.damage = Damage::Buffer(Rectangle {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,28 +140,32 @@ impl<U, H> wl_region::Handler for CompositorHandler<U, H> {
|
||||||
width: i32, height: i32) {
|
width: i32, height: i32) {
|
||||||
trace!(self.log, "Adding rectangle to a region.");
|
trace!(self.log, "Adding rectangle to a region.");
|
||||||
unsafe {
|
unsafe {
|
||||||
RegionData::add_rectangle(region,
|
RegionData::add_rectangle(
|
||||||
RectangleKind::Add,
|
region,
|
||||||
Rectangle {
|
RectangleKind::Add,
|
||||||
x,
|
Rectangle {
|
||||||
y,
|
x,
|
||||||
width,
|
y,
|
||||||
height,
|
width,
|
||||||
})
|
height,
|
||||||
|
},
|
||||||
|
)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
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) {
|
||||||
trace!(self.log, "Subtracting rectangle to a region.");
|
trace!(self.log, "Subtracting rectangle to a region.");
|
||||||
unsafe {
|
unsafe {
|
||||||
RegionData::add_rectangle(region,
|
RegionData::add_rectangle(
|
||||||
RectangleKind::Subtract,
|
region,
|
||||||
Rectangle {
|
RectangleKind::Subtract,
|
||||||
x,
|
Rectangle {
|
||||||
y,
|
x,
|
||||||
width,
|
y,
|
||||||
height,
|
width,
|
||||||
})
|
height,
|
||||||
|
},
|
||||||
|
)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,8 +183,9 @@ impl<U> Destroy<wl_region::WlRegion> for CompositorDestructor<U> {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
impl<U, H> wl_subcompositor::Handler for CompositorHandler<U, H>
|
impl<U, H> wl_subcompositor::Handler for CompositorHandler<U, H>
|
||||||
where U: Send + 'static,
|
where
|
||||||
H: Send + 'static
|
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,
|
||||||
|
@ -187,7 +195,9 @@ impl<U, H> wl_subcompositor::Handler for CompositorHandler<U, H>
|
||||||
resource.post_error(wl_subcompositor::Error::BadSurface as u32, "Surface already has a role.".into());
|
resource.post_error(wl_subcompositor::Error::BadSurface as u32, "Surface already has a role.".into());
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
id.set_user_data(Box::into_raw(Box::new(unsafe { surface.clone_unchecked() })) as *mut _);
|
id.set_user_data(Box::into_raw(
|
||||||
|
Box::new(unsafe { surface.clone_unchecked() }),
|
||||||
|
) as *mut _);
|
||||||
unsafe {
|
unsafe {
|
||||||
SurfaceData::<U>::with_data(surface, |d| {
|
SurfaceData::<U>::with_data(surface, |d| {
|
||||||
d.subsurface_attributes = Some(Default::default())
|
d.subsurface_attributes = Some(Default::default())
|
||||||
|
@ -204,7 +214,8 @@ server_declare_handler!(CompositorHandler<U: [Send], H: [Send]>, wl_subcomposito
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsafe fn with_subsurface_attributes<U, F>(subsurface: &wl_subsurface::WlSubsurface, f: F)
|
unsafe fn with_subsurface_attributes<U, F>(subsurface: &wl_subsurface::WlSubsurface, f: F)
|
||||||
where F: FnOnce(&mut SubsurfaceAttributes)
|
where
|
||||||
|
F: FnOnce(&mut SubsurfaceAttributes),
|
||||||
{
|
{
|
||||||
let ptr = subsurface.get_user_data();
|
let ptr = subsurface.get_user_data();
|
||||||
let surface = &*(ptr as *mut wl_surface::WlSurface);
|
let surface = &*(ptr as *mut wl_surface::WlSurface);
|
||||||
|
|
|
@ -285,10 +285,13 @@ impl<U: Send + 'static, H: Handler<U> + Send + 'static> CompositorToken<U, H> {
|
||||||
/// 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 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, H>>(surface, self.hid),
|
assert!(
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
|
"Accessing the data of foreign surfaces is not supported."
|
||||||
|
);
|
||||||
unsafe {
|
unsafe {
|
||||||
SurfaceData::<U>::with_data(surface, f);
|
SurfaceData::<U>::with_data(surface, f);
|
||||||
}
|
}
|
||||||
|
@ -303,10 +306,13 @@ impl<U: Send + 'static, H: Handler<U> + Send + 'static> CompositorToken<U, H> {
|
||||||
/// 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 with_surface_tree<F, T>(&self, surface: &wl_surface::WlSurface, initial: T, f: F) -> Result<(), ()>
|
pub fn with_surface_tree<F, T>(&self, surface: &wl_surface::WlSurface, initial: T, f: F) -> Result<(), ()>
|
||||||
where F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &T) -> TraversalAction<T>
|
where
|
||||||
|
F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &T) -> TraversalAction<T>,
|
||||||
{
|
{
|
||||||
assert!(resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
assert!(
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
|
"Accessing the data of foreign surfaces is not supported."
|
||||||
|
);
|
||||||
unsafe {
|
unsafe {
|
||||||
SurfaceData::<U>::map_tree(surface, initial, f);
|
SurfaceData::<U>::map_tree(surface, initial, f);
|
||||||
}
|
}
|
||||||
|
@ -320,8 +326,10 @@ impl<U: Send + 'static, H: Handler<U> + Send + 'static> CompositorToken<U, H> {
|
||||||
/// 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, H>>(surface, self.hid),
|
assert!(
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
|
"Accessing the data of foreign surfaces is not supported."
|
||||||
|
);
|
||||||
unsafe { SurfaceData::<U>::get_parent(surface) }
|
unsafe { SurfaceData::<U>::get_parent(surface) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,8 +338,10 @@ impl<U: Send + 'static, H: Handler<U> + Send + 'static> CompositorToken<U, H> {
|
||||||
/// 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_children(&self, surface: &wl_surface::WlSurface) -> Vec<wl_surface::WlSurface> {
|
pub fn get_children(&self, surface: &wl_surface::WlSurface) -> Vec<wl_surface::WlSurface> {
|
||||||
assert!(resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
assert!(
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
|
"Accessing the data of foreign surfaces is not supported."
|
||||||
|
);
|
||||||
unsafe { SurfaceData::<U>::get_children(surface) }
|
unsafe { SurfaceData::<U>::get_children(surface) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,8 +350,10 @@ impl<U: Send + 'static, H: Handler<U> + Send + 'static> CompositorToken<U, H> {
|
||||||
/// 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, H>>(surface, self.hid),
|
assert!(
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
|
"Accessing the data of foreign surfaces is not supported."
|
||||||
|
);
|
||||||
unsafe { SurfaceData::<U>::role_status(surface) }
|
unsafe { SurfaceData::<U>::role_status(surface) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,8 +367,10 @@ impl<U: Send + 'static, H: Handler<U> + Send + 'static> CompositorToken<U, H> {
|
||||||
/// 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, H>>(surface, self.hid),
|
assert!(
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
|
"Accessing the data of foreign surfaces is not supported."
|
||||||
|
);
|
||||||
unsafe { SurfaceData::<U>::give_role(surface) }
|
unsafe { SurfaceData::<U>::give_role(surface) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,8 +383,10 @@ impl<U: Send + 'static, H: Handler<U> + Send + 'static> CompositorToken<U, H> {
|
||||||
/// 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, H>>(surface, self.hid),
|
assert!(
|
||||||
"Accessing the data of foreign surfaces is not supported.");
|
resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
|
||||||
|
"Accessing the data of foreign surfaces is not supported."
|
||||||
|
);
|
||||||
unsafe { SurfaceData::<U>::remove_role(surface) }
|
unsafe { SurfaceData::<U>::remove_role(surface) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,8 +395,10 @@ impl<U: Send + 'static, H: Handler<U> + Send + 'static> CompositorToken<U, H> {
|
||||||
/// If the region is not managed by the CompositorGlobal that provided this token, this
|
/// If the region 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_region_attributes(&self, region: &wl_region::WlRegion) -> RegionAttributes {
|
pub fn get_region_attributes(&self, region: &wl_region::WlRegion) -> RegionAttributes {
|
||||||
assert!(resource_is_registered::<_, CompositorHandler<U, H>>(region, self.hid),
|
assert!(
|
||||||
"Accessing the data of foreign regions is not supported.");
|
resource_is_registered::<_, CompositorHandler<U, H>>(region, self.hid),
|
||||||
|
"Accessing the data of foreign regions is not supported."
|
||||||
|
);
|
||||||
unsafe { RegionData::get_attributes(region) }
|
unsafe { RegionData::get_attributes(region) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -410,7 +428,8 @@ impl<U, H> Init for CompositorHandler<U, H> {
|
||||||
impl<U, H> CompositorHandler<U, H> {
|
impl<U, H> CompositorHandler<U, H> {
|
||||||
/// Create a new CompositorHandler
|
/// Create a new CompositorHandler
|
||||||
pub fn new<L>(handler: H, logger: L) -> CompositorHandler<U, H>
|
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 {
|
||||||
|
@ -423,8 +442,10 @@ impl<U, H> CompositorHandler<U, H> {
|
||||||
|
|
||||||
/// Create a token to access the data associated to the objects managed by this handler.
|
/// Create a token to access the data associated to the objects managed by this handler.
|
||||||
pub fn get_token(&self) -> CompositorToken<U, H> {
|
pub fn get_token(&self) -> CompositorToken<U, H> {
|
||||||
assert!(self.my_id != ::std::usize::MAX,
|
assert!(
|
||||||
"CompositorHandler is not initialized yet.");
|
self.my_id != ::std::usize::MAX,
|
||||||
|
"CompositorHandler is not initialized yet."
|
||||||
|
);
|
||||||
trace!(self.log, "Creating a compositor token.");
|
trace!(self.log, "Creating a compositor token.");
|
||||||
CompositorToken {
|
CompositorToken {
|
||||||
hid: self.my_id,
|
hid: self.my_id,
|
||||||
|
|
|
@ -13,7 +13,9 @@ pub struct RegionData {
|
||||||
impl RegionData {
|
impl RegionData {
|
||||||
/// Initialize the user_data of a region, must be called right when the surface is created
|
/// Initialize the user_data of a region, must be called right when the surface is created
|
||||||
pub unsafe fn init(region: &wl_region::WlRegion) {
|
pub unsafe fn init(region: &wl_region::WlRegion) {
|
||||||
region.set_user_data(Box::into_raw(Box::new(Mutex::new(RegionData::default()))) as *mut _)
|
region.set_user_data(Box::into_raw(
|
||||||
|
Box::new(Mutex::new(RegionData::default())),
|
||||||
|
) as *mut _)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cleans the user_data of that surface, must be called when it is destroyed
|
/// Cleans the user_data of that surface, must be called when it is destroyed
|
||||||
|
|
|
@ -70,7 +70,9 @@ impl<U: Default> SurfaceData<U> {
|
||||||
|
|
||||||
/// Initialize the user_data of a surface, must be called right when the surface is created
|
/// Initialize the user_data of a surface, must be called right when the surface is created
|
||||||
pub unsafe fn init(surface: &wl_surface::WlSurface) {
|
pub unsafe fn init(surface: &wl_surface::WlSurface) {
|
||||||
surface.set_user_data(Box::into_raw(Box::new(Mutex::new(SurfaceData::<U>::new()))) as *mut _)
|
surface.set_user_data(Box::into_raw(
|
||||||
|
Box::new(Mutex::new(SurfaceData::<U>::new())),
|
||||||
|
) as *mut _)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +272,8 @@ impl<U> SurfaceData<U> {
|
||||||
/// Note that an internal lock is taken during access of this data,
|
/// Note that an internal lock is taken during access of this data,
|
||||||
/// so the tree cannot be manipulated at the same time
|
/// so the tree cannot be manipulated at the same time
|
||||||
pub unsafe fn with_data<F>(surface: &wl_surface::WlSurface, f: F)
|
pub unsafe fn with_data<F>(surface: &wl_surface::WlSurface, f: F)
|
||||||
where F: FnOnce(&mut SurfaceAttributes<U>)
|
where
|
||||||
|
F: FnOnce(&mut SurfaceAttributes<U>),
|
||||||
{
|
{
|
||||||
let data_mutex = Self::get_data(surface);
|
let data_mutex = Self::get_data(surface);
|
||||||
let mut data_guard = data_mutex.lock().unwrap();
|
let mut data_guard = data_mutex.lock().unwrap();
|
||||||
|
@ -286,13 +289,15 @@ impl<U> SurfaceData<U> {
|
||||||
/// The callback returns wether the traversal should continue or not. Returning
|
/// The callback returns wether the traversal should continue or not. Returning
|
||||||
/// false will cause an early-stopping.
|
/// false will cause an early-stopping.
|
||||||
pub unsafe fn map_tree<F, T>(root: &wl_surface::WlSurface, initial: T, mut f: F)
|
pub unsafe fn map_tree<F, T>(root: &wl_surface::WlSurface, initial: T, mut f: F)
|
||||||
where F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &T) -> TraversalAction<T>
|
where
|
||||||
|
F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &T) -> TraversalAction<T>,
|
||||||
{
|
{
|
||||||
// helper function for recursion
|
// helper function for recursion
|
||||||
unsafe fn map<U, F, T>(surface: &wl_surface::WlSurface, root: &wl_surface::WlSurface, initial: &T,
|
unsafe fn map<U, F, T>(surface: &wl_surface::WlSurface, root: &wl_surface::WlSurface, initial: &T,
|
||||||
f: &mut F)
|
f: &mut F)
|
||||||
-> bool
|
-> bool
|
||||||
where F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &T) -> TraversalAction<T>
|
where
|
||||||
|
F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &T) -> TraversalAction<T>,
|
||||||
{
|
{
|
||||||
// stop if we met the root, so to not deadlock/inifinte loop
|
// stop if we met the root, so to not deadlock/inifinte loop
|
||||||
if surface.equals(root) {
|
if surface.equals(root) {
|
||||||
|
|
Loading…
Reference in New Issue