Skip to content

Commit 9762445

Browse files
committed
Use Granite's Blur API
1 parent 59919f6 commit 9762445

File tree

2 files changed

+72
-49
lines changed

2 files changed

+72
-49
lines changed

data/Application.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dock {
1414
0 0 0 1px @borders,
1515
0 1px 3px alpha(black, 0.2),
1616
0 3px 9px alpha(black, 0.3);
17-
opacity: 0.6;
17+
opacity: 0.3;
1818
padding: 9px;
1919
}
2020

src/MainWindow.vala

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-FileCopyrightText: 2022-2025 elementary, Inc. (https://elementary.io)
44
*/
55

6-
public class Dock.MainWindow : Gtk.ApplicationWindow {
6+
public class Dock.MainWindow : Granite.BlurSurface, Gtk.ApplicationWindow {
77
private class Container : Gtk.Box {
88
class construct {
99
set_css_name ("dock");
@@ -16,14 +16,20 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
1616
}
1717
}
1818

19+
// Keep in sync with CSS
20+
private const int TOP_PADDING = 64;
21+
private const int BORDER_RADIUS = 9;
22+
1923
private Settings transparency_settings;
2024
private static Settings settings = new Settings ("io.elementary.dock");
2125

2226
private Pantheon.Desktop.Shell? desktop_shell;
2327
private Pantheon.Desktop.Panel? panel;
2428

2529
private Gtk.Box main_box;
26-
private int height = 0;
30+
private int full_height = 0;
31+
private int visible_width = 0;
32+
private int visible_height = 0;
2733

2834
class construct {
2935
set_css_name ("dock-window");
@@ -63,7 +69,7 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
6369
if (panel != null) {
6470
panel.set_hide_mode (settings.get_enum ("autohide-mode"));
6571
} else {
66-
update_panel_x11 ();
72+
update_real_x11_hints ();
6773
}
6874
});
6975

@@ -84,7 +90,56 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
8490
}
8591
}
8692

93+
private void init_panel () {
94+
if (is_wayland ()) {
95+
init_wayland (registry_handle_global);
96+
} else {
97+
update_real_x11_hints ();
98+
}
99+
100+
get_surface ().layout.connect_after (() => {
101+
var new_full_height = main_box.get_height ();
102+
103+
if (new_full_height != full_height) {
104+
full_height = new_full_height;
105+
106+
if (panel != null) {
107+
panel.set_size (-1, full_height);
108+
} else {
109+
update_real_x11_hints ();
110+
}
111+
112+
}
113+
114+
unowned var item_manager = ItemManager.get_default ();
115+
var new_visible_width = item_manager.get_width ();
116+
var new_visible_height = item_manager.get_height ();
117+
118+
if (new_visible_width != visible_width || new_visible_height != visible_height) {
119+
visible_width = new_visible_width;
120+
visible_height = new_visible_height;
121+
122+
if (is_wayland ()) {
123+
request_blur_wayland (
124+
0,
125+
TOP_PADDING,
126+
visible_width,
127+
visible_height,
128+
BORDER_RADIUS
129+
);
130+
} else {
131+
update_real_x11_hints ();
132+
}
133+
}
134+
});
135+
}
136+
87137
public void registry_handle_global (Wl.Registry wl_registry, uint32 name, string @interface, uint32 version) {
138+
panel_registry_handle_global (wl_registry, name, @interface, version);
139+
blur_registry_handle_global (wl_registry, name, @interface, version);
140+
}
141+
142+
public void panel_registry_handle_global (Wl.Registry wl_registry, uint32 name, string @interface, uint32 version) {
88143
if (@interface == "io_elementary_pantheon_shell_v1") {
89144
desktop_shell = wl_registry.bind<Pantheon.Desktop.Shell> (name, ref Pantheon.Desktop.Shell.iface, uint32.min (version, 1));
90145
unowned var surface = get_surface ();
@@ -97,53 +152,21 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
97152
}
98153
}
99154

100-
private static Wl.RegistryListener registry_listener;
101-
private void init_panel () {
102-
get_surface ().layout.connect_after (() => {
103-
var new_height = main_box.get_height ();
104-
if (new_height == height) {
105-
return;
106-
}
107-
108-
height = new_height;
109-
110-
if (panel != null) {
111-
panel.set_size (-1, height);
112-
} else {
113-
update_panel_x11 ();
114-
}
115-
});
116-
117-
registry_listener.global = registry_handle_global;
118-
unowned var display = Gdk.Display.get_default ();
119-
if (display is Gdk.Wayland.Display) {
120-
unowned var wl_display = ((Gdk.Wayland.Display) display).get_wl_display ();
121-
var wl_registry = wl_display.get_registry ();
122-
wl_registry.add_listener (
123-
registry_listener,
124-
this
125-
);
126-
127-
if (wl_display.roundtrip () < 0) {
128-
return;
129-
}
130-
} else {
131-
update_panel_x11 ();
132-
}
155+
private void update_real_x11_hints () {
156+
update_x11_hints (get_x11_panel_hints () + get_real_x11_blur_hints ());
133157
}
134158

135-
private void update_panel_x11 () {
136-
var display = Gdk.Display.get_default ();
137-
if (display is Gdk.X11.Display) {
138-
unowned var xdisplay = ((Gdk.X11.Display) display).get_xdisplay ();
139-
140-
var window = ((Gdk.X11.Surface) get_surface ()).get_xid ();
141-
142-
var prop = xdisplay.intern_atom ("_MUTTER_HINTS", false);
143-
144-
var value = "anchor=8:hide-mode=%d:size=-1,%d".printf (settings.get_enum ("autohide-mode"), height);
159+
private string get_x11_panel_hints () {
160+
return "anchor=8:hide-mode=%d:size=-1,%d:".printf (settings.get_enum ("autohide-mode"), full_height);
161+
}
145162

146-
xdisplay.change_property (window, prop, X.XA_STRING, 8, 0, (uchar[]) value, value.length);
147-
}
163+
private string get_real_x11_blur_hints () {
164+
return get_x11_blur_hints (
165+
0,
166+
TOP_PADDING,
167+
visible_width,
168+
visible_height,
169+
BORDER_RADIUS
170+
);
148171
}
149172
}

0 commit comments

Comments
 (0)