How can I fetch current monitor orientation while under Wayland?

I’m trying to write a bash script that will rotate the screen to the right or left. To do this I need to fetch the current orientation and then increment it. I cannot for the life of me figure out how to fetch this information and it’s making me wonder why we all thought Wayland was so great in the first place.

I DON’T care about setting the orientation. I am doing that via gnome-randr. All I need is to fetch the current orientation.

I’m not an expert here, but there are 2 things.

  1. Wayland protocol.
  2. Wayland compositors implementing the protocol.

Mutter is GNOME’s wayland compositor implementation. If screen rotation / orientation is supported by Wayland protocol and works with other implementations (like reference Weston), then this question belongs here. Else, this is probably a question to the Wayland team.

Thanks!

1 Like

The only leads I had found on this problem involved querying dbus, which is why I put the question here

If you don’t get a response here, you can try asking in GNOME matrix room.

#gnome-shell:gnome.org

While solving a similar problem, I discovered the following:

# Permanent
xmllint --xpath '//rotation/text()' ~/.config/monitors.xml
xmllint --xpath '//flipped/text()' ~/.config/monitors.xml

# Runtime
busctl -j --user call \
    org.gnome.Mutter.DisplayConfig \
    /org/gnome/Mutter/DisplayConfig \
    org.gnome.Mutter.DisplayConfig \
    GetCurrentState | jq -r '.data[2][0][3]'