Skip to content

Commit 3196b4a

Browse files
committed
Remove Granite's Blur API
1 parent 9762445 commit 3196b4a

File tree

7 files changed

+173
-37
lines changed

7 files changed

+173
-37
lines changed

blur-protocol/meson.build

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
dep_scanner = dependency('wayland-scanner', native: true)
2+
prog_scanner = find_program(dep_scanner.get_variable(pkgconfig: 'wayland_scanner'))
3+
4+
blur_protocol_file = files('pantheon-blur-v1.xml')
5+
6+
pantheon_blur_sources = []
7+
pantheon_blur_sources += custom_target(
8+
'pantheon-blur-client-protocol.h',
9+
command: [ prog_scanner, 'client-header', '@INPUT@', '@OUTPUT@' ],
10+
input: blur_protocol_file,
11+
output: 'pantheon-blur-client-protocol.h',
12+
)
13+
14+
output_type = 'private-code'
15+
if dep_scanner.version().version_compare('< 1.14.91')
16+
output_type = 'code'
17+
endif
18+
pantheon_blur_sources += custom_target(
19+
'pantheon-blur-protocol.c',
20+
command: [ prog_scanner, output_type, '@INPUT@', '@OUTPUT@' ],
21+
input: blur_protocol_file,
22+
output: 'pantheon-blur-protocol.c',
23+
)
24+
25+
pantheon_blur_lib = static_library(
26+
'pantheon-blur',
27+
pantheon_blur_sources,
28+
dependencies: [
29+
wayland_client_dep
30+
],
31+
)
32+
33+
pantheon_blur_dep = declare_dependency(
34+
link_with: pantheon_blur_lib,
35+
dependencies: [
36+
meson.get_compiler('vala').find_library('pantheon-blur', dirs: meson.current_source_dir()),
37+
wayland_client_dep,
38+
],
39+
include_directories: include_directories('.'),
40+
sources: pantheon_blur_sources
41+
)

blur-protocol/pantheon-blur-v1.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<protocol name="pantheon_blur_v1">
3+
<copyright><![CDATA[
4+
SPDX-FileCopyrightText: 2025 elementary <https://elementary.io>
5+
SPDX-License-Identifier: LGPL-2.1-or-later
6+
]]></copyright>
7+
8+
<interface name="io_elementary_pantheon_blur_manager_v1" version="1">
9+
<description summary="blur object factory">
10+
This protocol provides a way for Pantheon applications to ask for background blur.
11+
</description>
12+
13+
<request name="get_blur">
14+
<description summary="get blur object">
15+
Get blur object for the given wl_surface to blur background behind it.
16+
If the given wl_surface already has a io_elementary_pantheon_blur_v1 object associated,
17+
an error will be raised.
18+
</description>
19+
<arg name="output" type="new_id" interface="io_elementary_pantheon_blur_v1"/>
20+
<arg name="surface" type="object" interface="wl_surface"/>
21+
</request>
22+
</interface>
23+
24+
<interface name="io_elementary_pantheon_blur_v1" version="1">
25+
<description summary="blur object for surface">
26+
This interface provides a way for Pantheon applications to specify region of the window to be blurred.
27+
By default the region to blur is considered to be null.
28+
</description>
29+
30+
<request name="destroy" type="destructor"/>
31+
32+
<request name="set_region">
33+
<description summary="set blur region">
34+
Tell the window manager to crop blur to a given region.
35+
The coordinates must be relative to the associated surface.
36+
</description>
37+
38+
<arg name="x" type="uint"/>
39+
<arg name="y" type="uint"/>
40+
<arg name="width" type="uint"/>
41+
<arg name="height" type="uint"/>
42+
<arg name="clip_radius" type="uint"/>
43+
</request>
44+
</interface>
45+
</protocol>

blur-protocol/pantheon-blur.deps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wayland-server

blur-protocol/pantheon-blur.vapi

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2025 elementary, Inc. <https://elementary.io>
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
namespace PantheonBlur {
7+
[CCode (cheader_filename = "pantheon-blur-client-protocol.h", cname = "struct io_elementary_pantheon_blur_manager_v1", cprefix = "io_elementary_pantheon_blur_manager_v1_")]
8+
public class BlurManager : Wl.Proxy {
9+
[CCode (cheader_filename = "pantheon-blur-client-protocol.h", cname = "io_elementary_pantheon_blur_manager_v1_interface")]
10+
public static Wl.Interface iface;
11+
public void set_user_data (void* user_data);
12+
public void* get_user_data ();
13+
public uint32 get_version ();
14+
public void destroy ();
15+
public PantheonBlur.Blur get_blur (Wl.Surface surface);
16+
17+
}
18+
19+
[CCode (cheader_filename = "pantheon-blur-client-protocol.h", cname = "struct io_elementary_pantheon_blur_v1", cprefix = "io_elementary_pantheon_blur_v1_")]
20+
public class Blur : Wl.Proxy {
21+
[CCode (cheader_filename = "pantheon-blur-client-protocol.h", cname = "io_elementary_pantheon_blur_v1_interface")]
22+
public static Wl.Interface iface;
23+
public void set_user_data (void* user_data);
24+
public void* get_user_data ();
25+
public uint32 get_version ();
26+
public void destroy ();
27+
public void set_region (uint x, uint y, uint width, uint height, uint clip_radius);
28+
}
29+
}

meson.build

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ x11_dep = dependency('x11')
2626
granite_dep = dependency('granite-7')
2727
adw_dep = dependency('libadwaita-1')
2828
m_dep = cc.find_library('m')
29-
wl_client_dep = dependency('wayland-client')
29+
wayland_client_dep = dependency('wayland-client')
3030

3131
subdir('protocol')
32+
subdir('blur-protocol')
3233

3334
dependencies = [
3435
gee_dep,
@@ -43,8 +44,9 @@ dependencies = [
4344
granite_dep,
4445
adw_dep,
4546
m_dep,
46-
wl_client_dep,
47-
pantheon_desktop_shell_dep
47+
wayland_client_dep,
48+
pantheon_desktop_shell_dep,
49+
pantheon_blur_dep
4850
]
4951

5052
gnome.post_install(glib_compile_schemas: true)

protocol/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pantheon_desktop_shell_sources += custom_target(
2525
pantheon_desktop_shell_dep = declare_dependency(
2626
dependencies: [
2727
vala.find_library('pantheon-desktop-shell', dirs: meson.current_source_dir()),
28-
dependency('wayland-client'),
28+
wayland_client_dep,
2929
],
3030
include_directories: include_directories('.'),
3131
sources: pantheon_desktop_shell_sources

src/MainWindow.vala

Lines changed: 51 additions & 33 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 : Granite.BlurSurface, Gtk.ApplicationWindow {
6+
public class Dock.MainWindow : Gtk.ApplicationWindow {
77
private class Container : Gtk.Box {
88
class construct {
99
set_css_name ("dock");
@@ -25,6 +25,7 @@ public class Dock.MainWindow : Granite.BlurSurface, Gtk.ApplicationWindow {
2525

2626
private Pantheon.Desktop.Shell? desktop_shell;
2727
private Pantheon.Desktop.Panel? panel;
28+
private PantheonBlur.Blur? blur;
2829

2930
private Gtk.Box main_box;
3031
private int full_height = 0;
@@ -69,7 +70,7 @@ public class Dock.MainWindow : Granite.BlurSurface, Gtk.ApplicationWindow {
6970
if (panel != null) {
7071
panel.set_hide_mode (settings.get_enum ("autohide-mode"));
7172
} else {
72-
update_real_x11_hints ();
73+
update_x11_hints ();
7374
}
7475
});
7576

@@ -90,25 +91,18 @@ public class Dock.MainWindow : Granite.BlurSurface, Gtk.ApplicationWindow {
9091
}
9192
}
9293

94+
private static Wl.RegistryListener registry_listener;
9395
private void init_panel () {
94-
if (is_wayland ()) {
95-
init_wayland (registry_handle_global);
96-
} else {
97-
update_real_x11_hints ();
98-
}
99-
10096
get_surface ().layout.connect_after (() => {
10197
var new_full_height = main_box.get_height ();
102-
10398
if (new_full_height != full_height) {
10499
full_height = new_full_height;
105100

106101
if (panel != null) {
107102
panel.set_size (-1, full_height);
108103
} else {
109-
update_real_x11_hints ();
104+
update_x11_hints ();
110105
}
111-
112106
}
113107

114108
unowned var item_manager = ItemManager.get_default ();
@@ -119,27 +113,39 @@ public class Dock.MainWindow : Granite.BlurSurface, Gtk.ApplicationWindow {
119113
visible_width = new_visible_width;
120114
visible_height = new_visible_height;
121115

122-
if (is_wayland ()) {
123-
request_blur_wayland (
116+
if (blur != null) {
117+
blur.set_region (
124118
0,
125119
TOP_PADDING,
126120
visible_width,
127121
visible_height,
128122
BORDER_RADIUS
129123
);
130124
} else {
131-
update_real_x11_hints ();
125+
update_x11_hints ();
132126
}
133127
}
134128
});
135-
}
136129

137-
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);
130+
registry_listener.global = registry_handle_global;
131+
unowned var display = Gdk.Display.get_default ();
132+
if (display is Gdk.Wayland.Display) {
133+
unowned var wl_display = ((Gdk.Wayland.Display) display).get_wl_display ();
134+
var wl_registry = wl_display.get_registry ();
135+
wl_registry.add_listener (
136+
registry_listener,
137+
this
138+
);
139+
140+
if (wl_display.roundtrip () < 0) {
141+
return;
142+
}
143+
} else {
144+
update_x11_hints ();
145+
}
140146
}
141147

142-
public void panel_registry_handle_global (Wl.Registry wl_registry, uint32 name, string @interface, uint32 version) {
148+
public void registry_handle_global (Wl.Registry wl_registry, uint32 name, string @interface, uint32 version) {
143149
if (@interface == "io_elementary_pantheon_shell_v1") {
144150
desktop_shell = wl_registry.bind<Pantheon.Desktop.Shell> (name, ref Pantheon.Desktop.Shell.iface, uint32.min (version, 1));
145151
unowned var surface = get_surface ();
@@ -149,24 +155,36 @@ public class Dock.MainWindow : Granite.BlurSurface, Gtk.ApplicationWindow {
149155
panel.set_anchor (BOTTOM);
150156
panel.set_hide_mode (settings.get_enum ("autohide-mode"));
151157
}
158+
} else if (@interface == "io_elementary_pantheon_blur_manager_v1") {
159+
var blur_manager = wl_registry.bind<PantheonBlur.BlurManager> (name, ref PantheonBlur.BlurManager.iface, uint32.min (version, 1));
160+
unowned var surface = get_surface ();
161+
if (surface is Gdk.Wayland.Surface) {
162+
unowned var wl_surface = ((Gdk.Wayland.Surface) surface).get_wl_surface ();
163+
blur = blur_manager.get_blur (wl_surface);
164+
}
152165
}
153166
}
154167

155-
private void update_real_x11_hints () {
156-
update_x11_hints (get_x11_panel_hints () + get_real_x11_blur_hints ());
157-
}
168+
private void update_x11_hints () {
169+
var display = Gdk.Display.get_default ();
170+
if (display is Gdk.X11.Display) {
171+
unowned var xdisplay = ((Gdk.X11.Display) display).get_xdisplay ();
158172

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-
}
173+
var window = ((Gdk.X11.Surface) get_surface ()).get_xid ();
174+
175+
var prop = xdisplay.intern_atom ("_MUTTER_HINTS", false);
162176

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-
);
177+
var value = "anchor=8:hide-mode=%d:size=-1,%d:blur=%d,%d,%d,%d,%d".printf (
178+
settings.get_enum ("autohide-mode"),
179+
full_height,
180+
0,
181+
TOP_PADDING,
182+
visible_width,
183+
visible_height,
184+
BORDER_RADIUS
185+
);
186+
187+
xdisplay.change_property (window, prop, X.XA_STRING, 8, 0, (uchar[]) value, value.length);
188+
}
171189
}
172190
}

0 commit comments

Comments
 (0)