Changing the way automatic screen rotation works in Gnome shell

gnome3touch screenudevxrandr

I recently acquired a Lenovo Yoga 3 11" convertible notebook. It works well with out-of-the-box with Ubuntu Gnome LTS 16.04.2 – WiFi, Bluetooth, even suspend and resume work without any issues so far.

I noticed that Gnome 3 even allows the screen to auto-rotate based on the built-in rotation sensors. The Yoga 3 11" does offer rotation sensors via iio-sensor-proxy which is already installed by default in Ubuntu Gnome. As it happens, the orientation reported by iio-sensor-proxy seems to be off by 90°.

Auto rotate screen on Dell 13 7000 with 15.04 (Gnome) has a solution in terms of a custom shell script which handles the screen rotation. I would rather not use this solution as it disables the "disable screen rotation" button in Gnome Shell.

I did some research already and found that iio-sensor-proxy should cause udev to trigger an event which is then used by Gnome 3 to set the screen orientation via xrandr. I cannot, however, find a way to tell either udev or Gnome 3 that the accelerometer is mounted in an orientation different from the display, which requires the directions to be translated in between.

So, the question is: How can that be done? The orientation remapping should be possible in either iio-sensor-proxy, udev or Gnome 3, and I actually don't care that much where it is done. I don't seem to find any config files I can easily change to achieve what I need.

As a workaround for now I am using the script from the Ask ubuntu question linked above, with modifications to account for the misaligned display/accelerometer issue. For this to work, I have to disable the automatic screen rotation in Gnome 3. Although this solution also allows automatically starting and killing onboard (on-screen keyboard) depending on current orientation, it kind of defeats the purpose of the Gnome 3 screen rotation setting.

Best Answer

See the answer by Krzysztof Stasiak for the theory.

In practice, my machine - a one mix one netbook 2s - by default has a screen rotated 90deg anticlockwise.

From what I understand, by default - every machine that doesn't have overrides has a matrix of ACCEL_MOUNT_MATRIX=1, 0, 0; 0, 1, 0; 0, 0, 1

Putting the following into /etc/udev/hwdb.d/60-sensor.hwdb fixed my case:

sensor:modalias:*
  ACCEL_MOUNT_MATRIX=0, 1, 0; 1, 0, 0; 0, 0, 1
Related Question