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
This commit is contained in:
Georges Basile Stavracas Neto 2018-07-06 10:01:39 +02:00
parent 197c0eee29
commit e9f4f2e8ae
No known key found for this signature in database
GPG Key ID: 886C17EE170D1385
2 changed files with 46 additions and 44 deletions

View File

@ -250,7 +250,7 @@ var ThumbnailsSlider = new Lang.Class({
this.actor.request_mode = Clutter.RequestMode.WIDTH_FOR_HEIGHT; this.actor.request_mode = Clutter.RequestMode.WIDTH_FOR_HEIGHT;
this.actor.reactive = true; this.actor.reactive = true;
this.actor.track_hover = 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)); Main.layoutManager.connect('monitors-changed', this._updateSlide.bind(this));
global.workspace_manager.connect('active-workspace-changed', global.workspace_manager.connect('active-workspace-changed',
@ -258,7 +258,7 @@ var ThumbnailsSlider = new Lang.Class({
global.workspace_manager.connect('notify::n-workspaces', global.workspace_manager.connect('notify::n-workspaces',
this._updateSlide.bind(this)); this._updateSlide.bind(this));
this.actor.connect('notify::hover', 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() { _getAlwaysZoomOut() {

View File

@ -615,14 +615,14 @@ Signals.addSignalMethods(WorkspaceThumbnail.prototype);
var ThumbnailsBox = new Lang.Class({ var ThumbnailsBox = new Lang.Class({
Name: 'ThumbnailsBox', Name: 'ThumbnailsBox',
Extends: St.Widget,
_init() { _init() {
this.actor = new Shell.GenericContainer({ reactive: true, this.parent({ reactive: true,
style_class: 'workspace-thumbnails', style_class: 'workspace-thumbnails',
request_mode: Clutter.RequestMode.WIDTH_FOR_HEIGHT }); 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 = this;
this.actor.connect('allocate', this._allocate.bind(this));
this.actor._delegate = this; this.actor._delegate = this;
let indicator = new St.Bin({ style_class: 'workspace-thumbnail-indicator' }); 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); Shell.util_set_hidden_from_pick(indicator, true);
this._indicator = indicator; this._indicator = indicator;
this.actor.add_actor(indicator); this.add_actor(indicator);
this._dropWorkspace = -1; this._dropWorkspace = -1;
this._dropPlaceholderPos = -1; this._dropPlaceholderPos = -1;
this._dropPlaceholder = new St.Bin({ style_class: 'placeholder' }); this._dropPlaceholder = new St.Bin({ style_class: 'placeholder' });
this.actor.add_actor(this._dropPlaceholder); this.add_actor(this._dropPlaceholder);
this._spliceIndex = -1; this._spliceIndex = -1;
this._targetScale = 0; this._targetScale = 0;
@ -652,9 +652,9 @@ var ThumbnailsBox = new Lang.Class({
this._thumbnails = []; this._thumbnails = [];
this.actor.connect('button-press-event', () => Clutter.EVENT_STOP); this.connect('button-press-event', () => Clutter.EVENT_STOP);
this.actor.connect('button-release-event', this._onButtonRelease.bind(this)); this.connect('button-release-event', this._onButtonRelease.bind(this));
this.actor.connect('touch-event', this._onTouchEvent.bind(this)); this.connect('touch-event', this._onTouchEvent.bind(this));
Main.overview.connect('showing', Main.overview.connect('showing',
this._createThumbnails.bind(this)); this._createThumbnails.bind(this));
@ -693,13 +693,13 @@ var ThumbnailsBox = new Lang.Class({
_updateSwitcherVisibility() { _updateSwitcherVisibility() {
let workspaceManager = global.workspace_manager; let workspaceManager = global.workspace_manager;
this.actor.visible = this.visible =
this._settings.get_boolean('dynamic-workspaces') || this._settings.get_boolean('dynamic-workspaces') ||
workspaceManager.n_workspaces > 1; workspaceManager.n_workspaces > 1;
}, },
_activateThumbnailAtPoint(stageX, stageY, time) { _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++) { for (let i = 0; i < this._thumbnails.length; i++) {
let thumbnail = this._thumbnails[i] let thumbnail = this._thumbnails[i]
@ -753,7 +753,7 @@ var ThumbnailsBox = new Lang.Class({
}, },
_onDragMotion(dragEvent) { _onDragMotion(dragEvent) {
if (!this.actor.contains(dragEvent.targetActor)) if (!this.contains(dragEvent.targetActor))
this._onLeave(); this._onLeave();
return DND.DragMotionResult.CONTINUE; return DND.DragMotionResult.CONTINUE;
}, },
@ -767,7 +767,7 @@ var ThumbnailsBox = new Lang.Class({
return; return;
this._dropPlaceholderPos = -1; this._dropPlaceholderPos = -1;
this.actor.queue_relayout(); this.queue_relayout();
}, },
// Draggable target interface // Draggable target interface
@ -776,7 +776,7 @@ var ThumbnailsBox = new Lang.Class({
return DND.DragMotionResult.CONTINUE; return DND.DragMotionResult.CONTINUE;
let canCreateWorkspaces = Meta.prefs_get_dynamic_workspaces(); 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; this._dropWorkspace = -1;
let placeholderPos = -1; let placeholderPos = -1;
@ -814,7 +814,7 @@ var ThumbnailsBox = new Lang.Class({
if (this._dropPlaceholderPos != placeholderPos) { if (this._dropPlaceholderPos != placeholderPos) {
this._dropPlaceholderPos = placeholderPos; this._dropPlaceholderPos = placeholderPos;
this.actor.queue_relayout(); this.queue_relayout();
} }
if (this._dropWorkspace != -1) if (this._dropWorkspace != -1)
@ -962,7 +962,7 @@ var ThumbnailsBox = new Lang.Class({
thumbnail.setPorthole(this._porthole.x, this._porthole.y, thumbnail.setPorthole(this._porthole.x, this._porthole.y,
this._porthole.width, this._porthole.height); this._porthole.width, this._porthole.height);
this._thumbnails.push(thumbnail); this._thumbnails.push(thumbnail);
this.actor.add_actor(thumbnail.actor); this.add_actor(thumbnail.actor);
if (start > 0 && this._spliceIndex == -1) { if (start > 0 && this._spliceIndex == -1) {
// not the initial fill, and not splicing via DND // not the initial fill, and not splicing via DND
@ -1011,7 +1011,7 @@ var ThumbnailsBox = new Lang.Class({
set scale(scale) { set scale(scale) {
this._scale = scale; this._scale = scale;
this.actor.queue_relayout(); this.queue_relayout();
}, },
get scale() { get scale() {
@ -1020,7 +1020,7 @@ var ThumbnailsBox = new Lang.Class({
set indicatorY(indicatorY) { set indicatorY(indicatorY) {
this._indicatorY = indicatorY; this._indicatorY = indicatorY;
this.actor.queue_relayout(); this.queue_relayout();
}, },
get indicatorY() { 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 // Once that's complete, we can start scaling to the new size and collapse any removed thumbnails
this._iterateStateThumbnails(ThumbnailState.ANIMATED_OUT, thumbnail => { this._iterateStateThumbnails(ThumbnailState.ANIMATED_OUT, thumbnail => {
this.actor.set_skip_paint(thumbnail.actor, true);
this._setThumbnailState(thumbnail, ThumbnailState.COLLAPSING); this._setThumbnailState(thumbnail, ThumbnailState.COLLAPSING);
Tweener.addTween(thumbnail, Tweener.addTween(thumbnail,
{ collapseFraction: 1, { collapseFraction: 1,
@ -1132,39 +1131,38 @@ var ThumbnailsBox = new Lang.Class({
this._stateUpdateQueued = true; this._stateUpdateQueued = true;
}, },
_getPreferredHeight(actor, forWidth, alloc) { vfunc_get_preferred_height(forWidth) {
// Note that for getPreferredWidth/Height we cheat a bit and skip propagating // 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 // 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. // that the actors aren't depending on the virtual functions being called.
if (!this._ensurePorthole()) { if (!this._ensurePorthole())
alloc.min_size = -1; return [0, 0];
alloc.natural_size = -1;
return;
}
let workspaceManager = global.workspace_manager; 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 spacing = themeNode.get_length('spacing');
let nWorkspaces = workspaceManager.n_workspaces; let nWorkspaces = workspaceManager.n_workspaces;
let totalSpacing = (nWorkspaces - 1) * spacing; let totalSpacing = (nWorkspaces - 1) * spacing;
alloc.min_size = totalSpacing; let naturalHeight = totalSpacing + nWorkspaces * this._porthole.height * MAX_THUMBNAIL_SCALE;
alloc.natural_size = totalSpacing + nWorkspaces * this._porthole.height * MAX_THUMBNAIL_SCALE;
return themeNode.adjust_preferred_height(totalSpacing, naturalHeight);
}, },
_getPreferredWidth(actor, forHeight, alloc) { vfunc_get_preferred_width(forHeight) {
if (!this._ensurePorthole()) { if (!this._ensurePorthole())
alloc.min_size = -1; return [0, 0];
alloc.natural_size = -1;
return;
}
let workspaceManager = global.workspace_manager; 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 nWorkspaces = workspaceManager.n_workspaces;
let totalSpacing = (nWorkspaces - 1) * spacing; let totalSpacing = (nWorkspaces - 1) * spacing;
@ -1174,8 +1172,8 @@ var ThumbnailsBox = new Lang.Class({
scale = Math.min(scale, MAX_THUMBNAIL_SCALE); scale = Math.min(scale, MAX_THUMBNAIL_SCALE);
let width = Math.round(this._porthole.width * 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 // The "porthole" is the portion of the screen that we show in the
@ -1190,14 +1188,18 @@ var ThumbnailsBox = new Lang.Class({
return true; 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); let rtl = (Clutter.get_default_text_direction () == Clutter.TextDirection.RTL);
if (this._thumbnails.length == 0) // not visible if (this._thumbnails.length == 0) // not visible
return; return;
let workspaceManager = global.workspace_manager; 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 portholeWidth = this._porthole.width;
let portholeHeight = this._porthole.height; let portholeHeight = this._porthole.height;