Blame SOURCES/0001-gdm-add-AuthList-control.patch

35159f
From 592bf9b4ba879a365375a7edcb6c48258386e413 Mon Sep 17 00:00:00 2001
35159f
From: Ray Strode <rstrode@redhat.com>
35159f
Date: Tue, 18 Jul 2017 12:58:14 -0400
35159f
Subject: [PATCH 1/2] gdm: add AuthList control
35159f
35159f
Ultimately, we want to add support for GDM's new ChoiceList
35159f
PAM extension.  That extension allows PAM modules to present
35159f
a list of choices to the user. Before we can support that
35159f
extension, however, we need to have a list control in the
35159f
login-screen/unlock screen.  This commit adds that control.
35159f
35159f
For the most part, it's a copy-and-paste of the gdm userlist,
35159f
but with less features.  It lacks API specific to the users,
35159f
lacks the built in timed login indicator, etc. It does feature
35159f
a label heading.
35159f
---
35159f
 js/gdm/authList.js            | 195 ++++++++++++++++++++++++++++++++++
35159f
 js/js-resources.gresource.xml |   1 +
35159f
 2 files changed, 196 insertions(+)
35159f
 create mode 100644 js/gdm/authList.js
35159f
35159f
diff --git a/js/gdm/authList.js b/js/gdm/authList.js
35159f
new file mode 100644
35159f
index 000000000..fc1c3d6e4
35159f
--- /dev/null
35159f
+++ b/js/gdm/authList.js
35159f
@@ -0,0 +1,195 @@
35159f
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
35159f
+/*
35159f
+ * Copyright 2017 Red Hat, Inc
35159f
+ *
35159f
+ * This program is free software; you can redistribute it and/or modify
35159f
+ * it under the terms of the GNU General Public License as published by
35159f
+ * the Free Software Foundation; either version 2, or (at your option)
35159f
+ * any later version.
35159f
+ *
35159f
+ * This program is distributed in the hope that it will be useful,
35159f
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
35159f
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35159f
+ * GNU General Public License for more details.
35159f
+ *
35159f
+ * You should have received a copy of the GNU General Public License
35159f
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
35159f
+ */
35159f
+
35159f
+const Clutter = imports.gi.Clutter;
35159f
+const GObject = imports.gi.GObject;
35159f
+const Gtk = imports.gi.Gtk;
35159f
+const Lang = imports.lang;
35159f
+const Meta = imports.gi.Meta;
35159f
+const Signals = imports.signals;
35159f
+const St = imports.gi.St;
35159f
+
35159f
+const Tweener = imports.ui.tweener;
35159f
+
35159f
+const _SCROLL_ANIMATION_TIME = 0.5;
35159f
+
35159f
+const AuthListItem = new Lang.Class({
35159f
+    Name: 'AuthListItem',
35159f
+
35159f
+    _init(key, text) {
35159f
+        this.key = key;
35159f
+        let label = new St.Label({ style_class: 'auth-list-item-label',
35159f
+                                   y_align: Clutter.ActorAlign.CENTER });
35159f
+        label.text = text;
35159f
+
35159f
+        this.actor = new St.Button({ style_class: 'login-dialog-user-list-item',
35159f
+                                     button_mask: St.ButtonMask.ONE | St.ButtonMask.THREE,
35159f
+                                     can_focus: true,
35159f
+                                     child: label,
35159f
+                                     reactive: true,
35159f
+                                     x_align: St.Align.START,
35159f
+                                     x_fill: true });
35159f
+
35159f
+        this.actor.connect('key-focus-in', () => {
35159f
+            this._setSelected(true);
35159f
+        });
35159f
+        this.actor.connect('key-focus-out', () => {
35159f
+            this._setSelected(false);
35159f
+        });
35159f
+        this.actor.connect('notify::hover', () => {
35159f
+            this._setSelected(this.actor.hover);
35159f
+        });
35159f
+
35159f
+        this.actor.connect('clicked', this._onClicked.bind(this));
35159f
+    },
35159f
+
35159f
+    _onClicked() {
35159f
+        this.emit('activate');
35159f
+    },
35159f
+
35159f
+    _setSelected(selected) {
35159f
+        if (selected) {
35159f
+            this.actor.add_style_pseudo_class('selected');
35159f
+            this.actor.grab_key_focus();
35159f
+        } else {
35159f
+            this.actor.remove_style_pseudo_class('selected');
35159f
+        }
35159f
+    }
35159f
+});
35159f
+Signals.addSignalMethods(AuthListItem.prototype);
35159f
+
62948c
+var AuthList = new Lang.Class({
35159f
+    Name: 'AuthList',
35159f
+
35159f
+    _init() {
35159f
+        this.actor = new St.BoxLayout({ vertical: true,
35159f
+                                        style_class: 'login-dialog-auth-list-layout' });
35159f
+
35159f
+        this.label = new St.Label({ style_class: 'prompt-dialog-headline' });
35159f
+        this.actor.add_actor(this.label);
35159f
+
35159f
+        this._scrollView = new St.ScrollView({ style_class: 'login-dialog-user-list-view'});
35159f
+        this._scrollView.set_policy(Gtk.PolicyType.NEVER,
35159f
+                                    Gtk.PolicyType.AUTOMATIC);
35159f
+        this.actor.add_actor(this._scrollView);
35159f
+
35159f
+        this._box = new St.BoxLayout({ vertical: true,
35159f
+                                       style_class: 'login-dialog-user-list',
35159f
+                                       pseudo_class: 'expanded' });
35159f
+
35159f
+        this._scrollView.add_actor(this._box);
35159f
+        this._items = {};
35159f
+
35159f
+        this.actor.connect('key-focus-in', this._moveFocusToItems.bind(this));
35159f
+    },
35159f
+
35159f
+    _moveFocusToItems() {
35159f
+        let hasItems = Object.keys(this._items).length > 0;
35159f
+
35159f
+        if (!hasItems)
35159f
+            return;
35159f
+
35159f
+        if (global.stage.get_key_focus() != this.actor)
35159f
+            return;
35159f
+
35159f
+        let focusSet = this.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
35159f
+        if (!focusSet) {
35159f
+            Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
35159f
+                this._moveFocusToItems();
35159f
+                return false;
35159f
+            });
35159f
+        }
35159f
+    },
35159f
+
35159f
+    _onItemActivated(activatedItem) {
35159f
+        this.emit('activate', activatedItem.key);
35159f
+    },
35159f
+
35159f
+    scrollToItem(item) {
35159f
+        let box = item.actor.get_allocation_box();
35159f
+
35159f
+        let adjustment = this._scrollView.get_vscroll_bar().get_adjustment();
35159f
+
35159f
+        let value = (box.y1 + adjustment.step_increment / 2.0) - (adjustment.page_size / 2.0);
35159f
+        Tweener.removeTweens(adjustment);
35159f
+        Tweener.addTween (adjustment,
35159f
+                          { value: value,
35159f
+                            time: _SCROLL_ANIMATION_TIME,
35159f
+                            transition: 'easeOutQuad' });
35159f
+    },
35159f
+
35159f
+    jumpToItem(item) {
35159f
+        let box = item.actor.get_allocation_box();
35159f
+
35159f
+        let adjustment = this._scrollView.get_vscroll_bar().get_adjustment();
35159f
+
35159f
+        let value = (box.y1 + adjustment.step_increment / 2.0) - (adjustment.page_size / 2.0);
35159f
+
35159f
+        adjustment.set_value(value);
35159f
+    },
35159f
+
35159f
+    getItem(key) {
35159f
+        let item = this._items[key];
35159f
+
35159f
+        if (!item)
35159f
+            return null;
35159f
+
35159f
+        return item;
35159f
+    },
35159f
+
35159f
+    addItem(key, text) {
35159f
+        this.removeItem(key);
35159f
+
35159f
+        let item = new AuthListItem(key, text);
35159f
+        this._box.add(item.actor, { x_fill: true });
35159f
+
35159f
+        this._items[key] = item;
35159f
+
35159f
+        item.connect('activate',
35159f
+                     this._onItemActivated.bind(this));
35159f
+
35159f
+        // Try to keep the focused item front-and-center
35159f
+        item.actor.connect('key-focus-in',
35159f
+                           () => { this.scrollToItem(item); });
35159f
+
35159f
+        this._moveFocusToItems();
35159f
+
35159f
+        this.emit('item-added', item);
35159f
+    },
35159f
+
35159f
+    removeItem(key) {
35159f
+        let item = this._items[key];
35159f
+
35159f
+        if (!item)
35159f
+            return;
35159f
+
35159f
+        item.actor.destroy();
35159f
+        delete this._items[key];
35159f
+    },
35159f
+
35159f
+    numItems() {
35159f
+        return Object.keys(this._items).length;
35159f
+    },
35159f
+
35159f
+    clear() {
35159f
+        this.label.text = "";
35159f
+        this._box.destroy_all_children();
35159f
+        this._items = {};
35159f
+    }
35159f
+});
35159f
+Signals.addSignalMethods(AuthList.prototype);
35159f
diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml
35159f
index 836d1c674..002b202f8 100644
35159f
--- a/js/js-resources.gresource.xml
35159f
+++ b/js/js-resources.gresource.xml
35159f
@@ -1,6 +1,7 @@
35159f
 
35159f
 <gresources>
35159f
   <gresource prefix="/org/gnome/shell">
35159f
+    <file>gdm/authList.js</file>
35159f
     <file>gdm/authPrompt.js</file>
35159f
     <file>gdm/batch.js</file>
35159f
     <file>gdm/fingerprint.js</file>
35159f
-- 
35159f
2.21.0
35159f