thunderbird/D165152.diff

118 lines
4.0 KiB
Diff
Raw Normal View History

diff -up thunderbird-102.6.0/toolkit/system/gnome/nsGIOService.cpp.D165152 thunderbird-102.6.0/toolkit/system/gnome/nsGIOService.cpp
--- thunderbird-102.6.0/toolkit/system/gnome/nsGIOService.cpp.D165152 2022-12-12 22:37:40.000000000 +0100
+++ thunderbird-102.6.0/toolkit/system/gnome/nsGIOService.cpp 2022-12-20 13:41:17.337477022 +0100
@@ -19,6 +19,7 @@
#include "mozilla/WidgetUtilsGtk.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/net/DNS.h"
+#include "prenv.h"
#include <gio/gio.h>
#include <gtk/gtk.h>
@@ -224,9 +225,7 @@ static RefPtr<GAppLaunchContext> GetLaun
return context;
}
-NS_IMETHODIMP
-nsGIOMimeApp::LaunchWithURI(nsIURI* aUri,
- mozilla::dom::BrowsingContext* aBrowsingContext) {
+static NS_IMETHODIMP LaunchWithURIImpl(RefPtr<GAppInfo> aInfo, nsIURI* aUri) {
GList uris = {0};
nsCString spec;
aUri->GetSpec(spec);
@@ -235,7 +234,7 @@ nsGIOMimeApp::LaunchWithURI(nsIURI* aUri
GUniquePtr<GError> error;
gboolean result = g_app_info_launch_uris(
- mApp, &uris, GetLaunchContext().get(), getter_Transfers(error));
+ aInfo, &uris, GetLaunchContext().get(), getter_Transfers(error));
if (!result) {
g_warning("Cannot launch application: %s", error->message);
return NS_ERROR_FAILURE;
@@ -244,6 +243,27 @@ nsGIOMimeApp::LaunchWithURI(nsIURI* aUri
return NS_OK;
}
+NS_IMETHODIMP
+nsGIOMimeApp::LaunchWithURI(nsIURI* aUri,
+ mozilla::dom::BrowsingContext* aBrowsingContext) {
+ if (mozilla::widget::CanTransferWaylandFocus()) {
+ mozilla::widget::RequestWaylandFocus()->Then(
+ GetMainThreadSerialEventTarget(), __func__,
+ /* resolve */
+ [app = RefPtr{mApp}, uri = RefPtr{aUri}](nsCString token) {
+ PR_SetEnv(ToNewCString("XDG_ACTIVATION_TOKEN="_ns + token));
+ LaunchWithURIImpl(app, uri);
+ },
+ /* reject */
+ [app = RefPtr{mApp}, uri = RefPtr{aUri}](bool state) {
+ LaunchWithURIImpl(app, uri);
+ });
+ return NS_OK;
+ }
+
+ return LaunchWithURIImpl(mApp, aUri);
+}
+
class GIOUTF8StringEnumerator final : public nsStringEnumeratorBase {
~GIOUTF8StringEnumerator() = default;
@@ -531,7 +551,7 @@ nsGIOService::GetDescriptionForMimeType(
return NS_OK;
}
-nsresult nsGIOService::ShowURI(nsIURI* aURI) {
+static nsresult ShowURIImpl(nsIURI* aURI) {
nsAutoCString spec;
MOZ_TRY(aURI->GetSpec(spec));
GUniquePtr<GError> error;
@@ -544,7 +564,24 @@ nsresult nsGIOService::ShowURI(nsIURI* a
return NS_OK;
}
-static nsresult LaunchPath(const nsACString& aPath) {
+nsresult nsGIOService::ShowURI(nsIURI* aURI) {
+ if (mozilla::widget::CanTransferWaylandFocus()) {
+ mozilla::widget::RequestWaylandFocus()->Then(
+ GetMainThreadSerialEventTarget(), __func__,
+ /* resolve */
+ [uri = RefPtr{aURI}](nsCString token) {
+ PR_SetEnv(ToNewCString("XDG_ACTIVATION_TOKEN="_ns + token));
+ ShowURIImpl(uri);
+ },
+ /* reject */
+ [uri = RefPtr{aURI}](bool state) { ShowURIImpl(uri); });
+ return NS_OK;
+ }
+
+ return ShowURIImpl(aURI);
+}
+
+static nsresult LaunchPathImpl(const nsACString& aPath) {
RefPtr<GFile> file = dont_AddRef(
g_file_new_for_commandline_arg(PromiseFlatCString(aPath).get()));
GUniquePtr<char> spec(g_file_get_uri(file));
@@ -558,6 +595,22 @@ static nsresult LaunchPath(const nsACStr
return NS_OK;
}
+static nsresult LaunchPath(const nsACString& aPath) {
+ if (mozilla::widget::CanTransferWaylandFocus()) {
+ mozilla::widget::RequestWaylandFocus()->Then(
+ GetMainThreadSerialEventTarget(), __func__,
+ /* resolve */
+ [path = nsCString{aPath}](nsCString token) {
+ PR_SetEnv(ToNewCString("XDG_ACTIVATION_TOKEN="_ns + token));
+ LaunchPathImpl(path);
+ },
+ /* reject */
+ [path = nsCString{aPath}](bool state) { LaunchPathImpl(path); });
+ return NS_OK;
+ }
+ return LaunchPathImpl(aPath);
+}
+
nsresult nsGIOService::LaunchFile(const nsACString& aPath) {
return LaunchPath(aPath);
}