diff --git a/src/mangoapp.cpp b/src/mangoapp.cpp index 91e01bc275..595e9ac67f 100644 --- a/src/mangoapp.cpp +++ b/src/mangoapp.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "steamcompmgr.hpp" @@ -9,8 +10,10 @@ static bool inited = false; static int msgid = 0; +static mqd_t mangoapp_mq = 0; extern bool g_bAppWantsHDRCached; extern uint32_t g_focusedBaseAppId; +extern const char *g_sMangoappMqName; struct mangoapp_msg_header { long msg_type; // Message queue ID, never change @@ -36,8 +39,22 @@ struct mangoapp_msg_v1 { } __attribute__((packed)) mangoapp_msg_v1; void init_mangoapp(){ - int key = ftok("mangoapp", 65); + // WARNING: "mangoapp" most likely isn't in the working directory so key will be -1 (0xffffffff) + // TODO: Deprecate SysV message queues + key_t key = ftok("mangoapp", 65); msgid = msgget(key, 0666 | IPC_CREAT); + struct mq_attr attrs = { + .mq_flags = O_NONBLOCK, + .mq_maxmsg = 4, + .mq_msgsize = sizeof( mangoapp_msg_v1 ), + }; + if ( g_sMangoappMqName != nullptr ) { + mq_unlink( g_sMangoappMqName ); + mangoapp_mq = mq_open( g_sMangoappMqName, O_CREAT | O_EXCL | O_WRONLY | O_NONBLOCK, S_IRUSR | S_IWUSR, &attrs ); + if (mangoapp_mq == -1) + console_log.errorf("Failed to create mangoapp message queue at %s %d (%s)", g_sMangoappMqName, errno, strerror(errno)); + } + mangoapp_msg_v1.hdr.msg_type = 1; mangoapp_msg_v1.hdr.version = 1; mangoapp_msg_v1.fsrUpscale = 0; @@ -60,6 +77,9 @@ void mangoapp_update( uint64_t visible_frametime, uint64_t app_frametime_ns, uin mangoapp_msg_v1.displayRefresh = (uint16_t) gamescope::ConvertmHzToHz( g_nOutputRefresh ); mangoapp_msg_v1.bAppWantsHDR = g_bAppWantsHDRCached; mangoapp_msg_v1.bSteamFocused = g_focusedBaseAppId == 769; + if (mangoapp_mq > 0 && mq_send( mangoapp_mq, (const char *)&mangoapp_msg_v1, sizeof( struct mangoapp_msg_v1 ), 0 ) == -1 && errno != EAGAIN) { + console_log.errorf( "Failed to send message to mangoapp %d: %s", errno, strerror( errno ) ); + } msgsnd(msgid, &mangoapp_msg_v1, sizeof(mangoapp_msg_v1) - sizeof(mangoapp_msg_v1.hdr.msg_type), IPC_NOWAIT); } diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 11a7cade6c..67c5127b6e 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -74,6 +74,7 @@ #include #include #include +#include #include #include #include "waitable.h" @@ -164,6 +165,8 @@ uint32_t g_reshade_technique_idx = 0; bool g_bSteamIsActiveWindow = false; bool g_bForceInternal = false; +const char *g_sMangoappMqName = nullptr; + static std::vector< steamcompmgr_win_t* > GetGlobalPossibleFocusWindows(); static bool pick_primary_focus_and_override(focus_t *out, Window focusControlWindow, const std::vector& vecPossibleFocusWindows, bool globalFocus, const std::vector& ctxFocusControlAppIDs); @@ -5900,6 +5903,9 @@ steamcompmgr_exit(void) { g_ImageWaiter.Shutdown(); + if ( g_sMangoappMqName != nullptr ) + mq_unlink( g_sMangoappMqName ); + // Clean up any commits. { gamescope_xwayland_server_t *server = NULL; @@ -7384,6 +7390,11 @@ void LaunchNestedChildren( char **ppPrimaryChildArgv ) if ( g_bLaunchMangoapp ) { + char szMangoappMqName[ NAME_MAX ]; + snprintf( szMangoappMqName, sizeof( szMangoappMqName ), "/gamescope-mangoapp-%d", getpid() ); + setenv( "MANGOAPP_MQ_NAME", szMangoappMqName, 0 ); + g_sMangoappMqName = getenv( "MANGOAPP_MQ_NAME" ); + char *ppMangoappArgv[] = { (char *)"mangoapp", NULL }; gamescope::Process::SpawnProcessInWatchdog( ppMangoappArgv, true ); }