render: Implement workspace transitions
This commit is contained in:
parent
0d1894e08f
commit
7b3ac7fa77
8 changed files with 320 additions and 126 deletions
|
|
@ -87,6 +87,7 @@ pub struct Shell {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct WorkspaceSet {
|
||||
previously_active: Option<(usize, Instant)>,
|
||||
active: usize,
|
||||
amount: WorkspaceAmount,
|
||||
group: WorkspaceGroupHandle,
|
||||
|
|
@ -155,6 +156,7 @@ impl WorkspaceSet {
|
|||
};
|
||||
|
||||
WorkspaceSet {
|
||||
previously_active: None,
|
||||
active: 0,
|
||||
amount,
|
||||
group: group_handle,
|
||||
|
|
@ -170,6 +172,7 @@ impl WorkspaceSet {
|
|||
let old_active = self.active;
|
||||
state.remove_workspace_state(&self.workspaces[old_active].handle, WState::Active);
|
||||
state.add_workspace_state(&self.workspaces[idx].handle, WState::Active);
|
||||
self.previously_active = Some((old_active, Instant::now()));
|
||||
self.active = idx;
|
||||
}
|
||||
}
|
||||
|
|
@ -180,12 +183,19 @@ impl WorkspaceSet {
|
|||
toplevel_info: &mut ToplevelInfoState<State, CosmicSurface>,
|
||||
outputs: impl Iterator<Item = (&'a Output, Point<i32, Logical>)>,
|
||||
) {
|
||||
if let Some((_, start)) = self.previously_active {
|
||||
if Instant::now().duration_since(start).as_millis() >= ANIMATION_DURATION.as_millis() {
|
||||
self.previously_active = None;
|
||||
}
|
||||
}
|
||||
|
||||
match self.amount {
|
||||
WorkspaceAmount::Dynamic => self.ensure_last_empty(state, outputs),
|
||||
WorkspaceAmount::Static(len) => {
|
||||
self.ensure_static(len as usize, state, toplevel_info, outputs)
|
||||
}
|
||||
}
|
||||
|
||||
self.workspaces[self.active].refresh();
|
||||
}
|
||||
|
||||
|
|
@ -371,12 +381,20 @@ impl WorkspaceMode {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn active(&self, output: &Output) -> &Workspace {
|
||||
pub fn active(&self, output: &Output) -> (Option<(&Workspace, Instant)>, &Workspace) {
|
||||
match self {
|
||||
WorkspaceMode::Global(set) => &set.workspaces[set.active],
|
||||
WorkspaceMode::Global(set) => (
|
||||
set.previously_active
|
||||
.map(|(idx, start)| (&set.workspaces[idx], start)),
|
||||
&set.workspaces[set.active],
|
||||
),
|
||||
WorkspaceMode::OutputBound(sets, _) => {
|
||||
let set = sets.get(output).unwrap();
|
||||
&set.workspaces[set.active]
|
||||
(
|
||||
set.previously_active
|
||||
.map(|(idx, start)| (&set.workspaces[idx], start)),
|
||||
&set.workspaces[set.active],
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -391,12 +409,12 @@ impl WorkspaceMode {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn active_num(&self, output: &Output) -> usize {
|
||||
pub fn active_num(&self, output: &Output) -> (Option<usize>, usize) {
|
||||
match self {
|
||||
WorkspaceMode::Global(set) => set.active,
|
||||
WorkspaceMode::Global(set) => (set.previously_active.map(|(idx, _)| idx), set.active),
|
||||
WorkspaceMode::OutputBound(sets, _) => {
|
||||
let set = sets.get(output).unwrap();
|
||||
set.active
|
||||
(set.previously_active.map(|(idx, _)| idx), set.active)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1050,7 +1068,12 @@ impl Shell {
|
|||
}
|
||||
|
||||
pub fn animations_going(&self) -> bool {
|
||||
matches!(self.overview_mode, OverviewMode::None)
|
||||
(match &self.workspaces {
|
||||
WorkspaceMode::Global(set) => set.previously_active.is_some(),
|
||||
WorkspaceMode::OutputBound(sets, _) => {
|
||||
sets.values().any(|set| set.previously_active.is_some())
|
||||
}
|
||||
}) || matches!(self.overview_mode, OverviewMode::None)
|
||||
|| self
|
||||
.workspaces
|
||||
.spaces()
|
||||
|
|
@ -1233,7 +1256,7 @@ impl Shell {
|
|||
follow: bool,
|
||||
) -> Option<Point<i32, Logical>> {
|
||||
let (to_output, to_idx) = to;
|
||||
let to_idx = to_idx.unwrap_or(state.common.shell.workspaces.active_num(to_output));
|
||||
let to_idx = to_idx.unwrap_or(state.common.shell.workspaces.active_num(to_output).1);
|
||||
if state
|
||||
.common
|
||||
.shell
|
||||
|
|
@ -1245,7 +1268,7 @@ impl Shell {
|
|||
}
|
||||
|
||||
if from_output == to_output
|
||||
&& to_idx == state.common.shell.workspaces.active_num(from_output)
|
||||
&& to_idx == state.common.shell.workspaces.active_num(from_output).1
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use crate::{
|
|||
state::State,
|
||||
utils::prelude::*,
|
||||
wayland::{
|
||||
handlers::screencopy::{DropableSession, WORKSPACE_OVERVIEW_NAMESPACE},
|
||||
handlers::screencopy::DropableSession,
|
||||
protocols::{
|
||||
screencopy::{BufferParams, Session as ScreencopySession},
|
||||
toplevel_info::ToplevelInfoState,
|
||||
|
|
@ -38,12 +38,12 @@ use smithay::{
|
|||
ImportAll, ImportMem, Renderer,
|
||||
},
|
||||
},
|
||||
desktop::{layer_map_for_output, space::SpaceElement, LayerSurface},
|
||||
desktop::{layer_map_for_output, space::SpaceElement},
|
||||
input::{pointer::GrabStartData as PointerGrabStartData, Seat},
|
||||
output::Output,
|
||||
reexports::wayland_server::protocol::wl_surface::WlSurface,
|
||||
utils::{Buffer as BufferCoords, IsAlive, Logical, Physical, Point, Rectangle, Scale, Size},
|
||||
wayland::{seat::WaylandFocus, shell::wlr_layer::Layer},
|
||||
wayland::seat::WaylandFocus,
|
||||
xwayland::X11Surface,
|
||||
};
|
||||
use std::{collections::HashMap, time::Instant};
|
||||
|
|
@ -470,7 +470,6 @@ impl Workspace {
|
|||
draw_focus_indicator: Option<&Seat<State>>,
|
||||
overview: OverviewMode,
|
||||
indicator_thickness: u8,
|
||||
exclude_workspace_overview: bool,
|
||||
) -> Result<Vec<WorkspaceRenderElement<R>>, OutputNotMapped>
|
||||
where
|
||||
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
|
||||
|
|
@ -488,32 +487,6 @@ impl Workspace {
|
|||
let layer_map = layer_map_for_output(output);
|
||||
|
||||
if let Some(fullscreen) = self.fullscreen.get(output) {
|
||||
// overlay layer surfaces
|
||||
render_elements.extend(
|
||||
layer_map
|
||||
.layers()
|
||||
.rev()
|
||||
.filter(|s| {
|
||||
s.layer() == Layer::Overlay
|
||||
&& !(exclude_workspace_overview
|
||||
&& s.namespace() == WORKSPACE_OVERVIEW_NAMESPACE)
|
||||
})
|
||||
.filter_map(|surface| {
|
||||
layer_map
|
||||
.layer_geometry(surface)
|
||||
.map(|geo| (geo.loc, surface))
|
||||
})
|
||||
.flat_map(|(loc, surface)| {
|
||||
AsRenderElements::<R>::render_elements::<WorkspaceRenderElement<R>>(
|
||||
surface,
|
||||
renderer,
|
||||
loc.to_physical_precise_round(output_scale),
|
||||
Scale::from(output_scale),
|
||||
1.0,
|
||||
)
|
||||
}),
|
||||
);
|
||||
|
||||
render_elements.extend(
|
||||
override_redirect_windows
|
||||
.iter()
|
||||
|
|
@ -557,39 +530,6 @@ impl Workspace {
|
|||
// - keyboard window swapping
|
||||
// - resizing in tiling
|
||||
|
||||
// overlay and top layer surfaces
|
||||
let lower = {
|
||||
let (lower, upper): (Vec<&LayerSurface>, Vec<&LayerSurface>) = layer_map
|
||||
.layers()
|
||||
.rev()
|
||||
.filter(|s| {
|
||||
!(exclude_workspace_overview
|
||||
&& s.namespace() == "cosmic-workspace-overview")
|
||||
})
|
||||
.partition(|s| matches!(s.layer(), Layer::Background | Layer::Bottom));
|
||||
|
||||
render_elements.extend(
|
||||
upper
|
||||
.into_iter()
|
||||
.filter_map(|surface| {
|
||||
layer_map
|
||||
.layer_geometry(surface)
|
||||
.map(|geo| (geo.loc, surface))
|
||||
})
|
||||
.flat_map(|(loc, surface)| {
|
||||
AsRenderElements::<R>::render_elements::<WorkspaceRenderElement<R>>(
|
||||
surface,
|
||||
renderer,
|
||||
loc.to_physical_precise_round(output_scale),
|
||||
Scale::from(output_scale),
|
||||
1.0,
|
||||
)
|
||||
}),
|
||||
);
|
||||
|
||||
lower
|
||||
};
|
||||
|
||||
// OR windows above all
|
||||
render_elements.extend(
|
||||
override_redirect_windows
|
||||
|
|
@ -609,6 +549,7 @@ impl Workspace {
|
|||
|
||||
let focused =
|
||||
draw_focus_indicator.and_then(|seat| self.focus_stack.get(seat).last().cloned());
|
||||
|
||||
// floating surfaces
|
||||
let alpha = match &overview {
|
||||
OverviewMode::Started(_, started) => {
|
||||
|
|
@ -716,28 +657,6 @@ impl Workspace {
|
|||
.into(),
|
||||
)
|
||||
}
|
||||
|
||||
// bottom and background layer surfaces
|
||||
{
|
||||
render_elements.extend(
|
||||
lower
|
||||
.into_iter()
|
||||
.filter_map(|surface| {
|
||||
layer_map
|
||||
.layer_geometry(surface)
|
||||
.map(|geo| (geo.loc, surface))
|
||||
})
|
||||
.flat_map(|(loc, surface)| {
|
||||
AsRenderElements::<R>::render_elements::<WorkspaceRenderElement<R>>(
|
||||
surface,
|
||||
renderer,
|
||||
loc.to_physical_precise_round(output_scale),
|
||||
Scale::from(output_scale),
|
||||
1.0,
|
||||
)
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(render_elements)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue