shyzus / gnome-shell-extension-screen-autorotate

Enable screen rotation regardless of touch mode
GNU General Public License v3.0
33 stars 10 forks source link

Rotation fails when mode_props lacks the 'is-current' property #5

Closed efosmark closed 2 years ago

efosmark commented 2 years ago

GPD Pocket 3 running Ubuntu 22.10 (5.19.0-23-generic) with Gnome-43 and Wayland.

I received the following error message when looking at the output of journalctl -f -o cat /usr/bin/gnome-shell and tilting the laptop to the side.

(gnome-shell:27944): Gjs-WARNING **: 21:05:59.531: JS ERROR: TypeError: mode_props['is-current'] is undefined
Monitor@/~/.local/share/gnome-shell/extensions/screen-rotate@shyzus.github.io/busUtils.js:40:34
DisplayConfigState/<@/~/.local/share/gnome-shell/extensions/screen-rotate@shyzus.github.io/busUtils.js:88:27
DisplayConfigState@/~/.local/share/gnome-shell/extensions/screen-rotate@shyzus.github.io/busUtils.js:87:18
get_state/</<@/~/.local/share/gnome-shell/extensions/screen-rotate@shyzus.github.io/rotator.js:60:35

This inhibits the rotation.

I have a branch with the fix ready and can push a pull-request if you provide my account permission. If you don't want to deal with that, though, here's the diff of what got it working for me:

--- a/screen-rotate@shyzus.github.io/busUtils.js
+++ b/screen-rotate@shyzus.github.io/busUtils.js
@@ -36,10 +36,12 @@ var Monitor = class Monitor {
             let mode = modes[i].unpack();
             let id = mode[0].unpack();
             let mode_props = mode[6].unpack();
-            let is_current = mode_props['is-current'].unpack().get_boolean();
-            if (is_current) {
-                this.current_mode_id = id;
-                break;
+            if ('is-current' in mode_props) {
+                let is_current = mode_props['is-current'].unpack().get_boolean();
+                if (is_current) {
+                    this.current_mode_id = id;
+                    break;
+                }
             }
         }

(tl;dr, just wrap it with a key-exists check)

After this change I no longer receive the journalctl message and the screen rotates properly.

shyzus commented 2 years ago

@efosmark I have invited you as a collaborator. Thank you for your effort and work. Il be looking forward to seeing your pull request.