suport long lived plugin, and sort top level manually

This commit is contained in:
wiiznokes 2024-07-03 03:42:39 +02:00 committed by Ashley Wulber
parent fca3b25552
commit 593e397b03
12 changed files with 123 additions and 21 deletions

View file

@ -1,10 +1,12 @@
mod toplevel_handler;
use cctk::cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::State;
use cctk::wayland_client::Proxy;
use cctk::{cosmic_protocols, sctk::reexports::calloop, toplevel_info::ToplevelInfo};
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;
use fde::DesktopEntry;
use freedesktop_desktop_entry as fde;
use tracing::{debug, info};
use crate::desktop_entries::utils::get_description;
use crate::send;
@ -19,12 +21,13 @@ use pop_launcher::{
};
use std::borrow::Cow;
use std::iter;
use std::collections::VecDeque;
use tokio::io::{AsyncWrite, AsyncWriteExt};
use self::toplevel_handler::{toplevel_handler, ToplevelAction, ToplevelEvent};
pub async fn main() {
tracing::info!("starting cosmic-toplevel");
info!("starting cosmic-toplevel");
let mut tx = async_stdout();
@ -68,20 +71,37 @@ pub async fn main() {
Either::Right((Some(event), second_to_next_request)) => {
next_event = toplevel_rx.next();
next_request = second_to_next_request;
match event {
ToplevelEvent::Add(handle, info) => {
tracing::info!("{}", &info.app_id);
tracing::info!("add {}", &info.app_id);
app.toplevels.retain(|t| t.0 != handle);
app.toplevels.push((handle, info));
app.toplevels.push_front((handle, info));
}
ToplevelEvent::Remove(handle) => {
app.toplevels.retain(|t| t.0 != handle);
// ignore requests for this id until after the next search
app.ids_to_ignore.push(handle.id().protocol_id());
if let Some(pos) = app.toplevels.iter().position(|t| t.0 == handle) {
app.toplevels.remove(pos);
// ignore requests for this id until after the next search
app.ids_to_ignore.push(handle.id().protocol_id());
} else {
tracing::warn!("ToplevelEvent::Remove, no toplevel found");
}
}
ToplevelEvent::Update(handle, info) => {
if let Some(t) = app.toplevels.iter_mut().find(|t| t.0 == handle) {
t.1 = info;
debug!("Update {}", &info.app_id);
debug!("Update {:?}", &info.state);
if let Some(pos) = app.toplevels.iter().position(|t| t.0 == handle) {
if info.state.contains(&State::Activated) {
tracing::warn!("Update {:?}: push front", &info.app_id);
app.toplevels.remove(pos);
app.toplevels.push_front((handle, info));
} else {
app.toplevels[pos].1 = info;
}
} else {
tracing::warn!("ToplevelEvent::Update, no toplevel found");
app.toplevels.push_front((handle, info));
}
}
}
@ -95,7 +115,8 @@ struct App<W> {
locales: Vec<String>,
desktop_entries: Vec<DesktopEntry<'static>>,
ids_to_ignore: Vec<u32>,
toplevels: Vec<(ZcosmicToplevelHandleV1, ToplevelInfo)>,
// XXX: use LinkedList?
toplevels: VecDeque<(ZcosmicToplevelHandleV1, ToplevelInfo)>,
calloop_tx: calloop::channel::Sender<ToplevelAction>,
tx: W,
}
@ -119,7 +140,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
locales,
desktop_entries,
ids_to_ignore: Vec::new(),
toplevels: Vec::new(),
toplevels: VecDeque::new(),
calloop_tx,
tx,
},

View file

@ -4,4 +4,5 @@
query: (persistent: true, priority: High),
bin: (path: "cosmic-toplevel"),
icon: Name("focus-windows-symbolic"),
long_lived: true,
)

View file

@ -9,11 +9,13 @@ use futures::StreamExt;
use pop_launcher::*;
use std::borrow::Cow;
use tokio::io::AsyncWrite;
use tracing::info;
use utils::get_description;
pub(crate) mod utils;
pub async fn main() {
info!("starting desktop entries");
let mut app = App::new(async_stdout());
app.reload().await;