Florian Müllner 8ea3556
From f91a2109fb139131a5f4ba5d00fca043df82ba10 Mon Sep 17 00:00:00 2001
22f01e4
From: Hans de Goede <hdegoede@redhat.com>
22f01e4
Date: Wed, 15 Aug 2018 15:03:56 +0200
22f01e4
Subject: [PATCH 2/2] endSessionDialog: Support rebooting into the bootloader
22f01e4
 menu aka ("Boot Options")
22f01e4
22f01e4
This implements the "Alt" behavior for the "Reboot" button as outlined in
22f01e4
the design here: https://wiki.gnome.org/Design/OS/BootOptions
22f01e4
22f01e4
This causes the endSessionDialog to send a ConfirmedRebootToBootOptions signal
22f01e4
to gnome-session instead of the normal ConfirmedReboot signal, actually
22f01e4
telling the boot-loader that it should show its menu the next boot is left
22f01e4
up to gnome-session.
22f01e4
Florian Müllner ccbb314
Note I've tried implemeting this with the AltSwitcher class from
22f01e4
js/ui/status/system.js first, but that puts the button in a St.Bin()
22f01e4
which causes the button to think it is the only button on the dialog
22f01e4
and makes it have rounded corners on both of its bottom corners.
22f01e4
---
Florian Müllner 1859568
 js/ui/endSessionDialog.js | 52 +++++++++++++++++++++++++++++++++++++++
Florian Müllner 1859568
 1 file changed, 52 insertions(+)
22f01e4
22f01e4
diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js
Florian Müllner 8ea3556
index 27ddf6804..6cebf2a81 100644
22f01e4
--- a/js/ui/endSessionDialog.js
22f01e4
+++ b/js/ui/endSessionDialog.js
Florian Müllner 8ea3556
@@ -239,6 +239,9 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
22f01e4
         this._totalSecondsToStayOpen = 0;
22f01e4
         this._applications = [];
22f01e4
         this._sessions = [];
22f01e4
+        this._capturedEventId = 0;
22f01e4
+        this._rebootButton = null;
22f01e4
+        this._rebootButtonAlt = null;
22f01e4
 
22f01e4
         this.connect('destroy',
22f01e4
                      this._onDestroy.bind(this));
Florian Müllner 8ea3556
@@ -368,6 +371,26 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
Florian Müllner 8ea3556
         this._sessionSection.visible = hasSessions;
Florian Müllner ccbb314
     }
22f01e4
 
22f01e4
+    _onCapturedEvent(actor, event) {
22f01e4
+        let altEnabled = false;
22f01e4
+
22f01e4
+        let type = event.type();
22f01e4
+        if (type != Clutter.EventType.KEY_PRESS && type != Clutter.EventType.KEY_RELEASE)
22f01e4
+            return Clutter.EVENT_PROPAGATE;
22f01e4
+
22f01e4
+        let key = event.get_key_symbol();
22f01e4
+        if (key != Clutter.KEY_Alt_L && key != Clutter.KEY_Alt_R)
22f01e4
+            return Clutter.EVENT_PROPAGATE;
22f01e4
+
22f01e4
+        if (type == Clutter.EventType.KEY_PRESS)
22f01e4
+            altEnabled = true;
22f01e4
+
22f01e4
+        this._rebootButton.visible = !altEnabled;
22f01e4
+        this._rebootButtonAlt.visible = altEnabled;
22f01e4
+
22f01e4
+        return Clutter.EVENT_PROPAGATE;
Florian Müllner ccbb314
+    }
22f01e4
+
22f01e4
     _updateButtons() {
22f01e4
         this.clearButtons();
22f01e4
 
Florian Müllner 8ea3556
@@ -389,7 +412,34 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
Florian Müllner 66fca8f
                 },
Florian Müllner 1859568
                 label,
Florian Müllner 66fca8f
             });
22f01e4
+
22f01e4
+            // Add Alt "Boot Options" option to the Reboot button
22f01e4
+            if (signal == 'ConfirmedReboot') {
22f01e4
+                this._rebootButton = button;
Florian Müllner 66fca8f
+                this._rebootButtonAlt = this.addButton({
Florian Müllner 66fca8f
+                    action: () => {
Florian Müllner 66fca8f
+                        this.close(true);
Florian Müllner 66fca8f
+                        let signalId = this.connect('closed', () => {
Florian Müllner 66fca8f
+                            this.disconnect(signalId);
Florian Müllner 66fca8f
+                            this._confirm('ConfirmedRebootToBootOptions');
Florian Müllner 66fca8f
+                        });
Florian Müllner 66fca8f
+                    },
Florian Müllner 66fca8f
+                    label: C_("button", "Boot Options")
Florian Müllner 66fca8f
+                });
22f01e4
+                this._rebootButtonAlt.visible = false;
Florian Müllner 1859568
+                this._capturedEventId = global.stage.connect('captured-event',
Florian Müllner 1859568
+                    this._onCapturedEvent.bind(this));
22f01e4
+            }
22f01e4
+        }
Florian Müllner ccbb314
+    }
22f01e4
+
22f01e4
+    _stopAltCapture() {
22f01e4
+        if (this._capturedEventId > 0) {
22f01e4
+            global.stage.disconnect(this._capturedEventId);
22f01e4
+            this._capturedEventId = 0;
22f01e4
         }
22f01e4
+        this._rebootButton = null;
22f01e4
+        this._rebootButtonAlt = null;
Florian Müllner ccbb314
     }
22f01e4
 
22f01e4
     close(skipSignal) {
Florian Müllner 8ea3556
@@ -401,6 +451,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
22f01e4
 
22f01e4
     cancel() {
22f01e4
         this._stopTimer();
22f01e4
+        this._stopAltCapture();
22f01e4
         this._dbusImpl.emit_signal('Canceled', null);
22f01e4
         this.close();
Florian Müllner ccbb314
     }
Florian Müllner 8ea3556
@@ -409,6 +460,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
22f01e4
         let callback = () => {
22f01e4
             this._fadeOutDialog();
22f01e4
             this._stopTimer();
22f01e4
+            this._stopAltCapture();
22f01e4
             this._dbusImpl.emit_signal(signal, null);
22f01e4
         };
22f01e4
 
22f01e4
-- 
Florian Müllner 8ea3556
2.24.1
22f01e4