Support automatic screen rotation based on orientation sensor
ClosedPublic

Authored by graesslin on Nov 7 2017, 4:35 PM.

Details

Summary

This change introduces an OrientationSensor class which wraps a
QOrientationSensor. The OrientationSensor is hold by Screens and gets
enabled if Screens knows about an internal (e.g. LVDS) display which
supports rotation. In addition the OrientationSensor holds an KSni to
enable/disable the automatic rotation support.

The drm platform plugin is adjusted to make use of the OrientationSensor.
The API is defined in a way that this can also be implemented on other
platforms supporting rotation. Most important are hwcomposer and X11
standalone. The latter should be straight forward as rotation is provided
through XRandR. The former needs addition for rotation support first.

Test Plan

Rotated my Yoga 12

Diff Detail

Repository
R108 KWin
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
graesslin created this revision.Nov 7 2017, 4:35 PM
Restricted Application added a project: Plasma. · View Herald TranscriptNov 7 2017, 4:35 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
sebas accepted this revision.Nov 7 2017, 5:40 PM

Code-wise, looks good.

Have you thought about a way to switch it on and off? Perhaps a simple dbus interface that allows checking its state and turning it on and off is sufficient.

This revision is now accepted and ready to land.Nov 7 2017, 5:40 PM
sebas added a comment.Nov 7 2017, 5:46 PM

Ah, btw ... we have icons: They're in breeze-icons/applets/*/osd-rotate-{ccw,cw,flip,normal].svg

These should probably be used for the statusnotifier then.

I don't see how the interaction with KScreen is going to work; you rotate the screen in kscreen, kscreen will consider that a completely different config change and save it.
Then we completely lose track of what comes from a user setting and what doesn't.

The only way I can see it working is if we don't update the OutputDevice when the rotation was triggered by kwin.
(or it gains an 'auto' enum value which kscreen-daemon ignores)

plugins/platforms/drm/drm_output.cpp
308

what about the the initial position?

sebas added a comment.Nov 7 2017, 6:01 PM

Or ... kwin has two modes: 1) kwin auto-rotates, tells kscreen that it doesn't do any other transforms, 2) kwin hands over to kscreen, not auto-rotating...

Perhaps adding "auto" is the best option, though.

In D8699#165395, @sebas wrote:

Code-wise, looks good.

Have you thought about a way to switch it on and off? Perhaps a simple dbus interface that allows checking its state and turning it on and off is sufficient.

There's a status notifier to enable/disable it.

I don't see how the interaction with KScreen is going to work; you rotate the screen in kscreen, kscreen will consider that a completely different config change and save it.

My suggestion would be to copy from Windows 10 (I studied a system on Saturday for inspiration): if auto rotation is enabled you cannot manually rotate the screen and vice versa. The "Windows KScreen KCM" has a checkbox which disables the rotation combobox.

In D8699#165399, @sebas wrote:

Ah, btw ... we have icons: They're in breeze-icons/applets/*/osd-rotate-{ccw,cw,flip,normal].svg

These should probably be used for the statusnotifier then.

No, the idea for the status notifier is to indicate whether we have automatic rotation enabled/disabled. I think we need new icons for this. I don't think the icon needs to express the current mode, I'm sure the user can visually see it without the icon.

That reminds me: VDG how can I request two new status notifier icons? I need: "automatic-screen-rotation-enabled" and "automatic-screen-rotation-disabled"

if auto rotation is enabled you cannot manually rotate the screen and vice versa.

Yeah, that's great...but kscreen needs to have that information.

It's going to be especially difficult if you do want to support X.
kscreen there is following any external xrandr changes and we need to think about the whole set of potential races between kwin, X and kscreen.

if auto rotation is enabled you cannot manually rotate the screen and vice versa.

Yeah, that's great...but kscreen needs to have that information.

It's going to be especially difficult if you do want to support X.
kscreen there is following any external xrandr changes and we need to think about the whole set of potential races between kwin, X and kscreen.

Hmm, I was only thinking of Wayland where we have the Wayland protocol. So maybe sebas suggestion of dbus service. It's still possible to race of course but that's something we should be able to handle. Activating the sensor takes it time so dbus should be faster. Then kscreen can ignore all rotations.

This revision was automatically updated to reflect the committed changes.
Restricted Application edited projects, added KWin; removed Plasma. · View Herald TranscriptOct 31 2019, 3:52 PM
Restricted Application added a subscriber: kwin. · View Herald Transcript