feat(wallpapers): add function to retrieve displays from sctk
This commit is contained in:
parent
9fb0bcdac9
commit
913b219118
7 changed files with 170 additions and 24 deletions
|
|
@ -1 +1,2 @@
|
|||
pub mod outputs;
|
||||
pub mod wallpaper;
|
||||
|
|
|
|||
84
pages/desktop/src/outputs.rs
Normal file
84
pages/desktop/src/outputs.rs
Normal 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
|
||||
}
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue