improv(wallpaper): share display listing logic with display page
This commit is contained in:
parent
f25e31ed45
commit
e7c9595578
14 changed files with 66 additions and 145 deletions
|
|
@ -1,2 +0,0 @@
|
|||
pub mod outputs;
|
||||
pub mod wallpaper;
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
//! 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,5 +1,5 @@
|
|||
[package]
|
||||
name = "cosmic-settings-desktop"
|
||||
name = "cosmic-settings-wallpaper"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
|
@ -8,13 +8,12 @@ edition = "2021"
|
|||
[dependencies]
|
||||
cosmic-bg-config = { workspace = true }
|
||||
cosmic-config = { workspace = true }
|
||||
cosmic-randr-shell = { workspace = true }
|
||||
dirs = "5.0.1"
|
||||
freedesktop-icons = "0.2.5"
|
||||
futures-lite = "2.2.0"
|
||||
image = "0.24.8"
|
||||
infer = "0.15.0"
|
||||
rayon = "1.8.1"
|
||||
sctk = { workspace = true }
|
||||
tokio = { version = "1.35.1", features = ["sync"] }
|
||||
tracing = "0.1.40"
|
||||
wayland-client = "0.31.2"
|
||||
|
|
@ -43,14 +43,12 @@ pub const DEFAULT_COLORS: &[Color] = &[
|
|||
}),
|
||||
];
|
||||
|
||||
pub fn config() -> (Config, HashMap<String, String>) {
|
||||
pub async fn config() -> (Config, HashMap<String, (String, (u32, u32))>) {
|
||||
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);
|
||||
}
|
||||
if let Ok(list) = cosmic_randr_shell::list().await {
|
||||
for (_key, output) in list.outputs {
|
||||
displays.insert(output.name, (output.model, output.physical));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue