Skip to content

Commit 588ddeb

Browse files
lenemterdanirabbit
andauthored
Move BottomMargin into a separate file and clean it up (#461)
Co-authored-by: Danielle Foré <[email protected]>
1 parent 9fa93cb commit 588ddeb

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

src/BottomMargin.vala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0
3+
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
4+
*/
5+
6+
public class BottomMargin : Gtk.Widget {
7+
private static GLib.List<unowned BottomMargin> instances = new GLib.List<unowned BottomMargin> ();
8+
9+
class construct {
10+
set_css_name ("bottom-margin");
11+
}
12+
13+
construct {
14+
instances.append (this);
15+
}
16+
17+
~BottomMargin () {
18+
instances.remove (this);
19+
}
20+
21+
public new static int get_size () {
22+
foreach (var instance in instances) {
23+
if (instance.get_realized ()) {
24+
return instance.get_height ();
25+
}
26+
}
27+
28+
return 0;
29+
}
30+
}

src/MainWindow.vala

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
1010
}
1111
}
1212

13-
private class BottomMargin : Gtk.Widget {
14-
class construct {
15-
set_css_name ("bottom-margin");
16-
}
17-
}
18-
1913
// Matches top margin in Launcher.css
2014
private const int TOP_MARGIN = 64;
2115
private const int BORDER_RADIUS = 9;
@@ -29,7 +23,6 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
2923
private Gtk.Box main_box;
3024

3125
private WindowDragManager window_drag_manager;
32-
private BottomMargin bottom_margin;
3326
private bool initialized_blur = false;
3427

3528
class construct {
@@ -53,11 +46,9 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
5346
size_group.add_widget (overlay.child);
5447
size_group.add_widget (launcher_manager);
5548

56-
bottom_margin = new BottomMargin ();
57-
5849
main_box = new Gtk.Box (VERTICAL, 0);
5950
main_box.append (overlay);
60-
main_box.append (bottom_margin);
51+
main_box.append (new BottomMargin ());
6152
child = main_box;
6253

6354
remove_css_class ("background");
@@ -141,13 +132,10 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
141132
return;
142133
}
143134

144-
Graphene.Rect bounds;
145-
bottom_margin.compute_bounds (bottom_margin, out bounds);
146-
147135
initialized_blur = true;
148136

149137
if (panel != null) {
150-
panel.add_blur (0, 0, 0, (int) bounds.get_height (), BORDER_RADIUS);
138+
panel.add_blur (0, 0, 0, BottomMargin.get_size (), BORDER_RADIUS);
151139
} else {
152140
update_panel_x11 ();
153141
}
@@ -183,9 +171,7 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
183171
var value = "anchor=8:hide-mode=%d:restore-previous-region=1:visible-in-multitasking-view=1".printf (settings.get_enum ("autohide-mode"));
184172

185173
if (initialized_blur) {
186-
Graphene.Rect bounds;
187-
bottom_margin.compute_bounds (bottom_margin, out bounds);
188-
value += ":blur=0,0,0,%d,%d".printf ((int) bounds.get_height (), BORDER_RADIUS);
174+
value += ":blur=0,0,0,%d,%d".printf (BottomMargin.get_size (), BORDER_RADIUS);
189175
}
190176

191177
xdisplay.change_property (window, prop, X.XA_STRING, 8, 0, (uchar[]) value, value.length);

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ sources = [
22
'Application.vala',
33
'BaseIconGroup.vala',
44
'BaseItem.vala',
5+
'BottomMargin.vala',
56
'ItemManager.vala',
67
'MainWindow.vala',
78
'AppSystem' / 'App.vala',

0 commit comments

Comments
 (0)