Skip to content

Commit

Permalink
Support floating point scale for resize button (#1630)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmhewitt committed Apr 7, 2023
1 parent a39676e commit 53da4ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions lib/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Gala {
public int scale;
}

private static Gdk.Pixbuf? resize_pixbuf = null;
private static Gee.HashMap<int, Gdk.Pixbuf?>? resize_pixbufs = null;
private static Gee.HashMap<int, Gdk.Pixbuf?>? close_pixbufs = null;

private static Gee.HashMultiMap<DesktopAppInfo, CachedIcon?> icon_cache;
Expand Down Expand Up @@ -379,11 +379,16 @@ namespace Gala {
*
* @return the close button pixbuf or null if it failed to load
*/
public static Gdk.Pixbuf? get_resize_button_pixbuf () {
var height = 36 * Utils.get_ui_scaling_factor ();
if (resize_pixbuf == null || resize_pixbuf.height != height) {
public static Gdk.Pixbuf? get_resize_button_pixbuf (float scale) {
var height = scale_to_int (36, scale);

if (resize_pixbufs == null) {
resize_pixbufs = new Gee.HashMap<int, Gdk.Pixbuf?> ();
}

if (resize_pixbufs[height] == null) {
try {
resize_pixbuf = new Gdk.Pixbuf.from_resource_at_scale (
resize_pixbufs[height] = new Gdk.Pixbuf.from_resource_at_scale (
Config.RESOURCEPATH + "/buttons/resize.svg",
-1,
height,
Expand All @@ -395,17 +400,17 @@ namespace Gala {
}
}

return resize_pixbuf;
return resize_pixbufs[height];
}

/**
* Creates a new reactive ClutterActor at 36px with the resize pixbuf
*
* @return The resize button actor
*/
public static Clutter.Actor create_resize_button () {
public static Clutter.Actor create_resize_button (float scale) {
var texture = new Clutter.Actor ();
var pixbuf = get_resize_button_pixbuf ();
var pixbuf = get_resize_button_pixbuf (scale);

texture.reactive = true;

Expand All @@ -421,8 +426,8 @@ namespace Gala {
// we'll just make this red so there's at least something as an
// indicator that loading failed. Should never happen and this
// works as good as some weird fallback-image-failed-to-load pixbuf
var scale = Utils.get_ui_scaling_factor ();
texture.set_size (36 * scale, 36 * scale);
var size = scale_to_int (36, scale);
texture.set_size (size, size);
texture.background_color = { 255, 0, 0, 255 };
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/pip/PopupWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
close_button.add_constraint (new Clutter.AlignConstraint (this, Clutter.AlignAxis.Y_AXIS, 0.0f));
close_button.add_action (close_action);

resize_button = Utils.create_resize_button ();
resize_button = Utils.create_resize_button (scale);
resize_button.opacity = 0;
resize_button.reactive = true;
resize_button.add_constraint (new Clutter.AlignConstraint (this, Clutter.AlignAxis.X_AXIS, 1.0f));
Expand Down

0 comments on commit 53da4ea

Please sign in to comment.