tiling: Add group selection highlight
This commit is contained in:
parent
56131b13ae
commit
a9e06741d4
2 changed files with 49 additions and 60 deletions
|
|
@ -92,36 +92,44 @@ pub static RECTANGLE_SHADER: &str = include_str!("./shaders/rounded_rectangle.fr
|
||||||
pub struct IndicatorShader(pub GlesPixelProgram);
|
pub struct IndicatorShader(pub GlesPixelProgram);
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum IndicatorKey {
|
pub enum Key {
|
||||||
|
Static(Id),
|
||||||
Group(Weak<()>),
|
Group(Weak<()>),
|
||||||
Window(CosmicMapped),
|
Window(CosmicMapped),
|
||||||
}
|
}
|
||||||
impl std::hash::Hash for IndicatorKey {
|
impl std::hash::Hash for Key {
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
match self {
|
match self {
|
||||||
IndicatorKey::Group(arc) => (arc.as_ptr() as usize).hash(state),
|
Key::Static(id) => id.hash(state),
|
||||||
IndicatorKey::Window(window) => window.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 {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(IndicatorKey::Group(g1), IndicatorKey::Group(g2)) => Weak::ptr_eq(g1, g2),
|
(Key::Static(s1), Key::Static(s2)) => s1 == s2,
|
||||||
(IndicatorKey::Window(w1), IndicatorKey::Window(w2)) => w1 == w2,
|
(Key::Group(g1), Key::Group(g2)) => Weak::ptr_eq(g1, g2),
|
||||||
|
(Key::Window(w1), Key::Window(w2)) => w1 == w2,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Eq for IndicatorKey {}
|
impl Eq for Key {}
|
||||||
impl From<CosmicMapped> for IndicatorKey {
|
impl From<CosmicMapped> for Key {
|
||||||
fn from(window: CosmicMapped) -> Self {
|
fn from(window: CosmicMapped) -> Self {
|
||||||
IndicatorKey::Window(window)
|
Key::Window(window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<WindowGroup> for IndicatorKey {
|
impl From<WindowGroup> for Key {
|
||||||
fn from(group: WindowGroup) -> Self {
|
fn from(group: WindowGroup) -> Self {
|
||||||
IndicatorKey::Group(group.alive.clone())
|
Key::Group(group.alive.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<Id> for Key {
|
||||||
|
fn from(id: Id) -> Self {
|
||||||
|
Key::Static(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,7 +139,7 @@ struct IndicatorSettings {
|
||||||
alpha: f32,
|
alpha: f32,
|
||||||
color: [f32; 3],
|
color: [f32; 3],
|
||||||
}
|
}
|
||||||
type IndicatorCache = RefCell<HashMap<IndicatorKey, (IndicatorSettings, PixelShaderElement)>>;
|
type IndicatorCache = RefCell<HashMap<Key, (IndicatorSettings, PixelShaderElement)>>;
|
||||||
|
|
||||||
impl IndicatorShader {
|
impl IndicatorShader {
|
||||||
pub fn get<R: AsGlowRenderer>(renderer: &R) -> GlesPixelProgram {
|
pub fn get<R: AsGlowRenderer>(renderer: &R) -> GlesPixelProgram {
|
||||||
|
|
@ -146,7 +154,7 @@ impl IndicatorShader {
|
||||||
|
|
||||||
pub fn focus_element<R: AsGlowRenderer>(
|
pub fn focus_element<R: AsGlowRenderer>(
|
||||||
renderer: &R,
|
renderer: &R,
|
||||||
key: impl Into<IndicatorKey>,
|
key: impl Into<Key>,
|
||||||
mut element_geo: Rectangle<i32, Logical>,
|
mut element_geo: Rectangle<i32, Logical>,
|
||||||
thickness: u8,
|
thickness: u8,
|
||||||
alpha: f32,
|
alpha: f32,
|
||||||
|
|
@ -161,7 +169,7 @@ impl IndicatorShader {
|
||||||
|
|
||||||
pub fn element<R: AsGlowRenderer>(
|
pub fn element<R: AsGlowRenderer>(
|
||||||
renderer: &R,
|
renderer: &R,
|
||||||
key: impl Into<IndicatorKey>,
|
key: impl Into<Key>,
|
||||||
geo: Rectangle<i32, Logical>,
|
geo: Rectangle<i32, Logical>,
|
||||||
thickness: u8,
|
thickness: u8,
|
||||||
alpha: f32,
|
alpha: f32,
|
||||||
|
|
@ -180,8 +188,9 @@ impl IndicatorShader {
|
||||||
user_data.insert_if_missing(|| IndicatorCache::new(HashMap::new()));
|
user_data.insert_if_missing(|| IndicatorCache::new(HashMap::new()));
|
||||||
let mut cache = user_data.get::<IndicatorCache>().unwrap().borrow_mut();
|
let mut cache = user_data.get::<IndicatorCache>().unwrap().borrow_mut();
|
||||||
cache.retain(|k, _| match k {
|
cache.retain(|k, _| match k {
|
||||||
IndicatorKey::Group(w) => w.upgrade().is_some(),
|
Key::Static(_) => true,
|
||||||
IndicatorKey::Window(w) => w.alive(),
|
Key::Group(w) => w.upgrade().is_some(),
|
||||||
|
Key::Window(w) => w.alive(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let key = key.into();
|
let key = key.into();
|
||||||
|
|
@ -217,47 +226,13 @@ impl IndicatorShader {
|
||||||
|
|
||||||
pub struct BackdropShader(pub GlesPixelProgram);
|
pub struct BackdropShader(pub GlesPixelProgram);
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub enum BackdropKey {
|
|
||||||
Static(Id),
|
|
||||||
Window(CosmicMapped),
|
|
||||||
}
|
|
||||||
impl std::hash::Hash for BackdropKey {
|
|
||||||
fn hash<H: std::hash::Hasher>(&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<CosmicMapped> for BackdropKey {
|
|
||||||
fn from(window: CosmicMapped) -> Self {
|
|
||||||
BackdropKey::Window(window)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl From<Id> for BackdropKey {
|
|
||||||
fn from(id: Id) -> Self {
|
|
||||||
BackdropKey::Static(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
struct BackdropSettings {
|
struct BackdropSettings {
|
||||||
radius: f32,
|
radius: f32,
|
||||||
alpha: f32,
|
alpha: f32,
|
||||||
color: [f32; 3],
|
color: [f32; 3],
|
||||||
}
|
}
|
||||||
type BackdropCache = RefCell<HashMap<BackdropKey, (BackdropSettings, PixelShaderElement)>>;
|
type BackdropCache = RefCell<HashMap<Key, (BackdropSettings, PixelShaderElement)>>;
|
||||||
|
|
||||||
impl BackdropShader {
|
impl BackdropShader {
|
||||||
pub fn get<R: AsGlowRenderer>(renderer: &R) -> GlesPixelProgram {
|
pub fn get<R: AsGlowRenderer>(renderer: &R) -> GlesPixelProgram {
|
||||||
|
|
@ -272,7 +247,7 @@ impl BackdropShader {
|
||||||
|
|
||||||
pub fn element<R: AsGlowRenderer>(
|
pub fn element<R: AsGlowRenderer>(
|
||||||
renderer: &R,
|
renderer: &R,
|
||||||
key: impl Into<BackdropKey>,
|
key: impl Into<Key>,
|
||||||
geo: Rectangle<i32, Logical>,
|
geo: Rectangle<i32, Logical>,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
alpha: f32,
|
alpha: f32,
|
||||||
|
|
@ -291,8 +266,9 @@ impl BackdropShader {
|
||||||
user_data.insert_if_missing(|| BackdropCache::new(HashMap::new()));
|
user_data.insert_if_missing(|| BackdropCache::new(HashMap::new()));
|
||||||
let mut cache = user_data.get::<BackdropCache>().unwrap().borrow_mut();
|
let mut cache = user_data.get::<BackdropCache>().unwrap().borrow_mut();
|
||||||
cache.retain(|k, _| match k {
|
cache.retain(|k, _| match k {
|
||||||
BackdropKey::Static(_) => true,
|
Key::Static(_) => true,
|
||||||
BackdropKey::Window(w) => w.alive(),
|
Key::Group(a) => a.upgrade().is_some(),
|
||||||
|
Key::Window(w) => w.alive(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let key = key.into();
|
let key = key.into();
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::render::{
|
backend::render::{
|
||||||
element::AsGlowRenderer, IndicatorKey, IndicatorShader, ACTIVE_GROUP_COLOR,
|
element::AsGlowRenderer, BackdropShader, IndicatorShader, Key, ACTIVE_GROUP_COLOR,
|
||||||
FOCUS_INDICATOR_COLOR, GROUP_COLOR,
|
FOCUS_INDICATOR_COLOR, GROUP_COLOR,
|
||||||
},
|
},
|
||||||
shell::{
|
shell::{
|
||||||
|
|
@ -1815,7 +1815,7 @@ where
|
||||||
elements.push(
|
elements.push(
|
||||||
IndicatorShader::element(
|
IndicatorShader::element(
|
||||||
renderer,
|
renderer,
|
||||||
IndicatorKey::Group(Arc::downgrade(&alive)),
|
Key::Group(Arc::downgrade(&alive)),
|
||||||
geo,
|
geo,
|
||||||
3,
|
3,
|
||||||
alpha,
|
alpha,
|
||||||
|
|
@ -2152,9 +2152,7 @@ where
|
||||||
renderer,
|
renderer,
|
||||||
match data {
|
match data {
|
||||||
Data::Mapped { mapped, .. } => mapped.clone().into(),
|
Data::Mapped { mapped, .. } => mapped.clone().into(),
|
||||||
Data::Group { alive, .. } => {
|
Data::Group { alive, .. } => Key::Group(Arc::downgrade(alive)),
|
||||||
IndicatorKey::Group(Arc::downgrade(alive))
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
geo,
|
geo,
|
||||||
indicator_thickness,
|
indicator_thickness,
|
||||||
|
|
@ -2163,6 +2161,21 @@ where
|
||||||
);
|
);
|
||||||
elements.push(element.into());
|
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 {
|
if let Data::Mapped { mapped, .. } = data {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue