From 7592a3144fb01f90803795db117ed3906065f3bb Mon Sep 17 00:00:00 2001 From: Ryan Brue Date: Tue, 2 Apr 2024 13:05:13 -0500 Subject: [PATCH] feat: Set focused window as selected --- cosmic-app-list/src/app.rs | 28 ++++++++++++++++++++++--- cosmic-app-list/src/wayland_handler.rs | 29 +++++++++++++------------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/cosmic-app-list/src/app.rs b/cosmic-app-list/src/app.rs index a4414f73..f9a19aeb 100755 --- a/cosmic-app-list/src/app.rs +++ b/cosmic-app-list/src/app.rs @@ -147,6 +147,7 @@ impl DockItem { rectangle_tracker: Option<&RectangleTracker>, interaction_enabled: bool, gpus: Option<&[Gpu]>, + is_focused: bool, ) -> Element<'_, Message> { let Self { toplevels, @@ -250,7 +251,8 @@ impl DockItem { PanelAnchor::Bottom => cosmic::widget::button(icon_wrapper) .style(Button::Text) .padding([0, 5]), - }; + } + .selected(is_focused); let icon_button = if interaction_enabled { dnd_source( @@ -433,12 +435,12 @@ pub fn toplevel_button<'a, Msg>( on_press: Msg, title: String, text_size: f32, + is_focused: bool, ) -> cosmic::widget::Button<'a, Msg, cosmic::Theme, cosmic::Renderer> where Msg: 'static + Clone, { let border = 1.0; - let is_focused = false; // We could optionally make this dependent on currently focused toplevel cosmic::widget::Button::new( container( column![ @@ -541,6 +543,7 @@ where }) .width(Length::Fixed(TOPLEVEL_BUTTON_WIDTH)) .height(Length::Fixed(TOPLEVEL_BUTTON_HEIGHT)) + .selected(is_focused) } pub fn menu_control_padding() -> Padding { @@ -1180,6 +1183,7 @@ impl cosmic::Application for CosmicAppList { } fn view(&self) -> Element { + let focused_item = self.currently_active_toplevel(); let is_horizontal = match self.core.applet.anchor { PanelAnchor::Top | PanelAnchor::Bottom => true, PanelAnchor::Left | PanelAnchor::Right => false, @@ -1193,6 +1197,9 @@ impl cosmic::Application for CosmicAppList { self.rectangle_tracker.as_ref(), self.popup.is_none(), self.gpus.as_deref(), + focused_item + .as_ref() + .is_some_and(|x| dock_item.toplevels.iter().any(|y| *x == y.0)), ) }) .collect(); @@ -1204,7 +1211,15 @@ impl cosmic::Application for CosmicAppList { { favorites.insert( index, - item.as_icon(&self.core.applet, None, false, self.gpus.as_deref()), + item.as_icon( + &self.core.applet, + None, + false, + self.gpus.as_deref(), + focused_item + .as_ref() + .is_some_and(|x| item.toplevels.iter().any(|y| *x == y.0)), + ), ); } else if self.is_listening_for_dnd && self.favorite_list.is_empty() { // show star indicating favorite_list is drag target @@ -1227,6 +1242,9 @@ impl cosmic::Application for CosmicAppList { self.rectangle_tracker.as_ref(), self.popup.is_none(), self.gpus.as_deref(), + focused_item + .as_ref() + .is_some_and(|x| dock_item.toplevels.iter().any(|y| *x == y.0)), ) }) .collect(); @@ -1461,6 +1479,8 @@ impl cosmic::Application for CosmicAppList { Message::Toggle(handle.clone()), title, 10.0, + self.currently_active_toplevel() + .is_some_and(|x| x == handle.clone()), )); } self.core.applet.popup_container(content).into() @@ -1480,6 +1500,8 @@ impl cosmic::Application for CosmicAppList { Message::Toggle(handle.clone()), title, 10.0, + self.currently_active_toplevel() + .is_some_and(|x| x == handle.clone()), )); } self.core.applet.popup_container(content).into() diff --git a/cosmic-app-list/src/wayland_handler.rs b/cosmic-app-list/src/wayland_handler.rs index 5c0567fb..46646b73 100644 --- a/cosmic-app-list/src/wayland_handler.rs +++ b/cosmic-app-list/src/wayland_handler.rs @@ -58,14 +58,14 @@ struct AppData { tx: UnboundedSender, conn: Connection, queue_handle: QueueHandle, - registry_state: RegistryState, - activation_state: Option, + workspace_state: WorkspaceState, toplevel_info_state: ToplevelInfoState, toplevel_manager_state: ToplevelManagerState, - seat_state: SeatState, - workspace_state: WorkspaceState, - shm_state: Shm, screencopy_state: ScreencopyState, + registry_state: RegistryState, + seat_state: SeatState, + shm_state: Shm, + activation_state: Option, output_state: OutputState, } @@ -670,23 +670,22 @@ pub(crate) fn wayland_handler( return; } let registry_state = RegistryState::new(&globals); - let screencopy_state = ScreencopyState::new(&globals, &qh); - let shm_state = Shm::bind(&globals, &qh).expect("Failed to get shm state"); + let workspace_state = WorkspaceState::new(®istry_state, &qh); // Create before toplevel info state let mut app_data = AppData { exit: false, tx, conn, queue_handle: qh.clone(), - activation_state: ActivationState::bind::(&globals, &qh).ok(), - seat_state: SeatState::new(&globals, &qh), + workspace_state, toplevel_info_state: ToplevelInfoState::new(®istry_state, &qh), toplevel_manager_state: ToplevelManagerState::new(®istry_state, &qh), - output_state: OutputState::new(&globals, &qh), - workspace_state: WorkspaceState::new(®istry_state, &qh), - shm_state, - screencopy_state, + screencopy_state: ScreencopyState::new(&globals, &qh), registry_state, + seat_state: SeatState::new(&globals, &qh), + shm_state: Shm::bind(&globals, &qh).unwrap(), + activation_state: ActivationState::bind::(&globals, &qh).ok(), + output_state: OutputState::new(&globals, &qh), }; loop { @@ -697,14 +696,14 @@ pub(crate) fn wayland_handler( } } -sctk::delegate_shm!(AppData); sctk::delegate_seat!(AppData); sctk::delegate_registry!(AppData); +sctk::delegate_shm!(AppData); cctk::delegate_toplevel_info!(AppData); +cctk::delegate_workspace!(AppData); cctk::delegate_toplevel_manager!(AppData); cctk::delegate_screencopy!(AppData, session: [SessionData], frame: [FrameData]); sctk::delegate_activation!(AppData, ExecRequestData); sctk::delegate_output!(AppData); -cctk::delegate_workspace!(AppData);