Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic sizing of thumbnails in alt+tab window selector #11682

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ debian/files
debian/tmp/
obj-x86_64-linux-gnu
*.pyc
sync_files.sh
10 changes: 10 additions & 0 deletions data/org.cinnamon.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@
<summary>Warp mouse pointer to the new focused window</summary>
</key>

<key type="i" name="alttab-switcher-text-minimum-size">
<default>12</default>
<summary>The minimum font size for the alt-tab switcher</summary>
</key>

<key type="i" name="alttab-switcher-thumbnail-maximum-size">
<default>1000</default>
<summary>The maximum size of thumbnails in the "Thumbnails only" alt-tab switcher</summary>
</key>

<key name="bring-windows-to-current-workspace" type="b">
<default>false</default>
<summary>not used - lives in org.cinnamon.muffin now</summary>
Expand Down
10 changes: 8 additions & 2 deletions files/usr/share/cinnamon/cinnamon-settings/modules/cs_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,14 @@ def update_setting(widget, pspec):
widget = GSettingsSpinButton(_("Delay before displaying the alt-tab switcher"), "org.cinnamon", "alttab-switcher-delay", units=_("milliseconds"), mini=0, maxi=1000, step=50, page=150)
settings.add_row(widget)

widget = GSettingsSwitch(_("Show windows from all workspaces"), "org.cinnamon", "alttab-switcher-show-all-workspaces")
widget = GSettingsSpinButton(_("The minimum text size for the alt-tab switcher"), "org.cinnamon", "alttab-switcher-text-minimum-size", units=_("pt"), mini=4, maxi=128, step=1)
settings.add_row(widget)

widget = GSettingsSwitch(_("Warp mouse pointer to the new focused window"), "org.cinnamon", "alttab-switcher-warp-mouse-pointer")
widget = GSettingsSpinButton(_("Maximum size of thumbnails in thumbnail-only alt-tab switcher"), "org.cinnamon", "alttab-switcher-thumbnail-maximum-size", units=_("px"), mini=32, maxi=2000, step=20)
settings.add_row(widget)

widget = GSettingsSwitch(_("Show windows from all workspaces"), "org.cinnamon", "alttab-switcher-show-all-workspaces")
settings.add_row(widget)

# widget = GSettingsSwitch(_("Warp mouse pointer to the new focused window"), "org.cinnamon", "alttab-switcher-warp-mouse-pointer")
# settings.add_row(widget)
57 changes: 35 additions & 22 deletions js/ui/appSwitcher/classicSwitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ const THUMBNAIL_FADE_TIME = 0.1; // seconds
const PREVIEW_DELAY_TIMEOUT = 0; // milliseconds
var PREVIEW_SWITCHER_FADEOUT_TIME = 0.2; // seconds

const iconSizes = [96, 64, 48];
const iconMinSize = 32; // minimum size of the icons in icon-only alt+tab window selector

var thumbnailMaxSize = 1000; // maximum size of thumbnail in the thumbnail-only alt+tab window selector
const thumbnailMinSize = 32; // minimum size of thumbnail in the thumbnail-only alt+tab window selector

var fontMinSize = 12; // minimum size of dynamically-sized fonts, in pt

function mod(a, b) {
return (a + b) % b;
Expand Down Expand Up @@ -68,7 +73,8 @@ ClassicSwitcher.prototype = {

this._showThumbnails = this._thumbnailsEnabled && !this._iconsEnabled;
this._showArrows = this._thumbnailsEnabled && this._iconsEnabled;

fontMinSize = global.settings.get_int("alttab-switcher-text-minimum-size");
thumbnailMaxSize = global.settings.get_int("alttab-switcher-thumbnail-maximum-size");
this._updateList(0);

this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
Expand Down Expand Up @@ -415,28 +421,27 @@ AppIcon.prototype = {
vertical: true });
this.icon = null;
this._iconBin = new St.Bin();
this.label = new St.Label({text: " "});
let bin = new St.Bin({ x_align: St.Align.MIDDLE });

this.actor.add(this._iconBin, { x_fill: false, y_fill: false } );
let title = window.get_title();
if (title) {
if (window.minimized) {
this.label = new St.Label({ text: "[" + title + "]"});
this.label.set_text("[" + title + "]");
let contrast_effect = new Clutter.BrightnessContrastEffect();
contrast_effect.set_brightness_full(-0.5, -0.5, -0.5);
this._iconBin.add_effect(contrast_effect);
}
else {
this.label = new St.Label({ text: title });
this.label.set_text(title);
}

let bin = new St.Bin({ x_align: St.Align.MIDDLE });
bin.add_actor(this.label);
this.actor.add(bin);
}
else {
this.label = new St.Label({ text: this.app ? this.app.get_name() : window.title });
this.actor.add(this.label, { x_fill: false });
this.label.set_text(this.app ? this.app.get_name() : window.title );
}
bin.add_actor(this.label, { x_fill: false });
this.actor.add(bin);
},

set_size: function(size) {
Expand All @@ -458,6 +463,12 @@ AppIcon.prototype = {
icon_type: St.IconType.FULLCOLOR,
icon_size: size });
}

this.fontSize = Math.max(size / 24, fontMinSize); // allow font no smaller than 12 pt
this.fontSize = Math.min(this.fontSize, 20); // allow font no larger than 20 pt
this.fontSize *= global.ui_scale; // scale fonts for ui scale
this.label.set_style("font-size: " + this.fontSize + "pt;");
this.label.set_height(this.fontSize * 1.2 + this.bottomPadding);
size *= global.ui_scale;
this._iconBin.set_size(size, size);
this._iconBin.child = this.icon;
Expand Down Expand Up @@ -780,6 +791,7 @@ AppList.prototype = {
this._showArrows = showArrows;
this._mouseTimeOutId = 0;
this._activeMonitor = activeMonitor;
this._showThumbnails = showThumbnails;
},

_getPreferredHeight: function (actor, forWidth, alloc) {
Expand All @@ -803,19 +815,20 @@ AppList.prototype = {
let availWidth = this._activeMonitor.width - parentPadding - this.actor.get_theme_node().get_horizontal_padding();
let height = 0;

for(let i = 0; i < iconSizes.length; i++) {
this._iconSize = iconSizes[i];
height = (iconSizes[i] * global.ui_scale) + iconSpacing;
let w = height * this._items.length + totalSpacing;
if (w <= availWidth)
break;
}
if (this._items.length == 1) {
this._iconSize = iconSizes[0];
height = (iconSizes[0] * global.ui_scale) + iconSpacing;
}
if (this._showThumbnails) {
if (this._items.length == 1) {
this._iconSize = thumbnailMaxSize;
} else {
this._iconSize = Math.min((availWidth / this._items.length) - iconSpacing, thumbnailMaxSize);
this._iconSize = Math.max(this._iconSize, thumbnailMinSize);
}
} else {
this._iconSize = Math.max(this._activeMonitor.width / 14, iconMinHeight);
}
height = this._iconSize + iconSpacing;
this._iconSize /= global.ui_scale;

for(let i = 0; i < this.icons.length; i++) {
for (let i = 0; i < this.icons.length; i++) {
if (this.icons[i].icon != null)
break;
this.icons[i].set_size(this._iconSize);
Expand Down