File 0340-wx-Overload-OSXIsGUIApplication-with-our-own-check.patch of Package erlang

From 94af64ba87debf6e5da46d7860ca3715fd45d41e Mon Sep 17 00:00:00 2001
From: Wojtek Mach <wojtek@wojtekmach.pl>
Date: Sun, 10 Apr 2022 13:11:27 +0200
Subject: [PATCH] wx: Overload `OSXIsGUIApplication` with our own check

Some macOS apps only run in the background and thus have no GUI. Some
apps only live in the "menu bar" (top-right corner) and thus don't have
the traditional GUI either. In both cases, we don't want the application
to show up in the Dock (and thus show up when switching apps with
cmd+tab, etc)

A standard way to do this to set `LSUIElement` to `true`. See:
https://developer.apple.com/documentation/bundleresources/information_property_list/lsuielement)
---
 lib/wx/c_src/wxe_impl.cpp | 10 ++++++++++
 lib/wx/c_src/wxe_impl.h   |  1 +
 lib/wx/c_src/wxe_nif.h    |  4 ++++
 3 files changed, 15 insertions(+)

diff --git a/lib/wx/c_src/wxe_impl.cpp b/lib/wx/c_src/wxe_impl.cpp
index 67b319b036..440198fa42 100644
--- a/lib/wx/c_src/wxe_impl.cpp
+++ b/lib/wx/c_src/wxe_impl.cpp
@@ -224,6 +224,16 @@ void WxeApp::MacReopenApp() {
   wxString empty;
   send_msg("reopen_app", &empty);
 }
+
+bool WxeApp::OSXIsGUIApplication() {
+  // wx manually activates the application if it's not in the bundle [1]. In particular, it calls
+  // `[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular]` which prevents the app
+  // from running in the background and we cannot control it with `LSUIElement` [2]. Their check
+  // if it's a bundle always returns false for wxErlang. Thus we use our own way of detecting it.
+  // [1] https://github.com/wxWidgets/wxWidgets/blob/v3.1.5/src/osx/cocoa/utils.mm#L76:L93
+  // [2] https://developer.apple.com/documentation/bundleresources/information_property_list/lsuielement
+  return !is_packaged_app();
+}
 #endif
 
 void WxeApp::shutdown(wxeMetaCommand& Ecmd) {
diff --git a/lib/wx/c_src/wxe_impl.h b/lib/wx/c_src/wxe_impl.h
index 16487f3c0d..c2f144e0bf 100644
--- a/lib/wx/c_src/wxe_impl.h
+++ b/lib/wx/c_src/wxe_impl.h
@@ -64,6 +64,7 @@ public:
   virtual void MacOpenURL(const wxString &url);
   virtual void MacNewFile();
   virtual void MacReopenApp();
+  virtual bool OSXIsGUIApplication();
 #endif
 
   void init_consts(wxeMetaCommand& event);
diff --git a/lib/wx/c_src/wxe_nif.h b/lib/wx/c_src/wxe_nif.h
index a0e301b7a5..e466182ccf 100644
--- a/lib/wx/c_src/wxe_nif.h
+++ b/lib/wx/c_src/wxe_nif.h
@@ -116,3 +116,7 @@ void stop_native_gui(ErlNifEnv *);
 /* wxe_ps_init */
 void * wxe_ps_init();
 void * wxe_ps_init2();
+
+#ifdef  _MACOSX
+int is_packaged_app();
+#endif
-- 
2.34.1

openSUSE Build Service is sponsored by