Skip to content

Commit f01ebf2

Browse files
wash2Drakulix
authored andcommitted
refactor(corner-radius): corner_radius method for CosmicSurface
1 parent 4e30513 commit f01ebf2

File tree

4 files changed

+33
-113
lines changed

4 files changed

+33
-113
lines changed

src/shell/element/surface.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::wayland::protocols::corner_radius::CornerRadiusData;
2+
use smithay::reexports::wayland_server::Resource;
13
use std::{
24
borrow::Cow,
35
sync::{
@@ -7,6 +9,7 @@ use std::{
79
time::Duration,
810
};
911

12+
use cosmic_protocols::corner_radius::v1::server::cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1;
1013
use smithay::{
1114
backend::renderer::{
1215
element::{
@@ -34,7 +37,7 @@ use smithay::{
3437
},
3538
},
3639
wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration::Mode as KdeMode,
37-
wayland_server::protocol::wl_surface::WlSurface,
40+
wayland_server::{protocol::wl_surface::WlSurface, Weak},
3841
},
3942
utils::{
4043
user_data::UserDataMap, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size,
@@ -124,6 +127,30 @@ impl CosmicSurface {
124127
}
125128
}
126129

130+
pub fn corner_radius(&self) -> Option<[u8; 4]> {
131+
self.wl_surface().and_then(|surface| {
132+
with_states(&surface, |s| {
133+
let d = s
134+
.data_map
135+
.get::<Mutex<Weak<CosmicCornerRadiusToplevelV1>>>()?;
136+
let guard = d.lock().unwrap();
137+
138+
let weak_data = guard.upgrade().ok()?;
139+
140+
let corners = weak_data.data::<CornerRadiusData>()?;
141+
142+
let guard = corners.lock().unwrap();
143+
144+
Some([
145+
guard.top_right,
146+
guard.bottom_right,
147+
guard.top_left,
148+
guard.bottom_left,
149+
])
150+
})
151+
})
152+
}
153+
127154
pub fn app_id(&self) -> String {
128155
match self.0.underlying_surface() {
129156
WindowSurface::Wayland(toplevel) => with_states(toplevel.wl_surface(), |states| {

src/shell/grabs/moving.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,7 @@ impl MoveGrabState {
119119
let active_window_hint = crate::theme::active_window_hint(theme);
120120
let radius = self
121121
.window()
122-
.wl_surface()
123-
.and_then(|surface| {
124-
with_states(&surface, |s| {
125-
let d = s
126-
.data_map
127-
.get::<Mutex<Weak<CosmicCornerRadiusToplevelV1>>>()?;
128-
let guard = d.lock().unwrap();
129-
130-
let weak_data = guard.upgrade().ok()?;
131-
132-
let corners = weak_data.data::<CornerRadiusData>()?;
133-
134-
let guard = corners.lock().unwrap();
135-
136-
Some([
137-
guard.top_right,
138-
guard.bottom_right,
139-
guard.top_left,
140-
guard.bottom_left,
141-
])
142-
})
143-
})
122+
.corner_radius()
144123
.unwrap_or([self.indicator_thickness; 4]);
145124

146125
let focus_element = if self.indicator_thickness > 0 {

src/shell/layout/floating/mod.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,28 +1600,7 @@ impl FloatingLayout {
16001600
let active_window_hint = crate::theme::active_window_hint(theme);
16011601
let radius = elem
16021602
.active_window()
1603-
.wl_surface()
1604-
.and_then(|surface| {
1605-
with_states(&surface, |s| {
1606-
let d = s
1607-
.data_map
1608-
.get::<Mutex<Weak<CosmicCornerRadiusToplevelV1>>>()?;
1609-
let guard = d.lock().unwrap();
1610-
1611-
let weak_data = guard.upgrade().ok()?;
1612-
1613-
let corners = weak_data.data::<CornerRadiusData>()?;
1614-
1615-
let guard = corners.lock().unwrap();
1616-
1617-
Some([
1618-
guard.top_right,
1619-
guard.bottom_right,
1620-
guard.top_left,
1621-
guard.bottom_left,
1622-
])
1623-
})
1624-
})
1603+
.corner_radius()
16251604
.unwrap_or([indicator_thickness; 4]);
16261605
if indicator_thickness > 0 {
16271606
let element = IndicatorShader::focus_element(

src/shell/layout/tiling/mod.rs

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5020,28 +5020,7 @@ where
50205020
}));
50215021
let radius = mapped
50225022
.active_window()
5023-
.wl_surface()
5024-
.and_then(|surface| {
5025-
with_states(&surface, |s| {
5026-
let d = s
5027-
.data_map
5028-
.get::<Mutex<WsWeak<CosmicCornerRadiusToplevelV1>>>()?;
5029-
let guard = d.lock().unwrap();
5030-
5031-
let weak_data = guard.upgrade().ok()?;
5032-
5033-
let corners = weak_data.data::<CornerRadiusData>()?;
5034-
5035-
let guard = corners.lock().unwrap();
5036-
5037-
Some([
5038-
guard.top_right,
5039-
guard.bottom_right,
5040-
guard.top_left,
5041-
guard.bottom_left,
5042-
])
5043-
})
5044-
})
5023+
.corner_radius()
50455024
.unwrap_or([indicator_thickness; 4]);
50465025
if is_minimizing && indicator_thickness > 0 {
50475026
elements.push(CosmicMappedRenderElement::FocusIndicator(
@@ -5312,30 +5291,7 @@ where
53125291
)
53135292
.unwrap();
53145293

5315-
let radius = window
5316-
.wl_surface()
5317-
.and_then(|surface| {
5318-
with_states(&surface, |s| {
5319-
let d = s
5320-
.data_map
5321-
.get::<Mutex<WsWeak<CosmicCornerRadiusToplevelV1>>>()?;
5322-
let guard = d.lock().unwrap();
5323-
5324-
let weak_data = guard.upgrade().ok()?;
5325-
5326-
let corners = weak_data.data::<CornerRadiusData>()?;
5327-
5328-
let guard = corners.lock().unwrap();
5329-
5330-
Some([
5331-
guard.top_right,
5332-
guard.bottom_right,
5333-
guard.top_left,
5334-
guard.bottom_left,
5335-
])
5336-
})
5337-
})
5338-
.unwrap_or([indicator_thickness; 4]);
5294+
let radius = window.corner_radius().unwrap_or([indicator_thickness; 4]);
53395295
swap_elements.push(CosmicMappedRenderElement::FocusIndicator(
53405296
IndicatorShader::focus_element(
53415297
renderer,
@@ -5416,28 +5372,7 @@ where
54165372
let radius = match data {
54175373
Data::Mapped { mapped, .. } => mapped
54185374
.active_window()
5419-
.wl_surface()
5420-
.and_then(|surface| {
5421-
with_states(&surface, |s| {
5422-
let d = s
5423-
.data_map
5424-
.get::<Mutex<WsWeak<CosmicCornerRadiusToplevelV1>>>()?;
5425-
let guard = d.lock().unwrap();
5426-
5427-
let weak_data = guard.upgrade().ok()?;
5428-
5429-
let corners = weak_data.data::<CornerRadiusData>()?;
5430-
5431-
let guard = corners.lock().unwrap();
5432-
5433-
Some([
5434-
guard.top_right,
5435-
guard.bottom_right,
5436-
guard.top_left,
5437-
guard.bottom_left,
5438-
])
5439-
})
5440-
})
5375+
.corner_radius()
54415376
.unwrap_or([indicator_thickness; 4]),
54425377
_ => [1; 4],
54435378
};

0 commit comments

Comments
 (0)