Skip to content

Commit 0971022

Browse files
committed
wip: proxied corners, padding and blur for popups
1 parent 5b2782c commit 0971022

12 files changed

Lines changed: 1213 additions & 73 deletions

File tree

Cargo.lock

Lines changed: 59 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cosmic-panel-bin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ smithay = { git = "https://github.com/smithay/smithay", default-features = false
1717
"backend_egl",
1818
"backend_drm",
1919
"renderer_gl",
20-
], rev = "dba255c" }
20+
], rev = "f0992e7" }
2121
# sctk = { git = "https://github.com/smithay/client-toolkit", package = "smithay-client-toolkit", features = ["calloop", "xkbcommon"] }
2222
sctk.workspace = true
2323
# sctk = { package = "smithay-client-toolkit", path = "../../fork/client-toolkit", default-features = false, features = ["calloop", "xkbcommon"] }

cosmic-panel-bin/src/space/overflow.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use anyhow::bail;
22
use cctk::sctk::shell::xdg::{XdgPositioner, popup};
33
use cctk::wayland_client::QueueHandle;
4+
use cctk::wayland_client::protocol::wl_region::WlRegion;
45
use cctk::wayland_client::protocol::wl_seat::WlSeat;
56
use cosmic::iced::id;
67

78
use cosmic_panel_config::PanelAnchor;
9+
use sctk::compositor::Region;
810
use sctk::shell::WaylandSurface;
911
use smithay::backend::renderer::damage::OutputDamageTracker;
1012
use smithay::backend::renderer::gles::GlesRenderer;
@@ -113,6 +115,35 @@ impl PanelSpace {
113115

114116
// must be done after role is assigned as popup
115117
c_wl_surface.commit();
118+
let blur_surface = if let Some(blur_manager) = self.blur_manager.as_ref()
119+
&& self.colors.theme.cosmic().frosted_applets
120+
{
121+
let b = blur_manager.get_background_effect(c_popup.wl_surface(), &self.qh, ());
122+
let region = Region::new(compositor_state).unwrap();
123+
region.add(0, 0, popup_bbox.size.w, popup_bbox.size.h);
124+
b.set_blur_region(Some(region.wl_region()));
125+
Some(b)
126+
} else {
127+
None
128+
};
129+
130+
let cosmic = self.colors.theme.cosmic();
131+
let radius_m = cosmic.corner_radii.radius_m;
132+
133+
let corner_radius = if let Some(corner_radius) = self.corner_radius_manager.as_ref()
134+
&& self.colors.theme.cosmic().frosted_applets
135+
{
136+
let c = corner_radius.get_corner_radius_surface(c_popup.xdg_surface(), &self.qh, ());
137+
c.set_radius(
138+
radius_m[0] as u32,
139+
radius_m[1] as u32,
140+
radius_m[2] as u32,
141+
radius_m[3] as u32,
142+
);
143+
Some(c)
144+
} else {
145+
None
146+
};
116147

117148
self.overflow_popup = Some((
118149
PanelPopup {
@@ -135,6 +166,8 @@ impl PanelSpace {
135166
input_region: None,
136167
parent: self.layer.as_ref().unwrap().wl_surface().clone(),
137168
grab: true,
169+
blur_surface,
170+
corner_radius,
138171
},
139172
section,
140173
));

cosmic-panel-bin/src/space/panel_space.rs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::workspaces_dbus::CosmicWorkspaces;
1515
use crate::xdg_shell_wrapper::client::handlers::cosmic_corner_radius::CornerRadius;
1616
use crate::xdg_shell_wrapper::client::handlers::overlap::OverlapNotifyV1;
1717
use crate::xdg_shell_wrapper::client_state::{ClientFocus, FocusStatus};
18+
use crate::xdg_shell_wrapper::server::handlers::cosmic_corner_radius::{CacheableCorners, Corners};
1819
use crate::xdg_shell_wrapper::server_state::{ServerFocus, ServerPtrFocus};
1920
use crate::xdg_shell_wrapper::shared_state::GlobalState;
2021
use crate::xdg_shell_wrapper::space::{
@@ -25,7 +26,6 @@ use crate::xdg_shell_wrapper::util::smootherstep;
2526
use crate::xdg_shell_wrapper::wp_fractional_scaling::FractionalScalingManager;
2627
use crate::xdg_shell_wrapper::wp_security_context::SecurityContextManager;
2728
use crate::xdg_shell_wrapper::wp_viewporter::ViewporterState;
28-
use cctk::cosmic_protocols::corner_radius;
2929
use cctk::cosmic_protocols::corner_radius::v1::client::cosmic_corner_radius_manager_v1::CosmicCornerRadiusManagerV1;
3030
use cctk::cosmic_protocols::overlap_notify::v1::client::zcosmic_overlap_notification_v1::ZcosmicOverlapNotificationV1;
3131
use cctk::sctk::shell::wlr_layer::Layer;
@@ -58,6 +58,7 @@ use smithay::desktop::{PopupManager, Space};
5858
use smithay::output::Output;
5959
use smithay::reexports::wayland_protocols::xdg::shell::client::xdg_positioner::{Anchor, Gravity};
6060
use smithay::reexports::wayland_server::backend::ClientId;
61+
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
6162
use smithay::reexports::wayland_server::{Client, DisplayHandle, Resource};
6263
use smithay::utils::{Logical, Rectangle, Size};
6364
use smithay::wayland::compositor::with_states;
@@ -388,7 +389,7 @@ pub struct PanelSpace {
388389
pub(crate) hover_track: HoverTrack,
389390
pub(crate) start_show_instant: Rc<RefCell<Option<Instant>>>,
390391
pub shared: Rc<PanelSharedState>,
391-
qh: QueueHandle<GlobalState>,
392+
pub(crate) qh: QueueHandle<GlobalState>,
392393
}
393394

394395
impl PanelSpace {
@@ -2135,6 +2136,74 @@ impl PanelSpace {
21352136
}
21362137
self.is_dirty = true;
21372138
}
2139+
2140+
pub(crate) fn update_popup_corners(
2141+
&mut self,
2142+
corners: CacheableCorners,
2143+
surface: &WlSurface,
2144+
) -> bool {
2145+
let Some(popup) = self.popups.iter_mut().find(|p| p.s_surface.wl_surface() == surface)
2146+
else {
2147+
return false;
2148+
};
2149+
let Some(corner_manager) = self.corner_radius_manager.as_ref() else {
2150+
return false;
2151+
};
2152+
2153+
let corners_surface = popup.popup.corner_radius.take().unwrap_or_else(|| {
2154+
corner_manager.get_corner_radius_surface(
2155+
popup.popup.c_popup.xdg_surface(),
2156+
&self.qh,
2157+
(),
2158+
)
2159+
});
2160+
2161+
if let Some(Corners { top_left, top_right, bottom_right, bottom_left }) = corners.0 {
2162+
corners_surface.set_radius(top_left, top_right, bottom_right, bottom_left);
2163+
} else {
2164+
corners_surface.unset_radius();
2165+
}
2166+
2167+
popup.popup.corner_radius = Some(corners_surface);
2168+
2169+
true
2170+
}
2171+
2172+
pub(crate) fn commit_popup_blur(
2173+
&mut self,
2174+
region: Option<&Vec<Rectangle<i32, Logical>>>,
2175+
surface: &WlSurface,
2176+
) -> bool {
2177+
let Some(popup) = self.popups.iter_mut().find(|p| p.s_surface.wl_surface() == surface)
2178+
else {
2179+
return false;
2180+
};
2181+
let Some(blur_manager) = self.blur_manager.as_ref() else {
2182+
return false;
2183+
};
2184+
2185+
let blur_surface = popup.popup.blur_surface.take().unwrap_or_else(|| {
2186+
blur_manager.get_background_effect(popup.popup.c_popup.wl_surface(), &self.qh, ())
2187+
});
2188+
2189+
let Some(compositor_state) = self.compositor_state.as_ref() else {
2190+
tracing::error!("Missing compositor state");
2191+
return false;
2192+
};
2193+
2194+
let region = region.map(|r| {
2195+
let wl_region = Region::new(compositor_state).unwrap();
2196+
for Rectangle { loc, size } in r {
2197+
wl_region.add(loc.x, loc.y, size.w, size.h);
2198+
}
2199+
wl_region
2200+
});
2201+
blur_surface.set_blur_region(region.as_ref().map(|r| r.wl_region()));
2202+
2203+
popup.popup.blur_surface = Some(blur_surface);
2204+
2205+
true
2206+
}
21382207
}
21392208

21402209
impl Drop for PanelSpace {

cosmic-panel-bin/src/space/wrapper_space.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ impl WrapperSpace for PanelSpace {
327327
.map(|p| p.wl_surface().clone())
328328
.unwrap_or(self.layer.as_ref().unwrap().wl_surface().clone()),
329329
grab: true,
330+
blur_surface: None,
331+
corner_radius: None,
330332
},
331333
s_surface,
332334
});

cosmic-panel-bin/src/xdg_shell_wrapper/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub use xdg_shell_wrapper_config as config;
2222
use crate::space_container::SpaceContainer;
2323

2424
pub(crate) mod client;
25-
mod server;
25+
pub(crate) mod server;
2626
/// shared state
2727
pub mod shared_state;
2828
/// wrapper space abstraction

0 commit comments

Comments
 (0)