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
39
Cargo.lock
generated
39
Cargo.lock
generated
|
|
@ -1083,7 +1083,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-randr-shell"
|
name = "cosmic-randr-shell"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/cosmic-randr?rev=c35172c#c35172c637865d498ac509848a9194ba345d1350"
|
source = "git+https://github.com/pop-os/cosmic-randr#88c570cf8b88beae1cf4f3e2d412cc64ec49cd7c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"kdl",
|
"kdl",
|
||||||
"slotmap",
|
"slotmap",
|
||||||
|
|
@ -1104,10 +1104,10 @@ dependencies = [
|
||||||
"cosmic-comp-config",
|
"cosmic-comp-config",
|
||||||
"cosmic-panel-config",
|
"cosmic-panel-config",
|
||||||
"cosmic-randr-shell",
|
"cosmic-randr-shell",
|
||||||
"cosmic-settings-desktop",
|
|
||||||
"cosmic-settings-page",
|
"cosmic-settings-page",
|
||||||
"cosmic-settings-system",
|
"cosmic-settings-system",
|
||||||
"cosmic-settings-time",
|
"cosmic-settings-time",
|
||||||
|
"cosmic-settings-wallpaper",
|
||||||
"derivative",
|
"derivative",
|
||||||
"derive_setters",
|
"derive_setters",
|
||||||
"dirs 5.0.1",
|
"dirs 5.0.1",
|
||||||
|
|
@ -1136,24 +1136,6 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cosmic-settings-desktop"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"cosmic-bg-config",
|
|
||||||
"cosmic-config",
|
|
||||||
"dirs 5.0.1",
|
|
||||||
"freedesktop-icons",
|
|
||||||
"futures-lite 2.2.0",
|
|
||||||
"image",
|
|
||||||
"infer",
|
|
||||||
"rayon",
|
|
||||||
"smithay-client-toolkit 0.18.0",
|
|
||||||
"tokio",
|
|
||||||
"tracing",
|
|
||||||
"wayland-client 0.31.2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-settings-page"
|
name = "cosmic-settings-page"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
@ -1190,6 +1172,23 @@ dependencies = [
|
||||||
"zbus",
|
"zbus",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cosmic-settings-wallpaper"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"cosmic-bg-config",
|
||||||
|
"cosmic-config",
|
||||||
|
"cosmic-randr-shell",
|
||||||
|
"dirs 5.0.1",
|
||||||
|
"freedesktop-icons",
|
||||||
|
"futures-lite 2.2.0",
|
||||||
|
"image",
|
||||||
|
"infer",
|
||||||
|
"rayon",
|
||||||
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-text"
|
name = "cosmic-text"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ git = "https://github.com/pop-os/cosmic-comp"
|
||||||
[workspace.dependencies.cosmic-panel-config]
|
[workspace.dependencies.cosmic-panel-config]
|
||||||
git = "https://github.com/pop-os/cosmic-panel"
|
git = "https://github.com/pop-os/cosmic-panel"
|
||||||
|
|
||||||
|
[workspace.dependencies.cosmic-randr-shell]
|
||||||
|
git = "https://github.com/pop-os/cosmic-randr"
|
||||||
|
|
||||||
[workspace.dependencies.sctk]
|
[workspace.dependencies.sctk]
|
||||||
git = "https://github.com/smithay/client-toolkit/"
|
git = "https://github.com/smithay/client-toolkit/"
|
||||||
package = "smithay-client-toolkit"
|
package = "smithay-client-toolkit"
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ rust-version = "1.65.0"
|
||||||
apply = "0.3.0"
|
apply = "0.3.0"
|
||||||
async-channel = "2.1.1"
|
async-channel = "2.1.1"
|
||||||
color-eyre = "0.6.2"
|
color-eyre = "0.6.2"
|
||||||
cosmic-randr-shell = { git = "https://github.com/pop-os/cosmic-randr", rev = "c35172c" }
|
cosmic-randr-shell = { workspace = true }
|
||||||
cosmic-settings-desktop = { path = "../pages/desktop" }
|
cosmic-settings-wallpaper = { path = "../pages/wallpapers" }
|
||||||
cosmic-settings-page = { path = "../page" }
|
cosmic-settings-page = { path = "../page" }
|
||||||
cosmic-settings-system = { path = "../pages/system" }
|
cosmic-settings-system = { path = "../pages/system" }
|
||||||
cosmic-settings-time = { path = "../pages/time" }
|
cosmic-settings-time = { path = "../pages/time" }
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ pub mod config;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod localize;
|
pub mod localize;
|
||||||
pub mod pages;
|
pub mod pages;
|
||||||
pub mod theme;
|
|
||||||
pub mod widget;
|
|
||||||
|
|
||||||
pub mod subscription;
|
pub mod subscription;
|
||||||
|
pub mod theme;
|
||||||
|
pub mod utils;
|
||||||
|
pub mod widget;
|
||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use cosmic::{app::CosmicFlags, iced::Limits};
|
use cosmic::{app::CosmicFlags, iced::Limits};
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ use cosmic::widget::{
|
||||||
settings, spin_button, text, ColorPickerModel,
|
settings, spin_button, text, ColorPickerModel,
|
||||||
};
|
};
|
||||||
use cosmic::{command, Command, Element};
|
use cosmic::{command, Command, Element};
|
||||||
use cosmic_settings_desktop::wallpaper;
|
|
||||||
use cosmic_settings_page::Section;
|
use cosmic_settings_page::Section;
|
||||||
use cosmic_settings_page::{self as page, section};
|
use cosmic_settings_page::{self as page, section};
|
||||||
|
use cosmic_settings_wallpaper as wallpaper;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use ron::ser::PrettyConfig;
|
use ron::ser::PrettyConfig;
|
||||||
use slotmap::SlotMap;
|
use slotmap::SlotMap;
|
||||||
|
|
|
||||||
|
|
@ -470,24 +470,9 @@ impl Page {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let inches =
|
|
||||||
((output.physical.0.pow(2) + output.physical.1.pow(2)) as f32).sqrt() * 0.039_370_1;
|
|
||||||
|
|
||||||
let inches_string = format!("{inches:.1}\"");
|
|
||||||
|
|
||||||
self.display_tabs
|
self.display_tabs
|
||||||
.insert()
|
.insert()
|
||||||
.text(match name {
|
.text(crate::utils::display_name(&output.name, output.physical))
|
||||||
"eDP-1" | "LVDS1" => {
|
|
||||||
fl!("display", "laptop", size = inches_string.as_str())
|
|
||||||
}
|
|
||||||
output => fl!(
|
|
||||||
"display",
|
|
||||||
"external",
|
|
||||||
size = inches_string.as_str(),
|
|
||||||
output = output
|
|
||||||
),
|
|
||||||
})
|
|
||||||
.data::<OutputKey>(id);
|
.data::<OutputKey>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use cosmic::cosmic_config::{self, ConfigGet, ConfigSet};
|
use cosmic::cosmic_config::{self, ConfigGet, ConfigSet};
|
||||||
use cosmic_settings_desktop::wallpaper;
|
use cosmic_settings_wallpaper as wallpaper;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,9 @@ use cosmic::{
|
||||||
widget::{color_picker::ColorPickerUpdate, ColorPickerModel},
|
widget::{color_picker::ColorPickerUpdate, ColorPickerModel},
|
||||||
Element,
|
Element,
|
||||||
};
|
};
|
||||||
use cosmic_settings_desktop::wallpaper::{self, Entry, ScalingMode};
|
|
||||||
use cosmic_settings_page::Section;
|
use cosmic_settings_page::Section;
|
||||||
use cosmic_settings_page::{self as page, section};
|
use cosmic_settings_page::{self as page, section};
|
||||||
|
use cosmic_settings_wallpaper::{self as wallpaper, Entry, ScalingMode};
|
||||||
use image::imageops::FilterType::Lanczos3;
|
use image::imageops::FilterType::Lanczos3;
|
||||||
use image::{ImageBuffer, Rgba};
|
use image::{ImageBuffer, Rgba};
|
||||||
use slotmap::{DefaultKey, SecondaryMap, SlotMap};
|
use slotmap::{DefaultKey, SecondaryMap, SlotMap};
|
||||||
|
|
@ -93,7 +93,13 @@ pub enum Message {
|
||||||
/// Removes a custom image from the wallpaper view.
|
/// Removes a custom image from the wallpaper view.
|
||||||
ImageRemove(DefaultKey),
|
ImageRemove(DefaultKey),
|
||||||
/// Initializes the view.
|
/// Initializes the view.
|
||||||
Init(Box<(wallpaper::Config, HashMap<String, String>, Context)>),
|
Init(
|
||||||
|
Box<(
|
||||||
|
wallpaper::Config,
|
||||||
|
HashMap<String, (String, (u32, u32))>,
|
||||||
|
Context,
|
||||||
|
)>,
|
||||||
|
),
|
||||||
/// Changes the active output display that is to be configured.
|
/// Changes the active output display that is to be configured.
|
||||||
Output(segmented_button::Entity),
|
Output(segmented_button::Entity),
|
||||||
/// Changes the rotation frequency of wallpaper images in slideshow mode.
|
/// Changes the rotation frequency of wallpaper images in slideshow mode.
|
||||||
|
|
@ -184,7 +190,7 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
let current_folder = self.config.current_folder().to_owned();
|
let current_folder = self.config.current_folder().to_owned();
|
||||||
|
|
||||||
command::future(async move {
|
command::future(async move {
|
||||||
let (wallpaper_service_config, outputs) = wallpaper::config();
|
let (wallpaper_service_config, outputs) = wallpaper::config().await;
|
||||||
|
|
||||||
let update = change_folder(current_folder).await;
|
let update = change_folder(current_folder).await;
|
||||||
|
|
||||||
|
|
@ -414,7 +420,7 @@ impl Page {
|
||||||
fn wallpaper_service_config_update(
|
fn wallpaper_service_config_update(
|
||||||
&mut self,
|
&mut self,
|
||||||
wallpaper_service_config: wallpaper::Config,
|
wallpaper_service_config: wallpaper::Config,
|
||||||
displays: HashMap<String, String>,
|
displays: HashMap<String, (String, (u32, u32))>,
|
||||||
selection: Context,
|
selection: Context,
|
||||||
) {
|
) {
|
||||||
self.wallpaper_service_config = wallpaper_service_config;
|
self.wallpaper_service_config = wallpaper_service_config;
|
||||||
|
|
@ -422,11 +428,11 @@ impl Page {
|
||||||
self.outputs.clear();
|
self.outputs.clear();
|
||||||
|
|
||||||
let mut first = None;
|
let mut first = None;
|
||||||
for (name, model) in displays {
|
for (name, (_model, physical)) in displays {
|
||||||
let entity = self
|
let entity = self
|
||||||
.outputs
|
.outputs
|
||||||
.insert()
|
.insert()
|
||||||
.text(format!("{model} ({name})"))
|
.text(crate::utils::display_name(&name, physical))
|
||||||
.data(name);
|
.data(name);
|
||||||
|
|
||||||
if first.is_none() {
|
if first.is_none() {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use cosmic::iced_runtime::core::image::Handle as ImageHandle;
|
||||||
use cosmic::prelude::*;
|
use cosmic::prelude::*;
|
||||||
use cosmic::widget::{button, container, space};
|
use cosmic::widget::{button, container, space};
|
||||||
use cosmic::{iced, Element};
|
use cosmic::{iced, Element};
|
||||||
use cosmic_settings_desktop::wallpaper;
|
use cosmic_settings_wallpaper as wallpaper;
|
||||||
use slotmap::DefaultKey;
|
use slotmap::DefaultKey;
|
||||||
|
|
||||||
const COLOR_WIDTH: u16 = 70;
|
const COLOR_WIDTH: u16 = 70;
|
||||||
|
|
|
||||||
17
app/src/utils.rs
Normal file
17
app/src/utils.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
/// Normalize the labeling of displays across settings pages.
|
||||||
|
pub fn display_name(name: &str, physical: (u32, u32)) -> String {
|
||||||
|
let inches = ((physical.0.pow(2) + physical.1.pow(2)) as f32).sqrt() * 0.039_370_1;
|
||||||
|
let inches_string = format!("{inches:.1}\"");
|
||||||
|
|
||||||
|
match name {
|
||||||
|
"eDP-1" | "LVDS1" => {
|
||||||
|
fl!("display", "laptop", size = inches_string.as_str())
|
||||||
|
}
|
||||||
|
output => fl!(
|
||||||
|
"display",
|
||||||
|
"external",
|
||||||
|
size = inches_string.as_str(),
|
||||||
|
output = output
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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]
|
[package]
|
||||||
name = "cosmic-settings-desktop"
|
name = "cosmic-settings-wallpaper"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
@ -8,13 +8,12 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cosmic-bg-config = { workspace = true }
|
cosmic-bg-config = { workspace = true }
|
||||||
cosmic-config = { workspace = true }
|
cosmic-config = { workspace = true }
|
||||||
|
cosmic-randr-shell = { workspace = true }
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
freedesktop-icons = "0.2.5"
|
freedesktop-icons = "0.2.5"
|
||||||
futures-lite = "2.2.0"
|
futures-lite = "2.2.0"
|
||||||
image = "0.24.8"
|
image = "0.24.8"
|
||||||
infer = "0.15.0"
|
infer = "0.15.0"
|
||||||
rayon = "1.8.1"
|
rayon = "1.8.1"
|
||||||
sctk = { workspace = true }
|
|
||||||
tokio = { version = "1.35.1", features = ["sync"] }
|
tokio = { version = "1.35.1", features = ["sync"] }
|
||||||
tracing = "0.1.40"
|
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();
|
let mut displays = HashMap::new();
|
||||||
|
|
||||||
if let Ok(outputs) = crate::outputs::outputs() {
|
if let Ok(list) = cosmic_randr_shell::list().await {
|
||||||
for output in outputs {
|
for (_key, output) in list.outputs {
|
||||||
if let Some(name) = output.name {
|
displays.insert(output.name, (output.model, output.physical));
|
||||||
displays.insert(name, output.make);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue