Reduce panel allocations and fix transient surface leaks (#19)
Repeated panel updates rebuilt unchanged controls and SVG artwork, cloned composition data, and kept unused workspace icon resources. This reuses controls when their layout stays the same, bounds the SVG cache, removes temporary layout allocations, and releases icon resources when apps close or the workspace style changes. Rapidly closing a modal could also leave a native surface behind when its asynchronous creation finished after the close. Late openings now get destroyed when their owner is gone. Ferese uses the published `ferese-v0.1.2` Iced/libcosmic fixes so a temporary software buffer/viewport size mismatch retries the frame instead of crashing. Two runs per version of the same workspace/overview/reload workload measured **26% fewer allocated bytes and 23% fewer allocation calls**. A separate 1,800-cycle notification/modal stress run retained about **40 MiB less shell memory**, including shared-buffer retention falling from 28.2 MiB to 272 KiB. These are measured workload results, not an overall desktop speedup claim. Validation: - 1,350 workspace tests passed, including GPU Settings text rendering (50 optional tests ignored); formatting and Clippy passed. - Native continuous/island panel tests passed rapid notification resizing, modal cancellation, and live material/input-region changes. - A Wayland lifetime trace confirmed all 280 created modal surfaces were destroyed; longer DHAT traces and Intel GPU memory measurements were checked separately. - All installation binaries rebuilt and the installation bundle passed inventory and checksum verification.
This commit is contained in:
1 parent
65fcaef13f
commit
cf540f1feb
14 files changed
+403
-74
No files matched your search
Generated
+18
-18
@@ -705,7 +705,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "build_helpers"
|
name = "build_helpers"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg_aliases",
|
"cfg_aliases",
|
||||||
]
|
]
|
||||||
@@ -1124,7 +1124,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config"
|
name = "cosmic-config"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomicwrites",
|
"atomicwrites",
|
||||||
"cosmic-config-derive",
|
"cosmic-config-derive",
|
||||||
@@ -1145,7 +1145,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config-derive"
|
name = "cosmic-config-derive"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.119",
|
"syn 2.0.119",
|
||||||
@@ -1214,7 +1214,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-theme"
|
name = "cosmic-theme"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"almost",
|
"almost",
|
||||||
"configparser",
|
"configparser",
|
||||||
@@ -2740,7 +2740,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced"
|
name = "iced"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"build_helpers",
|
"build_helpers",
|
||||||
"dnd",
|
"dnd",
|
||||||
@@ -2762,7 +2762,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_accessibility"
|
name = "iced_accessibility"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"accesskit",
|
"accesskit",
|
||||||
"accesskit_winit",
|
"accesskit_winit",
|
||||||
@@ -2771,7 +2771,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_core"
|
name = "iced_core"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.13.2",
|
"bitflags 2.13.2",
|
||||||
"build_helpers",
|
"build_helpers",
|
||||||
@@ -2799,7 +2799,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_debug"
|
name = "iced_debug"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_core",
|
"iced_core",
|
||||||
"iced_futures",
|
"iced_futures",
|
||||||
@@ -2809,7 +2809,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_futures"
|
name = "iced_futures"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
@@ -2823,7 +2823,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_graphics"
|
name = "iced_graphics"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.13.2",
|
"bitflags 2.13.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
@@ -2844,7 +2844,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_program"
|
name = "iced_program"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
"iced_runtime",
|
"iced_runtime",
|
||||||
@@ -2853,7 +2853,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_renderer"
|
name = "iced_renderer"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
"iced_tiny_skia",
|
"iced_tiny_skia",
|
||||||
@@ -2865,7 +2865,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_runtime"
|
name = "iced_runtime"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"build_helpers",
|
"build_helpers",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -2882,7 +2882,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_tiny_skia"
|
name = "iced_tiny_skia"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cosmic-text",
|
"cosmic-text",
|
||||||
@@ -2899,7 +2899,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_wgpu"
|
name = "iced_wgpu"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"as-raw-xcb-connection",
|
"as-raw-xcb-connection",
|
||||||
"bitflags 2.13.2",
|
"bitflags 2.13.2",
|
||||||
@@ -2931,7 +2931,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_widget"
|
name = "iced_widget"
|
||||||
version = "0.14.2"
|
version = "0.14.2"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"build_helpers",
|
"build_helpers",
|
||||||
"cosmic-client-toolkit",
|
"cosmic-client-toolkit",
|
||||||
@@ -2951,7 +2951,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_winit"
|
name = "iced_winit"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"build_helpers",
|
"build_helpers",
|
||||||
"cosmic-client-toolkit",
|
"cosmic-client-toolkit",
|
||||||
@@ -3488,7 +3488,7 @@ checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "libcosmic"
|
name = "libcosmic"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.1#891a4e821687543f5c0debfa385b0b16cf7d9b2c"
|
source = "git+https://github.com/ferese-wm/libcosmic?tag=ferese-v0.1.2#ae75e94131417d33fb91054e4f20b864b5f601fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"apply",
|
"apply",
|
||||||
"ashpd 0.12.3",
|
"ashpd 0.12.3",
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ bitflags = "2.9.4"
|
|||||||
calloop = { version = "0.14.4", features = ["signals"] }
|
calloop = { version = "0.14.4", features = ["signals"] }
|
||||||
jiff = "0.2.37"
|
jiff = "0.2.37"
|
||||||
libc = "0.2.176"
|
libc = "0.2.176"
|
||||||
libcosmic = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.1", default-features = false, features = ["multi-window", "tokio", "wayland"] }
|
libcosmic = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.2", default-features = false, features = ["multi-window", "tokio", "wayland"] }
|
||||||
smithay = { version = "0.7.0", default-features = false, features = [
|
smithay = { version = "0.7.0", default-features = false, features = [
|
||||||
"backend_drm",
|
"backend_drm",
|
||||||
"backend_gbm",
|
"backend_gbm",
|
||||||
|
|||||||
@@ -29,30 +29,34 @@ pub struct Resolution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn zone_width(panel: &Panel, zone: &Zone, items: &BTreeMap<ItemId, Placement>) -> f32 {
|
fn zone_width(panel: &Panel, zone: &Zone, items: &BTreeMap<ItemId, Placement>) -> f32 {
|
||||||
let mut groups = Vec::new();
|
let mut width = 0.0;
|
||||||
|
let mut group_count: usize = 0;
|
||||||
for group in &zone.groups {
|
for group in &zone.groups {
|
||||||
let mut widths = Vec::new();
|
let mut content_width = 0.0;
|
||||||
|
let mut occupied = false;
|
||||||
for item in &group.items {
|
for item in &group.items {
|
||||||
if let Some(Placement::Visible { width, .. }) = items.get(&item.id)
|
if let Some(Placement::Visible { width, .. }) = items.get(&item.id)
|
||||||
&& *width > 0.0
|
&& *width > 0.0
|
||||||
{
|
{
|
||||||
if !widths.is_empty() {
|
if occupied {
|
||||||
widths.push(item.gap_before.unwrap_or(group.spacing));
|
content_width += item.gap_before.unwrap_or(group.spacing);
|
||||||
}
|
}
|
||||||
widths.push(*width);
|
content_width += *width;
|
||||||
|
occupied = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !widths.is_empty() {
|
if occupied {
|
||||||
let padding = 2.0 * f32::from(group.padding[1]);
|
let padding = 2.0 * f32::from(group.padding[1]);
|
||||||
let island = if panel.resolved_surface(group) == super::GroupSurface::Island {
|
let island = if panel.resolved_surface(group) == super::GroupSurface::Island {
|
||||||
2.0 * group.island_padding
|
2.0 * group.island_padding
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
groups.push(widths.iter().sum::<f32>() + padding + island);
|
width += content_width + padding + island;
|
||||||
|
group_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
groups.iter().sum::<f32>() + zone.spacing * groups.len().saturating_sub(1) as f32
|
width + zone.spacing * group_count.saturating_sub(1) as f32
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Resolution {
|
impl Resolution {
|
||||||
@@ -271,19 +275,14 @@ pub fn resolve_with_gap(
|
|||||||
let mut high = maximum;
|
let mut high = maximum;
|
||||||
for _ in 0..20 {
|
for _ in 0..20 {
|
||||||
let width = (low + high) * 0.5;
|
let width = (low + high) * 0.5;
|
||||||
result
|
*result.items.get_mut(&measured.id).unwrap() = Placement::Visible { representation, width };
|
||||||
.items
|
|
||||||
.insert(measured.id.clone(), Placement::Visible { representation, width });
|
|
||||||
result.update_widths(panel, overflow_width);
|
result.update_widths(panel, overflow_width);
|
||||||
if fits(&result) { low = width } else { high = width }
|
if fits(&result) { low = width } else { high = width }
|
||||||
}
|
}
|
||||||
result.items.insert(
|
*result.items.get_mut(&measured.id).unwrap() = Placement::Visible {
|
||||||
measured.id.clone(),
|
representation,
|
||||||
Placement::Visible {
|
width: low,
|
||||||
representation,
|
};
|
||||||
width: low,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
.overflow
|
.overflow
|
||||||
@@ -296,6 +295,55 @@ pub fn resolve_with_gap(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zone_width_ignores_empty_groups_and_gaps_before_hidden_items() {
|
||||||
|
use super::super::{Group, GroupSurface, Item, ItemKind};
|
||||||
|
let mut panel = Panel::default();
|
||||||
|
let mut first = Item::new("first", ItemKind::Overview);
|
||||||
|
first.gap_before = Some(99.);
|
||||||
|
let hidden = Item::new("hidden", ItemKind::Network);
|
||||||
|
let mut last = Item::new("last", ItemKind::Clock);
|
||||||
|
last.gap_before = Some(7.);
|
||||||
|
let mut group = Group::new("content", vec![first, hidden, last], [0, 3], 5.);
|
||||||
|
group.surface = Some(GroupSurface::Island);
|
||||||
|
group.island_padding = 4.;
|
||||||
|
let empty = Group::new("empty", vec![Item::new("missing", ItemKind::Media)], [0, 99], 99.);
|
||||||
|
let trailing = Group::new(
|
||||||
|
"trailing",
|
||||||
|
vec![Item::new("trailing", ItemKind::Battery { percentage: false })],
|
||||||
|
[0, 2],
|
||||||
|
5.,
|
||||||
|
);
|
||||||
|
panel.start.groups = vec![empty.clone(), group, empty, trailing];
|
||||||
|
panel.start.spacing = 11.;
|
||||||
|
let items = [
|
||||||
|
(
|
||||||
|
ItemId("first".into()),
|
||||||
|
Placement::Visible {
|
||||||
|
representation: Representation::Icon,
|
||||||
|
width: 20.,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(ItemId("hidden".into()), Placement::Overflow),
|
||||||
|
(
|
||||||
|
ItemId("last".into()),
|
||||||
|
Placement::Visible {
|
||||||
|
representation: Representation::Wide,
|
||||||
|
width: 30.,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
ItemId("trailing".into()),
|
||||||
|
Placement::Visible {
|
||||||
|
representation: Representation::Icon,
|
||||||
|
width: 10.,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
.into();
|
||||||
|
assert_eq!(zone_width(&panel, &panel.start, &items), 96.);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_center_only_item_keeps_its_preferred_size_without_side_gaps() {
|
fn a_center_only_item_keeps_its_preferred_size_without_side_gaps() {
|
||||||
use super::super::{Group, Item, ItemKind};
|
use super::super::{Group, Item, ItemKind};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ ferese-theme-model = { path = "../ferese-theme-model" }
|
|||||||
ferese-config = { path = "../ferese-config" }
|
ferese-config = { path = "../ferese-config" }
|
||||||
libcosmic = { workspace = true, features = ["a11y"] }
|
libcosmic = { workspace = true, features = ["a11y"] }
|
||||||
|
|
||||||
iced_accessibility = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.1" }
|
iced_accessibility = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.2" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { version = "1", features = ["rt"] }
|
tokio = { version = "1", features = ["rt"] }
|
||||||
@@ -76,6 +76,69 @@ pub fn symbolic(source: &'static [u8], size: u16) -> icon::Icon {
|
|||||||
icon::from_svg_bytes(source).symbolic(true).icon().size(size)
|
icon::from_svg_bytes(source).symbolic(true).icon().size(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TINT_CACHE_ENTRIES: usize = 64;
|
||||||
|
const TINT_CACHE_BYTES: usize = 128 * 1024;
|
||||||
|
|
||||||
|
struct TintedIcon {
|
||||||
|
source: &'static [u8],
|
||||||
|
colors: [u32; 8],
|
||||||
|
handle: icon::Handle,
|
||||||
|
bytes: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct TintCache {
|
||||||
|
entries: std::collections::VecDeque<TintedIcon>,
|
||||||
|
bytes: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TintCache {
|
||||||
|
fn get(&mut self, source: &'static [u8], foreground: Color, accent: Color) -> icon::Handle {
|
||||||
|
let colors = [
|
||||||
|
foreground.r,
|
||||||
|
foreground.g,
|
||||||
|
foreground.b,
|
||||||
|
foreground.a,
|
||||||
|
accent.r,
|
||||||
|
accent.g,
|
||||||
|
accent.b,
|
||||||
|
accent.a,
|
||||||
|
]
|
||||||
|
.map(f32::to_bits);
|
||||||
|
if let Some(index) = self
|
||||||
|
.entries
|
||||||
|
.iter()
|
||||||
|
.position(|entry| std::ptr::eq(entry.source, source) && entry.colors == colors)
|
||||||
|
{
|
||||||
|
let entry = self.entries.remove(index).unwrap();
|
||||||
|
let handle = entry.handle.clone();
|
||||||
|
self.entries.push_back(entry);
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
let svg = tint_svg(source, foreground, accent);
|
||||||
|
let bytes = svg.capacity();
|
||||||
|
let handle = icon::from_svg_bytes(svg).symbolic(false);
|
||||||
|
if bytes <= TINT_CACHE_BYTES {
|
||||||
|
while self.entries.len() >= TINT_CACHE_ENTRIES || self.bytes + bytes > TINT_CACHE_BYTES {
|
||||||
|
self.bytes -= self.entries.pop_front().unwrap().bytes;
|
||||||
|
}
|
||||||
|
self.bytes += bytes;
|
||||||
|
self.entries.push_back(TintedIcon {
|
||||||
|
source,
|
||||||
|
colors,
|
||||||
|
handle: handle.clone(),
|
||||||
|
bytes,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
handle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_local! {
|
||||||
|
// Retain shared artwork across view rebuilds, with bounded storage as colors change.
|
||||||
|
static TINT_CACHE: std::cell::RefCell<TintCache> = std::cell::RefCell::new(TintCache::default());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn accented(source: &'static [u8], size: u16, foreground: Color, accent: Color) -> icon::Icon {
|
pub fn accented(source: &'static [u8], size: u16, foreground: Color, accent: Color) -> icon::Icon {
|
||||||
let svg = std::str::from_utf8(source).expect("embedded SVG must be UTF-8");
|
let svg = std::str::from_utf8(source).expect("embedded SVG must be UTF-8");
|
||||||
// Battery canvases are wider; reserve that space instead of stretching
|
// Battery canvases are wider; reserve that space instead of stretching
|
||||||
@@ -85,8 +148,8 @@ pub fn accented(source: &'static [u8], size: u16, foreground: Color, accent: Col
|
|||||||
} else {
|
} else {
|
||||||
1.0
|
1.0
|
||||||
};
|
};
|
||||||
icon::from_svg_bytes(tint_svg(source, foreground, accent))
|
TINT_CACHE
|
||||||
.symbolic(false)
|
.with(|cache| cache.borrow_mut().get(source, foreground, accent))
|
||||||
.icon()
|
.icon()
|
||||||
.size(size)
|
.size(size)
|
||||||
.width(Length::Fixed(f32::from(size) * aspect))
|
.width(Length::Fixed(f32::from(size) * aspect))
|
||||||
@@ -131,6 +194,45 @@ pub fn outline(path: &str, tint: Color, size: u16) -> icon::Icon {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use cosmic::iced::Color;
|
use cosmic::iced::Color;
|
||||||
|
#[test]
|
||||||
|
fn tinted_icons_share_artwork_and_distinguish_accent_and_alpha() {
|
||||||
|
let mut cache = super::TintCache::default();
|
||||||
|
let foreground = Color::from_rgb8(205, 214, 244);
|
||||||
|
let accent = Color::from_rgb8(203, 166, 247);
|
||||||
|
let bytes = |handle: &cosmic::widget::icon::Handle| {
|
||||||
|
let cosmic::widget::icon::Data::Svg(svg) = &handle.data else {
|
||||||
|
panic!("expected SVG");
|
||||||
|
};
|
||||||
|
let cosmic::iced::advanced::svg::Data::Bytes(bytes) = svg.data() else {
|
||||||
|
panic!("expected SVG bytes");
|
||||||
|
};
|
||||||
|
bytes.as_ptr()
|
||||||
|
};
|
||||||
|
let first = cache.get(super::BATTERY_50, foreground, accent);
|
||||||
|
let second = cache.get(super::BATTERY_50, foreground, accent);
|
||||||
|
assert_eq!(bytes(&first), bytes(&second), "rebuilds must reuse the same allocation");
|
||||||
|
let changed_accent = cache.get(super::BATTERY_50, foreground, Color::from_rgb8(42, 90, 180));
|
||||||
|
assert_ne!(bytes(&first), bytes(&changed_accent));
|
||||||
|
let translucent = cache.get(super::BATTERY_50, Color { a: 0.5, ..foreground }, accent);
|
||||||
|
assert_ne!(bytes(&first), bytes(&translucent));
|
||||||
|
assert_eq!(cache.entries.len(), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn icon_tint_cache_evicts_old_colors_without_growing() {
|
||||||
|
let mut cache = super::TintCache::default();
|
||||||
|
for value in 0..512 {
|
||||||
|
let _ = cache.get(
|
||||||
|
super::FERESE,
|
||||||
|
Color::from_rgba(0.5, 0.5, 0.5, value as f32 / 512.),
|
||||||
|
Color::BLACK,
|
||||||
|
);
|
||||||
|
assert!(cache.entries.len() <= super::TINT_CACHE_ENTRIES);
|
||||||
|
assert!(cache.bytes <= super::TINT_CACHE_BYTES);
|
||||||
|
}
|
||||||
|
assert_eq!(cache.entries.back().unwrap().colors[3], (511_f32 / 512.).to_bits());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn icons_use_theme_accent_and_preserve_battery_status_colors() {
|
fn icons_use_theme_accent_and_preserve_battery_status_colors() {
|
||||||
for (source, accent) in [
|
for (source, accent) in [
|
||||||
|
|||||||
@@ -139,16 +139,19 @@ impl<M> Widget<M, Theme, cosmic::Renderer> for Adaptive<'_, M> {
|
|||||||
.find(|measurement| measurement.id.0 == "_overflow")
|
.find(|measurement| measurement.id.0 == "_overflow")
|
||||||
.map_or(0.0, |measurement| measurement.alternatives[0].1);
|
.map_or(0.0, |measurement| measurement.alternatives[0].1);
|
||||||
let trigger = trigger.min((limits.max().width - self.overflow_width).max(0.0));
|
let trigger = trigger.min((limits.max().width - self.overflow_width).max(0.0));
|
||||||
self.resolution = resolve_with_gap(
|
let mut resolution = resolve_with_gap(
|
||||||
&self.panel,
|
&self.panel,
|
||||||
&measurements,
|
&measurements,
|
||||||
limits.max().width,
|
limits.max().width,
|
||||||
(self.overflow_width + trigger).min(limits.max().width),
|
(self.overflow_width + trigger).min(limits.max().width),
|
||||||
self.zone_gap,
|
self.zone_gap,
|
||||||
);
|
);
|
||||||
self.resolution.overflow_trigger_width = trigger;
|
resolution.overflow_trigger_width = trigger;
|
||||||
self.content = (self.build)(&self.resolution);
|
if self.resolution != resolution {
|
||||||
tree.children[0].diff(self.content.as_widget_mut());
|
self.resolution = resolution;
|
||||||
|
self.content = (self.build)(&self.resolution);
|
||||||
|
tree.children[0].diff(self.content.as_widget_mut());
|
||||||
|
}
|
||||||
self.content
|
self.content
|
||||||
.as_widget_mut()
|
.as_widget_mut()
|
||||||
.layout(&mut tree.children[0], renderer, limits)
|
.layout(&mut tree.children[0], renderer, limits)
|
||||||
@@ -383,12 +386,15 @@ mod tests {
|
|||||||
}))
|
}))
|
||||||
.collect();
|
.collect();
|
||||||
let id = id.clone();
|
let id = id.clone();
|
||||||
|
let builds = std::cell::Cell::new(0);
|
||||||
|
let build_count = &builds;
|
||||||
let mut view = frame(
|
let mut view = frame(
|
||||||
Cow::Borrowed(&panel),
|
Cow::Borrowed(&panel),
|
||||||
samples,
|
samples,
|
||||||
0.,
|
0.,
|
||||||
Resolution::default(),
|
Resolution::default(),
|
||||||
move |resolution| {
|
move |resolution| {
|
||||||
|
build_count.set(build_count.get() + 1);
|
||||||
let width = match resolution.items.get(&id) {
|
let width = match resolution.items.get(&id) {
|
||||||
Some(Placement::Visible { width, .. }) => *width,
|
Some(Placement::Visible { width, .. }) => *width,
|
||||||
_ => resolution.overflow_trigger_width,
|
_ => resolution.overflow_trigger_width,
|
||||||
@@ -406,6 +412,10 @@ mod tests {
|
|||||||
let viewport = Rectangle::new(Point::ORIGIN, Size::new(width, 28.));
|
let viewport = Rectangle::new(Point::ORIGIN, Size::new(width, 28.));
|
||||||
let limits = layout::Limits::new(Size::ZERO, viewport.size());
|
let limits = layout::Limits::new(Size::ZERO, viewport.size());
|
||||||
let node = view.as_widget_mut().layout(tree, &renderer, &limits);
|
let node = view.as_widget_mut().layout(tree, &renderer, &limits);
|
||||||
|
let built = builds.get();
|
||||||
|
assert_eq!(built, 2, "initial measurement must replace the unallocated content");
|
||||||
|
view.as_widget_mut().layout(tree, &renderer, &limits);
|
||||||
|
assert_eq!(builds.get(), built, "unchanged allocation must reuse its controls");
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
for _ in 0..4 {
|
for _ in 0..4 {
|
||||||
view.as_widget_mut().update(
|
view.as_widget_mut().update(
|
||||||
|
|||||||
@@ -89,10 +89,15 @@ class ShellMotionTest(unittest.TestCase):
|
|||||||
env=ipc_environment(env), text=True, capture_output=True, timeout=5, check=check)
|
env=ipc_environment(env), text=True, capture_output=True, timeout=5, check=check)
|
||||||
|
|
||||||
def layer_surface(namespace):
|
def layer_surface(namespace):
|
||||||
matches = list(re.finditer(r'get_layer_surface\([^\n]*?wl_surface[@#](\d+)[^\n]*"' + namespace + '"', log_path.read_text()))
|
matches = layer_surfaces(namespace)
|
||||||
# Wayland object IDs can be reused after destruction. Restrict
|
# Wayland object IDs can be reused after destruction. Restrict
|
||||||
# assertions to this surface's lifetime in the trace.
|
# assertions to this surface's lifetime in the trace.
|
||||||
return (matches[-1].group(1), matches[-1].start()) if matches else None
|
return matches[-1] if matches else None
|
||||||
|
|
||||||
|
def layer_surfaces(namespace):
|
||||||
|
return [(match.group(1), match.start()) for match in re.finditer(
|
||||||
|
r'get_layer_surface\([^\n]*?wl_surface[@#](\d+)[^\n]*"' + namespace + '"',
|
||||||
|
log_path.read_text())]
|
||||||
|
|
||||||
def frames(surface):
|
def frames(surface):
|
||||||
identity, start = surface
|
identity, start = surface
|
||||||
@@ -200,6 +205,48 @@ class ShellMotionTest(unittest.TestCase):
|
|||||||
self.assertNotIn("panicked at", log_path.read_text())
|
self.assertNotIn("panicked at", log_path.read_text())
|
||||||
print(f"Modal: {frames(modal)} callbacks; interrupted opening closed and destroyed", flush=True)
|
print(f"Modal: {frames(modal)} callbacks; interrupted opening closed and destroyed", flush=True)
|
||||||
|
|
||||||
|
# A toast can resize or start closing before its previous
|
||||||
|
# software buffer has caught up with the new viewport.
|
||||||
|
for index in range(40):
|
||||||
|
reply = dbus("Notify", "Ferese motion test", "0", "", "Rapid toast",
|
||||||
|
"Short body", "[]", "{}", "0").stdout
|
||||||
|
notice = re.search(r'uint32 (\d+)', reply).group(1)
|
||||||
|
if index % 2 == 0:
|
||||||
|
dbus("Notify", "Ferese motion test", notice, "", "Updated toast",
|
||||||
|
"A longer notification body that wraps over several lines. " * 6,
|
||||||
|
"[]", "{}", "0")
|
||||||
|
dbus("CloseNotification", notice)
|
||||||
|
time.sleep(.015)
|
||||||
|
time.sleep(.5)
|
||||||
|
self.assertIsNone(compositor.poll(), log_path.read_text()[-8000:])
|
||||||
|
self.assertEqual(dbus("GetServerInformation", check=False).returncode, 0)
|
||||||
|
self.assertNotIn("panicked at", log_path.read_text())
|
||||||
|
print("Toast: 40 rapid open/update/close cycles completed", flush=True)
|
||||||
|
|
||||||
|
for _ in range(40):
|
||||||
|
subprocess.run([str(ctl), "toggle-keybinding-guide"],
|
||||||
|
env=ipc_environment(env), check=True, capture_output=True)
|
||||||
|
time.sleep(.03)
|
||||||
|
subprocess.run([str(ctl), "toggle-keybinding-guide"],
|
||||||
|
env=ipc_environment(env), check=True, capture_output=True)
|
||||||
|
time.sleep(.06)
|
||||||
|
# A final toggle may leave the owned modal closing. Let
|
||||||
|
# that motion finish before deciding whether a live modal
|
||||||
|
# needs another toggle; toggling during closing reopens it.
|
||||||
|
deadline = time.monotonic() + 5
|
||||||
|
while True:
|
||||||
|
remaining = [surface for surface in layer_surfaces("ferese-system-modal")
|
||||||
|
if not destroyed(surface)]
|
||||||
|
if not remaining or time.monotonic() >= deadline:
|
||||||
|
break
|
||||||
|
time.sleep(.05)
|
||||||
|
self.assertLessEqual(len(remaining), 1, "cancelled modals retained native surfaces")
|
||||||
|
if remaining:
|
||||||
|
subprocess.run([str(ctl), "toggle-keybinding-guide"],
|
||||||
|
env=ipc_environment(env), check=True, capture_output=True)
|
||||||
|
wait_for(lambda: destroyed(remaining[0]))
|
||||||
|
print("Modal: rapid toggles released all native surfaces", flush=True)
|
||||||
|
|
||||||
if bar_layout == "islands":
|
if bar_layout == "islands":
|
||||||
for layout_name, expected_count in [("continuous", 1), ("islands", None)]:
|
for layout_name, expected_count in [("continuous", 1), ("islands", None)]:
|
||||||
config_file.write_text('animations { speed 0.5; }\nstatus { keybinding-guide #false; }\n' + panel_config(layout_name))
|
config_file.write_text('animations { speed 0.5; }\nstatus { keybinding-guide #false; }\n' + panel_config(layout_name))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ ferese-theme-client = { path = "../../crates/ferese-theme-client" }
|
|||||||
ferese-theme = { path = "../../crates/ferese-theme" }
|
ferese-theme = { path = "../../crates/ferese-theme" }
|
||||||
ferese-config = { path = "../../crates/ferese-config" }
|
ferese-config = { path = "../../crates/ferese-config" }
|
||||||
libcosmic = { workspace = true, features = ["wgpu", "a11y", "xdg-portal"] }
|
libcosmic = { workspace = true, features = ["wgpu", "a11y", "xdg-portal"] }
|
||||||
iced_accessibility = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.1" }
|
iced_accessibility = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.2" }
|
||||||
ferese-ipc = { path = "../../crates/ferese-ipc" }
|
ferese-ipc = { path = "../../crates/ferese-ipc" }
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
tempfile.workspace = true
|
tempfile.workspace = true
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ libc.workspace = true
|
|||||||
# tiny-skia to avoid a second GPU initialization during desktop startup.
|
# tiny-skia to avoid a second GPU initialization during desktop startup.
|
||||||
libcosmic = { workspace = true, features = ["wgpu", "a11y"] }
|
libcosmic = { workspace = true, features = ["wgpu", "a11y"] }
|
||||||
freedesktop-desktop-entry = { version = "0.8.3", default-features = false }
|
freedesktop-desktop-entry = { version = "0.8.3", default-features = false }
|
||||||
iced_accessibility = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.1" }
|
iced_accessibility = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.2" }
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
tempfile.workspace = true
|
tempfile.workspace = true
|
||||||
|
|||||||
@@ -131,16 +131,13 @@ impl FereseShell {
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
move |resolution| {
|
move |resolution| {
|
||||||
let zone = |zone: &Zone| {
|
let zone = |zone: &Zone| {
|
||||||
let mut zone = zone.clone();
|
|
||||||
for group in &mut zone.groups {
|
|
||||||
group.items.retain(|item| matches!(resolution.items.get(&item.id), Some(Placement::Visible { width, .. }) if *width > 0.0));
|
|
||||||
}
|
|
||||||
view_zone(
|
view_zone(
|
||||||
panel,
|
panel,
|
||||||
&zone,
|
zone,
|
||||||
availability,
|
availability,
|
||||||
shell_theme,
|
shell_theme,
|
||||||
compositor_material,
|
compositor_material,
|
||||||
|
|item| matches!(resolution.items.get(&item.id), Some(Placement::Visible { width, .. }) if *width > 0.0),
|
||||||
|item, surface| {
|
|item, surface| {
|
||||||
let Some(Placement::Visible { representation, width }) = resolution.items.get(&item.id)
|
let Some(Placement::Visible { representation, width }) = resolution.items.get(&item.id)
|
||||||
else {
|
else {
|
||||||
@@ -171,6 +168,7 @@ impl FereseShell {
|
|||||||
availability,
|
availability,
|
||||||
shell_theme,
|
shell_theme,
|
||||||
compositor_material,
|
compositor_material,
|
||||||
|
|_| true,
|
||||||
|item, surface| {
|
|item, surface| {
|
||||||
self.view_panel_item(
|
self.view_panel_item(
|
||||||
id,
|
id,
|
||||||
@@ -566,6 +564,7 @@ fn view_zone<'a>(
|
|||||||
availability: Availability,
|
availability: Availability,
|
||||||
shell_theme: ShellTheme,
|
shell_theme: ShellTheme,
|
||||||
compositor_material: bool,
|
compositor_material: bool,
|
||||||
|
visible: impl Fn(&Item) -> bool,
|
||||||
render: impl Fn(&Item, GroupSurface) -> (Element<'a, cosmic::Action<Message>>, bool),
|
render: impl Fn(&Item, GroupSurface) -> (Element<'a, cosmic::Action<Message>>, bool),
|
||||||
) -> Element<'a, cosmic::Action<Message>> {
|
) -> Element<'a, cosmic::Action<Message>> {
|
||||||
let bar = BarMetrics::from(panel.geometry);
|
let bar = BarMetrics::from(panel.geometry);
|
||||||
@@ -577,7 +576,11 @@ fn view_zone<'a>(
|
|||||||
let mut controls = row::with_capacity(group.items.len()).align_y(cosmic::iced::Alignment::Center);
|
let mut controls = row::with_capacity(group.items.len()).align_y(cosmic::iced::Alignment::Center);
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let mut has_content = false;
|
let mut has_content = false;
|
||||||
for item in group.items.iter().filter(|item| item.available(availability)) {
|
for item in group
|
||||||
|
.items
|
||||||
|
.iter()
|
||||||
|
.filter(|item| item.available(availability) && visible(item))
|
||||||
|
{
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
controls =
|
controls =
|
||||||
controls.push(cosmic::iced::widget::Space::new().width(item.gap_before.unwrap_or(group.spacing)));
|
controls.push(cosmic::iced::widget::Space::new().width(item.gap_before.unwrap_or(group.spacing)));
|
||||||
@@ -1006,24 +1009,32 @@ mod island_tests {
|
|||||||
Some("tiny-skia"),
|
Some("tiny-skia"),
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let view = view_zone(panel, zone, availability, theme, true, |item, _| {
|
let view = view_zone(
|
||||||
let width = match item.kind {
|
panel,
|
||||||
ItemKind::Overview => 28.,
|
zone,
|
||||||
ItemKind::Workspaces { .. } => 72.,
|
availability,
|
||||||
ItemKind::FocusedWindow => 80.,
|
theme,
|
||||||
ItemKind::Clock => 60.,
|
true,
|
||||||
_ => 20.,
|
|_| true,
|
||||||
};
|
|item, _| {
|
||||||
let height = if matches!(item.kind, ItemKind::FocusedWindow) {
|
let width = match item.kind {
|
||||||
24.
|
ItemKind::Overview => 28.,
|
||||||
} else {
|
ItemKind::Workspaces { .. } => 72.,
|
||||||
20.
|
ItemKind::FocusedWindow => 80.,
|
||||||
};
|
ItemKind::Clock => 60.,
|
||||||
(
|
_ => 20.,
|
||||||
container(cosmic::iced::widget::Space::new().width(width).height(height)).into(),
|
};
|
||||||
!matches!(item.kind, ItemKind::FocusedWindow) || title_content,
|
let height = if matches!(item.kind, ItemKind::FocusedWindow) {
|
||||||
)
|
24.
|
||||||
});
|
} else {
|
||||||
|
20.
|
||||||
|
};
|
||||||
|
(
|
||||||
|
container(cosmic::iced::widget::Space::new().width(width).height(height)).into(),
|
||||||
|
!matches!(item.kind, ItemKind::FocusedWindow) || title_content,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
let mut view: Element<'_, cosmic::Action<Message>> = container(view)
|
let mut view: Element<'_, cosmic::Action<Message>> = container(view)
|
||||||
.height(panel.geometry.height)
|
.height(panel.geometry.height)
|
||||||
.align_y(alignment::Vertical::Center)
|
.align_y(alignment::Vertical::Center)
|
||||||
|
|||||||
@@ -1378,6 +1378,36 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn late_open_checks_preserve_owned_desktop_widgets_and_tooltips() {
|
||||||
|
let mut shell = shell_with_measured_panel();
|
||||||
|
let wallpaper = window::Id::unique();
|
||||||
|
let clock = window::Id::unique();
|
||||||
|
let note = window::Id::unique();
|
||||||
|
let tooltip = window::Id::unique();
|
||||||
|
shell.outputs[0].wallpaper = Some(wallpaper);
|
||||||
|
shell.outputs[0].clock = Some(clock);
|
||||||
|
shell.outputs[0].notes.push(("note".into(), note));
|
||||||
|
shell.workspace_ui.tooltip = Some(tooltip);
|
||||||
|
for id in [wallpaper, clock, note, tooltip] {
|
||||||
|
assert!(shell.owns_surface(id));
|
||||||
|
assert_eq!(
|
||||||
|
shell
|
||||||
|
.handle_event(
|
||||||
|
Event::Window(window::Event::Opened {
|
||||||
|
position: None,
|
||||||
|
size: cosmic::iced::Size::new(100., 100.),
|
||||||
|
}),
|
||||||
|
id,
|
||||||
|
)
|
||||||
|
.units(),
|
||||||
|
0,
|
||||||
|
"an owned surface must not be destroyed on opening"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert!(!shell.owns_surface(window::Id::unique()));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn an_empty_measured_panel_is_not_an_unmeasured_panel() {
|
fn an_empty_measured_panel_is_not_an_unmeasured_panel() {
|
||||||
let mut shell = shell_with_measured_panel();
|
let mut shell = shell_with_measured_panel();
|
||||||
|
|||||||
@@ -203,6 +203,22 @@ impl FereseShell {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn owns_surface(&self, id: window::Id) -> bool {
|
||||||
|
self.outputs.iter().any(|entry| {
|
||||||
|
entry.bar == id
|
||||||
|
|| entry.wallpaper == Some(id)
|
||||||
|
|| entry.clock == Some(id)
|
||||||
|
|| entry.notes.iter().any(|(_, surface)| *surface == id)
|
||||||
|
}) || self.menu.as_ref().is_some_and(|menu| menu.id == id)
|
||||||
|
|| self.system_modal.as_ref().is_some_and(|modal| modal.contains(id))
|
||||||
|
|| self
|
||||||
|
.notification_surface
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|surface| surface.id == id)
|
||||||
|
|| self.workspace_ui.tooltip == Some(id)
|
||||||
|
|| self.note_drag.as_ref().is_some_and(|drag| drag.overlay == id)
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn handle_event(&mut self, event: Event, id: window::Id) -> Task<Message> {
|
pub(super) fn handle_event(&mut self, event: Event, id: window::Id) -> Task<Message> {
|
||||||
if matches!(event, Event::Mouse(cosmic::iced::mouse::Event::CursorLeft)) {
|
if matches!(event, Event::Mouse(cosmic::iced::mouse::Event::CursorLeft)) {
|
||||||
return self.dismiss_workspace_tooltip_for_bar(id);
|
return self.dismiss_workspace_tooltip_for_bar(id);
|
||||||
@@ -338,6 +354,15 @@ impl FereseShell {
|
|||||||
Event::PlatformSpecific(PlatformSpecific::Wayland(wayland::Event::Output(event, output))) => {
|
Event::PlatformSpecific(PlatformSpecific::Wayland(wayland::Event::Output(event, output))) => {
|
||||||
self.output_event(event, output)
|
self.output_event(event, output)
|
||||||
}
|
}
|
||||||
|
Event::Window(window::Event::Opened { .. }) if !self.owns_surface(id) => {
|
||||||
|
// Creation is asynchronous. A close can arrive before the
|
||||||
|
// surface exists, so dispose of any late opening once its
|
||||||
|
// owner has gone away. IDs are never reused by the shell.
|
||||||
|
Task::batch([
|
||||||
|
destroy_layer_surface(id),
|
||||||
|
cosmic::task::message(cosmic::Action::Surface(cosmic::surface::action::destroy_popup(id))),
|
||||||
|
])
|
||||||
|
}
|
||||||
Event::Window(window::Event::Opened { .. })
|
Event::Window(window::Event::Opened { .. })
|
||||||
if self.outputs.iter().any(|entry| entry.bar == id)
|
if self.outputs.iter().any(|entry| entry.bar == id)
|
||||||
|| self.menu.as_ref().is_some_and(|menu| menu.id == id)
|
|| self.menu.as_ref().is_some_and(|menu| menu.id == id)
|
||||||
|
|||||||
@@ -683,6 +683,33 @@ fn modal_focus_operation<T: Send + 'static>(backwards: bool) -> Box<dyn cosmic::
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_cancelled_modal_that_opens_late_is_destroyed_without_closing_its_replacement() {
|
||||||
|
let mut app = crate::tests::shell_with_measured_panel();
|
||||||
|
drop(app.open_guide(Vec::new()));
|
||||||
|
let cancelled = app.system_modal.as_ref().unwrap().surfaces[0].id;
|
||||||
|
assert!(app.owns_surface(cancelled));
|
||||||
|
drop(app.destroy_system_modal(false));
|
||||||
|
drop(app.open_guide(Vec::new()));
|
||||||
|
let replacement = app.system_modal.as_ref().unwrap().surfaces[0].id;
|
||||||
|
assert!(!app.owns_surface(cancelled));
|
||||||
|
assert!(app.owns_surface(replacement));
|
||||||
|
|
||||||
|
let close = app.handle_event(
|
||||||
|
Event::Window(window::Event::Opened {
|
||||||
|
position: None,
|
||||||
|
size: cosmic::iced::Size::new(800., 600.),
|
||||||
|
}),
|
||||||
|
cancelled,
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
close.units(),
|
||||||
|
2,
|
||||||
|
"a late layer or popup must receive a destruction command"
|
||||||
|
);
|
||||||
|
assert!(app.owns_surface(replacement));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tab_stays_within_modal_actions_in_both_directions() {
|
fn tab_stays_within_modal_actions_in_both_directions() {
|
||||||
use cosmic::iced::Rectangle;
|
use cosmic::iced::Rectangle;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ fn discover_icons(entries: Option<Arc<Vec<fde::DesktopEntry>>>, app_ids: Vec<Str
|
|||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
Arc::new(
|
Arc::new(
|
||||||
fde::Iter::new(fde::default_paths())
|
fde::Iter::new(fde::default_paths())
|
||||||
.entries::<&str>(None)
|
.entries::<&str>(Some(&[]))
|
||||||
.filter(|entry| seen.insert(entry.appid.clone()))
|
.filter(|entry| seen.insert(entry.appid.clone()))
|
||||||
.filter(|entry| !entry.hidden())
|
.filter(|entry| !entry.hidden())
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -402,7 +402,14 @@ impl WorkspaceUi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn load_icons(&mut self, snapshot: &ShellSnapshot, needed: bool) -> Task<Message> {
|
fn load_icons(&mut self, snapshot: &ShellSnapshot, needed: bool) -> Task<Message> {
|
||||||
if !needed || self.icons_loading {
|
if !needed {
|
||||||
|
self.entries = None;
|
||||||
|
self.icons = HashMap::new();
|
||||||
|
return Task::none();
|
||||||
|
}
|
||||||
|
self.icons
|
||||||
|
.retain(|id, _| snapshot.windows.iter().any(|window| &window.app_id == id));
|
||||||
|
if self.icons_loading {
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
let app_ids: Vec<_> = snapshot
|
let app_ids: Vec<_> = snapshot
|
||||||
@@ -517,6 +524,28 @@ mod tests {
|
|||||||
assert!(ui.icons.is_empty());
|
assert!(ui.icons.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn workspace_icon_storage_follows_running_apps_and_selected_style() {
|
||||||
|
let mut ui = WorkspaceUi::default();
|
||||||
|
let mut snapshot = snapshot(1);
|
||||||
|
add_window(&mut snapshot, "running");
|
||||||
|
ui.entries = Some(Arc::new(Vec::new()));
|
||||||
|
for id in ["running", "closed"] {
|
||||||
|
ui.icons
|
||||||
|
.insert(id.into(), icon::from_svg_bytes(ferese_theme::icons::APPLICATION));
|
||||||
|
}
|
||||||
|
assert_eq!(ui.load_icons(&snapshot, true).units(), 0);
|
||||||
|
assert!(ui.icons.contains_key("running"));
|
||||||
|
assert!(!ui.icons.contains_key("closed"));
|
||||||
|
assert!(ui.entries.is_some());
|
||||||
|
ui.icons_loading = true;
|
||||||
|
assert_eq!(ui.load_icons(&snapshot, false).units(), 0);
|
||||||
|
assert!(ui.icons.is_empty());
|
||||||
|
assert_eq!(ui.icons.capacity(), 0);
|
||||||
|
assert!(ui.entries.is_none());
|
||||||
|
assert!(ui.icons_loading, "an in-flight worker still owns its discovery request");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn icon_publication_preserves_existing_icons_and_queues_new_windows() {
|
fn icon_publication_preserves_existing_icons_and_queues_new_windows() {
|
||||||
let mut shell = crate::tests::shell_with_measured_panel();
|
let mut shell = crate::tests::shell_with_measured_panel();
|
||||||
|
|||||||
Reference in new issue
Block a user