From 109668fa30bf65e56a2723ff29bcadc3e9a6e4ca Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 21 Sep 2023 13:48:32 +0400 Subject: Add output configuration & integer scaling support --- src/backend/tty.rs | 16 ++++++++++++++-- src/backend/winit.rs | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'src/backend') diff --git a/src/backend/tty.rs b/src/backend/tty.rs index 9f126507..bce16ff0 100644 --- a/src/backend/tty.rs +++ b/src/backend/tty.rs @@ -21,7 +21,7 @@ use smithay::backend::session::libseat::LibSeatSession; use smithay::backend::session::{Event as SessionEvent, Session}; use smithay::backend::udev::{self, UdevBackend, UdevEvent}; use smithay::desktop::utils::OutputPresentationFeedback; -use smithay::output::{Mode, Output, OutputModeSource, PhysicalProperties, Subpixel}; +use smithay::output::{Mode, Output, OutputModeSource, PhysicalProperties, Subpixel, Scale}; use smithay::reexports::calloop::{Dispatcher, LoopHandle, RegistrationToken}; use smithay::reexports::drm::control::{ connector, crtc, Mode as DrmMode, ModeFlags, ModeTypeFlags, @@ -500,6 +500,15 @@ impl Tty { ); debug!("connecting connector: {output_name}"); + let config = self + .config + .borrow() + .outputs + .iter() + .find(|o| o.name == output_name) + .cloned() + .unwrap_or_default(); + let device = self.output_device.as_mut().unwrap(); let mut mode = connector.modes().get(0); @@ -534,6 +543,9 @@ impl Tty { .map(|info| (info.manufacturer, info.model)) .unwrap_or_else(|| ("Unknown".into(), "Unknown".into())); + let scale = config.scale.clamp(0.1, 10.); + let scale = scale.max(1.).round() as i32; + let output = Output::new( output_name.clone(), PhysicalProperties { @@ -544,7 +556,7 @@ impl Tty { }, ); let wl_mode = Mode::from(*mode); - output.change_current_state(Some(wl_mode), None, None, Some((0, 0).into())); + output.change_current_state(Some(wl_mode), None, Some(Scale::Integer(scale)), None); output.set_preferred(wl_mode); output.user_data().insert_if_missing(|| TtyOutputState { diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 9f591e71..99cfe7db 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -8,7 +8,7 @@ use smithay::backend::renderer::damage::OutputDamageTracker; use smithay::backend::renderer::gles::GlesRenderer; use smithay::backend::renderer::{DebugFlags, Renderer}; use smithay::backend::winit::{self, WinitError, WinitEvent, WinitGraphicsBackend}; -use smithay::output::{Mode, Output, PhysicalProperties, Subpixel}; +use smithay::output::{Mode, Output, PhysicalProperties, Scale, Subpixel}; use smithay::reexports::calloop::timer::{TimeoutAction, Timer}; use smithay::reexports::calloop::LoopHandle; use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback; @@ -38,6 +38,16 @@ impl Winit { .with_title("niri"); let (backend, mut winit_event_loop) = winit::init_from_builder(builder).unwrap(); + let output_config = config + .borrow() + .outputs + .iter() + .find(|o| o.name == "winit") + .cloned() + .unwrap_or_default(); + let scale = output_config.scale.clamp(0.1, 10.); + let scale = scale.max(1.).round() as i32; + let mode = Mode { size: backend.window_size().physical_size, refresh: 60_000, @@ -55,8 +65,8 @@ impl Winit { output.change_current_state( Some(mode), Some(Transform::Flipped180), + Some(Scale::Integer(scale)), None, - Some((0, 0).into()), ); output.set_preferred(mode); -- cgit