Compare commits

...

7 Commits

Author SHA1 Message Date
Kiko
a89c800c7f
Merge branch 'YaLTeR:main' into main 2024-07-12 18:31:59 +00:00
K's Thinkpad
bb300b6290 fixed the problem with 0 alpha would cause information loss 2024-07-12 20:23:18 +02:00
Tglman
a5a34934df feat: add metadata for generate deb package with cargo deb 2024-07-12 16:58:30 +03:00
K's Thinkpad
f223b6d2a7 added tests for alpha in oklch longer 2024-07-12 14:23:23 +02:00
Kiko
4c80ab922f
Merge branch 'YaLTeR:main' into main 2024-07-12 11:50:06 +00:00
Ivan Molodetskikh
08a8a0f29a Update Cargo.lock 2024-07-12 10:44:02 +03:00
Oli Strik
519611c6c8
Add schemars::JsonSchema trait to ipc types (#536)
* feat: add schemars JsonSchema trait to ipc types

* niri-ipc: use feature-flag for deriving schemars::JsonSchema

---------

Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
2024-07-12 05:21:52 +00:00
9 changed files with 139 additions and 7 deletions

42
Cargo.lock generated
View File

@ -985,6 +985,12 @@ dependencies = [
"linux-raw-sys 0.6.4", "linux-raw-sys 0.6.4",
] ]
[[package]]
name = "dyn-clone"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125"
[[package]] [[package]]
name = "edid-rs" name = "edid-rs"
version = "0.1.0" version = "0.1.0"
@ -2294,6 +2300,7 @@ name = "niri-ipc"
version = "0.1.7" version = "0.1.7"
dependencies = [ dependencies = [
"clap", "clap",
"schemars",
"serde", "serde",
"serde_json", "serde_json",
] ]
@ -3307,6 +3314,30 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b53b0a5db882a8e2fdaae0a43f7b39e7e9082389e978398bdf223a55b581248" checksum = "0b53b0a5db882a8e2fdaae0a43f7b39e7e9082389e978398bdf223a55b581248"
[[package]]
name = "schemars"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92"
dependencies = [
"dyn-clone",
"schemars_derive",
"serde",
"serde_json",
]
[[package]]
name = "schemars_derive"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e"
dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals",
"syn 2.0.69",
]
[[package]] [[package]]
name = "scoped-tls" name = "scoped-tls"
version = "1.0.1" version = "1.0.1"
@ -3345,6 +3376,17 @@ dependencies = [
"syn 2.0.69", "syn 2.0.69",
] ]
[[package]]
name = "serde_derive_internals"
version = "0.29.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.69",
]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.120" version = "1.0.120"

View File

@ -141,3 +141,14 @@ assets = [
[package.metadata.generate-rpm.requires] [package.metadata.generate-rpm.requires]
alacritty = "*" alacritty = "*"
fuzzel = "*" fuzzel = "*"
[package.metadata.deb]
depends = "alacritty, fuzzel"
assets = [
["target/release/niri", "usr/bin/", "755"],
["resources/niri-session", "usr/bin/", "755"],
["resources/niri.desktop", "/usr/share/wayland-sessions/", "644"],
["resources/niri-portals.conf", "/usr/share/xdg-desktop-portal/", "644"],
["resources/niri.service", "/usr/lib/systemd/user/", "644"],
["resources/niri-shutdown.target", "/usr/lib/systemd/user/", "644"],
]

View File

@ -529,7 +529,8 @@ impl Color {
impl From<Color> for [f32; 4] { impl From<Color> for [f32; 4] {
fn from(c: Color) -> Self { fn from(c: Color) -> Self {
let [r, g, b, a] = [c.r, c.g, c.b, c.a].map(|x| x as f32 / 255.); let [r, g, b, a] = [c.r, c.g, c.b, c.a].map(|x| x as f32 / 255.);
[r * a, g * a, b * a, a] //[r * a, g * a, b * a, a]
[r, g, b, a]
} }
} }
@ -2853,6 +2854,10 @@ mod tests {
to: Color::new(0, 128, 255, 255), to: Color::new(0, 128, 255, 255),
angle: 180, angle: 180,
relative_to: GradientRelativeTo::WorkspaceView, relative_to: GradientRelativeTo::WorkspaceView,
in_ : GradientInterpolation {
color_space: GradientColorSpace::Srgb,
hue_interpol: HueInterpolation::Shorter,
}
}), }),
inactive_gradient: None, inactive_gradient: None,
}, },

View File

@ -9,8 +9,10 @@ repository.workspace = true
[dependencies] [dependencies]
clap = { workspace = true, optional = true } clap = { workspace = true, optional = true }
schemars = { version = "0.8.21", optional = true }
serde.workspace = true serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
[features] [features]
clap = ["dep:clap"] clap = ["dep:clap"]
json-schema = ["dep:schemars"]

View File

@ -11,6 +11,7 @@ pub use socket::{Socket, SOCKET_PATH_ENV};
/// Request from client to niri. /// Request from client to niri.
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum Request { pub enum Request {
/// Request the version string for the running niri instance. /// Request the version string for the running niri instance.
Version, Version,
@ -51,6 +52,7 @@ pub type Reply = Result<Response, String>;
/// Successful response from niri to client. /// Successful response from niri to client.
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum Response { pub enum Response {
/// A request that does not need a response was handled successfully. /// A request that does not need a response was handled successfully.
Handled, Handled,
@ -77,6 +79,7 @@ pub enum Response {
#[cfg_attr(feature = "clap", derive(clap::Parser))] #[cfg_attr(feature = "clap", derive(clap::Parser))]
#[cfg_attr(feature = "clap", command(subcommand_value_name = "ACTION"))] #[cfg_attr(feature = "clap", command(subcommand_value_name = "ACTION"))]
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))] #[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum Action { pub enum Action {
/// Exit niri. /// Exit niri.
Quit { Quit {
@ -278,6 +281,7 @@ pub enum Action {
/// Change in window or column size. /// Change in window or column size.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum SizeChange { pub enum SizeChange {
/// Set the size in logical pixels. /// Set the size in logical pixels.
SetFixed(i32), SetFixed(i32),
@ -291,6 +295,7 @@ pub enum SizeChange {
/// Workspace reference (index or name) to operate on. /// Workspace reference (index or name) to operate on.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum WorkspaceReferenceArg { pub enum WorkspaceReferenceArg {
/// Index of the workspace. /// Index of the workspace.
Index(u8), Index(u8),
@ -300,6 +305,7 @@ pub enum WorkspaceReferenceArg {
/// Layout to switch to. /// Layout to switch to.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum LayoutSwitchTarget { pub enum LayoutSwitchTarget {
/// The next configured layout. /// The next configured layout.
Next, Next,
@ -314,6 +320,7 @@ pub enum LayoutSwitchTarget {
#[cfg_attr(feature = "clap", derive(clap::Parser))] #[cfg_attr(feature = "clap", derive(clap::Parser))]
#[cfg_attr(feature = "clap", command(subcommand_value_name = "ACTION"))] #[cfg_attr(feature = "clap", command(subcommand_value_name = "ACTION"))]
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))] #[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum OutputAction { pub enum OutputAction {
/// Turn off the output. /// Turn off the output.
Off, Off,
@ -362,6 +369,7 @@ pub enum OutputAction {
/// Output mode to set. /// Output mode to set.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum ModeToSet { pub enum ModeToSet {
/// Niri will pick the mode automatically. /// Niri will pick the mode automatically.
Automatic, Automatic,
@ -371,6 +379,7 @@ pub enum ModeToSet {
/// Output mode as set in the config file. /// Output mode as set in the config file.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct ConfiguredMode { pub struct ConfiguredMode {
/// Width in physical pixels. /// Width in physical pixels.
pub width: u16, pub width: u16,
@ -382,6 +391,7 @@ pub struct ConfiguredMode {
/// Output scale to set. /// Output scale to set.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum ScaleToSet { pub enum ScaleToSet {
/// Niri will pick the scale automatically. /// Niri will pick the scale automatically.
Automatic, Automatic,
@ -394,6 +404,7 @@ pub enum ScaleToSet {
#[cfg_attr(feature = "clap", derive(clap::Subcommand))] #[cfg_attr(feature = "clap", derive(clap::Subcommand))]
#[cfg_attr(feature = "clap", command(subcommand_value_name = "POSITION"))] #[cfg_attr(feature = "clap", command(subcommand_value_name = "POSITION"))]
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Position Values"))] #[cfg_attr(feature = "clap", command(subcommand_help_heading = "Position Values"))]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum PositionToSet { pub enum PositionToSet {
/// Position the output automatically. /// Position the output automatically.
#[cfg_attr(feature = "clap", command(name = "auto"))] #[cfg_attr(feature = "clap", command(name = "auto"))]
@ -406,6 +417,7 @@ pub enum PositionToSet {
/// Output position as set in the config file. /// Output position as set in the config file.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "clap", derive(clap::Args))] #[cfg_attr(feature = "clap", derive(clap::Args))]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct ConfiguredPosition { pub struct ConfiguredPosition {
/// Logical X position. /// Logical X position.
pub x: i32, pub x: i32,
@ -415,6 +427,7 @@ pub struct ConfiguredPosition {
/// Connected output. /// Connected output.
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct Output { pub struct Output {
/// Name of the output. /// Name of the output.
pub name: String, pub name: String,
@ -442,6 +455,7 @@ pub struct Output {
/// Output mode. /// Output mode.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct Mode { pub struct Mode {
/// Width in physical pixels. /// Width in physical pixels.
pub width: u16, pub width: u16,
@ -455,6 +469,7 @@ pub struct Mode {
/// Logical output in the compositor's coordinate space. /// Logical output in the compositor's coordinate space.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct LogicalOutput { pub struct LogicalOutput {
/// Logical X position. /// Logical X position.
pub x: i32, pub x: i32,
@ -473,6 +488,7 @@ pub struct LogicalOutput {
/// Output transform, which goes counter-clockwise. /// Output transform, which goes counter-clockwise.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))] #[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum Transform { pub enum Transform {
/// Untransformed. /// Untransformed.
Normal, Normal,
@ -500,6 +516,7 @@ pub enum Transform {
/// Toplevel window. /// Toplevel window.
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct Window { pub struct Window {
/// Title, if set. /// Title, if set.
pub title: Option<String>, pub title: Option<String>,
@ -509,6 +526,7 @@ pub struct Window {
/// Output configuration change result. /// Output configuration change result.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum OutputConfigChanged { pub enum OutputConfigChanged {
/// The target output was connected and the change was applied. /// The target output was connected and the change was applied.
Applied, Applied,
@ -518,6 +536,7 @@ pub enum OutputConfigChanged {
/// A workspace. /// A workspace.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct Workspace { pub struct Workspace {
/// Index of the workspace on its monitor. /// Index of the workspace on its monitor.
/// ///

View File

@ -0,0 +1,51 @@
use niri::render_helpers::border::BorderRenderElement;
use niri_config::{CornerRadius, GradientInterpolation, HueInterpolation, GradientColorSpace};
use smithay::backend::renderer::element::RenderElement;
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::utils::{Logical, Physical, Rectangle, Size};
use super::TestCase;
pub struct GradientOklchAlpha {
gradient_format: GradientInterpolation,
}
impl GradientOklchAlpha {
pub fn new(_size: Size<i32, Logical>) -> Self {
Self {
gradient_format: GradientInterpolation{
color_space: GradientColorSpace::Oklch,
hue_interpol: HueInterpolation::Longer
}
}
}
}
impl TestCase for GradientOklchAlpha {
fn render(
&mut self,
_renderer: &mut GlesRenderer,
size: Size<i32, Physical>,
) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {
let (a, b) = (size.w / 6, size.h / 3);
let size = (size.w - a * 2, size.h - b * 2);
let area = Rectangle::from_loc_and_size((a, b), size).to_f64();
[BorderRenderElement::new(
area.size,
Rectangle::from_loc_and_size((0., 0.), area.size),
self.gradient_format,
[1., 0., 0., 1.],
[0., 1., 0., 0.],
0.,
Rectangle::from_loc_and_size((0., 0.), area.size),
0.,
CornerRadius::default(),
1.,
)
.with_location(area.loc)]
.into_iter()
.map(|elem| Box::new(elem) as _)
.collect()
}
}

View File

@ -13,6 +13,7 @@ pub mod gradient_oklch_shorter;
pub mod gradient_oklch_longer; pub mod gradient_oklch_longer;
pub mod gradient_oklch_increasing; pub mod gradient_oklch_increasing;
pub mod gradient_oklch_decreasing; pub mod gradient_oklch_decreasing;
pub mod gradient_oklch_alpha;
pub mod layout; pub mod layout;
pub mod tile; pub mod tile;
pub mod window; pub mod window;

View File

@ -5,6 +5,7 @@ use std::env;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use adw::prelude::{AdwApplicationWindowExt, NavigationPageExt}; use adw::prelude::{AdwApplicationWindowExt, NavigationPageExt};
use cases::gradient_oklch_alpha::GradientOklchAlpha;
use cases::tile::Tile; use cases::tile::Tile;
use cases::window::Window; use cases::window::Window;
use gtk::prelude::{ use gtk::prelude::{
@ -126,6 +127,7 @@ fn build_ui(app: &adw::Application) {
s.add(GradientOklchLonger::new, "Gradient - Oklch Longer"); s.add(GradientOklchLonger::new, "Gradient - Oklch Longer");
s.add(GradientOklchIncreasing::new, "Gradient - Oklch Increasing"); s.add(GradientOklchIncreasing::new, "Gradient - Oklch Increasing");
s.add(GradientOklchDecreasing::new, "Gradient - Oklch Decreasing"); s.add(GradientOklchDecreasing::new, "Gradient - Oklch Decreasing");
s.add(GradientOklchAlpha::new, "Gradient - Alpha");
let content_headerbar = adw::HeaderBar::new(); let content_headerbar = adw::HeaderBar::new();

View File

@ -98,16 +98,15 @@ vec3 oklab_to_linear(vec3 color){
vec4 color_mix(vec4 color1, vec4 color2, float color_ratio) { vec4 color_mix(vec4 color1, vec4 color2, float color_ratio) {
// srgb // srgb
vec4 color_out;
if (colorspace == 0.0) { if (colorspace == 0.0) {
return mix(color1, color2, color_ratio); color_out = mix(color1, color2, color_ratio);
color_out.rgb = color_out.rgb * color_out.a;
return color_out;
} }
vec4 color_out;
color1.rgb /= color1.a != 0.0 ? color1.a : 1.0;
color2.rgb /= color2.a != 0.0 ? color2.a : 1.0;
color1.rgb = vec3( color1.rgb = vec3(
srgb_to_linear(color1.r), srgb_to_linear(color1.r),
srgb_to_linear(color1.g), srgb_to_linear(color1.g),