Skip to content

Make CloseButton and WindowIcon scales settable #2356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/CloseButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public class Gala.CloseButton : Clutter.Actor {
private static Gee.HashMap<int, Gdk.Pixbuf?> close_pixbufs;

public signal void triggered (uint32 timestamp);
public float scale { get; construct set; }
public float monitor_scale { set { load_pixbuf (value); } }

// used to avoid changing hitbox of the button
private Clutter.Actor pixbuf_actor;
private bool is_pressed = false;

public CloseButton (float scale) {
Object (scale: scale);
public CloseButton (float monitor_scale) {
Object (monitor_scale: monitor_scale);
}

static construct {
Expand All @@ -29,7 +29,9 @@ public class Gala.CloseButton : Clutter.Actor {
pivot_point = { 0.5f, 0.5f }
};
add_child (pixbuf_actor);
}

private void load_pixbuf (float scale) {
var pixbuf = get_close_button_pixbuf (scale);
if (pixbuf != null) {
try {
Expand All @@ -41,10 +43,10 @@ public class Gala.CloseButton : Clutter.Actor {
pixbuf_actor.set_size (pixbuf.width, pixbuf.height);
set_size (pixbuf.width, pixbuf.height);
} catch (Error e) {
create_error_texture ();
create_error_texture (scale);
}
} else {
create_error_texture ();
create_error_texture (scale);
}
}

Expand All @@ -68,7 +70,7 @@ public class Gala.CloseButton : Clutter.Actor {
return close_pixbufs[height];
}

private void create_error_texture () {
private void create_error_texture (float scale) {
// 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
Expand Down
17 changes: 10 additions & 7 deletions lib/WindowIcon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class Gala.WindowIcon : Clutter.Actor {
public Meta.Window window { get; construct; }
public int icon_size { get; construct; }
public float monitor_scale { get; construct set; }
public int scale { get; construct; }

/**
Expand All @@ -22,10 +23,8 @@ public class Gala.WindowIcon : Clutter.Actor {
* @param icon_size The size of the icon in pixels
* @param scale The desired scale of the icon
*/
public WindowIcon (Meta.Window window, int icon_size, int scale = 1) {
Object (window: window,
icon_size: icon_size,
scale: scale);
public WindowIcon (Meta.Window window, int icon_size, float monitor_scale, int scale = 1) {
Object (window: window, icon_size: icon_size, monitor_scale: monitor_scale, scale: scale);
}

construct {
Expand All @@ -38,14 +37,18 @@ public class Gala.WindowIcon : Clutter.Actor {
window.notify["wm-class"].connect (reload_icon);
window.notify["gtk-application-id"].connect (reload_icon);

notify["monitor-scale"].connect (reload_icon);

reload_icon ();
}

private void reload_icon () {
width = icon_size * scale;
height = icon_size * scale;
var actual_size = Utils.scale_to_int (icon_size, monitor_scale);

width = actual_size * scale;
height = actual_size * scale;

var pixbuf = Gala.Utils.get_icon_for_window (window, icon_size, scale);
var pixbuf = Gala.Utils.get_icon_for_window (window, actual_size, scale);
try {
var image = new Clutter.Image ();
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
Expand Down
40 changes: 17 additions & 23 deletions src/Widgets/MultitaskingView/WindowClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ public class Gala.WindowClone : ActorTarget {
get {
return _monitor_scale_factor;
}
set {
construct set {
if (value != _monitor_scale_factor) {
_monitor_scale_factor = value;
reallocate ();
}
}
}
Expand Down Expand Up @@ -139,13 +138,27 @@ public class Gala.WindowClone : ActorTarget {
pivot_point = { 0.5f, 0.5f }
};

window_icon = new WindowIcon (window, WINDOW_ICON_SIZE, monitor_scale_factor) {
visible = !overview_mode,
opacity = 0,
pivot_point = { 0.5f, 0.5f }
};
bind_property ("monitor-scale-factor", window_icon, "monitor-scale");

window_title = new Tooltip ();

close_button = new Gala.CloseButton (monitor_scale_factor) {
opacity = 0
};
close_button.triggered.connect (close_window);
close_button.notify["has-pointer"].connect (() => update_hover_widgets ());
bind_property ("monitor-scale-factor", close_button, "monitor-scale");

add_child (active_shape);
add_child (clone_container);
add_child (window_icon);
add_child (window_title);

reallocate ();
add_child (close_button);

InternalUtils.wait_for_window_actor (window, load_clone);

Expand All @@ -162,25 +175,6 @@ public class Gala.WindowClone : ActorTarget {
window.notify["maximized-vertically"].disconnect (check_shadow_requirements);
}

private void reallocate () {
close_button = new Gala.CloseButton (monitor_scale_factor) {
opacity = 0
};
close_button.triggered.connect (close_window);
close_button.notify["has-pointer"].connect (() => update_hover_widgets ());

window_icon = new WindowIcon (window, WINDOW_ICON_SIZE, (int)Math.round (monitor_scale_factor)) {
visible = !overview_mode
};
window_icon.opacity = 0;
window_icon.set_pivot_point (0.5f, 0.5f);

add_child (close_button);
add_child (window_icon);

set_child_below_sibling (window_icon, window_title);
}

/**
* Waits for the texture of a new Meta.WindowActor to be available
* and makes a close of it. If it was already was assigned a slot
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/MultitaskingView/WindowIconActor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public class Gala.WindowIconActor : Clutter.Actor {
* Fades out the old icon and fades in the new icon
*/
private void fade_new_icon () {
var new_icon = new WindowIcon (window, icon_size, (int)Math.round (cur_icon_scale));
var new_icon = new WindowIcon (window, icon_size, 1f, (int) Math.round (cur_icon_scale));
new_icon.add_constraint (new Clutter.BindConstraint (this, Clutter.BindCoordinate.SIZE, 0));
new_icon.opacity = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/MultitaskingView/WorkspaceInsertThumb.vala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class Gala.WorkspaceInsertThumb : Clutter.Actor {
public void set_window_thumb (Meta.Window window) {
destroy_all_children ();

var icon = new WindowIcon (window, IconGroupContainer.GROUP_WIDTH, (int)Math.round (scale_factor)) {
var icon = new WindowIcon (window, IconGroupContainer.GROUP_WIDTH, scale_factor) {
x = IconGroupContainer.SPACING,
x_align = Clutter.ActorAlign.CENTER
};
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/WindowSwitcher/WindowSwitcherIcon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Gala.WindowSwitcherIcon : CanvasActor {
public WindowSwitcherIcon (Meta.Window window, int icon_size, float scale_factor) {
Object (window: window);

icon = new WindowIcon (window, InternalUtils.scale_to_int (icon_size, scale_factor));
icon = new WindowIcon (window, icon_size, scale_factor);
icon.add_constraint (new Clutter.AlignConstraint (this, Clutter.AlignAxis.BOTH, 0.5f));
add_child (icon);

Expand Down