Move config into a separate crate

Get miette and knuffel deps contained within.
This commit is contained in:
Ivan Molodetskikh 2024-01-07 09:07:22 +04:00
parent 4e0aa39113
commit 64c41fa2c8
15 changed files with 92 additions and 41 deletions

15
Cargo.lock generated
View File

@ -1704,11 +1704,10 @@ dependencies = [
"directories",
"git-version",
"keyframe",
"knuffel",
"libc",
"log",
"logind-zbus",
"miette",
"niri-config",
"notify-rust",
"pipewire",
"png",
@ -1728,6 +1727,18 @@ dependencies = [
"zbus",
]
[[package]]
name = "niri-config"
version = "0.1.0-alpha.3"
dependencies = [
"bitflags 2.4.1",
"directories",
"knuffel",
"miette",
"smithay",
"tracing",
]
[[package]]
name = "nix"
version = "0.26.4"

View File

@ -1,13 +1,35 @@
[package]
name = "niri"
[workspace.package]
version = "0.1.0-alpha.3"
description = "A scrollable-tiling Wayland compositor"
authors = ["Ivan Molodetskikh <yalterz@gmail.com>"]
license = "GPL-3.0-or-later"
edition = "2021"
repository = "https://github.com/YaLTeR/niri"
[workspace.dependencies]
bitflags = "2.4.1"
directories = "5.0.1"
tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] }
[workspace.dependencies.smithay]
git = "https://github.com/Smithay/smithay.git"
# path = "../smithay"
default-features = false
[workspace.dependencies.smithay-drm-extras]
git = "https://github.com/Smithay/smithay.git"
# path = "../smithay/smithay-drm-extras"
[package]
name = "niri"
version.workspace = true
description.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true
repository.workspace = true
readme = "README.md"
repository = "https://github.com/YaLTeR/niri"
keywords = ["wayland", "compositor", "tiling", "smithay", "wm"]
[dependencies]
@ -20,29 +42,27 @@ clap = { version = "4.4.13", features = ["derive"] }
directories = "5.0.1"
git-version = "0.3.9"
keyframe = { version = "1.1.1", default-features = false }
knuffel = "3.2.0"
libc = "0.2.151"
logind-zbus = { version = "3.1.2", optional = true }
log = { version = "0.4.20", features = ["max_level_trace", "release_max_level_debug"] }
miette = "5.10.0"
niri-config = { version = "0.1.0-alpha.3", path = "niri-config" }
notify-rust = { version = "4.10.0", optional = true }
pipewire = { version = "0.7.2", optional = true }
png = "0.17.10"
portable-atomic = { version = "1.6.0", default-features = false, features = ["float"] }
profiling = "1.0.13"
sd-notify = "0.4.1"
smithay-drm-extras.workspace = true
serde = { version = "1.0.195", features = ["derive"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] }
tracing.workspace = true
tracy-client = { version = "0.16.5", default-features = false }
url = { version = "2.5.0", optional = true }
xcursor = "0.3.5"
zbus = { version = "3.14.1", optional = true }
[dependencies.smithay]
git = "https://github.com/Smithay/smithay.git"
# path = "../smithay"
default-features = false
workspace = true
features = [
"backend_drm",
"backend_egl",
@ -58,10 +78,6 @@ features = [
"wayland_frontend",
]
[dependencies.smithay-drm-extras]
git = "https://github.com/Smithay/smithay.git"
# path = "../smithay/smithay-drm-extras"
[dev-dependencies]
proptest = "1.4.0"
proptest-derive = "0.4.0"

16
niri-config/Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
name = "niri-config"
version.workspace = true
description.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true
repository.workspace = true
[dependencies]
bitflags.workspace = true
directories.workspace = true
knuffel = "3.2.0"
miette = "5.10.0"
smithay.workspace = true
tracing.workspace = true

View File

@ -1,9 +1,12 @@
#[macro_use]
extern crate tracing;
use std::path::PathBuf;
use std::str::FromStr;
use bitflags::bitflags;
use directories::ProjectDirs;
use miette::{miette, Context, IntoDiagnostic};
use miette::{miette, Context, IntoDiagnostic, NarratableReportHandler};
use smithay::input::keyboard::keysyms::KEY_NoSymbol;
use smithay::input::keyboard::xkb::{keysym_from_name, KEYSYM_CASE_INSENSITIVE};
use smithay::input::keyboard::{Keysym, XkbConfig};
@ -407,6 +410,10 @@ impl Default for DebugConfig {
impl Config {
pub fn load(path: Option<PathBuf>) -> miette::Result<(Self, PathBuf)> {
Self::load_internal(path).context("error loading config")
}
fn load_internal(path: Option<PathBuf>) -> miette::Result<(Self, PathBuf)> {
let path = if let Some(path) = path {
path
} else {
@ -436,7 +443,7 @@ impl Default for Config {
fn default() -> Self {
Config::parse(
"default-config.kdl",
include_str!("../resources/default-config.kdl"),
include_str!("../../resources/default-config.kdl"),
)
.unwrap()
}
@ -564,6 +571,10 @@ impl FromStr for SizeChange {
}
}
pub fn set_miette_hook() -> Result<(), miette::InstallError> {
miette::set_hook(Box::new(|_| Box::new(NarratableReportHandler::new())))
}
#[cfg(test)]
mod tests {
use miette::NarratableReportHandler;

View File

@ -9,6 +9,7 @@ use std::{io, mem};
use anyhow::{anyhow, Context};
use libc::dev_t;
use niri_config::Config;
use smithay::backend::allocator::dmabuf::{Dmabuf, DmabufAllocator};
use smithay::backend::allocator::gbm::{GbmAllocator, GbmBufferFlags, GbmDevice};
use smithay::backend::allocator::{Format, Fourcc};
@ -46,7 +47,6 @@ use wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_
use wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;
use super::RenderResult;
use crate::config::Config;
use crate::niri::{RedrawState, State};
use crate::render_helpers::AsGlesRenderer;
use crate::utils::get_monotonic_time;

View File

@ -5,6 +5,7 @@ use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use niri_config::Config;
use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::renderer::damage::OutputDamageTracker;
use smithay::backend::renderer::gles::GlesRenderer;
@ -18,7 +19,6 @@ use smithay::reexports::winit::window::WindowBuilder;
use smithay::utils::Transform;
use super::RenderResult;
use crate::config::Config;
use crate::niri::{RedrawState, State};
use crate::utils::get_monotonic_time;
use crate::Niri;

View File

@ -1,6 +1,7 @@
use std::any::Any;
use std::collections::HashSet;
use niri_config::{Action, Binds, LayoutAction, Modifiers};
use smithay::backend::input::{
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,
GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _,
@ -20,7 +21,6 @@ use smithay::utils::{Logical, Point, SERIAL_COUNTER};
use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint};
use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};
use crate::config::{Action, Binds, LayoutAction, Modifiers};
use crate::niri::State;
use crate::screenshot_ui::ScreenshotUi;
use crate::utils::{center, get_monotonic_time, spawn};
@ -1338,8 +1338,9 @@ fn allowed_during_screenshot(action: &Action) -> bool {
#[cfg(test)]
mod tests {
use niri_config::{Action, Bind, Binds, Key, Modifiers};
use super::*;
use crate::config::{Action, Bind, Binds, Key, Modifiers};
#[test]
fn bindings_suppress_keys() {

View File

@ -1,12 +1,11 @@
use std::iter::zip;
use arrayvec::ArrayVec;
use niri_config::{self, Color};
use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
use smithay::backend::renderer::element::Kind;
use smithay::utils::{Logical, Point, Scale, Size};
use crate::config::{self, Color};
#[derive(Debug)]
pub struct FocusRing {
buffers: [SolidColorBuffer; 4],
@ -21,7 +20,7 @@ pub struct FocusRing {
pub type FocusRingRenderElement = SolidColorRenderElement;
impl FocusRing {
pub fn new(config: config::FocusRing) -> Self {
pub fn new(config: niri_config::FocusRing) -> Self {
Self {
buffers: Default::default(),
locations: Default::default(),
@ -33,7 +32,7 @@ impl FocusRing {
}
}
pub fn update_config(&mut self, config: config::FocusRing) {
pub fn update_config(&mut self, config: niri_config::FocusRing) {
self.is_off = config.off;
self.width = config.width.into();
self.active_color = config.active_color;

View File

@ -33,6 +33,7 @@ use std::mem;
use std::rc::Rc;
use std::time::Duration;
use niri_config::{self, Config, SizeChange, Struts};
use smithay::backend::renderer::element::AsRenderElements;
use smithay::backend::renderer::{ImportAll, Renderer};
use smithay::desktop::space::SpaceElement;
@ -51,7 +52,6 @@ use self::workspace::{
compute_working_area, ColumnWidth, OutputId, Workspace, WorkspaceRenderElement,
};
use crate::animation::Animation;
use crate::config::{self, Config, SizeChange, Struts};
use crate::utils::output_size;
mod focus_ring;
@ -137,8 +137,8 @@ pub struct Options {
gaps: i32,
/// Extra padding around the working area in logical pixels.
struts: Struts,
focus_ring: config::FocusRing,
border: config::FocusRing,
focus_ring: niri_config::FocusRing,
border: niri_config::FocusRing,
/// Column widths that `toggle_width()` switches between.
preset_widths: Vec<ColumnWidth>,
/// Initial width for new columns.
@ -151,7 +151,7 @@ impl Default for Options {
gaps: 16,
struts: Default::default(),
focus_ring: Default::default(),
border: config::default_border(),
border: niri_config::default_border(),
preset_widths: vec![
ColumnWidth::Proportion(1. / 3.),
ColumnWidth::Proportion(0.5),

View File

@ -2,6 +2,7 @@ use std::cmp::min;
use std::rc::Rc;
use std::time::Duration;
use niri_config::SizeChange;
use smithay::backend::renderer::element::utils::{
CropRenderElement, Relocate, RelocateRenderElement,
};
@ -15,7 +16,6 @@ use super::workspace::{
};
use super::{LayoutElement, Options};
use crate::animation::Animation;
use crate::config::SizeChange;
use crate::utils::output_size;
#[derive(Debug)]

View File

@ -3,6 +3,7 @@ use std::iter::zip;
use std::rc::Rc;
use std::time::Duration;
use niri_config::{PresetWidth, SizeChange, Struts};
use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
use smithay::backend::renderer::element::utils::RelocateRenderElement;
use smithay::backend::renderer::{ImportAll, Renderer};
@ -17,7 +18,6 @@ use super::focus_ring::{FocusRing, FocusRingRenderElement};
use super::tile::Tile;
use super::{LayoutElement, Options};
use crate::animation::Animation;
use crate::config::{PresetWidth, SizeChange, Struts};
use crate::utils::output_size;
#[derive(Debug)]

View File

@ -3,7 +3,6 @@ extern crate tracing;
mod animation;
mod backend;
mod config;
mod cursor;
#[cfg(feature = "dbus")]
mod dbus;
@ -28,12 +27,11 @@ use std::process::Command;
use std::{env, mem};
use clap::{Parser, Subcommand};
use config::Config;
#[cfg(not(feature = "xdp-gnome-screencast"))]
use dummy_pw_utils as pw_utils;
use git_version::git_version;
use miette::{Context, NarratableReportHandler};
use niri::{Niri, State};
use niri_config::Config;
use portable_atomic::Ordering;
use sd_notify::NotifyState;
use smithay::reexports::calloop::{self, EventLoop};
@ -110,13 +108,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let _client = tracy_client::Client::start();
// Set a better error printer for config loading.
miette::set_hook(Box::new(|_| Box::new(NarratableReportHandler::new()))).unwrap();
niri_config::set_miette_hook().unwrap();
// Handle subcommands.
if let Some(subcommand) = cli.subcommand {
match subcommand {
Sub::Validate { config } => {
Config::load(config).context("error loading config")?;
Config::load(config)?;
info!("config is valid");
return Ok(());
}
@ -130,7 +128,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
);
// Load the config.
let (mut config, path) = match Config::load(cli.config).context("error loading config") {
let (mut config, path) = match Config::load(cli.config) {
Ok((config, path)) => (config, Some(path)),
Err(err) => {
warn!("{err:?}");

View File

@ -10,6 +10,7 @@ use std::{env, mem, thread};
use _server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as KdeDecorationsMode;
use anyhow::Context;
use niri_config::{Config, TrackLayout};
use smithay::backend::allocator::Fourcc;
use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
use smithay::backend::renderer::element::surface::{
@ -86,7 +87,6 @@ use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;
use crate::animation;
use crate::backend::tty::{SurfaceDmabufFeedback, TtyFrame, TtyRenderer, TtyRendererError};
use crate::backend::{Backend, RenderResult, Tty, Winit};
use crate::config::{Config, TrackLayout};
use crate::cursor::{CursorManager, CursorTextureCache, RenderCursor, XCursor};
#[cfg(feature = "dbus")]
use crate::dbus::gnome_shell_screenshot::{NiriToScreenshot, ScreenshotToNiri};

View File

@ -5,6 +5,7 @@ use std::mem;
use anyhow::Context;
use arrayvec::ArrayVec;
use niri_config::Action;
use smithay::backend::allocator::Fourcc;
use smithay::backend::input::{ButtonState, MouseButton};
use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
@ -18,7 +19,6 @@ use smithay::output::{Output, WeakOutput};
use smithay::utils::{Buffer, Physical, Point, Rectangle, Scale, Size, Transform};
use crate::backend::tty::{TtyFrame, TtyRenderer, TtyRendererError};
use crate::config::Action;
use crate::render_helpers::PrimaryGpuTextureRenderElement;
const BORDER: i32 = 2;

View File

@ -11,12 +11,11 @@ use std::time::Duration;
use anyhow::{ensure, Context};
use directories::UserDirs;
use niri_config::Config;
use smithay::output::Output;
use smithay::reexports::rustix::time::{clock_gettime, ClockId};
use smithay::utils::{Logical, Point, Rectangle, Size};
use crate::config::Config;
pub fn clone2<T: Clone, U: Clone>(t: (&T, &U)) -> (T, U) {
(t.0.clone(), t.1.clone())
}