Skip to content

Commit

Permalink
feat: can toggle activation now
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Brue <ryanbrue@gmail.com>
  • Loading branch information
ryanabx committed Aug 15, 2024
1 parent b88b42f commit 015f296
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
26 changes: 15 additions & 11 deletions src/app_tray/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ pub fn get_tray_widget<'a>(
app_info: ApplicationGroup,
active_window: Option<WindowHandle>,
) -> iced::widget::Button<'a, crate::Message> {
// println!("app_id: {}", app_id);
// if app_id == "Google-chrome" || app_id == "com.google.chrome" {
// println!("ODIUAOIDUWIO");
// }
let icon_path = desktop_entry
.and_then(|entry| entry.icon())
.and_then(|icon| freedesktop_icons::lookup(icon).with_cache().find())
Expand Down Expand Up @@ -80,13 +76,21 @@ pub fn get_tray_widget<'a>(
}
.width(Length::Fill)
.height(Length::Fill)
.padding(8)
.padding(4)
.on_press_maybe(if app_info.toplevels.is_empty() {
desktop_entry.and_then(|entry| entry.exec()).map(|exec| {
Message::WaylandOut(WaylandOutgoing::Exec(app_id.to_string(), exec.to_string()))
})
} else if app_info.toplevels.len() == 1 {
Some(Message::WaylandOut(WaylandOutgoing::Toggle(
app_info.toplevels.keys().next().unwrap().clone(),
)))
} else {
todo!("Not yet impl")
})
.style(move |theme, status| {
tray_button_style(theme, status, &app_info, &active_window.as_ref())
})
.on_press_maybe(desktop_entry.and_then(|entry| entry.exec()).map(|exec| {
Message::WaylandOut(WaylandOutgoing::Exec(app_id.to_string(), exec.to_string()))
}))
// .on_press_maybe(if toplevels.is_empty() {
// launch_on_preferred_gpu(desktop_info, gpus)
// } else if toplevels.len() == 1 {
Expand All @@ -102,7 +106,7 @@ fn get_horizontal_rule<'a>(
) -> Container<'a, Message> {
if app_info.toplevels.is_empty() {
iced::widget::container(iced::widget::Space::new(
Length::Fixed(8.0),
Length::Fixed(6.0),
Length::Fixed(2.0),
))
} else {
Expand All @@ -116,9 +120,9 @@ fn get_horizontal_rule<'a>(
})
.width(Length::Fixed(
if active_window.is_some_and(|w| app_info.toplevels.contains_key(w)) {
16.0
12.0
} else {
8.0
6.0
},
)),
)
Expand Down
43 changes: 41 additions & 2 deletions src/compositor/cosmic_comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,12 @@ impl CosmicCompBackend {

pub fn handle_outgoing(
&mut self,
_app_tray: &mut crate::app_tray::AppTray,
app_tray: &mut crate::app_tray::AppTray,
outgoing: WaylandOutgoing,
) -> Option<iced::Command<crate::Message>> {
match outgoing {
WaylandOutgoing::Exec(app_id, exec) => {
println!("{:?}", _app_tray.active_toplevels.keys());
println!("{:?}", app_tray.active_toplevels.keys());
if let Some(tx) = self.wayland_sender.as_ref() {
println!("Sending exec request! {}, {}", &app_id, &exec);
let _ = tx.send(WaylandRequest::TokenRequest {
Expand All @@ -656,6 +656,45 @@ impl CosmicCompBackend {
}
None
}
WaylandOutgoing::Toggle(window) => {
match window {
WindowHandle::Cosmic(toplevel) => {
if let Some(tx) = self.wayland_sender.as_ref() {
let _ = tx.send(WaylandRequest::Toplevel(
if self
.active_window(app_tray)
.is_some_and(|x| x == WindowHandle::Cosmic(toplevel.clone()))
{
ToplevelRequest::Minimize(toplevel)
} else {
ToplevelRequest::Activate(toplevel)
},
));
}
// if let Some(p) = self.popup.take() {
// return destroy_popup(p.id);
// }
None
}
_ => panic!(),
}
}
WaylandOutgoing::Activate(window) => {
match window {
WindowHandle::Cosmic(toplevel) => {
if let Some(tx) = self.wayland_sender.as_ref() {
let _ = tx.send(WaylandRequest::Toplevel(ToplevelRequest::Activate(
toplevel,
)));
}
// if let Some(p) = self.popup.take() {
// return destroy_popup(p.id);
// }
None
}
_ => panic!(),
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/compositor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub enum WaylandIncoming {
#[derive(Clone, Debug)]
pub enum WaylandOutgoing {
Exec(String, String),
Toggle(WindowHandle),
Activate(WindowHandle),
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a> Application for Panel<'a> {
// println!("{}, {:?}", &app_id, entry.map(|x| x.appid.clone()));
app_tray::get_tray_widget(&app_id, entry, group, active_window.map(|f| f.clone()))
})
.map(|x| Element::from(iced::widget::container(x).width(48).height(48).padding(2)));
.map(|x| Element::from(iced::widget::container(x).width(48).height(48).padding(6)));

let panel_items = iced::widget::row(app_tray_apps);
iced::widget::container(column![
Expand Down

0 comments on commit 015f296

Please sign in to comment.