From e9f4f2e8ae72ef370de79af7a1ea06f53c32f7f8 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Fri, 6 Jul 2018 10:01:39 +0200 Subject: [PATCH] thumbnailBox: Stop using Shell.GenericContainer This is another straight port from Shell.GenericContainer. The important thing to notice is that the calculation is broken if the StThemeNode helpers (adjust_preferred_* and adjust_for_*) aren't used. The downside of this patch is that it removed the skip_paint from the thumbnails. Keeping it would add an unecessarily large amount of code. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/153 --- js/ui/overviewControls.js | 4 +- js/ui/workspaceThumbnail.js | 86 +++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js index 4cd161374..6dd4ae032 100644 --- a/js/ui/overviewControls.js +++ b/js/ui/overviewControls.js @@ -250,7 +250,7 @@ var ThumbnailsSlider = new Lang.Class({ this.actor.request_mode = Clutter.RequestMode.WIDTH_FOR_HEIGHT; this.actor.reactive = true; this.actor.track_hover = true; - this.actor.add_actor(this._thumbnailsBox.actor); + this.actor.add_actor(this._thumbnailsBox); Main.layoutManager.connect('monitors-changed', this._updateSlide.bind(this)); global.workspace_manager.connect('active-workspace-changed', @@ -258,7 +258,7 @@ var ThumbnailsSlider = new Lang.Class({ global.workspace_manager.connect('notify::n-workspaces', this._updateSlide.bind(this)); this.actor.connect('notify::hover', this._updateSlide.bind(this)); - this._thumbnailsBox.actor.bind_property('visible', this.actor, 'visible', GObject.BindingFlags.SYNC_CREATE); + this._thumbnailsBox.bind_property('visible', this.actor, 'visible', GObject.BindingFlags.SYNC_CREATE); }, _getAlwaysZoomOut() { diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js index 76a7416c3..b8d1faeb6 100644 --- a/js/ui/workspaceThumbnail.js +++ b/js/ui/workspaceThumbnail.js @@ -615,14 +615,14 @@ Signals.addSignalMethods(WorkspaceThumbnail.prototype); var ThumbnailsBox = new Lang.Class({ Name: 'ThumbnailsBox', + Extends: St.Widget, _init() { - this.actor = new Shell.GenericContainer({ reactive: true, - style_class: 'workspace-thumbnails', - request_mode: Clutter.RequestMode.WIDTH_FOR_HEIGHT }); - this.actor.connect('get-preferred-width', this._getPreferredWidth.bind(this)); - this.actor.connect('get-preferred-height', this._getPreferredHeight.bind(this)); - this.actor.connect('allocate', this._allocate.bind(this)); + this.parent({ reactive: true, + style_class: 'workspace-thumbnails', + request_mode: Clutter.RequestMode.WIDTH_FOR_HEIGHT }); + + this.actor = this; this.actor._delegate = this; let indicator = new St.Bin({ style_class: 'workspace-thumbnail-indicator' }); @@ -631,12 +631,12 @@ var ThumbnailsBox = new Lang.Class({ Shell.util_set_hidden_from_pick(indicator, true); this._indicator = indicator; - this.actor.add_actor(indicator); + this.add_actor(indicator); this._dropWorkspace = -1; this._dropPlaceholderPos = -1; this._dropPlaceholder = new St.Bin({ style_class: 'placeholder' }); - this.actor.add_actor(this._dropPlaceholder); + this.add_actor(this._dropPlaceholder); this._spliceIndex = -1; this._targetScale = 0; @@ -652,9 +652,9 @@ var ThumbnailsBox = new Lang.Class({ this._thumbnails = []; - this.actor.connect('button-press-event', () => Clutter.EVENT_STOP); - this.actor.connect('button-release-event', this._onButtonRelease.bind(this)); - this.actor.connect('touch-event', this._onTouchEvent.bind(this)); + this.connect('button-press-event', () => Clutter.EVENT_STOP); + this.connect('button-release-event', this._onButtonRelease.bind(this)); + this.connect('touch-event', this._onTouchEvent.bind(this)); Main.overview.connect('showing', this._createThumbnails.bind(this)); @@ -693,13 +693,13 @@ var ThumbnailsBox = new Lang.Class({ _updateSwitcherVisibility() { let workspaceManager = global.workspace_manager; - this.actor.visible = + this.visible = this._settings.get_boolean('dynamic-workspaces') || workspaceManager.n_workspaces > 1; }, _activateThumbnailAtPoint(stageX, stageY, time) { - let [r, x, y] = this.actor.transform_stage_point(stageX, stageY); + let [r, x, y] = this.transform_stage_point(stageX, stageY); for (let i = 0; i < this._thumbnails.length; i++) { let thumbnail = this._thumbnails[i] @@ -753,7 +753,7 @@ var ThumbnailsBox = new Lang.Class({ }, _onDragMotion(dragEvent) { - if (!this.actor.contains(dragEvent.targetActor)) + if (!this.contains(dragEvent.targetActor)) this._onLeave(); return DND.DragMotionResult.CONTINUE; }, @@ -767,7 +767,7 @@ var ThumbnailsBox = new Lang.Class({ return; this._dropPlaceholderPos = -1; - this.actor.queue_relayout(); + this.queue_relayout(); }, // Draggable target interface @@ -776,7 +776,7 @@ var ThumbnailsBox = new Lang.Class({ return DND.DragMotionResult.CONTINUE; let canCreateWorkspaces = Meta.prefs_get_dynamic_workspaces(); - let spacing = this.actor.get_theme_node().get_length('spacing'); + let spacing = this.get_theme_node().get_length('spacing'); this._dropWorkspace = -1; let placeholderPos = -1; @@ -814,7 +814,7 @@ var ThumbnailsBox = new Lang.Class({ if (this._dropPlaceholderPos != placeholderPos) { this._dropPlaceholderPos = placeholderPos; - this.actor.queue_relayout(); + this.queue_relayout(); } if (this._dropWorkspace != -1) @@ -962,7 +962,7 @@ var ThumbnailsBox = new Lang.Class({ thumbnail.setPorthole(this._porthole.x, this._porthole.y, this._porthole.width, this._porthole.height); this._thumbnails.push(thumbnail); - this.actor.add_actor(thumbnail.actor); + this.add_actor(thumbnail.actor); if (start > 0 && this._spliceIndex == -1) { // not the initial fill, and not splicing via DND @@ -1011,7 +1011,7 @@ var ThumbnailsBox = new Lang.Class({ set scale(scale) { this._scale = scale; - this.actor.queue_relayout(); + this.queue_relayout(); }, get scale() { @@ -1020,7 +1020,7 @@ var ThumbnailsBox = new Lang.Class({ set indicatorY(indicatorY) { this._indicatorY = indicatorY; - this.actor.queue_relayout(); + this.queue_relayout(); }, get indicatorY() { @@ -1080,7 +1080,6 @@ var ThumbnailsBox = new Lang.Class({ // Once that's complete, we can start scaling to the new size and collapse any removed thumbnails this._iterateStateThumbnails(ThumbnailState.ANIMATED_OUT, thumbnail => { - this.actor.set_skip_paint(thumbnail.actor, true); this._setThumbnailState(thumbnail, ThumbnailState.COLLAPSING); Tweener.addTween(thumbnail, { collapseFraction: 1, @@ -1132,39 +1131,38 @@ var ThumbnailsBox = new Lang.Class({ this._stateUpdateQueued = true; }, - _getPreferredHeight(actor, forWidth, alloc) { + vfunc_get_preferred_height(forWidth) { // Note that for getPreferredWidth/Height we cheat a bit and skip propagating // the size request to our children because we know how big they are and know // that the actors aren't depending on the virtual functions being called. - if (!this._ensurePorthole()) { - alloc.min_size = -1; - alloc.natural_size = -1; - return; - } + if (!this._ensurePorthole()) + return [0, 0]; let workspaceManager = global.workspace_manager; - let themeNode = this.actor.get_theme_node(); + let themeNode = this.get_theme_node(); + + forWidth = themeNode.adjust_for_width(forWidth); let spacing = themeNode.get_length('spacing'); let nWorkspaces = workspaceManager.n_workspaces; let totalSpacing = (nWorkspaces - 1) * spacing; - alloc.min_size = totalSpacing; - alloc.natural_size = totalSpacing + nWorkspaces * this._porthole.height * MAX_THUMBNAIL_SCALE; + let naturalHeight = totalSpacing + nWorkspaces * this._porthole.height * MAX_THUMBNAIL_SCALE; + + return themeNode.adjust_preferred_height(totalSpacing, naturalHeight); }, - _getPreferredWidth(actor, forHeight, alloc) { - if (!this._ensurePorthole()) { - alloc.min_size = -1; - alloc.natural_size = -1; - return; - } + vfunc_get_preferred_width(forHeight) { + if (!this._ensurePorthole()) + return [0, 0]; let workspaceManager = global.workspace_manager; - let themeNode = this.actor.get_theme_node(); + let themeNode = this.get_theme_node(); - let spacing = this.actor.get_theme_node().get_length('spacing'); + forHeight = themeNode.adjust_for_height(forHeight); + + let spacing = themeNode.get_length('spacing'); let nWorkspaces = workspaceManager.n_workspaces; let totalSpacing = (nWorkspaces - 1) * spacing; @@ -1174,8 +1172,8 @@ var ThumbnailsBox = new Lang.Class({ scale = Math.min(scale, MAX_THUMBNAIL_SCALE); let width = Math.round(this._porthole.width * scale); - alloc.min_size = width; - alloc.natural_size = width; + + return themeNode.adjust_preferred_width(width, width); }, // The "porthole" is the portion of the screen that we show in the @@ -1190,14 +1188,18 @@ var ThumbnailsBox = new Lang.Class({ return true; }, - _allocate(actor, box, flags) { + vfunc_allocate(box, flags) { + this.set_allocation(box, flags); + let rtl = (Clutter.get_default_text_direction () == Clutter.TextDirection.RTL); if (this._thumbnails.length == 0) // not visible return; let workspaceManager = global.workspace_manager; - let themeNode = this.actor.get_theme_node(); + let themeNode = this.get_theme_node(); + + box = themeNode.get_content_box(box); let portholeWidth = this._porthole.width; let portholeHeight = this._porthole.height;