shell: load/update output configuration

This commit is contained in:
Victoria Brekenfeld 2022-04-05 16:35:58 +02:00
parent a9d6b8c3d7
commit ec861fadd4
11 changed files with 481 additions and 152 deletions

View file

@ -16,7 +16,10 @@ use smithay::{
mod grabs;
pub use self::grabs::*;
pub struct FloatingLayout;
#[derive(Debug, Default)]
pub struct FloatingLayout {
pending_windows: Vec<Window>,
}
impl Layout for FloatingLayout {
fn map_window<'a>(
@ -26,36 +29,26 @@ impl Layout for FloatingLayout {
seat: &Seat,
_focus_stack: Box<dyn Iterator<Item = &'a Window> + 'a>,
) {
let output = super::output_from_seat(Some(seat), space);
let win_geo = window.bbox();
let layers = layer_map_for_output(&output);
let geometry = layers.non_exclusive_zone();
let position = (
-geometry.loc.x + (geometry.size.w / 2) - (win_geo.size.w / 2),
-geometry.loc.y + (geometry.size.h / 2) - (win_geo.size.h / 2),
);
#[allow(irrefutable_let_patterns)]
if let Kind::Xdg(xdg) = &window.toplevel() {
let ret = xdg.with_pending_state(|state| {
state.states.unset(XdgState::TiledLeft);
state.states.unset(XdgState::TiledRight);
state.states.unset(XdgState::TiledTop);
state.states.unset(XdgState::TiledBottom);
});
if ret.is_ok() {
xdg.send_configure();
}
if let Some(output) = super::output_from_seat(Some(seat), space) {
Self::map_window(space, window, &output)
} else {
self.pending_windows.push(window.clone());
}
space.map_window(&window, position, false);
}
fn refresh(&mut self, _space: &mut Space) {
fn refresh(&mut self, space: &mut Space) {
self.pending_windows.retain(|w| w.toplevel().alive());
if let Some(output) = super::output_from_seat(None, space) {
for window in self.pending_windows.drain(..) {
Self::map_window(space, &window, &output);
}
}
// TODO make sure all windows are still visible on any output or move them
}
fn unmap_window(&mut self, space: &mut Space, window: &Window) {
space.unmap_window(window)
space.unmap_window(window);
self.pending_windows.retain(|w| w != window);
}
fn maximize_request(&mut self, space: &mut Space, window: &Window, output: &Output) {
@ -144,3 +137,37 @@ impl Layout for FloatingLayout {
}
}
}
impl FloatingLayout {
pub fn new() -> FloatingLayout {
Default::default()
}
fn map_window(
space: &mut Space,
window: &Window,
output: &Output,
) {
let win_geo = window.bbox();
let layers = layer_map_for_output(&output);
let geometry = layers.non_exclusive_zone();
let position = (
-geometry.loc.x + (geometry.size.w / 2) - (win_geo.size.w / 2),
-geometry.loc.y + (geometry.size.h / 2) - (win_geo.size.h / 2),
);
#[allow(irrefutable_let_patterns)]
if let Kind::Xdg(xdg) = &window.toplevel() {
let ret = xdg.with_pending_state(|state| {
state.states.unset(XdgState::TiledLeft);
state.states.unset(XdgState::TiledRight);
state.states.unset(XdgState::TiledTop);
state.states.unset(XdgState::TiledBottom);
});
if ret.is_ok() {
xdg.send_configure();
}
}
space.map_window(&window, position, false);
}
}

View file

@ -90,7 +90,7 @@ pub trait Layout {
pub fn new_default_layout() -> Box<dyn Layout> {
Box::new(combined::Combined::new(
tiling::TilingLayout::new(),
floating::FloatingLayout,
floating::FloatingLayout::new(),
|window| {
if let Some(surface) = window.toplevel().get_surface() {
with_states(surface, |states| {
@ -128,7 +128,7 @@ pub fn new_default_layout() -> Box<dyn Layout> {
))
}
fn output_from_seat(seat: Option<&Seat>, space: &Space) -> Output {
fn output_from_seat(seat: Option<&Seat>, space: &Space) -> Option<Output> {
seat.and_then(|seat| {
seat.user_data()
.get::<ActiveOutput>()
@ -139,5 +139,5 @@ fn output_from_seat(seat: Option<&Seat>, space: &Space) -> Output {
.cloned()
})
})
.unwrap_or_else(|| space.outputs().next().cloned().unwrap())
.or_else(|| space.outputs().next().cloned())
}

View file

@ -85,7 +85,7 @@ impl Layout for TilingLayout {
focus_stack: Box<dyn Iterator<Item = &'a Window> + 'a>,
) -> Option<Window> {
let output = super::output_from_seat(Some(seat), space);
let idx = space.outputs().position(|o| *o == output).unwrap_or(0);
let idx = space.outputs().position(|o| Some(o) == output.as_ref()).unwrap_or(0);
let tree = TilingLayout::active_tree(&mut self.trees, idx);
if let Some(last_active) = TilingLayout::last_active_window(tree, focus_stack) {
let mut node_id = last_active;
@ -141,7 +141,7 @@ impl Layout for TilingLayout {
focus_stack: Box<dyn Iterator<Item = &'a Window> + 'a>,
) {
let output = super::output_from_seat(Some(seat), space);
let idx = space.outputs().position(|o| *o == output).unwrap_or(0);
let idx = space.outputs().position(|o| Some(o) == output.as_ref()).unwrap_or(0);
let tree = TilingLayout::active_tree(&mut self.trees, idx);
if let Some(last_active) = TilingLayout::last_active_window(tree, focus_stack) {
if let Some((fork, _child)) = TilingLayout::find_fork(tree, last_active) {
@ -288,7 +288,7 @@ impl TilingLayout {
focus_stack: Option<Box<dyn Iterator<Item = &'a Window> + 'a>>,
) {
let output = super::output_from_seat(seat, space);
let idx = space.outputs().position(|o| *o == output).unwrap_or(0);
let idx = space.outputs().position(|o| Some(o) == output.as_ref()).unwrap_or(0);
let tree = TilingLayout::active_tree(&mut self.trees, idx);
let new_window = Node::new(Data::Window(window.clone()));