Florian Müllner ccbb314
From 7dae43a3ebb8972199da8ce272a3ff5c4ecc5805 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
---
22f01e4
 js/ui/endSessionDialog.js | 50 +++++++++++++++++++++++++++++++++++++++
22f01e4
 1 file changed, 50 insertions(+)
22f01e4
22f01e4
diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js
Florian Müllner ccbb314
index d107c87d9..a02cd7c23 100644
22f01e4
--- a/js/ui/endSessionDialog.js
22f01e4
+++ b/js/ui/endSessionDialog.js
Florian Müllner ccbb314
@@ -266,6 +266,9 @@ var EndSessionDialog = 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 ccbb314
@@ -431,6 +434,26 @@ var EndSessionDialog = class EndSessionDialog extends ModalDialog.ModalDialog {
22f01e4
         this._sessionHeader.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 ccbb314
@@ -451,7 +474,32 @@ var EndSessionDialog = class EndSessionDialog extends ModalDialog.ModalDialog {
22f01e4
                                });
22f01e4
                             },
22f01e4
                             label: label });
22f01e4
+
22f01e4
+            // Add Alt "Boot Options" option to the Reboot button
22f01e4
+            if (signal == 'ConfirmedReboot') {
22f01e4
+                this._rebootButton = button;
22f01e4
+                this._rebootButtonAlt = this.addButton(
22f01e4
+                               { action: () => {
22f01e4
+                                 this.close(true);
22f01e4
+                                   let signalId = this.connect('closed', () => {
22f01e4
+                                   this.disconnect(signalId);
22f01e4
+                                   this._confirm('ConfirmedRebootToBootOptions');
22f01e4
+                                 });
22f01e4
+                               },
22f01e4
+                               label: C_("button", "Boot Options") });
22f01e4
+                this._rebootButtonAlt.visible = false;
22f01e4
+                this._capturedEventId = global.stage.connect('captured-event', 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 ccbb314
@@ -463,6 +511,7 @@ var EndSessionDialog = 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 ccbb314
@@ -471,6 +520,7 @@ var EndSessionDialog = 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 ccbb314
2.20.1
22f01e4