Skip to content

wallpapers/image: strict slideshow intervals

Original commit message(s)

  • wallpapers/image: strict slideshow intervals

Reason for the change

Issues

  1. Slideshow timers run on each desktop separately and currently start once each desktop is loaded for the first time or when the slideshow was (re)started manually.

    If the user has multiple screens/desktops and multiple activities set up, then these slideshow timers can start to desync or already are running asynchronously, causing the next wallpaper transitions to start with a noticable offset, even if the user has configured each desktop to have the same slideshow timings. This is especially annoying when using multiple screens. On different activities, this might not be noticable immediately, but can still be annoying if the user expects the wallpapers to change all at the same time.

  2. Since the timers depend on when the desktop was loaded for the first time (e.g. after logging into the desktop session or when switching to a new activity) or when the slideshow was (re)started manually, this means that the start of the timer is arbitrary/random. This further means that the next transition will be unpredictable despite the user knowing their configured slideshow timer, unless they are also aware when the timer was started. A wallpaper transition at exact points in time synchronized accross all desktops resolves this unpredictability.

Solution

This change synchronizes the ImageBackend's m_timer accross all desktops by aligning it to strict m_delay intervals since UNIX epoch, which fixes both of the mentioned issues.

However, in order to be able to start the next wallpaper transition exactly at the same time accross all desktops, the QTimer m_timer timer type needs to be changed from Qt:CoarseTimer to Qt::PreciseTimer. Otherwise, the timers will deviate. Qt::PreciseTimer apparently isn't enough though, so this patch also adds a tiny offset of 10ms to the timer's duration in order to avoid having it sometimes trigger a few milliseconds too early, causing the following transition to trigger during the animation of the current transition (always 1 second), resulting in visual glitches.

I don't know if the timer type change causes issues in regards to CPU idle/sleep states or if this is negligible in this case:
https://doc.qt.io/qt-6/qt.html#TimerType-enum

On UNIX (including Linux, macOS, and iOS), Qt will keep millisecond accuracy for Qt::PreciseTimer. For Qt::CoarseTimer, the interval will be adjusted up to 5% to align the timer with other timers that are expected to fire at or around the same time. The objective is to make most timers wake up at the same time, thereby reducing CPU wakeups and power consumption.

Test plan

I tested these changes by temporarily adding debug log messages with all the timing values, and then running multiple slideshows on my desktops in various time intervals. This is how I noticed the QTimer issues and the additionally required offset.

I've been running these exact changes for a few months now and I never noticed any issues. I'm unaware of any existing test cases that could be extended here.

Screenshots or screen recordings

-

Bugs fixed

BUG: 480643


Btw, I'm not a C++/Qt developer, so I'm very much unfamiliar with this, the project's requirements, as well as the overall implementation of ImageBackend and the wallpaper slideshows. This patch is merely the result of me being annoyed by async slideshow timers, digging through the code and applying a quick patch for personal use. I'm opening this MR as a draft now because of Nate Graham's suggestion on the bug tracker. If there are any nontrivial follow-up requests for changes, I probably won't be able to implement them myself, so please be aware of that. Thank you.

Edited by Sebastian Meyer

Merge request reports

Loading