NickelMenu icon indicating copy to clipboard operation
NickelMenu copied to clipboard

feature request - orientation toggle

Open stiivgiaco opened this issue 6 years ago • 7 comments

First of all i wanted to say thank you for taking your time to develop this and well done. I have a small feature request if possible please.

I have added the ForceAllowLandscape=true parameter in the kobo config file which enabled portrait or landscape mode, but i would also like to have inverted landscape and inverted portrait as an option also as an option. This seems to be possible to do so as it is found in the Developer options menu.

Would it be possible to have a rotation flag added please? or even the possibility of adding the Developer options section in the home screen?

Thanks in advance, STiiVO

stiivgiaco avatar Aug 03 '20 05:08 stiivgiaco

Some notes for myself:

  • QGuiApplication::primaryScreen()->orientationChanged changes the orientation of the output (I'm assuming it's passed to KoboScreenNXP::setOrientation and does the ioctl on the FB), but not of the app itself or the touchscreen.
  • Applications::setLockedOrientation is used.
  • OrientationManager may or may not be important for this.
  • Most orientation changing stuff does something funny with the orientation sensors, but I haven't looked into whether it will be necessary for this action.
  • The manual orientation settings in the reading settings and the rotate popup all use RotatePopupController::on{Auto,Portrait,Landscape}.
  • ~~I'm not 100% sure what the purpose of calling QScreen::setOrientationUpdateMask for the new orientation is.~~ It seems to be used by libnickel to limit which values the sensor will return if enabled.
  • There are quite a few checks around ensuring the orientation is uninverted landscape/portrait. I don't know what the reason for adding them was, but I'm not going to implement this feature if I have to patch all of them to do so.
    • The least intrusive way to do this might be to do it the same way as the orientation sensor is handled.
    • The way the dev settings view does it might also work.
  • There's a global variable without a symbol name which is updated when the orientation changes (0x11e1df8 on 15268).
    • It's referenced by functions like setupGeometry, readingOrientationChanged, updateLayout, finishInitialization, and updateLandscapeFlag.
    • It's also used when determining whether to invert the page turn buttons.
  • I'm probably going to go with the orientation sensor method (the other one is probably too complicated to be worth it), which gives me two options:
    • Set the current orientation once the same way as the orientation sensor code does it (this will probably only work when the locked orientation is set to auto).
    • Hook the orientation sensor on devices without one (ones with them wouldn't be supported) and have actions to set the emulated value.
  • The auto orientation update function (which reads from QOrientationSensor::reading if the sensor exists and sets the orientation if between Qt::ScreenOrientation 1-4: i.e. subs r0, #1 cmp r0, #3 bhi skip) is called for the QSensor::readingChanged signal, which is connected if the device has a sensor (Device::hasOrientationSensor, {MMA8652,KX122}::exists).
    • It appears that QWindowSystemInterface::handleScreenOrientationChange should deal with most things for us.
      • On a side note, this should have been in the QPA, not Nickel, according to the QWindowSystemInterface docs. I suppose it was done this way to simplify Nickel.
        • Even more off topic, the headers are in qtbase5-private-dev on Debian/Ubuntu.
  • Applications::setLockedOrientation controls the allowed orientations (it's a bitmask made of ORing Qt::ScreenOrientation values). For "Auto", it's 0xF (i.e. 0b1111, or Qt::PortraitOrientation|Qt::LandscapeOrientation|Qt::InvertedPortraitOrientation|Qt::InvertedLandscapeOrientation).
    • This is limited by Nickel's allowed orientations (MainWindowController::allowableOrientations), which is based on the whether Device::hasOrientationSensor and the current view. This limit is overridden by the ForceAllowLandscape dev settings option.
  • RotatePopupController::on{Auto,Portrait,Landscape} is used by the rotate popup and the reading settings view to change the rotation, and:
    • Sets ApplicationSettings::lockedOrientation to auto:Qt::PortraitOrientation|Qt::LandscapeOrientation|Qt::InvertedPortraitOrientation|Qt::InvertedLandscapeOrientation portrait:Qt::PortraitOrientation|Qt::InvertedPortraitOrientation landscape:Qt::LandscapeOrientation|Qt::InvertedLandscapeOrientation.
    • Sets the sensor settings if necessary.
    • Updates the rotation icon in the status bar.
    • If the sensor is enabled, calls QScreen::setOrientationUpdateMask for the same mask.
    • Calls QWindowSystemInterface::handleScreenOrientationChange with the new rotation if necessary (this is the same thing the sensor update handler will call).
    • Sends analytics.

pgaskin avatar Aug 04 '20 15:08 pgaskin

* Most orientation changing stuff does something funny with the orientation sensors, but I haven't looked into whether it will be necessary for this action.

That's... weird.

For reference, on a device w/ a gyro, the gyro sends raw evdev events to a dedicated device (event2) but I don't think anyone consumes those in userspace. Instead, the ntx_io driver sends synthetic "I've rotated!" events to event0., and those are pretty-much rotation-independent, so I'm not quite sure what fiddling would be entailed here.

-- For the events of the Forma accelerometer (MSC.value)
local MSC_RAW_GSENSOR_PORTRAIT_DOWN = 0x17
local MSC_RAW_GSENSOR_PORTRAIT_UP = 0x18
local MSC_RAW_GSENSOR_LANDSCAPE_RIGHT = 0x19
local MSC_RAW_GSENSOR_LANDSCAPE_LEFT = 0x1a
-- Not that we care about those, but they are reported, and accurate ;).
local MSC_RAW_GSENSOR_BACK = 0x1b
local MSC_RAW_GSENSOR_FRONT = 0x1c

There may be an ntxio ioctl to toggle said synthetic events, though. But I never really quite managed to make it do something useful, IIRC.

NiLuJe avatar Aug 04 '20 19:08 NiLuJe

That's... weird ... ... so I'm not quite sure what fiddling would be entailed here

By "something funny", I was referring to that it does something to do with enabling/disabling the sensor, setting some global variables, and setting the rotation mask when the different locked modes are selected.

the gyro sends raw evdev events to a dedicated device

From the firmware, it appears that the MMA8652 and KX122 classes access the sensors directly (and Nickel reads the value and uses QWindowSystemInterface::handleScreenOrientationChange to trigger the actual logic for handling it). This really belongs in the QPA, but Kobo probably put it directly into Nickel rather than libkobo for simplicity (it helps that they control Qt, so they don't need to worry about source/binary compatibility with the private QPA APIs).

For the MMA8652 sensor, /sys/devices/virtual/input/input2/pl_cfg is used to configure the parameters, and other files under /sys/devices/virtual/input/input2/ are used to read the sensor state.

The KX122 sensor uses /sys/devices/platform/soc/2100000.aips-bus/21a0000.i2c/i2c-0/0-001e/input/input2/.

pgaskin avatar Aug 04 '20 19:08 pgaskin

Yep, the MMA on the Forma, and the KX on the Libra, IIRC.

Huh, so they do consume the raw events! (They may not have been happy with the way the ntxio driver interpreted some of the events? re: all the bugreports about wonky rotas ;p).

EDIT: Hmm, nope, I don't see event2 being opened/grabbed via lsof.

NiLuJe avatar Aug 04 '20 19:08 NiLuJe

Huh, so they do consume the raw events

The state is read from sysfs:

MMA8652: /sys/devices/virtual/input/input2/stick_status, /sys/devices/virtual/input/input2/pl_bf_zcomp, whatever QOrientationSensor::reading reads. KX122: /sys/devices/platform/soc/2100000.aips-bus/21a0000.i2c/i2c-0/0-001e/input/input2/tilt_angle_ll, /sys/devices/platform/soc/2100000.aips-bus/21a0000.i2c/i2c-0/0-001e/input/input2/tilt_angle_hl.

pgaskin avatar Aug 04 '20 19:08 pgaskin

Huh. Then the magic probably happens in QOrientationSensor::reading, and it probably does rely on the ntxio synthetic events, because stick_status is stuck to Normal over here, and zcomp to 0xc5 ;p.

Anyway, that was more for curiosity's sake than anything, really, thanks for humoring me ;).

NiLuJe avatar Aug 04 '20 19:08 NiLuJe

IIRC, stick_status is for if the sensor is literally stuck (the MMA sensor is known to have an issue with the z-axis sticking).

pgaskin avatar Aug 04 '20 20:08 pgaskin