Skip to content

Commit 29c23cc

Browse files
committed
Blur: Don't hardcode dock border-radius
1 parent bf85936 commit 29c23cc

File tree

4 files changed

+224
-5
lines changed

4 files changed

+224
-5
lines changed

data/Application.css

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
dock {
77
background: @bg_color;
8-
border-radius: 9px;
98
box-shadow:
109
inset 0 -1px 0 0 alpha(@highlight_color, 0.2),
1110
inset 0 1px 0 0 alpha(@highlight_color, 0.3),
@@ -15,7 +14,13 @@ dock {
1514
0 1px 3px alpha(black, 0.2),
1615
0 3px 9px alpha(black, 0.3);
1716
opacity: 0.6;
18-
padding: 9px;
17+
18+
border-radius: 9px;
19+
/* This is required to correctly get border-radius
20+
* If the size on startup is < border-radius * 2, the blur radius will be set incorrectly
21+
*/
22+
min-width: 18px;
23+
min-height: 18px;
1924
}
2025

2126
.reduce-transparency dock {

src/MainWindow.vala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
1818

1919
// Matches top margin in Launcher.css
2020
private const int TOP_MARGIN = 64;
21-
private const int BORDER_RADIUS = 9;
2221

2322
private Settings transparency_settings;
2423
private static Settings settings = new Settings ("io.elementary.dock");
@@ -31,6 +30,7 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
3130
private WindowDragManager window_drag_manager;
3231
private BottomMargin bottom_margin;
3332
private bool initialized_blur = false;
33+
private int border_radius = 0;
3434

3535
class construct {
3636
set_css_name ("dock-window");
@@ -144,10 +144,19 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
144144
Graphene.Rect bounds;
145145
bottom_margin.compute_bounds (bottom_margin, out bounds);
146146

147+
var new_snapshot = new Gtk.Snapshot ();
148+
snapshot (new_snapshot);
149+
150+
var widget_border_radius = RenderNodeWalker.get_first_border_radius (new_snapshot.free_to_node (), null);
151+
152+
if (widget_border_radius != null) {
153+
border_radius = widget_border_radius;
154+
}
155+
147156
initialized_blur = true;
148157

149158
if (panel != null) {
150-
panel.add_blur (0, 0, 0, (int) bounds.get_height (), BORDER_RADIUS);
159+
panel.add_blur (0, 0, 0, (int) bounds.get_height (), border_radius);
151160
} else {
152161
update_panel_x11 ();
153162
}
@@ -185,7 +194,7 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
185194
if (initialized_blur) {
186195
Graphene.Rect bounds;
187196
bottom_margin.compute_bounds (bottom_margin, out bounds);
188-
value += ":blur=0,0,0,%d,%d".printf ((int) bounds.get_height (), BORDER_RADIUS);
197+
value += ":blur=0,0,0,%d,%d".printf ((int) bounds.get_height (), border_radius);
189198
}
190199

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

src/RenderNodeWalker.vala

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
// TODO: Copyright
2+
3+
public class Dock.RenderNodeWalker : GLib.Object {
4+
public static int? get_first_border_radius (Gsk.RenderNode main_node, out int depth) {
5+
depth = 0;
6+
7+
var main_node_type = main_node.get_node_type ();
8+
9+
if (main_node_type == Gsk.RenderNodeType.ROUNDED_CLIP_NODE) {
10+
return (int) ((Gsk.RoundedClipNode) main_node).get_clip ().corner[0].width;
11+
}
12+
13+
depth++;
14+
15+
if (main_node_type == Gsk.RenderNodeType.CONTAINER_NODE) {
16+
var container_node = (Gsk.ContainerNode) main_node;
17+
18+
var min_child_depth = int.MAX;
19+
int? min_border_radius = null;
20+
21+
for (var i = 0; i < container_node.get_n_children (); i++) {
22+
var child_node = container_node.get_child (i);
23+
24+
int child_depth;
25+
var border_radius = get_first_border_radius (child_node, out child_depth);
26+
27+
if (child_depth < min_child_depth && border_radius != null) {
28+
min_child_depth = child_depth;
29+
min_border_radius = border_radius;
30+
}
31+
}
32+
33+
depth += min_child_depth;
34+
return min_border_radius;
35+
}
36+
37+
if (main_node_type == Gsk.RenderNodeType.GL_SHADER_NODE) {
38+
var gl_shader_node = (Gsk.GLShaderNode) main_node;
39+
40+
var min_child_depth = int.MAX;
41+
int? min_border_radius = null;
42+
43+
for (var i = 0; i < gl_shader_node.get_n_children (); i++) {
44+
var child_node = gl_shader_node.get_child (i);
45+
46+
int child_depth;
47+
var border_radius = get_first_border_radius (child_node, out child_depth);
48+
49+
if (child_depth < min_child_depth && border_radius != null) {
50+
min_child_depth = child_depth;
51+
min_border_radius = border_radius;
52+
}
53+
}
54+
55+
depth += min_child_depth;
56+
return min_border_radius;
57+
}
58+
59+
if (main_node_type == Gsk.RenderNodeType.TRANSFORM_NODE) {
60+
var child_node = ((Gsk.TransformNode) main_node).get_child ();
61+
62+
int child_depth;
63+
var border_radius = get_first_border_radius (child_node, out child_depth);
64+
65+
if (border_radius != null) {
66+
depth += child_depth;
67+
}
68+
69+
return border_radius;
70+
}
71+
72+
if (main_node_type == Gsk.RenderNodeType.OPACITY_NODE) {
73+
var child_node = ((Gsk.OpacityNode) main_node).get_child ();
74+
75+
int child_depth;
76+
var border_radius = get_first_border_radius (child_node, out child_depth);
77+
78+
if (border_radius != null) {
79+
depth += child_depth;
80+
}
81+
82+
return border_radius;
83+
}
84+
85+
if (main_node_type == Gsk.RenderNodeType.COLOR_MATRIX_NODE) {
86+
var child_node = ((Gsk.ColorMatrixNode) main_node).get_child ();
87+
88+
int child_depth;
89+
var border_radius = get_first_border_radius (child_node, out child_depth);
90+
91+
if (border_radius != null) {
92+
depth += child_depth;
93+
}
94+
95+
return border_radius;
96+
}
97+
98+
if (main_node_type == Gsk.RenderNodeType.REPEAT_NODE) {
99+
var child_node = ((Gsk.RepeatNode) main_node).get_child ();
100+
101+
int child_depth;
102+
var border_radius = get_first_border_radius (child_node, out child_depth);
103+
104+
if (border_radius != null) {
105+
depth += child_depth;
106+
}
107+
108+
return border_radius;
109+
}
110+
111+
if (main_node_type == Gsk.RenderNodeType.CLIP_NODE) {
112+
var child_node = ((Gsk.ClipNode) main_node).get_child ();
113+
114+
int child_depth;
115+
var border_radius = get_first_border_radius (child_node, out child_depth);
116+
117+
if (border_radius != null) {
118+
depth += child_depth;
119+
}
120+
121+
return border_radius;
122+
}
123+
124+
if (main_node_type == Gsk.RenderNodeType.SHADOW_NODE) {
125+
var child_node = ((Gsk.ShadowNode) main_node).get_child ();
126+
127+
int child_depth;
128+
var border_radius = get_first_border_radius (child_node, out child_depth);
129+
130+
if (border_radius != null) {
131+
depth += child_depth;
132+
}
133+
134+
return border_radius;
135+
}
136+
137+
if (main_node_type == Gsk.RenderNodeType.BLUR_NODE) {
138+
var child_node = ((Gsk.BlurNode) main_node).get_child ();
139+
140+
int child_depth;
141+
var border_radius = get_first_border_radius (child_node, out child_depth);
142+
143+
if (border_radius != null) {
144+
depth += child_depth;
145+
}
146+
147+
return border_radius;
148+
}
149+
150+
if (main_node_type == Gsk.RenderNodeType.DEBUG_NODE) {
151+
var child_node = ((Gsk.DebugNode) main_node).get_child ();
152+
153+
int child_depth;
154+
var border_radius = get_first_border_radius (child_node, out child_depth);
155+
156+
if (border_radius != null) {
157+
depth += child_depth;
158+
}
159+
160+
return border_radius;
161+
}
162+
163+
if (main_node_type == Gsk.RenderNodeType.FILL_NODE) {
164+
var child_node = ((Gsk.FillNode) main_node).get_child ();
165+
166+
int child_depth;
167+
var border_radius = get_first_border_radius (child_node, out child_depth);
168+
169+
if (border_radius != null) {
170+
depth += child_depth;
171+
}
172+
173+
return border_radius;
174+
}
175+
176+
if (main_node_type == Gsk.RenderNodeType.STROKE_NODE) {
177+
var child_node = ((Gsk.StrokeNode) main_node).get_child ();
178+
179+
int child_depth;
180+
var border_radius = get_first_border_radius (child_node, out child_depth);
181+
182+
if (border_radius != null) {
183+
depth += child_depth;
184+
}
185+
186+
return border_radius;
187+
}
188+
189+
if (main_node_type == Gsk.RenderNodeType.SUBSURFACE_NODE) {
190+
var child_node = ((Gsk.SubsurfaceNode) main_node).get_child ();
191+
192+
int child_depth;
193+
var border_radius = get_first_border_radius (child_node, out child_depth);
194+
195+
if (border_radius != null) {
196+
depth += child_depth;
197+
}
198+
199+
return border_radius;
200+
}
201+
202+
return null;
203+
}
204+
}

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ sources = [
44
'BaseItem.vala',
55
'ItemManager.vala',
66
'MainWindow.vala',
7+
'RenderNodeWalker.vala',
78
'AppSystem' / 'App.vala',
89
'AppSystem' / 'AppSystem.vala',
910
'AppSystem' / 'Launcher.vala',

0 commit comments

Comments
 (0)