mirror of
https://github.com/Noratrieb/colouncher.git
synced 2026-03-14 21:26:10 +01:00
cleanup
This commit is contained in:
parent
c75bf46ced
commit
cd0c164977
5 changed files with 86 additions and 82 deletions
30
Cargo.lock
generated
30
Cargo.lock
generated
|
|
@ -301,6 +301,21 @@ version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
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]]
|
[[package]]
|
||||||
name = "concurrent-queue"
|
name = "concurrent-queue"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
|
|
@ -1514,21 +1529,6 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"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]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
version = "0.11.1+wasi-snapshot-preview1"
|
version = "0.11.1+wasi-snapshot-preview1"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "wallpapersc"
|
name = "colouncher"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{ pkgs ? import <nixpkgs> { } }: pkgs.rustPlatform.buildRustPackage {
|
{ pkgs ? import <nixpkgs> { } }: pkgs.rustPlatform.buildRustPackage {
|
||||||
pname = "wallpapersc";
|
pname = "colouncher";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
|
|
||||||
src = pkgs.lib.cleanSource ./.;
|
src = pkgs.lib.cleanSource ./.;
|
||||||
|
|
@ -10,4 +10,8 @@
|
||||||
wayland
|
wayland
|
||||||
libxkbcommon
|
libxkbcommon
|
||||||
];
|
];
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
mainProgram = "colouncher";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,7 @@
|
||||||
use eyre::{Context, Result};
|
use eyre::{Context, Result};
|
||||||
use freedesktop_file_parser::{DesktopFile, EntryType};
|
use freedesktop_file_parser::{DesktopFile, EntryType};
|
||||||
use palette::{IntoColor, Oklab, Oklaba};
|
use palette::{IntoColor, Oklab, Oklaba};
|
||||||
use std::{
|
use std::{collections::HashMap, ffi::OsStr, fs::DirEntry, path::Path};
|
||||||
collections::HashMap,
|
|
||||||
ffi::OsStr,
|
|
||||||
fs::DirEntry,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
fn walkdir(path: &Path, f: &mut impl FnMut(&DirEntry) -> Result<()>) -> Result<()> {
|
fn walkdir(path: &Path, f: &mut impl FnMut(&DirEntry) -> Result<()>) -> Result<()> {
|
||||||
for entry in path.read_dir()? {
|
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)>> {
|
pub(crate) fn find_desktop_files() -> Result<Vec<(DesktopFile, Oklab)>> {
|
||||||
// https://specifications.freedesktop.org/desktop-entry/latest/file-naming.html
|
// 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::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();
|
let mut results = HashMap::new();
|
||||||
|
|
||||||
for data_dir in paths {
|
for data_dir in paths {
|
||||||
|
|
@ -47,14 +42,14 @@ pub(crate) fn find_desktop_files() -> Result<Vec<(DesktopFile, Oklab)>> {
|
||||||
let file =
|
let file =
|
||||||
freedesktop_file_parser::parse(&contents).wrap_err("parsing .desktop file")?;
|
freedesktop_file_parser::parse(&contents).wrap_err("parsing .desktop file")?;
|
||||||
|
|
||||||
if !results.contains_key(&id) {
|
if !results.contains_key(&id)
|
||||||
if file.entry.no_display != Some(true)
|
&& file.entry.no_display != Some(true)
|
||||||
&& file.entry.hidden != Some(true)
|
&& file.entry.hidden != Some(true)
|
||||||
&& let EntryType::Application(_) = file.entry.entry_type
|
&& let EntryType::Application(_) = file.entry.entry_type
|
||||||
&& let Some(icon) = &file.entry.icon
|
&& let Some(icon) = &file.entry.icon
|
||||||
&& let Some(icon) = icon.get_icon_path()
|
&& let Some(icon) = icon.get_icon_path()
|
||||||
&& icon.extension() != Some(OsStr::new("svg"))
|
&& icon.extension() != Some(OsStr::new("svg"))
|
||||||
{ dbg!(path);
|
{
|
||||||
let icon: image::DynamicImage = image::ImageReader::open(&icon)
|
let icon: image::DynamicImage = image::ImageReader::open(&icon)
|
||||||
.wrap_err_with(|| format!("{}", icon.display()))?
|
.wrap_err_with(|| format!("{}", icon.display()))?
|
||||||
.decode()
|
.decode()
|
||||||
|
|
@ -62,7 +57,6 @@ pub(crate) fn find_desktop_files() -> Result<Vec<(DesktopFile, Oklab)>> {
|
||||||
let color = average_color(&icon);
|
let color = average_color(&icon);
|
||||||
results.insert(id, (file, color));
|
results.insert(id, (file, color));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
|
|
||||||
24
src/main.rs
24
src/main.rs
|
|
@ -232,8 +232,15 @@ impl LayerShellHandler for App {
|
||||||
&mut self,
|
&mut self,
|
||||||
_conn: &Connection,
|
_conn: &Connection,
|
||||||
_qh: &QueueHandle<Self>,
|
_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(
|
fn configure(
|
||||||
|
|
@ -370,10 +377,10 @@ impl PointerHandler for App {
|
||||||
events: &[smithay_client_toolkit::seat::pointer::PointerEvent],
|
events: &[smithay_client_toolkit::seat::pointer::PointerEvent],
|
||||||
) {
|
) {
|
||||||
for event in events {
|
for event in events {
|
||||||
match event.kind {
|
if let PointerEventKind::Release {
|
||||||
PointerEventKind::Release {
|
|
||||||
button: BTN_LEFT, ..
|
button: BTN_LEFT, ..
|
||||||
} => {
|
} = event.kind
|
||||||
|
{
|
||||||
let Some(surface) = self
|
let Some(surface) = self
|
||||||
.layer_surfaces
|
.layer_surfaces
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -391,9 +398,10 @@ impl PointerHandler for App {
|
||||||
|
|
||||||
let oklab: Oklab = srgb.into_format::<f32>().into_color();
|
let oklab: Oklab = srgb.into_format::<f32>().into_color();
|
||||||
|
|
||||||
let best_match = self.desktop_files.iter().min_by_key(|(_, icon_color)| {
|
let best_match = self
|
||||||
(oklab.distance(*icon_color) * 1000000.0) as u32
|
.desktop_files
|
||||||
});
|
.iter()
|
||||||
|
.min_by_key(|(_, icon_color)| (oklab.distance(*icon_color) * 1000000.0) as u32);
|
||||||
|
|
||||||
if let Some(best_match) = best_match
|
if let Some(best_match) = best_match
|
||||||
&& let EntryType::Application(app) = &best_match.0.entry.entry_type
|
&& let EntryType::Application(app) = &best_match.0.entry.entry_type
|
||||||
|
|
@ -414,8 +422,6 @@ impl PointerHandler for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue