From 5aaac707f8ee7b8f62041bfac5450549c37d9451 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 2 Aug 2024 20:40:59 +0200 Subject: [PATCH] window: Fix round corners on maximize --- src/shell/element/window.rs | 54 ++++++++----------------------------- src/utils/iced.rs | 4 +-- 2 files changed, 13 insertions(+), 45 deletions(-) diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index f85f8f48..75e9da51 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -14,7 +14,12 @@ use crate::{ }, }; use calloop::LoopHandle; -use cosmic::{config::Density, iced::Command, widget::mouse_area, Apply, Theme}; +use cosmic::{ + config::Density, + iced::{Color, Command}, + widget::mouse_area, + Apply, +}; use smithay::{ backend::{ input::KeyState, @@ -44,7 +49,7 @@ use smithay::{ output::Output, reexports::wayland_server::protocol::wl_surface::WlSurface, render_elements, - utils::{Buffer as BufferCoords, IsAlive, Logical, Point, Rectangle, Serial, Size}, + utils::{IsAlive, Logical, Point, Rectangle, Serial, Size}, wayland::seat::WaylandFocus, }; use std::{ @@ -77,7 +82,6 @@ impl fmt::Debug for CosmicWindow { #[derive(Clone)] pub struct CosmicWindowInternal { pub(super) window: CosmicSurface, - mask: Arc>>, activated: Arc, /// TODO: This needs to be per seat pointer_entered: Arc, @@ -191,7 +195,6 @@ impl CosmicWindow { CosmicWindow(IcedElement::new( CosmicWindowInternal { window, - mask: Arc::new(Mutex::new(None)), activated: Arc::new(AtomicBool::new(false)), pointer_entered: Arc::new(AtomicU8::new(0)), last_seat: Arc::new(Mutex::new(None)), @@ -225,7 +228,6 @@ impl CosmicWindow { ); p.window .set_geometry(Rectangle::from_loc_and_size(loc, size)); - p.mask.lock().unwrap().take(); }); } @@ -491,45 +493,11 @@ impl Program for CosmicWindowInternal { Command::none() } - fn foreground( - &self, - pixels: &mut tiny_skia::PixmapMut<'_>, - _damage: &[Rectangle], - scale: f32, - _theme: &Theme, - ) { - let mut mask = self.mask.lock().unwrap(); + fn background_color(&self, theme: &cosmic::Theme) -> Color { if self.window.is_maximized(false) { - mask.take(); - } else 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); + theme.cosmic().background.base.into() + } else { + Color::TRANSPARENT } } diff --git a/src/utils/iced.rs b/src/utils/iced.rs index 81f28902..9f905479 100644 --- a/src/utils/iced.rs +++ b/src/utils/iced.rs @@ -110,7 +110,7 @@ pub trait Program { } fn view(&self) -> cosmic::Element<'_, Self::Message>; - fn background_color(&self) -> Color { + fn background_color(&self, _theme: &cosmic::Theme) -> Color { Color::TRANSPARENT } @@ -892,7 +892,7 @@ where .expect("Failed to create pixel map"); renderer.with_primitives(|backend, primitives| { - let background_color = state_ref.program().0.background_color(); + let background_color = state_ref.program().0.background_color(theme); let bounds = IcedSize::new(size.w as u32, size.h as u32); let viewport = Viewport::with_physical_size(bounds, scale.x);