Add logical output info and preferred modes to IPC
Browse files at this commitcf87a185a90aeacf7c15d27ddba23bc493d9c2ddParent: e276c9010 changed files +224 -76
- niri-ipc/src/lib.rs +47 -0
- src/backend/mod.rs +1 -1
- src/backend/tty.rs +6 -4
- src/backend/winit.rs +21 -17
- src/dbus/mutter_display_config.rs +23 -23
- src/dbus/mutter_screen_cast.rs +18 -10
- src/ipc/client.rs +47 -4
- src/ipc/server.rs +1 -5
- src/niri.rs +36 -11
- src/utils/mod.rs +24 -1
niri-ipc/src/lib.rsmodified+47 -0
| @@ -248,6 +248,10 @@ pub struct Output { | |||
| 248 | /// | 248 | /// |
| 249 | /// `None` if the output is disabled. | 249 | /// `None` if the output is disabled. |
| 250 | pub current_mode: Option<usize>, | 250 | pub current_mode: Option<usize>, |
| 251 | + /// Logical output information. | ||
| 252 | + /// | ||
| 253 | + /// `None` if the output is not mapped to any logical output (for example, if it is disabled). | ||
| 254 | + pub logical: Option<LogicalOutput>, | ||
| 251 | } | 255 | } |
| 252 | 256 | ||
| 253 | /// Output mode. | 257 | /// Output mode. |
| @@ -259,6 +263,49 @@ pub struct Mode { | |||
| 259 | pub height: u16, | 263 | pub height: u16, |
| 260 | /// Refresh rate in millihertz. | 264 | /// Refresh rate in millihertz. |
| 261 | pub refresh_rate: u32, | 265 | pub refresh_rate: u32, |
| 266 | + /// Whether this mode is preferred by the monitor. | ||
| 267 | + pub is_preferred: bool, | ||
| 268 | +} | ||
| 269 | + | ||
| 270 | +/// Logical output in the compositor's coordinate space. | ||
| 271 | +#[derive(Debug, Serialize, Deserialize, Clone, Copy)] | ||
| 272 | +pub struct LogicalOutput { | ||
| 273 | + /// Logical X position. | ||
| 274 | + pub x: i32, | ||
| 275 | + /// Logical Y position. | ||
| 276 | + pub y: i32, | ||
| 277 | + /// Width in logical pixels. | ||
| 278 | + pub width: u32, | ||
| 279 | + /// Height in logical pixels. | ||
| 280 | + pub height: u32, | ||
| 281 | + /// Scale factor. | ||
| 282 | + pub scale: f64, | ||
| 283 | + /// Transform. | ||
| 284 | + pub transform: Transform, | ||
| 285 | +} | ||
| 286 | + | ||
| 287 | +/// Output transform, which goes counter-clockwise. | ||
| 288 | +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] | ||
| 289 | +pub enum Transform { | ||
| 290 | + /// Untransformed. | ||
| 291 | + Normal, | ||
| 292 | + /// Rotated by 90°. | ||
| 293 | + #[serde(rename = "90")] | ||
| 294 | + _90, | ||
| 295 | + /// Rotated by 180°. | ||
| 296 | + #[serde(rename = "180")] | ||
| 297 | + _180, | ||
| 298 | + /// Rotated by 270°. | ||
| 299 | + #[serde(rename = "270")] | ||
| 300 | + _270, | ||
| 301 | + /// Flipped horizontally. | ||
| 302 | + Flipped, | ||
| 303 | + /// Rotated by 90° and flipped horizontally. | ||
| 304 | + Flipped90, | ||
| 305 | + /// Flipped vertically. | ||
| 306 | + Flipped180, | ||
| 307 | + /// Rotated by 270° and flipped horizontally. | ||
| 308 | + Flipped270, | ||
| 262 | } | 309 | } |
| 263 | 310 | ||
| 264 | impl FromStr for SizeChange { | 311 | impl FromStr for SizeChange { |
src/backend/mod.rsmodified+1 -1
| @@ -31,7 +31,7 @@ pub enum RenderResult { | |||
| 31 | Skipped, | 31 | Skipped, |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | -pub type IpcOutputMap = HashMap<String, (niri_ipc::Output, Option<Output>)>; | 34 | +pub type IpcOutputMap = HashMap<String, niri_ipc::Output>; |
| 35 | 35 | ||
| 36 | impl Backend { | 36 | impl Backend { |
| 37 | pub fn init(&mut self, niri: &mut Niri) { | 37 | pub fn init(&mut self, niri: &mut Niri) { |
src/backend/tty.rsmodified+6 -4
| @@ -60,7 +60,7 @@ use crate::frame_clock::FrameClock; | |||
| 60 | use crate::niri::{Niri, RedrawState, State}; | 60 | use crate::niri::{Niri, RedrawState, State}; |
| 61 | use crate::render_helpers::renderer::AsGlesRenderer; | 61 | use crate::render_helpers::renderer::AsGlesRenderer; |
| 62 | use crate::render_helpers::{shaders, RenderTarget}; | 62 | use crate::render_helpers::{shaders, RenderTarget}; |
| 63 | -use crate::utils::get_monotonic_time; | 63 | +use crate::utils::{get_monotonic_time, logical_output}; |
| 64 | 64 | ||
| 65 | const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888]; | 65 | const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888]; |
| 66 | 66 | ||
| @@ -1370,6 +1370,7 @@ impl Tty { | |||
| 1370 | width: m.size().0, | 1370 | width: m.size().0, |
| 1371 | height: m.size().1, | 1371 | height: m.size().1, |
| 1372 | refresh_rate: Mode::from(*m).refresh as u32, | 1372 | refresh_rate: Mode::from(*m).refresh as u32, |
| 1373 | + is_preferred: m.mode_type().contains(ModeTypeFlags::PREFERRED), | ||
| 1373 | } | 1374 | } |
| 1374 | }) | 1375 | }) |
| 1375 | .collect(); | 1376 | .collect(); |
| @@ -1384,14 +1385,14 @@ impl Tty { | |||
| 1384 | } | 1385 | } |
| 1385 | } | 1386 | } |
| 1386 | 1387 | ||
| 1387 | - let output = niri | 1388 | + let logical = niri |
| 1388 | .global_space | 1389 | .global_space |
| 1389 | .outputs() | 1390 | .outputs() |
| 1390 | .find(|output| { | 1391 | .find(|output| { |
| 1391 | let tty_state: &TtyOutputState = output.user_data().get().unwrap(); | 1392 | let tty_state: &TtyOutputState = output.user_data().get().unwrap(); |
| 1392 | tty_state.node == *node && tty_state.crtc == crtc | 1393 | tty_state.node == *node && tty_state.crtc == crtc |
| 1393 | }) | 1394 | }) |
| 1394 | - .cloned(); | 1395 | + .map(logical_output); |
| 1395 | 1396 | ||
| 1396 | let ipc_output = niri_ipc::Output { | 1397 | let ipc_output = niri_ipc::Output { |
| 1397 | name: connector_name.clone(), | 1398 | name: connector_name.clone(), |
| @@ -1400,9 +1401,10 @@ impl Tty { | |||
| 1400 | physical_size, | 1401 | physical_size, |
| 1401 | modes, | 1402 | modes, |
| 1402 | current_mode, | 1403 | current_mode, |
| 1404 | + logical, | ||
| 1403 | }; | 1405 | }; |
| 1404 | 1406 | ||
| 1405 | - ipc_outputs.insert(connector_name, (ipc_output, output)); | 1407 | + ipc_outputs.insert(connector_name, ipc_output); |
| 1406 | } | 1408 | } |
| 1407 | } | 1409 | } |
| 1408 | 1410 | ||
src/backend/winit.rsmodified+21 -17
| @@ -20,7 +20,7 @@ use smithay::reexports::winit::window::WindowBuilder; | |||
| 20 | use super::{IpcOutputMap, RenderResult}; | 20 | use super::{IpcOutputMap, RenderResult}; |
| 21 | use crate::niri::{Niri, RedrawState, State}; | 21 | use crate::niri::{Niri, RedrawState, State}; |
| 22 | use crate::render_helpers::{shaders, RenderTarget}; | 22 | use crate::render_helpers::{shaders, RenderTarget}; |
| 23 | -use crate::utils::get_monotonic_time; | 23 | +use crate::utils::{get_monotonic_time, logical_output}; |
| 24 | 24 | ||
| 25 | pub struct Winit { | 25 | pub struct Winit { |
| 26 | config: Rc<RefCell<Config>>, | 26 | config: Rc<RefCell<Config>>, |
| @@ -61,21 +61,20 @@ impl Winit { | |||
| 61 | let physical_properties = output.physical_properties(); | 61 | let physical_properties = output.physical_properties(); |
| 62 | let ipc_outputs = Arc::new(Mutex::new(HashMap::from([( | 62 | let ipc_outputs = Arc::new(Mutex::new(HashMap::from([( |
| 63 | "winit".to_owned(), | 63 | "winit".to_owned(), |
| 64 | - ( | 64 | + niri_ipc::Output { |
| 65 | - niri_ipc::Output { | 65 | + name: output.name(), |
| 66 | - name: output.name(), | 66 | + make: physical_properties.make, |
| 67 | - make: physical_properties.make, | 67 | + model: physical_properties.model, |
| 68 | - model: physical_properties.model, | 68 | + physical_size: None, |
| 69 | - physical_size: None, | 69 | + modes: vec![niri_ipc::Mode { |
| 70 | - modes: vec![niri_ipc::Mode { | 70 | + width: backend.window_size().w.clamp(0, u16::MAX as i32) as u16, |
| 71 | - width: backend.window_size().w.clamp(0, u16::MAX as i32) as u16, | 71 | + height: backend.window_size().h.clamp(0, u16::MAX as i32) as u16, |
| 72 | - height: backend.window_size().h.clamp(0, u16::MAX as i32) as u16, | 72 | + refresh_rate: 60_000, |
| 73 | - refresh_rate: 60_000, | 73 | + is_preferred: true, |
| 74 | - }], | 74 | + }], |
| 75 | - current_mode: Some(0), | 75 | + current_mode: Some(0), |
| 76 | - }, | 76 | + logical: Some(logical_output(&output)), |
| 77 | - Some(output.clone()), | 77 | + }, |
| 78 | - ), | ||
| 79 | )]))); | 78 | )]))); |
| 80 | 79 | ||
| 81 | let damage_tracker = OutputDamageTracker::from_output(&output); | 80 | let damage_tracker = OutputDamageTracker::from_output(&output); |
| @@ -96,9 +95,14 @@ impl Winit { | |||
| 96 | 95 | ||
| 97 | { | 96 | { |
| 98 | let mut ipc_outputs = winit.ipc_outputs.lock().unwrap(); | 97 | let mut ipc_outputs = winit.ipc_outputs.lock().unwrap(); |
| 99 | - let mode = &mut ipc_outputs.get_mut("winit").unwrap().0.modes[0]; | 98 | + let output = ipc_outputs.get_mut("winit").unwrap(); |
| 99 | + let mode = &mut output.modes[0]; | ||
| 100 | mode.width = size.w.clamp(0, u16::MAX as i32) as u16; | 100 | mode.width = size.w.clamp(0, u16::MAX as i32) as u16; |
| 101 | mode.height = size.h.clamp(0, u16::MAX as i32) as u16; | 101 | mode.height = size.h.clamp(0, u16::MAX as i32) as u16; |
| 102 | + if let Some(logical) = output.logical.as_mut() { | ||
| 103 | + logical.width = size.w as u32; | ||
| 104 | + logical.height = size.h as u32; | ||
| 105 | + } | ||
| 102 | state.niri.ipc_outputs_changed = true; | 106 | state.niri.ipc_outputs_changed = true; |
| 103 | } | 107 | } |
| 104 | 108 | ||
src/dbus/mutter_display_config.rsmodified+23 -23
| @@ -2,7 +2,6 @@ use std::collections::HashMap; | |||
| 2 | use std::sync::{Arc, Mutex}; | 2 | use std::sync::{Arc, Mutex}; |
| 3 | 3 | ||
| 4 | use serde::Serialize; | 4 | use serde::Serialize; |
| 5 | -use smithay::utils::Transform; | ||
| 6 | use zbus::fdo::RequestNameFlags; | 5 | use zbus::fdo::RequestNameFlags; |
| 7 | use zbus::zvariant::{self, OwnedValue, Type}; | 6 | use zbus::zvariant::{self, OwnedValue, Type}; |
| 8 | use zbus::{dbus_interface, fdo, SignalContext}; | 7 | use zbus::{dbus_interface, fdo, SignalContext}; |
| @@ -60,11 +59,8 @@ impl DisplayConfig { | |||
| 60 | .unwrap() | 59 | .unwrap() |
| 61 | .iter() | 60 | .iter() |
| 62 | // Take only enabled outputs. | 61 | // Take only enabled outputs. |
| 63 | - .filter_map(|(c, (ipc, output))| { | 62 | + .filter(|(_, output)| output.current_mode.is_some() && output.logical.is_some()) |
| 64 | - ipc.current_mode?; | 63 | + .map(|(c, output)| { |
| 65 | - output.as_ref().map(move |output| (c, (ipc, output))) | ||
| 66 | - }) | ||
| 67 | - .map(|(c, (ipc, output))| { | ||
| 68 | // Loosely matches the check in Mutter. | 64 | // Loosely matches the check in Mutter. |
| 69 | let is_laptop_panel = matches!(c.get(..4), Some("eDP-" | "LVDS" | "DSI-")); | 65 | let is_laptop_panel = matches!(c.get(..4), Some("eDP-" | "LVDS" | "DSI-")); |
| 70 | 66 | ||
| @@ -84,7 +80,7 @@ impl DisplayConfig { | |||
| 84 | OwnedValue::from(is_laptop_panel), | 80 | OwnedValue::from(is_laptop_panel), |
| 85 | ); | 81 | ); |
| 86 | 82 | ||
| 87 | - let mut modes: Vec<Mode> = ipc | 83 | + let mut modes: Vec<Mode> = output |
| 88 | .modes | 84 | .modes |
| 89 | .iter() | 85 | .iter() |
| 90 | .map(|m| { | 86 | .map(|m| { |
| @@ -92,6 +88,7 @@ impl DisplayConfig { | |||
| 92 | width, | 88 | width, |
| 93 | height, | 89 | height, |
| 94 | refresh_rate, | 90 | refresh_rate, |
| 91 | + is_preferred, | ||
| 95 | } = *m; | 92 | } = *m; |
| 96 | let refresh = refresh_rate as f64 / 1000.; | 93 | let refresh = refresh_rate as f64 / 1000.; |
| 97 | 94 | ||
| @@ -102,11 +99,14 @@ impl DisplayConfig { | |||
| 102 | refresh_rate: refresh, | 99 | refresh_rate: refresh, |
| 103 | preferred_scale: 1., | 100 | preferred_scale: 1., |
| 104 | supported_scales: vec![1., 2., 3.], | 101 | supported_scales: vec![1., 2., 3.], |
| 105 | - properties: HashMap::new(), | 102 | + properties: HashMap::from([( |
| 103 | + String::from("is-preferred"), | ||
| 104 | + OwnedValue::from(is_preferred), | ||
| 105 | + )]), | ||
| 106 | } | 106 | } |
| 107 | }) | 107 | }) |
| 108 | .collect(); | 108 | .collect(); |
| 109 | - modes[ipc.current_mode.unwrap()] | 109 | + modes[output.current_mode.unwrap()] |
| 110 | .properties | 110 | .properties |
| 111 | .insert(String::from("is-current"), OwnedValue::from(true)); | 111 | .insert(String::from("is-current"), OwnedValue::from(true)); |
| 112 | 112 | ||
| @@ -116,23 +116,23 @@ impl DisplayConfig { | |||
| 116 | properties, | 116 | properties, |
| 117 | }; | 117 | }; |
| 118 | 118 | ||
| 119 | - let loc = output.current_location(); | 119 | + let logical = output.logical.as_ref().unwrap(); |
| 120 | - | 120 | + |
| 121 | - let transform = match output.current_transform() { | 121 | + let transform = match logical.transform { |
| 122 | - Transform::Normal => 0, | 122 | + niri_ipc::Transform::Normal => 0, |
| 123 | - Transform::_90 => 1, | 123 | + niri_ipc::Transform::_90 => 1, |
| 124 | - Transform::_180 => 2, | 124 | + niri_ipc::Transform::_180 => 2, |
| 125 | - Transform::_270 => 3, | 125 | + niri_ipc::Transform::_270 => 3, |
| 126 | - Transform::Flipped => 4, | 126 | + niri_ipc::Transform::Flipped => 4, |
| 127 | - Transform::Flipped90 => 5, | 127 | + niri_ipc::Transform::Flipped90 => 5, |
| 128 | - Transform::Flipped180 => 6, | 128 | + niri_ipc::Transform::Flipped180 => 6, |
| 129 | - Transform::Flipped270 => 7, | 129 | + niri_ipc::Transform::Flipped270 => 7, |
| 130 | }; | 130 | }; |
| 131 | 131 | ||
| 132 | let logical_monitor = LogicalMonitor { | 132 | let logical_monitor = LogicalMonitor { |
| 133 | - x: loc.x, | 133 | + x: logical.x, |
| 134 | - y: loc.y, | 134 | + y: logical.y, |
| 135 | - scale: output.current_scale().fractional_scale(), | 135 | + scale: logical.scale, |
| 136 | transform, | 136 | transform, |
| 137 | is_primary: false, | 137 | is_primary: false, |
| 138 | monitors: vec![monitor.names.clone()], | 138 | monitors: vec![monitor.names.clone()], |
src/dbus/mutter_screen_cast.rsmodified+18 -10
| @@ -11,7 +11,6 @@ use zbus::{dbus_interface, fdo, InterfaceRef, ObjectServer, SignalContext}; | |||
| 11 | 11 | ||
| 12 | use super::Start; | 12 | use super::Start; |
| 13 | use crate::backend::IpcOutputMap; | 13 | use crate::backend::IpcOutputMap; |
| 14 | -use crate::utils::output_size; | ||
| 15 | 14 | ||
| 16 | #[derive(Clone)] | 15 | #[derive(Clone)] |
| 17 | pub struct ScreenCast { | 16 | pub struct ScreenCast { |
| @@ -49,7 +48,8 @@ struct RecordMonitorProperties { | |||
| 49 | 48 | ||
| 50 | #[derive(Clone)] | 49 | #[derive(Clone)] |
| 51 | pub struct Stream { | 50 | pub struct Stream { |
| 52 | - output: Output, | 51 | + // FIXME: update on scale changes and whatnot. |
| 52 | + output: niri_ipc::Output, | ||
| 53 | cursor_mode: CursorMode, | 53 | cursor_mode: CursorMode, |
| 54 | was_started: Arc<AtomicBool>, | 54 | was_started: Arc<AtomicBool>, |
| 55 | to_niri: calloop::channel::Sender<ScreenCastToNiri>, | 55 | to_niri: calloop::channel::Sender<ScreenCastToNiri>, |
| @@ -58,6 +58,8 @@ pub struct Stream { | |||
| 58 | #[derive(Debug, SerializeDict, Type, Value)] | 58 | #[derive(Debug, SerializeDict, Type, Value)] |
| 59 | #[zvariant(signature = "dict")] | 59 | #[zvariant(signature = "dict")] |
| 60 | struct StreamParameters { | 60 | struct StreamParameters { |
| 61 | + /// Position of the stream in logical coordinates. | ||
| 62 | + position: (i32, i32), | ||
| 61 | /// Size of the stream in logical coordinates. | 63 | /// Size of the stream in logical coordinates. |
| 62 | size: (i32, i32), | 64 | size: (i32, i32), |
| 63 | } | 65 | } |
| @@ -65,7 +67,7 @@ struct StreamParameters { | |||
| 65 | pub enum ScreenCastToNiri { | 67 | pub enum ScreenCastToNiri { |
| 66 | StartCast { | 68 | StartCast { |
| 67 | session_id: usize, | 69 | session_id: usize, |
| 68 | - output: Output, | 70 | + output: String, |
| 69 | cursor_mode: CursorMode, | 71 | cursor_mode: CursorMode, |
| 70 | signal_ctx: SignalContext<'static>, | 72 | signal_ctx: SignalContext<'static>, |
| 71 | }, | 73 | }, |
| @@ -160,11 +162,14 @@ impl Session { | |||
| 160 | ) -> fdo::Result<OwnedObjectPath> { | 162 | ) -> fdo::Result<OwnedObjectPath> { |
| 161 | debug!(connector, ?properties, "record_monitor"); | 163 | debug!(connector, ?properties, "record_monitor"); |
| 162 | 164 | ||
| 163 | - let Some((_, Some(output))) = self.ipc_outputs.lock().unwrap().get(connector).cloned() | 165 | + let Some(output) = self.ipc_outputs.lock().unwrap().get(connector).cloned() else { |
| 164 | - else { | ||
| 165 | return Err(fdo::Error::Failed("no such monitor".to_owned())); | 166 | return Err(fdo::Error::Failed("no such monitor".to_owned())); |
| 166 | }; | 167 | }; |
| 167 | 168 | ||
| 169 | + if output.logical.is_none() { | ||
| 170 | + return Err(fdo::Error::Failed("monitor is disabled".to_owned())); | ||
| 171 | + } | ||
| 172 | + | ||
| 168 | static NUMBER: AtomicUsize = AtomicUsize::new(0); | 173 | static NUMBER: AtomicUsize = AtomicUsize::new(0); |
| 169 | let path = format!( | 174 | let path = format!( |
| 170 | "/org/gnome/Mutter/ScreenCast/Stream/u{}", | 175 | "/org/gnome/Mutter/ScreenCast/Stream/u{}", |
| @@ -174,7 +179,7 @@ impl Session { | |||
| 174 | 179 | ||
| 175 | let cursor_mode = properties.cursor_mode.unwrap_or_default(); | 180 | let cursor_mode = properties.cursor_mode.unwrap_or_default(); |
| 176 | 181 | ||
| 177 | - let stream = Stream::new(output, cursor_mode, self.to_niri.clone()); | 182 | + let stream = Stream::new(output.clone(), cursor_mode, self.to_niri.clone()); |
| 178 | match server.at(&path, stream.clone()).await { | 183 | match server.at(&path, stream.clone()).await { |
| 179 | Ok(true) => { | 184 | Ok(true) => { |
| 180 | let iface = server.interface(&path).await.unwrap(); | 185 | let iface = server.interface(&path).await.unwrap(); |
| @@ -203,8 +208,11 @@ impl Stream { | |||
| 203 | 208 | ||
| 204 | #[dbus_interface(property)] | 209 | #[dbus_interface(property)] |
| 205 | async fn parameters(&self) -> StreamParameters { | 210 | async fn parameters(&self) -> StreamParameters { |
| 206 | - let size = output_size(&self.output).into(); | 211 | + let logical = self.output.logical.as_ref().unwrap(); |
| 207 | - StreamParameters { size } | 212 | + StreamParameters { |
| 213 | + position: (logical.x, logical.y), | ||
| 214 | + size: (logical.width as i32, logical.height as i32), | ||
| 215 | + } | ||
| 208 | } | 216 | } |
| 209 | } | 217 | } |
| 210 | 218 | ||
| @@ -261,7 +269,7 @@ impl Drop for Session { | |||
| 261 | 269 | ||
| 262 | impl Stream { | 270 | impl Stream { |
| 263 | pub fn new( | 271 | pub fn new( |
| 264 | - output: Output, | 272 | + output: niri_ipc::Output, |
| 265 | cursor_mode: CursorMode, | 273 | cursor_mode: CursorMode, |
| 266 | to_niri: calloop::channel::Sender<ScreenCastToNiri>, | 274 | to_niri: calloop::channel::Sender<ScreenCastToNiri>, |
| 267 | ) -> Self { | 275 | ) -> Self { |
| @@ -280,7 +288,7 @@ impl Stream { | |||
| 280 | 288 | ||
| 281 | let msg = ScreenCastToNiri::StartCast { | 289 | let msg = ScreenCastToNiri::StartCast { |
| 282 | session_id, | 290 | session_id, |
| 283 | - output: self.output.clone(), | 291 | + output: self.output.name.clone(), |
| 284 | cursor_mode: self.cursor_mode, | 292 | cursor_mode: self.cursor_mode, |
| 285 | signal_ctx: ctxt, | 293 | signal_ctx: ctxt, |
| 286 | }; | 294 | }; |
src/ipc/client.rsmodified+47 -4
| @@ -4,7 +4,7 @@ use std::net::Shutdown; | |||
| 4 | use std::os::unix::net::UnixStream; | 4 | use std::os::unix::net::UnixStream; |
| 5 | 5 | ||
| 6 | use anyhow::{anyhow, bail, Context}; | 6 | use anyhow::{anyhow, bail, Context}; |
| 7 | -use niri_ipc::{Mode, Output, Reply, Request, Response}; | 7 | +use niri_ipc::{LogicalOutput, Mode, Output, Reply, Request, Response}; |
| 8 | 8 | ||
| 9 | use crate::cli::Msg; | 9 | use crate::cli::Msg; |
| 10 | 10 | ||
| @@ -66,6 +66,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | |||
| 66 | physical_size, | 66 | physical_size, |
| 67 | modes, | 67 | modes, |
| 68 | current_mode, | 68 | current_mode, |
| 69 | + logical, | ||
| 69 | } = output; | 70 | } = output; |
| 70 | 71 | ||
| 71 | println!(r#"Output "{connector}" ({make} - {model} - {name})"#); | 72 | println!(r#"Output "{connector}" ({make} - {model} - {name})"#); |
| @@ -78,9 +79,11 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | |||
| 78 | width, | 79 | width, |
| 79 | height, | 80 | height, |
| 80 | refresh_rate, | 81 | refresh_rate, |
| 82 | + is_preferred, | ||
| 81 | } = mode; | 83 | } = mode; |
| 82 | let refresh = refresh_rate as f64 / 1000.; | 84 | let refresh = refresh_rate as f64 / 1000.; |
| 83 | - println!(" Current mode: {width}x{height} @ {refresh:.3} Hz"); | 85 | + let preferred = if is_preferred { " (preferred)" } else { "" }; |
| 86 | + println!(" Current mode: {width}x{height} @ {refresh:.3} Hz{preferred}"); | ||
| 84 | } else { | 87 | } else { |
| 85 | println!(" Disabled"); | 88 | println!(" Disabled"); |
| 86 | } | 89 | } |
| @@ -91,15 +94,55 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | |||
| 91 | println!(" Physical size: unknown"); | 94 | println!(" Physical size: unknown"); |
| 92 | } | 95 | } |
| 93 | 96 | ||
| 97 | + if let Some(logical) = logical { | ||
| 98 | + let LogicalOutput { | ||
| 99 | + x, | ||
| 100 | + y, | ||
| 101 | + width, | ||
| 102 | + height, | ||
| 103 | + scale, | ||
| 104 | + transform, | ||
| 105 | + } = logical; | ||
| 106 | + println!(" Logical position: {x}, {y}"); | ||
| 107 | + println!(" Logical size: {width}x{height}"); | ||
| 108 | + println!(" Scale: {scale}"); | ||
| 109 | + | ||
| 110 | + let transform = match transform { | ||
| 111 | + niri_ipc::Transform::Normal => "normal", | ||
| 112 | + niri_ipc::Transform::_90 => "90° counter-clockwise", | ||
| 113 | + niri_ipc::Transform::_180 => "180°", | ||
| 114 | + niri_ipc::Transform::_270 => "270° counter-clockwise", | ||
| 115 | + niri_ipc::Transform::Flipped => "flipped horizontally", | ||
| 116 | + niri_ipc::Transform::Flipped90 => { | ||
| 117 | + "90° counter-clockwise, flipped horizontally" | ||
| 118 | + } | ||
| 119 | + niri_ipc::Transform::Flipped180 => "flipped vertically", | ||
| 120 | + niri_ipc::Transform::Flipped270 => { | ||
| 121 | + "270° counter-clockwise, flipped horizontally" | ||
| 122 | + } | ||
| 123 | + }; | ||
| 124 | + println!(" Transform: {transform}"); | ||
| 125 | + } | ||
| 126 | + | ||
| 94 | println!(" Available modes:"); | 127 | println!(" Available modes:"); |
| 95 | - for mode in modes { | 128 | + for (idx, mode) in modes.into_iter().enumerate() { |
| 96 | let Mode { | 129 | let Mode { |
| 97 | width, | 130 | width, |
| 98 | height, | 131 | height, |
| 99 | refresh_rate, | 132 | refresh_rate, |
| 133 | + is_preferred, | ||
| 100 | } = mode; | 134 | } = mode; |
| 101 | let refresh = refresh_rate as f64 / 1000.; | 135 | let refresh = refresh_rate as f64 / 1000.; |
| 102 | - println!(" {width}x{height}@{refresh:.3}"); | 136 | + |
| 137 | + let is_current = Some(idx) == current_mode; | ||
| 138 | + let qualifier = match (is_current, is_preferred) { | ||
| 139 | + (true, true) => " (current, preferred)", | ||
| 140 | + (true, false) => " (current)", | ||
| 141 | + (false, true) => " (preferred)", | ||
| 142 | + (false, false) => "", | ||
| 143 | + }; | ||
| 144 | + | ||
| 145 | + println!(" {width}x{height}@{refresh:.3}{qualifier}"); | ||
| 103 | } | 146 | } |
| 104 | println!(); | 147 | println!(); |
| 105 | } | 148 | } |
src/ipc/server.rsmodified+1 -5
| @@ -125,11 +125,7 @@ fn process(ctx: &ClientCtx, buf: &str) -> anyhow::Result<Response> { | |||
| 125 | 125 | ||
| 126 | let response = match request { | 126 | let response = match request { |
| 127 | Request::Outputs => { | 127 | Request::Outputs => { |
| 128 | - let ipc_outputs = ctx.ipc_outputs.lock().unwrap(); | 128 | + let ipc_outputs = ctx.ipc_outputs.lock().unwrap().clone(); |
| 129 | - let ipc_outputs = ipc_outputs | ||
| 130 | - .iter() | ||
| 131 | - .map(|(name, (ipc, _))| (name.clone(), ipc.clone())) | ||
| 132 | - .collect(); | ||
| 133 | Response::Outputs(ipc_outputs) | 129 | Response::Outputs(ipc_outputs) |
| 134 | } | 130 | } |
| 135 | Request::Action(action) => { | 131 | Request::Action(action) => { |
src/niri.rsmodified+36 -11
| @@ -115,7 +115,8 @@ use crate::ui::hotkey_overlay::HotkeyOverlay; | |||
| 115 | use crate::ui::screenshot_ui::{ScreenshotUi, ScreenshotUiRenderElement}; | 115 | use crate::ui::screenshot_ui::{ScreenshotUi, ScreenshotUiRenderElement}; |
| 116 | use crate::utils::spawning::CHILD_ENV; | 116 | use crate::utils::spawning::CHILD_ENV; |
| 117 | use crate::utils::{ | 117 | use crate::utils::{ |
| 118 | - center, center_f64, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8, | 118 | + center, center_f64, get_monotonic_time, logical_output, make_screenshot_path, output_size, |
| 119 | + write_png_rgba8, | ||
| 119 | }; | 120 | }; |
| 120 | use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef}; | 121 | use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef}; |
| 121 | use crate::{animation, niri_render_elements}; | 122 | use crate::{animation, niri_render_elements}; |
| @@ -459,7 +460,7 @@ impl State { | |||
| 459 | self.refresh_pointer_focus(); | 460 | self.refresh_pointer_focus(); |
| 460 | foreign_toplevel::refresh(self); | 461 | foreign_toplevel::refresh(self); |
| 461 | self.niri.refresh_window_rules(); | 462 | self.niri.refresh_window_rules(); |
| 462 | - self.niri.check_ipc_output_changed(); | 463 | + self.refresh_ipc_outputs(); |
| 463 | } | 464 | } |
| 464 | 465 | ||
| 465 | pub fn move_cursor(&mut self, location: Point<f64, Logical>) { | 466 | pub fn move_cursor(&mut self, location: Point<f64, Logical>) { |
| @@ -967,6 +968,28 @@ impl State { | |||
| 967 | self.niri.queue_redraw_all(); | 968 | self.niri.queue_redraw_all(); |
| 968 | } | 969 | } |
| 969 | 970 | ||
| 971 | + pub fn refresh_ipc_outputs(&mut self) { | ||
| 972 | + if !self.niri.ipc_outputs_changed { | ||
| 973 | + return; | ||
| 974 | + } | ||
| 975 | + self.niri.ipc_outputs_changed = false; | ||
| 976 | + | ||
| 977 | + let _span = tracy_client::span!("State::refresh_ipc_outputs"); | ||
| 978 | + | ||
| 979 | + for (name, ipc_output) in self.backend.ipc_outputs().lock().unwrap().iter_mut() { | ||
| 980 | + let logical = self | ||
| 981 | + .niri | ||
| 982 | + .global_space | ||
| 983 | + .outputs() | ||
| 984 | + .find(|output| output.name() == *name) | ||
| 985 | + .map(logical_output); | ||
| 986 | + ipc_output.logical = logical; | ||
| 987 | + } | ||
| 988 | + | ||
| 989 | + #[cfg(feature = "dbus")] | ||
| 990 | + self.niri.on_ipc_outputs_changed(); | ||
| 991 | + } | ||
| 992 | + | ||
| 970 | #[cfg(feature = "xdp-gnome-screencast")] | 993 | #[cfg(feature = "xdp-gnome-screencast")] |
| 971 | pub fn on_screen_cast_msg( | 994 | pub fn on_screen_cast_msg( |
| 972 | &mut self, | 995 | &mut self, |
| @@ -997,6 +1020,17 @@ impl State { | |||
| 997 | return; | 1020 | return; |
| 998 | }; | 1021 | }; |
| 999 | 1022 | ||
| 1023 | + let Some(output) = self | ||
| 1024 | + .niri | ||
| 1025 | + .global_space | ||
| 1026 | + .outputs() | ||
| 1027 | + .find(|out| out.name() == output) | ||
| 1028 | + .cloned() | ||
| 1029 | + else { | ||
| 1030 | + warn!("tried to start a screencast on missing output: {output}"); | ||
| 1031 | + return; | ||
| 1032 | + }; | ||
| 1033 | + | ||
| 1000 | match pw.start_cast( | 1034 | match pw.start_cast( |
| 1001 | to_niri.clone(), | 1035 | to_niri.clone(), |
| 1002 | gbm, | 1036 | gbm, |
| @@ -3438,15 +3472,6 @@ impl Niri { | |||
| 3438 | }); | 3472 | }); |
| 3439 | } | 3473 | } |
| 3440 | 3474 | ||
| 3441 | - pub fn check_ipc_output_changed(&mut self) { | ||
| 3442 | - if self.ipc_outputs_changed { | ||
| 3443 | - self.ipc_outputs_changed = false; | ||
| 3444 | - | ||
| 3445 | - #[cfg(feature = "dbus")] | ||
| 3446 | - self.on_ipc_outputs_changed(); | ||
| 3447 | - } | ||
| 3448 | - } | ||
| 3449 | - | ||
| 3450 | #[cfg(feature = "dbus")] | 3475 | #[cfg(feature = "dbus")] |
| 3451 | pub fn on_ipc_outputs_changed(&self) { | 3476 | pub fn on_ipc_outputs_changed(&self) { |
| 3452 | let _span = tracy_client::span!("Niri::on_ipc_outputs_changed"); | 3477 | let _span = tracy_client::span!("Niri::on_ipc_outputs_changed"); |
src/utils/mod.rsmodified+24 -1
| @@ -12,7 +12,7 @@ use git_version::git_version; | |||
| 12 | use niri_config::Config; | 12 | use niri_config::Config; |
| 13 | use smithay::output::Output; | 13 | use smithay::output::Output; |
| 14 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; | 14 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; |
| 15 | -use smithay::utils::{Logical, Point, Rectangle, Size}; | 15 | +use smithay::utils::{Logical, Point, Rectangle, Size, Transform}; |
| 16 | 16 | ||
| 17 | pub mod id; | 17 | pub mod id; |
| 18 | pub mod spawning; | 18 | pub mod spawning; |
| @@ -51,6 +51,29 @@ pub fn output_size(output: &Output) -> Size<i32, Logical> { | |||
| 51 | .to_logical(output_scale) | 51 | .to_logical(output_scale) |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | +pub fn logical_output(output: &Output) -> niri_ipc::LogicalOutput { | ||
| 55 | + let loc = output.current_location(); | ||
| 56 | + let size = output_size(output); | ||
| 57 | + let transform = match output.current_transform() { | ||
| 58 | + Transform::Normal => niri_ipc::Transform::Normal, | ||
| 59 | + Transform::_90 => niri_ipc::Transform::_90, | ||
| 60 | + Transform::_180 => niri_ipc::Transform::_180, | ||
| 61 | + Transform::_270 => niri_ipc::Transform::_270, | ||
| 62 | + Transform::Flipped => niri_ipc::Transform::Flipped, | ||
| 63 | + Transform::Flipped90 => niri_ipc::Transform::Flipped90, | ||
| 64 | + Transform::Flipped180 => niri_ipc::Transform::Flipped180, | ||
| 65 | + Transform::Flipped270 => niri_ipc::Transform::Flipped270, | ||
| 66 | + }; | ||
| 67 | + niri_ipc::LogicalOutput { | ||
| 68 | + x: loc.x, | ||
| 69 | + y: loc.y, | ||
| 70 | + width: size.w as u32, | ||
| 71 | + height: size.h as u32, | ||
| 72 | + scale: output.current_scale().fractional_scale(), | ||
| 73 | + transform, | ||
| 74 | + } | ||
| 75 | +} | ||
| 76 | + | ||
| 54 | pub fn expand_home(path: &Path) -> anyhow::Result<Option<PathBuf>> { | 77 | pub fn expand_home(path: &Path) -> anyhow::Result<Option<PathBuf>> { |
| 55 | if let Ok(rest) = path.strip_prefix("~") { | 78 | if let Ok(rest) = path.strip_prefix("~") { |
| 56 | let dirs = UserDirs::new().context("error retrieving home directory")?; | 79 | let dirs = UserDirs::new().context("error retrieving home directory")?; |