From 7b2220003cd46364ef6e1afc14f683764b5efe24 Mon Sep 17 00:00:00 2001 From: "Pierre-Loup A. Griffais" Date: Sat, 18 Jan 2020 17:12:03 -0800 Subject: [PATCH] Let it take a command to run in its DISPLAY after "--". --- src/main.cpp | 13 +++++++++++++ src/main.hpp | 2 ++ src/steamcompmgr.c | 23 ++++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 57e9576..31b0c65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,8 @@ bool g_bFilterGameWindow = true; bool g_bBorderlessOutputWindow = false; +uint32_t g_nSubCommandArg = 0; + int BIsNested() { return g_bIsNested == true; @@ -39,6 +41,17 @@ int BIsNested() int main(int argc, char **argv) { + // Grab the starting position of a potential command that follows "--" in argv + // Do it before getopt can reorder anything, for use later + for ( int i = 0; i < argc; i++ ) + { + if ( strcmp( "--", argv[ i ] ) == 0 && i + 1 < argc ) + { + g_nSubCommandArg = i + 1; + break; + } + } + int o; ac = argc; av = argv; diff --git a/src/main.hpp b/src/main.hpp index d725733..a252494 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -33,6 +33,8 @@ extern uint32_t g_nOutputHeight; extern bool g_bFilterGameWindow; +extern uint32_t g_nSubCommandArg; + int BIsNested( void ); #ifndef C_SIDE diff --git a/src/steamcompmgr.c b/src/steamcompmgr.c index f0e5785..f682738 100644 --- a/src/steamcompmgr.c +++ b/src/steamcompmgr.c @@ -41,6 +41,9 @@ #include #include #include +#include +#include + #include #include #include @@ -60,6 +63,8 @@ #define GPUVIS_TRACE_IMPLEMENTATION #include "gpuvis_trace_utils.h" +extern char **environ; + typedef struct _ignore { struct _ignore *next; unsigned long sequence; @@ -1702,7 +1707,7 @@ steamcompmgr_main (int argc, char **argv) break; } } - + dpy = XOpenDisplay (wlserver.wlr.xwayland->display_name); if (!dpy) { @@ -1832,6 +1837,22 @@ steamcompmgr_main (int argc, char **argv) readyPipeFD = -1; } + if ( g_nSubCommandArg != 0 ) + { + pid_t pid; + + sigset_t fullset; + sigfillset( &fullset ); + + posix_spawnattr_t attr; + + posix_spawnattr_init( &attr ); + posix_spawnattr_setflags( &attr, POSIX_SPAWN_SETSIGDEF ); + posix_spawnattr_setsigdefault( &attr, &fullset ); + + posix_spawnp( &pid, argv[ g_nSubCommandArg ], NULL, &attr, &argv[ g_nSubCommandArg ], environ ); + } + for (;;) { focusDirty = False;