Move output_size to utils
Browse files at this commit461ce5f3631c99e928280935d92f084f4b641b9eParent: 624c7994 changed files +18 -14
- src/handlers/mod.rs +1 -1
- src/layout/mod.rs +1 -10
- src/niri.rs +4 -2
- src/utils.rs +12 -1
src/handlers/mod.rsmodified+1 -1
| @@ -43,8 +43,8 @@ use smithay::{ | |||
| 43 | delegate_text_input_manager, delegate_virtual_keyboard_manager, | 43 | delegate_text_input_manager, delegate_virtual_keyboard_manager, |
| 44 | }; | 44 | }; |
| 45 | 45 | ||
| 46 | -use crate::layout::output_size; | ||
| 47 | use crate::niri::State; | 46 | use crate::niri::State; |
| 47 | +use crate::utils::output_size; | ||
| 48 | 48 | ||
| 49 | impl SeatHandler for State { | 49 | impl SeatHandler for State { |
| 50 | type KeyboardFocus = WlSurface; | 50 | type KeyboardFocus = WlSurface; |
src/layout/mod.rsmodified+1 -10
| @@ -57,6 +57,7 @@ use smithay::wayland::shell::xdg::SurfaceCachedState; | |||
| 57 | 57 | ||
| 58 | use crate::animation::Animation; | 58 | use crate::animation::Animation; |
| 59 | use crate::config::{self, Color, Config, PresetWidth, SizeChange, Struts}; | 59 | use crate::config::{self, Color, Config, PresetWidth, SizeChange, Struts}; |
| 60 | +use crate::utils::output_size; | ||
| 60 | 61 | ||
| 61 | #[derive(Debug, Clone, PartialEq, Eq)] | 62 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 62 | pub struct OutputId(String); | 63 | pub struct OutputId(String); |
| @@ -3264,16 +3265,6 @@ impl<W: LayoutElement> Column<W> { | |||
| 3264 | } | 3265 | } |
| 3265 | } | 3266 | } |
| 3266 | 3267 | ||
| 3267 | -pub fn output_size(output: &Output) -> Size<i32, Logical> { | ||
| 3268 | - let output_scale = output.current_scale().integer_scale(); | ||
| 3269 | - let output_transform = output.current_transform(); | ||
| 3270 | - let output_mode = output.current_mode().unwrap(); | ||
| 3271 | - | ||
| 3272 | - output_transform | ||
| 3273 | - .transform_size(output_mode.size) | ||
| 3274 | - .to_logical(output_scale) | ||
| 3275 | -} | ||
| 3276 | - | ||
| 3277 | fn compute_working_area(output: &Output, struts: Struts) -> Rectangle<i32, Logical> { | 3268 | fn compute_working_area(output: &Output, struts: Struts) -> Rectangle<i32, Logical> { |
| 3278 | // Start with the layer-shell non-exclusive zone. | 3269 | // Start with the layer-shell non-exclusive zone. |
| 3279 | let mut working_area = layer_map_for_output(output).non_exclusive_zone(); | 3270 | let mut working_area = layer_map_for_output(output).non_exclusive_zone(); |
src/niri.rsmodified+4 -2
| @@ -90,10 +90,12 @@ use crate::dbus::mutter_screen_cast::{self, ScreenCastToNiri}; | |||
| 90 | use crate::frame_clock::FrameClock; | 90 | use crate::frame_clock::FrameClock; |
| 91 | use crate::handlers::configure_lock_surface; | 91 | use crate::handlers::configure_lock_surface; |
| 92 | use crate::input::TabletData; | 92 | use crate::input::TabletData; |
| 93 | -use crate::layout::{output_size, Layout, MonitorRenderElement}; | 93 | +use crate::layout::{Layout, MonitorRenderElement}; |
| 94 | use crate::pw_utils::{Cast, PipeWire}; | 94 | use crate::pw_utils::{Cast, PipeWire}; |
| 95 | use crate::screenshot_ui::{ScreenshotUi, ScreenshotUiRenderElement}; | 95 | use crate::screenshot_ui::{ScreenshotUi, ScreenshotUiRenderElement}; |
| 96 | -use crate::utils::{center, get_monotonic_time, make_screenshot_path, write_png_rgba8}; | 96 | +use crate::utils::{ |
| 97 | + center, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8, | ||
| 98 | +}; | ||
| 97 | 99 | ||
| 98 | const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.]; | 100 | const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.]; |
| 99 | const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.]; | 101 | const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.]; |
src/utils.rsmodified+12 -1
| @@ -11,8 +11,9 @@ use std::time::Duration; | |||
| 11 | 11 | ||
| 12 | use anyhow::{ensure, Context}; | 12 | use anyhow::{ensure, Context}; |
| 13 | use directories::UserDirs; | 13 | use directories::UserDirs; |
| 14 | +use smithay::output::Output; | ||
| 14 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; | 15 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; |
| 15 | -use smithay::utils::{Logical, Point, Rectangle}; | 16 | +use smithay::utils::{Logical, Point, Rectangle, Size}; |
| 16 | 17 | ||
| 17 | use crate::config::Config; | 18 | use crate::config::Config; |
| 18 | 19 | ||
| @@ -25,6 +26,16 @@ pub fn center(rect: Rectangle<i32, Logical>) -> Point<i32, Logical> { | |||
| 25 | rect.loc + rect.size.downscale(2).to_point() | 26 | rect.loc + rect.size.downscale(2).to_point() |
| 26 | } | 27 | } |
| 27 | 28 | ||
| 29 | +pub fn output_size(output: &Output) -> Size<i32, Logical> { | ||
| 30 | + let output_scale = output.current_scale().integer_scale(); | ||
| 31 | + let output_transform = output.current_transform(); | ||
| 32 | + let output_mode = output.current_mode().unwrap(); | ||
| 33 | + | ||
| 34 | + output_transform | ||
| 35 | + .transform_size(output_mode.size) | ||
| 36 | + .to_logical(output_scale) | ||
| 37 | +} | ||
| 38 | + | ||
| 28 | pub fn make_screenshot_path(config: &Config) -> anyhow::Result<Option<PathBuf>> { | 39 | pub fn make_screenshot_path(config: &Config) -> anyhow::Result<Option<PathBuf>> { |
| 29 | let Some(path) = &config.screenshot_path else { | 40 | let Some(path) = &config.screenshot_path else { |
| 30 | return Ok(None); | 41 | return Ok(None); |