I recently converted my Chromebook to a plain Linux machine, using the fantastic mrchromebox.tech website. Part of the process of doing so was setting up various components and behaviours I’d got used to from when the laptop was a Chromebook. Most of this was relatively smooth and just involved installing packages, but one thing didn’t come builtin to Xfce (my desktop environment of choice) – auto-rotate (using the laptop accelerometer to determine device orientation, and then changing the display orientation such that it is always the right way up). Having looked at the issue tracker, it seems to be something that was mentioned but not developed, as no one had the required hardware, so I thought I’d give it a go as it was a feature I used occasionally.
The settings manager for Xfce has three main components:
xfsettingsd: the daemon, where I implemented the accelerometer watcher and rotation applierxfce-settings-manager: the graphical settings interface, where I added a toggle to enable/disable auto-rotate for each display.xfce-settings-editor: the graphical settings file editor, which automatically reads and makes UI for new options from the file content – so no changes were needed.
Fortunately, Matias de Lellis submitted an initial functional patch about 10 years ago for the daemon component, just without a settings toggle. This patch still worked fine and just needed a slight adaptation to fit the current codebase state. I opted to separate out the sensor access logic into a different file, and then have the application logic in the main display manager. I considered changing it back about half-way through, but I think it turned out to be the correct choice as it required adding a few general purpose functions that changed state that was more suited to be display level rather than being accelerometer plugin level.
I then added a toggle in the settings menu, which was surprisingly much harder than I expected (definitely the extra 90% after the 90%) and required a few more changes to allow the display name to be read and to allow it to be persisted. The current architecture saved/loaded configuration directly to the backend display manager in configuration snapshots (XfceOutput), which made sense for the fields the application currently provided, but didn’t for auto-rotate since this didn’t line up to a physical display output characteristic. The solution I opted for in the end saved/loaded directly from Xfconf instead, and injected the auto-rotate property into the XfceOutput configuration snapshot after the backend display manager produced it, which worked perfectly.
I had an issue where the display would sometimes “forget” to rotate to the correct orientation if you spun it quick enough, which was fairly easily resolved by tracking pending changes if one is currently occurring. The implementation also contains a handy power-saving feature thanks to the DBus, which allows it to release the accelerometer if no displays are set to auto-rotate, potentially allowing the accelerometer proxy to power it off it nothing else is using it.
I hadn’t worked with GLib/GTK before so this was a nice way to dive in. I’m not fully certain whether I’ve made my changes in the right place architecturally, so I’m waiting for a reviewer to advise (and hopefully eventually merge). You can see the merge request progress below.