Use libdisplay-info for make/model/serial parsing, implement throughout
Browse files at this commitf0157e03e72714264e684295fac226e2046f0b38Parent: 4b7c16b22 changed files +528 -197
- .github/workflows/ci.yml +5 -5
- Cargo.lock +31 -0
- Cargo.toml +1 -0
- niri-config/src/lib.rs +161 -6
- niri-ipc/src/lib.rs +3 -1
- niri-visual-tests/src/cases/layout.rs +7 -1
- niri.spec.rpkg +1 -0
- src/backend/mod.rs +8 -0
- src/backend/tty.rs +103 -100
- src/backend/winit.rs +9 -1
- src/dbus/mutter_display_config.rs +61 -20
- src/handlers/xdg_shell.rs +7 -2
- src/ipc/client.rs +7 -5
- src/ipc/server.rs +2 -1
- src/layout/mod.rs +21 -13
- src/layout/workspace.rs +20 -5
- src/niri.rs +48 -27
- src/protocols/output_management.rs +13 -5
- src/utils/mod.rs +6 -1
- wiki/Configuration:-Named-Workspaces.md +1 -1
- wiki/Configuration:-Outputs.md +10 -2
- wiki/Configuration:-Window-Rules.md +3 -1
.github/workflows/ci.ymlmodified+5 -5
| @@ -34,7 +34,7 @@ jobs: | |||
| 34 | - name: Install dependencies | 34 | - name: Install dependencies |
| 35 | run: | | 35 | run: | |
| 36 | apt-get update -y | 36 | apt-get update -y |
| 37 | - apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev | 37 | + apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev libdisplay-info-dev |
| 38 | 38 | ||
| 39 | - uses: dtolnay/rust-toolchain@stable | 39 | - uses: dtolnay/rust-toolchain@stable |
| 40 | 40 | ||
| @@ -85,7 +85,7 @@ jobs: | |||
| 85 | - name: Install dependencies | 85 | - name: Install dependencies |
| 86 | run: | | 86 | run: | |
| 87 | apt-get update -y | 87 | apt-get update -y |
| 88 | - apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev libadwaita-1-dev | 88 | + apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev libadwaita-1-dev libdisplay-info-dev |
| 89 | 89 | ||
| 90 | - uses: dtolnay/rust-toolchain@stable | 90 | - uses: dtolnay/rust-toolchain@stable |
| 91 | 91 | ||
| @@ -110,7 +110,7 @@ jobs: | |||
| 110 | - name: Install dependencies | 110 | - name: Install dependencies |
| 111 | run: | | 111 | run: | |
| 112 | apt-get update -y | 112 | apt-get update -y |
| 113 | - apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev libadwaita-1-dev | 113 | + apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev libadwaita-1-dev libdisplay-info-dev |
| 114 | 114 | ||
| 115 | - uses: dtolnay/rust-toolchain@1.77.0 | 115 | - uses: dtolnay/rust-toolchain@1.77.0 |
| 116 | 116 | ||
| @@ -134,7 +134,7 @@ jobs: | |||
| 134 | - name: Install dependencies | 134 | - name: Install dependencies |
| 135 | run: | | 135 | run: | |
| 136 | apt-get update -y | 136 | apt-get update -y |
| 137 | - apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev libadwaita-1-dev | 137 | + apt-get install -y curl gcc clang libudev-dev libgbm-dev libxkbcommon-dev libegl1-mesa-dev libwayland-dev libinput-dev libdbus-1-dev libsystemd-dev libseat-dev libpipewire-0.3-dev libpango1.0-dev libadwaita-1-dev libdisplay-info-dev |
| 138 | 138 | ||
| 139 | - uses: dtolnay/rust-toolchain@stable | 139 | - uses: dtolnay/rust-toolchain@stable |
| 140 | with: | 140 | with: |
| @@ -172,7 +172,7 @@ jobs: | |||
| 172 | - name: Install dependencies | 172 | - name: Install dependencies |
| 173 | run: | | 173 | run: | |
| 174 | sudo dnf update -y | 174 | sudo dnf update -y |
| 175 | - sudo dnf install -y cargo gcc libudev-devel libgbm-devel libxkbcommon-devel wayland-devel libinput-devel dbus-devel systemd-devel libseat-devel pipewire-devel pango-devel cairo-gobject-devel clang libadwaita-devel | 175 | + sudo dnf install -y cargo gcc libudev-devel libgbm-devel libxkbcommon-devel wayland-devel libinput-devel dbus-devel systemd-devel libseat-devel pipewire-devel pango-devel cairo-gobject-devel clang libadwaita-devel libdisplay-info-devel |
| 176 | 176 | ||
| 177 | - uses: Swatinem/rust-cache@v2 | 177 | - uses: Swatinem/rust-cache@v2 |
| 178 | - run: cargo build --all | 178 | - run: cargo build --all |
Cargo.lockmodified+31 -0
| @@ -1942,6 +1942,36 @@ version = "0.2.155" | |||
| 1942 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1942 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1943 | checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" | 1943 | checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" |
| 1944 | 1944 | ||
| 1945 | +[[package]] | ||
| 1946 | +name = "libdisplay-info" | ||
| 1947 | +version = "0.1.0" | ||
| 1948 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1949 | +checksum = "bb6dd47a677df2378a8bb88d08a593f51e8dddf4b61d2db5f2ceb35e67f9389d" | ||
| 1950 | +dependencies = [ | ||
| 1951 | + "bitflags 2.6.0", | ||
| 1952 | + "libc", | ||
| 1953 | + "libdisplay-info-derive", | ||
| 1954 | + "libdisplay-info-sys", | ||
| 1955 | + "thiserror", | ||
| 1956 | +] | ||
| 1957 | + | ||
| 1958 | +[[package]] | ||
| 1959 | +name = "libdisplay-info-derive" | ||
| 1960 | +version = "0.1.0" | ||
| 1961 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1962 | +checksum = "ea1cd31036b732a546d845f9485c56b1b606b5e476b0821c680dd66c8cd6fcee" | ||
| 1963 | +dependencies = [ | ||
| 1964 | + "proc-macro2", | ||
| 1965 | + "quote", | ||
| 1966 | + "syn 2.0.72", | ||
| 1967 | +] | ||
| 1968 | + | ||
| 1969 | +[[package]] | ||
| 1970 | +name = "libdisplay-info-sys" | ||
| 1971 | +version = "0.1.0" | ||
| 1972 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1973 | +checksum = "ea8cec1fa7872b621f40c756bc1304b1a975461282e250b0e76737b037c0c236" | ||
| 1974 | + | ||
| 1945 | [[package]] | 1975 | [[package]] |
| 1946 | name = "libloading" | 1976 | name = "libloading" |
| 1947 | version = "0.8.5" | 1977 | version = "0.8.5" |
| @@ -2238,6 +2268,7 @@ dependencies = [ | |||
| 2238 | "k9", | 2268 | "k9", |
| 2239 | "keyframe", | 2269 | "keyframe", |
| 2240 | "libc", | 2270 | "libc", |
| 2271 | + "libdisplay-info", | ||
| 2241 | "log", | 2272 | "log", |
| 2242 | "niri-config", | 2273 | "niri-config", |
| 2243 | "niri-ipc", | 2274 | "niri-ipc", |
Cargo.tomlmodified+1 -0
| @@ -59,6 +59,7 @@ glam = "0.28.0" | |||
| 59 | input = { version = "0.9.0", features = ["libinput_1_21"] } | 59 | input = { version = "0.9.0", features = ["libinput_1_21"] } |
| 60 | keyframe = { version = "1.1.1", default-features = false } | 60 | keyframe = { version = "1.1.1", default-features = false } |
| 61 | libc = "0.2.155" | 61 | libc = "0.2.155" |
| 62 | +libdisplay-info = "0.1.0" | ||
| 62 | log = { version = "0.4.22", features = ["max_level_trace", "release_max_level_debug"] } | 63 | log = { version = "0.4.22", features = ["max_level_trace", "release_max_level_debug"] } |
| 63 | niri-config = { version = "0.1.8", path = "niri-config" } | 64 | niri-config = { version = "0.1.8", path = "niri-config" } |
| 64 | niri-ipc = { version = "0.1.8", path = "niri-ipc", features = ["clap"] } | 65 | niri-ipc = { version = "0.1.8", path = "niri-ipc", features = ["clap"] } |
niri-config/src/lib.rsmodified+161 -6
| @@ -359,6 +359,14 @@ impl Default for Output { | |||
| 359 | } | 359 | } |
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | +#[derive(Debug, Clone)] | ||
| 363 | +pub struct OutputName { | ||
| 364 | + pub connector: String, | ||
| 365 | + pub make: Option<String>, | ||
| 366 | + pub model: Option<String>, | ||
| 367 | + pub serial: Option<String>, | ||
| 368 | +} | ||
| 369 | + | ||
| 362 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq, Eq)] | 370 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq, Eq)] |
| 363 | pub struct Position { | 371 | pub struct Position { |
| 364 | #[knuffel(property)] | 372 | #[knuffel(property)] |
| @@ -1720,14 +1728,95 @@ impl FromIterator<Output> for Outputs { | |||
| 1720 | } | 1728 | } |
| 1721 | 1729 | ||
| 1722 | impl Outputs { | 1730 | impl Outputs { |
| 1723 | - pub fn find(&self, name: &str) -> Option<&Output> { | 1731 | + pub fn find(&self, name: &OutputName) -> Option<&Output> { |
| 1724 | - self.0.iter().find(|o| o.name.eq_ignore_ascii_case(name)) | 1732 | + self.0.iter().find(|o| name.matches(&o.name)) |
| 1725 | } | 1733 | } |
| 1726 | 1734 | ||
| 1727 | - pub fn find_mut(&mut self, name: &str) -> Option<&mut Output> { | 1735 | + pub fn find_mut(&mut self, name: &OutputName) -> Option<&mut Output> { |
| 1728 | - self.0 | 1736 | + self.0.iter_mut().find(|o| name.matches(&o.name)) |
| 1729 | - .iter_mut() | 1737 | + } |
| 1730 | - .find(|o| o.name.eq_ignore_ascii_case(name)) | 1738 | +} |
| 1739 | + | ||
| 1740 | +impl OutputName { | ||
| 1741 | + pub fn from_ipc_output(output: &niri_ipc::Output) -> Self { | ||
| 1742 | + Self { | ||
| 1743 | + connector: output.name.clone(), | ||
| 1744 | + make: (output.make != "Unknown").then(|| output.make.clone()), | ||
| 1745 | + model: (output.model != "Unknown").then(|| output.model.clone()), | ||
| 1746 | + serial: output.serial.clone(), | ||
| 1747 | + } | ||
| 1748 | + } | ||
| 1749 | + | ||
| 1750 | + /// Returns an output description matching what Smithay's `Output::new()` does. | ||
| 1751 | + pub fn format_description(&self) -> String { | ||
| 1752 | + format!( | ||
| 1753 | + "{} - {} - {}", | ||
| 1754 | + self.make.as_deref().unwrap_or("Unknown"), | ||
| 1755 | + self.model.as_deref().unwrap_or("Unknown"), | ||
| 1756 | + self.connector, | ||
| 1757 | + ) | ||
| 1758 | + } | ||
| 1759 | + | ||
| 1760 | + /// Returns an output name that will match by make/model/serial or, if they are missing, by | ||
| 1761 | + /// connector. | ||
| 1762 | + pub fn format_make_model_serial_or_connector(&self) -> String { | ||
| 1763 | + if self.make.is_none() && self.model.is_none() && self.serial.is_none() { | ||
| 1764 | + self.connector.to_string() | ||
| 1765 | + } else { | ||
| 1766 | + let make = self.make.as_deref().unwrap_or("Unknown"); | ||
| 1767 | + let model = self.model.as_deref().unwrap_or("Unknown"); | ||
| 1768 | + let serial = self.serial.as_deref().unwrap_or("Unknown"); | ||
| 1769 | + format!("{make} {model} {serial}") | ||
| 1770 | + } | ||
| 1771 | + } | ||
| 1772 | + | ||
| 1773 | + pub fn matches(&self, target: &str) -> bool { | ||
| 1774 | + // Match by connector. | ||
| 1775 | + if target.eq_ignore_ascii_case(&self.connector) { | ||
| 1776 | + return true; | ||
| 1777 | + } | ||
| 1778 | + | ||
| 1779 | + // If no other fields are available, don't try to match by them. | ||
| 1780 | + // | ||
| 1781 | + // This is used by niri msg output. | ||
| 1782 | + if self.make.is_none() && self.model.is_none() && self.serial.is_none() { | ||
| 1783 | + return false; | ||
| 1784 | + } | ||
| 1785 | + | ||
| 1786 | + // Match by "make model serial" with Unknown if something is missing. | ||
| 1787 | + let make = self.make.as_deref().unwrap_or("Unknown"); | ||
| 1788 | + let model = self.model.as_deref().unwrap_or("Unknown"); | ||
| 1789 | + let serial = self.serial.as_deref().unwrap_or("Unknown"); | ||
| 1790 | + | ||
| 1791 | + let Some(target_make) = target.get(..make.len()) else { | ||
| 1792 | + return false; | ||
| 1793 | + }; | ||
| 1794 | + let rest = &target[make.len()..]; | ||
| 1795 | + if !target_make.eq_ignore_ascii_case(make) { | ||
| 1796 | + return false; | ||
| 1797 | + } | ||
| 1798 | + if !rest.starts_with(' ') { | ||
| 1799 | + return false; | ||
| 1800 | + } | ||
| 1801 | + let rest = &rest[1..]; | ||
| 1802 | + | ||
| 1803 | + let Some(target_model) = rest.get(..model.len()) else { | ||
| 1804 | + return false; | ||
| 1805 | + }; | ||
| 1806 | + let rest = &rest[model.len()..]; | ||
| 1807 | + if !target_model.eq_ignore_ascii_case(model) { | ||
| 1808 | + return false; | ||
| 1809 | + } | ||
| 1810 | + if !rest.starts_with(' ') { | ||
| 1811 | + return false; | ||
| 1812 | + } | ||
| 1813 | + | ||
| 1814 | + let rest = &rest[1..]; | ||
| 1815 | + if !rest.eq_ignore_ascii_case(serial) { | ||
| 1816 | + return false; | ||
| 1817 | + } | ||
| 1818 | + | ||
| 1819 | + true | ||
| 1731 | } | 1820 | } |
| 1732 | } | 1821 | } |
| 1733 | 1822 | ||
| @@ -3351,4 +3440,70 @@ mod tests { | |||
| 3351 | assert_eq!(config.input.keyboard.repeat_delay, 600); | 3440 | assert_eq!(config.input.keyboard.repeat_delay, 600); |
| 3352 | assert_eq!(config.input.keyboard.repeat_rate, 25); | 3441 | assert_eq!(config.input.keyboard.repeat_rate, 25); |
| 3353 | } | 3442 | } |
| 3443 | + | ||
| 3444 | + #[test] | ||
| 3445 | + fn test_output_name_match() { | ||
| 3446 | + fn check( | ||
| 3447 | + target: &str, | ||
| 3448 | + connector: &str, | ||
| 3449 | + make: Option<&str>, | ||
| 3450 | + model: Option<&str>, | ||
| 3451 | + serial: Option<&str>, | ||
| 3452 | + ) -> bool { | ||
| 3453 | + let name = OutputName { | ||
| 3454 | + connector: connector.to_string(), | ||
| 3455 | + make: make.map(|x| x.to_string()), | ||
| 3456 | + model: model.map(|x| x.to_string()), | ||
| 3457 | + serial: serial.map(|x| x.to_string()), | ||
| 3458 | + }; | ||
| 3459 | + name.matches(target) | ||
| 3460 | + } | ||
| 3461 | + | ||
| 3462 | + assert!(check("dp-2", "DP-2", None, None, None)); | ||
| 3463 | + assert!(!check("dp-1", "DP-2", None, None, None)); | ||
| 3464 | + assert!(check("dp-2", "DP-2", Some("a"), Some("b"), Some("c"))); | ||
| 3465 | + assert!(check( | ||
| 3466 | + "some company some monitor 1234", | ||
| 3467 | + "DP-2", | ||
| 3468 | + Some("Some Company"), | ||
| 3469 | + Some("Some Monitor"), | ||
| 3470 | + Some("1234") | ||
| 3471 | + )); | ||
| 3472 | + assert!(!check( | ||
| 3473 | + "some other company some monitor 1234", | ||
| 3474 | + "DP-2", | ||
| 3475 | + Some("Some Company"), | ||
| 3476 | + Some("Some Monitor"), | ||
| 3477 | + Some("1234") | ||
| 3478 | + )); | ||
| 3479 | + assert!(!check( | ||
| 3480 | + "make model serial ", | ||
| 3481 | + "DP-2", | ||
| 3482 | + Some("make"), | ||
| 3483 | + Some("model"), | ||
| 3484 | + Some("serial") | ||
| 3485 | + )); | ||
| 3486 | + assert!(check( | ||
| 3487 | + "make serial", | ||
| 3488 | + "DP-2", | ||
| 3489 | + Some("make"), | ||
| 3490 | + Some(""), | ||
| 3491 | + Some("serial") | ||
| 3492 | + )); | ||
| 3493 | + assert!(check( | ||
| 3494 | + "make model unknown", | ||
| 3495 | + "DP-2", | ||
| 3496 | + Some("Make"), | ||
| 3497 | + Some("Model"), | ||
| 3498 | + None | ||
| 3499 | + )); | ||
| 3500 | + assert!(check( | ||
| 3501 | + "unknown unknown serial", | ||
| 3502 | + "DP-2", | ||
| 3503 | + None, | ||
| 3504 | + None, | ||
| 3505 | + Some("Serial") | ||
| 3506 | + )); | ||
| 3507 | + assert!(!check("unknown unknown unknown", "DP-2", None, None, None)); | ||
| 3508 | + } | ||
| 3354 | } | 3509 | } |
niri-ipc/src/lib.rsmodified+3 -1
| @@ -71,7 +71,7 @@ pub enum Response { | |||
| 71 | Version(String), | 71 | Version(String), |
| 72 | /// Information about connected outputs. | 72 | /// Information about connected outputs. |
| 73 | /// | 73 | /// |
| 74 | - /// Map from connector name to output info. | 74 | + /// Map from output name to output info. |
| 75 | Outputs(HashMap<String, Output>), | 75 | Outputs(HashMap<String, Output>), |
| 76 | /// Information about workspaces. | 76 | /// Information about workspaces. |
| 77 | Workspaces(Vec<Workspace>), | 77 | Workspaces(Vec<Workspace>), |
| @@ -466,6 +466,8 @@ pub struct Output { | |||
| 466 | pub make: String, | 466 | pub make: String, |
| 467 | /// Textual description of the model. | 467 | /// Textual description of the model. |
| 468 | pub model: String, | 468 | pub model: String, |
| 469 | + /// Serial of the output, if known. | ||
| 470 | + pub serial: Option<String>, | ||
| 469 | /// Physical width and height of the output in millimeters, if known. | 471 | /// Physical width and height of the output in millimeters, if known. |
| 470 | pub physical_size: Option<(u32, u32)>, | 472 | pub physical_size: Option<(u32, u32)>, |
| 471 | /// Available modes for the output. | 473 | /// Available modes for the output. |
niri-visual-tests/src/cases/layout.rsmodified+7 -1
| @@ -5,7 +5,7 @@ use niri::layout::workspace::ColumnWidth; | |||
| 5 | use niri::layout::{LayoutElement as _, Options}; | 5 | use niri::layout::{LayoutElement as _, Options}; |
| 6 | use niri::render_helpers::RenderTarget; | 6 | use niri::render_helpers::RenderTarget; |
| 7 | use niri::utils::get_monotonic_time; | 7 | use niri::utils::get_monotonic_time; |
| 8 | -use niri_config::{Color, FloatOrInt}; | 8 | +use niri_config::{Color, FloatOrInt, OutputName}; |
| 9 | use smithay::backend::renderer::element::RenderElement; | 9 | use smithay::backend::renderer::element::RenderElement; |
| 10 | use smithay::backend::renderer::gles::GlesRenderer; | 10 | use smithay::backend::renderer::gles::GlesRenderer; |
| 11 | use smithay::desktop::layer_map_for_output; | 11 | use smithay::desktop::layer_map_for_output; |
| @@ -41,6 +41,12 @@ impl Layout { | |||
| 41 | refresh: 60000, | 41 | refresh: 60000, |
| 42 | }); | 42 | }); |
| 43 | output.change_current_state(mode, None, None, None); | 43 | output.change_current_state(mode, None, None, None); |
| 44 | + output.user_data().insert_if_missing(|| OutputName { | ||
| 45 | + connector: String::new(), | ||
| 46 | + make: None, | ||
| 47 | + model: None, | ||
| 48 | + serial: None, | ||
| 49 | + }); | ||
| 44 | 50 | ||
| 45 | let options = Options { | 51 | let options = Options { |
| 46 | focus_ring: niri_config::FocusRing { | 52 | focus_ring: niri_config::FocusRing { |
niri.spec.rpkgmodified+1 -0
| @@ -68,6 +68,7 @@ BuildRequires: pkgconfig(libinput) | |||
| 68 | BuildRequires: pkgconfig(dbus-1) | 68 | BuildRequires: pkgconfig(dbus-1) |
| 69 | BuildRequires: pkgconfig(systemd) | 69 | BuildRequires: pkgconfig(systemd) |
| 70 | BuildRequires: pkgconfig(libseat) | 70 | BuildRequires: pkgconfig(libseat) |
| 71 | +BuildRequires: pkgconfig(libdisplay-info) | ||
| 71 | BuildRequires: pipewire-devel | 72 | BuildRequires: pipewire-devel |
| 72 | BuildRequires: pango-devel | 73 | BuildRequires: pango-devel |
| 73 | BuildRequires: cairo-gobject-devel | 74 | BuildRequires: cairo-gobject-devel |
src/backend/mod.rsmodified+8 -0
| @@ -174,6 +174,14 @@ impl Backend { | |||
| 174 | } | 174 | } |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | + pub fn tty_checked(&mut self) -> Option<&mut Tty> { | ||
| 178 | + if let Self::Tty(v) = self { | ||
| 179 | + Some(v) | ||
| 180 | + } else { | ||
| 181 | + None | ||
| 182 | + } | ||
| 183 | + } | ||
| 184 | + | ||
| 177 | pub fn tty(&mut self) -> &mut Tty { | 185 | pub fn tty(&mut self) -> &mut Tty { |
| 178 | if let Self::Tty(v) = self { | 186 | if let Self::Tty(v) = self { |
| 179 | v | 187 | v |
src/backend/tty.rsmodified+103 -100
| @@ -4,7 +4,6 @@ use std::fmt::Write; | |||
| 4 | use std::iter::zip; | 4 | use std::iter::zip; |
| 5 | use std::num::NonZeroU64; | 5 | use std::num::NonZeroU64; |
| 6 | use std::os::fd::AsFd; | 6 | use std::os::fd::AsFd; |
| 7 | -use std::panic::{catch_unwind, AssertUnwindSafe}; | ||
| 8 | use std::path::Path; | 7 | use std::path::Path; |
| 9 | use std::rc::Rc; | 8 | use std::rc::Rc; |
| 10 | use std::sync::{Arc, Mutex}; | 9 | use std::sync::{Arc, Mutex}; |
| @@ -14,7 +13,7 @@ use std::{io, mem}; | |||
| 14 | use anyhow::{anyhow, bail, ensure, Context}; | 13 | use anyhow::{anyhow, bail, ensure, Context}; |
| 15 | use bytemuck::cast_slice_mut; | 14 | use bytemuck::cast_slice_mut; |
| 16 | use libc::dev_t; | 15 | use libc::dev_t; |
| 17 | -use niri_config::Config; | 16 | +use niri_config::{Config, OutputName}; |
| 18 | use smithay::backend::allocator::dmabuf::Dmabuf; | 17 | use smithay::backend::allocator::dmabuf::Dmabuf; |
| 19 | use smithay::backend::allocator::format::FormatSet; | 18 | use smithay::backend::allocator::format::FormatSet; |
| 20 | use smithay::backend::allocator::gbm::{GbmAllocator, GbmBufferFlags, GbmDevice}; | 19 | use smithay::backend::allocator::gbm::{GbmAllocator, GbmBufferFlags, GbmDevice}; |
| @@ -52,7 +51,6 @@ use smithay::wayland::drm_lease::{ | |||
| 52 | DrmLease, DrmLeaseBuilder, DrmLeaseRequest, DrmLeaseState, LeaseRejected, | 51 | DrmLease, DrmLeaseBuilder, DrmLeaseRequest, DrmLeaseState, LeaseRejected, |
| 53 | }; | 52 | }; |
| 54 | use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner}; | 53 | use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner}; |
| 55 | -use smithay_drm_extras::edid::EdidInfo; | ||
| 56 | use wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1::TrancheFlags; | 54 | use wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1::TrancheFlags; |
| 57 | use wayland_protocols::wp::presentation_time::server::wp_presentation_feedback; | 55 | use wayland_protocols::wp::presentation_time::server::wp_presentation_feedback; |
| 58 | 56 | ||
| @@ -178,7 +176,7 @@ struct TtyOutputState { | |||
| 178 | } | 176 | } |
| 179 | 177 | ||
| 180 | struct Surface { | 178 | struct Surface { |
| 181 | - name: String, | 179 | + name: OutputName, |
| 182 | compositor: GbmDrmCompositor, | 180 | compositor: GbmDrmCompositor, |
| 183 | connector: connector::Handle, | 181 | connector: connector::Handle, |
| 184 | dmabuf_feedback: Option<SurfaceDmabufFeedback>, | 182 | dmabuf_feedback: Option<SurfaceDmabufFeedback>, |
| @@ -440,7 +438,7 @@ impl Tty { | |||
| 440 | continue; | 438 | continue; |
| 441 | }; | 439 | }; |
| 442 | let Some(output_state) = niri.output_state.get_mut(&output) else { | 440 | let Some(output_state) = niri.output_state.get_mut(&output) else { |
| 443 | - error!("missing state for output {:?}", surface.name); | 441 | + error!("missing state for output {:?}", surface.name.connector); |
| 444 | continue; | 442 | continue; |
| 445 | }; | 443 | }; |
| 446 | 444 | ||
| @@ -746,26 +744,22 @@ impl Tty { | |||
| 746 | connector: connector::Info, | 744 | connector: connector::Info, |
| 747 | crtc: crtc::Handle, | 745 | crtc: crtc::Handle, |
| 748 | ) -> anyhow::Result<()> { | 746 | ) -> anyhow::Result<()> { |
| 749 | - let output_name = format!( | 747 | + let connector_name = format_connector_name(&connector); |
| 750 | - "{}-{}", | 748 | + debug!("connecting connector: {connector_name}"); |
| 751 | - connector.interface().as_str(), | ||
| 752 | - connector.interface_id(), | ||
| 753 | - ); | ||
| 754 | - debug!("connecting connector: {output_name}"); | ||
| 755 | 749 | ||
| 756 | let device = self.devices.get_mut(&node).context("missing device")?; | 750 | let device = self.devices.get_mut(&node).context("missing device")?; |
| 757 | 751 | ||
| 752 | + let output_name = make_output_name(&device.drm, connector.handle(), connector_name.clone()); | ||
| 753 | + | ||
| 758 | let non_desktop = find_drm_property(&device.drm, connector.handle(), "non-desktop") | 754 | let non_desktop = find_drm_property(&device.drm, connector.handle(), "non-desktop") |
| 759 | .and_then(|(_, info, value)| info.value_type().convert_value(value).as_boolean()) | 755 | .and_then(|(_, info, value)| info.value_type().convert_value(value).as_boolean()) |
| 760 | .unwrap_or(false); | 756 | .unwrap_or(false); |
| 761 | 757 | ||
| 762 | if non_desktop { | 758 | if non_desktop { |
| 763 | debug!("output is non desktop"); | 759 | debug!("output is non desktop"); |
| 764 | - let description = get_edid_info(&device.drm, connector.handle()) | 760 | + let description = output_name.format_description(); |
| 765 | - .map(|info| truncate_to_nul(info.model)) | ||
| 766 | - .unwrap_or_else(|| "Unknown".into()); | ||
| 767 | if let Some(lease_state) = &mut device.drm_lease_state { | 761 | if let Some(lease_state) = &mut device.drm_lease_state { |
| 768 | - lease_state.add_connector::<State>(connector.handle(), output_name, description); | 762 | + lease_state.add_connector::<State>(connector.handle(), connector_name, description); |
| 769 | } | 763 | } |
| 770 | device | 764 | device |
| 771 | .non_desktop_connectors | 765 | .non_desktop_connectors |
| @@ -881,22 +875,13 @@ impl Tty { | |||
| 881 | // Update the output mode. | 875 | // Update the output mode. |
| 882 | let (physical_width, physical_height) = connector.size().unwrap_or((0, 0)); | 876 | let (physical_width, physical_height) = connector.size().unwrap_or((0, 0)); |
| 883 | 877 | ||
| 884 | - let (make, model) = get_edid_info(&device.drm, connector.handle()) | ||
| 885 | - .map(|info| { | ||
| 886 | - ( | ||
| 887 | - truncate_to_nul(info.manufacturer), | ||
| 888 | - truncate_to_nul(info.model), | ||
| 889 | - ) | ||
| 890 | - }) | ||
| 891 | - .unwrap_or_else(|| ("Unknown".into(), "Unknown".into())); | ||
| 892 | - | ||
| 893 | let output = Output::new( | 878 | let output = Output::new( |
| 894 | - output_name.clone(), | 879 | + connector_name.clone(), |
| 895 | PhysicalProperties { | 880 | PhysicalProperties { |
| 896 | size: (physical_width as i32, physical_height as i32).into(), | 881 | size: (physical_width as i32, physical_height as i32).into(), |
| 897 | subpixel: connector.subpixel().into(), | 882 | subpixel: connector.subpixel().into(), |
| 898 | - model, | 883 | + model: output_name.model.as_deref().unwrap_or("Unknown").to_owned(), |
| 899 | - make, | 884 | + make: output_name.make.as_deref().unwrap_or("Unknown").to_owned(), |
| 900 | }, | 885 | }, |
| 901 | ); | 886 | ); |
| 902 | 887 | ||
| @@ -907,6 +892,7 @@ impl Tty { | |||
| 907 | output | 892 | output |
| 908 | .user_data() | 893 | .user_data() |
| 909 | .insert_if_missing(|| TtyOutputState { node, crtc }); | 894 | .insert_if_missing(|| TtyOutputState { node, crtc }); |
| 895 | + output.user_data().insert_if_missing(|| output_name.clone()); | ||
| 910 | 896 | ||
| 911 | let mut planes = surface.planes().clone(); | 897 | let mut planes = surface.planes().clone(); |
| 912 | 898 | ||
| @@ -993,17 +979,18 @@ impl Tty { | |||
| 993 | } | 979 | } |
| 994 | 980 | ||
| 995 | let vblank_frame_name = | 981 | let vblank_frame_name = |
| 996 | - tracy_client::FrameName::new_leak(format!("vblank on {output_name}")); | 982 | + tracy_client::FrameName::new_leak(format!("vblank on {connector_name}")); |
| 997 | - let time_since_presentation_plot_name = | 983 | + let time_since_presentation_plot_name = tracy_client::PlotName::new_leak(format!( |
| 998 | - tracy_client::PlotName::new_leak(format!("{output_name} time since presentation, ms")); | 984 | + "{connector_name} time since presentation, ms" |
| 985 | + )); | ||
| 999 | let presentation_misprediction_plot_name = tracy_client::PlotName::new_leak(format!( | 986 | let presentation_misprediction_plot_name = tracy_client::PlotName::new_leak(format!( |
| 1000 | - "{output_name} presentation misprediction, ms" | 987 | + "{connector_name} presentation misprediction, ms" |
| 1001 | )); | 988 | )); |
| 1002 | let sequence_delta_plot_name = | 989 | let sequence_delta_plot_name = |
| 1003 | - tracy_client::PlotName::new_leak(format!("{output_name} sequence delta")); | 990 | + tracy_client::PlotName::new_leak(format!("{connector_name} sequence delta")); |
| 1004 | 991 | ||
| 1005 | let surface = Surface { | 992 | let surface = Surface { |
| 1006 | - name: output_name.clone(), | 993 | + name: output_name, |
| 1007 | connector: connector.handle(), | 994 | connector: connector.handle(), |
| 1008 | compositor, | 995 | compositor, |
| 1009 | dmabuf_feedback, | 996 | dmabuf_feedback, |
| @@ -1066,7 +1053,7 @@ impl Tty { | |||
| 1066 | return; | 1053 | return; |
| 1067 | }; | 1054 | }; |
| 1068 | 1055 | ||
| 1069 | - debug!("disconnecting connector: {:?}", surface.name); | 1056 | + debug!("disconnecting connector: {:?}", surface.name.connector); |
| 1070 | 1057 | ||
| 1071 | let output = niri | 1058 | let output = niri |
| 1072 | .global_space | 1059 | .global_space |
| @@ -1108,7 +1095,7 @@ impl Tty { | |||
| 1108 | // Finish the Tracy frame, if any. | 1095 | // Finish the Tracy frame, if any. |
| 1109 | drop(surface.vblank_frame.take()); | 1096 | drop(surface.vblank_frame.take()); |
| 1110 | 1097 | ||
| 1111 | - let name = &surface.name; | 1098 | + let name = &surface.name.connector; |
| 1112 | trace!("vblank on {name} {meta:?}"); | 1099 | trace!("vblank on {name} {meta:?}"); |
| 1113 | span.emit_text(name); | 1100 | span.emit_text(name); |
| 1114 | 1101 | ||
| @@ -1311,7 +1298,7 @@ impl Tty { | |||
| 1311 | return rv; | 1298 | return rv; |
| 1312 | }; | 1299 | }; |
| 1313 | 1300 | ||
| 1314 | - span.emit_text(&surface.name); | 1301 | + span.emit_text(&surface.name.connector); |
| 1315 | 1302 | ||
| 1316 | if !device.drm.is_active() { | 1303 | if !device.drm.is_active() { |
| 1317 | warn!("device is inactive"); | 1304 | warn!("device is inactive"); |
| @@ -1526,22 +1513,10 @@ impl Tty { | |||
| 1526 | 1513 | ||
| 1527 | for (node, device) in &self.devices { | 1514 | for (node, device) in &self.devices { |
| 1528 | for (connector, crtc) in device.drm_scanner.crtcs() { | 1515 | for (connector, crtc) in device.drm_scanner.crtcs() { |
| 1529 | - let name = format!( | 1516 | + let connector_name = format_connector_name(connector); |
| 1530 | - "{}-{}", | ||
| 1531 | - connector.interface().as_str(), | ||
| 1532 | - connector.interface_id(), | ||
| 1533 | - ); | ||
| 1534 | - | ||
| 1535 | let physical_size = connector.size(); | 1517 | let physical_size = connector.size(); |
| 1536 | - | 1518 | + let output_name = |
| 1537 | - let (make, model) = get_edid_info(&device.drm, connector.handle()) | 1519 | + make_output_name(&device.drm, connector.handle(), connector_name.clone()); |
| 1538 | - .map(|info| { | ||
| 1539 | - ( | ||
| 1540 | - truncate_to_nul(info.manufacturer), | ||
| 1541 | - truncate_to_nul(info.model), | ||
| 1542 | - ) | ||
| 1543 | - }) | ||
| 1544 | - .unwrap_or_else(|| ("Unknown".into(), "Unknown".into())); | ||
| 1545 | 1520 | ||
| 1546 | let surface = device.surfaces.get(&crtc); | 1521 | let surface = device.surfaces.get(&crtc); |
| 1547 | let current_crtc_mode = surface.map(|surface| surface.compositor.pending_mode()); | 1522 | let current_crtc_mode = surface.map(|surface| surface.compositor.pending_mode()); |
| @@ -1589,9 +1564,10 @@ impl Tty { | |||
| 1589 | .map(logical_output); | 1564 | .map(logical_output); |
| 1590 | 1565 | ||
| 1591 | let ipc_output = niri_ipc::Output { | 1566 | let ipc_output = niri_ipc::Output { |
| 1592 | - name, | 1567 | + name: connector_name, |
| 1593 | - make, | 1568 | + make: output_name.make.unwrap_or_else(|| "Unknown".into()), |
| 1594 | - model, | 1569 | + model: output_name.model.unwrap_or_else(|| "Unknown".into()), |
| 1570 | + serial: output_name.serial, | ||
| 1595 | physical_size, | 1571 | physical_size, |
| 1596 | modes, | 1572 | modes, |
| 1597 | current_mode, | 1573 | current_mode, |
| @@ -1736,7 +1712,7 @@ impl Tty { | |||
| 1736 | continue; | 1712 | continue; |
| 1737 | }; | 1713 | }; |
| 1738 | let Some(output_state) = niri.output_state.get_mut(&output) else { | 1714 | let Some(output_state) = niri.output_state.get_mut(&output) else { |
| 1739 | - error!("missing state for output {:?}", surface.name); | 1715 | + error!("missing state for output {:?}", surface.name.connector); |
| 1740 | continue; | 1716 | continue; |
| 1741 | }; | 1717 | }; |
| 1742 | 1718 | ||
| @@ -1759,7 +1735,7 @@ impl Tty { | |||
| 1759 | warn!( | 1735 | warn!( |
| 1760 | "output {:?}: configured mode {}x{}{} could not be found, \ | 1736 | "output {:?}: configured mode {}x{}{} could not be found, \ |
| 1761 | falling back to preferred", | 1737 | falling back to preferred", |
| 1762 | - surface.name, | 1738 | + surface.name.connector, |
| 1763 | target.width, | 1739 | target.width, |
| 1764 | target.height, | 1740 | target.height, |
| 1765 | if let Some(refresh) = target.refresh { | 1741 | if let Some(refresh) = target.refresh { |
| @@ -1770,7 +1746,10 @@ impl Tty { | |||
| 1770 | ); | 1746 | ); |
| 1771 | } | 1747 | } |
| 1772 | 1748 | ||
| 1773 | - debug!("output {:?}: picking mode: {mode:?}", surface.name); | 1749 | + debug!( |
| 1750 | + "output {:?}: picking mode: {mode:?}", | ||
| 1751 | + surface.name.connector | ||
| 1752 | + ); | ||
| 1774 | if let Err(err) = surface.compositor.use_mode(mode) { | 1753 | if let Err(err) = surface.compositor.use_mode(mode) { |
| 1775 | warn!("error changing mode: {err:?}"); | 1754 | warn!("error changing mode: {err:?}"); |
| 1776 | continue; | 1755 | continue; |
| @@ -1796,12 +1775,8 @@ impl Tty { | |||
| 1796 | continue; | 1775 | continue; |
| 1797 | } | 1776 | } |
| 1798 | 1777 | ||
| 1799 | - let output_name = format!( | 1778 | + let connector_name = format_connector_name(connector); |
| 1800 | - "{}-{}", | 1779 | + let output_name = make_output_name(&device.drm, connector.handle(), connector_name); |
| 1801 | - connector.interface().as_str(), | ||
| 1802 | - connector.interface_id(), | ||
| 1803 | - ); | ||
| 1804 | - | ||
| 1805 | let config = self | 1780 | let config = self |
| 1806 | .config | 1781 | .config |
| 1807 | .borrow() | 1782 | .borrow() |
| @@ -1845,6 +1820,30 @@ impl Tty { | |||
| 1845 | pub fn get_device_from_node(&mut self, node: DrmNode) -> Option<&mut OutputDevice> { | 1820 | pub fn get_device_from_node(&mut self, node: DrmNode) -> Option<&mut OutputDevice> { |
| 1846 | self.devices.get_mut(&node) | 1821 | self.devices.get_mut(&node) |
| 1847 | } | 1822 | } |
| 1823 | + | ||
| 1824 | + pub fn disconnected_connector_name_by_name_match(&self, target: &str) -> Option<OutputName> { | ||
| 1825 | + for device in self.devices.values() { | ||
| 1826 | + for (connector, crtc) in device.drm_scanner.crtcs() { | ||
| 1827 | + // Check if connected. | ||
| 1828 | + if connector.state() != connector::State::Connected { | ||
| 1829 | + continue; | ||
| 1830 | + } | ||
| 1831 | + | ||
| 1832 | + // Check if already enabled. | ||
| 1833 | + if device.surfaces.contains_key(&crtc) { | ||
| 1834 | + continue; | ||
| 1835 | + } | ||
| 1836 | + | ||
| 1837 | + let connector_name = format_connector_name(connector); | ||
| 1838 | + let output_name = make_output_name(&device.drm, connector.handle(), connector_name); | ||
| 1839 | + if output_name.matches(target) { | ||
| 1840 | + return Some(output_name); | ||
| 1841 | + } | ||
| 1842 | + } | ||
| 1843 | + } | ||
| 1844 | + | ||
| 1845 | + None | ||
| 1846 | + } | ||
| 1848 | } | 1847 | } |
| 1849 | 1848 | ||
| 1850 | impl GammaProps { | 1849 | impl GammaProps { |
| @@ -2277,23 +2276,21 @@ fn pick_mode( | |||
| 2277 | mode.map(|m| (*m, fallback)) | 2276 | mode.map(|m| (*m, fallback)) |
| 2278 | } | 2277 | } |
| 2279 | 2278 | ||
| 2280 | -fn truncate_to_nul(mut s: String) -> String { | 2279 | +fn get_edid_info( |
| 2281 | - if let Some(index) = s.find('\0') { | 2280 | + device: &DrmDevice, |
| 2282 | - s.truncate(index); | 2281 | + connector: connector::Handle, |
| 2283 | - } | 2282 | +) -> anyhow::Result<libdisplay_info::info::Info> { |
| 2284 | - s | 2283 | + let (_, info, value) = |
| 2285 | -} | 2284 | + find_drm_property(device, connector, "EDID").context("no EDID property")?; |
| 2286 | - | 2285 | + let blob = info |
| 2287 | -fn get_edid_info(device: &DrmDevice, connector: connector::Handle) -> Option<EdidInfo> { | 2286 | + .value_type() |
| 2288 | - match catch_unwind(AssertUnwindSafe(move || { | 2287 | + .convert_value(value) |
| 2289 | - EdidInfo::for_connector(device, connector) | 2288 | + .as_blob() |
| 2290 | - })) { | 2289 | + .context("EDID was not blob type")?; |
| 2291 | - Ok(info) => info, | 2290 | + let data = device |
| 2292 | - Err(err) => { | 2291 | + .get_property_blob(blob) |
| 2293 | - warn!("edid-rs panicked: {err:?}"); | 2292 | + .context("error getting EDID blob value")?; |
| 2294 | - None | 2293 | + libdisplay_info::info::Info::parse_edid(&data).context("error parsing EDID") |
| 2295 | - } | ||
| 2296 | - } | ||
| 2297 | } | 2294 | } |
| 2298 | 2295 | ||
| 2299 | fn set_max_bpc(device: &DrmDevice, connector: connector::Handle, bpc: u64) -> anyhow::Result<u64> { | 2296 | fn set_max_bpc(device: &DrmDevice, connector: connector::Handle, bpc: u64) -> anyhow::Result<u64> { |
| @@ -2415,41 +2412,47 @@ fn try_to_change_vrr( | |||
| 2415 | match set_vrr_enabled(device, crtc, enable_vrr) { | 2412 | match set_vrr_enabled(device, crtc, enable_vrr) { |
| 2416 | Ok(enabled) => { | 2413 | Ok(enabled) => { |
| 2417 | if enabled != enable_vrr { | 2414 | if enabled != enable_vrr { |
| 2418 | - warn!("output {:?}: failed {} VRR", surface.name, word); | 2415 | + warn!("output {:?}: failed {} VRR", surface.name.connector, word); |
| 2419 | } | 2416 | } |
| 2420 | 2417 | ||
| 2421 | surface.vrr_enabled = enabled; | 2418 | surface.vrr_enabled = enabled; |
| 2422 | output_state.frame_clock.set_vrr(enabled); | 2419 | output_state.frame_clock.set_vrr(enabled); |
| 2423 | } | 2420 | } |
| 2424 | Err(err) => { | 2421 | Err(err) => { |
| 2425 | - warn!("output {:?}: error {} VRR: {err:?}", surface.name, word); | 2422 | + warn!( |
| 2423 | + "output {:?}: error {} VRR: {err:?}", | ||
| 2424 | + surface.name.connector, word | ||
| 2425 | + ); | ||
| 2426 | } | 2426 | } |
| 2427 | } | 2427 | } |
| 2428 | } else if enable_vrr { | 2428 | } else if enable_vrr { |
| 2429 | warn!( | 2429 | warn!( |
| 2430 | "output {:?}: cannot enable VRR because connector is not vrr_capable", | 2430 | "output {:?}: cannot enable VRR because connector is not vrr_capable", |
| 2431 | - surface.name | 2431 | + surface.name.connector |
| 2432 | ); | 2432 | ); |
| 2433 | } | 2433 | } |
| 2434 | } | 2434 | } |
| 2435 | 2435 | ||
| 2436 | -#[cfg(test)] | 2436 | +fn format_connector_name(connector: &connector::Info) -> String { |
| 2437 | -mod tests { | 2437 | + format!( |
| 2438 | - use super::*; | 2438 | + "{}-{}", |
| 2439 | - | 2439 | + connector.interface().as_str(), |
| 2440 | - #[track_caller] | 2440 | + connector.interface_id(), |
| 2441 | - fn check(input: &str, expected: &str) { | 2441 | + ) |
| 2442 | - let input = String::from(input); | 2442 | +} |
| 2443 | - assert_eq!(truncate_to_nul(input), expected); | ||
| 2444 | - } | ||
| 2445 | 2443 | ||
| 2446 | - #[test] | 2444 | +fn make_output_name( |
| 2447 | - fn truncate_to_nul_works() { | 2445 | + device: &DrmDevice, |
| 2448 | - check("", ""); | 2446 | + connector: connector::Handle, |
| 2449 | - check("qwer", "qwer"); | 2447 | + connector_name: String, |
| 2450 | - check("abc\0def", "abc"); | 2448 | +) -> OutputName { |
| 2451 | - check("\0as", ""); | 2449 | + let info = get_edid_info(device, connector) |
| 2452 | - check("a\0\0\0b", "a"); | 2450 | + .map_err(|err| warn!("error getting EDID info for {connector_name}: {err:?}")) |
| 2453 | - check("bb😁\0cc", "bb😁"); | 2451 | + .ok(); |
| 2452 | + OutputName { | ||
| 2453 | + connector: connector_name, | ||
| 2454 | + make: info.as_ref().and_then(|info| info.make()), | ||
| 2455 | + model: info.as_ref().and_then(|info| info.model()), | ||
| 2456 | + serial: info.as_ref().and_then(|info| info.serial()), | ||
| 2454 | } | 2457 | } |
| 2455 | } | 2458 | } |
src/backend/winit.rsmodified+9 -1
| @@ -5,7 +5,7 @@ use std::rc::Rc; | |||
| 5 | use std::sync::{Arc, Mutex}; | 5 | use std::sync::{Arc, Mutex}; |
| 6 | use std::time::Duration; | 6 | use std::time::Duration; |
| 7 | 7 | ||
| 8 | -use niri_config::Config; | 8 | +use niri_config::{Config, OutputName}; |
| 9 | use smithay::backend::allocator::dmabuf::Dmabuf; | 9 | use smithay::backend::allocator::dmabuf::Dmabuf; |
| 10 | use smithay::backend::renderer::damage::OutputDamageTracker; | 10 | use smithay::backend::renderer::damage::OutputDamageTracker; |
| 11 | use smithay::backend::renderer::gles::GlesRenderer; | 11 | use smithay::backend::renderer::gles::GlesRenderer; |
| @@ -59,6 +59,13 @@ impl Winit { | |||
| 59 | output.change_current_state(Some(mode), None, None, None); | 59 | output.change_current_state(Some(mode), None, None, None); |
| 60 | output.set_preferred(mode); | 60 | output.set_preferred(mode); |
| 61 | 61 | ||
| 62 | + output.user_data().insert_if_missing(|| OutputName { | ||
| 63 | + connector: "winit".to_string(), | ||
| 64 | + make: Some("Smithay".to_string()), | ||
| 65 | + model: Some("Winit".to_string()), | ||
| 66 | + serial: None, | ||
| 67 | + }); | ||
| 68 | + | ||
| 62 | let physical_properties = output.physical_properties(); | 69 | let physical_properties = output.physical_properties(); |
| 63 | let ipc_outputs = Arc::new(Mutex::new(HashMap::from([( | 70 | let ipc_outputs = Arc::new(Mutex::new(HashMap::from([( |
| 64 | OutputId::next(), | 71 | OutputId::next(), |
| @@ -66,6 +73,7 @@ impl Winit { | |||
| 66 | name: output.name(), | 73 | name: output.name(), |
| 67 | make: physical_properties.make, | 74 | make: physical_properties.make, |
| 68 | model: physical_properties.model, | 75 | model: physical_properties.model, |
| 76 | + serial: None, | ||
| 69 | physical_size: None, | 77 | physical_size: None, |
| 70 | modes: vec![niri_ipc::Mode { | 78 | modes: vec![niri_ipc::Mode { |
| 71 | width: backend.window_size().w.clamp(0, u16::MAX as i32) as u16, | 79 | width: backend.window_size().w.clamp(0, u16::MAX as i32) as u16, |
src/dbus/mutter_display_config.rsmodified+61 -20
| @@ -64,18 +64,13 @@ impl DisplayConfig { | |||
| 64 | // Loosely matches the check in Mutter. | 64 | // Loosely matches the check in Mutter. |
| 65 | let c = &output.name; | 65 | let c = &output.name; |
| 66 | let is_laptop_panel = matches!(c.get(..4), Some("eDP-" | "LVDS" | "DSI-")); | 66 | let is_laptop_panel = matches!(c.get(..4), Some("eDP-" | "LVDS" | "DSI-")); |
| 67 | - | 67 | + let display_name = make_display_name(output, is_laptop_panel); |
| 68 | - // FIXME: use proper serial when we have libdisplay-info. | ||
| 69 | - // A serial is required for correct session restore by xdp-gnome. | ||
| 70 | - let serial = c.clone(); | ||
| 71 | 68 | ||
| 72 | let mut properties = HashMap::new(); | 69 | let mut properties = HashMap::new(); |
| 73 | - if is_laptop_panel { | 70 | + properties.insert( |
| 74 | - properties.insert( | 71 | + String::from("display-name"), |
| 75 | - String::from("display-name"), | 72 | + OwnedValue::from(zvariant::Str::from(display_name)), |
| 76 | - OwnedValue::from(zvariant::Str::from_static("Built-in display")), | 73 | + ); |
| 77 | - ); | ||
| 78 | - } | ||
| 79 | properties.insert( | 74 | properties.insert( |
| 80 | String::from("is-builtin"), | 75 | String::from("is-builtin"), |
| 81 | OwnedValue::from(is_laptop_panel), | 76 | OwnedValue::from(is_laptop_panel), |
| @@ -111,8 +106,16 @@ impl DisplayConfig { | |||
| 111 | .properties | 106 | .properties |
| 112 | .insert(String::from("is-current"), OwnedValue::from(true)); | 107 | .insert(String::from("is-current"), OwnedValue::from(true)); |
| 113 | 108 | ||
| 109 | + let connector = c.clone(); | ||
| 110 | + let model = output.model.clone(); | ||
| 111 | + let make = output.make.clone(); | ||
| 112 | + | ||
| 113 | + // Serial is used for session restore, so fall back to the connector name if it's | ||
| 114 | + // not available. | ||
| 115 | + let serial = output.serial.as_ref().unwrap_or(&connector).clone(); | ||
| 116 | + | ||
| 114 | let monitor = Monitor { | 117 | let monitor = Monitor { |
| 115 | - names: (c.clone(), String::new(), String::new(), serial), | 118 | + names: (connector, make, model, serial), |
| 116 | modes, | 119 | modes, |
| 117 | properties, | 120 | properties, |
| 118 | }; | 121 | }; |
| @@ -144,15 +147,8 @@ impl DisplayConfig { | |||
| 144 | }) | 147 | }) |
| 145 | .collect(); | 148 | .collect(); |
| 146 | 149 | ||
| 147 | - // Sort the built-in monitor first, then by connector name. | 150 | + // Sort by connector. |
| 148 | - monitors.sort_unstable_by(|a, b| { | 151 | + monitors.sort_unstable_by(|a, b| a.0.names.0.cmp(&b.0.names.0)); |
| 149 | - let a_is_builtin = a.0.properties.contains_key("display-name"); | ||
| 150 | - let b_is_builtin = b.0.properties.contains_key("display-name"); | ||
| 151 | - a_is_builtin | ||
| 152 | - .cmp(&b_is_builtin) | ||
| 153 | - .reverse() | ||
| 154 | - .then_with(|| a.0.names.0.cmp(&b.0.names.0)) | ||
| 155 | - }); | ||
| 156 | 152 | ||
| 157 | let (monitors, logical_monitors) = monitors.into_iter().unzip(); | 153 | let (monitors, logical_monitors) = monitors.into_iter().unzip(); |
| 158 | let properties = HashMap::from([(String::from("layout-mode"), OwnedValue::from(1u32))]); | 154 | let properties = HashMap::from([(String::from("layout-mode"), OwnedValue::from(1u32))]); |
| @@ -183,3 +179,48 @@ impl Start for DisplayConfig { | |||
| 183 | Ok(conn) | 179 | Ok(conn) |
| 184 | } | 180 | } |
| 185 | } | 181 | } |
| 182 | + | ||
| 183 | +// Adapted from Mutter. | ||
| 184 | +fn make_display_name(output: &niri_ipc::Output, is_laptop_panel: bool) -> String { | ||
| 185 | + if is_laptop_panel { | ||
| 186 | + return String::from("Built-in display"); | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + let make = &output.make; | ||
| 190 | + let model = &output.model; | ||
| 191 | + if let Some(diagonal) = output.physical_size.map(|(width_mm, height_mm)| { | ||
| 192 | + let diagonal = f64::hypot(f64::from(width_mm), f64::from(height_mm)) / 25.4; | ||
| 193 | + format_diagonal(diagonal) | ||
| 194 | + }) { | ||
| 195 | + format!("{make} {diagonal}") | ||
| 196 | + } else if model != "Unknown" { | ||
| 197 | + format!("{make} {model}") | ||
| 198 | + } else { | ||
| 199 | + make.clone() | ||
| 200 | + } | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +fn format_diagonal(diagonal_inches: f64) -> String { | ||
| 204 | + let known = [12.1, 13.3, 15.6]; | ||
| 205 | + if let Some(d) = known.iter().find(|d| (*d - diagonal_inches).abs() < 0.1) { | ||
| 206 | + format!("{d:.1}″") | ||
| 207 | + } else { | ||
| 208 | + format!("{}″", diagonal_inches.round() as u32) | ||
| 209 | + } | ||
| 210 | +} | ||
| 211 | + | ||
| 212 | +#[cfg(test)] | ||
| 213 | +mod tests { | ||
| 214 | + use k9::snapshot; | ||
| 215 | + | ||
| 216 | + use super::*; | ||
| 217 | + | ||
| 218 | + #[test] | ||
| 219 | + fn test_format_diagonal() { | ||
| 220 | + snapshot!(format_diagonal(12.11), "12.1″"); | ||
| 221 | + snapshot!(format_diagonal(13.28), "13.3″"); | ||
| 222 | + snapshot!(format_diagonal(15.6), "15.6″"); | ||
| 223 | + snapshot!(format_diagonal(23.2), "23″"); | ||
| 224 | + snapshot!(format_diagonal(24.8), "25″"); | ||
| 225 | + } | ||
| 226 | +} | ||
src/handlers/xdg_shell.rsmodified+7 -2
| @@ -41,7 +41,7 @@ use crate::input::DOUBLE_CLICK_TIME; | |||
| 41 | use crate::layout::workspace::ColumnWidth; | 41 | use crate::layout::workspace::ColumnWidth; |
| 42 | use crate::niri::{PopupGrabState, State}; | 42 | use crate::niri::{PopupGrabState, State}; |
| 43 | use crate::utils::transaction::Transaction; | 43 | use crate::utils::transaction::Transaction; |
| 44 | -use crate::utils::{get_monotonic_time, send_scale_transform, ResizeEdge}; | 44 | +use crate::utils::{get_monotonic_time, output_matches_name, send_scale_transform, ResizeEdge}; |
| 45 | use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef}; | 45 | use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef}; |
| 46 | 46 | ||
| 47 | impl XdgShellHandler for State { | 47 | impl XdgShellHandler for State { |
| @@ -668,7 +668,12 @@ impl State { | |||
| 668 | rules | 668 | rules |
| 669 | .open_on_output | 669 | .open_on_output |
| 670 | .as_deref() | 670 | .as_deref() |
| 671 | - .and_then(|name| self.niri.output_by_name.get(name)) | 671 | + .and_then(|name| { |
| 672 | + self.niri | ||
| 673 | + .global_space | ||
| 674 | + .outputs() | ||
| 675 | + .find(|output| output_matches_name(output, name)) | ||
| 676 | + }) | ||
| 672 | .and_then(|o| self.niri.layout.monitor_for_output(o)) | 677 | .and_then(|o| self.niri.layout.monitor_for_output(o)) |
| 673 | }); | 678 | }); |
| 674 | 679 | ||
src/ipc/client.rsmodified+7 -5
| @@ -122,8 +122,8 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | |||
| 122 | let mut outputs = outputs.into_iter().collect::<Vec<_>>(); | 122 | let mut outputs = outputs.into_iter().collect::<Vec<_>>(); |
| 123 | outputs.sort_unstable_by(|a, b| a.0.cmp(&b.0)); | 123 | outputs.sort_unstable_by(|a, b| a.0.cmp(&b.0)); |
| 124 | 124 | ||
| 125 | - for (connector, output) in outputs.into_iter() { | 125 | + for (_name, output) in outputs.into_iter() { |
| 126 | - print_output(connector, output)?; | 126 | + print_output(output)?; |
| 127 | println!(); | 127 | println!(); |
| 128 | } | 128 | } |
| 129 | } | 129 | } |
| @@ -207,7 +207,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | |||
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | if let Some(output) = output { | 209 | if let Some(output) = output { |
| 210 | - print_output(output.name.clone(), output)?; | 210 | + print_output(output)?; |
| 211 | } else { | 211 | } else { |
| 212 | println!("No output is focused."); | 212 | println!("No output is focused."); |
| 213 | } | 213 | } |
| @@ -364,11 +364,12 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | |||
| 364 | Ok(()) | 364 | Ok(()) |
| 365 | } | 365 | } |
| 366 | 366 | ||
| 367 | -fn print_output(connector: String, output: Output) -> anyhow::Result<()> { | 367 | +fn print_output(output: Output) -> anyhow::Result<()> { |
| 368 | let Output { | 368 | let Output { |
| 369 | name, | 369 | name, |
| 370 | make, | 370 | make, |
| 371 | model, | 371 | model, |
| 372 | + serial, | ||
| 372 | physical_size, | 373 | physical_size, |
| 373 | modes, | 374 | modes, |
| 374 | current_mode, | 375 | current_mode, |
| @@ -377,7 +378,8 @@ fn print_output(connector: String, output: Output) -> anyhow::Result<()> { | |||
| 377 | logical, | 378 | logical, |
| 378 | } = output; | 379 | } = output; |
| 379 | 380 | ||
| 380 | - println!(r#"Output "{connector}" ({make} - {model} - {name})"#); | 381 | + let serial = serial.as_deref().unwrap_or("Unknown"); |
| 382 | + println!(r#"Output "{make} {model} {serial}" ({name})"#); | ||
| 381 | 383 | ||
| 382 | if let Some(current) = current_mode { | 384 | if let Some(current) = current_mode { |
| 383 | let mode = *modes | 385 | let mode = *modes |
src/ipc/server.rsmodified+2 -1
| @@ -13,6 +13,7 @@ use calloop::io::Async; | |||
| 13 | use directories::BaseDirs; | 13 | use directories::BaseDirs; |
| 14 | use futures_util::io::{AsyncReadExt, BufReader}; | 14 | use futures_util::io::{AsyncReadExt, BufReader}; |
| 15 | use futures_util::{select_biased, AsyncBufReadExt, AsyncWrite, AsyncWriteExt, FutureExt as _}; | 15 | use futures_util::{select_biased, AsyncBufReadExt, AsyncWrite, AsyncWriteExt, FutureExt as _}; |
| 16 | +use niri_config::OutputName; | ||
| 16 | use niri_ipc::state::{EventStreamState, EventStreamStatePart as _}; | 17 | use niri_ipc::state::{EventStreamState, EventStreamStatePart as _}; |
| 17 | use niri_ipc::{Event, KeyboardLayouts, OutputConfigChanged, Reply, Request, Response, Workspace}; | 18 | use niri_ipc::{Event, KeyboardLayouts, OutputConfigChanged, Reply, Request, Response, Workspace}; |
| 18 | use smithay::input::keyboard::XkbContextHandler; | 19 | use smithay::input::keyboard::XkbContextHandler; |
| @@ -296,7 +297,7 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply { | |||
| 296 | let ipc_outputs = ctx.ipc_outputs.lock().unwrap(); | 297 | let ipc_outputs = ctx.ipc_outputs.lock().unwrap(); |
| 297 | let found = ipc_outputs | 298 | let found = ipc_outputs |
| 298 | .values() | 299 | .values() |
| 299 | - .any(|o| o.name.eq_ignore_ascii_case(&output)); | 300 | + .any(|o| OutputName::from_ipc_output(o).matches(&output)); |
| 300 | let response = if found { | 301 | let response = if found { |
| 301 | OutputConfigChanged::Applied | 302 | OutputConfigChanged::Applied |
| 302 | } else { | 303 | } else { |
src/layout/mod.rsmodified+21 -13
| @@ -54,7 +54,7 @@ use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderEleme | |||
| 54 | use crate::render_helpers::texture::TextureBuffer; | 54 | use crate::render_helpers::texture::TextureBuffer; |
| 55 | use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; | 55 | use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; |
| 56 | use crate::utils::transaction::{Transaction, TransactionBlocker}; | 56 | use crate::utils::transaction::{Transaction, TransactionBlocker}; |
| 57 | -use crate::utils::{output_size, round_logical_in_physical_max1, ResizeEdge}; | 57 | +use crate::utils::{output_matches_name, output_size, round_logical_in_physical_max1, ResizeEdge}; |
| 58 | use crate::window::ResolvedWindowRules; | 58 | use crate::window::ResolvedWindowRules; |
| 59 | 59 | ||
| 60 | pub mod closing_window; | 60 | pub mod closing_window; |
| @@ -344,8 +344,6 @@ impl<W: LayoutElement> Layout<W> { | |||
| 344 | } | 344 | } |
| 345 | 345 | ||
| 346 | pub fn add_output(&mut self, output: Output) { | 346 | pub fn add_output(&mut self, output: Output) { |
| 347 | - let id = OutputId::new(&output); | ||
| 348 | - | ||
| 349 | self.monitor_set = match mem::take(&mut self.monitor_set) { | 347 | self.monitor_set = match mem::take(&mut self.monitor_set) { |
| 350 | MonitorSet::Normal { | 348 | MonitorSet::Normal { |
| 351 | mut monitors, | 349 | mut monitors, |
| @@ -358,7 +356,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 358 | 356 | ||
| 359 | let mut workspaces = vec![]; | 357 | let mut workspaces = vec![]; |
| 360 | for i in (0..primary.workspaces.len()).rev() { | 358 | for i in (0..primary.workspaces.len()).rev() { |
| 361 | - if primary.workspaces[i].original_output == id { | 359 | + if primary.workspaces[i].original_output.matches(&output) { |
| 362 | let ws = primary.workspaces.remove(i); | 360 | let ws = primary.workspaces.remove(i); |
| 363 | 361 | ||
| 364 | // FIXME: this can be coded in a way that the workspace switch won't be | 362 | // FIXME: this can be coded in a way that the workspace switch won't be |
| @@ -1722,18 +1720,16 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1722 | assert!(after_idx < monitor.workspaces.len()); | 1720 | assert!(after_idx < monitor.workspaces.len()); |
| 1723 | } | 1721 | } |
| 1724 | 1722 | ||
| 1725 | - let monitor_id = OutputId::new(&monitor.output); | ||
| 1726 | - | ||
| 1727 | if idx == primary_idx { | 1723 | if idx == primary_idx { |
| 1728 | for ws in &monitor.workspaces { | 1724 | for ws in &monitor.workspaces { |
| 1729 | - if ws.original_output == monitor_id { | 1725 | + if ws.original_output.matches(&monitor.output) { |
| 1730 | // This is the primary monitor's own workspace. | 1726 | // This is the primary monitor's own workspace. |
| 1731 | continue; | 1727 | continue; |
| 1732 | } | 1728 | } |
| 1733 | 1729 | ||
| 1734 | let own_monitor_exists = monitors | 1730 | let own_monitor_exists = monitors |
| 1735 | .iter() | 1731 | .iter() |
| 1736 | - .any(|m| OutputId::new(&m.output) == ws.original_output); | 1732 | + .any(|m| ws.original_output.matches(&m.output)); |
| 1737 | assert!( | 1733 | assert!( |
| 1738 | !own_monitor_exists, | 1734 | !own_monitor_exists, |
| 1739 | "primary monitor cannot have workspaces for which their own monitor exists" | 1735 | "primary monitor cannot have workspaces for which their own monitor exists" |
| @@ -1744,7 +1740,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1744 | monitor | 1740 | monitor |
| 1745 | .workspaces | 1741 | .workspaces |
| 1746 | .iter() | 1742 | .iter() |
| 1747 | - .any(|workspace| workspace.original_output == monitor_id), | 1743 | + .any(|workspace| workspace.original_output.matches(&monitor.output)), |
| 1748 | "secondary monitor must not have any non-own workspaces" | 1744 | "secondary monitor must not have any non-own workspaces" |
| 1749 | ); | 1745 | ); |
| 1750 | } | 1746 | } |
| @@ -1881,7 +1877,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1881 | .map(|name| { | 1877 | .map(|name| { |
| 1882 | monitors | 1878 | monitors |
| 1883 | .iter_mut() | 1879 | .iter_mut() |
| 1884 | - .position(|monitor| monitor.output_name().eq_ignore_ascii_case(name)) | 1880 | + .position(|monitor| output_matches_name(&monitor.output, name)) |
| 1885 | .unwrap_or(*primary_idx) | 1881 | .unwrap_or(*primary_idx) |
| 1886 | }) | 1882 | }) |
| 1887 | .unwrap_or(*active_monitor_idx); | 1883 | .unwrap_or(*active_monitor_idx); |
| @@ -2556,7 +2552,7 @@ impl<W: LayoutElement> Default for MonitorSet<W> { | |||
| 2556 | mod tests { | 2552 | mod tests { |
| 2557 | use std::cell::Cell; | 2553 | use std::cell::Cell; |
| 2558 | 2554 | ||
| 2559 | - use niri_config::{FloatOrInt, WorkspaceName}; | 2555 | + use niri_config::{FloatOrInt, OutputName, WorkspaceName}; |
| 2560 | use proptest::prelude::*; | 2556 | use proptest::prelude::*; |
| 2561 | use proptest_derive::Arbitrary; | 2557 | use proptest_derive::Arbitrary; |
| 2562 | use smithay::output::{Mode, PhysicalProperties, Subpixel}; | 2558 | use smithay::output::{Mode, PhysicalProperties, Subpixel}; |
| @@ -2967,7 +2963,7 @@ mod tests { | |||
| 2967 | } | 2963 | } |
| 2968 | 2964 | ||
| 2969 | let output = Output::new( | 2965 | let output = Output::new( |
| 2970 | - name, | 2966 | + name.clone(), |
| 2971 | PhysicalProperties { | 2967 | PhysicalProperties { |
| 2972 | size: Size::from((1280, 720)), | 2968 | size: Size::from((1280, 720)), |
| 2973 | subpixel: Subpixel::Unknown, | 2969 | subpixel: Subpixel::Unknown, |
| @@ -2984,6 +2980,12 @@ mod tests { | |||
| 2984 | None, | 2980 | None, |
| 2985 | None, | 2981 | None, |
| 2986 | ); | 2982 | ); |
| 2983 | + output.user_data().insert_if_missing(|| OutputName { | ||
| 2984 | + connector: name, | ||
| 2985 | + make: None, | ||
| 2986 | + model: None, | ||
| 2987 | + serial: None, | ||
| 2988 | + }); | ||
| 2987 | layout.add_output(output.clone()); | 2989 | layout.add_output(output.clone()); |
| 2988 | } | 2990 | } |
| 2989 | Op::AddScaledOutput { id, scale } => { | 2991 | Op::AddScaledOutput { id, scale } => { |
| @@ -2993,7 +2995,7 @@ mod tests { | |||
| 2993 | } | 2995 | } |
| 2994 | 2996 | ||
| 2995 | let output = Output::new( | 2997 | let output = Output::new( |
| 2996 | - name, | 2998 | + name.clone(), |
| 2997 | PhysicalProperties { | 2999 | PhysicalProperties { |
| 2998 | size: Size::from((1280, 720)), | 3000 | size: Size::from((1280, 720)), |
| 2999 | subpixel: Subpixel::Unknown, | 3001 | subpixel: Subpixel::Unknown, |
| @@ -3010,6 +3012,12 @@ mod tests { | |||
| 3010 | Some(smithay::output::Scale::Fractional(scale)), | 3012 | Some(smithay::output::Scale::Fractional(scale)), |
| 3011 | None, | 3013 | None, |
| 3012 | ); | 3014 | ); |
| 3015 | + output.user_data().insert_if_missing(|| OutputName { | ||
| 3016 | + connector: name, | ||
| 3017 | + make: None, | ||
| 3018 | + model: None, | ||
| 3019 | + serial: None, | ||
| 3020 | + }); | ||
| 3013 | layout.add_output(output.clone()); | 3021 | layout.add_output(output.clone()); |
| 3014 | } | 3022 | } |
| 3015 | Op::RemoveOutput(id) => { | 3023 | Op::RemoveOutput(id) => { |
src/layout/workspace.rsmodified+20 -5
| @@ -3,7 +3,9 @@ use std::iter::{self, zip}; | |||
| 3 | use std::rc::Rc; | 3 | use std::rc::Rc; |
| 4 | use std::time::Duration; | 4 | use std::time::Duration; |
| 5 | 5 | ||
| 6 | -use niri_config::{CenterFocusedColumn, PresetWidth, Struts, Workspace as WorkspaceConfig}; | 6 | +use niri_config::{ |
| 7 | + CenterFocusedColumn, OutputName, PresetWidth, Struts, Workspace as WorkspaceConfig, | ||
| 8 | +}; | ||
| 7 | use niri_ipc::SizeChange; | 9 | use niri_ipc::SizeChange; |
| 8 | use ordered_float::NotNan; | 10 | use ordered_float::NotNan; |
| 9 | use smithay::backend::renderer::gles::GlesRenderer; | 11 | use smithay::backend::renderer::gles::GlesRenderer; |
| @@ -117,9 +119,16 @@ pub struct Workspace<W: LayoutElement> { | |||
| 117 | id: WorkspaceId, | 119 | id: WorkspaceId, |
| 118 | } | 120 | } |
| 119 | 121 | ||
| 120 | -#[derive(Debug, Clone, PartialEq, Eq)] | 122 | +#[derive(Debug, Clone)] |
| 121 | pub struct OutputId(String); | 123 | pub struct OutputId(String); |
| 122 | 124 | ||
| 125 | +impl OutputId { | ||
| 126 | + pub fn matches(&self, output: &Output) -> bool { | ||
| 127 | + let output_name = output.user_data().get::<OutputName>().unwrap(); | ||
| 128 | + output_name.matches(&self.0) | ||
| 129 | + } | ||
| 130 | +} | ||
| 131 | + | ||
| 123 | static WORKSPACE_ID_COUNTER: IdCounter = IdCounter::new(); | 132 | static WORKSPACE_ID_COUNTER: IdCounter = IdCounter::new(); |
| 124 | 133 | ||
| 125 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 134 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| @@ -274,7 +283,8 @@ struct TileData { | |||
| 274 | 283 | ||
| 275 | impl OutputId { | 284 | impl OutputId { |
| 276 | pub fn new(output: &Output) -> Self { | 285 | pub fn new(output: &Output) -> Self { |
| 277 | - Self(output.name()) | 286 | + let output_name = output.user_data().get::<OutputName>().unwrap(); |
| 287 | + Self(output_name.format_make_model_serial_or_connector()) | ||
| 278 | } | 288 | } |
| 279 | } | 289 | } |
| 280 | 290 | ||
| @@ -401,8 +411,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 401 | ) -> Self { | 411 | ) -> Self { |
| 402 | let original_output = OutputId( | 412 | let original_output = OutputId( |
| 403 | config | 413 | config |
| 404 | - .clone() | 414 | + .as_ref() |
| 405 | - .and_then(|c| c.open_on_output) | 415 | + .and_then(|c| c.open_on_output.clone()) |
| 406 | .unwrap_or_default(), | 416 | .unwrap_or_default(), |
| 407 | ); | 417 | ); |
| 408 | 418 | ||
| @@ -559,6 +569,11 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 559 | self.output = output; | 569 | self.output = output; |
| 560 | 570 | ||
| 561 | if let Some(output) = &self.output { | 571 | if let Some(output) = &self.output { |
| 572 | + // Normalize original output: possibly replace connector with make/model/serial. | ||
| 573 | + if self.original_output.matches(output) { | ||
| 574 | + self.original_output = OutputId::new(output); | ||
| 575 | + } | ||
| 576 | + | ||
| 562 | let scale = output.current_scale(); | 577 | let scale = output.current_scale(); |
| 563 | let transform = output.current_transform(); | 578 | let transform = output.current_transform(); |
| 564 | let working_area = compute_working_area(output, self.options.struts); | 579 | let working_area = compute_working_area(output, self.options.struts); |
src/niri.rsmodified+48 -27
| @@ -13,7 +13,7 @@ use _server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as | |||
| 13 | use anyhow::{bail, ensure, Context}; | 13 | use anyhow::{bail, ensure, Context}; |
| 14 | use calloop::futures::Scheduler; | 14 | use calloop::futures::Scheduler; |
| 15 | use niri_config::{ | 15 | use niri_config::{ |
| 16 | - Config, FloatOrInt, Key, Modifiers, PreviewRender, TrackLayout, WorkspaceReference, | 16 | + Config, FloatOrInt, Key, Modifiers, OutputName, PreviewRender, TrackLayout, WorkspaceReference, |
| 17 | DEFAULT_BACKGROUND_COLOR, | 17 | DEFAULT_BACKGROUND_COLOR, |
| 18 | }; | 18 | }; |
| 19 | use smithay::backend::allocator::Fourcc; | 19 | use smithay::backend::allocator::Fourcc; |
| @@ -142,7 +142,7 @@ use crate::utils::scale::{closest_representable_scale, guess_monitor_scale}; | |||
| 142 | use crate::utils::spawning::CHILD_ENV; | 142 | use crate::utils::spawning::CHILD_ENV; |
| 143 | use crate::utils::{ | 143 | use crate::utils::{ |
| 144 | center, center_f64, get_monotonic_time, ipc_transform_to_smithay, logical_output, | 144 | center, center_f64, get_monotonic_time, ipc_transform_to_smithay, logical_output, |
| 145 | - make_screenshot_path, output_size, send_scale_transform, write_png_rgba8, | 145 | + make_screenshot_path, output_matches_name, output_size, send_scale_transform, write_png_rgba8, |
| 146 | }; | 146 | }; |
| 147 | use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef}; | 147 | use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef}; |
| 148 | use crate::{animation, niri_render_elements}; | 148 | use crate::{animation, niri_render_elements}; |
| @@ -198,7 +198,6 @@ pub struct Niri { | |||
| 198 | pub blocker_cleared_rx: Receiver<Client>, | 198 | pub blocker_cleared_rx: Receiver<Client>, |
| 199 | 199 | ||
| 200 | pub output_state: HashMap<Output, OutputState>, | 200 | pub output_state: HashMap<Output, OutputState>, |
| 201 | - pub output_by_name: HashMap<String, Output>, | ||
| 202 | 201 | ||
| 203 | // When false, we're idling with monitors powered off. | 202 | // When false, we're idling with monitors powered off. |
| 204 | pub monitors_active: bool, | 203 | pub monitors_active: bool, |
| @@ -1121,9 +1120,9 @@ impl State { | |||
| 1121 | let mut recolored_outputs = vec![]; | 1120 | let mut recolored_outputs = vec![]; |
| 1122 | 1121 | ||
| 1123 | for output in self.niri.global_space.outputs() { | 1122 | for output in self.niri.global_space.outputs() { |
| 1124 | - let name = output.name(); | 1123 | + let name = output.user_data().get::<OutputName>().unwrap(); |
| 1125 | let config = self.niri.config.borrow_mut(); | 1124 | let config = self.niri.config.borrow_mut(); |
| 1126 | - let config = config.outputs.find(&name); | 1125 | + let config = config.outputs.find(name); |
| 1127 | 1126 | ||
| 1128 | let scale = config | 1127 | let scale = config |
| 1129 | .and_then(|c| c.scale) | 1128 | .and_then(|c| c.scale) |
| @@ -1139,7 +1138,7 @@ impl State { | |||
| 1139 | .map(|c| ipc_transform_to_smithay(c.transform)) | 1138 | .map(|c| ipc_transform_to_smithay(c.transform)) |
| 1140 | .unwrap_or(Transform::Normal); | 1139 | .unwrap_or(Transform::Normal); |
| 1141 | // FIXME: fix winit damage on other transforms. | 1140 | // FIXME: fix winit damage on other transforms. |
| 1142 | - if name == "winit" { | 1141 | + if name.connector == "winit" { |
| 1143 | transform = Transform::Flipped180; | 1142 | transform = Transform::Flipped180; |
| 1144 | } | 1143 | } |
| 1145 | 1144 | ||
| @@ -1193,11 +1192,36 @@ impl State { | |||
| 1193 | 1192 | ||
| 1194 | pub fn apply_transient_output_config(&mut self, name: &str, action: niri_ipc::OutputAction) { | 1193 | pub fn apply_transient_output_config(&mut self, name: &str, action: niri_ipc::OutputAction) { |
| 1195 | { | 1194 | { |
| 1195 | + // Try hard to find the output config section corresponding to the output set by the | ||
| 1196 | + // user. Since if we add a new section and some existing section also matches the | ||
| 1197 | + // output, then our new section won't do anything. | ||
| 1198 | + let temp; | ||
| 1199 | + let match_name = if let Some(output) = self.niri.output_by_name_match(name) { | ||
| 1200 | + output.user_data().get::<OutputName>().unwrap() | ||
| 1201 | + } else if let Some(output_name) = self | ||
| 1202 | + .backend | ||
| 1203 | + .tty_checked() | ||
| 1204 | + .and_then(|tty| tty.disconnected_connector_name_by_name_match(name)) | ||
| 1205 | + { | ||
| 1206 | + temp = output_name; | ||
| 1207 | + &temp | ||
| 1208 | + } else { | ||
| 1209 | + // Even if name is "make model serial", matching will work fine this way. | ||
| 1210 | + temp = OutputName { | ||
| 1211 | + connector: name.to_owned(), | ||
| 1212 | + make: None, | ||
| 1213 | + model: None, | ||
| 1214 | + serial: None, | ||
| 1215 | + }; | ||
| 1216 | + &temp | ||
| 1217 | + }; | ||
| 1218 | + | ||
| 1196 | let mut config = self.niri.config.borrow_mut(); | 1219 | let mut config = self.niri.config.borrow_mut(); |
| 1197 | - let config = if let Some(config) = config.outputs.find_mut(name) { | 1220 | + let config = if let Some(config) = config.outputs.find_mut(match_name) { |
| 1198 | config | 1221 | config |
| 1199 | } else { | 1222 | } else { |
| 1200 | config.outputs.0.push(niri_config::Output { | 1223 | config.outputs.0.push(niri_config::Output { |
| 1224 | + // Save name as set by the user. | ||
| 1201 | name: String::from(name), | 1225 | name: String::from(name), |
| 1202 | ..Default::default() | 1226 | ..Default::default() |
| 1203 | }); | 1227 | }); |
| @@ -1759,7 +1783,6 @@ impl Niri { | |||
| 1759 | layout, | 1783 | layout, |
| 1760 | global_space: Space::default(), | 1784 | global_space: Space::default(), |
| 1761 | output_state: HashMap::new(), | 1785 | output_state: HashMap::new(), |
| 1762 | - output_by_name: HashMap::new(), | ||
| 1763 | unmapped_windows: HashMap::new(), | 1786 | unmapped_windows: HashMap::new(), |
| 1764 | root_surface: HashMap::new(), | 1787 | root_surface: HashMap::new(), |
| 1765 | dmabuf_pre_commit_hook: HashMap::new(), | 1788 | dmabuf_pre_commit_hook: HashMap::new(), |
| @@ -1892,13 +1915,13 @@ impl Niri { | |||
| 1892 | let config = self.config.borrow(); | 1915 | let config = self.config.borrow(); |
| 1893 | let mut outputs = vec![]; | 1916 | let mut outputs = vec![]; |
| 1894 | for output in self.global_space.outputs().chain(new_output) { | 1917 | for output in self.global_space.outputs().chain(new_output) { |
| 1895 | - let name = output.name(); | 1918 | + let name = output.user_data().get::<OutputName>().unwrap(); |
| 1896 | let position = self.global_space.output_geometry(output).map(|geo| geo.loc); | 1919 | let position = self.global_space.output_geometry(output).map(|geo| geo.loc); |
| 1897 | - let config = config.outputs.find(&name).and_then(|c| c.position); | 1920 | + let config = config.outputs.find(name).and_then(|c| c.position); |
| 1898 | 1921 | ||
| 1899 | outputs.push(Data { | 1922 | outputs.push(Data { |
| 1900 | output: output.clone(), | 1923 | output: output.clone(), |
| 1901 | - name, | 1924 | + name: name.connector.clone(), |
| 1902 | position, | 1925 | position, |
| 1903 | config, | 1926 | config, |
| 1904 | }); | 1927 | }); |
| @@ -1996,10 +2019,10 @@ impl Niri { | |||
| 1996 | pub fn add_output(&mut self, output: Output, refresh_interval: Option<Duration>, vrr: bool) { | 2019 | pub fn add_output(&mut self, output: Output, refresh_interval: Option<Duration>, vrr: bool) { |
| 1997 | let global = output.create_global::<State>(&self.display_handle); | 2020 | let global = output.create_global::<State>(&self.display_handle); |
| 1998 | 2021 | ||
| 1999 | - let name = output.name(); | 2022 | + let name = output.user_data().get::<OutputName>().unwrap(); |
| 2000 | 2023 | ||
| 2001 | let config = self.config.borrow(); | 2024 | let config = self.config.borrow(); |
| 2002 | - let c = config.outputs.find(&name); | 2025 | + let c = config.outputs.find(name); |
| 2003 | let scale = c.and_then(|c| c.scale).map(|s| s.0).unwrap_or_else(|| { | 2026 | let scale = c.and_then(|c| c.scale).map(|s| s.0).unwrap_or_else(|| { |
| 2004 | let size_mm = output.physical_properties().size; | 2027 | let size_mm = output.physical_properties().size; |
| 2005 | let resolution = output.current_mode().unwrap().size; | 2028 | let resolution = output.current_mode().unwrap().size; |
| @@ -2018,7 +2041,7 @@ impl Niri { | |||
| 2018 | background_color[3] = 1.; | 2041 | background_color[3] = 1.; |
| 2019 | 2042 | ||
| 2020 | // FIXME: fix winit damage on other transforms. | 2043 | // FIXME: fix winit damage on other transforms. |
| 2021 | - if name == "winit" { | 2044 | + if name.connector == "winit" { |
| 2022 | transform = Transform::Flipped180; | 2045 | transform = Transform::Flipped180; |
| 2023 | } | 2046 | } |
| 2024 | drop(config); | 2047 | drop(config); |
| @@ -2058,8 +2081,6 @@ impl Niri { | |||
| 2058 | }; | 2081 | }; |
| 2059 | let rv = self.output_state.insert(output.clone(), state); | 2082 | let rv = self.output_state.insert(output.clone(), state); |
| 2060 | assert!(rv.is_none(), "output was already tracked"); | 2083 | assert!(rv.is_none(), "output was already tracked"); |
| 2061 | - let rv = self.output_by_name.insert(name, output.clone()); | ||
| 2062 | - assert!(rv.is_none(), "output was already tracked"); | ||
| 2063 | 2084 | ||
| 2064 | // Must be last since it will call queue_redraw(output) which needs things to be filled-in. | 2085 | // Must be last since it will call queue_redraw(output) which needs things to be filled-in. |
| 2065 | self.reposition_outputs(Some(&output)); | 2086 | self.reposition_outputs(Some(&output)); |
| @@ -2076,7 +2097,6 @@ impl Niri { | |||
| 2076 | self.gamma_control_manager_state.output_removed(output); | 2097 | self.gamma_control_manager_state.output_removed(output); |
| 2077 | 2098 | ||
| 2078 | let state = self.output_state.remove(output).unwrap(); | 2099 | let state = self.output_state.remove(output).unwrap(); |
| 2079 | - self.output_by_name.remove(&output.name()).unwrap(); | ||
| 2080 | 2100 | ||
| 2081 | match state.redraw_state { | 2101 | match state.redraw_state { |
| 2082 | RedrawState::Idle => (), | 2102 | RedrawState::Idle => (), |
| @@ -2412,13 +2432,6 @@ impl Niri { | |||
| 2412 | .cloned() | 2432 | .cloned() |
| 2413 | } | 2433 | } |
| 2414 | 2434 | ||
| 2415 | - pub fn output_by_name(&self, name: &str) -> Option<Output> { | ||
| 2416 | - self.global_space | ||
| 2417 | - .outputs() | ||
| 2418 | - .find(|output| output.name().eq_ignore_ascii_case(name)) | ||
| 2419 | - .cloned() | ||
| 2420 | - } | ||
| 2421 | - | ||
| 2422 | pub fn find_output_and_workspace_index( | 2435 | pub fn find_output_and_workspace_index( |
| 2423 | &self, | 2436 | &self, |
| 2424 | workspace_reference: WorkspaceReference, | 2437 | workspace_reference: WorkspaceReference, |
| @@ -2465,17 +2478,23 @@ impl Niri { | |||
| 2465 | pub fn output_for_tablet(&self) -> Option<&Output> { | 2478 | pub fn output_for_tablet(&self) -> Option<&Output> { |
| 2466 | let config = self.config.borrow(); | 2479 | let config = self.config.borrow(); |
| 2467 | let map_to_output = config.input.tablet.map_to_output.as_ref(); | 2480 | let map_to_output = config.input.tablet.map_to_output.as_ref(); |
| 2468 | - map_to_output.and_then(|name| self.output_by_name.get(name)) | 2481 | + map_to_output.and_then(|name| self.output_by_name_match(name)) |
| 2469 | } | 2482 | } |
| 2470 | 2483 | ||
| 2471 | pub fn output_for_touch(&self) -> Option<&Output> { | 2484 | pub fn output_for_touch(&self) -> Option<&Output> { |
| 2472 | let config = self.config.borrow(); | 2485 | let config = self.config.borrow(); |
| 2473 | let map_to_output = config.input.touch.map_to_output.as_ref(); | 2486 | let map_to_output = config.input.touch.map_to_output.as_ref(); |
| 2474 | map_to_output | 2487 | map_to_output |
| 2475 | - .and_then(|name| self.output_by_name.get(name)) | 2488 | + .and_then(|name| self.output_by_name_match(name)) |
| 2476 | .or_else(|| self.global_space.outputs().next()) | 2489 | .or_else(|| self.global_space.outputs().next()) |
| 2477 | } | 2490 | } |
| 2478 | 2491 | ||
| 2492 | + pub fn output_by_name_match(&self, target: &str) -> Option<&Output> { | ||
| 2493 | + self.global_space | ||
| 2494 | + .outputs() | ||
| 2495 | + .find(|output| output_matches_name(output, target)) | ||
| 2496 | + } | ||
| 2497 | + | ||
| 2479 | pub fn output_for_root(&self, root: &WlSurface) -> Option<&Output> { | 2498 | pub fn output_for_root(&self, root: &WlSurface) -> Option<&Output> { |
| 2480 | // Check the main layout. | 2499 | // Check the main layout. |
| 2481 | let win_out = self.layout.find_window_and_output(root); | 2500 | let win_out = self.layout.find_window_and_output(root); |
| @@ -3177,11 +3196,13 @@ impl Niri { | |||
| 3177 | 3196 | ||
| 3178 | pub fn refresh_on_demand_vrr(&mut self, backend: &mut Backend, output: &Output) { | 3197 | pub fn refresh_on_demand_vrr(&mut self, backend: &mut Backend, output: &Output) { |
| 3179 | let _span = tracy_client::span!("Niri::refresh_on_demand_vrr"); | 3198 | let _span = tracy_client::span!("Niri::refresh_on_demand_vrr"); |
| 3199 | + | ||
| 3200 | + let name = output.user_data().get::<OutputName>().unwrap(); | ||
| 3180 | let Some(on_demand) = self | 3201 | let Some(on_demand) = self |
| 3181 | .config | 3202 | .config |
| 3182 | .borrow() | 3203 | .borrow() |
| 3183 | .outputs | 3204 | .outputs |
| 3184 | - .find(&output.name()) | 3205 | + .find(name) |
| 3185 | .map(|output| output.is_vrr_on_demand()) | 3206 | .map(|output| output.is_vrr_on_demand()) |
| 3186 | else { | 3207 | else { |
| 3187 | warn!("error getting output config for {}", output.name()); | 3208 | warn!("error getting output config for {}", output.name()); |
src/protocols/output_management.rsmodified+13 -5
| @@ -3,7 +3,7 @@ use std::collections::HashMap; | |||
| 3 | use std::iter::zip; | 3 | use std::iter::zip; |
| 4 | use std::mem; | 4 | use std::mem; |
| 5 | 5 | ||
| 6 | -use niri_config::{FloatOrInt, Vrr}; | 6 | +use niri_config::{FloatOrInt, OutputName, Vrr}; |
| 7 | use niri_ipc::Transform; | 7 | use niri_ipc::Transform; |
| 8 | use smithay::reexports::wayland_protocols_wlr::output_management::v1::server::{ | 8 | use smithay::reexports::wayland_protocols_wlr::output_management::v1::server::{ |
| 9 | zwlr_output_configuration_head_v1, zwlr_output_configuration_v1, zwlr_output_head_v1, | 9 | zwlr_output_configuration_head_v1, zwlr_output_configuration_v1, zwlr_output_head_v1, |
| @@ -403,12 +403,13 @@ where | |||
| 403 | return; | 403 | return; |
| 404 | } | 404 | } |
| 405 | Entry::Vacant(entry) => { | 405 | Entry::Vacant(entry) => { |
| 406 | + let name = OutputName::from_ipc_output(current_config); | ||
| 406 | let mut config = g_state | 407 | let mut config = g_state |
| 407 | .current_config | 408 | .current_config |
| 408 | - .find(¤t_config.name) | 409 | + .find(&name) |
| 409 | .cloned() | 410 | .cloned() |
| 410 | .unwrap_or_else(|| niri_config::Output { | 411 | .unwrap_or_else(|| niri_config::Output { |
| 411 | - name: current_config.name.clone(), | 412 | + name: name.format_make_model_serial_or_connector(), |
| 412 | ..Default::default() | 413 | ..Default::default() |
| 413 | }); | 414 | }); |
| 414 | config.off = false; | 415 | config.off = false; |
| @@ -452,12 +453,13 @@ where | |||
| 452 | ); | 453 | ); |
| 453 | } | 454 | } |
| 454 | Entry::Vacant(entry) => { | 455 | Entry::Vacant(entry) => { |
| 456 | + let name = OutputName::from_ipc_output(current_config); | ||
| 455 | let mut config = g_state | 457 | let mut config = g_state |
| 456 | .current_config | 458 | .current_config |
| 457 | - .find(¤t_config.name) | 459 | + .find(&name) |
| 458 | .cloned() | 460 | .cloned() |
| 459 | .unwrap_or_else(|| niri_config::Output { | 461 | .unwrap_or_else(|| niri_config::Output { |
| 460 | - name: current_config.name.clone(), | 462 | + name: name.format_make_model_serial_or_connector(), |
| 461 | ..Default::default() | 463 | ..Default::default() |
| 462 | }); | 464 | }); |
| 463 | config.off = true; | 465 | config.off = true; |
| @@ -841,6 +843,7 @@ fn send_new_head<D>( | |||
| 841 | .unwrap(); | 843 | .unwrap(); |
| 842 | client_data.manager.head(&new_head); | 844 | client_data.manager.head(&new_head); |
| 843 | new_head.name(conf.name.clone()); | 845 | new_head.name(conf.name.clone()); |
| 846 | + // Format matches what Output::new() does internally. | ||
| 844 | new_head.description(format!("{} - {} - {}", conf.make, conf.model, conf.name)); | 847 | new_head.description(format!("{} - {} - {}", conf.make, conf.model, conf.name)); |
| 845 | if let Some((width, height)) = conf.physical_size { | 848 | if let Some((width, height)) = conf.physical_size { |
| 846 | if let (Ok(a), Ok(b)) = (width.try_into(), height.try_into()) { | 849 | if let (Ok(a), Ok(b)) = (width.try_into(), height.try_into()) { |
| @@ -877,6 +880,11 @@ fn send_new_head<D>( | |||
| 877 | if new_head.version() >= zwlr_output_head_v1::EVT_MODEL_SINCE { | 880 | if new_head.version() >= zwlr_output_head_v1::EVT_MODEL_SINCE { |
| 878 | new_head.model(conf.model.clone()); | 881 | new_head.model(conf.model.clone()); |
| 879 | } | 882 | } |
| 883 | + if new_head.version() >= zwlr_output_head_v1::EVT_SERIAL_NUMBER_SINCE { | ||
| 884 | + if let Some(serial) = &conf.serial { | ||
| 885 | + new_head.serial_number(serial.clone()); | ||
| 886 | + } | ||
| 887 | + } | ||
| 880 | 888 | ||
| 881 | if new_head.version() >= zwlr_output_head_v1::EVT_ADAPTIVE_SYNC_SINCE { | 889 | if new_head.version() >= zwlr_output_head_v1::EVT_ADAPTIVE_SYNC_SINCE { |
| 882 | new_head.adaptive_sync(match conf.vrr_enabled { | 890 | new_head.adaptive_sync(match conf.vrr_enabled { |
src/utils/mod.rsmodified+6 -1
| @@ -10,7 +10,7 @@ use anyhow::{ensure, Context}; | |||
| 10 | use bitflags::bitflags; | 10 | use bitflags::bitflags; |
| 11 | use directories::UserDirs; | 11 | use directories::UserDirs; |
| 12 | use git_version::git_version; | 12 | use git_version::git_version; |
| 13 | -use niri_config::Config; | 13 | +use niri_config::{Config, OutputName}; |
| 14 | use smithay::input::pointer::CursorIcon; | 14 | use smithay::input::pointer::CursorIcon; |
| 15 | use smithay::output::{self, Output}; | 15 | use smithay::output::{self, Output}; |
| 16 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; | 16 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; |
| @@ -216,6 +216,11 @@ pub fn write_png_rgba8( | |||
| 216 | writer.write_image_data(pixels) | 216 | writer.write_image_data(pixels) |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | +pub fn output_matches_name(output: &Output, target: &str) -> bool { | ||
| 220 | + let name = output.user_data().get::<OutputName>().unwrap(); | ||
| 221 | + name.matches(target) | ||
| 222 | +} | ||
| 223 | + | ||
| 219 | #[cfg(feature = "dbus")] | 224 | #[cfg(feature = "dbus")] |
| 220 | pub fn show_screenshot_notification(image_path: Option<PathBuf>) { | 225 | pub fn show_screenshot_notification(image_path: Option<PathBuf>) { |
| 221 | let mut notification = notify_rust::Notification::new(); | 226 | let mut notification = notify_rust::Notification::new(); |
wiki/Configuration:-Named-Workspaces.mdmodified+1 -1
| @@ -8,7 +8,7 @@ You can declare named workspaces at the top level of the config: | |||
| 8 | workspace "browser" | 8 | workspace "browser" |
| 9 | 9 | ||
| 10 | workspace "chat" { | 10 | workspace "chat" { |
| 11 | - open-on-output "DP-2" | 11 | + open-on-output "Some Company CoolMonitor 1234" |
| 12 | } | 12 | } |
| 13 | ``` | 13 | ``` |
| 14 | 14 | ||
wiki/Configuration:-Outputs.mdmodified+10 -2
| @@ -19,14 +19,22 @@ output "eDP-1" { | |||
| 19 | output "HDMI-A-1" { | 19 | output "HDMI-A-1" { |
| 20 | // ...settings for HDMI-A-1... | 20 | // ...settings for HDMI-A-1... |
| 21 | } | 21 | } |
| 22 | + | ||
| 23 | +output "Some Company CoolMonitor 1234" { | ||
| 24 | + // ...settings for CoolMonitor... | ||
| 25 | +} | ||
| 22 | ``` | 26 | ``` |
| 23 | 27 | ||
| 24 | -Outputs are matched by connector name (i.e. `eDP-1`, `HDMI-A-1`) which you can find by running `niri msg outputs`. | 28 | +Outputs are matched by connector name (i.e. `eDP-1`, `HDMI-A-1`), or by monitor manufacturer, model, and serial, separated by a single space each. |
| 29 | +You can find all of these by running `niri msg outputs`. | ||
| 30 | + | ||
| 25 | Usually, the built-in monitor in laptops will be called `eDP-1`. | 31 | Usually, the built-in monitor in laptops will be called `eDP-1`. |
| 26 | -Matching by output manufacturer and model is planned, but blocked on Smithay adopting libdisplay-info instead of edid-rs. | ||
| 27 | 32 | ||
| 28 | <sup>Since: 0.1.6</sup> The output name is case-insensitive. | 33 | <sup>Since: 0.1.6</sup> The output name is case-insensitive. |
| 29 | 34 | ||
| 35 | +<sup>Since: 0.1.9</sup> Outputs can be matched by manufacturer, model, and serial. | ||
| 36 | +Before, they could be matched only by the connector name. | ||
| 37 | + | ||
| 30 | ### `off` | 38 | ### `off` |
| 31 | 39 | ||
| 32 | This flag turns off that output entirely. | 40 | This flag turns off that output entirely. |
wiki/Configuration:-Window-Rules.mdmodified+3 -1
| @@ -37,7 +37,7 @@ window-rule { | |||
| 37 | 37 | ||
| 38 | // Properties that apply once upon window opening. | 38 | // Properties that apply once upon window opening. |
| 39 | default-column-width { proportion 0.75; } | 39 | default-column-width { proportion 0.75; } |
| 40 | - open-on-output "eDP-1" | 40 | + open-on-output "Some Company CoolMonitor 1234" |
| 41 | open-on-workspace "chat" | 41 | open-on-workspace "chat" |
| 42 | open-maximized true | 42 | open-maximized true |
| 43 | open-fullscreen true | 43 | open-fullscreen true |
| @@ -252,6 +252,8 @@ window-rule { | |||
| 252 | exclude app-id=r#"^org\.telegram\.desktop$"# title="^Media viewer$" | 252 | exclude app-id=r#"^org\.telegram\.desktop$"# title="^Media viewer$" |
| 253 | 253 | ||
| 254 | open-on-output "HDMI-A-1" | 254 | open-on-output "HDMI-A-1" |
| 255 | + // Or: | ||
| 256 | + // open-on-output "Some Company CoolMonitor 1234" | ||
| 255 | } | 257 | } |
| 256 | ``` | 258 | ``` |
| 257 | 259 | ||