feat(kded): add orientation sensor

Authored by romangg on Dec 16 2019, 1:24 AM.



With this patch KScreen controls rotation of internal outputs if an orientation
sensor is present and emitting rotation values.

The default behavior is auto-rotation but can be configured through control

This functionality is developed for the Wayland session but might potentially
also work on X11, what needs to be tested more.

Test Plan

Screen of convertible with orientation sensor rotates.

Diff Detail

R104 KScreen
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
romangg requested review of this revision.Dec 16 2019, 1:24 AM
romangg created this revision.
ngraham edited the summary of this revision. (Show Details)Dec 16 2019, 4:50 AM

Generally, as you know, I approve of the direction of moving this to kscreen so that kwin has one source.


Do we need to set mode to QSensor::FixedOrientation

it's not clear what the default is in the docs


It's very wasteful to have this always on when we're not in autorotate mode.

From a mobile POV, that's an entire sensor being active and causing wakeups. We also want it off when the screen is on dpms.


IMHO this would be clearer if we abstract to a screen orientation inside this class, rather than exposing a version with FaceUp and FaceDown events only to ignore them.

romangg added inline comments.Dec 17 2019, 1:44 PM

It says the default is fixed orientation: https://doc.qt.io/qt-5/qsensor.html#orientation


Yea, we need to start it in the beginning to see if a sensor is available. But we could cache the result and then shut it off again in case auto rotation or screen is off. Needs some more logic though.


I left FaceUp and FaceDown in there in case at some point we also want to react to these states. But it's not really necessary and I will change it to use KScreen::Output::Rotation directly instead.

davidedmundson added inline comments.Dec 17 2019, 5:48 PM

I suspect some apps will need that info, but it's just as easy for them to get that via QSensors directly.

romangg updated this revision to Diff 72352.Dec 29 2019, 11:46 PM
  • Activate orientation sensor only when used
  • Query new libkscreen auto rotation and tablet mode API
Restricted Application added a project: Plasma. · View Herald TranscriptDec 29 2019, 11:46 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
romangg added inline comments.Dec 29 2019, 11:47 PM

Looking at it again I don't think it is advisable to remove these two values from the class interface. Instead having them in there for later and ignoring them in the meantime in the implementation in the KScreenDaemon is fine. See the comment there:

We currently don't do anything with FaceUp/FaceDown, but in the future we could use them to shut off and switch on again a display when display is facing downwards/upwards.

romangg marked 2 inline comments as done.Dec 29 2019, 11:47 PM
davidedmundson added inline comments.Jan 7 2020, 4:07 PM

From what I can tell, we can call

if (!sensor->connectToBackend()) {
m_available = false;

in the constructor

and then we have the option to call start/stop whenever.


I don't really understand.

The only reason to wrap QOrientationSensor in a wrapper class is to try and encapsulate the details of the sensor into something domain specific.

If we just forward everything 1:1, what does this wrapper provide over just having the other code use QOrietnationSensor directly.

(but whatever this isn't a topic I'm particularly passionate about, so whatever)

romangg added inline comments.Jan 8 2020, 9:21 AM

Yea, I overlooked this getter. Will replace.


Yea, the "just use QOrientationSensor enum" argument makes sense. I will try to use this instead.

romangg updated this revision to Diff 73146.Jan 9 2020, 6:24 PM

Rebase on master.

romangg updated this revision to Diff 73148.Jan 9 2020, 6:55 PM
romangg marked 2 inline comments as done.
  • Use connectedToBackend getter
  • Replace DeviceOrientation
romangg marked 6 inline comments as done.Jan 9 2020, 6:55 PM
davidedmundson accepted this revision.Jan 9 2020, 6:59 PM
This revision is now accepted and ready to land.Jan 9 2020, 6:59 PM
romangg updated this revision to Diff 73185.Jan 10 2020, 11:12 AM
  • Fix seg fault on orientation sensor
romangg edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.