viewSelector: Cleanup pages

Remove the dummy applications page that was introduced as a temporary
step. Replace the 'page-changed' and 'page-empty' signals with a 'search-active'
boolean property.

Remove ViewSelector.ViewsPage since it's now unused, and all the page handling
mechanism. At last, since we don't use any ShellStack features anymore, simply
make it a St.Widget with a ClutterBinLayout as the layout manager.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1667>
This commit is contained in:
Georges Basile Stavracas Neto 2021-01-15 09:50:39 -03:00 committed by Marge Bot
parent 692b6d2577
commit 27627bd40a
2 changed files with 36 additions and 99 deletions

View File

@ -287,7 +287,7 @@ class ControlsManager extends St.Widget {
this.viewSelector = new ViewSelector.ViewSelector(this._searchEntry, this.viewSelector = new ViewSelector.ViewSelector(this._searchEntry,
this.dash.showAppsButton); this.dash.showAppsButton);
this.viewSelector.connect('page-empty', this._onPageEmpty.bind(this)); this.viewSelector.connect('notify::search-active', this._onSearchChanged.bind(this));
this._thumbnailsBox = this._thumbnailsBox =
new WorkspaceThumbnail.ThumbnailsBox(this._workspaceAdjustment); new WorkspaceThumbnail.ThumbnailsBox(this._workspaceAdjustment);
@ -402,24 +402,23 @@ class ControlsManager extends St.Widget {
} }
_updateThumbnailsBox(animate = false) { _updateThumbnailsBox(animate = false) {
const page = this.viewSelector.getActivePage(); const { searchActive } = this.viewSelector;
const searching = page === ViewSelector.ViewPage.SEARCH;
const [opacity, scale, translationY] = this._getThumbnailsBoxParams(); const [opacity, scale, translationY] = this._getThumbnailsBoxParams();
const thumbnailsBoxVisible = !searching && opacity !== 0; const thumbnailsBoxVisible = !searchActive && opacity !== 0;
if (thumbnailsBoxVisible) { if (thumbnailsBoxVisible) {
this._thumbnailsBox.opacity = 0; this._thumbnailsBox.opacity = 0;
this._thumbnailsBox.visible = thumbnailsBoxVisible; this._thumbnailsBox.visible = thumbnailsBoxVisible;
} }
const params = { const params = {
opacity: searching ? 0 : opacity, opacity: searchActive ? 0 : opacity,
duration: animate ? SIDE_CONTROLS_ANIMATION_TIME : 0, duration: animate ? SIDE_CONTROLS_ANIMATION_TIME : 0,
mode: Clutter.AnimationMode.EASE_OUT_QUAD, mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => (this._thumbnailsBox.visible = thumbnailsBoxVisible), onComplete: () => (this._thumbnailsBox.visible = thumbnailsBoxVisible),
}; };
if (!searching) { if (!searchActive) {
params.scale_x = scale; params.scale_x = scale;
params.scale_y = scale; params.scale_y = scale;
params.translation_y = translationY; params.translation_y = translationY;
@ -442,11 +441,10 @@ class ControlsManager extends St.Widget {
this._updateThumbnailsBox(); this._updateThumbnailsBox();
} }
_onPageEmpty() { _onSearchChanged() {
const page = this.viewSelector.getActivePage(); const { searchActive } = this.viewSelector;
const isActivities = page === ViewSelector.ViewPage.ACTIVITIES;
if (isActivities) { if (!searchActive) {
this._appDisplay.show(); this._appDisplay.show();
this._workspacesDisplay.reactive = true; this._workspacesDisplay.reactive = true;
this._workspacesDisplay.setPrimaryWorkspaceVisible(true); this._workspacesDisplay.setPrimaryWorkspaceVisible(true);
@ -457,25 +455,25 @@ class ControlsManager extends St.Widget {
this._updateThumbnailsBox(true); this._updateThumbnailsBox(true);
this._appDisplay.ease({ this._appDisplay.ease({
opacity: isActivities ? 255 : 0, opacity: searchActive ? 0 : 255,
duration: SIDE_CONTROLS_ANIMATION_TIME, duration: SIDE_CONTROLS_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD, mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => (this._appDisplay.visible = isActivities), onComplete: () => (this._appDisplay.visible = !searchActive),
}); });
this._workspacesDisplay.ease({ this._workspacesDisplay.ease({
opacity: isActivities ? 255 : 0, opacity: searchActive ? 0 : 255,
duration: SIDE_CONTROLS_ANIMATION_TIME, duration: SIDE_CONTROLS_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD, mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => { onComplete: () => {
this._workspacesDisplay.reactive = isActivities; this._workspacesDisplay.reactive = !searchActive;
this._workspacesDisplay.setPrimaryWorkspaceVisible(isActivities); this._workspacesDisplay.setPrimaryWorkspaceVisible(!searchActive);
}, },
}); });
this.viewSelector.ease({ this.viewSelector.ease({
opacity: isActivities ? 0 : 255, opacity: searchActive ? 255 : 0,
duration: SIDE_CONTROLS_ANIMATION_TIME, duration: SIDE_CONTROLS_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD, mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => (this.viewSelector.visible = !isActivities), onComplete: () => (this.viewSelector.visible = searchActive),
}); });
} }

View File

@ -1,18 +1,12 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported ViewSelector */ /* exported ViewSelector */
const { Clutter, GObject, Shell, St } = imports.gi; const { Clutter, GObject, St } = imports.gi;
const Main = imports.ui.main; const Main = imports.ui.main;
const OverviewControls = imports.ui.overviewControls;
const Search = imports.ui.search; const Search = imports.ui.search;
const ShellEntry = imports.ui.shellEntry; const ShellEntry = imports.ui.shellEntry;
var ViewPage = {
ACTIVITIES: 1,
SEARCH: 2,
};
var FocusTrap = GObject.registerClass( var FocusTrap = GObject.registerClass(
class FocusTrap extends St.Widget { class FocusTrap extends St.Widget {
vfunc_navigate_focus(from, direction) { vfunc_navigate_focus(from, direction) {
@ -33,14 +27,17 @@ function getTermsForSearchString(searchString) {
} }
var ViewSelector = GObject.registerClass({ var ViewSelector = GObject.registerClass({
Signals: { Properties: {
'page-changed': {}, 'search-active': GObject.ParamSpec.boolean(
'page-empty': {}, 'search-active', 'search-active', 'search-active',
GObject.ParamFlags.READABLE,
false),
}, },
}, class ViewSelector extends Shell.Stack { }, class ViewSelector extends St.Widget {
_init(searchEntry, showAppsButton) { _init(searchEntry, showAppsButton) {
super._init({ super._init({
name: 'viewSelector', name: 'viewSelector',
layout_manager: new Clutter.BinLayout(),
x_expand: true, x_expand: true,
y_expand: true, y_expand: true,
visible: false, visible: false,
@ -83,12 +80,8 @@ var ViewSelector = GObject.registerClass({
this._iconClickedId = 0; this._iconClickedId = 0;
this._capturedEventId = 0; this._capturedEventId = 0;
const dummy = new St.Widget();
this._activitiesPage =
this._addPage(dummy, _('Activities'), 'view-app-grid-symbolic');
this._searchResults = new Search.SearchResultsView(); this._searchResults = new Search.SearchResultsView();
this._searchPage = this._addPage(this._searchResults); this.add_child(this._searchResults);
Main.ctrlAltTabManager.addGroup(this._entry, _('Search'), 'edit-find-symbolic'); Main.ctrlAltTabManager.addGroup(this._entry, _('Search'), 'edit-find-symbolic');
// Since the entry isn't inside the results container we install this // Since the entry isn't inside the results container we install this
@ -117,8 +110,7 @@ var ViewSelector = GObject.registerClass({
prepareToEnterOverview() { prepareToEnterOverview() {
this.reset(); this.reset();
this._activePage = null; this._setSearchActive(false);
this._showPage(this._activitiesPage);
} }
vfunc_unmap() { vfunc_unmap() {
@ -127,66 +119,16 @@ var ViewSelector = GObject.registerClass({
super.vfunc_unmap(); super.vfunc_unmap();
} }
_addPage(actor) { _setSearchActive(searchActive) {
let page = new St.Bin({ child: actor }); if (this._searchActive === searchActive)
page.hide();
this.add_actor(page);
return page;
}
_fadePageIn() {
this._activePage.ease({
opacity: 255,
duration: OverviewControls.SIDE_CONTROLS_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
});
}
_fadePageOut(page) {
let oldPage = page;
page.ease({
opacity: 0,
duration: OverviewControls.SIDE_CONTROLS_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onStopped: () => this._animateIn(oldPage),
});
}
_animateIn(oldPage) {
if (oldPage)
oldPage.hide();
this.emit('page-empty');
if (this._activePage) {
this._activePage.show();
this._fadePageIn();
}
}
_animateOut(page) {
this._fadePageOut(page);
}
_showPage(page) {
if (!Main.overview.visible)
return; return;
if (page == this._activePage) this._searchActive = searchActive;
return; this.notify('search-active');
let oldPage = this._activePage;
this._activePage = page;
this.emit('page-changed');
if (oldPage)
this._animateOut(oldPage);
else
this._animateIn();
} }
_onShowAppsButtonToggled() { _onShowAppsButtonToggled() {
this._showPage(this._activitiesPage); this._setSearchActive(false);
} }
_onStageKeyPress(actor, event) { _onStageKeyPress(actor, event) {
@ -220,7 +162,7 @@ var ViewSelector = GObject.registerClass({
} }
_searchCancelled() { _searchCancelled() {
this._showPage(this._activitiesPage); this._setSearchActive(false);
// Leave the entry focused when it doesn't have any text; // Leave the entry focused when it doesn't have any text;
// when replacing a selected search term, Clutter emits // when replacing a selected search term, Clutter emits
@ -306,11 +248,11 @@ var ViewSelector = GObject.registerClass({
_onTextChanged() { _onTextChanged() {
let terms = getTermsForSearchString(this._entry.get_text()); let terms = getTermsForSearchString(this._entry.get_text());
this._searchActive = terms.length > 0; const searchActive = terms.length > 0;
this._searchResults.setTerms(terms); this._searchResults.setTerms(terms);
if (this._searchActive) { if (searchActive) {
this._showPage(this._searchPage); this._setSearchActive(true);
this._entry.set_secondary_icon(this._clearIcon); this._entry.set_secondary_icon(this._clearIcon);
@ -386,10 +328,7 @@ var ViewSelector = GObject.registerClass({
return Clutter.EVENT_PROPAGATE; return Clutter.EVENT_PROPAGATE;
} }
getActivePage() { get searchActive() {
if (this._activePage === this._activitiesPage) return this._searchActive;
return ViewPage.ACTIVITIES;
else
return ViewPage.SEARCH;
} }
}); });