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

@ -12,7 +12,10 @@ use {
walker::NodeVisitor, ContainingNode, FindTreeResult, FoundNode, Node, NodeId,
StackedNode, ToplevelNode, WorkspaceNode,
},
utils::{clonecell::CloneCell, errorfmt::ErrorFmt, linkedlist::LinkedNode},
utils::{
clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt,
linkedlist::LinkedNode,
},
},
ahash::AHashMap,
std::{
@ -39,7 +42,7 @@ pub struct FloatNode {
pub layout_scheduled: Cell<bool>,
pub render_titles_scheduled: Cell<bool>,
pub title: RefCell<String>,
pub title_texture: CloneCell<Option<Rc<Texture>>>,
pub title_textures: CopyHashMap<Fixed, Rc<Texture>>,
seats: RefCell<AHashMap<SeatId, SeatState>>,
}
@ -106,7 +109,7 @@ impl FloatNode {
layout_scheduled: Cell::new(false),
render_titles_scheduled: Cell::new(false),
title: Default::default(),
title_texture: Default::default(),
title_textures: Default::default(),
seats: Default::default(),
});
floater
@ -174,23 +177,38 @@ impl FloatNode {
let bw = theme.sizes.border_width.get();
let font = theme.font.borrow_mut();
let title = self.title.borrow_mut();
self.title_texture.set(None);
self.title_textures.clear();
let pos = self.position.get();
if pos.width() <= 2 * bw || th == 0 || title.is_empty() {
if pos.width() <= 2 * bw || title.is_empty() {
return;
}
let ctx = match self.state.render_ctx.get() {
Some(c) => c,
_ => return,
};
let texture = match text::render(&ctx, pos.width() - 2 * bw, th, &font, &title, tc) {
Ok(t) => t,
Err(e) => {
log::error!("Could not render title {}: {}", title, ErrorFmt(e));
return;
let scales = self.state.scales.lock();
for (scale, _) in scales.iter() {
let mut th = th;
let mut scalef = None;
let mut width = pos.width() - 2 * bw;
if *scale != 1 {
let scale = scale.to_f64();
th = (th as f64 * scale).round() as _;
width = (width as f64 * scale).round() as _;
scalef = Some(scale);
}
};
self.title_texture.set(Some(texture));
if th == 0 || width == 0 {
continue;
}
let texture = match text::render(&ctx, width, th, &font, &title, tc, scalef) {
Ok(t) => t,
Err(e) => {
log::error!("Could not render title {}: {}", title, ErrorFmt(e));
return;
}
};
self.title_textures.set(*scale, texture);
}
}
fn pointer_move(self: &Rc<Self>, seat: &Rc<WlSeatGlobal>, x: i32, y: i32) {