Skip to content

Commit 520ea05

Browse files
committed
classicSwitcher: Fix icon spacing when transitioning to the next
smaller size. - Remove separator code (it's been unused for a while). - Simplify and fix some allocation issues. - Fix a popdown thumbnail positioning problem. - Remove the smallest two icon sizes - it's pretty excessive and in thumbnail mode it's nearly useless to have very small icons. - Ignore enter events when an item is selected. This is due to a forwarded enter-event callback from individual items. It's simpler for the moment to ignore the calls than set up accounting for all of the item signals. - Improve some signal cleanup. Fixes #11387 ref: linuxmint/mint21.1-beta#63
1 parent 990b582 commit 520ea05

File tree

2 files changed

+37
-67
lines changed

2 files changed

+37
-67
lines changed

js/ui/appSwitcher/appSwitcher.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ AppSwitcher.prototype = {
208208
},
209209

210210
_next: function() {
211+
if (!this._windows)
212+
return;
213+
211214
if(this._windows.length <= 1) {
212215
this._currentIndex = 0;
213216
this._updateList(0);
@@ -220,6 +223,9 @@ AppSwitcher.prototype = {
220223
},
221224

222225
_previous: function() {
226+
if (!this._windows)
227+
return;
228+
223229
if(this._windows.length <= 1) {
224230
this._currentIndex = 0;
225231
this._updateList(0);
@@ -232,6 +238,9 @@ AppSwitcher.prototype = {
232238
},
233239

234240
_select: function(index) {
241+
if (!this._windows)
242+
return;
243+
235244
this._currentIndex = index;
236245
this._setCurrentWindow(this._windows[this._currentIndex]);
237246
},
@@ -454,7 +463,14 @@ AppSwitcher.prototype = {
454463
this._motionTimeoutId = 0;
455464
}
456465

457-
this._windowManager.disconnect(this._dcid);
458-
this._windowManager.disconnect(this._mcid);
466+
if (this._dcid > 0) {
467+
this._windowManager.disconnect(this._dcid);
468+
this._dcid = 0;
469+
}
470+
471+
if (this._mcid > 0) {
472+
this._windowManager.disconnect(this._mcid);
473+
this._mcid = 0;
474+
}
459475
}
460476
};

js/ui/appSwitcher/classicSwitcher.js

Lines changed: 19 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const THUMBNAIL_FADE_TIME = 0.1; // seconds
2929
const PREVIEW_DELAY_TIMEOUT = 0; // milliseconds
3030
var PREVIEW_SWITCHER_FADEOUT_TIME = 0.2; // seconds
3131

32-
const iconSizes = [96, 64, 48, 32, 22];
32+
const iconSizes = [96, 64, 48];
3333

3434
function mod(a, b) {
3535
return (a + b) % b;
@@ -124,16 +124,14 @@ ClassicSwitcher.prototype = {
124124
let thumbnailCenter = posX + icon.width / 2;
125125
let [childMinWidth, childNaturalWidth] = this._thumbnails.actor.get_preferred_width(-1);
126126
childBox.x1 = Math.max(monitor.x + leftPadding, Math.floor(thumbnailCenter - childNaturalWidth / 2));
127-
if (childBox.x1 + childNaturalWidth > monitor.x + monitor.width - hPadding) {
128-
let offset = childBox.x1 + childNaturalWidth - monitor.width + hPadding;
129-
childBox.x1 = Math.max(monitor.x + leftPadding, childBox.x1 - offset - hPadding);
127+
if (childBox.x1 + childNaturalWidth > monitor.x + monitor.width - rightPadding) {
128+
let offset = (childBox.x1 + childNaturalWidth) - (monitor.x + monitor.width - rightPadding);
129+
childBox.x1 -= offset;
130130
}
131131

132132
let spacing = this.actor.get_theme_node().get_length('spacing');
133133

134134
childBox.x2 = childBox.x1 + childNaturalWidth;
135-
if (childBox.x2 > monitor.x + monitor.width - rightPadding)
136-
childBox.x2 = monitor.x + monitor.width - rightPadding;
137135
childBox.y1 = this._appList.actor.allocation.y2 + spacing;
138136
this._thumbnails.addClones(monitor.y + monitor.height - bottomPadding - childBox.y1);
139137
let [childMinHeight, childNaturalHeight] = this._thumbnails.actor.get_preferred_height(-1);
@@ -479,8 +477,9 @@ SwitcherList.prototype = {
479477

480478
// Here we use a GenericContainer so that we can force all the
481479
// children except the separator to have the same width.
480+
// TODO: Separator is gone, we could use an St.ScrollView now.
482481
this._list = new Cinnamon.GenericContainer({ style_class: 'switcher-list-item-container' });
483-
this._list.spacing = 0;
482+
this._list.spacing = -1;
484483
this._list.connect('style-changed', Lang.bind(this, function() {
485484
this._list.spacing = this._list.get_theme_node().get_length('spacing');
486485
}));
@@ -513,7 +512,6 @@ SwitcherList.prototype = {
513512

514513
this._items = [];
515514
this._highlighted = -1;
516-
this._separator = null;
517515
this._squareItems = squareItems;
518516
this._minSize = 0;
519517
this._scrollableRight = true;
@@ -522,6 +520,10 @@ SwitcherList.prototype = {
522520
},
523521

524522
_allocateTop: function(actor, box, flags) {
523+
if (this._list.spacing === -1) {
524+
this._list.spacing = this._list.get_theme_node().get_length('spacing');
525+
}
526+
525527
let leftPadding = this.actor.get_theme_node().get_padding(St.Side.LEFT);
526528
let rightPadding = this.actor.get_theme_node().get_padding(St.Side.RIGHT);
527529

@@ -587,12 +589,6 @@ SwitcherList.prototype = {
587589
this._itemEntered(index);
588590
},
589591

590-
addSeparator: function () {
591-
let box = new St.Bin({ style_class: 'separator' });
592-
this._separator = box;
593-
this._list.add_actor(box);
594-
},
595-
596592
highlight: function(index, justOutline) {
597593
if (this._highlighted != -1) {
598594
this._items[this._highlighted].remove_style_pseudo_class('outlined');
@@ -659,36 +655,22 @@ SwitcherList.prototype = {
659655
this.emit('item-entered', n);
660656
},
661657

662-
_maxChildWidth: function (forHeight) {
658+
_maxChildWidth: function () {
663659
let maxChildMin = 0;
664660
let maxChildNat = 0;
665661

666-
for (let i = 0; i < this._items.length; i++) {
667-
let [childMin, childNat] = this._items[i].get_preferred_width(forHeight);
668-
maxChildMin = Math.max(childMin, maxChildMin);
669-
maxChildNat = Math.max(childNat, maxChildNat);
670-
671-
if (this._squareItems) {
672-
let [childMin, childNat] = this._items[i].get_preferred_height(-1);
673-
maxChildMin = Math.max(childMin, maxChildMin);
674-
maxChildNat = Math.max(childNat, maxChildNat);
675-
}
662+
if (this._items.length > 0) {
663+
return this._items[0].get_preferred_width(-1);
676664
}
677665

678-
return [maxChildMin, maxChildNat];
666+
return [0, 0]
679667
},
680668

681669
_getPreferredWidth: function (actor, forHeight, alloc) {
682-
let [maxChildMin, maxChildNat] = this._maxChildWidth(forHeight);
683-
684-
let separatorWidth = 0;
685-
if (this._separator) {
686-
let [sepMin, sepNat] = this._separator.get_preferred_width(forHeight);
687-
separatorWidth = sepNat + this._list.spacing;
688-
}
670+
let [maxChildMin, maxChildNat] = this._maxChildWidth();
689671

690672
let totalSpacing = this._list.spacing * Math.max(1, (this._items.length - 1));
691-
alloc.min_size = this._items.length * maxChildMin + separatorWidth + totalSpacing;
673+
alloc.min_size = this._items.length * maxChildMin + totalSpacing;
692674
alloc.natural_size = alloc.min_size;
693675
this._minSize = alloc.min_size;
694676
},
@@ -704,7 +686,7 @@ SwitcherList.prototype = {
704686
}
705687

706688
if (this._squareItems) {
707-
let [childMin, childNat] = this._maxChildWidth(-1);
689+
let [childMin, childNat] = this._maxChildWidth();
708690
maxChildMin = Math.max(childMin, maxChildMin);
709691
maxChildNat = maxChildMin;
710692
}
@@ -716,17 +698,10 @@ SwitcherList.prototype = {
716698
_allocate: function (actor, box, flags) {
717699
let childHeight = box.y2 - box.y1;
718700

719-
let [maxChildMin, maxChildNat] = this._maxChildWidth(childHeight);
701+
let [maxChildMin, maxChildNat] = this._maxChildWidth();
720702
let totalSpacing = this._list.spacing * (this._items.length - 1);
721703

722-
let separatorWidth = 0;
723-
if (this._separator) {
724-
let [sepMin, sepNat] = this._separator.get_preferred_width(childHeight);
725-
separatorWidth = sepNat;
726-
totalSpacing += this._list.spacing;
727-
}
728-
729-
let childWidth = Math.floor(Math.max(0, box.x2 - box.x1 - totalSpacing - separatorWidth) / this._items.length);
704+
let childWidth = Math.floor(Math.max(0, box.x2 - box.x1 - totalSpacing) / this._items.length);
730705

731706
let x = 0;
732707
let children = this._list.get_children();
@@ -754,14 +729,6 @@ SwitcherList.prototype = {
754729
children[i].allocate(childBox, flags);
755730

756731
x += this._list.spacing + childWidth;
757-
} else if (children[i] == this._separator) {
758-
// We want the separator to be more compact than the rest.
759-
childBox.x1 = x;
760-
childBox.y1 = 0;
761-
childBox.x2 = x + separatorWidth;
762-
childBox.y2 = childHeight;
763-
children[i].allocate(childBox, flags);
764-
x += this._list.spacing + separatorWidth;
765732
} else {
766733
// Something else, eg, AppList's arrows;
767734
// we don't allocate it.
@@ -830,8 +797,6 @@ AppList.prototype = {
830797
let [iconMinHeight, iconNaturalHeight] = this.icons[j].label.get_preferred_height(-1);
831798
let iconSpacing = iconNaturalHeight + iconPadding + iconBorder;
832799
let totalSpacing = this._list.spacing * (this._items.length - 1);
833-
if (this._separator)
834-
totalSpacing += this._separator.width + this._list.spacing;
835800

836801
// We just assume the whole screen here due to weirdness happing with the passed width
837802
let parentPadding = this.actor.get_parent().get_theme_node().get_horizontal_padding();
@@ -845,7 +810,6 @@ AppList.prototype = {
845810
if (w <= availWidth)
846811
break;
847812
}
848-
849813
if (this._items.length == 1) {
850814
this._iconSize = iconSizes[0];
851815
height = (iconSizes[0] * global.ui_scale) + iconSpacing;
@@ -937,22 +901,12 @@ ThumbnailList.prototype = {
937901

938902
let activeWorkspace = global.screen.get_active_workspace();
939903

940-
// We fake the value of 'separatorAdded' when the app has no window
941-
// on the current workspace, to avoid displaying a useless separator in
942-
// that case.
943-
let separatorAdded = windows.length == 0 || windows[0].get_workspace() != activeWorkspace;
944-
945904
this._labels = new Array();
946905
this._thumbnailBins = new Array();
947906
this._clones = new Array();
948907
this._windows = windows;
949908

950909
for (let i = 0; i < windows.length; i++) {
951-
if (!separatorAdded && windows[i].get_workspace() != activeWorkspace) {
952-
this.addSeparator();
953-
separatorAdded = true;
954-
}
955-
956910
let box = new St.BoxLayout({ style_class: 'thumbnail-box',
957911
vertical: true });
958912

0 commit comments

Comments
 (0)