1
0
Fork 0
forked from wry/wry

wayland: implement surface transformations

- buffer scale
- buffer transform
- viewporter
This commit is contained in:
Julian Orth 2022-05-28 18:18:29 +02:00
parent 20f0fba553
commit 95327685c1
16 changed files with 635 additions and 75 deletions

View file

@ -50,10 +50,7 @@ impl CursorSurface {
}
pub fn handle_buffer_change(&self) {
let (width, height) = match self.surface.buffer.get() {
Some(b) => (b.rect.width(), b.rect.height()),
_ => (0, 0),
};
let (width, height) = self.surface.buffer_abs_pos.get().size();
self.extents
.set(Rect::new_sized(0, 0, width, height).unwrap());
self.update_extents();

View file

@ -282,12 +282,9 @@ impl SurfaceExt for WlSubsurface {
self.node.borrow_mut().replace(v);
}
if let Some((x, y)) = self.pending.position.take() {
if let Some(buffer) = self.surface.buffer.get() {
self.position.set(buffer.rect.move_(x, y));
self.parent.need_extents_update.set(true);
} else {
self.position.set(Rect::new_empty(x, y));
}
self.position
.set(self.surface.buffer_abs_pos.get().at_point(x, y));
self.parent.need_extents_update.set(true);
}
}

View file

@ -0,0 +1,107 @@
use {
crate::{
client::{Client, ClientError},
ifs::wl_surface::WlSurface,
leaks::Tracker,
object::Object,
utils::buffd::{MsgParser, MsgParserError},
wire::{wp_viewport::*, WpViewportId},
},
std::rc::Rc,
thiserror::Error,
};
pub struct WpViewport {
pub id: WpViewportId,
pub client: Rc<Client>,
pub surface: Rc<WlSurface>,
pub tracker: Tracker<Self>,
}
impl WpViewport {
pub fn new(id: WpViewportId, surface: &Rc<WlSurface>) -> Self {
Self {
id,
client: surface.client.clone(),
surface: surface.clone(),
tracker: Default::default(),
}
}
pub fn install(self: &Rc<Self>) -> Result<(), WpViewportError> {
if self.surface.viewporter.get().is_some() {
return Err(WpViewportError::ViewportExists);
}
self.surface.viewporter.set(Some(self.clone()));
Ok(())
}
fn destroy(&self, msg: MsgParser<'_, '_>) -> Result<(), WpViewportError> {
let _req: Destroy = self.client.parse(self, msg)?;
self.surface.pending.src_rect.set(Some(None));
self.surface.pending.dst_size.set(Some(None));
self.surface.viewporter.take();
self.client.remove_obj(self)?;
Ok(())
}
fn set_source(&self, msg: MsgParser<'_, '_>) -> Result<(), WpViewportError> {
let req: SetSource = self.client.parse(self, msg)?;
let rect = if req.x == -1 && req.y == -1 && req.width == -1 && req.height == -1 {
None
} else {
let invalid = req.x < 0 || req.y < 0 || req.width <= 0 || req.height <= 0;
if invalid {
return Err(WpViewportError::InvalidSourceRect);
}
Some([req.x, req.y, req.width, req.height])
};
self.surface.pending.src_rect.set(Some(rect));
Ok(())
}
fn set_destination(&self, msg: MsgParser<'_, '_>) -> Result<(), WpViewportError> {
let req: SetDestination = self.client.parse(self, msg)?;
let size = if req.width == -1 && req.height == -1 {
None
} else if req.width <= 0 || req.height <= 0 {
return Err(WpViewportError::InvalidDestRect);
} else {
Some((req.width, req.height))
};
self.surface.pending.dst_size.set(Some(size));
Ok(())
}
}
object_base! {
WpViewport;
DESTROY => destroy,
SET_SOURCE => set_source,
SET_DESTINATION => set_destination,
}
impl Object for WpViewport {
fn num_requests(&self) -> u32 {
SET_DESTINATION + 1
}
}
simple_add_obj!(WpViewport);
#[derive(Debug, Error)]
pub enum WpViewportError {
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("The surface already has a viewport")]
ViewportExists,
#[error("Rectangle is empty or outside the first quadrant")]
InvalidSourceRect,
#[error("Rectangle is empty")]
InvalidDestRect,
}
efrom!(WpViewportError, MsgParserError);
efrom!(WpViewportError, ClientError);

View file

@ -343,15 +343,14 @@ impl Node for Xwindow {
}
fn node_find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
if let Some(buffer) = self.surface.buffer.get() {
if x < buffer.rect.width() && y < buffer.rect.height() {
tree.push(FoundNode {
node: self.surface.clone(),
x,
y,
});
return FindTreeResult::AcceptsInput;
}
let rect = self.surface.buffer_abs_pos.get();
if x < rect.width() && y < rect.height() {
tree.push(FoundNode {
node: self.surface.clone(),
x,
y,
});
return FindTreeResult::AcceptsInput;
}
FindTreeResult::Other
}