Repository navigation
Expand file tree
/
Copy pathextension.js
More file actions
663 lines (604 loc) · 27.3 KB
/
Copy pathextension.js
File metadata and controls
663 lines (604 loc) · 27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
// Copyright (C) 2026 DIOR27
// SPDX-License-Identifier: GPL-2.0-only
import Cogl from 'gi://Cogl';
import Clutter from 'gi://Clutter';
import GdkPixbuf from 'gi://GdkPixbuf';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import Shell from 'gi://Shell';
import St from 'gi://St';
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
import * as IconGrid from 'resource:///org/gnome/shell/ui/iconGrid.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
export default class ConsistentIconsExtension extends Extension {
enable() {
this._appPrototype = Shell.App.prototype;
this._originalCreateIconTexture = this._appPrototype.create_icon_texture;
this._styledIconActors = new WeakMap();
const extension = this;
this._patchedCreateIconTexture = function (size) {
const source = extension._originalCreateIconTexture.call(this, size);
const styled = extension._styleAppIcon(source, size);
if (styled !== source)
extension._styledIconActors.set(styled, {app: this, size});
return styled;
};
this._appPrototype.create_icon_texture = this._patchedCreateIconTexture;
this._settings = St.Settings.get();
this._extensionSettings = this.getSettings();
this._extensionSettingsChangedId = this._extensionSettings.connect(
'changed', () => this._refreshAppIcons());
this._backgroundSettings = new Gio.Settings({
schema_id: 'org.gnome.desktop.background',
});
this._backgroundSettingsChangedId = this._backgroundSettings.connect(
'changed', () => this._refreshWallpaperPalette());
this._wallpaperPalette = null;
this._refreshWallpaperPalette(false);
this._themeContext = St.ThemeContext.get_for_stage(global.stage);
this._analysisCache = new Map();
this._scaleFactorChangedId = this._themeContext.connect(
'notify::scale-factor', () => {
this._analysisCache.clear();
this._refreshAppIcons();
});
this._iconTheme = new St.IconTheme();
this._iconThemeChangedId = this._iconTheme.connect('changed', () => {
this._analysisCache.clear();
this._refreshAppIcons();
});
this._colorSchemeChangedId = this._settings.connect(
'notify::color-scheme', () => {
this._refreshWallpaperPalette(false);
this._updateTileColors();
});
this._accentColorChangedId = this._settings.connect(
'notify::accent-color', () => this._updateTileColors());
this._refreshAppIcons();
}
disable() {
if (this._colorSchemeChangedId) {
this._settings.disconnect(this._colorSchemeChangedId);
this._colorSchemeChangedId = 0;
}
if (this._accentColorChangedId) {
this._settings.disconnect(this._accentColorChangedId);
this._accentColorChangedId = 0;
}
if (this._extensionSettingsChangedId) {
this._extensionSettings.disconnect(this._extensionSettingsChangedId);
this._extensionSettingsChangedId = 0;
}
if (this._backgroundSettingsChangedId) {
this._backgroundSettings.disconnect(this._backgroundSettingsChangedId);
this._backgroundSettingsChangedId = 0;
}
if (this._iconThemeChangedId) {
this._iconTheme.disconnect(this._iconThemeChangedId);
this._iconThemeChangedId = 0;
}
if (this._scaleFactorChangedId) {
this._themeContext.disconnect(this._scaleFactorChangedId);
this._scaleFactorChangedId = 0;
}
if (this._appPrototype?.create_icon_texture === this._patchedCreateIconTexture)
this._appPrototype.create_icon_texture = this._originalCreateIconTexture;
this._restoreDockIcons();
// Recreate current actors with the original Shell method so padding and
// background styling disappear immediately when the extension is off.
this._refreshAppIcons();
this._appPrototype = null;
this._originalCreateIconTexture = null;
this._patchedCreateIconTexture = null;
this._settings = null;
this._extensionSettings = null;
this._backgroundSettings = null;
this._wallpaperPalette = null;
this._themeContext = null;
this._iconTheme = null;
this._analysisCache = null;
this._styledIconActors = null;
}
_styleAppIcon(source, size) {
if (!(source instanceof St.Icon))
return source;
const analysis = this._analyzeIcon(source, size);
if (analysis?.shape === 'rounded-square')
return source;
if (analysis?.shape === 'square') {
try {
const rounded = this._createImageActor(
analysis.pixbuf, size, true, analysis.bounds);
source.destroy();
return rounded;
} catch (error) {
console.debug(`Consistent Icons: cannot round square icon: ${error.message}`);
}
} else if (analysis?.shape === 'other') {
try {
const contentSize = Math.max(1, Math.round(size * 0.70));
const image = this._createImageActor(
analysis.pixbuf, contentSize, false, analysis.bounds);
source.destroy();
return this._createTile(image, size, analysis.palette);
} catch (error) {
console.debug(`Consistent Icons: cannot render icon image: ${error.message}`);
}
}
const contentSize = Math.max(1, Math.round(size * 0.70));
source.x_align = Clutter.ActorAlign.CENTER;
source.y_align = Clutter.ActorAlign.CENTER;
source.set_size(contentSize, contentSize);
return this._createTile(source, size, analysis?.palette ?? null);
}
_styleTile(tile, size, palette = null) {
const settings = this._extensionSettings;
const mode = settings.get_int('background-mode');
const dark = this._getTileAppearance(mode);
const radius = Math.max(3, Math.round(size * 0.22));
const gradientPalette = mode === 2 && settings.get_int('gradient-source') === 1
? this._wallpaperPalette ?? palette
: palette;
const hasGradient = mode === 2 && gradientPalette?.length > 1;
let backgroundColor = dark ? '#292a30' : '#f1f2f4';
if (mode === 1) {
backgroundColor = settings.get_int('solid-color-source') === 0
? '-st-accent-color'
: this._getSafeCustomColor();
}
tile.set_content(hasGradient
? this._createGradientContent(gradientPalette, size,
settings.get_int('gradient-style'), settings.get_int('gradient-direction'),
settings.get_int('wave-orientation'), settings.get_int('radial-center'))
: null);
const style = dark
? `background-color: ${hasGradient ? 'transparent' : backgroundColor}; border: 1px solid rgba(255,255,255,0.045); border-radius: ${radius}px; box-shadow: 0 1px 3px rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.065);`
: `background-color: ${hasGradient ? 'transparent' : backgroundColor}; border: 1px solid rgba(255,255,255,0.55); border-radius: ${radius}px; box-shadow: 0 1px 3px rgba(0,0,0,0.14), inset 0 1px 0 rgba(255,255,255,0.72);`;
tile.set_style(style);
}
_getSystemDarkAppearance() {
const variant = Main.getStyleVariant();
return variant === 'dark' ||
(variant === '' && this._settings.colorScheme === St.SystemColorScheme.PREFER_DARK);
}
_getTileAppearance(backgroundMode) {
if (backgroundMode !== 0)
return this._getSystemDarkAppearance();
const appearance = this._extensionSettings.get_int('system-appearance');
if (appearance === 1)
return false;
if (appearance === 2)
return true;
return this._getSystemDarkAppearance();
}
_getWallpaperUri() {
const dark = this._getSystemDarkAppearance();
const primaryKey = dark ? 'picture-uri-dark' : 'picture-uri';
const fallbackKey = dark ? 'picture-uri' : 'picture-uri-dark';
return this._backgroundSettings.get_string(primaryKey) ||
this._backgroundSettings.get_string(fallbackKey);
}
_refreshWallpaperPalette(updateTiles = true) {
this._wallpaperPalette = null;
try {
const path = Gio.File.new_for_uri(this._getWallpaperUri()).get_path();
if (path) {
const pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(path, 256, 256, true);
this._wallpaperPalette = this._extractPalette(pixbuf);
}
} catch (error) {
console.debug(`Consistent Icons: cannot inspect wallpaper: ${error.message}`);
}
if (updateTiles && this._styledIconActors)
this._updateTileColors();
}
_getSafeCustomColor() {
const color = this._extensionSettings.get_string('solid-color');
return /^#[\da-f]{6}(?:[\da-f]{2})?$/i.test(color) ||
/^rgba?\([\d.,%\s]+\)$/i.test(color)
? color
: '#3584e4';
}
_createTile(icon, size, palette = null) {
const tile = new St.Widget({
layout_manager: new Clutter.BinLayout(),
style_class: 'consistent-app-icon-tile',
width: size,
height: size,
content_gravity: Clutter.ContentGravity.RESIZE_ASPECT,
reactive: false,
can_focus: false,
});
tile._consistentIconPalette = palette;
tile.add_child(icon);
const syncSize = () => {
const tileSize = Math.max(tile.width, tile.height, size);
const contentSize = Math.max(1, Math.round(tileSize * 0.70));
icon.set_size(contentSize, contentSize);
this._styleTile(tile, tileSize, tile._consistentIconPalette);
};
tile.connect('notify::width', syncSize);
tile.connect('notify::height', syncSize);
this._styleTile(tile, size, palette);
return tile;
}
_analyzeIcon(icon, iconSize) {
if (!(icon instanceof St.Icon))
return null;
const gicon = icon.gicon ?? (icon.icon_name
? new Gio.ThemedIcon({name: icon.icon_name})
: null);
if (!gicon)
return null;
const scale = Math.max(1, this._themeContext.scale_factor);
// St.Icon sizes are logical pixels; the scale argument asks the icon
// theme for the matching high-resolution source when one is available.
const requestedSize = Math.max(1, Math.round(
iconSize || icon.icon_size || icon.width || 48));
const key = `${gicon.to_string()}:${requestedSize}@${scale}`;
if (this._analysisCache.has(key))
return this._analysisCache.get(key);
let analysis = null;
try {
// Use the active icon theme at the actor's real display scale.
// Without FORCE_SIZE, raster assets are not enlarged before display.
const pixbuf = this._iconTheme.lookup_by_gicon_for_scale(
gicon, requestedSize, scale, 0)?.load_icon();
if (pixbuf) {
const shape = this._classifyShape(pixbuf);
analysis = {...shape, pixbuf,
palette: this._extractPalette(pixbuf, shape.bounds)};
}
} catch (error) {
console.debug(`Consistent Icons: cannot inspect icon: ${error.message}`);
}
this._analysisCache.set(key, analysis);
return analysis;
}
_classifyShape(pixbuf) {
const imageWidth = pixbuf.get_width();
const imageHeight = pixbuf.get_height();
const pixels = pixbuf.get_pixels();
const channels = pixbuf.get_n_channels();
const rowstride = pixbuf.get_rowstride();
const alpha = (x, y) => channels === 4
? pixels[y * rowstride + x * channels + 3]
: 255;
let minX = imageWidth;
let minY = imageHeight;
let maxX = -1;
let maxY = -1;
for (let y = 0; y < imageHeight; y++) {
for (let x = 0; x < imageWidth; x++) {
if (alpha(x, y) < 120)
continue;
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
}
}
if (maxX < minX || maxY < minY)
return {shape: 'other'};
const width = maxX - minX + 1;
const height = maxY - minY + 1;
if (width < 16 || height < 16 ||
Math.abs(width - height) > Math.max(width, height) * 0.06)
return {shape: 'other', bounds: {x: minX, y: minY, width, height}};
const sample = (x, y) => {
const px = minX + Math.round(x * (width - 1));
const py = minY + Math.round(y * (height - 1));
return alpha(px, py);
};
const opaque = (x, y) => sample(x, y) >= 210;
const edgeMids = [[0.5, 0.02], [0.5, 0.98], [0.02, 0.5], [0.98, 0.5]];
if (!edgeMids.every(([x, y]) => opaque(x, y)))
return {shape: 'other', bounds: {x: minX, y: minY, width, height}};
const directions = [[1, 1], [-1, 1], [1, -1], [-1, -1]];
const roundedCorners = directions.every(([xDir, yDir]) => {
const point = (x, y) => sample(xDir > 0 ? x : 1 - x, yDir > 0 ? y : 1 - y);
if (point(0.02, 0.02) >= 120 || point(0.12, 0.12) < 210)
return false;
// A curved corner reaches the side before the diagonal does; this
// separates a rounded square from circular or irregular artwork.
const offsets = [0.06, 0.1, 0.14, 0.18, 0.22, 0.26, 0.3];
return offsets.some(offset => point(0.02, offset) >= 210 &&
point(offset, 0.02) >= 210);
});
if (roundedCorners)
return {shape: 'rounded-square', bounds: {x: minX, y: minY, width, height}};
const sharpCorners = directions.every(([xDir, yDir]) => {
const x = xDir > 0 ? 0.02 : 0.98;
const y = yDir > 0 ? 0.02 : 0.98;
const insetX = xDir > 0 ? 0.04 : 0.96;
const insetY = yDir > 0 ? 0.04 : 0.96;
return opaque(x, y) || opaque(insetX, insetY);
});
return {shape: sharpCorners ? 'square' : 'other',
bounds: {x: minX, y: minY, width, height}};
}
_extractPalette(pixbuf, bounds = null) {
const imageWidth = bounds?.width ?? pixbuf.get_width();
const imageHeight = bounds?.height ?? pixbuf.get_height();
const xOffset = bounds?.x ?? 0;
const yOffset = bounds?.y ?? 0;
const pixels = pixbuf.get_pixels();
const channels = pixbuf.get_n_channels();
const rowstride = pixbuf.get_rowstride();
const step = Math.max(1, Math.ceil(Math.sqrt(imageWidth * imageHeight / 4096)));
const colors = new Map();
let total = 0;
for (let y = 0; y < imageHeight; y += step) {
for (let x = 0; x < imageWidth; x += step) {
const source = (y + yOffset) * rowstride + (x + xOffset) * channels;
if (channels === 4 && pixels[source + 3] < 120)
continue;
const red = pixels[source];
const green = pixels[source + 1];
const blue = pixels[source + 2];
const maximum = Math.max(red, green, blue);
const minimum = Math.min(red, green, blue);
const saturation = maximum === 0 ? 0 : (maximum - minimum) / maximum;
const hue = this._paletteHue({red, green, blue});
const key = saturation < 0.18
? `neutral:${Math.min(7, Math.floor(maximum / 32))}`
: `hue:${Math.floor(((hue + 15) % 360) / 30)}`;
const entry = colors.get(key) ?? {red: 0, green: 0, blue: 0, count: 0};
entry.red += red;
entry.green += green;
entry.blue += blue;
entry.count++;
colors.set(key, entry);
total++;
}
}
if (total === 0)
return null;
const toRgb = color => ({
red: color.red / color.count,
green: color.green / color.count,
blue: color.blue / color.count,
});
const leaders = [...colors.values()];
const largestCount = Math.max(...leaders.map(color => color.count));
const byHue = (a, b) => this._paletteHue(a) - this._paletteHue(b);
const tiedLeaders = leaders
.filter(color => color.count === largestCount)
.map(toRgb)
.sort(byHue);
const selectedColors = tiedLeaders.length >= 3
? [tiedLeaders[0]]
: leaders
.filter(color => largestCount - color.count <= total * 0.02)
.sort((a, b) => b.count - a.count || byHue(toRgb(a), toRgb(b)))
.slice(0, 2)
.map(toRgb)
.sort(byHue);
const palette = [];
for (const color of selectedColors) {
palette.push(
this._mixColor(color, {red: 255, green: 255, blue: 255}, 0.35),
color,
this._mixColor(color, {red: 0, green: 0, blue: 0}, 0.25));
}
return palette;
}
_paletteHue(color) {
const red = color.red / 255;
const green = color.green / 255;
const blue = color.blue / 255;
const max = Math.max(red, green, blue);
const min = Math.min(red, green, blue);
const delta = max - min;
if (delta < 0.04)
return 360 + (red + green + blue) / 765;
let hue;
if (max === red)
hue = ((green - blue) / delta) % 6;
else if (max === green)
hue = (blue - red) / delta + 2;
else
hue = (red - green) / delta + 4;
return (hue * 60 + 360) % 360;
}
_mixColor(first, second, amount) {
return {
red: first.red * (1 - amount) + second.red * amount,
green: first.green * (1 - amount) + second.green * amount,
blue: first.blue * (1 - amount) + second.blue * amount,
};
}
_createGradientContent(palette, size, style, direction, waveOrientation, radialCenter) {
if (!palette || palette.length < 2 || size < 1)
return null;
const rgba = new Uint8Array(size * size * 4);
const linearVectors = [
[1, 0], [1, 1], [0, 1], [-1, 1],
[-1, 0], [-1, -1], [0, -1], [1, -1],
];
const waveVectors = [
[1, 0], [0, 1], [-1, 0], [0, -1],
[1, 1], [-1, 1], [-1, -1], [1, -1],
];
const [vectorX, vectorY] = linearVectors[
Math.clamp(direction, 0, linearVectors.length - 1)];
const [waveX, waveY] = waveVectors[
Math.clamp(waveOrientation, 0, waveVectors.length - 1)];
const linearSpan = Math.abs(vectorX) + Math.abs(vectorY);
const waveLength = Math.hypot(waveX, waveY);
const waveUnitX = waveX / waveLength;
const waveUnitY = waveY / waveLength;
const waveSpan = Math.abs(waveUnitX) + Math.abs(waveUnitY);
const radialCenters = [
[0.5, 0.5], [0.25, 0.5], [0.25, 0.25], [0.5, 0.25],
[0.75, 0.25], [0.75, 0.5], [0.75, 0.75], [0.5, 0.75],
[0.25, 0.75],
];
const [centerX, centerY] = radialCenters[
Math.clamp(radialCenter, 0, radialCenters.length - 1)];
const radialX = centerX - 0.5;
const radialY = centerY - 0.5;
const corners = [[-0.5, -0.5], [0.5, -0.5], [-0.5, 0.5], [0.5, 0.5]];
const radialMax = Math.max(...corners.map(([x, y]) =>
Math.hypot(x - radialX, y - radialY)));
const radius = size * 0.22;
const getColor = t => {
const position = Math.clamp(t, 0, 1) * (palette.length - 1);
const index = Math.min(Math.floor(position), palette.length - 2);
const amount = position - index;
return this._mixColor(palette[index], palette[index + 1], amount);
};
for (let y = 0; y < size; y++) {
for (let x = 0; x < size; x++) {
const nx = size === 1 ? 0 : x / (size - 1) - 0.5;
const ny = size === 1 ? 0 : y / (size - 1) - 0.5;
let t;
if (style === 1) {
t = Math.hypot(nx - radialX, ny - radialY) / radialMax;
} else if (style === 2) {
const along = nx * waveUnitX + ny * waveUnitY;
const across = -nx * waveUnitY + ny * waveUnitX;
t = (along + waveSpan / 2) / waveSpan +
Math.sin(across * Math.PI * 4) * 0.14;
} else {
t = (nx * vectorX + ny * vectorY + linearSpan / 2) / linearSpan;
}
const color = getColor(t);
const target = (y * size + x) * 4;
rgba[target] = color.red;
rgba[target + 1] = color.green;
rgba[target + 2] = color.blue;
const centerX = Math.max(radius, Math.min(size - radius, x + 0.5));
const centerY = Math.max(radius, Math.min(size - radius, y + 0.5));
const distance = Math.hypot(x + 0.5 - centerX, y + 0.5 - centerY);
rgba[target + 3] = Math.round(255 * Math.clamp(radius + 0.5 - distance, 0, 1));
}
}
return this._createImageContent(rgba, size, size);
}
_createImageContent(rgba, width, height) {
const content = new St.ImageContent({preferredWidth: width, preferredHeight: height});
const coglContext = [];
const backend = global.stage?.context?.get_backend?.();
// GNOME Shell 48 added Cogl.Context as the first set_bytes() argument.
if (content.set_bytes.length === 6 && backend?.get_cogl_context)
coglContext.push(backend.get_cogl_context());
content.set_bytes(...coglContext, GLib.Bytes.new(rgba), Cogl.PixelFormat.RGBA_8888,
width, height, width * 4);
return content;
}
_createImageActor(pixbuf, size, roundCorners = false, bounds = null) {
const xOffset = bounds?.x ?? 0;
const yOffset = bounds?.y ?? 0;
const width = bounds?.width ?? pixbuf.get_width();
const height = bounds?.height ?? pixbuf.get_height();
const pixels = pixbuf.get_pixels();
const channels = pixbuf.get_n_channels();
const rowstride = pixbuf.get_rowstride();
const rgba = new Uint8Array(width * height * 4);
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const source = (y + yOffset) * rowstride + (x + xOffset) * channels;
const target = (y * width + x) * 4;
rgba[target] = pixels[source];
rgba[target + 1] = pixels[source + 1];
rgba[target + 2] = pixels[source + 2];
rgba[target + 3] = channels === 4 ? pixels[source + 3] : 255;
if (roundCorners) {
const radius = Math.min(width, height) * 0.22;
const centerX = Math.max(radius, Math.min(width - radius, x + 0.5));
const centerY = Math.max(radius, Math.min(height - radius, y + 0.5));
const distance = Math.hypot(x + 0.5 - centerX, y + 0.5 - centerY);
const coverage = Math.clamp(radius + 0.5 - distance, 0, 1);
rgba[target + 3] = Math.round(rgba[target + 3] * coverage);
}
}
}
const content = this._createImageContent(rgba, width, height);
return new St.Widget({
content,
content_gravity: Clutter.ContentGravity.RESIZE_ASPECT,
width: size,
height: size,
x_align: Clutter.ActorAlign.CENTER,
y_align: Clutter.ActorAlign.CENTER,
reactive: false,
can_focus: false,
});
}
_refreshAppIcons() {
const iconWidgets = new Set();
const dockIcons = [];
const visit = actor => {
if (actor instanceof IconGrid.BaseIcon)
iconWidgets.add(actor);
else if (actor.app && actor.icon?.update && typeof actor._createIcon === 'function')
iconWidgets.add(actor.icon);
const app = actor.app ?? actor._taskbarApp;
const property = actor.icon instanceof St.Icon || actor.icon instanceof St.Widget
? 'icon'
: '_taskbarIcon';
const icon = actor[property];
const previous = icon && this._styledIconActors.get(icon);
if (previous || (app?.create_icon_texture && icon instanceof St.Icon))
dockIcons.push({owner: actor, app: previous?.app ?? app,
icon, property, size: previous?.size ?? icon.icon_size ?? icon.width ?? 32});
for (const child of actor.get_children())
visit(child);
};
visit(global.stage);
for (const icon of iconWidgets) {
if (icon instanceof IconGrid.BaseIcon && typeof icon._createIconTexture === 'function')
icon._createIconTexture(icon.iconSize);
else
icon.update();
}
for (const {owner, app, icon, property, size} of dockIcons) {
const parent = icon.get_parent();
if (!parent)
continue;
const index = parent.get_children().indexOf(icon);
const replacement = app.create_icon_texture(size);
if (replacement === icon)
continue;
if (replacement.get_parent() !== parent)
parent.insert_child_at_index(replacement, index);
owner[property] = replacement;
icon.destroy();
}
}
_restoreDockIcons() {
const restore = (owner, property) => {
const styled = owner[property];
const info = styled && this._styledIconActors.get(styled);
if (!info)
return;
const parent = styled.get_parent();
if (!parent)
return;
const index = parent.get_children().indexOf(styled);
const source = this._originalCreateIconTexture.call(info.app, info.size);
parent.insert_child_at_index(source, index);
owner[property] = source;
styled.destroy();
};
const visit = actor => {
restore(actor, 'icon');
restore(actor, '_taskbarIcon');
for (const child of actor.get_children())
visit(child);
};
visit(global.stage);
}
_updateTileColors() {
const visit = actor => {
if (actor.has_style_class_name?.('consistent-app-icon-tile')) {
const size = actor.width || actor.height || 16;
this._styleTile(actor, size, actor._consistentIconPalette ?? null);
}
for (const child of actor.get_children())
visit(child);
};
visit(global.stage);
}
}