feat: Set focused window as selected

This commit is contained in:
Ryan Brue 2024-04-02 13:05:13 -05:00 committed by Michael Murphy
parent 769af3d944
commit 7592a3144f
2 changed files with 39 additions and 18 deletions

View file

@ -147,6 +147,7 @@ impl DockItem {
rectangle_tracker: Option<&RectangleTracker<u32>>,
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<Message> {
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()

View file

@ -58,14 +58,14 @@ struct AppData {
tx: UnboundedSender<WaylandUpdate>,
conn: Connection,
queue_handle: QueueHandle<Self>,
registry_state: RegistryState,
activation_state: Option<ActivationState>,
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<ActivationState>,
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(&registry_state, &qh); // Create before toplevel info state
let mut app_data = AppData {
exit: false,
tx,
conn,
queue_handle: qh.clone(),
activation_state: ActivationState::bind::<AppData>(&globals, &qh).ok(),
seat_state: SeatState::new(&globals, &qh),
workspace_state,
toplevel_info_state: ToplevelInfoState::new(&registry_state, &qh),
toplevel_manager_state: ToplevelManagerState::new(&registry_state, &qh),
output_state: OutputState::new(&globals, &qh),
workspace_state: WorkspaceState::new(&registry_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::<AppData>(&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);