Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 14 additions & 36 deletions cosmic-app-list/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ use cosmic::{
platform_specific::shell::commands::popup::{destroy_popup, get_popup},
runtime::{core::event, dnd::peek_dnd, platform_specific::wayland::CornerRadius},
widget::{
Column, Row, column, mouse_area, row,
Column, Row, column, hover, mouse_area, row,
rule::vertical as vertical_rule,
space::{horizontal as horizontal_space, vertical as vertical_space},
stack,
},
window,
},
Expand Down Expand Up @@ -376,7 +375,6 @@ struct CosmicAppList {
active_workspaces: Vec<ExtWorkspaceHandleV1>,
output_list: FxHashMap<WlOutput, OutputInfo>,
locales: Vec<String>,
hovered_toplevel: Option<ExtForeignToplevelHandleV1>,
overflow_favorites_popup: Option<window::Id>,
overflow_active_popup: Option<window::Id>,
}
Expand All @@ -395,7 +393,6 @@ enum Message {
Popup(u32, window::Id),
Pressed(window::Id),
ToplevelListPopup(u32, window::Id),
ToplevelHoverChanged(ExtForeignToplevelHandleV1, bool),
GpuRequest(Option<Vec<Gpu>>),
CloseRequested(window::Id),
ClosePopup,
Expand Down Expand Up @@ -487,7 +484,6 @@ fn toplevel_button<'a>(
title: String,
handle: ExtForeignToplevelHandleV1,
is_focused: bool,
is_hovered: bool,
) -> Element<'a, Message> {
let border = 1.0;
let preview = column![
Expand Down Expand Up @@ -518,32 +514,29 @@ fn toplevel_button<'a>(
]
.spacing(4)
.padding([4, 4, 0, 4]);
let close_button_overlay = if is_hovered {
row![
horizontal_space(),
button::custom(icon::from_name("window-close-symbolic").size(16))
.class(Button::Destructive)
.on_press(Message::CloseToplevel(handle.clone()))
.padding(4)
]
} else {
row![]
}
let close_button_overlay = row![
horizontal_space(),
button::custom(icon::from_name("window-close-symbolic").size(16))
.class(Button::Destructive)
.on_press(Message::CloseToplevel(handle.clone()))
.padding(4)
]
.padding(4)
.width(Length::Fill)
.height(Length::Fill);

stack![preview, close_button_overlay]
let thumbnail = preview
.apply(button::custom)
.on_press(Message::Toggle(handle.clone()))
.class(window_menu_style(is_focused))
.width(Length::Fixed(TOPLEVEL_BUTTON_WIDTH))
.height(Length::Fixed(TOPLEVEL_BUTTON_HEIGHT))
.padding(4)
.selected(is_focused)
.selected(is_focused);

hover(thumbnail, close_button_overlay)
.apply(mouse_area)
.on_enter(Message::ToplevelHoverChanged(handle.clone(), true))
.on_middle_press(Message::CloseToplevel(handle.clone()))
.on_exit(Message::ToplevelHoverChanged(handle, false))
.on_middle_press(Message::CloseToplevel(handle))
.apply(Element::from)
}

Expand Down Expand Up @@ -840,11 +833,6 @@ impl CosmicAppList {
fn is_focused(&self, handle: &ExtForeignToplevelHandleV1) -> bool {
self.currently_active_toplevel().contains(handle)
}

// Check if a specific toplevel button is currently hovered
fn is_hovered(&self, handle: &ExtForeignToplevelHandleV1) -> bool {
self.hovered_toplevel.as_ref() == Some(handle)
}
}

impl cosmic::Application for CosmicAppList {
Expand Down Expand Up @@ -1050,14 +1038,6 @@ impl cosmic::Application for CosmicAppList {
return popup_task;
}
}
Message::ToplevelHoverChanged(handle, entering) => {
match (entering, &self.hovered_toplevel) {
(true, _) => self.hovered_toplevel = Some(handle),
// prevents race condition
(false, Some(h)) if h == &handle => self.hovered_toplevel = None,
_ => {}
}
}
Message::PinApp(id) => {
if let Some(i) = self.active_list.iter().position(|t| t.id == id) {
let entry = self.active_list.remove(i);
Expand Down Expand Up @@ -2263,7 +2243,6 @@ impl cosmic::Application for CosmicAppList {
info.title.clone(),
info.foreign_toplevel.clone(),
self.is_focused(&info.foreign_toplevel),
self.is_hovered(&info.foreign_toplevel),
));
}
self.core
Expand All @@ -2280,7 +2259,6 @@ impl cosmic::Application for CosmicAppList {
info.title.clone(),
info.foreign_toplevel.clone(),
self.is_focused(&info.foreign_toplevel),
self.is_hovered(&info.foreign_toplevel),
));
}
self.core
Expand Down