Skip to content

Commit 9f461e7

Browse files
authored
WindowCloneContainer: use close button size for gaps size (#2602)
Fixes #335
1 parent fed940b commit 9f461e7

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

lib/CloseButton.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class Gala.CloseButton : Clutter.Actor {
4646
}
4747

4848
private static Gdk.Pixbuf? get_close_button_pixbuf (float scale) {
49-
var height = Utils.scale_to_int (36, scale);
49+
var height = Utils.calculate_button_size (scale);
5050

5151
if (close_pixbufs[height] == null) {
5252
try {
@@ -71,7 +71,7 @@ public class Gala.CloseButton : Clutter.Actor {
7171
// works as good as some weird fallback-image-failed-to-load pixbuf
7272
critical ("Could not create close button");
7373

74-
var size = Utils.scale_to_int (36, scale);
74+
var size = Utils.calculate_button_size (scale);
7575
pixbuf_actor.set_size (size, size);
7676
pixbuf_actor.background_color = { 255, 0, 0, 255 };
7777
}

lib/Utils.vala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace Gala {
1919
public class Utils {
20+
private const int BUTTON_SIZE = 36;
21+
2022
private struct CachedIcon {
2123
public Gdk.Pixbuf icon;
2224
public int icon_size;
@@ -365,7 +367,7 @@ namespace Gala {
365367
* @return the resize button pixbuf or null if it failed to load
366368
*/
367369
public static Gdk.Pixbuf? get_resize_button_pixbuf (float scale) {
368-
var height = scale_to_int (36, scale);
370+
var height = calculate_button_size (scale);
369371

370372
if (resize_pixbufs == null) {
371373
resize_pixbufs = new Gee.HashMap<int, Gdk.Pixbuf?> ();
@@ -407,7 +409,7 @@ namespace Gala {
407409
// we'll just make this red so there's at least something as an
408410
// indicator that loading failed. Should never happen and this
409411
// works as good as some weird fallback-image-failed-to-load pixbuf
410-
var size = scale_to_int (36, scale);
412+
var size = calculate_button_size (scale);
411413
texture.set_size (size, size);
412414
texture.background_color = { 255, 0, 0, 255 };
413415
}
@@ -480,5 +482,9 @@ namespace Gala {
480482
return false;
481483
}
482484
}
485+
486+
public static int calculate_button_size (float monitor_scale) {
487+
return Utils.scale_to_int (BUTTON_SIZE, monitor_scale);
488+
}
483489
}
484490
}

plugins/pip/PopupWindow.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
5252
construct {
5353
var scale = display.get_monitor_scale (display.get_current_monitor ());
5454

55-
button_size = Gala.Utils.scale_to_int (36, scale);
55+
button_size = Gala.Utils.calculate_button_size (scale);
5656
container_margin = button_size / 2;
5757

5858
reactive = true;

src/Widgets/MultitaskingView/WindowCloneContainer.vala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ public class Gala.WindowCloneContainer : ActorTarget {
309309
return k1 * k1 + k2 * k2;
310310
}
311311

312-
private static Mtk.Rectangle rect_adjusted (Mtk.Rectangle rect, int dx1, int dy1, int dx2, int dy2) {
313-
return {rect.x + dx1, rect.y + dy1, rect.width + (-dx1 + dx2), rect.height + (-dy1 + dy2)};
312+
private static Mtk.Rectangle rect_adjusted (Mtk.Rectangle rect, int dw, int dh) {
313+
return { rect.x + dw / 2, rect.y + dh / 2, rect.width - dw, rect.height - dh };
314314
}
315315

316316
private static Graphene.Point rect_center (Mtk.Rectangle rect) {
@@ -325,7 +325,7 @@ public class Gala.WindowCloneContainer : ActorTarget {
325325
/**
326326
* Careful: List<TilableWindow?> windows will be modified in place and shouldn't be used afterwards.
327327
*/
328-
private static GLib.List<TilableWindow?> calculate_grid_placement (Mtk.Rectangle area, GLib.List<TilableWindow?> windows) {
328+
private GLib.List<TilableWindow?> calculate_grid_placement (Mtk.Rectangle area, GLib.List<TilableWindow?> windows) {
329329
uint window_count = windows.length ();
330330
int columns = (int) Math.ceil (Math.sqrt (window_count));
331331
int rows = (int) Math.ceil (window_count / (double) columns);
@@ -395,6 +395,8 @@ public class Gala.WindowCloneContainer : ActorTarget {
395395
// see how many windows we have on the last row
396396
int left_over = (int) window_count - columns * (rows - 1);
397397

398+
var button_size = Utils.calculate_button_size (monitor_scale);
399+
398400
for (int slot = 0; slot < columns * rows; slot++) {
399401
var window = taken_slots[slot];
400402
// some slots might be empty
@@ -410,7 +412,7 @@ public class Gala.WindowCloneContainer : ActorTarget {
410412
slot_width,
411413
slot_height
412414
};
413-
target = rect_adjusted (target, 10, 10, -10, -10);
415+
target = rect_adjusted (target, button_size, button_size);
414416

415417
float scale;
416418
if (target.width / (double) rect.width < target.height / (double) rect.height) {

0 commit comments

Comments
 (0)