shell: handle fullscreen windows on a dedicated layer

I hoped to split this up into multiple commits, but the api
changes to `shell/workspace.rs` were to invasive to feasibly do this.

Here is a rough list of changes:

- Fullscreen windows aren't mapped to other layers anymore
  - This they need their own logic for:
    - Sending frames
    - Dmabuf Feedback
    - Primary outputs
    - On commit handlers
    - cursor tests
  - They get their own unmap/remap logic
  - They get a new restore state similar to minimized windows
    - Refactored the minimized window state to reuse as much as possible
      here
  - They need to be part of focus stacks, which means adjusting them
    to a new type `FocusTarget` as they previously only handled
    `CosmicMapped`.
  - Various shell handlers (minimize, move, menu) now have dedicated
    logic for fullscreen surfaces
    - This was partially necessary due to relying on CosmicSurface now,
      partially because they should've had their own logic from the
      start. E.g. the context menu is now reflecting the fullscreen
      state
- Fullscreen windows may be rendered behind other windows now, when they
  loose focus.
  - This needed changes to input handling / rendering
This commit is contained in:
Victoria Brekenfeld 2025-06-25 17:54:27 +02:00 committed by Victoria Brekenfeld
parent 8ef6c161a0
commit adedb705e7
23 changed files with 2554 additions and 1796 deletions

View file

@ -20,7 +20,7 @@ use smithay::{
ImportAll, ImportMem, Renderer,
},
},
desktop::{space::SpaceElement, PopupManager, WindowSurfaceType},
desktop::{space::SpaceElement, WindowSurfaceType},
input::{
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
Seat,
@ -31,10 +31,7 @@ use smithay::{
utils::{
Buffer as BufferCoords, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size,
},
wayland::{
compositor::{with_surface_tree_downward, TraversalAction},
seat::WaylandFocus,
},
wayland::seat::WaylandFocus,
xwayland::{xwm::X11Relatable, X11Surface},
};
use stack::CosmicStackInternal;
@ -245,7 +242,10 @@ impl CosmicMapped {
.cloned()
}
pub fn set_active(&self, window: &CosmicSurface) {
pub fn set_active<S>(&self, window: &S)
where
CosmicSurface: PartialEq<S>,
{
if let CosmicMappedInternal::Stack(stack) = &self.element {
stack.set_active(window);
}
@ -259,41 +259,8 @@ impl CosmicMapped {
}
pub fn has_surface(&self, surface: &WlSurface, surface_type: WindowSurfaceType) -> bool {
self.windows().any(|(w, _)| {
let Some(toplevel) = w.wl_surface() else {
return false;
};
if surface_type.contains(WindowSurfaceType::TOPLEVEL) {
if *toplevel == *surface {
return true;
}
}
if surface_type.contains(WindowSurfaceType::SUBSURFACE) {
use std::sync::atomic::Ordering;
let found = AtomicBool::new(false);
with_surface_tree_downward(
&toplevel,
surface,
|_, _, search| TraversalAction::DoChildren(search),
|s, _, search| {
found.fetch_or(s == *search, Ordering::SeqCst);
},
|_, _, _| !found.load(Ordering::SeqCst),
);
if found.load(Ordering::SeqCst) {
return true;
}
}
if surface_type.contains(WindowSurfaceType::POPUP) {
PopupManager::popups_for_surface(&toplevel).any(|(p, _)| p.wl_surface() == surface)
} else {
false
}
})
self.windows()
.any(|(w, _)| w.has_surface(surface, surface_type))
}
/// Give the pointer target under a relative offset into this element.

View file

@ -455,7 +455,10 @@ impl CosmicStack {
.with_program(|p| p.group_focused.load(Ordering::SeqCst))
}
pub fn set_active(&self, window: &CosmicSurface) {
pub fn set_active<S>(&self, window: &S)
where
CosmicSurface: PartialEq<S>,
{
self.0.with_program(|p| {
if let Some(val) = p.windows.lock().unwrap().iter().position(|w| w == window) {
let old = p.active.swap(val, Ordering::SeqCst);

View file

@ -18,7 +18,8 @@ use smithay::{
ImportAll, Renderer,
},
desktop::{
space::SpaceElement, utils::OutputPresentationFeedback, PopupManager, Window, WindowSurface,
space::SpaceElement, utils::OutputPresentationFeedback, PopupManager, Window,
WindowSurface, WindowSurfaceType,
},
input::{
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
@ -40,7 +41,7 @@ use smithay::{
user_data::UserDataMap, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size,
},
wayland::{
compositor::{with_states, SurfaceData},
compositor::{with_states, with_surface_tree_downward, SurfaceData, TraversalAction},
seat::WaylandFocus,
shell::xdg::{SurfaceCachedState, ToplevelSurface, XdgToplevelSurfaceData},
},
@ -54,7 +55,7 @@ use crate::{
wayland::handlers::decoration::{KdeDecorationData, PreferredDecorationMode},
};
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Hash, Eq)]
pub struct CosmicSurface(pub Window);
impl From<ToplevelSurface> for CosmicSurface {
@ -81,6 +82,13 @@ impl PartialEq<WlSurface> for CosmicSurface {
}
}
impl PartialEq<ToplevelSurface> for CosmicSurface {
fn eq(&self, other: &ToplevelSurface) -> bool {
self.wl_surface()
.map_or(false, |s| &*s == other.wl_surface())
}
}
impl PartialEq<X11Surface> for CosmicSurface {
fn eq(&self, other: &X11Surface) -> bool {
self.x11_surface().map_or(false, |s| s == other)
@ -602,6 +610,42 @@ impl CosmicSurface {
}
}
pub fn has_surface(&self, surface: &WlSurface, surface_type: WindowSurfaceType) -> bool {
let Some(toplevel) = self.wl_surface() else {
return false;
};
if surface_type.contains(WindowSurfaceType::TOPLEVEL) {
if *toplevel == *surface {
return true;
}
}
if surface_type.contains(WindowSurfaceType::SUBSURFACE) {
use std::sync::atomic::Ordering;
let found = AtomicBool::new(false);
with_surface_tree_downward(
&toplevel,
surface,
|_, _, search| TraversalAction::DoChildren(search),
|s, _, search| {
found.fetch_or(s == *search, Ordering::SeqCst);
},
|_, _, _| !found.load(Ordering::SeqCst),
);
if found.load(Ordering::SeqCst) {
return true;
}
}
if surface_type.contains(WindowSurfaceType::POPUP) {
PopupManager::popups_for_surface(&toplevel).any(|(p, _)| p.wl_surface() == surface)
} else {
false
}
}
pub fn on_commit(&self) {
self.0.on_commit();
}

View file

@ -468,9 +468,7 @@ impl Program for CosmicWindowInternal {
if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) {
loop_handle.insert_idle(move |state| {
let mut shell = state.common.shell.write();
if let Some(mapped) = shell.element_for_surface(&surface).cloned() {
shell.minimize_request(&mapped)
}
shell.minimize_request(&surface)
});
}
}
@ -480,7 +478,7 @@ impl Program for CosmicWindowInternal {
let mut shell = state.common.shell.write();
if let Some(mapped) = shell.element_for_surface(&surface).cloned() {
let seat = shell.seats.last_active().clone();
shell.maximize_toggle(&mapped, &seat)
shell.maximize_toggle(&mapped, &seat, &state.common.event_loop_handle)
}
});
}

View file

@ -1,5 +1,5 @@
use crate::{
shell::{element::CosmicMapped, Shell},
shell::{element::CosmicMapped, CosmicSurface, MinimizedWindow, Shell},
state::Common,
utils::prelude::*,
wayland::handlers::{xdg_shell::PopupGrabData, xwayland_keyboard_grab::XWaylandGrabSeatData},
@ -9,7 +9,7 @@ use smithay::{
desktop::{layer_map_for_output, PopupUngrabStrategy},
input::{pointer::MotionEvent, Seat},
output::Output,
reexports::wayland_server::Resource,
reexports::wayland_server::{protocol::wl_surface::WlSurface, Resource},
utils::{IsAlive, Point, Serial, SERIAL_COUNTER},
wayland::{
seat::WaylandFocus,
@ -29,18 +29,80 @@ use super::{grabs::SeatMoveGrabState, layout::floating::FloatingLayout, SeatExt}
mod order;
pub mod target;
pub struct FocusStack<'a>(pub(super) Option<&'a IndexSet<CosmicMapped>>);
pub struct FocusStackMut<'a>(pub(super) &'a mut IndexSet<CosmicMapped>);
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub enum FocusTarget {
Window(CosmicMapped),
Fullscreen(CosmicSurface),
}
impl PartialEq<CosmicMapped> for FocusTarget {
fn eq(&self, other: &CosmicMapped) -> bool {
matches!(self, FocusTarget::Window(mapped) if mapped == other)
}
}
impl PartialEq<CosmicSurface> for FocusTarget {
fn eq(&self, other: &CosmicSurface) -> bool {
matches!(self, FocusTarget::Fullscreen(surface) if surface == other)
}
}
impl From<CosmicMapped> for FocusTarget {
fn from(value: CosmicMapped) -> Self {
Self::Window(value)
}
}
impl From<CosmicSurface> for FocusTarget {
fn from(value: CosmicSurface) -> Self {
Self::Fullscreen(value)
}
}
impl Into<KeyboardFocusTarget> for FocusTarget {
fn into(self) -> KeyboardFocusTarget {
match self {
FocusTarget::Window(mapped) => KeyboardFocusTarget::Element(mapped),
FocusTarget::Fullscreen(surface) => KeyboardFocusTarget::Fullscreen(surface),
}
}
}
impl FocusTarget {
pub fn alive(&self) -> bool {
match self {
FocusTarget::Window(mapped) => mapped.alive(),
FocusTarget::Fullscreen(surface) => surface.alive(),
}
}
fn is_minimized(&self) -> bool {
match self {
FocusTarget::Window(mapped) => mapped.is_minimized(),
FocusTarget::Fullscreen(surface) => surface.is_minimized(),
}
}
pub fn wl_surface(&self) -> Option<WlSurface> {
match self {
FocusTarget::Window(mapped) => mapped.active_window().wl_surface().map(Cow::into_owned),
FocusTarget::Fullscreen(surface) => surface.wl_surface().map(Cow::into_owned),
}
}
}
pub struct FocusStack<'a>(pub(super) Option<&'a IndexSet<FocusTarget>>);
pub struct FocusStackMut<'a>(pub(super) &'a mut IndexSet<FocusTarget>);
impl<'a> FocusStack<'a> {
/// returns the last unminimized window in the focus stack that is still alive
pub fn last(&self) -> Option<&CosmicMapped> {
pub fn last(&self) -> Option<&FocusTarget> {
self.0
.as_ref()
.and_then(|set| set.iter().rev().find(|w| w.alive() && !w.is_minimized()))
}
pub fn iter(&self) -> impl Iterator<Item = &'_ CosmicMapped> {
pub fn iter(&self) -> impl Iterator<Item = &'_ FocusTarget> {
self.0
.iter()
.flat_map(|set| set.iter().rev().filter(|w| w.alive() && !w.is_minimized()))
@ -48,21 +110,25 @@ impl<'a> FocusStack<'a> {
}
impl<'a> FocusStackMut<'a> {
pub fn append(&mut self, window: &CosmicMapped) {
pub fn append(&mut self, target: impl Into<FocusTarget>) {
let target = target.into();
self.0.retain(|w| w.alive());
self.0.shift_remove(window);
self.0.insert(window.clone());
self.0.shift_remove(&target);
self.0.insert(target);
}
pub fn remove(&mut self, window: &CosmicMapped) {
self.0.retain(|w| w != window);
pub fn remove<T>(&mut self, target: &T)
where
FocusTarget: PartialEq<T>,
{
self.0.retain(|w| w != target);
}
pub fn last(&self) -> Option<&CosmicMapped> {
pub fn last(&self) -> Option<&FocusTarget> {
self.0.iter().rev().find(|w| w.alive() && !w.is_minimized())
}
pub fn iter(&self) -> impl Iterator<Item = &'_ CosmicMapped> {
pub fn iter(&self) -> impl Iterator<Item = &'_ FocusTarget> {
self.0
.iter()
.rev()
@ -107,23 +173,16 @@ impl Shell {
serial: Option<Serial>,
update_cursor: bool,
) {
let element = match target {
Some(KeyboardFocusTarget::Element(mapped)) => Some(mapped.clone()),
Some(KeyboardFocusTarget::Fullscreen(window)) => state
.common
.shell
.read()
.element_for_surface(window)
.cloned(),
let focus_target = match target {
Some(KeyboardFocusTarget::Element(mapped)) => Some(FocusTarget::Window(mapped.clone())),
Some(KeyboardFocusTarget::Fullscreen(surface)) => {
Some(FocusTarget::Fullscreen(surface.clone()))
}
_ => None,
};
if let Some(mapped) = element {
if mapped.is_minimized() {
return;
}
state.common.shell.write().append_focus_stack(&mapped, seat);
if let Some(target) = focus_target {
state.common.shell.write().append_focus_stack(target, seat);
}
update_focus_state(seat, target, state, serial, update_cursor);
@ -131,25 +190,30 @@ impl Shell {
state.common.shell.write().update_active();
}
pub fn append_focus_stack(&mut self, mapped: &CosmicMapped, seat: &Seat<State>) {
if mapped.is_minimized() {
pub fn append_focus_stack(&mut self, target: impl Into<FocusTarget>, seat: &Seat<State>) {
let target = target.into();
if target.is_minimized() {
return;
}
// update FocusStack and notify layouts about new focus (if any window)
let workspace = self.space_for_mut(&mapped);
let workspace = target
.wl_surface()
.and_then(|surface| self.workspace_for_surface(&surface));
let workspace = if workspace.is_none() {
//should this be the active output or the focused output?
self.active_space_mut(&seat.focused_or_active_output())
.unwrap()
} else {
workspace.unwrap()
self.workspaces
.space_for_handle_mut(&workspace.unwrap().0)
.unwrap()
};
let mut focus_stack = workspace.focus_stack.get_mut(seat);
if Some(mapped) != focus_stack.last() {
trace!(?mapped, "Focusing window.");
focus_stack.append(&mapped);
if Some(&target) != focus_stack.last() {
trace!(?target, "Focusing window.");
focus_stack.append(target);
// also remove popup grabs, if we are switching focus
if let Some(mut popup_grab) = seat
.user_data()
@ -171,7 +235,7 @@ impl Shell {
.map(|seat| {
if matches!(
seat.get_keyboard().unwrap().current_focus(),
Some(KeyboardFocusTarget::Group(_))
Some(KeyboardFocusTarget::Group(_)) | Some(KeyboardFocusTarget::LockSurface(_))
) {
return None;
}
@ -179,7 +243,10 @@ impl Shell {
let output = seat.focused_or_active_output();
let space = self.active_space(&output).unwrap();
let stack = space.focus_stack.get(seat);
stack.last().cloned()
stack.last().and_then(|target| match target {
FocusTarget::Window(window) => Some(window.clone()),
FocusTarget::Fullscreen(_) => None,
})
})
.flatten()
.collect::<Vec<_>>();
@ -193,12 +260,33 @@ impl Shell {
window.set_activated(focused_windows.contains(&window));
window.configure();
}
for m in set.minimized_windows.iter() {
m.window.set_activated(false);
m.window.configure();
for window in set
.minimized_windows
.iter()
.flat_map(MinimizedWindow::mapped)
{
window.set_activated(false);
window.configure();
}
let workspace = &mut set.workspaces[set.active];
if let Some(fullscreen) = workspace.get_fullscreen() {
if self.seats.iter().any(|seat| {
if let Some(KeyboardFocusTarget::Fullscreen(s)) =
seat.get_keyboard().unwrap().current_focus()
{
&s == fullscreen
} else {
false
}
}) {
fullscreen.set_activated(true);
fullscreen.send_configure();
} else {
fullscreen.set_activated(false);
fullscreen.send_configure();
}
}
for focused in focused_windows.iter() {
raise_with_children(&mut workspace.floating_layer, focused);
}
@ -207,8 +295,15 @@ impl Shell {
window.configure();
}
for m in workspace.minimized_windows.iter() {
m.window.set_activated(false);
m.window.configure();
if let Some(window) = m.mapped() {
window.set_activated(false);
window.configure();
} else {
for surface in m.windows() {
surface.set_activated(false);
surface.send_configure();
}
}
}
for (i, workspace) in set.workspaces.iter().enumerate() {
@ -515,13 +610,11 @@ fn focus_target_is_valid(
let workspace = shell.active_space(&output).unwrap();
let focus_stack = workspace.focus_stack.get(&seat);
let is_in_focus_stack = focus_stack.last().map(|m| m == &mapped).unwrap_or(false);
let has_fullscreen = workspace.get_fullscreen().is_some();
if is_sticky && !is_in_focus_stack {
shell.append_focus_stack(&mapped, seat);
shell.append_focus_stack(mapped, seat);
}
(is_sticky || is_in_focus_stack) && !has_fullscreen
is_sticky || is_in_focus_stack
}
KeyboardFocusTarget::LayerSurface(layer) => {
layer_map_for_output(&output).layers().any(|l| l == &layer)
@ -535,13 +628,7 @@ fn focus_target_is_valid(
.has_node(&node),
KeyboardFocusTarget::Fullscreen(window) => {
let workspace = shell.active_space(&output).unwrap();
let focus_stack = workspace.focus_stack.get(&seat);
focus_stack
.last()
.map(|m| m.has_active_window(&window))
.unwrap_or(false)
&& workspace.get_fullscreen().is_some()
workspace.get_fullscreen().is_some_and(|w| w == &window)
}
KeyboardFocusTarget::Popup(_) => true,
KeyboardFocusTarget::LockSurface(_) => false,
@ -579,8 +666,6 @@ fn update_focus_target(
})
.cloned()
.map(KeyboardFocusTarget::from)
} else if let Some(surface) = shell.active_space(&output).unwrap().get_fullscreen() {
Some(KeyboardFocusTarget::Fullscreen(surface.clone()))
} else {
shell
.active_space(&output)
@ -588,9 +673,23 @@ fn update_focus_target(
.focus_stack
.get(&seat)
.last()
.or_else(|| shell.active_space(&output).unwrap().mapped().next())
.cloned()
.map(KeyboardFocusTarget::from)
.map(Into::<KeyboardFocusTarget>::into)
.or_else(|| {
let workspace = shell.active_space(&output).unwrap();
workspace
.mapped()
.next()
.cloned()
.map(KeyboardFocusTarget::Element)
.or_else(|| {
workspace
.get_fullscreen()
.cloned()
.map(KeyboardFocusTarget::Fullscreen)
})
})
}
}

View file

@ -13,10 +13,15 @@ use smithay::{
use crate::{
backend::render::ElementFilter,
shell::{
focus::target::KeyboardFocusTarget,
layout::{floating::FloatingLayout, tiling::ANIMATION_DURATION},
Shell, Workspace, WorkspaceDelta,
SeatExt, Shell, Workspace, WorkspaceDelta,
},
utils::{
geometry::*,
prelude::OutputExt,
quirks::{workspace_overview_is_open, WORKSPACE_OVERVIEW_NAMESPACE},
},
utils::{geometry::*, prelude::OutputExt, quirks::WORKSPACE_OVERVIEW_NAMESPACE},
wayland::protocols::workspace::WorkspaceHandle,
};
@ -105,11 +110,32 @@ fn render_input_order_internal<R: 'static>(
return ControlFlow::Break(Err(OutputNoMode));
};
let output_size = output.geometry().size;
let has_fullscreen = workspace
.fullscreen
.as_ref()
.filter(|f| !f.is_animating())
.is_some();
// this is more hacky than I would like..
let fullscreen = workspace.fullscreen.as_ref().filter(|f| !f.is_animating());
let seat = shell.seats.last_active();
let is_active_workspace = seat.focused_output().is_some_and(|output| {
shell
.active_space(&output)
.is_some_and(|w| w.handle == workspace.handle)
});
let focus_stack_is_valid_fullscreen = workspace
.focus_stack
.get(seat)
.last()
.zip(fullscreen)
.is_some_and(|(target, fullscreen)| target == &fullscreen.surface);
let overview_is_open = workspace_overview_is_open(&output);
let has_focused_fullscreen = if is_active_workspace {
let current_focus = seat.get_keyboard().unwrap().current_focus();
matches!(current_focus, Some(KeyboardFocusTarget::Fullscreen(_)))
|| (current_focus.is_none()
&& focus_stack_is_valid_fullscreen
&& !workspace_overview_is_open(&output))
} else {
focus_stack_is_valid_fullscreen && !overview_is_open
};
let has_fullscreen = fullscreen.is_some() && !overview_is_open;
let (previous, current_offset) = match previous.as_ref() {
Some((previous, previous_idx, start)) => {
@ -163,7 +189,7 @@ fn render_input_order_internal<R: 'static>(
};
// Top-level layer shell popups
if !has_fullscreen {
if !has_focused_fullscreen {
for (layer, popup, location) in layer_popups(output, Layer::Top, element_filter) {
callback(Stage::LayerPopup {
layer,
@ -193,7 +219,7 @@ fn render_input_order_internal<R: 'static>(
}
// sticky window popups
if !has_fullscreen {
if !has_focused_fullscreen {
callback(Stage::StickyPopups(&set.sticky_layer))?;
}
}
@ -222,7 +248,7 @@ fn render_input_order_internal<R: 'static>(
})?;
}
if !has_fullscreen {
if !has_focused_fullscreen {
// bottom layer popups
for (layer, popup, location) in layer_popups(output, Layer::Bottom, element_filter) {
callback(Stage::LayerPopup {
@ -271,7 +297,7 @@ fn render_input_order_internal<R: 'static>(
}
}
if !has_fullscreen {
if !has_focused_fullscreen {
// top-layer shell
for (layer, location) in layer_surfaces(output, Layer::Top, element_filter) {
callback(Stage::LayerSurface { layer, location })?;
@ -302,7 +328,7 @@ fn render_input_order_internal<R: 'static>(
}
}
if !has_fullscreen {
if !has_focused_fullscreen {
// bottom layer
for (layer, mut location) in layer_surfaces(output, Layer::Bottom, element_filter) {
location += current_offset.as_global();

View file

@ -181,6 +181,15 @@ impl KeyboardFocusTarget {
}
}
pub fn windows(&self) -> impl Iterator<Item = CosmicSurface> + '_ {
match self {
KeyboardFocusTarget::Element(mapped) => Box::new(mapped.windows().map(|(s, _)| s))
as Box<dyn Iterator<Item = CosmicSurface>>,
KeyboardFocusTarget::Fullscreen(surface) => Box::new(std::iter::once(surface.clone())),
_ => Box::new(std::iter::empty()),
}
}
pub fn is_xwm(&self, xwm: XwmId) -> bool {
match self {
KeyboardFocusTarget::Element(mapped) => {

View file

@ -1,5 +1,8 @@
use cosmic_settings_config::shortcuts::Action;
use smithay::{input::pointer::MotionEvent, utils::SERIAL_COUNTER, wayland::seat::WaylandFocus};
use smithay::{
input::pointer::MotionEvent, reexports::wayland_server::protocol::wl_surface::WlSurface,
utils::SERIAL_COUNTER, wayland::seat::WaylandFocus,
};
use crate::{
config::Config,
@ -11,6 +14,7 @@ use crate::{
},
state::State,
utils::{prelude::SeatExt, screenshot::screenshot_window},
wayland::protocols::workspace::WorkspaceHandle,
};
use super::{Item, ResizeEdge};
@ -24,69 +28,136 @@ fn toggle_stacking(state: &mut State, mapped: &CosmicMapped) {
}
}
fn move_prev_workspace(state: &mut State, mapped: &CosmicMapped) {
let mut shell = state.common.shell.write();
let seat = shell.seats.last_active().clone();
let (current_handle, output) = {
let Some(ws) = shell.space_for(mapped) else {
return;
};
(ws.handle, ws.output.clone())
};
let maybe_handle = shell
fn prev_workspace(
shell: &Shell,
surface: &WlSurface,
) -> Option<(WorkspaceHandle, WorkspaceHandle)> {
let (current_handle, output) = shell.workspace_for_surface(surface)?;
shell
.workspaces
.spaces_for_output(&output)
.enumerate()
.find_map(|(i, space)| (space.handle == current_handle).then_some(i))
.and_then(|i| i.checked_sub(1))
.and_then(|i| shell.workspaces.get(i, &output).map(|s| s.handle));
if let Some(prev_handle) = maybe_handle {
let res = shell.move_window(
Some(&seat),
mapped,
&current_handle,
&prev_handle,
true,
None,
&mut state.common.workspace_state.update(),
);
if let Some((target, _)) = res {
std::mem::drop(shell);
Shell::set_focus(state, Some(&target), &seat, None, true);
}
}
.and_then(|i| shell.workspaces.get(i, &output))
.map(|space| (current_handle, space.handle))
}
fn move_next_workspace(state: &mut State, mapped: &CosmicMapped) {
let mut shell = state.common.shell.write();
let seat = shell.seats.last_active().clone();
let (current_handle, output) = {
let Some(ws) = shell.space_for(mapped) else {
return;
};
(ws.handle, ws.output.clone())
};
let maybe_handle = shell
fn next_workspace(
shell: &Shell,
surface: &WlSurface,
) -> Option<(WorkspaceHandle, WorkspaceHandle)> {
let (current_handle, output) = shell.workspace_for_surface(surface)?;
shell
.workspaces
.spaces_for_output(&output)
.skip_while(|space| space.handle != current_handle)
.skip(1)
.next()
.map(|space| space.handle);
if let Some(next_handle) = maybe_handle {
let res = shell.move_window(
Some(&seat),
mapped,
&current_handle,
&next_handle,
true,
None,
&mut state.common.workspace_state.update(),
);
if let Some((target, _point)) = res {
std::mem::drop(shell);
Shell::set_focus(state, Some(&target), &seat, None, true)
}
.map(|space| (current_handle, space.handle))
}
fn move_fullscreen_prev_workspace(state: &mut State, surface: &CosmicSurface) {
let mut shell = state.common.shell.write();
let Some(wl_surface) = surface.wl_surface() else {
return;
};
let Some((from, to)) = prev_workspace(&shell, &*wl_surface) else {
return;
};
let seat = shell.seats.last_active().clone();
let res = shell.move_window(
Some(&seat),
surface,
&from,
&to,
true,
None,
&mut state.common.workspace_state.update(),
&state.common.event_loop_handle,
);
if let Some((target, _)) = res {
std::mem::drop(shell);
Shell::set_focus(state, Some(&target), &seat, None, true);
}
}
fn move_fullscreen_next_workspace(state: &mut State, surface: &CosmicSurface) {
let mut shell = state.common.shell.write();
let Some(wl_surface) = surface.wl_surface() else {
return;
};
let Some((from, to)) = next_workspace(&shell, &*wl_surface) else {
return;
};
let seat = shell.seats.last_active().clone();
let res = shell.move_window(
Some(&seat),
surface,
&from,
&to,
true,
None,
&mut state.common.workspace_state.update(),
&state.common.event_loop_handle,
);
if let Some((target, _)) = res {
std::mem::drop(shell);
Shell::set_focus(state, Some(&target), &seat, None, true);
}
}
fn move_element_prev_workspace(state: &mut State, mapped: &CosmicMapped) {
let mut shell = state.common.shell.write();
let window = mapped.active_window();
let Some(wl_surface) = window.wl_surface() else {
return;
};
let Some((from, to)) = prev_workspace(&shell, &*wl_surface) else {
return;
};
let seat = shell.seats.last_active().clone();
let res = shell.move_element(
Some(&seat),
mapped,
&from,
&to,
true,
None,
&mut state.common.workspace_state.update(),
);
if let Some((target, _)) = res {
std::mem::drop(shell);
Shell::set_focus(state, Some(&target), &seat, None, true);
}
}
fn move_element_next_workspace(state: &mut State, mapped: &CosmicMapped) {
let mut shell = state.common.shell.write();
let window = mapped.active_window();
let Some(wl_surface) = window.wl_surface() else {
return;
};
let Some((from, to)) = next_workspace(&shell, &*wl_surface) else {
return;
};
let seat = shell.seats.last_active().clone();
let res = shell.move_element(
Some(&seat),
mapped,
&from,
&to,
true,
None,
&mut state.common.workspace_state.update(),
);
if let Some((target, _point)) = res {
std::mem::drop(shell);
Shell::set_focus(state, Some(&target), &seat, None, true)
}
}
@ -198,7 +269,11 @@ pub fn window_items(
Item::new(fl!("window-menu-minimize"), move |handle| {
let mapped = minimize_clone.clone();
let _ = handle.insert_idle(move |state| {
state.common.shell.write().minimize_request(&mapped);
state
.common
.shell
.write()
.minimize_request(&mapped.active_window());
});
})
.shortcut(config.shortcut_for_action(&Action::Minimize)),
@ -209,7 +284,7 @@ pub fn window_items(
let _ = handle.insert_idle(move |state| {
let mut shell = state.common.shell.write();
let seat = shell.seats.last_active().clone();
shell.maximize_toggle(&mapped, &seat);
shell.maximize_toggle(&mapped, &seat, &state.common.event_loop_handle);
});
})
.shortcut(config.shortcut_for_action(&Action::Maximize))
@ -422,7 +497,8 @@ pub fn window_items(
Some(
Item::new(fl!("window-menu-move-prev-workspace"), move |handle| {
let mapped = move_prev_clone.clone();
let _ = handle.insert_idle(move |state| move_prev_workspace(state, &mapped));
let _ =
handle.insert_idle(move |state| move_element_prev_workspace(state, &mapped));
})
.shortcut(config.shortcut_for_action(&Action::MoveToPreviousWorkspace))
.disabled(is_sticky),
@ -430,7 +506,8 @@ pub fn window_items(
Some(
Item::new(fl!("window-menu-move-next-workspace"), move |handle| {
let mapped = move_next_clone.clone();
let _ = handle.insert_idle(move |state| move_next_workspace(state, &mapped));
let _ =
handle.insert_idle(move |state| move_element_next_workspace(state, &mapped));
})
.shortcut(config.shortcut_for_action(&Action::MoveToNextWorkspace))
.disabled(is_sticky),
@ -466,3 +543,105 @@ pub fn window_items(
.into_iter()
.flatten()
}
pub fn fullscreen_items(window: &CosmicSurface, config: &Config) -> impl Iterator<Item = Item> {
let minimize_clone = window.clone();
let fullscreen_clone = window.clone();
let move_prev_clone = window.clone();
let move_next_clone = window.clone();
let move_clone = window.clone();
let screenshot_clone = window.clone();
let close_clone = window.clone();
vec![
Some(
Item::new(fl!("window-menu-minimize"), move |handle| {
let window = minimize_clone.clone();
let _ = handle.insert_idle(move |state| {
state.common.shell.write().minimize_request(&window);
});
})
.shortcut(config.shortcut_for_action(&Action::Minimize)),
),
Some(
Item::new(fl!("window-menu-fullscreen"), move |handle| {
let window = fullscreen_clone.clone();
let _ = handle.insert_idle(move |state| {
let mut shell = state.common.shell.write();
shell.unfullscreen_request(&window, &state.common.event_loop_handle);
});
})
//.shortcut(config.shortcut_for_action(&Action::Fullscreen))
.toggled(true),
),
Some(Item::Separator),
// TODO: Where to save?
Some(Item::new(fl!("window-menu-screenshot"), move |handle| {
let window = screenshot_clone.clone();
let _ = handle.insert_idle(move |state| screenshot_window(state, &window));
})),
Some(Item::Separator),
Some(Item::new(fl!("window-menu-move"), move |handle| {
let move_clone = move_clone.clone();
let _ = handle.insert_idle(move |state| {
if let Some(surface) = move_clone.wl_surface() {
let mut shell = state.common.shell.write();
let seat = shell.seats.last_active().clone();
let res = shell.move_request(
&surface,
&seat,
None,
ReleaseMode::Click,
false,
&state.common.config,
&state.common.event_loop_handle,
false,
);
std::mem::drop(shell);
if let Some((grab, focus)) = res {
if grab.is_touch_grab() {
seat.get_touch().unwrap().set_grab(
state,
grab,
SERIAL_COUNTER.next_serial(),
)
} else {
seat.get_pointer().unwrap().set_grab(
state,
grab,
SERIAL_COUNTER.next_serial(),
focus,
);
}
}
}
});
})),
Some(
Item::new(fl!("window-menu-move-prev-workspace"), move |handle| {
let window = move_prev_clone.clone();
let _ =
handle.insert_idle(move |state| move_fullscreen_prev_workspace(state, &window));
})
.shortcut(config.shortcut_for_action(&Action::MoveToPreviousWorkspace)),
),
Some(
Item::new(fl!("window-menu-move-next-workspace"), move |handle| {
let window = move_next_clone.clone();
let _ =
handle.insert_idle(move |state| move_fullscreen_next_workspace(state, &window));
})
.shortcut(config.shortcut_for_action(&Action::MoveToNextWorkspace)),
),
Some(Item::Separator),
Some(
Item::new(fl!("window-menu-close"), move |_handle| {
close_clone.close();
})
.shortcut(config.shortcut_for_action(&Action::Close)),
),
]
.into_iter()
.flatten()
}

View file

@ -432,7 +432,8 @@ impl MoveGrab {
}
}
let indicator_location = shell.stacking_indicator(&current_output, self.previous);
let indicator_location =
shell.stacking_indicator(&current_output, self.previous.clone());
if indicator_location.is_some() != grab_state.stacking_indicator.is_some() {
grab_state.stacking_indicator = indicator_location.map(|geo| {
let element = stack_hover(
@ -731,7 +732,7 @@ impl MoveGrab {
start: Instant::now(),
stacking_indicator: None,
snapping_zone: None,
previous: previous_layer,
previous: previous_layer.clone(),
location: start_data.location(),
cursor_output: cursor_output.clone(),
};
@ -779,7 +780,7 @@ impl Drop for MoveGrab {
let output = self.cursor_output.clone();
let seat = self.seat.clone();
let window_outputs = self.window_outputs.drain().collect::<HashSet<_>>();
let previous = self.previous;
let previous = self.previous.clone();
let window = self.window.clone();
let is_touch_grab = matches!(self.start_data, GrabStartData::Touch(_));
@ -841,10 +842,14 @@ impl Drop for MoveGrab {
window_location.to_local(&workspace.output),
);
if previous == ManagedLayer::Floating {
if matches!(previous, ManagedLayer::Floating) {
if let Some(sz) = grab_state.snapping_zone {
if sz == SnappingZone::Maximize {
shell.maximize_toggle(&window, &seat);
shell.maximize_toggle(
&window,
&seat,
&state.common.event_loop_handle,
);
} else {
let directions = match sz {
SnappingZone::Maximize => vec![],

View file

@ -627,78 +627,46 @@ impl FloatingLayout {
);
}
pub fn unmap(&mut self, window: &CosmicMapped) -> Option<Size<i32, Logical>> {
let mut new_size = None;
pub fn unmap(
&mut self,
window: &CosmicMapped,
to: Option<Rectangle<i32, Local>>,
) -> Option<Rectangle<i32, Local>> {
let _ = self.animations.remove(window);
let Some(mut mapped_geometry) = self.space.element_geometry(window).map(RectExt::as_local)
else {
return None;
};
if let Some(_) = window.floating_tiled.lock().unwrap().take() {
if let Some(last_size) = window.last_geometry.lock().unwrap().map(|geo| geo.size) {
if let Some(location) = self.space.element_location(window) {
window.set_tiled(false);
window.set_geometry(
Rectangle::new(location, last_size.as_logical())
.as_local()
.to_global(self.space.outputs().next().unwrap()),
);
window.configure();
new_size = Some(last_size.as_logical());
}
}
} else if !window.is_maximized(true) && !window.is_fullscreen(true) {
if let Some(location) = self.space.element_location(window) {
*window.last_geometry.lock().unwrap() = Some(
Rectangle::new(
location,
window
.pending_size()
.unwrap_or_else(|| window.geometry().size),
)
.as_local(),
)
let geometry = Rectangle::new(mapped_geometry.loc, last_size);
window.set_tiled(false);
window.set_geometry(geometry.to_global(self.space.outputs().next().unwrap()));
window.configure();
mapped_geometry.size = last_size;
}
} else if !window.is_maximized(true) {
*window.last_geometry.lock().unwrap() = Some(mapped_geometry);
}
let _ = self.animations.remove(window);
let was_unmaped = self.space.elements().any(|e| e == window);
self.space.unmap_elem(&window);
if was_unmaped {
if let Some(pos) = self.spawn_order.iter().position(|w| w == window) {
self.spawn_order.truncate(pos);
}
window.moved_since_mapped.store(true, Ordering::SeqCst);
Some(new_size.unwrap_or_else(|| window.geometry().size))
} else {
None
}
}
pub fn unmap_minimize(
&mut self,
window: &CosmicMapped,
to: Rectangle<i32, Local>,
) -> Option<(CosmicMapped, Point<i32, Local>)> {
let previous_geometry = self.space.element_geometry(window);
self.space.unmap_elem(&window);
if let Some(previous_geometry) = previous_geometry {
if let Some(pos) = self.spawn_order.iter().position(|w| w == window) {
self.spawn_order.truncate(pos);
}
window.moved_since_mapped.store(true, Ordering::SeqCst);
if let Some(to) = to {
self.animations.insert(
window.clone(),
Animation::Minimize {
start: Instant::now(),
previous_geometry: previous_geometry.as_local(),
previous_geometry: mapped_geometry,
target_geometry: to,
},
);
window.set_minimized(true);
Some((window.clone(), previous_geometry.loc.as_local()))
} else {
None
}
self.space.unmap_elem(&window);
if let Some(pos) = self.spawn_order.iter().position(|w| w == window) {
self.spawn_order.truncate(pos);
}
window.moved_since_mapped.store(true, Ordering::SeqCst);
Some(mapped_geometry)
}
pub fn drop_window(
@ -1027,7 +995,7 @@ impl FloatingLayout {
Some(geo.size),
None,
);
focus_stack.append(&mapped);
focus_stack.append(mapped.clone());
Some(KeyboardFocusTarget::Element(mapped))
} else {
// if we have a stack
@ -1068,7 +1036,7 @@ impl FloatingLayout {
self.space.refresh();
for elem in new_elements.into_iter().rev() {
focus_stack.append(&elem);
focus_stack.append(elem);
}
Some(KeyboardFocusTarget::Element(mapped))

View file

@ -18,7 +18,7 @@ use crate::{
},
focus::{
target::{KeyboardFocusTarget, PointerFocusTarget, WindowGroup},
FocusStackMut,
FocusStackMut, FocusTarget,
},
grabs::ResizeEdge,
layout::Orientation,
@ -130,7 +130,7 @@ impl TreeQueue {
pub struct TilingLayout {
output: Output,
queue: TreeQueue,
placeholder_id: Id,
backdrop_id: Id,
swapping_stack_surface_id: Id,
last_overview_hover: Option<(Option<Instant>, TargetZone)>,
pub theme: cosmic::Theme,
@ -157,11 +157,18 @@ pub enum Data {
minimize_rect: Option<Rectangle<i32, Local>>,
},
Placeholder {
id: Id,
last_geometry: Rectangle<i32, Local>,
initial_placeholder: bool,
type_: PlaceholderType,
},
}
#[derive(Debug, Clone)]
pub enum PlaceholderType {
GrabbedWindow,
DropZone,
}
impl Data {
fn new_group(orientation: Orientation, geo: Rectangle<i32, Local>) -> Data {
Data::Group {
@ -331,8 +338,8 @@ enum FocusedNodeData {
Window(CosmicMapped),
}
#[derive(Debug)]
pub struct MinimizedTilingState {
#[derive(Debug, Clone)]
pub struct RestoreTilingState {
pub parent: Option<id_tree::NodeId>,
pub sibling: Option<id_tree::NodeId>,
pub orientation: Orientation,
@ -352,7 +359,7 @@ impl TilingLayout {
animation_start: None,
},
output: output.clone(),
placeholder_id: Id::new(),
backdrop_id: Id::new(),
swapping_stack_surface_id: Id::new(),
last_overview_hover: None,
theme,
@ -383,7 +390,7 @@ impl TilingLayout {
pub fn map<'a>(
&mut self,
window: CosmicMapped,
focus_stack: Option<impl Iterator<Item = &'a CosmicMapped> + 'a>,
focus_stack: Option<impl Iterator<Item = &'a FocusTarget> + 'a>,
direction: Option<Direction>,
) {
window.output_enter(&self.output, window.bbox());
@ -394,7 +401,7 @@ impl TilingLayout {
pub fn map_internal<'a>(
&mut self,
window: impl Into<CosmicMapped>,
focus_stack: Option<impl Iterator<Item = &'a CosmicMapped> + 'a>,
focus_stack: Option<impl Iterator<Item = &'a FocusTarget> + 'a>,
direction: Option<Direction>,
minimize_rect: Option<Rectangle<i32, Local>>,
) {
@ -422,18 +429,17 @@ impl TilingLayout {
self.queue.push_tree(tree, duration, blocker);
}
pub fn remap_minimized<'a>(
pub fn remap<'a>(
&mut self,
window: CosmicMapped,
from: Rectangle<i32, Local>,
tiling_state: Option<MinimizedTilingState>,
focus_stack: Option<impl Iterator<Item = &'a CosmicMapped> + 'a>,
from: Option<Rectangle<i32, Local>>,
tiling_state: Option<RestoreTilingState>,
focus_stack: Option<impl Iterator<Item = &'a FocusTarget> + 'a>,
) {
window.set_minimized(false);
let gaps = self.gaps();
let mut tree = self.queue.trees.back().unwrap().0.copy_clone();
if let Some(MinimizedTilingState {
if let Some(RestoreTilingState {
parent,
sibling,
orientation,
@ -475,7 +481,7 @@ impl TilingLayout {
let new_node = Node::new(Data::Mapped {
mapped: window.clone(),
last_geometry: Rectangle::from_size((100, 100).into()),
minimize_rect: Some(from),
minimize_rect: from,
});
let new_id = tree
.insert(new_node, InsertBehavior::UnderNode(&parent_id))
@ -498,7 +504,7 @@ impl TilingLayout {
let new_node = Node::new(Data::Mapped {
mapped: window.clone(),
last_geometry: Rectangle::from_size((100, 100).into()),
minimize_rect: Some(from),
minimize_rect: from,
});
let new_id = tree.insert(new_node, InsertBehavior::AsRoot).unwrap();
@ -530,7 +536,7 @@ impl TilingLayout {
}
// else add as new_window
self.map_internal(window, focus_stack, None, Some(from));
self.map_internal(window, focus_stack, None, from);
}
fn map_to_tree(
@ -637,7 +643,7 @@ impl TilingLayout {
other: &mut Self,
other_handle: &WorkspaceHandle,
seat: &Seat<State>,
focus_stack: impl Iterator<Item = &'a CosmicMapped> + 'a,
focus_stack: impl Iterator<Item = &'a FocusTarget> + 'a,
desc: NodeDesc,
direction: Option<Direction>,
) -> Option<KeyboardFocusTarget> {
@ -658,7 +664,7 @@ impl TilingLayout {
let this_stack = this_mapped.stack_ref()?;
this_stack.remove_window(&stack_surface);
if !this_stack.alive() {
this.unmap(&this_mapped);
let _ = this.unmap(&this_mapped, None);
}
let mapped: CosmicMapped =
@ -1210,7 +1216,7 @@ impl TilingLayout {
let this_was_active = &this_stack.active() == this_surface;
let other_was_active = &other_stack.active() == other_surface;
this_stack.add_window(other_surface.clone(), Some(this_idx), None);
this_stack.remove_window(&this_surface);
this_stack.remove_window(this_surface);
other_stack.add_window(this_surface.clone(), Some(other_idx), None);
if this.output != other_output {
@ -1226,12 +1232,12 @@ impl TilingLayout {
toplevel_enter_workspace(other_surface, &this_desc.handle);
}
other_stack.remove_window(&other_surface);
other_stack.remove_window(other_surface);
if this_was_active {
this_stack.set_active(&other_surface);
this_stack.set_active(other_surface);
}
if other_was_active {
other_stack.set_active(&this_surface);
other_stack.set_active(this_surface);
}
return other
@ -1289,45 +1295,17 @@ impl TilingLayout {
&self.queue.trees.back().unwrap().0
}
pub fn unmap(&mut self, window: &CosmicMapped) -> bool {
if self.unmap_window_internal(window, false) {
window.output_leave(&self.output);
window.set_tiled(false);
*window.tiling_node_id.lock().unwrap() = None;
true
} else {
false
}
}
pub fn unmap_as_placeholder(&mut self, window: &CosmicMapped) -> Option<NodeId> {
let node_id = window.tiling_node_id.lock().unwrap().take()?;
let data = self
.queue
.trees
.back_mut()
.unwrap()
.0
.get_mut(&node_id)
.unwrap()
.data_mut();
*data = Data::Placeholder {
last_geometry: data.geometry().clone(),
initial_placeholder: true,
};
window.output_leave(&self.output);
window.set_tiled(false);
Some(node_id)
}
pub fn unmap_minimize(
pub fn unmap(
&mut self,
window: &CosmicMapped,
to: Rectangle<i32, Local>,
) -> Option<MinimizedTilingState> {
let node_id = window.tiling_node_id.lock().unwrap().clone()?;
to: Option<Rectangle<i32, Local>>,
) -> Result<Option<RestoreTilingState>, NodeIdError> {
let node_id = window
.tiling_node_id
.lock()
.unwrap()
.clone()
.ok_or(NodeIdError::NodeIdNoLongerValid)?;
let state = {
let tree = &self.queue.trees.back().unwrap().0;
tree.get(&node_id).unwrap().parent().and_then(|parent_id| {
@ -1343,7 +1321,7 @@ impl TilingLayout {
{
if sizes.len() == 2 {
// this group will be flattened
Some(MinimizedTilingState {
Some(RestoreTilingState {
parent: None,
sibling: parent.children().iter().cloned().find(|id| id != &node_id),
orientation: *orientation,
@ -1351,7 +1329,7 @@ impl TilingLayout {
sizes: sizes.clone(),
})
} else {
Some(MinimizedTilingState {
Some(RestoreTilingState {
parent: Some(parent_id.clone()),
sibling: None,
orientation: *orientation,
@ -1365,24 +1343,58 @@ impl TilingLayout {
})
};
if self.unmap_window_internal(window, true) {
let tree = &mut self
.queue
.trees
.get_mut(self.queue.trees.len() - 2)
.unwrap()
.0;
if let Data::Mapped {
minimize_rect: minimize_to,
..
} = tree.get_mut(&node_id).unwrap().data_mut()
{
*minimize_to = Some(to);
if self.unmap_window_internal(window, to.is_some()) {
if let Some(to) = to {
let tree = &mut self
.queue
.trees
.get_mut(self.queue.trees.len() - 2)
.unwrap()
.0;
if let Data::Mapped {
minimize_rect: minimize_to,
..
} = tree.get_mut(&node_id).unwrap().data_mut()
{
*minimize_to = Some(to);
}
}
window.set_minimized(true);
window.output_leave(&self.output);
window.set_tiled(false);
*window.tiling_node_id.lock().unwrap() = None;
} else {
return Err(NodeIdError::InvalidNodeIdForTree);
}
state
Ok(state)
}
pub fn unmap_as_placeholder(
&mut self,
window: &CosmicMapped,
type_: PlaceholderType,
) -> Option<NodeId> {
let node_id = window.tiling_node_id.lock().unwrap().take()?;
let data = self
.queue
.trees
.back_mut()
.unwrap()
.0
.get_mut(&node_id)
.unwrap()
.data_mut();
*data = Data::Placeholder {
id: Id::new(),
last_geometry: data.geometry().clone(),
type_,
};
window.output_leave(&self.output);
window.set_tiled(false);
Some(node_id)
}
fn unmap_window_internal(&mut self, mapped: &CosmicMapped, minimizing: bool) -> bool {
@ -1810,7 +1822,7 @@ impl TilingLayout {
&self,
direction: FocusDirection,
seat: &Seat<State>,
focus_stack: impl Iterator<Item = &'a CosmicMapped> + 'a,
focus_stack: impl Iterator<Item = &'a FocusTarget> + 'a,
swap_desc: Option<NodeDesc>,
) -> FocusResult {
let tree = &self.queue.trees.back().unwrap().0;
@ -2127,7 +2139,7 @@ impl TilingLayout {
match tree.get_mut(&node_id).unwrap().data_mut() {
Data::Mapped { mapped, .. } => {
mapped.convert_to_stack((&self.output, mapped.bbox()), self.theme.clone());
focus_stack.append(&mapped);
focus_stack.append(mapped.clone());
KeyboardFocusTarget::Element(mapped.clone())
}
_ => unreachable!(),
@ -2198,7 +2210,7 @@ impl TilingLayout {
};
for elem in new_elements.iter().rev() {
focus_stack.append(elem);
focus_stack.append(elem.clone());
}
match tree.get(&node_id).unwrap().data() {
@ -2286,7 +2298,7 @@ impl TilingLayout {
let mapped = CosmicMapped::from(stack);
*mapped.last_geometry.lock().unwrap() = Some(geo);
*mapped.tiling_node_id.lock().unwrap() = Some(last_active);
focus_stack.append(&mapped);
focus_stack.append(mapped.clone());
*data = Data::Mapped {
mapped: mapped.clone(),
last_geometry: geo,
@ -2785,14 +2797,23 @@ impl TilingLayout {
fn last_active_window<'a>(
tree: &Tree<Data>,
mut focus_stack: impl Iterator<Item = &'a CosmicMapped>,
mut focus_stack: impl Iterator<Item = &'a FocusTarget>,
) -> Option<(NodeId, CosmicMapped)> {
focus_stack
.find_map(|mapped| tree.root_node_id()
.and_then(|root| tree.traverse_pre_order_ids(root).unwrap()
.find(|id| matches!(tree.get(id).map(|n| n.data()), Ok(Data::Mapped { mapped: m, .. }) if m == mapped))
).map(|id| (id, mapped.clone()))
)
focus_stack.find_map(|target| {
tree.root_node_id().and_then(|root| {
tree.traverse_pre_order_ids(root).unwrap().find_map(|id| {
let Ok(Data::Mapped { mapped, .. }) = tree.get(&id).map(|n| n.data()) else {
return None;
};
if target == mapped {
Some((id, mapped.clone()))
} else {
None
}
})
})
})
}
fn currently_focused_node(
@ -3314,7 +3335,6 @@ impl TilingLayout {
) {
let gaps = self.gaps();
let last_overview_hover = &mut self.last_overview_hover;
let placeholder_id = &self.placeholder_id;
let tree = &self.queue.trees.back().unwrap().0;
let Some(root) = tree.root_node_id() else {
return;
@ -3346,7 +3366,7 @@ impl TilingLayout {
None,
1.0,
overview.alpha().unwrap(),
placeholder_id,
&self.backdrop_id,
Some(None),
None,
None,
@ -3372,7 +3392,7 @@ impl TilingLayout {
matches!(
child.data(),
Data::Placeholder {
initial_placeholder: false,
type_: PlaceholderType::DropZone,
..
}
)
@ -3407,7 +3427,7 @@ impl TilingLayout {
matches!(
child.data(),
Data::Placeholder {
initial_placeholder: false,
type_: PlaceholderType::DropZone,
..
}
)
@ -3620,7 +3640,7 @@ impl TilingLayout {
.unwrap()
.find(|id| match tree.get(id).unwrap().data() {
Data::Placeholder {
initial_placeholder: true,
type_: PlaceholderType::GrabbedWindow,
..
} => true,
_ => false,
@ -3679,7 +3699,7 @@ impl TilingLayout {
let matches = matches!(
tree.get(&id).unwrap().data(),
Data::Placeholder {
initial_placeholder: false,
type_: PlaceholderType::DropZone,
..
}
);
@ -3724,10 +3744,11 @@ impl TilingLayout {
let id = tree
.insert(
Node::new(Data::Placeholder {
id: Id::new(),
last_geometry: Rectangle::from_size(
(100, 100).into(),
),
initial_placeholder: false,
type_: PlaceholderType::DropZone,
}),
InsertBehavior::UnderNode(node_id),
)
@ -4001,7 +4022,7 @@ impl TilingLayout {
// but for that we have to associate focus with a tree (and animate focus changes properly)
1.0 - transition,
transition,
&self.placeholder_id,
&self.backdrop_id,
is_mouse_tiling,
swap_desc.clone(),
overview.1.as_ref().and_then(|(_, tree)| tree.clone()),
@ -4038,7 +4059,7 @@ impl TilingLayout {
seat,
transition,
transition,
&self.placeholder_id,
&self.backdrop_id,
is_mouse_tiling,
swap_desc.clone(),
overview.1.as_ref().and_then(|(_, tree)| tree.clone()),
@ -4076,7 +4097,7 @@ impl TilingLayout {
resize_indicator,
swap_desc.clone(),
&self.swapping_stack_surface_id,
&self.placeholder_id,
&self.backdrop_id,
theme,
));
@ -4150,7 +4171,7 @@ impl TilingLayout {
// but for that we have to associate focus with a tree (and animate focus changes properly)
1.0 - transition,
transition,
&self.placeholder_id,
&self.backdrop_id,
is_mouse_tiling,
swap_desc.clone(),
overview.1.as_ref().and_then(|(_, tree)| tree.clone()),
@ -4185,7 +4206,7 @@ impl TilingLayout {
seat,
transition,
transition,
&self.placeholder_id,
&self.backdrop_id,
is_mouse_tiling,
swap_desc.clone(),
overview.1.as_ref().and_then(|(_, tree)| tree.clone()),
@ -4259,7 +4280,7 @@ fn geometries_for_groupview<'a, R>(
seat: Option<&Seat<State>>,
alpha: f32,
transition: f32,
placeholder_id: &Id,
backdrop_id: &Id,
mouse_tiling: Option<Option<&TargetZone>>,
swap_desc: Option<NodeDesc>,
swap_tree: Option<&Tree<Data>>,
@ -4593,7 +4614,7 @@ where
elements.push(
BackdropShader::element(
*renderer,
placeholder_id.clone(),
backdrop_id.clone(),
pill_geo,
8.,
alpha * 0.4,
@ -4696,7 +4717,7 @@ where
elements.push(
BackdropShader::element(
*renderer,
placeholder_id.clone(),
backdrop_id.clone(),
Rectangle::new(
(geo.loc.x, geo.loc.y - 8).into(),
(geo.size.w, 16).into(),
@ -4738,7 +4759,7 @@ where
elements.push(
BackdropShader::element(
*renderer,
placeholder_id.clone(),
backdrop_id.clone(),
Rectangle::new(
(geo.loc.x - 8, geo.loc.y).into(),
(16, geo.size.h).into(),
@ -4855,7 +4876,7 @@ where
geometries.insert(node_id.clone(), geo);
}
Data::Placeholder { .. } => {
Data::Placeholder { id, .. } => {
geo.loc += (element_gap_left, element_gap_up).into();
geo.size -= (element_gap_left, element_gap_up).into();
geo.size -= (element_gap_right, element_gap_down).into();
@ -4866,7 +4887,7 @@ where
elements.push(
BackdropShader::element(
*renderer,
placeholder_id.clone(),
id.clone(),
geo,
8.,
alpha * 0.4,
@ -5165,7 +5186,7 @@ fn render_new_tree_windows<R>(
mut resize_indicator: Option<(ResizeMode, ResizeIndicator)>,
swap_desc: Option<NodeDesc>,
swapping_stack_surface_id: &Id,
placeholder_id: &Id,
backdrop_id: &Id,
theme: &cosmic::theme::CosmicTheme,
) -> Vec<CosmicMappedRenderElement<R>>
where
@ -5230,7 +5251,7 @@ where
window_elements.push(
BackdropShader::element(
renderer,
placeholder_id.clone(),
backdrop_id.clone(),
focused_geo,
8.,
transition.unwrap_or(1.0) * 0.4,

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff