From b229c80717d1162aae5916377a31263f2bad14e4 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Fri, 16 May 2025 00:28:07 -0400 Subject: [PATCH] fix(display): Show revert dialog iff mode changed Closes: #1190 RandR may revert or not apply invalid mode changes. The revert dialog shouldn't show in these cases. --- cosmic-settings/src/pages/display/mod.rs | 30 +++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/cosmic-settings/src/pages/display/mod.rs b/cosmic-settings/src/pages/display/mod.rs index d740d38..6a52e81 100644 --- a/cosmic-settings/src/pages/display/mod.rs +++ b/cosmic-settings/src/pages/display/mod.rs @@ -74,7 +74,7 @@ pub enum Message { DialogCancel, /// The dialog was completed. DialogComplete, - /// How long until the dialog automatically cancelles, in seconds. + /// How long until the dialog automatically cancels, in seconds. DialogCountdown, /// Toggles display on or off. DisplayToggle(bool), @@ -475,6 +475,34 @@ impl Page { Message::RandrResult(result) => { if let Some(Err(why)) = Arc::into_inner(result) { tracing::error!(why = why.to_string(), "cosmic-randr error"); + // Cancel the revert dialog if resolution or refresh rate did not change. + // RandR may revert those changes in certain circumstances so showing the + // dialog is superfluous and confusing. + if let Some(mode) = + self.list + .outputs + .get(self.active_display) + .and_then(|display| { + display.current.and_then(|key| self.list.modes.get(key)) + }) + { + tracing::debug!(old = ?self.dialog, new = ?mode, "Mode update"); + match self.dialog { + Some(Randr::Resolution(width, height)) => { + if mode.size.0 == width && mode.size.1 == height { + self.config.resolution = Some((width, height)); + return self.update(Message::DialogComplete); + } + } + Some(Randr::RefreshRate(rate)) => { + if mode.refresh_rate == rate { + self.config.refresh_rate = Some(rate); + return self.update(Message::DialogComplete); + } + } + _ => {} + } + } } }