refactor: recreate rectangles for all active workspaces on toplevel update and workspaces list changes
This commit is contained in:
parent
20ac821954
commit
01b5836a97
1 changed files with 45 additions and 66 deletions
111
src/main.rs
111
src/main.rs
|
|
@ -499,7 +499,6 @@ impl App {
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
strips.append(&mut rects);
|
strips.append(&mut rects);
|
||||||
|
|
||||||
return Some(
|
return Some(
|
||||||
|
|
@ -539,57 +538,19 @@ impl Application for App {
|
||||||
Msg::Rectangle(u) => match u {
|
Msg::Rectangle(u) => match u {
|
||||||
RectangleUpdate::Rectangle(r) => {
|
RectangleUpdate::Rectangle(r) => {
|
||||||
self.rects.insert(r.0.clone(), r.1);
|
self.rects.insert(r.0.clone(), r.1);
|
||||||
let active = cosmic::theme::active();
|
if self.visible {
|
||||||
let rad = active
|
let to_update: Vec<_> = self
|
||||||
.cosmic()
|
.workspaces
|
||||||
.radius_s()
|
.0
|
||||||
.map(|x| if x < 4.0 { x } else { x + 8.0 });
|
.iter()
|
||||||
let mut rects = Vec::new();
|
.filter_map(|w| w.is_active().then(|| w.handle().id()))
|
||||||
let mut strips: Vec<Rectangle> = self
|
.collect();
|
||||||
.rects
|
return Task::batch(
|
||||||
.iter()
|
to_update
|
||||||
.filter_map(|(id, rect)| {
|
.into_iter()
|
||||||
if self.drag_surface.as_ref().is_some_and(|(s, _)| match s {
|
.filter_map(|w| self.update_active_workspace(w)),
|
||||||
DragSurface::Workspace(_) => false,
|
);
|
||||||
DragSurface::Toplevel(ext_foreign_toplevel_handle_v1) => id
|
}
|
||||||
.toplevel_id
|
|
||||||
.as_ref()
|
|
||||||
.is_some_and(|t| *t == ext_foreign_toplevel_handle_v1.id()),
|
|
||||||
}) || r.0.id != id.id
|
|
||||||
|| r.0
|
|
||||||
.workspaces_id
|
|
||||||
.as_ref()
|
|
||||||
.zip(id.workspaces_id.as_ref())
|
|
||||||
.is_some_and(|(a, b)| !a.iter().any(|r_id| b.contains(r_id)))
|
|
||||||
{
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let rad = if id.toplevel_id.is_none() {
|
|
||||||
CornerRadius {
|
|
||||||
top_left: rad[0] as u32,
|
|
||||||
top_right: rad[1] as u32,
|
|
||||||
bottom_left: rad[3] as u32,
|
|
||||||
bottom_right: rad[2] as u32,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rects.push(*rect);
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
Some(cosmic::surface::corner_radius::rounded_rect_strips(
|
|
||||||
*rect, rad,
|
|
||||||
))
|
|
||||||
})
|
|
||||||
.flatten()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
strips.append(&mut rects);
|
|
||||||
|
|
||||||
return cosmic::iced::platform_specific::shell::commands::blur::blur(
|
|
||||||
r.0.id,
|
|
||||||
Some(strips),
|
|
||||||
)
|
|
||||||
.discard();
|
|
||||||
}
|
}
|
||||||
RectangleUpdate::Init(tracker) => {
|
RectangleUpdate::Init(tracker) => {
|
||||||
self.rectangle_tracker = Some(tracker);
|
self.rectangle_tracker = Some(tracker);
|
||||||
|
|
@ -665,11 +626,6 @@ impl Application for App {
|
||||||
backend::Event::Workspaces(mut workspaces) => {
|
backend::Event::Workspaces(mut workspaces) => {
|
||||||
workspaces.sort_by(|(_, w1), (_, w2)| w1.coordinates.cmp(&w2.coordinates));
|
workspaces.sort_by(|(_, w1), (_, w2)| w1.coordinates.cmp(&w2.coordinates));
|
||||||
let old_workspaces = mem::take(&mut self.workspaces);
|
let old_workspaces = mem::take(&mut self.workspaces);
|
||||||
let old_active: HashSet<_> = old_workspaces
|
|
||||||
.0
|
|
||||||
.iter()
|
|
||||||
.filter_map(|w| w.is_active().then(|| w.handle().clone()))
|
|
||||||
.collect();
|
|
||||||
let mut new_active = Vec::new();
|
let mut new_active = Vec::new();
|
||||||
for (outputs, workspace) in workspaces {
|
for (outputs, workspace) in workspaces {
|
||||||
// XXX efficiency
|
// XXX efficiency
|
||||||
|
|
@ -692,14 +648,12 @@ impl Application for App {
|
||||||
self.workspaces.0.push(w);
|
self.workspaces.0.push(w);
|
||||||
}
|
}
|
||||||
self.update_capture_filter();
|
self.update_capture_filter();
|
||||||
return Task::batch(new_active.into_iter().map(|new| {
|
if self.visible {
|
||||||
if old_active.contains(&new) {
|
return Task::batch(new_active.into_iter().map(|new| {
|
||||||
Task::none()
|
|
||||||
} else {
|
|
||||||
self.update_active_workspace(new.id())
|
self.update_active_workspace(new.id())
|
||||||
.unwrap_or(Task::none())
|
.unwrap_or(Task::none())
|
||||||
}
|
}));
|
||||||
}));
|
}
|
||||||
}
|
}
|
||||||
backend::Event::NewToplevel(handle, info) => {
|
backend::Event::NewToplevel(handle, info) => {
|
||||||
log::debug!("New toplevel: {info:?}");
|
log::debug!("New toplevel: {info:?}");
|
||||||
|
|
@ -743,7 +697,7 @@ impl Application for App {
|
||||||
tasks.push(task);
|
tasks.push(task);
|
||||||
}
|
}
|
||||||
if let Some((t, w)) = t_w {
|
if let Some((t, w)) = t_w {
|
||||||
tasks.push(Task::batch(w.iter().map(|w| {
|
for w in w {
|
||||||
self.rects.retain(|id, _| {
|
self.rects.retain(|id, _| {
|
||||||
!(id.toplevel_id.as_ref().is_some_and(|old| *old == t)
|
!(id.toplevel_id.as_ref().is_some_and(|old| *old == t)
|
||||||
&& id
|
&& id
|
||||||
|
|
@ -751,8 +705,20 @@ impl Application for App {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_some_and(|old| !old.contains(&w.id())))
|
.is_some_and(|old| !old.contains(&w.id())))
|
||||||
});
|
});
|
||||||
self.update_active_workspace(w.id()).unwrap_or(Task::none())
|
}
|
||||||
})));
|
}
|
||||||
|
if self.visible {
|
||||||
|
let to_update: Vec<_> = self
|
||||||
|
.workspaces
|
||||||
|
.0
|
||||||
|
.iter()
|
||||||
|
.filter_map(|w| w.is_active().then(|| w.handle().id()))
|
||||||
|
.collect();
|
||||||
|
tasks.push(Task::batch(
|
||||||
|
to_update
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|w| self.update_active_workspace(w)),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task::batch(tasks);
|
return Task::batch(tasks);
|
||||||
|
|
@ -818,6 +784,19 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
if self.visible {
|
||||||
|
let to_update: Vec<_> = self
|
||||||
|
.workspaces
|
||||||
|
.0
|
||||||
|
.iter()
|
||||||
|
.filter_map(|w| w.is_active().then(|| w.handle().id()))
|
||||||
|
.collect();
|
||||||
|
return Task::batch(
|
||||||
|
to_update
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|w| self.update_active_workspace(w)),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Msg::CloseToplevel(toplevel_handle) => {
|
Msg::CloseToplevel(toplevel_handle) => {
|
||||||
// TODO confirmation?
|
// TODO confirmation?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue