From 9895bd4b4309419057128cd4ab7be6c47f2cd080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Vojinovi=C4=87?= <150025636+git-f0x@users.noreply.github.com> Date: Tue, 28 Apr 2026 15:13:02 +0200 Subject: [PATCH] chore: add rustfmt config --- .zed/settings.json | 15 +++++++ cosmic-greeter-config/src/lib.rs | 6 ++- daemon/src/lib.rs | 15 ++++--- daemon/src/main.rs | 11 +++-- examples/server.rs | 3 +- rustfmt.toml | 1 + src/common.rs | 25 +++++------- src/greeter.rs | 70 +++++++++++++------------------- src/localize.rs | 6 +-- src/locker.rs | 56 +++++++++++-------------- src/logind.rs | 22 +++++----- src/networkmanager.rs | 14 ++++--- src/time.rs | 18 ++++---- src/upower.rs | 11 +++-- src/wayland/mod.rs | 7 +--- 15 files changed, 136 insertions(+), 144 deletions(-) create mode 100644 .zed/settings.json create mode 100644 rustfmt.toml diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000..2cc7b98 --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,15 @@ +{ + "format_on_save": "on", + "lsp": { + "rust-analyzer": { + "initialization_options": { + "check": { + "command": "clippy", + }, + "rustfmt": { + "extraArgs": ["+nightly"], + }, + }, + }, + }, +} diff --git a/cosmic-greeter-config/src/lib.rs b/cosmic-greeter-config/src/lib.rs index 96869c5..50fff98 100644 --- a/cosmic-greeter-config/src/lib.rs +++ b/cosmic-greeter-config/src/lib.rs @@ -3,9 +3,11 @@ pub mod user; -use cosmic_config::{CosmicConfigEntry, cosmic_config_derive::CosmicConfigEntry}; +use cosmic_config::CosmicConfigEntry; +use cosmic_config::cosmic_config_derive::CosmicConfigEntry; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, num::NonZeroU32}; +use std::collections::HashMap; +use std::num::NonZeroU32; pub const APP_ID: &str = "com.system76.CosmicGreeter"; pub const CONFIG_VERSION: u64 = 1; diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs index 842a92e..842aebe 100644 --- a/daemon/src/lib.rs +++ b/daemon/src/lib.rs @@ -1,16 +1,15 @@ use cosmic_comp_config::output::randr; use cosmic_config::CosmicConfigEntry; use kdl::KdlDocument; -use std::{ - collections::BTreeMap, - fs, - io::Read, - os::unix::fs::OpenOptionsExt, - path::{Path, PathBuf}, -}; +use std::collections::BTreeMap; +use std::fs; +use std::io::Read; +use std::os::unix::fs::OpenOptionsExt; +use std::path::{Path, PathBuf}; pub use cosmic_applets_config::time::TimeAppletConfig; -pub use cosmic_bg_config::{Color, Source as BgSource, state::State as BgState}; +pub use cosmic_bg_config::state::State as BgState; +pub use cosmic_bg_config::{Color, Source as BgSource}; pub use cosmic_comp_config::{CosmicCompConfig, XkbConfig, ZoomConfig}; pub use cosmic_theme::{Theme, ThemeBuilder}; diff --git a/daemon/src/main.rs b/daemon/src/main.rs index 41bd5ed..427070a 100644 --- a/daemon/src/main.rs +++ b/daemon/src/main.rs @@ -1,10 +1,15 @@ use color_eyre::eyre::Context; use cosmic_greeter_daemon::{UserData, UserFilter}; -use std::{env, error::Error, ffi::CString, future::pending, io}; +use std::error::Error; +use std::ffi::CString; +use std::future::pending; +use std::{env, io}; use tracing::metadata::LevelFilter; use tracing::warn; -use tracing_subscriber::{EnvFilter, fmt, prelude::*}; -use zbus::{DBusError, connection::Builder}; +use tracing_subscriber::prelude::*; +use tracing_subscriber::{EnvFilter, fmt}; +use zbus::DBusError; +use zbus::connection::Builder; //IMPORTANT: this function is critical to the security of this proxy. It must ensure that the // callback is executed with the permissions of the specified user id. A good test is to see if diff --git a/examples/server.rs b/examples/server.rs index 6fbfe5f..c6f35f8 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -1,4 +1,5 @@ -use greetd_ipc::{AuthMessageType, ErrorType, Request, Response, codec::TokioCodec}; +use greetd_ipc::codec::TokioCodec; +use greetd_ipc::{AuthMessageType, ErrorType, Request, Response}; use std::{env, fs, io, thread}; use tokio::net::UnixListener; diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..c1578aa --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +imports_granularity = "Module" diff --git a/src/common.rs b/src/common.rs index 691a94c..6fdd371 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,20 +1,15 @@ -use cosmic::{ - app::{Core, Task}, - iced::runtime::core::window::Id as SurfaceId, - iced::{ - self, Rectangle, Size, Subscription, - core::SmolStr, - event::{ - self, - wayland::{Event as WaylandEvent, OutputEvent, SessionLockEvent}, - }, - keyboard::{Event as KeyEvent, Key, Modifiers}, - }, - widget, -}; +use cosmic::app::{Core, Task}; +use cosmic::iced::core::SmolStr; +use cosmic::iced::event::wayland::{Event as WaylandEvent, OutputEvent, SessionLockEvent}; +use cosmic::iced::event::{self}; +use cosmic::iced::keyboard::{Event as KeyEvent, Key, Modifiers}; +use cosmic::iced::runtime::core::window::Id as SurfaceId; +use cosmic::iced::{self, Rectangle, Size, Subscription}; +use cosmic::widget; use cosmic_config::{ConfigSet, CosmicConfigEntry}; use cosmic_greeter_daemon::{BgSource, CosmicCompConfig, UserData}; -use std::{collections::HashMap, sync::Arc}; +use std::collections::HashMap; +use std::sync::Arc; use wayland_client::protocol::wl_output::WlOutput; pub const DEFAULT_MENU_ITEM_HEIGHT: f32 = 36.; diff --git a/src/greeter.rs b/src/greeter.rs index d0b0405..51fe4b2 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -8,63 +8,51 @@ use cctk::sctk::reexports::calloop; use color_eyre::eyre::WrapErr; use cosmic::app::{Core, Settings, Task}; use cosmic::cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Gravity; +use cosmic::cosmic_config::{self, ConfigSet}; +use cosmic::cosmic_theme::{self, CosmicPalette}; +use cosmic::desktop::fde::{DesktopEntry, get_languages_from_env}; use cosmic::iced::event::listen_with; +use cosmic::iced::event::wayland::OutputEvent; +use cosmic::iced::futures::SinkExt; +use cosmic::iced::platform_specific::runtime::wayland::layer_surface::{ + IcedMargin, IcedOutput, SctkLayerSurfaceSettings, +}; +use cosmic::iced::platform_specific::shell::wayland::commands::layer_surface::{ + Anchor, KeyboardInteractivity, Layer, destroy_layer_surface, get_layer_surface, +}; +use cosmic::iced::platform_specific::shell::wayland::commands::subsurface::reposition_subsurface; +use cosmic::iced::runtime::core::window::Id as SurfaceId; use cosmic::iced::runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings; -use cosmic::iced::{Point, Size, window}; +use cosmic::iced::{ + self, Alignment, Background, Border, Length, Point, Size, Subscription, window, +}; use cosmic::widget::{id_container, text}; -use cosmic::{ - Element, - cosmic_config::{self, ConfigSet}, - executor, - iced::runtime::core::window::Id as SurfaceId, - iced::{ - self, Alignment, Background, Border, Length, Subscription, - event::wayland::OutputEvent, - futures::SinkExt, - platform_specific::{ - runtime::wayland::layer_surface::{IcedMargin, IcedOutput, SctkLayerSurfaceSettings}, - shell::wayland::commands::layer_surface::{ - Anchor, KeyboardInteractivity, Layer, destroy_layer_surface, get_layer_surface, - }, - shell::wayland::commands::subsurface::reposition_subsurface, - }, - }, - theme, widget, -}; -use cosmic::{ - cosmic_theme::{self, CosmicPalette}, - desktop::fde::{DesktopEntry, get_languages_from_env}, - surface, -}; +use cosmic::{Element, executor, surface, theme, widget}; use cosmic_greeter_config::Config as CosmicGreeterConfig; use cosmic_greeter_daemon::{UserData, UserFilter}; use cosmic_randr_shell::{KdlParseWithError, List}; use cosmic_settings_a11y_manager_subscription::{AccessibilityEvent, AccessibilityRequest}; use greetd_ipc::Request; use kdl::KdlDocument; +use std::collections::{HashMap, hash_map}; +use std::error::Error; +use std::num::NonZeroU32; use std::process::Stdio; -use std::sync::LazyLock; -use std::{ - collections::{HashMap, hash_map}, - error::Error, - fs, io, - num::NonZeroU32, - process, - sync::Arc, - time::{Duration, Instant}, -}; +use std::sync::{Arc, LazyLock}; +use std::time::{Duration, Instant}; +use std::{fs, io, process}; use tokio::process::Child; use tokio::time; use tracing::metadata::LevelFilter; use tracing::warn; -use tracing_subscriber::{EnvFilter, fmt, prelude::*}; -use wayland_client::{Proxy, protocol::wl_output::WlOutput}; +use tracing_subscriber::prelude::*; +use tracing_subscriber::{EnvFilter, fmt}; +use wayland_client::Proxy; +use wayland_client::protocol::wl_output::WlOutput; use zbus::{Connection, proxy}; -use crate::{ - common::{self, Common, DEFAULT_MENU_ITEM_HEIGHT}, - fl, -}; +use crate::common::{self, Common, DEFAULT_MENU_ITEM_HEIGHT}; +use crate::fl; static USERNAME_ID: LazyLock = LazyLock::new(|| iced::id::Id::new("username-id")); diff --git a/src/localize.rs b/src/localize.rs index 30eedec..8998576 100644 --- a/src/localize.rs +++ b/src/localize.rs @@ -1,9 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only -use i18n_embed::{ - DefaultLocalizer, LanguageLoader, Localizer, - fluent::{FluentLanguageLoader, fluent_language_loader}, -}; +use i18n_embed::fluent::{FluentLanguageLoader, fluent_language_loader}; +use i18n_embed::{DefaultLocalizer, LanguageLoader, Localizer}; use rust_embed::RustEmbed; use std::sync::OnceLock; diff --git a/src/locker.rs b/src/locker.rs index 1a5f8a5..9098b55 100644 --- a/src/locker.rs +++ b/src/locker.rs @@ -4,45 +4,37 @@ use color_eyre::eyre::WrapErr; use cosmic::app::{Core, Settings, Task}; use cosmic::cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Gravity; -use cosmic::iced::runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings; -use cosmic::iced::{Point, Rectangle, Size}; -use cosmic::surface; -use cosmic::{ - Element, executor, - iced::runtime::core::window::Id as SurfaceId, - iced::{ - self, Alignment, Background, Border, Length, Subscription, - event::wayland::{OutputEvent, SessionLockEvent}, - futures::{self, SinkExt}, - platform_specific::shell::wayland::commands::session_lock::{ - destroy_lock_surface, get_lock_surface, lock, unlock, - }, - }, - theme, widget, +use cosmic::iced::event::wayland::{OutputEvent, SessionLockEvent}; +use cosmic::iced::futures::{self, SinkExt}; +use cosmic::iced::platform_specific::shell::wayland::commands::session_lock::{ + destroy_lock_surface, get_lock_surface, lock, unlock, }; +use cosmic::iced::runtime::core::window::Id as SurfaceId; +use cosmic::iced::runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings; +use cosmic::iced::{ + self, Alignment, Background, Border, Length, Point, Rectangle, Size, Subscription, +}; +use cosmic::{Element, executor, surface, theme, widget}; use cosmic_config::CosmicConfigEntry; use cosmic_greeter_daemon::{TimeAppletConfig, UserData}; +use std::any::TypeId; +use std::ffi::{CStr, CString}; +use std::os::fd::OwnedFd; +use std::path::PathBuf; +use std::sync::Arc; use std::time::Duration; -use std::{ - any::TypeId, - env, - ffi::{CStr, CString}, - fs, - os::fd::OwnedFd, - path::PathBuf, - process, - sync::Arc, -}; -use tokio::{sync::mpsc, task}; +use std::{env, fs, process}; +use tokio::sync::mpsc; +use tokio::task; use tracing::level_filters::LevelFilter; use tracing::warn; -use tracing_subscriber::{EnvFilter, fmt, prelude::*}; -use wayland_client::{Proxy, protocol::wl_output::WlOutput}; +use tracing_subscriber::prelude::*; +use tracing_subscriber::{EnvFilter, fmt}; +use wayland_client::Proxy; +use wayland_client::protocol::wl_output::WlOutput; -use crate::{ - common::{self, Common, DEFAULT_MENU_ITEM_HEIGHT}, - fl, -}; +use crate::common::{self, Common, DEFAULT_MENU_ITEM_HEIGHT}; +use crate::fl; fn lockfile_opt() -> Option { let runtime_dir = dirs::runtime_dir()?; diff --git a/src/logind.rs b/src/logind.rs index 822140c..c5561f3 100644 --- a/src/logind.rs +++ b/src/logind.rs @@ -1,15 +1,17 @@ -use cosmic::iced::{ - Subscription, - futures::{SinkExt, StreamExt, channel::mpsc}, -}; -use logind_zbus::{ - manager::{InhibitType, ManagerProxy}, - session::SessionProxy, -}; -use std::{any::TypeId, error::Error, os::fd::OwnedFd, sync::Arc, time::Duration}; +use cosmic::iced::Subscription; +use cosmic::iced::futures::channel::mpsc; +use cosmic::iced::futures::{SinkExt, StreamExt}; +use logind_zbus::manager::{InhibitType, ManagerProxy}; +use logind_zbus::session::SessionProxy; +use std::any::TypeId; +use std::error::Error; +use std::os::fd::OwnedFd; +use std::sync::Arc; +use std::time::Duration; use zbus::Connection; -use crate::{common, locker::Message}; +use crate::common; +use crate::locker::Message; pub async fn power_off() -> zbus::Result<()> { let connection = Connection::system().await?; diff --git a/src/networkmanager.rs b/src/networkmanager.rs index 06cba00..0f4ee9c 100644 --- a/src/networkmanager.rs +++ b/src/networkmanager.rs @@ -1,9 +1,11 @@ -use cosmic::iced::{ - Subscription, - futures::{SinkExt, StreamExt, channel::mpsc}, -}; -use cosmic_dbus_networkmanager::{device::SpecificDevice, nm::NetworkManager}; -use std::{any::TypeId, cmp, time::Duration}; +use cosmic::iced::Subscription; +use cosmic::iced::futures::channel::mpsc; +use cosmic::iced::futures::{SinkExt, StreamExt}; +use cosmic_dbus_networkmanager::device::SpecificDevice; +use cosmic_dbus_networkmanager::nm::NetworkManager; +use std::any::TypeId; +use std::cmp; +use std::time::Duration; use zbus::{Connection, Result}; #[derive(Clone, Copy, Debug)] diff --git a/src/time.rs b/src/time.rs index f3b1540..bc2c22d 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,17 +1,13 @@ use anyhow::bail; use async_fn_stream::StreamEmitter; -use cosmic::{ - Element, Task, style, - widget::{column, text}, -}; +use cosmic::widget::{column, text}; +use cosmic::{Element, Task, style}; use futures_util::StreamExt; -use icu::{ - datetime::{ - DateTimeFormatter, DateTimeFormatterPreferences, fieldsets, input::DateTime, - options::TimePrecision, - }, - locale::{Locale, preferences::extensions::unicode::keywords::HourCycle}, -}; +use icu::datetime::input::DateTime; +use icu::datetime::options::TimePrecision; +use icu::datetime::{DateTimeFormatter, DateTimeFormatterPreferences, fieldsets}; +use icu::locale::Locale; +use icu::locale::preferences::extensions::unicode::keywords::HourCycle; use jiff::tz::TimeZone; use jiff_icu::ConvertFrom; use std::time::Duration; diff --git a/src/upower.rs b/src/upower.rs index 3e5b96b..77bb82f 100644 --- a/src/upower.rs +++ b/src/upower.rs @@ -1,10 +1,9 @@ -use cosmic::iced::{ - Subscription, - futures::{SinkExt, StreamExt, channel::mpsc}, - stream, -}; +use cosmic::iced::futures::channel::mpsc; +use cosmic::iced::futures::{SinkExt, StreamExt}; +use cosmic::iced::{Subscription, stream}; use futures_util::select; -use std::{any::TypeId, time::Duration}; +use std::any::TypeId; +use std::time::Duration; use upower_dbus::{BatteryState, BatteryType, UPowerProxy}; use zbus::{Connection, Result}; diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 20acaf3..cfb6e9a 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -2,11 +2,8 @@ // SPDX-License-Identifier: GPL-3.0-only use cctk::sctk::reexports::calloop; -use cosmic::iced::{ - self, Subscription, - futures::{self, SinkExt}, - stream, -}; +use cosmic::iced::futures::{self, SinkExt}; +use cosmic::iced::{self, Subscription, stream}; use cosmic_settings_a11y_manager_subscription::{ self as thread, AccessibilityEvent, AccessibilityRequest, };