minimize applet (#217)
* chore: add minimize applet skeleton * fix(minimize): desktop typo * wip: minimize applet * feat: include window images, and overlay their icon * cleanup * fix: add minimize applet to workspace * chore: add host wayland display to desktop file for minimize applet * chore: Cargo.lock * cleanup: fix typos * fix: don't hide minimized apps in app-list
This commit is contained in:
parent
06634c3348
commit
090bb9653f
16 changed files with 1301 additions and 4 deletions
121
cosmic-applet-minimize/src/wayland_subscription.rs
Normal file
121
cosmic-applet-minimize/src/wayland_subscription.rs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
//! # DBus interface proxy for: `org.freedesktop.UPower.KbdBacklight`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/UPower/KbdBacklight' from service 'org.freedesktop.UPower' on system bus`.
|
||||
use cctk::sctk::reexports::calloop;
|
||||
use cctk::toplevel_info::ToplevelInfo;
|
||||
use cosmic::cctk::cosmic_protocols;
|
||||
use cosmic::iced::subscription;
|
||||
use cosmic::iced_futures::futures;
|
||||
use cosmic::{cctk, iced};
|
||||
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;
|
||||
use futures::{
|
||||
channel::mpsc::{unbounded, UnboundedReceiver},
|
||||
SinkExt, StreamExt,
|
||||
};
|
||||
use image::EncodableLayout;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::wayland_handler::wayland_handler;
|
||||
|
||||
pub static WAYLAND_RX: Lazy<Mutex<Option<UnboundedReceiver<WaylandUpdate>>>> =
|
||||
Lazy::new(|| Mutex::new(None));
|
||||
|
||||
pub fn wayland_subscription() -> iced::Subscription<WaylandUpdate> {
|
||||
subscription::channel(
|
||||
std::any::TypeId::of::<WaylandUpdate>(),
|
||||
50,
|
||||
move |mut output| async move {
|
||||
let mut state = State::Waiting;
|
||||
|
||||
loop {
|
||||
state = start_listening(state, &mut output).await;
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub enum State {
|
||||
Waiting,
|
||||
Finished,
|
||||
}
|
||||
|
||||
async fn start_listening(
|
||||
state: State,
|
||||
output: &mut futures::channel::mpsc::Sender<WaylandUpdate>,
|
||||
) -> State {
|
||||
match state {
|
||||
State::Waiting => {
|
||||
let mut guard = WAYLAND_RX.lock().await;
|
||||
let rx = {
|
||||
if guard.is_none() {
|
||||
let (calloop_tx, calloop_rx) = calloop::channel::channel();
|
||||
let (toplevel_tx, toplevel_rx) = unbounded();
|
||||
let _ = std::thread::spawn(move || {
|
||||
wayland_handler(toplevel_tx, calloop_rx);
|
||||
});
|
||||
*guard = Some(toplevel_rx);
|
||||
_ = output.send(WaylandUpdate::Init(calloop_tx)).await;
|
||||
}
|
||||
guard.as_mut().unwrap()
|
||||
};
|
||||
match rx.next().await {
|
||||
Some(u) => {
|
||||
_ = output.send(u).await;
|
||||
State::Waiting
|
||||
}
|
||||
None => {
|
||||
_ = output.send(WaylandUpdate::Finished).await;
|
||||
tracing::error!("Wayland handler thread died");
|
||||
State::Finished
|
||||
}
|
||||
}
|
||||
}
|
||||
State::Finished => iced::futures::future::pending().await,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum WaylandUpdate {
|
||||
Init(calloop::channel::Sender<WaylandRequest>),
|
||||
Finished,
|
||||
Toplevel(ToplevelUpdate),
|
||||
Image(ZcosmicToplevelHandleV1, WaylandImage),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WaylandImage {
|
||||
pub img: Arc<image::RgbaImage>,
|
||||
}
|
||||
|
||||
impl WaylandImage {
|
||||
pub fn new(img: image::RgbaImage) -> Self {
|
||||
Self { img: Arc::new(img) }
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8]> for WaylandImage {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
self.img.as_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ToplevelUpdate {
|
||||
Add(ZcosmicToplevelHandleV1, ToplevelInfo),
|
||||
Update(ZcosmicToplevelHandleV1, ToplevelInfo),
|
||||
Remove(ZcosmicToplevelHandleV1),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum WaylandRequest {
|
||||
Toplevel(ToplevelRequest),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ToplevelRequest {
|
||||
Activate(ZcosmicToplevelHandleV1),
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue