forked from mirrors/gecko-dev
Bug 1762816 [Linux] Watch org.freedesktop.portal.Desktop DBus name and get session data only if it's running r=emilio
Don't autostart org.freedesktop.portal.Desktop by g_dbus_proxy_new_for_bus_sync(), that may block Firefox start for 30~ seconds after desktop start. Use g_bus_watch_name() and get session data only if org.freedesktop.portal.Desktop is available. Differential Revision: https://phabricator.services.mozilla.com/D192335
This commit is contained in:
parent
d38cab7dd8
commit
3312286f42
2 changed files with 50 additions and 15 deletions
|
|
@ -134,6 +134,35 @@ static void settings_changed_signal_cb(GDBusProxy* proxy, gchar* sender_name,
|
|||
}
|
||||
}
|
||||
|
||||
void nsLookAndFeel::WatchDBus() {
|
||||
GUniquePtr<GError> error;
|
||||
mDBusSettingsProxy = dont_AddRef(g_dbus_proxy_new_for_bus_sync(
|
||||
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, nullptr,
|
||||
"org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop",
|
||||
"org.freedesktop.portal.Settings", nullptr, getter_Transfers(error)));
|
||||
if (mDBusSettingsProxy) {
|
||||
g_signal_connect(mDBusSettingsProxy, "g-signal",
|
||||
G_CALLBACK(settings_changed_signal_cb), this);
|
||||
} else {
|
||||
LOGLNF("Can't create DBus proxy for settings: %s\n", error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
// DBus interface was started after L&F init so we need to load
|
||||
// our settings from DBus explicitly.
|
||||
if (!sIgnoreChangedSettings) {
|
||||
OnColorSchemeSettingChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void nsLookAndFeel::UnwatchDBus() {
|
||||
if (mDBusSettingsProxy) {
|
||||
g_signal_handlers_disconnect_by_func(
|
||||
mDBusSettingsProxy, FuncToGpointer(settings_changed_signal_cb), this);
|
||||
mDBusSettingsProxy = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
nsLookAndFeel::nsLookAndFeel() {
|
||||
static constexpr nsLiteralCString kObservedSettings[] = {
|
||||
// Affects system font sizes.
|
||||
|
|
@ -172,27 +201,29 @@ nsLookAndFeel::nsLookAndFeel() {
|
|||
nsWindow::GetSystemGtkWindowDecoration() != nsWindow::GTK_DECORATION_NONE;
|
||||
|
||||
if (ShouldUsePortal(PortalKind::Settings)) {
|
||||
GUniquePtr<GError> error;
|
||||
mDBusSettingsProxy = dont_AddRef(g_dbus_proxy_new_for_bus_sync(
|
||||
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, nullptr,
|
||||
"org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop",
|
||||
"org.freedesktop.portal.Settings", nullptr, getter_Transfers(error)));
|
||||
if (mDBusSettingsProxy) {
|
||||
g_signal_connect(mDBusSettingsProxy, "g-signal",
|
||||
G_CALLBACK(settings_changed_signal_cb), this);
|
||||
} else {
|
||||
LOGLNF("Can't create DBus proxy for settings: %s\n", error->message);
|
||||
}
|
||||
mDBusID = g_bus_watch_name(
|
||||
G_BUS_TYPE_SESSION, "org.freedesktop.portal.Desktop",
|
||||
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
||||
[](GDBusConnection*, const gchar*, const gchar*,
|
||||
gpointer data) -> void {
|
||||
auto* lnf = static_cast<nsLookAndFeel*>(data);
|
||||
lnf->WatchDBus();
|
||||
},
|
||||
[](GDBusConnection*, const gchar*, gpointer data) -> void {
|
||||
auto* lnf = static_cast<nsLookAndFeel*>(data);
|
||||
lnf->UnwatchDBus();
|
||||
},
|
||||
this, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
nsLookAndFeel::~nsLookAndFeel() {
|
||||
ClearRoundedCornerProvider();
|
||||
if (mDBusSettingsProxy) {
|
||||
g_signal_handlers_disconnect_by_func(
|
||||
mDBusSettingsProxy, FuncToGpointer(settings_changed_signal_cb), this);
|
||||
mDBusSettingsProxy = nullptr;
|
||||
if (mDBusID) {
|
||||
g_bus_unwatch_name(mDBusID);
|
||||
mDBusID = 0;
|
||||
}
|
||||
UnwatchDBus();
|
||||
g_signal_handlers_disconnect_by_func(
|
||||
gtk_settings_get_default(), FuncToGpointer(settings_changed_cb), nullptr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
static bool ShouldHonorThemeScrollbarColors();
|
||||
mozilla::Maybe<ColorScheme> ComputeColorSchemeSetting();
|
||||
|
||||
void WatchDBus();
|
||||
void UnwatchDBus();
|
||||
|
||||
enum class ThemeFamily : uint8_t {
|
||||
// Adwaita, the default GTK theme.
|
||||
Adwaita,
|
||||
|
|
@ -160,6 +163,7 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
return mSystemThemeOverridden ? mAltTheme : mSystemTheme;
|
||||
}
|
||||
|
||||
uint32_t mDBusID = 0;
|
||||
RefPtr<GDBusProxy> mDBusSettingsProxy;
|
||||
mozilla::Maybe<ColorScheme> mColorSchemePreference;
|
||||
int32_t mCaretBlinkTime = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue