Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mangoapp: Select unique SysV message queue #1660

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/mangoapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ static bool inited = false;
static int msgid = 0;
extern bool g_bAppWantsHDRCached;
extern uint32_t g_focusedBaseAppId;
extern int g_sMangoappMqId;

struct mangoapp_msg_header {
long msg_type; // Message queue ID, never change
Expand All @@ -36,8 +37,11 @@ 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: Stop using message queues
key_t key = ftok("mangoapp", 65);
msgid = msgget(key, 0666 | IPC_CREAT);

mangoapp_msg_v1.hdr.msg_type = 1;
mangoapp_msg_v1.hdr.version = 1;
mangoapp_msg_v1.fsrUpscale = 0;
Expand All @@ -60,7 +64,10 @@ 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;

msgsnd(msgid, &mangoapp_msg_v1, sizeof(mangoapp_msg_v1) - sizeof(mangoapp_msg_v1.hdr.msg_type), IPC_NOWAIT);
if (g_sMangoappMqId > 0)
msgsnd(g_sMangoappMqId, &mangoapp_msg_v1, sizeof(mangoapp_msg_v1) - sizeof(mangoapp_msg_v1.hdr.msg_type), IPC_NOWAIT);
}

extern uint64_t g_uCurrentBasePlaneCommitID;
Expand Down
27 changes: 27 additions & 0 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#endif
#include <sys/socket.h>
#include <sys/resource.h>
#include <sys/msg.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>
Expand Down Expand Up @@ -164,6 +165,8 @@ uint32_t g_reshade_technique_idx = 0;
bool g_bSteamIsActiveWindow = false;
bool g_bForceInternal = false;

int g_sMangoappMqId = -1;

static std::vector< steamcompmgr_win_t* > GetGlobalPossibleFocusWindows();
static bool
pick_primary_focus_and_override(focus_t *out, Window focusControlWindow, const std::vector<steamcompmgr_win_t*>& vecPossibleFocusWindows, bool globalFocus, const std::vector<uint32_t>& ctxFocusControlAppIDs);
Expand Down Expand Up @@ -5900,6 +5903,9 @@ steamcompmgr_exit(void)
{
g_ImageWaiter.Shutdown();

if ( g_sMangoappMqId > 0 )
msgctl( g_sMangoappMqId, IPC_RMID, NULL);

// Clean up any commits.
{
gamescope_xwayland_server_t *server = NULL;
Expand Down Expand Up @@ -7390,6 +7396,27 @@ void LaunchNestedChildren( char **ppPrimaryChildArgv )

if ( g_bLaunchMangoapp )
{
char szMangoappMqKey[ NAME_MAX ];
// Attempt to find a fresh message queue id
for ( int i = 0; i < 255; i++ ) {
key_t key = ftok( ".", i );
int res = msgget( key, 0666 | IPC_CREAT | IPC_EXCL );
if ( res == -1 ) {
switch ( errno ) {
case EEXIST:
continue;
default:
break;
}
}

// Success
g_sMangoappMqId = res;
snprintf( szMangoappMqKey, sizeof( szMangoappMqKey ), "%d", key );
setenv( "MANGOAPP_MQ_KEY", szMangoappMqKey, 0 );
break;
}

char *ppMangoappArgv[] = { (char *)"mangoapp", NULL };
gamescope::Process::SpawnProcessInWatchdog( ppMangoappArgv, true );
}
Expand Down
Loading