This commit is contained in:
nora 2025-12-29 14:40:40 +01:00
parent c75bf46ced
commit cd0c164977
5 changed files with 86 additions and 82 deletions

30
Cargo.lock generated
View file

@ -301,6 +301,21 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "colouncher"
version = "0.1.0"
dependencies = [
"env_logger",
"eyre",
"freedesktop-file-parser",
"freedesktop-icons",
"image",
"log",
"palette",
"smithay-client-toolkit",
"wayland-client",
]
[[package]]
name = "concurrent-queue"
version = "2.5.0"
@ -1514,21 +1529,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "wallpapersc"
version = "0.1.0"
dependencies = [
"env_logger",
"eyre",
"freedesktop-file-parser",
"freedesktop-icons",
"image",
"log",
"palette",
"smithay-client-toolkit",
"wayland-client",
]
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"

View file

@ -1,5 +1,5 @@
[package]
name = "wallpapersc"
name = "colouncher"
version = "0.1.0"
edition = "2024"

View file

@ -1,5 +1,5 @@
{ pkgs ? import <nixpkgs> { } }: pkgs.rustPlatform.buildRustPackage {
pname = "wallpapersc";
pname = "colouncher";
version = "0.1.0";
src = pkgs.lib.cleanSource ./.;
@ -10,4 +10,8 @@
wayland
libxkbcommon
];
meta = {
mainProgram = "colouncher";
};
}

View file

@ -1,12 +1,7 @@
use eyre::{Context, Result};
use freedesktop_file_parser::{DesktopFile, EntryType};
use palette::{IntoColor, Oklab, Oklaba};
use std::{
collections::HashMap,
ffi::OsStr,
fs::DirEntry,
path::{Path, PathBuf},
};
use std::{collections::HashMap, ffi::OsStr, fs::DirEntry, path::Path};
fn walkdir(path: &Path, f: &mut impl FnMut(&DirEntry) -> Result<()>) -> Result<()> {
for entry in path.read_dir()? {
@ -22,7 +17,7 @@ fn walkdir(path: &Path, f: &mut impl FnMut(&DirEntry) -> Result<()>) -> Result<(
pub(crate) fn find_desktop_files() -> Result<Vec<(DesktopFile, Oklab)>> {
// https://specifications.freedesktop.org/desktop-entry/latest/file-naming.html
let paths = std::env::var("XDG_DATA_DIRS").unwrap_or("/usr/local/share/:/usr/share/".into());
let paths = std::env::split_paths(&paths).map(PathBuf::from);
let paths = std::env::split_paths(&paths);
let mut results = HashMap::new();
for data_dir in paths {
@ -47,14 +42,14 @@ pub(crate) fn find_desktop_files() -> Result<Vec<(DesktopFile, Oklab)>> {
let file =
freedesktop_file_parser::parse(&contents).wrap_err("parsing .desktop file")?;
if !results.contains_key(&id) {
if file.entry.no_display != Some(true)
if !results.contains_key(&id)
&& file.entry.no_display != Some(true)
&& file.entry.hidden != Some(true)
&& let EntryType::Application(_) = file.entry.entry_type
&& let Some(icon) = &file.entry.icon
&& let Some(icon) = icon.get_icon_path()
&& icon.extension() != Some(OsStr::new("svg"))
{ dbg!(path);
{
let icon: image::DynamicImage = image::ImageReader::open(&icon)
.wrap_err_with(|| format!("{}", icon.display()))?
.decode()
@ -62,7 +57,6 @@ pub(crate) fn find_desktop_files() -> Result<Vec<(DesktopFile, Oklab)>> {
let color = average_color(&icon);
results.insert(id, (file, color));
}
}
Ok(())
})

View file

@ -232,8 +232,15 @@ impl LayerShellHandler for App {
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_layer: &smithay_client_toolkit::shell::wlr_layer::LayerSurface,
layer: &smithay_client_toolkit::shell::wlr_layer::LayerSurface,
) {
if let Some(surface_idx) = self
.layer_surfaces
.iter()
.position(|surface| surface.layer_surface == *layer)
{
self.layer_surfaces.swap_remove(surface_idx);
}
}
fn configure(
@ -370,10 +377,10 @@ impl PointerHandler for App {
events: &[smithay_client_toolkit::seat::pointer::PointerEvent],
) {
for event in events {
match event.kind {
PointerEventKind::Release {
if let PointerEventKind::Release {
button: BTN_LEFT, ..
} => {
} = event.kind
{
let Some(surface) = self
.layer_surfaces
.iter()
@ -391,9 +398,10 @@ impl PointerHandler for App {
let oklab: Oklab = srgb.into_format::<f32>().into_color();
let best_match = self.desktop_files.iter().min_by_key(|(_, icon_color)| {
(oklab.distance(*icon_color) * 1000000.0) as u32
});
let best_match = self
.desktop_files
.iter()
.min_by_key(|(_, icon_color)| (oklab.distance(*icon_color) * 1000000.0) as u32);
if let Some(best_match) = best_match
&& let EntryType::Application(app) = &best_match.0.entry.entry_type
@ -414,8 +422,6 @@ impl PointerHandler for App {
}
}
}
_ => {}
}
}
}
}