feat(wallpapers): add function to retrieve displays from sctk

This commit is contained in:
Michael Aaron Murphy 2023-05-31 02:43:35 +02:00
parent 9fb0bcdac9
commit 913b219118
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
7 changed files with 170 additions and 24 deletions

51
Cargo.lock generated
View file

@ -718,7 +718,7 @@ dependencies = [
[[package]]
name = "cosmic-bg-config"
version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-bg#c9fec966262a9a3572e662b4e98f647f4807ba33"
source = "git+https://github.com/pop-os/cosmic-bg?branch=settings_jammy#23f4a1f80e98d36efc4a83a59ec9e8b13bfca35b"
dependencies = [
"cosmic-config",
"derive_setters",
@ -754,7 +754,7 @@ dependencies = [
[[package]]
name = "cosmic-panel-config"
version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-panel?branch=settings_jammy#a71a4cba13184f22ba8874c910b20e99f60871c0"
source = "git+https://github.com/pop-os/cosmic-panel?branch=settings_jammy#1b8699fb4b23243e425d05174afb8e3275ff3d4a"
dependencies = [
"anyhow",
"cosmic-config",
@ -804,8 +804,10 @@ dependencies = [
"futures-lite",
"image",
"rayon",
"smithay-client-toolkit 0.17.0 (git+https://github.com/Smithay/client-toolkit)",
"tokio",
"tracing",
"wayland-client 0.30.2",
]
[[package]]
@ -2076,7 +2078,7 @@ dependencies = [
"instant",
"log",
"palette",
"smithay-client-toolkit 0.17.0",
"smithay-client-toolkit 0.17.0 (git+https://github.com/pop-os/client-toolkit?tag=themed-pointer)",
"thiserror",
"twox-hash",
]
@ -2131,7 +2133,7 @@ dependencies = [
"iced_accessibility",
"iced_core",
"iced_futures",
"smithay-client-toolkit 0.17.0",
"smithay-client-toolkit 0.17.0 (git+https://github.com/pop-os/client-toolkit?tag=themed-pointer)",
"thiserror",
]
@ -2150,7 +2152,7 @@ dependencies = [
"itertools",
"log",
"raw-window-handle 0.5.2",
"smithay-client-toolkit 0.17.0",
"smithay-client-toolkit 0.17.0 (git+https://github.com/pop-os/client-toolkit?tag=themed-pointer)",
"smithay-clipboard",
"thiserror",
"wayland-backend",
@ -2216,7 +2218,7 @@ dependencies = [
"iced_style",
"num-traits",
"ouroboros 0.13.0",
"smithay-client-toolkit 0.17.0",
"smithay-client-toolkit 0.17.0 (git+https://github.com/pop-os/client-toolkit?tag=themed-pointer)",
"thiserror",
"unicode-segmentation",
]
@ -2533,7 +2535,7 @@ dependencies = [
"lazy_static",
"palette",
"slotmap",
"smithay-client-toolkit 0.17.0",
"smithay-client-toolkit 0.17.0 (git+https://github.com/pop-os/client-toolkit?tag=themed-pointer)",
"tokio",
]
@ -4006,6 +4008,30 @@ dependencies = [
"xkbcommon",
]
[[package]]
name = "smithay-client-toolkit"
version = "0.17.0"
source = "git+https://github.com/Smithay/client-toolkit#9d0bbc69f33873d5e85864413e12c71f8c458a2d"
dependencies = [
"bitflags 1.3.2",
"calloop",
"cursor-icon",
"dlib",
"log",
"memmap2",
"nix 0.26.2",
"pkg-config",
"thiserror",
"wayland-backend",
"wayland-client 0.30.2",
"wayland-csd-frame",
"wayland-cursor 0.30.0",
"wayland-protocols 0.30.0",
"wayland-protocols-wlr",
"wayland-scanner 0.30.0",
"xkbcommon",
]
[[package]]
name = "smithay-clipboard"
version = "0.6.6"
@ -4840,6 +4866,17 @@ dependencies = [
"wayland-sys 0.29.5",
]
[[package]]
name = "wayland-csd-frame"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72191e30290b83491325d32c1327be7f45459c97263d9d48494c81efc9328116"
dependencies = [
"bitflags 2.3.1",
"cursor-icon",
"wayland-backend",
]
[[package]]
name = "wayland-cursor"
version = "0.29.5"

View file

@ -15,6 +15,7 @@ git = "https://github.com/pop-os/libcosmic"
[workspace.dependencies.cosmic-bg-config]
git = "https://github.com/pop-os/cosmic-bg"
branch = "settings_jammy"
[workspace.dependencies.cosmic-panel-config]
git = "https://github.com/pop-os/cosmic-panel"

View file

@ -1,7 +1,7 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only
use std::{path::PathBuf, time::Instant};
use std::{collections::HashMap, path::PathBuf, time::Instant};
use apply::Apply;
use cosmic::{
@ -23,16 +23,17 @@ pub enum Message {
SameBackground(bool),
Select(DefaultKey),
Slideshow(bool),
Update((wallpaper::Config, Context)),
Update((wallpaper::Config, HashMap<String, String>, Context)),
}
pub struct Page {
pub config: wallpaper::Config,
pub selection: Context,
pub same_background: bool,
pub slideshow: bool,
pub fit_options: Vec<String>,
pub outputs: HashMap<String, String>,
pub same_background: bool,
pub selected_fit: u32,
pub selection: Context,
pub slideshow: bool,
}
const FIT: u32 = 0;
@ -43,11 +44,12 @@ impl Default for Page {
fn default() -> Self {
Page {
config: wallpaper::Config::default(),
selection: Context::default(),
same_background: true,
slideshow: false,
fit_options: vec!["Fit to Screen".into(), "Stretch".into(), "Zoom".into()],
outputs: HashMap::new(),
same_background: true,
selected_fit: 0,
selection: Context::default(),
slideshow: false,
}
}
}
@ -89,15 +91,22 @@ impl Page {
self.apply();
}
Message::SameBackground(value) => self.same_background = value,
Message::SameBackground(value) => {
self.same_background = value;
}
Message::Select(id) => {
self.selection.active = id;
self.apply();
}
Message::Slideshow(value) => self.slideshow = value,
Message::Update((config, selection)) => {
Message::Update((config, outputs, selection)) => {
self.config = config;
self.selection = selection;
self.outputs = outputs;
if let Some(entry) = self
.config
@ -138,7 +147,7 @@ impl page::Page<crate::pages::Message> for Page {
fn load(&self, _page: page::Entity) -> Option<page::Task<crate::pages::Message>> {
Some(Box::pin(async move {
let config = wallpaper::config();
let (config, outputs) = wallpaper::config();
let mut backgrounds =
wallpaper::load_each_from_path("/usr/share/backgrounds/pop/".into());
@ -160,7 +169,7 @@ impl page::Page<crate::pages::Message> for Page {
Instant::now().duration_since(start)
);
crate::pages::Message::DesktopWallpaper(Message::Update((config, update)))
crate::pages::Message::DesktopWallpaper(Message::Update((config, outputs, update)))
}))
}
}

View file

@ -14,4 +14,6 @@ futures-lite = "1.13.0"
image = "0.24.6"
rayon = "1.7.0"
tokio = { version = "1.28.0", features = ["sync"] }
tracing = "0.1.37"
tracing = "0.1.37"
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit" }
wayland-client = "0.30.1"

View file

@ -1 +1,2 @@
pub mod outputs;
pub mod wallpaper;

View file

@ -0,0 +1,84 @@
//! Test application to list all available outputs.
use std::error::Error;
use sctk::{
delegate_output, delegate_registry,
output::{OutputHandler, OutputInfo, OutputState},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
};
use wayland_client::{globals::registry_queue_init, protocol::wl_output, Connection, QueueHandle};
pub fn outputs() -> Result<impl Iterator<Item = OutputInfo>, Box<dyn Error>> {
let conn = Connection::connect_to_env()?;
let (globals, mut event_queue) = registry_queue_init(&conn).unwrap();
let qh = event_queue.handle();
let registry_state = RegistryState::new(&globals);
let output_delegate = OutputState::new(&globals, &qh);
let mut list_outputs = ListOutputs {
registry_state,
output_state: output_delegate,
};
event_queue.roundtrip(&mut list_outputs)?;
// Now our outputs have been initialized with data, we may access what outputs exist and information about
// said outputs using the output delegate.
Ok(list_outputs
.output_state
.outputs()
.filter_map(move |output| list_outputs.output_state.info(&output)))
}
struct ListOutputs {
registry_state: RegistryState,
output_state: OutputState,
}
impl OutputHandler for ListOutputs {
fn output_state(&mut self) -> &mut OutputState {
&mut self.output_state
}
fn new_output(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_output: wl_output::WlOutput,
) {
}
fn update_output(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_output: wl_output::WlOutput,
) {
}
fn output_destroyed(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_output: wl_output::WlOutput,
) {
}
}
delegate_output!(ListOutputs);
delegate_registry!(ListOutputs);
impl ProvidesRegistryState for ListOutputs {
fn registry(&mut self) -> &mut RegistryState {
&mut self.registry_state
}
registry_handlers! {
OutputState
}
}

View file

@ -1,7 +1,7 @@
pub use cosmic_bg_config::{Config, Entry, Output, ScalingMode};
use image::RgbaImage;
use std::{
collections::hash_map::DefaultHasher,
collections::{hash_map::DefaultHasher, HashMap},
fs::DirEntry,
hash::{Hash, Hasher},
path::{Path, PathBuf},
@ -9,16 +9,28 @@ use std::{
};
use tokio::sync::mpsc::{self, Receiver};
pub fn config() -> Config {
pub fn config() -> (Config, HashMap<String, String>) {
let mut displays = HashMap::new();
if let Ok(outputs) = crate::outputs::outputs() {
for output in outputs {
if let Some(name) = output.name {
displays.insert(name, output.make);
}
}
}
let helper = Config::helper().expect("failed to get helper for cosmic bg config");
match Config::load(&helper) {
let config = match Config::load(&helper) {
Ok(conf) => conf,
Err(why) => {
tracing::warn!(?why, "Config file error, falling back to defaults");
Config::default()
}
}
};
(config, displays)
}
pub fn set(config: &mut Config, entry: Entry) {