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

@ -1,10 +1,12 @@
use {
crate::{
cursor::Cursor,
fixed::Fixed,
ifs::{wl_seat::WlSeatGlobal, wl_surface::WlSurface},
leaks::Tracker,
rect::Rect,
render::Renderer,
tree::OutputNode,
},
std::{cell::Cell, rc::Rc},
};
@ -13,7 +15,6 @@ pub struct CursorSurface {
seat: Rc<WlSeatGlobal>,
surface: Rc<WlSurface>,
hotspot: Cell<(i32, i32)>,
pos: Cell<(i32, i32)>,
extents: Cell<Rect>,
pub tracker: Tracker<Self>,
}
@ -24,25 +25,16 @@ impl CursorSurface {
seat: seat.clone(),
surface: surface.clone(),
hotspot: Cell::new((0, 0)),
pos: Cell::new((0, 0)),
extents: Cell::new(Default::default()),
tracker: Default::default(),
}
}
fn update_extents(&self) {
let (pos_x, pos_y) = self.pos.get();
let extents = self.extents.get();
let (hot_x, hot_y) = self.hotspot.get();
self.extents.set(
Rect::new_sized(
pos_x - hot_x,
pos_y - hot_y,
extents.width(),
extents.height(),
)
.unwrap(),
);
self.extents
.set(Rect::new_sized(-hot_x, -hot_y, extents.width(), extents.height()).unwrap());
}
pub fn handle_surface_destroy(&self) {
@ -69,21 +61,25 @@ impl CursorSurface {
}
impl Cursor for CursorSurface {
fn set_position(&self, x: i32, y: i32) {
self.pos.set((x, y));
self.update_extents();
fn render(&self, renderer: &mut Renderer, x: Fixed, y: Fixed) {
let extents = self.extents.get().move_(x.round_down(), y.round_down());
if extents.intersects(&renderer.logical_extents()) {
let scale = renderer.scale();
if scale != 1 {
let scale = scale.to_f64();
let (hot_x, hot_y) = self.hotspot.get();
let (hot_x, hot_y) = (Fixed::from_int(hot_x), Fixed::from_int(hot_y));
let x = ((x - hot_x).to_f64() * scale).round() as _;
let y = ((y - hot_y).to_f64() * scale).round() as _;
renderer.render_surface_scaled(&self.surface, x, y, None);
} else {
renderer.render_surface(&self.surface, extents.x1(), extents.y1());
}
}
}
fn render(&self, renderer: &mut Renderer, x: i32, y: i32) {
renderer.render_surface(&self.surface, x, y);
}
fn get_hotspot(&self) -> (i32, i32) {
self.hotspot.get()
}
fn extents(&self) -> Rect {
self.extents.get()
fn set_output(&self, output: &Rc<OutputNode>) {
self.surface.set_output(output);
}
fn handle_unset(&self) {