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

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