|
1 | 1 | // SPDX-License-Identifier: GPL-3.0-only |
2 | 2 |
|
3 | | -use std::collections::HashMap; |
| 3 | +use std::{collections::HashMap, sync::{Arc, Condvar, Mutex}}; |
4 | 4 |
|
| 5 | +use ashpd::enumflags2::BitFlags; |
5 | 6 | use cosmic::{iced::window, widget}; |
6 | 7 | use futures::{FutureExt, TryFutureExt}; |
7 | 8 | use tokio::sync::mpsc::Sender; |
8 | 9 | use zbus::{fdo, object_server::SignalContext, zvariant}; |
9 | 10 |
|
10 | | -use crate::{app::CosmicPortal, fl, subscription, PortalResponse}; |
11 | | - |
12 | | -const POP_SHELL_DEST: &str = "com.System76.PopShell"; |
13 | | -const POP_SHELL_PATH: &str = "/com.System76.PopShell"; |
| 11 | +use crate::{app::CosmicPortal, fl, subscription, wayland::WaylandHelper, PortalResponse}; |
14 | 12 |
|
15 | 13 | /// Background portal backend |
16 | 14 | /// |
17 | 15 | /// https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.impl.portal.Background.html |
18 | 16 | pub struct Background { |
| 17 | + wayland_helper: WaylandHelper, |
19 | 18 | tx: Sender<subscription::Event>, |
20 | 19 | } |
21 | 20 |
|
22 | 21 | impl Background { |
23 | | - pub const fn new(tx: Sender<subscription::Event>) -> Self { |
24 | | - Self { tx } |
| 22 | + pub fn new(wayland_helper: WaylandHelper, tx: Sender<subscription::Event>) -> Self { |
| 23 | + let toplevel_signal = wayland_helper.toplevel_signal(); |
| 24 | + let toplevel_handle = std::thread::Builder::new() |
| 25 | + .name("background-toplevel-updates".into()) |
| 26 | + .spawn(move || Background::toplevel_signal(toplevel_signal)) |
| 27 | + .expect("Spawning toplevels update thread should succeed"); |
| 28 | + |
| 29 | + Self { |
| 30 | + wayland_helper, |
| 31 | + tx, |
| 32 | + toplevel_handle, |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + fn toplevel_signal(signal: Arc<(Mutex<bool>, Condvar)>) { |
| 37 | + let connection = zbus::blocking::Connection::session().unwrap(); |
| 38 | + |
| 39 | + loop { |
| 40 | + |
| 41 | + } |
25 | 42 | } |
26 | 43 | } |
27 | 44 |
|
28 | 45 | #[zbus::interface(name = "org.freedesktop.impl.portal.Background")] |
29 | 46 | impl Background { |
30 | 47 | /// Current status on running apps |
31 | | - async fn get_app_state( |
32 | | - &self, |
33 | | - // #[zbus(connection)] connection: &zbus::Connection, |
34 | | - ) -> fdo::Result<HashMap<String, AppStatus>> { |
| 48 | + async fn get_app_state(&self) -> fdo::Result<HashMap<String, AppStatus>> { |
35 | 49 | // TODO: Subscribe to Wayland window open events for running apps |
36 | 50 | log::warn!("[background] GetAppState is currently unimplemented"); |
37 | 51 | Ok(HashMap::default()) |
@@ -147,7 +161,7 @@ impl Background { |
147 | 161 | // } |
148 | 162 |
|
149 | 163 | #[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, zvariant::Type)] |
150 | | -#[zvariant(signature = "u")] |
| 164 | +#[zvariant(signature = "v")] |
151 | 165 | pub enum AppStatus { |
152 | 166 | /// No open windows |
153 | 167 | Background = 0, |
|
0 commit comments