From a9e06741d44ddb5a938f70534297ef9104a2fbc4 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 31 May 2023 13:27:52 +0200 Subject: [PATCH] tiling: Add group selection highlight --- src/backend/render/mod.rs | 86 ++++++++++++---------------------- src/shell/layout/tiling/mod.rs | 23 +++++++-- 2 files changed, 49 insertions(+), 60 deletions(-) diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index e53e3cf9..8a383cd0 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -92,36 +92,44 @@ pub static RECTANGLE_SHADER: &str = include_str!("./shaders/rounded_rectangle.fr pub struct IndicatorShader(pub GlesPixelProgram); #[derive(Clone)] -pub enum IndicatorKey { +pub enum Key { + Static(Id), Group(Weak<()>), Window(CosmicMapped), } -impl std::hash::Hash for IndicatorKey { +impl std::hash::Hash for Key { fn hash(&self, state: &mut H) { match self { - IndicatorKey::Group(arc) => (arc.as_ptr() as usize).hash(state), - IndicatorKey::Window(window) => window.hash(state), + Key::Static(id) => id.hash(state), + Key::Group(arc) => (arc.as_ptr() as usize).hash(state), + Key::Window(window) => window.hash(state), } } } -impl PartialEq for IndicatorKey { +impl PartialEq for Key { fn eq(&self, other: &Self) -> bool { match (self, other) { - (IndicatorKey::Group(g1), IndicatorKey::Group(g2)) => Weak::ptr_eq(g1, g2), - (IndicatorKey::Window(w1), IndicatorKey::Window(w2)) => w1 == w2, + (Key::Static(s1), Key::Static(s2)) => s1 == s2, + (Key::Group(g1), Key::Group(g2)) => Weak::ptr_eq(g1, g2), + (Key::Window(w1), Key::Window(w2)) => w1 == w2, _ => false, } } } -impl Eq for IndicatorKey {} -impl From for IndicatorKey { +impl Eq for Key {} +impl From for Key { fn from(window: CosmicMapped) -> Self { - IndicatorKey::Window(window) + Key::Window(window) } } -impl From for IndicatorKey { +impl From for Key { fn from(group: WindowGroup) -> Self { - IndicatorKey::Group(group.alive.clone()) + Key::Group(group.alive.clone()) + } +} +impl From for Key { + fn from(id: Id) -> Self { + Key::Static(id) } } @@ -131,7 +139,7 @@ struct IndicatorSettings { alpha: f32, color: [f32; 3], } -type IndicatorCache = RefCell>; +type IndicatorCache = RefCell>; impl IndicatorShader { pub fn get(renderer: &R) -> GlesPixelProgram { @@ -146,7 +154,7 @@ impl IndicatorShader { pub fn focus_element( renderer: &R, - key: impl Into, + key: impl Into, mut element_geo: Rectangle, thickness: u8, alpha: f32, @@ -161,7 +169,7 @@ impl IndicatorShader { pub fn element( renderer: &R, - key: impl Into, + key: impl Into, geo: Rectangle, thickness: u8, alpha: f32, @@ -180,8 +188,9 @@ impl IndicatorShader { user_data.insert_if_missing(|| IndicatorCache::new(HashMap::new())); let mut cache = user_data.get::().unwrap().borrow_mut(); cache.retain(|k, _| match k { - IndicatorKey::Group(w) => w.upgrade().is_some(), - IndicatorKey::Window(w) => w.alive(), + Key::Static(_) => true, + Key::Group(w) => w.upgrade().is_some(), + Key::Window(w) => w.alive(), }); let key = key.into(); @@ -217,47 +226,13 @@ impl IndicatorShader { pub struct BackdropShader(pub GlesPixelProgram); -#[derive(Clone)] -pub enum BackdropKey { - Static(Id), - Window(CosmicMapped), -} -impl std::hash::Hash for BackdropKey { - fn hash(&self, state: &mut H) { - match self { - BackdropKey::Static(id) => id.hash(state), - BackdropKey::Window(window) => window.hash(state), - } - } -} -impl PartialEq for BackdropKey { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (BackdropKey::Static(s1), BackdropKey::Static(s2)) => s1 == s2, - (BackdropKey::Window(w1), BackdropKey::Window(w2)) => w1 == w2, - _ => false, - } - } -} -impl Eq for BackdropKey {} -impl From for BackdropKey { - fn from(window: CosmicMapped) -> Self { - BackdropKey::Window(window) - } -} -impl From for BackdropKey { - fn from(id: Id) -> Self { - BackdropKey::Static(id) - } -} - #[derive(PartialEq)] struct BackdropSettings { radius: f32, alpha: f32, color: [f32; 3], } -type BackdropCache = RefCell>; +type BackdropCache = RefCell>; impl BackdropShader { pub fn get(renderer: &R) -> GlesPixelProgram { @@ -272,7 +247,7 @@ impl BackdropShader { pub fn element( renderer: &R, - key: impl Into, + key: impl Into, geo: Rectangle, radius: f32, alpha: f32, @@ -291,8 +266,9 @@ impl BackdropShader { user_data.insert_if_missing(|| BackdropCache::new(HashMap::new())); let mut cache = user_data.get::().unwrap().borrow_mut(); cache.retain(|k, _| match k { - BackdropKey::Static(_) => true, - BackdropKey::Window(w) => w.alive(), + Key::Static(_) => true, + Key::Group(a) => a.upgrade().is_some(), + Key::Window(w) => w.alive(), }); let key = key.into(); diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 9ca0c75e..fe3566a7 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -2,7 +2,7 @@ use crate::{ backend::render::{ - element::AsGlowRenderer, IndicatorKey, IndicatorShader, ACTIVE_GROUP_COLOR, + element::AsGlowRenderer, BackdropShader, IndicatorShader, Key, ACTIVE_GROUP_COLOR, FOCUS_INDICATOR_COLOR, GROUP_COLOR, }, shell::{ @@ -1815,7 +1815,7 @@ where elements.push( IndicatorShader::element( renderer, - IndicatorKey::Group(Arc::downgrade(&alive)), + Key::Group(Arc::downgrade(&alive)), geo, 3, alpha, @@ -2152,9 +2152,7 @@ where renderer, match data { Data::Mapped { mapped, .. } => mapped.clone().into(), - Data::Group { alive, .. } => { - IndicatorKey::Group(Arc::downgrade(alive)) - } + Data::Group { alive, .. } => Key::Group(Arc::downgrade(alive)), }, geo, indicator_thickness, @@ -2163,6 +2161,21 @@ where ); elements.push(element.into()); } + + if data.is_group() { + let element = BackdropShader::element( + renderer, + match data { + Data::Mapped { mapped, .. } => mapped.clone().into(), + Data::Group { alive, .. } => Key::Group(Arc::downgrade(alive)), + }, + geo, + (indicator_thickness * 2) as f32, + 0.25, + FOCUS_INDICATOR_COLOR, + ); + elements.push(element.into()); + } } if let Data::Mapped { mapped, .. } = data {