diff --git a/docs/wiki/Configuration:-Outputs.md b/docs/wiki/Configuration:-Outputs.md
index b2b394bd..ecdee105 100644
--- a/docs/wiki/Configuration:-Outputs.md
+++ b/docs/wiki/Configuration:-Outputs.md
@@ -27,6 +27,10 @@ output "eDP-1" {
layout {
// ...layout settings for eDP-1...
}
+
+ // Custom modes. Caution: may damage your display.
+ // mode custom=true "1920x1080@100"
+ // modeline 173.00 1920 2048 2248 2576 1080 1083 1088 1120 "-hsync" "+vsync"
}
output "HDMI-A-1" {
@@ -86,6 +90,42 @@ output "eDP-1" {
}
```
+#### `mode custom=true`
+
+Since: next release
+
+You can configure a custom mode (not offered by the monitor) by setting `custom=true`.
+In this case, the refresh rate is mandatory.
+
+> [!CAUTION]
+> Custom modes may damage your monitor, especially if it's a CRT.
+> Follow the maximum supported limits in your monitor's instructions.
+
+```kdl
+// Use a custom mode for this display.
+output "HDMI-A-1" {
+ mode custom=true "2560x1440@143.912"
+}
+```
+
+### `modeline`
+
+Since: next release
+
+Directly configures the monitor's mode via a modeline, overriding any configured `mode`.
+The modeline can be calculated via utilities such as [cvt](https://man.archlinux.org/man/cvt.1.en) or [gtf](https://man.archlinux.org/man/gtf.1.en).
+
+> [!CAUTION]
+> Out of spec modelines may damage your monitor, especially if it's a CRT.
+> Follow the maximum supported limits in your monitor's instructions.
+
+```kdl
+// Use a modeline for this display.
+output "eDP-3" {
+ modeline 173.00 1920 2048 2248 2576 1080 1083 1088 1120 "-hsync" "+vsync"
+}
+```
+
### `scale`
Set the scale of the monitor.
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs
index e939f0c3..dda7dfd6 100644
--- a/niri-config/src/lib.rs
+++ b/niri-config/src/lib.rs
@@ -663,6 +663,14 @@ mod tests {
}
}
+ output "eDP-2" {
+ mode custom=true "1920x1080@144"
+ }
+
+ output "eDP-3" {
+ modeline 173.00 1920 2048 2248 2576 1080 1083 1088 1120 "-hsync" "+vsync"
+ }
+
layout {
focus-ring {
width 5
@@ -1035,14 +1043,18 @@ mod tests {
},
),
mode: Some(
- ConfiguredMode {
- width: 1920,
- height: 1080,
- refresh: Some(
- 144.0,
- ),
+ Mode {
+ custom: false,
+ mode: ConfiguredMode {
+ width: 1920,
+ height: 1080,
+ refresh: Some(
+ 144.0,
+ ),
+ },
},
),
+ modeline: None,
variable_refresh_rate: Some(
Vrr {
on_demand: true,
@@ -1069,6 +1081,61 @@ mod tests {
),
layout: None,
},
+ Output {
+ off: false,
+ name: "eDP-2",
+ scale: None,
+ transform: Normal,
+ position: None,
+ mode: Some(
+ Mode {
+ custom: true,
+ mode: ConfiguredMode {
+ width: 1920,
+ height: 1080,
+ refresh: Some(
+ 144.0,
+ ),
+ },
+ },
+ ),
+ modeline: None,
+ variable_refresh_rate: None,
+ focus_at_startup: false,
+ background_color: None,
+ backdrop_color: None,
+ hot_corners: None,
+ layout: None,
+ },
+ Output {
+ off: false,
+ name: "eDP-3",
+ scale: None,
+ transform: Normal,
+ position: None,
+ mode: None,
+ modeline: Some(
+ Modeline {
+ clock: 173.0,
+ hdisplay: 1920,
+ hsync_start: 2048,
+ hsync_end: 2248,
+ htotal: 2576,
+ vdisplay: 1080,
+ vsync_start: 1083,
+ vsync_end: 1088,
+ vtotal: 1120,
+ hsync_polarity: NHSync,
+ vsync_polarity: PVSync,
+ },
+ ),
+ variable_refresh_rate: None,
+ focus_at_startup: false,
+ background_color: None,
+ backdrop_color: None,
+ hot_corners: None,
+ layout: None,
+ },
],
),
spawn_at_startup: [
diff --git a/niri-config/src/output.rs b/niri-config/src/output.rs
index 62c14705..5d6565f5 100644
--- a/niri-config/src/output.rs
+++ b/niri-config/src/output.rs
@@ -1,4 +1,11 @@
-use niri_ipc::{ConfiguredMode, Transform};
+use std::str::FromStr;
+
+use knuffel::ast::SpannedNode;
+use knuffel::decode::Context;
+use knuffel::errors::DecodeError;
+use knuffel::traits::ErrorSpan;
+use knuffel::Decode;
+use niri_ipc::{ConfiguredMode, HSyncPolarity, Transform, VSyncPolarity};
use crate::gestures::HotCorners;
use crate::{Color, FloatOrInt, LayoutPart};
@@ -6,6 +13,40 @@ use crate::{Color, FloatOrInt, LayoutPart};
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Outputs(pub Vec