firefox/mozilla-1762816.patch
2023-11-06 10:28:24 +01:00

122 lines
4.5 KiB
Diff

changeset: 688555:933a3df01cfa
tag: tip
parent: 688549:db8c28afe588
user: stransky <stransky@redhat.com>
date: Tue Oct 31 15:27:05 2023 +0100
files: widget/gtk/nsLookAndFeel.cpp widget/gtk/nsLookAndFeel.h
description:
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
diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -134,6 +134,35 @@ static void settings_changed_signal_cb(G
}
}
+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);
}
diff --git a/widget/gtk/nsLookAndFeel.h b/widget/gtk/nsLookAndFeel.h
--- a/widget/gtk/nsLookAndFeel.h
+++ b/widget/gtk/nsLookAndFeel.h
@@ -53,6 +53,9 @@ class nsLookAndFeel final : public nsXPL
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 nsXPL
return mSystemThemeOverridden ? mAltTheme : mSystemTheme;
}
+ uint32_t mDBusID = 0;
RefPtr<GDBusProxy> mDBusSettingsProxy;
mozilla::Maybe<ColorScheme> mColorSchemePreference;
int32_t mCaretBlinkTime = 0;