layer-shell: compute configure width/height after every commit
This commit is contained in:
parent
7cb9bd667f
commit
cc37d14c9e
1 changed files with 30 additions and 30 deletions
|
|
@ -13,8 +13,7 @@ use {
|
||||||
renderer::Renderer,
|
renderer::Renderer,
|
||||||
tree::{FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId, NodeVisitor},
|
tree::{FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId, NodeVisitor},
|
||||||
utils::{
|
utils::{
|
||||||
bitflags::BitflagsExt, cell_ext::CellExt, linkedlist::LinkedNode, numcell::NumCell,
|
bitflags::BitflagsExt, linkedlist::LinkedNode, numcell::NumCell, option_ext::OptionExt,
|
||||||
option_ext::OptionExt,
|
|
||||||
},
|
},
|
||||||
wire::{zwlr_layer_surface_v1::*, WlSurfaceId, ZwlrLayerSurfaceV1Id},
|
wire::{zwlr_layer_surface_v1::*, WlSurfaceId, ZwlrLayerSurfaceV1Id},
|
||||||
},
|
},
|
||||||
|
|
@ -60,6 +59,7 @@ pub struct ZwlrLayerSurfaceV1 {
|
||||||
keyboard_interactivity: Cell<u32>,
|
keyboard_interactivity: Cell<u32>,
|
||||||
link: Cell<Option<LinkedNode<Rc<Self>>>>,
|
link: Cell<Option<LinkedNode<Rc<Self>>>>,
|
||||||
seat_state: NodeSeatState,
|
seat_state: NodeSeatState,
|
||||||
|
last_configure: Cell<(i32, i32)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -123,6 +123,7 @@ impl ZwlrLayerSurfaceV1 {
|
||||||
keyboard_interactivity: Cell::new(0),
|
keyboard_interactivity: Cell::new(0),
|
||||||
link: Cell::new(None),
|
link: Cell::new(None),
|
||||||
seat_state: Default::default(),
|
seat_state: Default::default(),
|
||||||
|
last_configure: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,11 +245,7 @@ impl ZwlrLayerSurfaceV1RequestHandler for ZwlrLayerSurfaceV1 {
|
||||||
|
|
||||||
impl ZwlrLayerSurfaceV1 {
|
impl ZwlrLayerSurfaceV1 {
|
||||||
fn pre_commit(&self, pending: &mut PendingState) -> Result<(), ZwlrLayerSurfaceV1Error> {
|
fn pre_commit(&self, pending: &mut PendingState) -> Result<(), ZwlrLayerSurfaceV1Error> {
|
||||||
let Some(global) = self.output.get() else {
|
|
||||||
return Ok(());
|
|
||||||
};
|
|
||||||
let pending = pending.layer_surface.get_or_insert_default_ext();
|
let pending = pending.layer_surface.get_or_insert_default_ext();
|
||||||
let mut send_configure = mem::replace(&mut pending.any, false);
|
|
||||||
if let Some(size) = pending.size.take() {
|
if let Some(size) = pending.size.take() {
|
||||||
self.size.set(size);
|
self.size.set(size);
|
||||||
}
|
}
|
||||||
|
|
@ -267,34 +264,36 @@ impl ZwlrLayerSurfaceV1 {
|
||||||
if let Some(layer) = pending.layer.take() {
|
if let Some(layer) = pending.layer.take() {
|
||||||
self.layer.set(layer);
|
self.layer.set(layer);
|
||||||
}
|
}
|
||||||
{
|
let anchor = self.anchor.get();
|
||||||
let (mut width, mut height) = self.size.get();
|
let (width, height) = self.size.get();
|
||||||
let anchor = self.anchor.get();
|
if width == 0 && !anchor.contains(LEFT | RIGHT) {
|
||||||
if width == 0 {
|
return Err(ZwlrLayerSurfaceV1Error::WidthZero);
|
||||||
if !anchor.contains(LEFT | RIGHT) {
|
|
||||||
return Err(ZwlrLayerSurfaceV1Error::WidthZero);
|
|
||||||
}
|
|
||||||
send_configure = true;
|
|
||||||
width = global.position().width();
|
|
||||||
}
|
|
||||||
if height == 0 {
|
|
||||||
if !anchor.contains(TOP | BOTTOM) {
|
|
||||||
return Err(ZwlrLayerSurfaceV1Error::HeightZero);
|
|
||||||
}
|
|
||||||
send_configure = true;
|
|
||||||
height = global.position().height();
|
|
||||||
}
|
|
||||||
self.size.set((width, height));
|
|
||||||
}
|
}
|
||||||
if self.acked_serial.is_none() {
|
if height == 0 && !anchor.contains(TOP | BOTTOM) {
|
||||||
send_configure = true;
|
return Err(ZwlrLayerSurfaceV1Error::HeightZero);
|
||||||
}
|
}
|
||||||
if send_configure {
|
self.configure();
|
||||||
let (width, height) = self.size.get();
|
Ok(())
|
||||||
let serial = self.requested_serial.fetch_add(1) + 1;
|
}
|
||||||
|
|
||||||
|
fn configure(&self) {
|
||||||
|
let Some(global) = self.output.get() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let (mut width, mut height) = self.size.get();
|
||||||
|
let (available_width, available_height) = global.position().size();
|
||||||
|
if width == 0 {
|
||||||
|
width = available_width;
|
||||||
|
}
|
||||||
|
width = width.min(available_width).max(1);
|
||||||
|
if height == 0 {
|
||||||
|
height = available_height;
|
||||||
|
}
|
||||||
|
height = height.min(available_height).max(1);
|
||||||
|
let serial = self.requested_serial.fetch_add(1) + 1;
|
||||||
|
if self.last_configure.replace((width, height)) != (width, height) {
|
||||||
self.send_configure(serial, width as _, height as _);
|
self.send_configure(serial, width as _, height as _);
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn output_position(&self) -> Rect {
|
pub fn output_position(&self) -> Rect {
|
||||||
|
|
@ -345,6 +344,7 @@ impl ZwlrLayerSurfaceV1 {
|
||||||
self.surface.destroy_node();
|
self.surface.destroy_node();
|
||||||
self.seat_state.destroy_node(self);
|
self.seat_state.destroy_node(self);
|
||||||
self.client.state.tree_changed();
|
self.client.state.tree_changed();
|
||||||
|
self.last_configure.take();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue