Skip to content

Commit 69b6efb

Browse files
authored
keyboard applet: Respect "icon-size" when panel is vertical (#10456)
If the panel is vertical, the flag icon has the width of panel (minus some padding) regardless of the panel icon size setting. The commit fixes this behaviour.
1 parent da8a3b3 commit 69b6efb

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

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

+20-12
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,28 @@ class EmblemedIcon {
3535
cr.save();
3636

3737
const surf = St.TextureCache.get_default().load_file_to_cairo_surface(this.path);
38+
const surf_width = surf.getWidth();
39+
const surf_height = surf.getHeight();
3840

39-
const factor = w / surf.getWidth();
41+
let [new_w, new_h] = [w, h];
42+
const aspect = surf_width / surf_height;
43+
if ((new_w / new_h) > aspect) {
44+
new_w = new_h * aspect;
45+
}
46+
47+
const factor = new_w / surf_width;
4048

41-
const true_width = surf.getWidth() * factor;
42-
const true_height = surf.getHeight() * factor;
49+
const render_width = surf_width * factor;
50+
const render_height = surf_height * factor;
4351

44-
const x_offset = ((w * (1 / factor)) - surf.getWidth()) / 2;
45-
const y_offset = ((h * (1 / factor)) - surf.getHeight()) / 2;
52+
const surf_x_offset = ((w / factor) - surf_width) / 2;
53+
const surf_y_offset = ((h / factor) - surf_height) / 2;
4654

47-
const true_x_offset = (w - true_width) / 2;
48-
const true_y_offset = (h - true_height) / 2;
55+
const render_x_offset = (new_w - render_width) / 2;
56+
const render_y_offset = (new_h - render_height) / 2;
4957

5058
cr.scale(factor, factor);
51-
cr.setSourceSurface(surf, x_offset, y_offset);
59+
cr.setSourceSurface(surf, surf_x_offset, surf_y_offset);
5260

5361
cr.getSource().setFilter(Cairo.Filter.BEST);
5462
cr.setOperator(Cairo.Operator.SOURCE);
@@ -58,10 +66,10 @@ class EmblemedIcon {
5866
cr.restore();
5967

6068
XApp.KbdLayoutController.render_cairo_subscript(cr,
61-
true_x_offset + (true_width / 2),
62-
true_y_offset + (true_height / 2),
63-
true_width / 2,
64-
true_height / 2,
69+
render_x_offset + (render_width / 2),
70+
render_y_offset + (render_height / 2),
71+
render_width / 2,
72+
render_height / 2,
6573
this.id);
6674

6775
cr.$dispose();

0 commit comments

Comments
 (0)