Skip to content

Commit c25b61d

Browse files
committed
st-texture-cache.c: Fix st_texture_cache_load_image_from_file_async.
This was applying the scale factor to images even though in many places it's used this was already being done by its caller. This resulted in inconsistencies depending on how the returned actor was used. Remove the internal scaling and fix callers that were unknowingly relying on this behavior.
1 parent 731d2f7 commit c25b61d

5 files changed

Lines changed: 22 additions & 34 deletions

File tree

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class CinnamonKeyboardApplet extends Applet.Applet {
161161
let actor = null;
162162

163163
if (this._inputSourcesManager.showFlags) {
164-
actor = this._inputSourcesManager.createFlagIcon(source, POPUP_MENU_ICON_STYLE_CLASS, 22 * global.ui_scale);
164+
actor = this._inputSourcesManager.createFlagIcon(source, POPUP_MENU_ICON_STYLE_CLASS, 22);
165165
}
166166

167167
if (actor == null) {

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,8 @@ class Player extends PopupMenu.PopupMenuSection {
890890
}
891891
else {
892892
this._cover_path = cover_path;
893-
this._cover_load_handle = St.TextureCache.get_default().load_image_from_file_async(cover_path, 300, 300, this._on_cover_loaded.bind(this));
893+
const cover_size = 300 * global.ui_scale;
894+
this._cover_load_handle = St.TextureCache.get_default().load_image_from_file_async(cover_path, cover_size, cover_size, this._on_cover_loaded.bind(this));
894895
}
895896
}
896897

@@ -904,7 +905,7 @@ class Player extends PopupMenu.PopupMenuSection {
904905

905906
// Make sure any oddly-shaped album art doesn't affect the height of the applet popup
906907
// (and move the player controls as a result).
907-
actor.margin_bottom = 300 - actor.height;
908+
actor.margin_bottom = (300 * global.ui_scale) - actor.height;
908909

909910
this.cover = actor;
910911
this.coverBox.add_actor(this.cover);

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,13 @@ class XAppStatusIcon {
218218

219219
// Assume symbolic icons would always be square/suitable for an StIcon.
220220
if (iconName.includes("/") && type != St.IconType.SYMBOLIC) {
221+
const scaledIconSize = this.iconSize * global.ui_scale;
221222
this.icon_loader_handle = St.TextureCache.get_default().load_image_from_file_async(
222223
iconName,
223224
/* If top/bottom panel, allow the image to expand horizontally,
224225
* otherwise, restrict it to a square (but keep aspect ratio.) */
225-
this.actor.vertical ? this.iconSize : -1,
226-
this.iconSize,
226+
this.actor.vertical ? scaledIconSize : -1,
227+
scaledIconSize,
227228
(...args)=>this._onImageLoaded(...args)
228229
);
229230

js/ui/keyboardManager.js

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ var SubscriptableFlagIcon = GObject.registerClass({
235235
this._subscript = null;
236236
this._file = null;
237237
this._image = null;
238+
this._loadHandle = 0;
238239

239240
super._init({
240241
style_class: 'input-source-switcher-flag-icon',
@@ -251,10 +252,10 @@ var SubscriptableFlagIcon = GObject.registerClass({
251252

252253
this.add_child(this._drawingArea);
253254

254-
this.connect("allocation-changed", () => {
255-
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
255+
this.connect('allocation-changed', () => {
256+
if (this._image == null) {
256257
this._load_file();
257-
});
258+
}
258259
});
259260
}
260261

@@ -281,26 +282,22 @@ var SubscriptableFlagIcon = GObject.registerClass({
281282
}
282283

283284
try {
284-
St.TextureCache.get_default().load_image_from_file_async(
285+
this._loadHandle = St.TextureCache.get_default().load_image_from_file_async(
285286
this._file.get_path(),
286287
-1, this.get_height(),
287288
(cache, handle, actor) => {
288-
this._image = actor;
289-
let constraint = new Clutter.BindConstraint({
290-
source: actor,
291-
coordinate: Clutter.BindCoordinate.ALL
292-
})
289+
if (handle !== this._loadHandle) {
290+
return;
291+
}
293292

294-
this._drawingArea.add_constraint(constraint);
293+
this._image = actor;
295294
this._imageBin.set_child(actor);
295+
this._drawingArea.queue_repaint();
296296
}
297297
);
298-
299298
} catch (e) {
300299
global.logError(e);
301300
}
302-
303-
this._drawingArea.queue_relayout();
304301
}
305302

306303
_drawingAreaRepaint(area) {
@@ -310,22 +307,13 @@ var SubscriptableFlagIcon = GObject.registerClass({
310307

311308
const cr = area.get_context();
312309
const [w, h] = area.get_surface_size();
313-
const surf_w = this._image.width;
314-
const surf_h = this._image.height;
315310

316311
cr.save();
317312

318-
// // Debugging...
319-
320-
// cr.setSourceRGBA(1.0, 1.0, 1.0, .2);
321-
// cr.rectangle(0, 0, w, h);
322-
// cr.fill();
323-
// cr.save()
324-
325313
if (this._subscript != null) {
326-
let x = surf_w / 2;
314+
let x = w / 2;
327315
let width = x;
328-
let y = surf_h / 2;
316+
let y = h / 2;
329317
let height = y;
330318
cr.setSourceRGBA(0.0, 0.0, 0.0, 0.5);
331319
cr.rectangle(x, y, width, height);
@@ -963,7 +951,7 @@ var InputSourceManager = class {
963951
style_class: actorClass,
964952
file: file,
965953
subscript: source.dupeId > 0 ? String(source.dupeId) : null,
966-
height: size,
954+
height: size * global.ui_scale,
967955
});
968956
}
969957

src/st/st-texture-cache.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,6 @@ st_texture_cache_load_image_from_file_async (StTextureCache *ca
16901690
StTextureCacheLoadImageCallback callback,
16911691
gpointer user_data)
16921692
{
1693-
gint scale;
16941693
if (callback == NULL)
16951694
{
16961695
g_warning ("st_texture_cache_load_image_from_file_async callback cannot be NULL");
@@ -1699,10 +1698,9 @@ st_texture_cache_load_image_from_file_async (StTextureCache *ca
16991698

17001699
ImageFromFileAsyncData *data;
17011700
GTask *result;
1702-
scale = st_theme_context_get_scale_for_stage (),
17031701
data = g_new0 (ImageFromFileAsyncData, 1);
1704-
data->width = width == -1 ? -1 : width * scale;
1705-
data->height = height == -1 ? -1 : height * scale;
1702+
data->width = width;
1703+
data->height = height;
17061704

17071705
static gint handles = 1;
17081706
data->handle = handles++;

0 commit comments

Comments
 (0)