summaryrefslogtreecommitdiffstats
path: root/extensions/44/vertical-workspaces/lib/iconGrid.js
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/44/vertical-workspaces/lib/iconGrid.js')
-rw-r--r--extensions/44/vertical-workspaces/lib/iconGrid.js131
1 files changed, 81 insertions, 50 deletions
diff --git a/extensions/44/vertical-workspaces/lib/iconGrid.js b/extensions/44/vertical-workspaces/lib/iconGrid.js
index 1aa980e..1f7516b 100644
--- a/extensions/44/vertical-workspaces/lib/iconGrid.js
+++ b/extensions/44/vertical-workspaces/lib/iconGrid.js
@@ -9,11 +9,13 @@
*/
'use strict';
-const { GLib, St, Meta } = imports.gi;
+
+const St = imports.gi.St;
+
const IconGrid = imports.ui.iconGrid;
-const Me = imports.misc.extensionUtils.getCurrentExtension();
-const _Util = Me.imports.lib.util;
-const shellVersion = _Util.shellVersion;
+
+let Me;
+let opt;
// added sizes for better scaling
const IconSize = {
@@ -29,47 +31,58 @@ const IconSize = {
LARGE: 96,
80: 80,
64: 64,
- 48: 48,
- TINY: 32,
+ TINY: 48,
};
const PAGE_WIDTH_CORRECTION = 100;
-let opt;
-let _overrides;
-let _firstRun = true;
-
-function update(reset = false) {
- opt = Me.imports.lib.settings.opt;
- const moduleEnabled = opt.get('appDisplayModule', true);
- reset = reset || !moduleEnabled;
+var IconGridModule = class {
+ constructor(me) {
+ Me = me;
+ opt = Me.opt;
- // don't even touch this module if disabled
- if (_firstRun && reset)
- return;
+ this._firstActivation = true;
+ this.moduleEnabled = false;
+ this._overrides = null;
+ }
- _firstRun = false;
+ cleanGlobals() {
+ Me = null;
+ opt = null;
+ }
- if (_overrides)
- _overrides.removeAll();
+ update(reset) {
+ this.moduleEnabled = opt.get('appDisplayModule');
+ // if notifications are enabled no override is needed
+ reset = reset || !this.moduleEnabled;
+
+ // don't touch original code if module disabled
+ if (reset && !this._firstActivation) {
+ this._disableModule();
+ } else if (!reset) {
+ this._firstActivation = false;
+ this._activateModule();
+ }
+ }
+ _activateModule() {
+ if (!this._overrides)
+ this._overrides = new Me.Util.Overrides();
- if (reset) {
- _overrides = null;
- opt = null;
- return;
+ if (Me.shellVersion < 43 && IconGridCommon._findBestModeForSize) {
+ IconGridCommon['findBestModeForSize'] = IconGridCommon._findBestModeForSize;
+ delete IconGridCommon['_findBestModeForSize'];
+ }
+ this._overrides.addOverride('IconGrid', IconGrid.IconGrid.prototype, IconGridCommon);
+ this._overrides.addOverride('IconGridLayout', IconGrid.IconGridLayout.prototype, IconGridLayoutCommon);
}
- _overrides = new _Util.Overrides();
-
- if (shellVersion < 43 && IconGridCommon._findBestModeForSize) {
- IconGridCommon['findBestModeForSize'] = IconGridCommon._findBestModeForSize;
- IconGridCommon['_findBestModeForSize'] = undefined;
+ _disableModule() {
+ if (this._overrides)
+ this._overrides.removeAll();
+ this._overrides = null;
}
- _overrides.addOverride('IconGrid', IconGrid.IconGrid.prototype, IconGridCommon);
- _overrides.addOverride('IconGridLayout', IconGrid.IconGridLayout.prototype, IconGridLayoutCommon);
-}
-// workaround - silence page -2 error on gnome 43 while cleaning app grid
+};
const IconGridCommon = {
getItemsAtPage(page) {
@@ -87,7 +100,7 @@ const IconGridCommon = {
return;
const { pagePadding } = this.layout_manager;
const { scaleFactor } = St.ThemeContext.get_for_stage(global.stage);
- const iconPadding = 53 * scaleFactor;
+ const iconPadding = 51 * scaleFactor;
// provided width is usually about 100px wider in horizontal orientation with prev/next page indicators
const pageIndicatorCompensation = opt.ORIENTATION ? 0 : PAGE_WIDTH_CORRECTION;
@@ -99,8 +112,13 @@ const IconGridCommon = {
this.layoutManager._gridWidth = width;
this.layoutManager._gridHeight = height;
+ width -= 80; // compensation for default padding
+ height -= 80;
+
const spacing = opt.APP_GRID_SPACING;
- const iconSize = (opt.APP_GRID_ICON_SIZE > 0 ? opt.APP_GRID_ICON_SIZE : opt.APP_GRID_ICON_SIZE_DEFAULT) * scaleFactor;
+ // set the icon size as fixed to avoid changes in size later
+ const iconSize = opt.APP_GRID_ICON_SIZE > 0 ? opt.APP_GRID_ICON_SIZE : opt.APP_GRID_ICON_SIZE_DEFAULT;
+ const itemSize = iconSize * scaleFactor + iconPadding;
// if this._gridModes.length === 1, custom grid should be used
// if (iconSize > 0 && this._gridModes.length > 1) {
let columns = opt.APP_GRID_COLUMNS;
@@ -109,17 +127,20 @@ const IconGridCommon = {
let unusedSpaceH = -1;
let unusedSpaceV = -1;
if (!columns) {
- columns = Math.floor(width / (iconSize + iconPadding)) + 1;
+ // calculate #columns + 1 without spacing
+ columns = Math.floor(width / itemSize) + 1;
+ // check if columns with spacing fits the available width
+ // and reduce the number until it fits
while (unusedSpaceH < 0) {
columns -= 1;
- unusedSpaceH = width - columns * (iconSize + iconPadding) - (columns - 1) * spacing;
+ unusedSpaceH = width - columns * itemSize - (columns - 1) * spacing;
}
}
if (!rows) {
- rows = Math.floor(height / (iconSize + iconPadding)) + 1;
+ rows = Math.floor(height / itemSize) + 1;
while (unusedSpaceV < 0) {
rows -= 1;
- unusedSpaceV = height - rows * (iconSize + iconPadding) - (rows - 1) * spacing;
+ unusedSpaceV = height - rows * itemSize - ((rows - 1) * spacing);
}
}
@@ -135,9 +156,16 @@ const IconGridLayoutCommon = {
const { scaleFactor } = St.ThemeContext.get_for_stage(global.stage);
const nColumns = this.columnsPerPage;
const nRows = this.rowsPerPage;
+
+ // if grid is not defined return default icon size
+ if (nColumns < 1 && nRows < 1) {
+ return this._isFolder
+ ? opt.APP_GRID_FOLDER_ICON_SIZE_DEFAULT : opt.APP_GRID_ICON_SIZE_DEFAULT;
+ }
+
const columnSpacingPerPage = opt.APP_GRID_SPACING * (nColumns - 1);
const rowSpacingPerPage = opt.APP_GRID_SPACING * (nRows - 1);
- const iconPadding = 53 * scaleFactor;
+ const iconPadding = 55 * scaleFactor;
const paddingH = this._isFolder ? this.pagePadding.left + this.pagePadding.right : 0;
const paddingV = this._isFolder ? this.pagePadding.top + this.pagePadding.bottom : 0;
@@ -156,10 +184,14 @@ const IconGridLayoutCommon = {
return opt.APP_GRID_ICON_SIZE_DEFAULT;*/
let iconSizes = Object.values(IconSize).sort((a, b) => b - a);
-
- // limit max icon size for folders, the whole range is for the main grid with active folders
- if (this._isFolder)
+ // limit max icon size for folders and fully adaptive folder grids, the whole range is for the main grid with active folders
+ if (this._isFolder && opt.APP_GRID_FOLDER_ADAPTIVE && opt.APP_GRID_FOLDER_ICON_SIZE < 0)
+ iconSizes = iconSizes.slice(iconSizes.indexOf(opt.APP_GRID_FOLDER_ICON_SIZE_DEFAULT), -1);
+ else if (this._isFolder)
iconSizes = iconSizes.slice(iconSizes.indexOf(IconSize.LARGE), -1);
+ else if (opt.APP_GRID_ADAPTIVE && opt.APP_GRID_ICON_SIZE < 0)
+ iconSizes = iconSizes.slice(iconSizes.indexOf(opt.APP_GRID_ICON_SIZE_DEFAULT), -1);
+
let sizeInvalid = false;
for (const size of iconSizes) {
@@ -167,10 +199,9 @@ const IconGridLayoutCommon = {
if (firstItem) {
firstItem.icon.setIconSize(size);
- const [firstItemWidth, firstItemHeight] =
- firstItem.get_preferred_size();
+ const [firstItemWidth] = firstItem.get_preferred_size();
- const itemSize = Math.max(firstItemWidth, firstItemHeight);
+ const itemSize = firstItemWidth;
if (itemSize < size)
sizeInvalid = true;
@@ -199,7 +230,7 @@ const IconGridLayoutCommon = {
removeItem(item) {
if (!this._items.has(item)) {
- log(`Item ${item} is not part of the IconGridLayout`);
+ console.error(`Item ${item} is not part of the IconGridLayout`);
return;
// throw new Error(`Item ${item} is not part of the IconGridLayout`);
}
@@ -215,13 +246,13 @@ const IconGridLayoutCommon = {
addItem(item, page = -1, index = -1) {
if (this._items.has(item)) {
- log(`iconGrid: Item ${item} already added to IconGridLayout`);
+ console.error(`iconGrid: Item ${item} already added to IconGridLayout`);
return;
// throw new Error(`Item ${item} already added to IconGridLayout`);
}
if (page > this._pages.length) {
- log(`iconGrid: Cannot add ${item} to page ${page}`);
+ console.error(`iconGrid: Cannot add ${item} to page ${page}`);
page = -1;
index = -1;
// throw new Error(`Cannot add ${item} to page ${page}`);
@@ -240,7 +271,7 @@ const IconGridLayoutCommon = {
moveItem(item, newPage, newPosition) {
if (!this._items.has(item)) {
- log(`iconGrid: Item ${item} is not part of the IconGridLayout`);
+ console.error(`iconGrid: Item ${item} is not part of the IconGridLayout`);
return;
// throw new Error(`Item ${item} is not part of the IconGridLayout`);
}