Skip to content

Commit

Permalink
wayland: implement wl_surface v6
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Feb 6, 2024
1 parent 0bd61bc commit bf1bb58
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ifs/wl_compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Global for WlCompositorGlobal {
}

fn version(&self) -> u32 {
5
6
}
}

Expand Down
19 changes: 14 additions & 5 deletions src/ifs/wl_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const INVALID_TRANSFORM: u32 = 1;
const INVALID_SIZE: u32 = 2;

const OFFSET_SINCE: u32 = 5;
const BUFFER_SCALE_SINCE: u32 = 6;

#[derive(Copy, Clone, Debug, PartialEq)]
enum Transform {
Expand Down Expand Up @@ -211,7 +212,7 @@ impl SurfaceRole {
pub struct SurfaceSendPreferredScaleVisitor;
impl NodeVisitorBase for SurfaceSendPreferredScaleVisitor {
fn visit_surface(&mut self, node: &Rc<WlSurface>) {
node.send_preferred_scale();
node.on_scale_change();
node.node_visit_children(self);
}
}
Expand Down Expand Up @@ -432,9 +433,7 @@ impl WlSurface {
output.global.send_enter(self);
old.global.send_leave(self);
if old.preferred_scale.get() != output.preferred_scale.get() {
if let Some(fs) = self.fractional_scale.get() {
fs.send_preferred_scale();
}
self.on_scale_change();
}
let children = self.children.borrow_mut();
if let Some(children) = &*children {
Expand All @@ -444,10 +443,11 @@ impl WlSurface {
}
}

pub fn send_preferred_scale(&self) {
fn on_scale_change(&self) {
if let Some(fs) = self.fractional_scale.get() {
fs.send_preferred_scale();
}
self.send_preferred_buffer_scale();
}

pub fn get_toplevel(&self) -> Option<Rc<dyn ToplevelNode>> {
Expand Down Expand Up @@ -518,6 +518,15 @@ impl WlSurface {
})
}

pub fn send_preferred_buffer_scale(&self) {
if self.version >= BUFFER_SCALE_SINCE {
self.client.event(PreferredBufferScale {
self_id: self.id,
factor: self.output.get().global.legacy_scale.get() as _,
});
}
}

fn set_toplevel(&self, tl: Option<Rc<dyn ToplevelNode>>) {
let ch = self.children.borrow();
if let Some(ch) = &*ch {
Expand Down
8 changes: 8 additions & 0 deletions wire/wl_surface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ msg enter = 0 {
msg leave = 1 {
output: id(wl_output),
}

msg preferred_buffer_scale = 2 {
factor: i32,
}

msg preferred_buffer_transform = 3 {
transform: u32,
}

0 comments on commit bf1bb58

Please sign in to comment.