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:
parent
16aec8f87e
commit
e52a60b3b6
41 changed files with 1417 additions and 364 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
78
src/ifs/wl_surface/wp_fractional_scale_v1.rs
Normal file
78
src/ifs/wl_surface/wp_fractional_scale_v1.rs
Normal 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);
|
||||
|
|
@ -124,6 +124,7 @@ impl XdgSurface {
|
|||
|
||||
fn set_workspace(&self, ws: &Rc<WorkspaceNode>) {
|
||||
self.workspace.set(Some(ws.clone()));
|
||||
self.surface.set_output(&ws.output.get());
|
||||
let pu = self.popups.lock();
|
||||
for pu in pu.values() {
|
||||
pu.xdg.set_workspace(ws);
|
||||
|
|
|
|||
|
|
@ -456,8 +456,7 @@ impl ToplevelNode for XdgToplevel {
|
|||
Some(self.xdg.surface.clone())
|
||||
}
|
||||
|
||||
fn tl_set_workspace(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
|
||||
self.toplevel_data.workspace.set(Some(ws.clone()));
|
||||
fn tl_set_workspace_ext(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
|
||||
self.xdg.set_workspace(ws);
|
||||
}
|
||||
|
||||
|
|
@ -548,12 +547,7 @@ impl XdgSurfaceExt for XdgToplevel {
|
|||
self.extents_changed();
|
||||
if let Some(workspace) = self.xdg.workspace.get() {
|
||||
let output = workspace.output.get();
|
||||
let bindings = output.global.bindings.borrow_mut();
|
||||
if let Some(binding) = bindings.get(&self.xdg.surface.client.id) {
|
||||
for binding in binding.values() {
|
||||
self.xdg.surface.send_enter(binding.id);
|
||||
}
|
||||
}
|
||||
surface.set_output(&output);
|
||||
}
|
||||
// {
|
||||
// let seats = surface.client.state.globals.lock_seats();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use {
|
|||
state::State,
|
||||
tree::{
|
||||
Direction, FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, StackedNode,
|
||||
ToplevelData, ToplevelNode,
|
||||
ToplevelData, ToplevelNode, WorkspaceNode,
|
||||
},
|
||||
utils::{clonecell::CloneCell, copyhashmap::CopyHashMap, linkedlist::LinkedNode},
|
||||
wire::WlSurfaceId,
|
||||
|
|
@ -401,6 +401,10 @@ impl ToplevelNode for Xwindow {
|
|||
Some(self.surface.clone())
|
||||
}
|
||||
|
||||
fn tl_set_workspace_ext(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
|
||||
self.surface.set_output(&ws.output.get());
|
||||
}
|
||||
|
||||
fn tl_change_extents(self: Rc<Self>, rect: &Rect) {
|
||||
// log::info!("xwin {} change_extents {:?}", self.data.window_id, rect);
|
||||
let old = self.data.info.extents.replace(*rect);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue