Apple's screen.c changes between upstream screen-4.0.3
and their release of screen, called screen-24.
You can view the screen-24 source at
https://opensource.apple.com/tarballs/screen/

Upstream screen-4.0.3 is released under the GPLv2,
so Apple's changes (this patch) is a derivative work and
also licensed under the GPLv2.

This patch was then rebased against the latest upstream
GNU Screen, which was version 4.6.2 and no longer required
many of Apple's changes. This was done by David Gilman
for MacPorts.

This patch is maintained separately from the window.c
changes since vproc.h and _CS_DARWIN_USER_TEMP_DIR require
macOS 10.5 or later.
--- screen.c	2021-05-08 19:39:20.092413588 -0400
+++ screen.c	2021-05-08 19:48:03.152597182 -0400
@@ -118,6 +118,15 @@
 
 #include "logfile.h" /* islogfile, logfflush, logfopen/logfclose */
 
+#ifdef __APPLE__
+#include <TargetConditionals.h>
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
+#include <vproc.h>
+#include <vproc_priv.h>
+#include <err.h>
+#endif
+#endif
+
 #ifdef DEBUG
 FILE *dfp;
 #endif
@@ -1206,6 +1215,16 @@
 	  Attacher();
 	  /* NOTREACHED */
     }
+#ifdef __APPLE__
+    else if (!multi && real_uid == eff_uid) {
+      static char DarwinSockDir[PATH_MAX];
+      if (confstr(_CS_DARWIN_USER_TEMP_DIR, DarwinSockDir, sizeof(DarwinSockDir))) {
+	strlcat(DarwinSockDir, ".screen", sizeof(DarwinSockDir));
+	SockDir = DarwinSockDir;
+      }
+    }
+#endif	/* __APPLE__ */
+
 #ifdef MULTIUSER
     if (multiattach)
       Panic(0, "Can't create sessions of other users.");
@@ -1314,6 +1333,11 @@
   freopen("/dev/null", "w", stderr);
   debug("-- screen.back debug started\n");
 
+#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
+	if (_vprocmgr_detach_from_console(0) != NULL)
+		errx(1, "can't detach from console");
+#endif
+
   /*  This guarantees that the session owner is listed, even when we
    *  start detached. From now on we should not refer to 'LoginName'
    *  any more, use users->u_name instead.
