Skip to content

Commit

Permalink
chore: more plumbing
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Brue <[email protected]>
  • Loading branch information
ryanabx committed Aug 14, 2024
1 parent 07b3a70 commit def138f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/app_tray/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::collections::HashMap;

use cctk::toplevel_info::ToplevelInfo;
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;
use desktop_entry::DesktopEntryCache;
use freedesktop_desktop_entry::DesktopEntry;

use crate::compositor::{WindowHandle, WindowInfo};

pub mod desktop_entry;

Expand All @@ -18,14 +17,14 @@ impl<'a> Default for AppTray<'a> {
fn default() -> Self {
Self {
de_cache: DesktopEntryCache::new(),
active_toplevels: HashMap::new()
active_toplevels: HashMap::new(),
}
}
}

#[derive(Clone, Debug)]
pub struct ApplicationGroup {
pub toplevels: HashMap<ZcosmicToplevelHandleV1, ToplevelInfo>,
pub toplevels: HashMap<WindowHandle, WindowInfo>,
}

impl<'a> AppTray<'a> {
Expand Down
26 changes: 17 additions & 9 deletions src/compositor/cosmic_comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use iced::{
};
use once_cell::sync::Lazy;

use crate::compositor::{WindowHandle, WindowInfo};

struct WaylandData {
_conn: Connection,
Expand Down Expand Up @@ -462,7 +463,6 @@ pub enum State {
Finished,
}


pub static WAYLAND_RX: Lazy<Mutex<Option<UnboundedReceiver<CosmicWaylandMessage>>>> =
Lazy::new(|| Mutex::new(None));

Expand Down Expand Up @@ -508,7 +508,7 @@ pub struct CosmicCompBackend {
impl CosmicCompBackend {
pub fn new() -> Self {
Self {
wayland_sender: None
wayland_sender: None,
}
}

Expand Down Expand Up @@ -550,12 +550,15 @@ impl CosmicCompBackend {
.get_mut(&info.app_id)
.unwrap()
.toplevels
.insert(handle, info);
.insert(WindowHandle::Cosmic(handle), WindowInfo::Cosmic(info));
} else {
app_tray.active_toplevels.insert(
app_id.clone(),
crate::app_tray::ApplicationGroup {
toplevels: HashMap::from([(handle, info.clone())]),
toplevels: HashMap::from([(
WindowHandle::Cosmic(handle),
WindowInfo::Cosmic(info.clone()),
)]),
},
);
}
Expand All @@ -576,9 +579,11 @@ impl CosmicCompBackend {
.unwrap()
.toplevels
{
if &handle == t_handle {
*t_info = info;
break;
if let WindowHandle::Cosmic(c_handle) = t_handle {
if &handle == c_handle {
*t_info = WindowInfo::Cosmic(info);
break;
}
}
}

Expand All @@ -587,9 +592,12 @@ impl CosmicCompBackend {
ToplevelUpdate::Remove(handle) => {
let mut target_app_id: Option<String> = None;
for (app_id, app_info) in app_tray.active_toplevels.iter_mut() {
if app_info.toplevels.contains_key(&handle) {
if app_info
.toplevels
.contains_key(&WindowHandle::Cosmic(handle.clone()))
{
println!("Removing toplevel with app_id {} from list!", &app_id);
app_info.toplevels.remove(&handle);
app_info.toplevels.remove(&WindowHandle::Cosmic(handle));
if app_info.toplevels.is_empty() {
target_app_id = Some(app_id.clone());
}
Expand Down
21 changes: 19 additions & 2 deletions src/compositor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;

use cctk::toplevel_info::ToplevelInfo;
use cosmic_comp::CosmicCompBackend;
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;

Expand All @@ -11,6 +12,8 @@ pub mod wlr;
#[derive(Clone, Debug)]
pub enum CompositorBackend {
Cosmic(CosmicCompBackend),
#[allow(dead_code)]
NotSupported,
}

impl CompositorBackend {
Expand All @@ -30,6 +33,7 @@ impl CompositorBackend {
pub fn wayland_subscription(&self) -> iced::Subscription<WaylandEvent> {
match self {
Self::Cosmic(backend) => backend.wayland_subscription().map(WaylandEvent::Cosmic),
Self::NotSupported => unreachable!(),
}
}

Expand All @@ -42,16 +46,29 @@ impl CompositorBackend {
(Self::Cosmic(backend), WaylandEvent::Cosmic(evt)) => {
backend.handle_message(app_tray, evt)
}
(Self::NotSupported, _) => unreachable!(),
(_, WaylandEvent::NotSupported) => unreachable!(),
}
}
}

#[derive(Clone, Debug)]
pub enum WaylandEvent {
Cosmic(cosmic_comp::CosmicWaylandMessage),
#[allow(dead_code)]
NotSupported,
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum WindowHandle {
Cosmic(ZcosmicToplevelHandleV1),
}
#[allow(dead_code)]
NotSupported,
}

#[derive(Clone, Debug)]
pub enum WindowInfo {
Cosmic(ToplevelInfo),
#[allow(dead_code)]
NotSupported,
}

0 comments on commit def138f

Please sign in to comment.