-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCanberraGtk4.vala
More file actions
78 lines (64 loc) · 3.13 KB
/
CanberraGtk4.vala
File metadata and controls
78 lines (64 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright 2022 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
/* code adapted from libcanberra */
namespace CanberraGtk4 {
private Canberra.Context? context = null;
public unowned Canberra.Context? context_get () {
Canberra.Proplist proplist;
if (context != null) {
return context;
} if (Canberra.Context.create (out context) != Canberra.SUCCESS) {
return null;
} if (Canberra.Proplist.create (out proplist) != Canberra.SUCCESS) {
return null;
}
proplist.sets (Canberra.PROP_CANBERRA_XDG_THEME_NAME, Gtk.Settings.get_default ().gtk_sound_theme_name);
unowned var name = GLib.Environment.get_application_name ();
if (name != null) {
proplist.sets (Canberra.PROP_APPLICATION_NAME, name);
} else {
proplist.sets (Canberra.PROP_APPLICATION_NAME, "libcanberra-gtk");
proplist.sets (Canberra.PROP_APPLICATION_VERSION, "%i.%i".printf (Canberra.MAJOR, Canberra.MINOR));
proplist.sets (Canberra.PROP_APPLICATION_ID, "org.freedesktop.libcanberra.gtk");
}
unowned var icon = Gtk.Window.get_default_icon_name ();
if (icon != null) {
proplist.sets (Canberra.PROP_APPLICATION_ICON_NAME, icon);
}
unowned var display = Gdk.Display.get_default ();
if (display is Gdk.X11.Display) {
unowned var display_name = display.get_name ();
if (display_name != null) {
proplist.sets (Canberra.PROP_WINDOW_X11_SCREEN, display_name);
}
var screen = "%i".printf (((Gdk.X11.Display) display).get_screen ().get_screen_number ());
proplist.sets (Canberra.PROP_WINDOW_X11_SCREEN, screen);
}
context.change_props_full (proplist);
var val = Value (typeof (string));
if (display.get_setting ("gtk-sound-theme-name", val)) {
context.change_props (Canberra.PROP_CANBERRA_XDG_THEME_NAME, val.get_string ());
}
val = Value (typeof (bool));
if (display.get_setting ("gtk-enable-event-sounds", val)) {
unowned var env = GLib.Environment.get_variable ("CANBERRA_FORCE_EVENT_SOUNDS");
context.change_props (Canberra.PROP_CANBERRA_ENABLE, env != null ? true : val.get_boolean ());
}
display.setting_changed.connect ((setting) => {
Value new_val;
if (setting == "gtk-sound-theme-name") {
new_val = Value (typeof (string));
display.get_setting ("gtk-sound-theme-name", new_val);
context.change_props (Canberra.PROP_CANBERRA_ENABLE, new_val.get_string ());
} else if (setting == "gtk-enable-event-sounds") {
new_val = Value (typeof (bool));
unowned var env = GLib.Environment.get_variable ("CANBERRA_FORCE_EVENT_SOUNDS");
display.get_setting ("gtk-enable-event-sounds", new_val);
context.change_props (Canberra.PROP_CANBERRA_ENABLE, env != null ? true : new_val.get_boolean ());
}
});
return context;
}
}