From fb107f2e76f57ba6b53cc9dbeafb10454feaa51b Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Fri, 2 Feb 2024 08:17:03 +0100 Subject: [PATCH] Respect preferred output modes Connector mode selection now respects the `ModeTypeFlags::PREFERRED` mode type. Closes #144. --- src/udev.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/udev.rs b/src/udev.rs index 9744eeb..2641755 100644 --- a/src/udev.rs +++ b/src/udev.rs @@ -37,7 +37,7 @@ use smithay::reexports::drm::control::connector::{Info as ConnectorInfo, State a use smithay::reexports::drm::control::property::{ Handle as PropertyHandle, Value as PropertyValue, }; -use smithay::reexports::drm::control::{Device, Mode as DrmMode, ResourceHandles}; +use smithay::reexports::drm::control::{Device, Mode as DrmMode, ModeTypeFlags, ResourceHandles}; use smithay::reexports::input::Libinput; use smithay::reexports::rustix::fs::OFlags; use smithay::reexports::wayland_protocols::wp::linux_dmabuf as _linux_dmabuf; @@ -437,10 +437,14 @@ impl Udev { .ok() .filter(|conn| conn.state() == ConnectorState::Connected) })?; - let connector_mode = *connector.modes().first()?; + let modes = connector.modes(); + let connector_mode = modes + .iter() + .find(|mode| mode.mode_type().contains(ModeTypeFlags::PREFERRED)) + .unwrap_or(modes.first()?); // Create DRM surface. - let surface = Self::create_surface(drm, resources, &connector, connector_mode)?; + let surface = Self::create_surface(drm, resources, &connector, *connector_mode)?; // Create GBM allocator. let gbm_flags = GbmBufferFlags::RENDERING | GbmBufferFlags::SCANOUT;