1
0
Fork 0
forked from wry/wry

wayland: implement scaling

This involves many subsystems:

- config:
    - allow setting the connector scale
    - allow setting the cursor size
- cursors:
    - load server cursors for all requested sizes and scales
- wl_surface:
    - track the output the surface belongs to
    - send wl_surface.enter/leave
- wl_output:
    - implement wl_output.scale
- text:
    - pre-render texts for all used scales
- renderer:
    - properly align scale textures and rectangles
- wp_fractional_scale:
    - new interface for fractional scaling
This commit is contained in:
Julian Orth 2022-05-30 17:00:25 +02:00
parent 16aec8f87e
commit e52a60b3b6
41 changed files with 1417 additions and 364 deletions

View file

@ -0,0 +1,78 @@
use {
crate::{
client::{Client, ClientError},
ifs::wl_surface::WlSurface,
leaks::Tracker,
object::Object,
utils::buffd::{MsgParser, MsgParserError},
wire::{wp_fractional_scale_v1::*, WpFractionalScaleV1Id},
},
std::rc::Rc,
thiserror::Error,
};
pub struct WpFractionalScaleV1 {
pub id: WpFractionalScaleV1Id,
pub client: Rc<Client>,
pub surface: Rc<WlSurface>,
pub tracker: Tracker<Self>,
}
impl WpFractionalScaleV1 {
pub fn new(id: WpFractionalScaleV1Id, surface: &Rc<WlSurface>) -> Self {
Self {
id,
client: surface.client.clone(),
surface: surface.clone(),
tracker: Default::default(),
}
}
pub fn install(self: &Rc<Self>) -> Result<(), WpFractionalScaleError> {
if self.surface.fractional_scale.get().is_some() {
return Err(WpFractionalScaleError::Exists);
}
self.surface.fractional_scale.set(Some(self.clone()));
Ok(())
}
pub fn send_preferred_scale(&self) {
self.client.event(PreferredScale {
self_id: self.id,
scale: self.surface.output.get().preferred_scale.get(),
});
}
fn destroy(&self, msg: MsgParser<'_, '_>) -> Result<(), WpFractionalScaleError> {
let _req: Destroy = self.client.parse(self, msg)?;
self.surface.fractional_scale.take();
self.client.remove_obj(self)?;
Ok(())
}
}
object_base! {
WpFractionalScaleV1;
DESTROY => destroy,
}
impl Object for WpFractionalScaleV1 {
fn num_requests(&self) -> u32 {
DESTROY + 1
}
}
simple_add_obj!(WpFractionalScaleV1);
#[derive(Debug, Error)]
pub enum WpFractionalScaleError {
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("The surface already has a fractional scale extension attached")]
Exists,
}
efrom!(WpFractionalScaleError, MsgParserError);
efrom!(WpFractionalScaleError, ClientError);