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

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