diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index d80d3362..dd8226b4 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -1,5 +1,5 @@ use crate::{ - shell::{focus::FocusDirection, Shell}, + shell::{focus::FocusDirection, layout::tiling::Direction, Shell}, state::State, utils::iced::{IcedElement, Program}, utils::prelude::SeatExt, @@ -9,7 +9,7 @@ use apply::Apply; use calloop::LoopHandle; use cosmic::{ iced::widget as iced_widget, - iced_core::{alignment, Color, Length}, + iced_core::{alignment, renderer::BorderRadius, Background, Color, Length}, iced_runtime::Command, iced_widget::rule::FillMode, theme, widget as cosmic_widget, Element as CosmicElement, @@ -723,52 +723,26 @@ impl Program for CosmicStackInternal { .width(width as u16) .apply(iced_widget::container) .center_y() + .style(if self.group_focused.load(Ordering::SeqCst) { + theme::Container::custom(|theme| iced_widget::container::Appearance { + text_color: Some(Color::from(theme.cosmic().background.on)), + background: Some(Background::Color(theme.cosmic().accent_color().into())), + border_radius: BorderRadius::from([8.0, 8.0, 0.0, 0.0]), + border_width: 0.0, + border_color: Color::TRANSPARENT, + }) + } else { + theme::Container::custom(|theme| iced_widget::container::Appearance { + text_color: Some(Color::from(theme.cosmic().background.on)), + background: Some(Background::Color(theme.cosmic().palette.neutral_3.into())), + border_radius: BorderRadius::from([8.0, 8.0, 0.0, 0.0]), + border_width: 0.0, + border_color: Color::TRANSPARENT, + }) + }) .into() } - fn clip_mask(&self, size: Size, scale: f32) -> tiny_skia::Mask { - let mut mask = self.mask.lock().unwrap(); - if mask.is_none() { - let mut new_mask = tiny_skia::Mask::new(size.w as u32, size.h as u32).unwrap(); - - let mut pb = tiny_skia::PathBuilder::new(); - let radius = 8. * scale; - let (w, h) = (size.w as f32, size.h as f32); - - pb.move_to(0., h); // lower-left - - // upper-left rounded corner - pb.line_to(0., radius); - pb.quad_to(0., 0., radius, 0.); - - // upper-right rounded corner - pb.line_to(w - radius, 0.); - pb.quad_to(w, 0., w, radius); - - pb.line_to(w, h); // lower-right - - let path = pb.finish().unwrap(); - new_mask.fill_path( - &path, - tiny_skia::FillRule::EvenOdd, - true, - Default::default(), - ); - - *mask = Some(new_mask); - } - - mask.clone().unwrap() - } - - fn background_color(&self) -> Color { - if self.group_focused.load(Ordering::SeqCst) { - Color::from(cosmic::theme::COSMIC_DARK.accent_color()) - } else { - Color::from(cosmic::theme::COSMIC_DARK.palette.neutral_3) - } - } - fn foreground( &self, pixels: &mut tiny_skia::PixmapMut<'_>, @@ -780,7 +754,6 @@ impl Program for CosmicStackInternal { (0, TAB_HEIGHT - scale as i32), (pixels.width() as i32, scale as i32), ); - let mask = self.mask.lock().unwrap(); let mut paint = tiny_skia::Paint::default(); let (b, g, r, a) = theme::COSMIC_DARK.accent_color().into_components(); @@ -798,7 +771,7 @@ impl Program for CosmicStackInternal { .unwrap(), &paint, Default::default(), - mask.as_ref(), + None, ) } } diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 79eaa116..253e9603 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -8,7 +8,7 @@ use crate::{ wayland::handlers::screencopy::ScreencopySessions, }; use calloop::LoopHandle; -use cosmic::{iced::Command, iced_core::Color}; +use cosmic::iced::Command; use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::InputType; use smithay::{ backend::{ @@ -138,8 +138,8 @@ impl CosmicWindow { ); p.window .set_geometry(Rectangle::from_loc_and_size(loc, size)); + p.mask.lock().unwrap().take(); }); - self.0.with_program(|p| p.mask.lock().unwrap().take()); self.0.resize(Size::from((geo.size.w, SSD_HEIGHT))); } @@ -221,67 +221,45 @@ impl Program for CosmicWindowInternal { Command::none() } - fn clip_mask(&self, size: Size, scale: f32) -> tiny_skia::Mask { - let mut mask = self.mask.lock().unwrap(); - if mask.is_none() { - let mut new_mask = tiny_skia::Mask::new(size.w as u32, size.h as u32).unwrap(); - - let mut pb = tiny_skia::PathBuilder::new(); - let radius = 8. * scale; - let (w, h) = (size.w as f32, size.h as f32); - - pb.move_to(0., h); // lower-left - - // upper-left rounded corner - pb.line_to(0., radius); - pb.quad_to(0., 0., radius, 0.); - - // upper-right rounded corner - pb.line_to(w - radius, 0.); - pb.quad_to(w, 0., w, radius); - - pb.line_to(w, h); // lower-right - - let path = pb.finish().unwrap(); - new_mask.fill_path( - &path, - tiny_skia::FillRule::EvenOdd, - true, - Default::default(), - ); - - *mask = Some(new_mask); - } - - mask.clone().unwrap() - } - - fn background_color(&self) -> Color { - if self.window.is_activated(false) { - Color { - r: 0.1176, - g: 0.1176, - b: 0.1176, - a: 1.0, - } - } else { - Color { - r: 0.153, - g: 0.153, - b: 0.153, - a: 1.0, - } - } - } - fn foreground( &self, pixels: &mut tiny_skia::PixmapMut<'_>, damage: &[Rectangle], - _scale: f32, + scale: f32, ) { if !self.window.is_activated(false) { - let mask = self.mask.lock().unwrap(); + let mut mask = self.mask.lock().unwrap(); + if mask.is_none() { + let (w, h) = (pixels.width(), pixels.height()); + let mut new_mask = tiny_skia::Mask::new(w, h).unwrap(); + + let mut pb = tiny_skia::PathBuilder::new(); + let radius = 8. * scale; + let (w, h) = (w as f32, h as f32); + + pb.move_to(0., h); // lower-left + + // upper-left rounded corner + pb.line_to(0., radius); + pb.quad_to(0., 0., radius, 0.); + + // upper-right rounded corner + pb.line_to(w - radius, 0.); + pb.quad_to(w, 0., w, radius); + + pb.line_to(w, h); // lower-right + + let path = pb.finish().unwrap(); + new_mask.fill_path( + &path, + tiny_skia::FillRule::EvenOdd, + true, + Default::default(), + ); + + *mask = Some(new_mask); + } + let mut paint = tiny_skia::Paint::default(); paint.set_color_rgba8(0, 0, 0, 102); diff --git a/src/utils/iced.rs b/src/utils/iced.rs index 4f41825f..fabf8663 100644 --- a/src/utils/iced.rs +++ b/src/utils/iced.rs @@ -94,8 +94,9 @@ pub trait Program { } fn view(&self) -> Element<'_, Self::Message>; - fn clip_mask(&self, size: Size, scale: f32) -> tiny_skia::Mask; - fn background_color(&self) -> Color; + fn background_color(&self) -> Color { + Color::TRANSPARENT + } fn foreground( &self, @@ -600,7 +601,7 @@ where if size.w > 0 && size.h > 0 { let renderer = &mut internal_ref.renderer; let state_ref = &internal_ref.state; - let mut clip_mask = state_ref.program().0.clip_mask(size, scale.x as f32); + let mut clip_mask = tiny_skia::Mask::new(size.w as u32, size.h as u32).unwrap(); let overlay = internal_ref.debug.overlay(); buffer