fixup! unlockDialog: Add UnlockDialogLayout

This commit is contained in:
Georges Basile Stavracas Neto 2019-10-15 15:37:46 +02:00
parent be714f7401
commit 5380b06eb5
2 changed files with 97 additions and 52 deletions

View File

@ -2101,7 +2101,6 @@ $_screenshield_shadow: 0px 0px 6px rgba(0, 0, 0, 0.726);
spacing: 6px; spacing: 6px;
background-color: transparent; background-color: transparent;
padding: 24px 0; padding: 24px 0;
max-height: 500px;
.summary-notification-stack-scrollview { .summary-notification-stack-scrollview {
padding-top: 0; padding-top: 0;
padding-bottom: 0; padding-bottom: 0;

View File

@ -313,51 +313,34 @@ Signals.addSignalMethods(NotificationsBox.prototype);
var UnlockDialogLayout = GObject.registerClass( var UnlockDialogLayout = GObject.registerClass(
class UnlockDialogLayout extends Clutter.LayoutManager { class UnlockDialogLayout extends Clutter.LayoutManager {
_init(clock, authPrompt, notifications) { _init(clockStack, notifications) {
super._init(); super._init();
this._clock = clock; this._clockStack = clockStack;
this._authPrompt = authPrompt;
this._notifications = notifications; this._notifications = notifications;
} }
vfunc_get_preferred_width(container, forHeight) { vfunc_get_preferred_width(container, forHeight) {
let [clockWidth] = this._clock.get_preferred_width(forHeight); return this._clockStack.get_preferred_width(forHeight);
let [authWidth] = this._authPrompt.get_preferred_width(forHeight);
let columnWidth = Math.max(authWidth, clockWidth);
return [columnWidth, columnWidth];
} }
vfunc_get_preferred_height(container, forWidth) { vfunc_get_preferred_height(container, forWidth) {
let [clockHeight] = this._clock.get_preferred_height(forWidth); return this._clockStack.get_preferred_height(forWidth);
let [authHeight] = this._authPrompt.get_preferred_height(forWidth);
let height = clockHeight + authHeight;
return [height, height];
} }
vfunc_allocate(container, box, flags) { vfunc_allocate(container, box, flags) {
let [width, height] = box.get_size(); let [width, height] = box.get_size();
// FIXME: blurred text
let tenthOfHeight = height / 10.0; let tenthOfHeight = height / 10.0;
let thirdOfHeight = height / 3.0; let thirdOfHeight = height / 3.0;
let [clockWidth, clockHeight] = let [clockStackWidth, clockStackHeight] =
this._clock.get_preferred_size(); this._clockStack.get_preferred_size();
let [authWidth, authHeight] =
this._authPrompt.get_preferred_size();
let [, , notificationsWidth, notificationsHeight] = let [, , notificationsWidth, notificationsHeight] =
this._notifications.get_preferred_size(); this._notifications.get_preferred_size();
let clockBoxHeight = clockHeight + authHeight; let columnWidth = Math.max(clockStackWidth, notificationsWidth);
let columnWidth = Math.max(authWidth, clockWidth, notificationsWidth);
let columnX1 = Math.floor(width / 2.0 - columnWidth / 2.0); let columnX1 = Math.floor(width / 2.0 - columnWidth / 2.0);
let actorBox = new Clutter.ActorBox(); let actorBox = new Clutter.ActorBox();
@ -365,7 +348,7 @@ class UnlockDialogLayout extends Clutter.LayoutManager {
// Notifications // Notifications
let maxNotificationsHeight = Math.min( let maxNotificationsHeight = Math.min(
notificationsHeight, notificationsHeight,
height - tenthOfHeight - clockBoxHeight); height - tenthOfHeight - clockStackHeight);
actorBox.x1 = columnX1; actorBox.x1 = columnX1;
actorBox.y1 = height - maxNotificationsHeight; actorBox.y1 = height - maxNotificationsHeight;
@ -374,29 +357,17 @@ class UnlockDialogLayout extends Clutter.LayoutManager {
this._notifications.allocate(actorBox, flags); this._notifications.allocate(actorBox, flags);
// Auth Prompt // Clock Stack
let authPromptY = Math.min( let clockStackY = Math.min(
thirdOfHeight + clockHeight,
height - maxNotificationsHeight - authHeight);
actorBox.x1 = columnX1;
actorBox.y1 = authPromptY;
actorBox.x2 = columnX1 + columnWidth;
actorBox.y2 = authPromptY + authHeight;
this._authPrompt.allocate(actorBox, flags);
// Clock
let clockY = Math.min(
thirdOfHeight, thirdOfHeight,
height - maxNotificationsHeight - clockBoxHeight); height - clockStackHeight - maxNotificationsHeight);
actorBox.x1 = columnX1; actorBox.x1 = columnX1;
actorBox.y1 = clockY; actorBox.y1 = clockStackY;
actorBox.x2 = columnX1 + columnWidth; actorBox.x2 = columnX1 + columnWidth;
actorBox.y2 = clockY + clockHeight; actorBox.y2 = clockStackY + clockStackHeight;
this._clock.allocate(actorBox, flags); this._clockStack.allocate(actorBox, flags);
} }
}); });
@ -417,17 +388,23 @@ var UnlockDialog = GObject.registerClass({
this._userName = GLib.get_user_name(); this._userName = GLib.get_user_name();
this._user = this._userManager.get_user(this._userName); this._user = this._userManager.get_user(this._userName);
this._clock = new Clock(); let clockStack = new Shell.Stack();
this.add_child(this._clock.actor); this.add_child(clockStack);
let authBox = new St.BoxLayout({ this._clock = new Clock();
clockStack.add_child(this._clock.actor);
this._activePage = this._clock.actor;
this._authBox = new St.BoxLayout({
x_align: Clutter.ActorAlign.CENTER, x_align: Clutter.ActorAlign.CENTER,
y_align: Clutter.ActorAlign.CENTER, y_align: Clutter.ActorAlign.CENTER,
x_expand: true, x_expand: true,
y_expand: true, y_expand: true,
vertical: true, vertical: true,
visible: false,
}); });
this.add_child(authBox); clockStack.add_child(this._authBox);
this._authPrompt = new AuthPrompt.AuthPrompt(new Gdm.Client(), AuthPrompt.AuthPromptMode.UNLOCK_ONLY); this._authPrompt = new AuthPrompt.AuthPrompt(new Gdm.Client(), AuthPrompt.AuthPromptMode.UNLOCK_ONLY);
this._authPrompt.connect('failed', this._fail.bind(this)); this._authPrompt.connect('failed', this._fail.bind(this));
@ -435,7 +412,7 @@ var UnlockDialog = GObject.registerClass({
this._authPrompt.connect('reset', this._onReset.bind(this)); this._authPrompt.connect('reset', this._onReset.bind(this));
this._authPrompt.setPasswordChar('\u25cf'); this._authPrompt.setPasswordChar('\u25cf');
authBox.add_child(this._authPrompt.actor); this._authBox.add_child(this._authPrompt.actor);
this.allowCancel = false; this.allowCancel = false;
@ -450,7 +427,7 @@ var UnlockDialog = GObject.registerClass({
x_align: St.Align.START, x_align: St.Align.START,
x_fill: false }); x_fill: false });
this._otherUserButton.connect('clicked', this._otherUserClicked.bind(this)); this._otherUserButton.connect('clicked', this._otherUserClicked.bind(this));
authBox.add_child(this._otherUserButton); this._authBox.add_child(this._otherUserButton);
} else { } else {
this._otherUserButton = null; this._otherUserButton = null;
} }
@ -468,13 +445,80 @@ var UnlockDialog = GObject.registerClass({
this._idleWatchId = this._idleMonitor.add_idle_watch(IDLE_TIMEOUT * 1000, this._escape.bind(this)); this._idleWatchId = this._idleMonitor.add_idle_watch(IDLE_TIMEOUT * 1000, this._escape.bind(this));
this.layout_manager = new UnlockDialogLayout( this.layout_manager = new UnlockDialogLayout(
this._clock.actor, clockStack,
authBox,
this._notificationsBox.actor); this._notificationsBox.actor);
this.connect('destroy', this._onDestroy.bind(this)); this.connect('destroy', this._onDestroy.bind(this));
} }
_showClock() {
if (this._activePage == this._clock.actor)
return;
this._activePage = this._clock.actor;
this._clock.actor.show();
this._authBox.ease({
opacity: 0,
duration: 300,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => this._authBox.hide(),
});
this._clock.actor.ease({
opacity: 255,
duration: 300,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
});
}
_showAuth() {
if (this._activePage == this._authBox)
return;
this._activePage = this._authBox;
this._authBox.show();
this._clock.actor.ease({
opacity: 0,
duration: 300,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => this._clock.actor.hide(),
});
this._authBox.ease({
opacity: 255,
duration: 300,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
});
}
vfunc_captured_event(event) {
if (event.type() != Clutter.EventType.KEY_PRESS)
return Clutter.EVENT_PROPAGATE;
if (this._activePage == this._authBox)
return Clutter.EVENT_PROPAGATE;
let symbol = event.get_key_symbol();
let unichar = event.get_key_unicode();
let isEnter = (symbol == Clutter.KEY_Return ||
symbol == Clutter.KEY_KP_Enter ||
symbol == Clutter.KEY_ISO_Enter);
let isEscape = (symbol == Clutter.KEY_Escape);
let isLiftChar = (GLib.unichar_isprint(unichar) &&
(this._activePage == this._clock.actor ||
!GLib.unichar_isgraph(unichar)));
if (!isEnter && !isEscape && !isLiftChar)
return Clutter.EVENT_PROPAGATE;
this._showAuth();
return Clutter.EVENT_PROPAGATE;
}
_updateSensitivity(sensitive) { _updateSensitivity(sensitive) {
this._authPrompt.updateSensitivity(sensitive); this._authPrompt.updateSensitivity(sensitive);
@ -485,6 +529,7 @@ var UnlockDialog = GObject.registerClass({
} }
_fail() { _fail() {
this._showClock();
this.emit('failed'); this.emit('failed');
} }
@ -540,6 +585,7 @@ var UnlockDialog = GObject.registerClass({
} }
addCharacter(unichar) { addCharacter(unichar) {
this._showAuth();
this._authPrompt.addCharacter(unichar); this._authPrompt.addCharacter(unichar);
} }