refactor(corner-radius): corner_radius method for CosmicSurface
This commit is contained in:
parent
4e30513673
commit
f01ebf2f6f
4 changed files with 33 additions and 113 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
use crate::wayland::protocols::corner_radius::CornerRadiusData;
|
||||||
|
use smithay::reexports::wayland_server::Resource;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
sync::{
|
sync::{
|
||||||
|
|
@ -7,6 +9,7 @@ use std::{
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use cosmic_protocols::corner_radius::v1::server::cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1;
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::renderer::{
|
backend::renderer::{
|
||||||
element::{
|
element::{
|
||||||
|
|
@ -34,7 +37,7 @@ use smithay::{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration::Mode as KdeMode,
|
wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration::Mode as KdeMode,
|
||||||
wayland_server::protocol::wl_surface::WlSurface,
|
wayland_server::{protocol::wl_surface::WlSurface, Weak},
|
||||||
},
|
},
|
||||||
utils::{
|
utils::{
|
||||||
user_data::UserDataMap, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size,
|
user_data::UserDataMap, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size,
|
||||||
|
|
@ -124,6 +127,30 @@ impl CosmicSurface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn corner_radius(&self) -> Option<[u8; 4]> {
|
||||||
|
self.wl_surface().and_then(|surface| {
|
||||||
|
with_states(&surface, |s| {
|
||||||
|
let d = s
|
||||||
|
.data_map
|
||||||
|
.get::<Mutex<Weak<CosmicCornerRadiusToplevelV1>>>()?;
|
||||||
|
let guard = d.lock().unwrap();
|
||||||
|
|
||||||
|
let weak_data = guard.upgrade().ok()?;
|
||||||
|
|
||||||
|
let corners = weak_data.data::<CornerRadiusData>()?;
|
||||||
|
|
||||||
|
let guard = corners.lock().unwrap();
|
||||||
|
|
||||||
|
Some([
|
||||||
|
guard.top_right,
|
||||||
|
guard.bottom_right,
|
||||||
|
guard.top_left,
|
||||||
|
guard.bottom_left,
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn app_id(&self) -> String {
|
pub fn app_id(&self) -> String {
|
||||||
match self.0.underlying_surface() {
|
match self.0.underlying_surface() {
|
||||||
WindowSurface::Wayland(toplevel) => with_states(toplevel.wl_surface(), |states| {
|
WindowSurface::Wayland(toplevel) => with_states(toplevel.wl_surface(), |states| {
|
||||||
|
|
|
||||||
|
|
@ -119,28 +119,7 @@ impl MoveGrabState {
|
||||||
let active_window_hint = crate::theme::active_window_hint(theme);
|
let active_window_hint = crate::theme::active_window_hint(theme);
|
||||||
let radius = self
|
let radius = self
|
||||||
.window()
|
.window()
|
||||||
.wl_surface()
|
.corner_radius()
|
||||||
.and_then(|surface| {
|
|
||||||
with_states(&surface, |s| {
|
|
||||||
let d = s
|
|
||||||
.data_map
|
|
||||||
.get::<Mutex<Weak<CosmicCornerRadiusToplevelV1>>>()?;
|
|
||||||
let guard = d.lock().unwrap();
|
|
||||||
|
|
||||||
let weak_data = guard.upgrade().ok()?;
|
|
||||||
|
|
||||||
let corners = weak_data.data::<CornerRadiusData>()?;
|
|
||||||
|
|
||||||
let guard = corners.lock().unwrap();
|
|
||||||
|
|
||||||
Some([
|
|
||||||
guard.top_right,
|
|
||||||
guard.bottom_right,
|
|
||||||
guard.top_left,
|
|
||||||
guard.bottom_left,
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.unwrap_or([self.indicator_thickness; 4]);
|
.unwrap_or([self.indicator_thickness; 4]);
|
||||||
|
|
||||||
let focus_element = if self.indicator_thickness > 0 {
|
let focus_element = if self.indicator_thickness > 0 {
|
||||||
|
|
|
||||||
|
|
@ -1600,28 +1600,7 @@ impl FloatingLayout {
|
||||||
let active_window_hint = crate::theme::active_window_hint(theme);
|
let active_window_hint = crate::theme::active_window_hint(theme);
|
||||||
let radius = elem
|
let radius = elem
|
||||||
.active_window()
|
.active_window()
|
||||||
.wl_surface()
|
.corner_radius()
|
||||||
.and_then(|surface| {
|
|
||||||
with_states(&surface, |s| {
|
|
||||||
let d = s
|
|
||||||
.data_map
|
|
||||||
.get::<Mutex<Weak<CosmicCornerRadiusToplevelV1>>>()?;
|
|
||||||
let guard = d.lock().unwrap();
|
|
||||||
|
|
||||||
let weak_data = guard.upgrade().ok()?;
|
|
||||||
|
|
||||||
let corners = weak_data.data::<CornerRadiusData>()?;
|
|
||||||
|
|
||||||
let guard = corners.lock().unwrap();
|
|
||||||
|
|
||||||
Some([
|
|
||||||
guard.top_right,
|
|
||||||
guard.bottom_right,
|
|
||||||
guard.top_left,
|
|
||||||
guard.bottom_left,
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.unwrap_or([indicator_thickness; 4]);
|
.unwrap_or([indicator_thickness; 4]);
|
||||||
if indicator_thickness > 0 {
|
if indicator_thickness > 0 {
|
||||||
let element = IndicatorShader::focus_element(
|
let element = IndicatorShader::focus_element(
|
||||||
|
|
|
||||||
|
|
@ -5020,28 +5020,7 @@ where
|
||||||
}));
|
}));
|
||||||
let radius = mapped
|
let radius = mapped
|
||||||
.active_window()
|
.active_window()
|
||||||
.wl_surface()
|
.corner_radius()
|
||||||
.and_then(|surface| {
|
|
||||||
with_states(&surface, |s| {
|
|
||||||
let d = s
|
|
||||||
.data_map
|
|
||||||
.get::<Mutex<WsWeak<CosmicCornerRadiusToplevelV1>>>()?;
|
|
||||||
let guard = d.lock().unwrap();
|
|
||||||
|
|
||||||
let weak_data = guard.upgrade().ok()?;
|
|
||||||
|
|
||||||
let corners = weak_data.data::<CornerRadiusData>()?;
|
|
||||||
|
|
||||||
let guard = corners.lock().unwrap();
|
|
||||||
|
|
||||||
Some([
|
|
||||||
guard.top_right,
|
|
||||||
guard.bottom_right,
|
|
||||||
guard.top_left,
|
|
||||||
guard.bottom_left,
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.unwrap_or([indicator_thickness; 4]);
|
.unwrap_or([indicator_thickness; 4]);
|
||||||
if is_minimizing && indicator_thickness > 0 {
|
if is_minimizing && indicator_thickness > 0 {
|
||||||
elements.push(CosmicMappedRenderElement::FocusIndicator(
|
elements.push(CosmicMappedRenderElement::FocusIndicator(
|
||||||
|
|
@ -5312,30 +5291,7 @@ where
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let radius = window
|
let radius = window.corner_radius().unwrap_or([indicator_thickness; 4]);
|
||||||
.wl_surface()
|
|
||||||
.and_then(|surface| {
|
|
||||||
with_states(&surface, |s| {
|
|
||||||
let d = s
|
|
||||||
.data_map
|
|
||||||
.get::<Mutex<WsWeak<CosmicCornerRadiusToplevelV1>>>()?;
|
|
||||||
let guard = d.lock().unwrap();
|
|
||||||
|
|
||||||
let weak_data = guard.upgrade().ok()?;
|
|
||||||
|
|
||||||
let corners = weak_data.data::<CornerRadiusData>()?;
|
|
||||||
|
|
||||||
let guard = corners.lock().unwrap();
|
|
||||||
|
|
||||||
Some([
|
|
||||||
guard.top_right,
|
|
||||||
guard.bottom_right,
|
|
||||||
guard.top_left,
|
|
||||||
guard.bottom_left,
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.unwrap_or([indicator_thickness; 4]);
|
|
||||||
swap_elements.push(CosmicMappedRenderElement::FocusIndicator(
|
swap_elements.push(CosmicMappedRenderElement::FocusIndicator(
|
||||||
IndicatorShader::focus_element(
|
IndicatorShader::focus_element(
|
||||||
renderer,
|
renderer,
|
||||||
|
|
@ -5416,28 +5372,7 @@ where
|
||||||
let radius = match data {
|
let radius = match data {
|
||||||
Data::Mapped { mapped, .. } => mapped
|
Data::Mapped { mapped, .. } => mapped
|
||||||
.active_window()
|
.active_window()
|
||||||
.wl_surface()
|
.corner_radius()
|
||||||
.and_then(|surface| {
|
|
||||||
with_states(&surface, |s| {
|
|
||||||
let d = s
|
|
||||||
.data_map
|
|
||||||
.get::<Mutex<WsWeak<CosmicCornerRadiusToplevelV1>>>()?;
|
|
||||||
let guard = d.lock().unwrap();
|
|
||||||
|
|
||||||
let weak_data = guard.upgrade().ok()?;
|
|
||||||
|
|
||||||
let corners = weak_data.data::<CornerRadiusData>()?;
|
|
||||||
|
|
||||||
let guard = corners.lock().unwrap();
|
|
||||||
|
|
||||||
Some([
|
|
||||||
guard.top_right,
|
|
||||||
guard.bottom_right,
|
|
||||||
guard.top_left,
|
|
||||||
guard.bottom_left,
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.unwrap_or([indicator_thickness; 4]),
|
.unwrap_or([indicator_thickness; 4]),
|
||||||
_ => [1; 4],
|
_ => [1; 4],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue