[gnome-shell] viewSelector: Cleanup pages



commit 27627bd40a46fd77188d718c7a8f53e656dc197e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jan 15 09:50:39 2021 -0300

    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>

 js/ui/overviewControls.js |  32 +++++++-------
 js/ui/viewSelector.js     | 103 ++++++++++------------------------------------
 2 files changed, 36 insertions(+), 99 deletions(-)
---
diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js
index 9b1e5dea39..4e2c3f8cdb 100644
--- a/js/ui/overviewControls.js
+++ b/js/ui/overviewControls.js
@@ -287,7 +287,7 @@ class ControlsManager extends St.Widget {
 
         this.viewSelector = new ViewSelector.ViewSelector(this._searchEntry,
             this.dash.showAppsButton);
-        this.viewSelector.connect('page-empty', this._onPageEmpty.bind(this));
+        this.viewSelector.connect('notify::search-active', this._onSearchChanged.bind(this));
 
         this._thumbnailsBox =
             new WorkspaceThumbnail.ThumbnailsBox(this._workspaceAdjustment);
@@ -402,24 +402,23 @@ class ControlsManager extends St.Widget {
     }
 
     _updateThumbnailsBox(animate = false) {
-        const page = this.viewSelector.getActivePage();
-        const searching = page === ViewSelector.ViewPage.SEARCH;
+        const { searchActive } = this.viewSelector;
         const [opacity, scale, translationY] = this._getThumbnailsBoxParams();
 
-        const thumbnailsBoxVisible = !searching && opacity !== 0;
+        const thumbnailsBoxVisible = !searchActive && opacity !== 0;
         if (thumbnailsBoxVisible) {
             this._thumbnailsBox.opacity = 0;
             this._thumbnailsBox.visible = thumbnailsBoxVisible;
         }
 
         const params = {
-            opacity: searching ? 0 : opacity,
+            opacity: searchActive ? 0 : opacity,
             duration: animate ? SIDE_CONTROLS_ANIMATION_TIME : 0,
             mode: Clutter.AnimationMode.EASE_OUT_QUAD,
             onComplete: () => (this._thumbnailsBox.visible = thumbnailsBoxVisible),
         };
 
-        if (!searching) {
+        if (!searchActive) {
             params.scale_x = scale;
             params.scale_y = scale;
             params.translation_y = translationY;
@@ -442,11 +441,10 @@ class ControlsManager extends St.Widget {
         this._updateThumbnailsBox();
     }
 
-    _onPageEmpty() {
-        const page = this.viewSelector.getActivePage();
-        const isActivities = page === ViewSelector.ViewPage.ACTIVITIES;
+    _onSearchChanged() {
+        const { searchActive } = this.viewSelector;
 
-        if (isActivities) {
+        if (!searchActive) {
             this._appDisplay.show();
             this._workspacesDisplay.reactive = true;
             this._workspacesDisplay.setPrimaryWorkspaceVisible(true);
@@ -457,25 +455,25 @@ class ControlsManager extends St.Widget {
         this._updateThumbnailsBox(true);
 
         this._appDisplay.ease({
-            opacity: isActivities ? 255 : 0,
+            opacity: searchActive ? 0 : 255,
             duration: SIDE_CONTROLS_ANIMATION_TIME,
             mode: Clutter.AnimationMode.EASE_OUT_QUAD,
-            onComplete: () => (this._appDisplay.visible = isActivities),
+            onComplete: () => (this._appDisplay.visible = !searchActive),
         });
         this._workspacesDisplay.ease({
-            opacity: isActivities ? 255 : 0,
+            opacity: searchActive ? 0 : 255,
             duration: SIDE_CONTROLS_ANIMATION_TIME,
             mode: Clutter.AnimationMode.EASE_OUT_QUAD,
             onComplete: () => {
-                this._workspacesDisplay.reactive = isActivities;
-                this._workspacesDisplay.setPrimaryWorkspaceVisible(isActivities);
+                this._workspacesDisplay.reactive = !searchActive;
+                this._workspacesDisplay.setPrimaryWorkspaceVisible(!searchActive);
             },
         });
         this.viewSelector.ease({
-            opacity: isActivities ? 0 : 255,
+            opacity: searchActive ? 255 : 0,
             duration: SIDE_CONTROLS_ANIMATION_TIME,
             mode: Clutter.AnimationMode.EASE_OUT_QUAD,
-            onComplete: () => (this.viewSelector.visible = !isActivities),
+            onComplete: () => (this.viewSelector.visible = searchActive),
         });
     }
 
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index a5ab6ff3ac..210598d8cd 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -1,18 +1,12 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 /* exported ViewSelector */
 
-const { Clutter, GObject, Shell, St } = imports.gi;
+const { Clutter, GObject, St } = imports.gi;
 
 const Main = imports.ui.main;
-const OverviewControls = imports.ui.overviewControls;
 const Search = imports.ui.search;
 const ShellEntry = imports.ui.shellEntry;
 
-var ViewPage = {
-    ACTIVITIES: 1,
-    SEARCH: 2,
-};
-
 var FocusTrap = GObject.registerClass(
 class FocusTrap extends St.Widget {
     vfunc_navigate_focus(from, direction) {
@@ -33,14 +27,17 @@ function getTermsForSearchString(searchString) {
 }
 
 var ViewSelector = GObject.registerClass({
-    Signals: {
-        'page-changed': {},
-        'page-empty': {},
+    Properties: {
+        'search-active': GObject.ParamSpec.boolean(
+            'search-active', 'search-active', 'search-active',
+            GObject.ParamFlags.READABLE,
+            false),
     },
-}, class ViewSelector extends Shell.Stack {
+}, class ViewSelector extends St.Widget {
     _init(searchEntry, showAppsButton) {
         super._init({
             name: 'viewSelector',
+            layout_manager: new Clutter.BinLayout(),
             x_expand: true,
             y_expand: true,
             visible: false,
@@ -83,12 +80,8 @@ var ViewSelector = GObject.registerClass({
         this._iconClickedId = 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._searchPage = this._addPage(this._searchResults);
+        this.add_child(this._searchResults);
         Main.ctrlAltTabManager.addGroup(this._entry, _('Search'), 'edit-find-symbolic');
 
         // Since the entry isn't inside the results container we install this
@@ -117,8 +110,7 @@ var ViewSelector = GObject.registerClass({
 
     prepareToEnterOverview() {
         this.reset();
-        this._activePage = null;
-        this._showPage(this._activitiesPage);
+        this._setSearchActive(false);
     }
 
     vfunc_unmap() {
@@ -127,66 +119,16 @@ var ViewSelector = GObject.registerClass({
         super.vfunc_unmap();
     }
 
-    _addPage(actor) {
-        let page = new St.Bin({ child: actor });
-        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)
+    _setSearchActive(searchActive) {
+        if (this._searchActive === searchActive)
             return;
 
-        if (page == this._activePage)
-            return;
-
-        let oldPage = this._activePage;
-        this._activePage = page;
-        this.emit('page-changed');
-
-        if (oldPage)
-            this._animateOut(oldPage);
-        else
-            this._animateIn();
+        this._searchActive = searchActive;
+        this.notify('search-active');
     }
 
     _onShowAppsButtonToggled() {
-        this._showPage(this._activitiesPage);
+        this._setSearchActive(false);
     }
 
     _onStageKeyPress(actor, event) {
@@ -220,7 +162,7 @@ var ViewSelector = GObject.registerClass({
     }
 
     _searchCancelled() {
-        this._showPage(this._activitiesPage);
+        this._setSearchActive(false);
 
         // Leave the entry focused when it doesn't have any text;
         // when replacing a selected search term, Clutter emits
@@ -306,11 +248,11 @@ var ViewSelector = GObject.registerClass({
     _onTextChanged() {
         let terms = getTermsForSearchString(this._entry.get_text());
 
-        this._searchActive = terms.length > 0;
+        const searchActive = terms.length > 0;
         this._searchResults.setTerms(terms);
 
-        if (this._searchActive) {
-            this._showPage(this._searchPage);
+        if (searchActive) {
+            this._setSearchActive(true);
 
             this._entry.set_secondary_icon(this._clearIcon);
 
@@ -386,10 +328,7 @@ var ViewSelector = GObject.registerClass({
         return Clutter.EVENT_PROPAGATE;
     }
 
-    getActivePage() {
-        if (this._activePage === this._activitiesPage)
-            return ViewPage.ACTIVITIES;
-        else
-            return ViewPage.SEARCH;
+    get searchActive() {
+        return this._searchActive;
     }
 });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]