feat: theme integration

refactor: only apply updates if there is a change in the theme

refactor: include theme in state

cleanup: theme integration
This commit is contained in:
Ashley Wulber 2023-10-10 13:55:34 -04:00 committed by Victoria Brekenfeld
parent c16b86d1bf
commit abbe94e6e1
24 changed files with 409 additions and 139 deletions

View file

@ -501,6 +501,7 @@ impl CosmicMapped {
pub fn convert_to_stack<'a>(
&mut self,
(output, overlap): (&'a Output, Rectangle<i32, Logical>),
theme: cosmic::Theme,
) {
match &self.element {
CosmicMappedInternal::Window(window) => {
@ -508,7 +509,7 @@ impl CosmicMapped {
let activated = surface.is_activated(true);
let handle = window.loop_handle();
let stack = CosmicStack::new(std::iter::once(surface), handle);
let stack = CosmicStack::new(std::iter::once(surface), handle, theme);
if let Some(geo) = self.last_geometry.lock().unwrap().clone() {
stack.set_geometry(geo.to_global(&output));
}
@ -527,11 +528,12 @@ impl CosmicMapped {
&mut self,
surface: CosmicSurface,
(output, overlap): (&'a Output, Rectangle<i32, Logical>),
theme: cosmic::Theme,
) {
let handle = self.loop_handle();
surface.try_force_undecorated(false);
surface.set_tiled(false);
let window = CosmicWindow::new(surface, handle);
let window = CosmicWindow::new(surface, handle, theme);
if let Some(geo) = self.last_geometry.lock().unwrap().clone() {
window.set_geometry(geo.to_global(&output));
@ -764,6 +766,22 @@ impl CosmicMapped {
popup_elements.into_iter().map(C::from).collect(),
)
}
pub(crate) fn update_theme(&self, theme: cosmic::Theme) {
match &self.element {
CosmicMappedInternal::Window(w) => w.set_theme(theme),
CosmicMappedInternal::Stack(s) => s.set_theme(theme),
CosmicMappedInternal::_GenericCatcher(_) => {}
}
}
pub(crate) fn force_redraw(&self) {
match &self.element {
CosmicMappedInternal::Window(w) => w.force_redraw(),
CosmicMappedInternal::Stack(s) => s.force_redraw(),
CosmicMappedInternal::_GenericCatcher(_) => {}
}
}
}
impl IsAlive for CosmicMapped {

View file

@ -23,6 +23,7 @@ pub fn resize_indicator(
direction: ResizeDirection,
config: &Config,
evlh: LoopHandle<'static, crate::state::State>,
theme: cosmic::Theme,
) -> ResizeIndicator {
ResizeIndicator::new(
ResizeIndicatorInternal {
@ -49,6 +50,7 @@ pub fn resize_indicator(
},
Size::from((1, 1)),
evlh,
theme,
)
}

View file

@ -129,6 +129,7 @@ impl CosmicStack {
pub fn new<I: Into<CosmicSurface>>(
windows: impl Iterator<Item = I>,
handle: LoopHandle<'static, crate::state::State>,
theme: cosmic::Theme,
) -> CosmicStack {
let windows = windows.map(Into::into).collect::<Vec<_>>();
assert!(!windows.is_empty());
@ -160,6 +161,7 @@ impl CosmicStack {
},
(width, TAB_HEIGHT),
handle,
theme,
))
}
@ -544,6 +546,14 @@ impl CosmicStack {
popup_elements.into_iter().map(C::from).collect(),
)
}
pub(crate) fn set_theme(&self, theme: cosmic::Theme) {
self.0.set_theme(theme);
}
pub(crate) fn force_redraw(&self) {
self.0.force_redraw();
}
}
#[derive(Debug, Clone, Copy)]
@ -1056,11 +1066,12 @@ impl PointerTarget<State> for CosmicStack {
let mapped = CosmicMapped::from(CosmicWindow::new(
surface,
self.0.loop_handle(),
data.common.theme.clone(),
));
let elem_geo =
workspace.element_geometry(stack_mapped).unwrap();
let indicator_thickness =
data.common.config.static_conf.active_hint;
data.common.theme.cosmic().active_hint as u8;
let was_tiled = workspace.is_tiled(stack_mapped);
self.remove_idx(dragged_out);

View file

@ -18,8 +18,9 @@ pub type StackHover = IcedElement<StackHoverInternal>;
pub fn stack_hover(
evlh: LoopHandle<'static, crate::state::State>,
size: Size<i32, Logical>,
theme: cosmic::Theme,
) -> StackHover {
StackHover::new(StackHoverInternal, size, evlh)
StackHover::new(StackHoverInternal, size, evlh, theme)
}
pub struct StackHoverInternal;

View file

@ -15,8 +15,11 @@ use smithay::utils::Size;
pub type SwapIndicator = IcedElement<SwapIndicatorInternal>;
pub fn swap_indicator(evlh: LoopHandle<'static, crate::state::State>) -> SwapIndicator {
SwapIndicator::new(SwapIndicatorInternal, Size::from((1, 1)), evlh)
pub fn swap_indicator(
evlh: LoopHandle<'static, crate::state::State>,
theme: cosmic::Theme,
) -> SwapIndicator {
SwapIndicator::new(SwapIndicatorInternal, Size::from((1, 1)), evlh, theme)
}
pub struct SwapIndicatorInternal;

View file

@ -114,6 +114,7 @@ impl CosmicWindow {
pub fn new(
window: impl Into<CosmicSurface>,
handle: LoopHandle<'static, crate::state::State>,
theme: cosmic::Theme,
) -> CosmicWindow {
let window = window.into();
let width = window.geometry().size.w;
@ -129,6 +130,7 @@ impl CosmicWindow {
},
(width, SSD_HEIGHT),
handle,
theme,
))
}
@ -213,6 +215,14 @@ impl CosmicWindow {
popup_elements.into_iter().map(C::from).collect(),
)
}
pub(crate) fn set_theme(&self, theme: cosmic::Theme) {
self.0.set_theme(theme);
}
pub(crate) fn force_redraw(&self) {
self.0.force_redraw();
}
}
#[derive(Debug, Clone, Copy)]

View file

@ -17,6 +17,7 @@ use crate::{
utils::prelude::*,
};
use cosmic::theme::CosmicTheme;
use smithay::{
backend::renderer::{
element::{utils::RescaleRenderElement, AsRenderElements, RenderElement},
@ -58,7 +59,13 @@ pub struct MoveGrabState {
}
impl MoveGrabState {
pub fn render<I, R>(&self, renderer: &mut R, seat: &Seat<State>, output: &Output) -> Vec<I>
pub fn render<I, R>(
&self,
renderer: &mut R,
seat: &Seat<State>,
output: &Output,
theme: &CosmicTheme,
) -> Vec<I>
where
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
<R as Renderer>::TextureId: 'static,
@ -103,6 +110,7 @@ impl MoveGrabState {
+ self.window_offset
- scaling_offset;
let active_window_hint = crate::theme::active_window_hint(theme);
let focus_element = if self.indicator_thickness > 0 {
Some(
CosmicMappedRenderElement::from(IndicatorShader::focus_element(
@ -121,6 +129,11 @@ impl MoveGrabState {
self.indicator_thickness,
output_scale.x,
alpha,
[
active_window_hint.red,
active_window_hint.green,
active_window_hint.blue,
],
))
.into(),
)
@ -277,6 +290,7 @@ impl PointerGrab<State> for MoveGrab {
let element = stack_hover(
state.common.event_loop_handle.clone(),
geo.size.as_logical(),
state.common.theme.clone(),
);
for output in &self.window_outputs {
element.output_enter(

View file

@ -364,6 +364,7 @@ impl FloatingLayout {
&mut self,
direction: Direction,
seat: &Seat<State>,
theme: cosmic::Theme,
) -> MoveResult {
let Some(target) = seat.get_keyboard().unwrap().current_focus() else {
return MoveResult::None
@ -388,7 +389,7 @@ impl FloatingLayout {
match focused.handle_move(direction) {
StackMoveResult::Handled => return MoveResult::Done,
StackMoveResult::MoveOut(surface, loop_handle) => {
let mapped: CosmicMapped = CosmicWindow::new(surface, loop_handle).into();
let mapped: CosmicMapped = CosmicWindow::new(surface, loop_handle, theme).into();
let output = seat.active_output();
let pos = self.space.element_geometry(focused).unwrap().loc
+ match direction {
@ -464,6 +465,7 @@ impl FloatingLayout {
mut resize_indicator: Option<(ResizeMode, ResizeIndicator)>,
indicator_thickness: u8,
alpha: f32,
theme: &cosmic::theme::CosmicTheme,
) -> (
Vec<CosmicMappedRenderElement<R>>,
Vec<CosmicMappedRenderElement<R>>,
@ -521,6 +523,8 @@ impl FloatingLayout {
);
}
let active_window_hint = crate::theme::active_window_hint(theme);
if indicator_thickness > 0 {
let element = IndicatorShader::focus_element(
renderer,
@ -529,6 +533,11 @@ impl FloatingLayout {
indicator_thickness,
output_scale,
alpha,
[
active_window_hint.red,
active_window_hint.green,
active_window_hint.blue,
],
);
window_elements.push(element.into());
}

View file

@ -137,6 +137,8 @@ impl PointerGrab<State> for ResizeForkGrab {
if let Some(output) = self.output.upgrade() {
let tiling_layer = &mut data.common.shell.active_space_mut(&output).tiling_layer;
let gaps = tiling_layer.gaps();
let tree = &mut tiling_layer.queue.trees.back_mut().unwrap().0;
if tree.get(&self.node).is_ok() {
let delta = match self.orientation {
@ -191,7 +193,7 @@ impl PointerGrab<State> for ResizeForkGrab {
}
self.last_loc = event.location;
let blocker = TilingLayout::update_positions(&output, tree, tiling_layer.gaps);
let blocker = TilingLayout::update_positions(&output, tree, gaps);
tiling_layer.pending_blockers.extend(blocker);
} else {
handle.unset_grab(data, event.serial, event.time);

View file

@ -1,10 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::{
backend::render::{
element::AsGlowRenderer, BackdropShader, IndicatorShader, Key, Usage, ACTIVE_GROUP_COLOR,
GROUP_COLOR,
},
backend::render::{element::AsGlowRenderer, BackdropShader, IndicatorShader, Key, Usage},
shell::{
element::{
resize_indicator::ResizeIndicator,
@ -25,6 +22,7 @@ use crate::{
CosmicSurface, Direction, FocusResult, MoveResult, OutputNotMapped, OverviewMode,
ResizeDirection, ResizeMode, Trigger,
},
theme::group_color,
utils::{prelude::*, tween::EaseRectangle},
wayland::{
handlers::xdg_shell::popup::get_popup_toplevel,
@ -116,13 +114,13 @@ impl TreeQueue {
#[derive(Debug, Clone)]
pub struct TilingLayout {
gaps: (i32, i32),
output: Output,
queue: TreeQueue,
pending_blockers: Vec<TilingBlocker>,
placeholder_id: Id,
swapping_stack_surface_id: Id,
last_overview_hover: Option<(Option<Instant>, TargetZone)>,
pub theme: cosmic::Theme,
}
#[derive(Debug, Clone, PartialEq)]
@ -317,9 +315,8 @@ enum FocusedNodeData {
}
impl TilingLayout {
pub fn new(gaps: (u8, u8), output: &Output) -> TilingLayout {
pub fn new(theme: cosmic::Theme, output: &Output) -> TilingLayout {
TilingLayout {
gaps: (gaps.0 as i32, gaps.1 as i32),
queue: TreeQueue {
trees: {
let mut queue = VecDeque::new();
@ -333,10 +330,12 @@ impl TilingLayout {
placeholder_id: Id::new(),
swapping_stack_surface_id: Id::new(),
last_overview_hover: None,
theme,
}
}
pub fn set_output(&mut self, output: &Output) {
let gaps = self.gaps();
let mut tree = self.queue.trees.back().unwrap().0.copy_clone();
for node in tree
@ -355,7 +354,7 @@ impl TilingLayout {
}
}
let blocker = TilingLayout::update_positions(output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(output, &mut tree, gaps);
self.queue.push_tree(tree, None, blocker);
self.output = output.clone();
}
@ -377,9 +376,11 @@ impl TilingLayout {
focus_stack: Option<impl Iterator<Item = &'a CosmicMapped> + 'a>,
direction: Option<Direction>,
) {
let gaps = self.gaps();
let mut tree = self.queue.trees.back().unwrap().0.copy_clone();
TilingLayout::map_to_tree(&mut tree, window, &self.output, focus_stack, direction);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
}
@ -466,6 +467,7 @@ impl TilingLayout {
}
pub fn replace_window(&mut self, old: &CosmicMapped, new: &CosmicMapped) {
let gaps = self.gaps();
let Some(old_id) = old.tiling_node_id.lock().unwrap().clone() else { return };
let mut tree = self.queue.trees.back().unwrap().0.copy_clone();
@ -484,7 +486,7 @@ impl TilingLayout {
old.output_leave(&self.output);
new.output_enter(&self.output, new.bbox());
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
}
}
@ -513,7 +515,8 @@ impl TilingLayout {
}
let mapped: CosmicMapped =
CosmicWindow::new(stack_surface, this_stack.loop_handle()).into();
CosmicWindow::new(stack_surface, this_stack.loop_handle(), this.theme.clone())
.into();
if this.output != other.output {
mapped.output_leave(&this.output);
mapped.output_enter(&other.output, mapped.bbox());
@ -635,13 +638,15 @@ impl TilingLayout {
);
}
}
let this_gaps = this.gaps();
let other_gaps = other.gaps();
let blocker =
TilingLayout::update_positions(&this.output, &mut this_tree, this.gaps);
TilingLayout::update_positions(&this.output, &mut this_tree, this_gaps);
this.queue.push_tree(this_tree, ANIMATION_DURATION, blocker);
let blocker =
TilingLayout::update_positions(&other.output, &mut other_tree, other.gaps);
TilingLayout::update_positions(&other.output, &mut other_tree, other_gaps);
other
.queue
.push_tree(other_tree, ANIMATION_DURATION, blocker);
@ -900,8 +905,12 @@ impl TilingLayout {
}
this_stack.remove_window(&this_surface);
let mapped: CosmicMapped =
CosmicWindow::new(this_surface.clone(), this_stack.loop_handle()).into();
let mapped: CosmicMapped = CosmicWindow::new(
this_surface.clone(),
this_stack.loop_handle(),
this.theme.clone(),
)
.into();
mapped.set_tiled(true);
mapped.refresh();
if this.output != other_output {
@ -977,8 +986,12 @@ impl TilingLayout {
}
other_stack.remove_window(&other_surface);
let mapped: CosmicMapped =
CosmicWindow::new(other_surface.clone(), other_stack.loop_handle()).into();
let mapped: CosmicMapped = CosmicWindow::new(
other_surface.clone(),
other_stack.loop_handle(),
this.theme.clone(),
)
.into();
mapped.set_tiled(true);
mapped.refresh();
if this.output != other_output {
@ -1063,15 +1076,17 @@ impl TilingLayout {
}
}
let blocker = TilingLayout::update_positions(&this.output, &mut this_tree, this.gaps);
let this_gaps = this.gaps();
let blocker = TilingLayout::update_positions(&this.output, &mut this_tree, this_gaps);
this.queue.push_tree(this_tree, ANIMATION_DURATION, blocker);
let has_other_tree = other_tree.is_some();
if let Some(mut other_tree) = other_tree {
let (other_queue, gaps) = if let Some(other) = other.as_mut() {
(&mut other.queue, other.gaps)
let other_gaps = other.gaps();
(&mut other.queue, other_gaps)
} else {
(&mut this.queue, this.gaps)
(&mut this.queue, this_gaps)
};
let blocker = TilingLayout::update_positions(&other_output, &mut other_tree, gaps);
other_queue.push_tree(other_tree, ANIMATION_DURATION, blocker);
@ -1144,6 +1159,8 @@ impl TilingLayout {
fn unmap_window_internal(&mut self, mapped: &CosmicMapped) -> bool {
let tiling_node_id = mapped.tiling_node_id.lock().unwrap().as_ref().cloned();
let gaps = self.gaps();
if let Some(node_id) = tiling_node_id {
if self
.queue
@ -1159,7 +1176,7 @@ impl TilingLayout {
TilingLayout::unmap_internal(&mut tree, &node_id);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
return true;
@ -1241,6 +1258,8 @@ impl TilingLayout {
direction: Direction,
seat: &Seat<State>,
) -> MoveResult {
let gaps = self.gaps();
let mut tree = self.queue.trees.back().unwrap().0.copy_clone();
let Some(target) = seat.get_keyboard().unwrap().current_focus() else {
@ -1257,7 +1276,8 @@ impl TilingLayout {
match window.handle_move(direction) {
StackMoveResult::Handled => return MoveResult::Done,
StackMoveResult::MoveOut(surface, loop_handle) => {
let mapped: CosmicMapped = CosmicWindow::new(surface, loop_handle).into();
let mapped: CosmicMapped =
CosmicWindow::new(surface, loop_handle, self.theme.clone()).into();
mapped.output_enter(&self.output, mapped.bbox());
let orientation = match direction {
Direction::Left | Direction::Right => Orientation::Vertical,
@ -1280,8 +1300,7 @@ impl TilingLayout {
.unwrap();
*mapped.tiling_node_id.lock().unwrap() = Some(new_id);
let blocker =
TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
return MoveResult::ShiftFocus(mapped.into());
}
@ -1357,7 +1376,7 @@ impl TilingLayout {
.data_mut()
.remove_window(og_idx);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
return MoveResult::Done;
}
@ -1383,7 +1402,7 @@ impl TilingLayout {
.data_mut()
.remove_window(og_idx);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
return MoveResult::Done;
}
@ -1539,7 +1558,7 @@ impl TilingLayout {
MoveResult::Done
};
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
return result;
}
@ -1836,6 +1855,8 @@ impl TilingLayout {
new_orientation: Option<Orientation>,
seat: &Seat<State>,
) {
let gaps = self.gaps();
let Some(target) = seat.get_keyboard().unwrap().current_focus() else {
return;
};
@ -1871,8 +1892,7 @@ impl TilingLayout {
*orientation = new_orientation;
let blocker =
TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
}
}
@ -1880,6 +1900,8 @@ impl TilingLayout {
}
pub fn toggle_stacking<'a>(&mut self, seat: &Seat<State>, mut focus_stack: FocusStackMut) {
let gaps = self.gaps();
let Some(target) = seat.get_keyboard().unwrap().current_focus() else {
return;
};
@ -1894,7 +1916,10 @@ impl TilingLayout {
// if it is just a window
match tree.get_mut(&last_active).unwrap().data_mut() {
Data::Mapped { mapped, .. } => {
mapped.convert_to_stack((&self.output, mapped.bbox()));
mapped.convert_to_stack(
(&self.output, mapped.bbox()),
self.theme.clone(),
);
focus_stack.append(&mapped);
}
_ => unreachable!(),
@ -1907,7 +1932,11 @@ impl TilingLayout {
let handle = match tree.get_mut(&last_active).unwrap().data_mut() {
Data::Mapped { mapped, .. } => {
let handle = mapped.loop_handle();
mapped.convert_to_surface(first, (&self.output, mapped.bbox()));
mapped.convert_to_surface(
first,
(&self.output, mapped.bbox()),
self.theme.clone(),
);
focus_stack.append(&mapped);
handle
}
@ -1918,8 +1947,11 @@ impl TilingLayout {
for other in surfaces {
other.try_force_undecorated(false);
other.set_tiled(false);
let window =
CosmicMapped::from(CosmicWindow::new(other, handle.clone()));
let window = CosmicMapped::from(CosmicWindow::new(
other,
handle.clone(),
self.theme.clone(),
));
window.output_enter(&self.output, window.bbox());
{
@ -1960,7 +1992,7 @@ impl TilingLayout {
return;
}
let handle = handle.unwrap();
let stack = CosmicStack::new(surfaces.into_iter(), handle);
let stack = CosmicStack::new(surfaces.into_iter(), handle, self.theme.clone());
for child in tree
.children_ids(&last_active)
@ -1992,14 +2024,16 @@ impl TilingLayout {
}
}
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
}
}
pub fn recalculate(&mut self) {
let gaps = self.gaps();
let mut tree = self.queue.trees.back().unwrap().0.copy_clone();
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
}
@ -2136,6 +2170,8 @@ impl TilingLayout {
edges: ResizeEdge,
amount: i32,
) -> bool {
let gaps = self.gaps();
let mut tree = self.queue.trees.back().unwrap().0.copy_clone();
let Some(root_id) = tree.root_node_id() else { return false };
let Some(mut node_id) =
@ -2214,7 +2250,7 @@ impl TilingLayout {
}
_ => unreachable!(),
}
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, None, blocker);
return true;
@ -2234,6 +2270,8 @@ impl TilingLayout {
}
pub fn cleanup_drag(&mut self) {
let gaps = self.gaps();
let mut tree = self.queue.trees.back().unwrap().0.copy_clone();
if let Some(root) = tree.root_node_id() {
@ -2252,12 +2290,14 @@ impl TilingLayout {
}
}
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
}
}
pub fn drop_window(&mut self, window: CosmicMapped) -> (CosmicMapped, Point<i32, Local>) {
let gaps = self.gaps();
let mut tree = self.queue.trees.back().unwrap().0.copy_clone();
window.output_enter(&self.output, window.bbox());
@ -2358,7 +2398,7 @@ impl TilingLayout {
Some(TargetZone::WindowStack(window_id, _)) if tree.get(&window_id).is_ok() => {
match tree.get_mut(window_id).unwrap().data_mut() {
Data::Mapped { mapped, .. } => {
mapped.convert_to_stack((&self.output, mapped.bbox()));
mapped.convert_to_stack((&self.output, mapped.bbox()), self.theme.clone());
let Some(stack) = mapped.stack_ref_mut() else {
unreachable!()
};
@ -2399,7 +2439,7 @@ impl TilingLayout {
}
}
let blocker = TilingLayout::update_positions(&self.output, &mut tree, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps);
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
let location = self.element_geometry(&mapped).unwrap().loc;
@ -2728,9 +2768,9 @@ impl TilingLayout {
location: Point<f64, Local>,
overview: OverviewMode,
) -> Option<(PointerFocusTarget, Point<i32, Local>)> {
let gaps = self.gaps();
let last_overview_hover = &mut self.last_overview_hover;
let placeholder_id = &self.placeholder_id;
let gaps = &self.gaps;
let tree = &self.queue.trees.back().unwrap().0;
let root = tree.root_node_id()?;
let location = location.to_i32_round();
@ -2850,6 +2890,7 @@ impl TilingLayout {
Some(None),
None,
None,
self.theme.cosmic(),
)
.0;
@ -3275,7 +3316,7 @@ impl TilingLayout {
let blocker = TilingLayout::update_positions(
&self.output,
&mut tree,
*gaps,
gaps,
);
self.queue.push_tree(tree, duration, blocker);
}
@ -3372,6 +3413,8 @@ impl TilingLayout {
}
pub fn merge(&mut self, mut other: TilingLayout) {
let gaps = self.gaps();
let src = other.queue.trees.pop_back().unwrap().0;
let mut dst = self.queue.trees.back().unwrap().0.copy_clone();
@ -3381,7 +3424,7 @@ impl TilingLayout {
};
TilingLayout::merge_trees(src, &mut dst, orientation);
let blocker = TilingLayout::update_positions(&self.output, &mut dst, self.gaps);
let blocker = TilingLayout::update_positions(&self.output, &mut dst, gaps);
self.queue.push_tree(dst, ANIMATION_DURATION, blocker);
}
@ -3432,6 +3475,7 @@ impl TilingLayout {
overview: (OverviewMode, Option<(SwapIndicator, Option<&Tree<Data>>)>),
resize_indicator: Option<(ResizeMode, ResizeIndicator)>,
indicator_thickness: u8,
theme: &cosmic::theme::CosmicTheme,
) -> Result<
(
Vec<CosmicMappedRenderElement<R>>,
@ -3502,6 +3546,7 @@ impl TilingLayout {
is_mouse_tiling,
swap_desc.clone(),
overview.1.as_ref().and_then(|(_, tree)| tree.clone()),
theme,
))
} else {
None
@ -3539,6 +3584,7 @@ impl TilingLayout {
is_mouse_tiling,
swap_desc.clone(),
overview.1.as_ref().and_then(|(_, tree)| tree.clone()),
theme,
))
} else {
None
@ -3573,6 +3619,7 @@ impl TilingLayout {
swap_desc.clone(),
&self.swapping_stack_surface_id,
&self.placeholder_id,
theme,
);
window_elements.extend(w_elements);
popup_elements.extend(p_elements);
@ -3584,6 +3631,11 @@ impl TilingLayout {
Ok((window_elements, popup_elements))
}
fn gaps(&self) -> (i32, i32) {
let g = self.theme.cosmic().gaps;
(g.0 as i32, g.1 as i32)
}
}
const GAP_KEYBOARD: i32 = 8;
@ -3631,6 +3683,7 @@ fn geometries_for_groupview<'a, R>(
mouse_tiling: Option<Option<&TargetZone>>,
swap_desc: Option<NodeDesc>,
swap_tree: Option<&Tree<Data>>,
theme: &cosmic::theme::CosmicTheme,
) -> (
HashMap<NodeId, Rectangle<i32, Local>>,
Vec<CosmicMappedRenderElement<R>>,
@ -3788,6 +3841,8 @@ where
)
};
let group_color = group_color(theme);
match data {
Data::Group {
orientation,
@ -3825,7 +3880,7 @@ where
if render_active_child { 16 } else { 8 },
alpha * if render_potential_group { 0.40 } else { 1.0 },
output_scale,
GROUP_COLOR,
group_color,
)
.into(),
);
@ -3843,7 +3898,7 @@ where
8,
alpha * 0.40,
output_scale,
GROUP_COLOR,
group_color,
)
.into(),
);
@ -3907,7 +3962,7 @@ where
8,
alpha * 0.15,
output_scale,
GROUP_COLOR,
group_color,
)
.into(),
);
@ -3971,7 +4026,7 @@ where
pill_geo,
8.,
alpha * 0.4,
GROUP_COLOR,
group_color,
)
.into(),
);
@ -4001,7 +4056,7 @@ where
} else {
0.15
},
GROUP_COLOR,
group_color,
)
.into(),
);
@ -4077,7 +4132,7 @@ where
),
8.,
alpha * 0.4,
GROUP_COLOR,
group_color,
)
.into(),
);
@ -4119,7 +4174,7 @@ where
),
8.,
alpha * 0.4,
GROUP_COLOR,
group_color,
)
.into(),
);
@ -4150,7 +4205,7 @@ where
8,
alpha * 0.40,
output_scale,
GROUP_COLOR,
group_color,
)
.into(),
);
@ -4158,6 +4213,8 @@ where
geo.size -= (gap * 2, gap * 2).into();
}
let accent = theme.accent.base;
if focused
.as_ref()
.map(|focused_id| {
@ -4172,9 +4229,9 @@ where
Some(Some(TargetZone::WindowStack(stack_id, _)))
if *stack_id == node_id =>
{
ACTIVE_GROUP_COLOR
[accent.red, accent.green, accent.blue]
}
_ => GROUP_COLOR,
_ => group_color,
};
geo.loc += (WINDOW_BACKDROP_BORDER, WINDOW_BACKDROP_BORDER).into();
geo.size -=
@ -4189,7 +4246,9 @@ where
* if focused
.as_ref()
.map(|focused_id| focused_id == &node_id)
.unwrap_or(color == ACTIVE_GROUP_COLOR)
.unwrap_or(
color == [accent.red, accent.green, accent.blue],
)
{
0.4
} else {
@ -4243,7 +4302,7 @@ where
geo,
8.,
alpha * 0.4,
GROUP_COLOR,
group_color,
)
.into(),
);
@ -4417,6 +4476,7 @@ fn render_new_tree<R>(
swap_desc: Option<NodeDesc>,
swapping_stack_surface_id: &Id,
placeholder_id: &Id,
theme: &cosmic::theme::CosmicTheme,
) -> (
Vec<CosmicMappedRenderElement<R>>,
Vec<CosmicMappedRenderElement<R>>,
@ -4476,7 +4536,8 @@ where
let (swap_indicator, swap_tree) = overview.1.unzip();
let swap_tree = swap_tree.flatten().filter(|_| is_active_output);
let swap_desc = swap_desc.filter(|_| is_active_output);
let window_hint = crate::theme::active_window_hint(theme);
let group_color = group_color(theme);
// render placeholder, if we are swapping to an empty workspace
if target_tree.root_node_id().is_none() && swap_desc.is_some() {
window_elements.push(
@ -4486,7 +4547,7 @@ where
focused_geo,
8.,
transition.unwrap_or(1.0) * 0.4,
GROUP_COLOR,
group_color,
)
.into(),
);
@ -4518,6 +4579,7 @@ where
4,
output_scale,
transition.unwrap_or(1.0),
[window_hint.red, window_hint.green, window_hint.blue],
));
let render_loc =
@ -4679,7 +4741,7 @@ where
geo,
8.,
0.4,
GROUP_COLOR,
group_color,
));
}
@ -4706,6 +4768,7 @@ where
},
output_scale,
1.0,
[window_hint.red, window_hint.green, window_hint.blue],
));
}
@ -4825,7 +4888,7 @@ where
geo,
0.0,
0.3,
GROUP_COLOR,
group_color,
)),
)
}

View file

@ -163,6 +163,7 @@ pub struct Shell {
pub xdg_shell_state: XdgShellState,
pub workspace_state: WorkspaceState<State>,
theme: cosmic::Theme,
overview_mode: OverviewMode,
swap_indicator: Option<SwapIndicator>,
resize_mode: ResizeMode,
@ -184,8 +185,8 @@ pub struct WorkspaceSet {
group: WorkspaceGroupHandle,
idx: usize,
tiling_enabled: bool,
gaps: (u8, u8),
output: Output,
theme: cosmic::Theme,
pub(crate) workspaces: Vec<Workspace>,
}
@ -201,7 +202,7 @@ fn create_workspace(
group_handle: &WorkspaceGroupHandle,
active: bool,
tiling: bool,
gaps: (u8, u8),
theme: cosmic::Theme,
) -> Workspace {
let workspace_handle = state.create_workspace(&group_handle).unwrap();
if active {
@ -211,7 +212,7 @@ fn create_workspace(
&workspace_handle,
[WorkspaceCapabilities::Activate].into_iter(),
);
Workspace::new(workspace_handle, output.clone(), tiling, gaps)
Workspace::new(workspace_handle, output.clone(), tiling, theme.clone())
}
impl WorkspaceSet {
@ -222,12 +223,18 @@ impl WorkspaceSet {
amount: WorkspaceAmount,
idx: usize,
tiling_enabled: bool,
gaps: (u8, u8),
theme: cosmic::Theme,
) -> WorkspaceSet {
let workspaces = match amount {
WorkspaceAmount::Dynamic => {
let workspace =
create_workspace(state, output, &group_handle, true, tiling_enabled, gaps);
let workspace = create_workspace(
state,
output,
&group_handle,
true,
tiling_enabled,
theme.clone(),
);
workspace_set_idx(state, 1, idx, &workspace.handle);
state.set_workspace_capabilities(
&workspace.handle,
@ -243,7 +250,7 @@ impl WorkspaceSet {
&group_handle,
i == 0,
tiling_enabled,
gaps,
theme.clone(),
);
workspace_set_idx(state, i + 1, idx, &workspace.handle);
state.set_workspace_capabilities(
@ -261,7 +268,7 @@ impl WorkspaceSet {
group: group_handle,
idx,
tiling_enabled,
gaps,
theme,
workspaces,
output: output.clone(),
}
@ -316,7 +323,7 @@ impl WorkspaceSet {
&self.group,
false,
self.tiling_enabled,
self.gaps,
self.theme.clone(),
);
workspace_set_idx(
state,
@ -411,7 +418,7 @@ impl WorkspaceSet {
&self.group,
false,
self.tiling_enabled,
self.gaps,
self.theme.clone(),
);
workspace_set_idx(
state,
@ -452,18 +459,18 @@ pub struct Workspaces {
amount: WorkspaceAmount,
mode: WorkspaceMode,
tiling_enabled: bool,
gaps: (u8, u8),
theme: cosmic::Theme,
}
impl Workspaces {
pub fn new(config: &Config) -> Workspaces {
pub fn new(config: &Config, theme: cosmic::Theme) -> Workspaces {
Workspaces {
sets: IndexMap::new(),
backup_set: None,
amount: config.static_conf.workspace_amount,
mode: config.static_conf.workspace_mode,
tiling_enabled: config.static_conf.tiling_enabled,
gaps: config.static_conf.gaps,
theme,
}
}
@ -500,7 +507,7 @@ impl Workspaces {
self.amount,
self.sets.len(),
self.tiling_enabled,
self.gaps,
self.theme.clone(),
)
});
workspace_state.add_group_output(&set.group, &output);
@ -674,7 +681,7 @@ impl Workspaces {
&group,
false,
config.static_conf.tiling_enabled,
config.static_conf.gaps,
self.theme.clone(),
),
);
// Otherwise just update
@ -882,6 +889,24 @@ impl Workspaces {
set.update_tiling_status(seat, tiling)
}
}
pub fn set_theme(&mut self, theme: cosmic::Theme) {
for (_, s) in &mut self.sets {
s.theme = theme.clone();
for mut w in &mut s.workspaces {
w.tiling_layer.theme = theme.clone();
w.mapped().for_each(|m| {
m.update_theme(theme.clone());
m.force_redraw();
});
w.refresh();
w.dirty.store(true, Ordering::Relaxed);
w.recalculate();
}
}
}
}
pub struct InvalidWorkspaceIndex;
@ -910,10 +935,11 @@ impl Shell {
//|client| client.get_data::<ClientState>().map_or(false, |s| s.privileged),
client_has_security_context,
);
let theme = cosmic::theme::system_preference();
Shell {
popups: PopupManager::default(),
workspaces: Workspaces::new(config),
workspaces: Workspaces::new(config, theme.clone()),
maximize_mode: MaximizeMode::Floating,
pending_windows: Vec::new(),
@ -926,6 +952,7 @@ impl Shell {
xdg_shell_state,
workspace_state,
theme,
overview_mode: OverviewMode::None,
swap_indicator: None,
resize_mode: ResizeMode::None,
@ -1158,7 +1185,7 @@ impl Shell {
if let Some(trigger) = enabled {
if !matches!(self.overview_mode, OverviewMode::Started(_, _)) {
if matches!(trigger, Trigger::KeyboardSwap(_, _)) {
self.swap_indicator = Some(swap_indicator(evlh));
self.swap_indicator = Some(swap_indicator(evlh, self.theme.clone()));
}
self.overview_mode = OverviewMode::Started(trigger, Instant::now());
}
@ -1204,7 +1231,12 @@ impl Shell {
} else {
self.resize_mode = ResizeMode::Started(pattern, Instant::now(), direction);
}
self.resize_indicator = Some(resize_indicator(direction, config, evlh));
self.resize_indicator = Some(resize_indicator(
direction,
config,
evlh,
self.theme.clone(),
));
} else {
if let ResizeMode::Started(_, _, direction) = &self.resize_mode {
self.resize_mode = ResizeMode::Ended(Instant::now(), *direction);
@ -1338,6 +1370,7 @@ impl Shell {
let mapped = CosmicMapped::from(CosmicWindow::new(
window.clone(),
state.common.event_loop_handle.clone(),
state.common.theme.clone(),
));
#[cfg(feature = "debug")]
{
@ -1579,12 +1612,13 @@ impl Shell {
.find(|(w, _)| w.wl_surface().as_ref() == Some(surface))
.unwrap();
let button = start_data.button;
let active_hint = state.common.theme.cosmic().active_hint as u8;
if let Some(grab) = workspace.move_request(
&window,
&seat,
&output,
start_data,
state.common.config.static_conf.active_hint,
active_hint as u8,
) {
let handle = workspace.handle;
state
@ -1684,6 +1718,12 @@ impl Shell {
}
}
}
pub(crate) fn set_theme(&mut self, theme: cosmic::Theme) {
self.theme = theme.clone();
self.refresh();
self.workspaces.set_theme(theme.clone());
}
}
fn workspace_set_idx<'a>(

View file

@ -21,6 +21,7 @@ use crate::{
xwayland::XWaylandState,
};
use cosmic::theme::CosmicTheme;
use id_tree::Tree;
use indexmap::IndexSet;
use keyframe::{ease, functions::EaseInOutCubic};
@ -210,9 +211,9 @@ impl Workspace {
handle: WorkspaceHandle,
output: Output,
tiling_enabled: bool,
gaps: (u8, u8),
theme: cosmic::Theme,
) -> Workspace {
let tiling_layer = TilingLayout::new(gaps, &output);
let tiling_layer = TilingLayout::new(theme, &output);
let floating_layer = FloatingLayout::new(&output);
Workspace {
@ -824,7 +825,7 @@ impl Workspace {
MoveResult::MoveFurther(KeyboardFocusTarget::Fullscreen(f.surface.clone()))
} else {
self.floating_layer
.move_current_element(direction, seat)
.move_current_element(direction, seat, self.tiling_layer.theme.clone())
.or_else(|| self.tiling_layer.move_current_node(direction, seat))
}
}
@ -838,6 +839,7 @@ impl Workspace {
overview: (OverviewMode, Option<(SwapIndicator, Option<&Tree<Data>>)>),
resize_indicator: Option<(ResizeMode, ResizeIndicator)>,
indicator_thickness: u8,
theme: &CosmicTheme,
) -> Result<
(
Vec<WorkspaceRenderElement<R>>,
@ -1014,6 +1016,7 @@ impl Workspace {
resize_indicator.clone(),
indicator_thickness,
alpha,
theme,
);
popup_elements.extend(p_elements.into_iter().map(WorkspaceRenderElement::from));
window_elements.extend(w_elements.into_iter().map(WorkspaceRenderElement::from));
@ -1038,6 +1041,7 @@ impl Workspace {
overview,
resize_indicator,
indicator_thickness,
theme,
)?;
popup_elements.extend(p_elements.into_iter().map(WorkspaceRenderElement::from));
window_elements.extend(w_elements.into_iter().map(WorkspaceRenderElement::from));