Introduce thread-safe take_screenshot

This commit is contained in:
Simon Ser 2021-07-28 10:12:04 +02:00
parent 501eff233e
commit 82ef0372d5
6 changed files with 11 additions and 12 deletions

View file

@ -42,8 +42,6 @@ bool g_bFilterGameWindow = true;
bool g_bBorderlessOutputWindow = false;
bool g_bTakeScreenshot = false;
bool g_bNiceCap = false;
int g_nOldNice = 0;
int g_nNewNice = 0;

View file

@ -23,8 +23,6 @@ extern bool g_bFilterGameWindow;
extern bool g_bBorderlessOutputWindow;
extern bool g_bTakeScreenshot;
extern bool g_bNiceCap;
extern int g_nOldNice;
extern int g_nNewNice;

View file

@ -160,7 +160,7 @@ void inputSDLThreadRun( void )
g_bFilterGameWindow = !g_bFilterGameWindow;
break;
case KEY_S:
g_bTakeScreenshot = true;
take_screenshot();
break;
default:
handled = false;

View file

@ -276,12 +276,13 @@ static Bool drawDebugInfo = False;
static Bool debugEvents = False;
static Bool steamMode = False;
static Bool alwaysComposite = False;
static Bool takeScreenshot = False;
static Bool useXRes = True;
std::mutex wayland_commit_lock;
std::vector<ResListEntry_t> wayland_commit_queue;
static std::atomic< bool > g_bTakeScreenshot{false};
static int g_nudgePipe[2];
// poor man's semaphore
@ -1249,11 +1250,7 @@ paint_all(Display *dpy, MouseCursor *cursor)
bool bDoComposite = true;
// Handoff from whatever thread to this one since we check ours twice
if ( g_bTakeScreenshot == true )
{
takeScreenshot = true;
g_bTakeScreenshot = false;
}
bool takeScreenshot = g_bTakeScreenshot.exchange(false);
if ( BIsNested() == false && alwaysComposite == False && takeScreenshot == False )
{
@ -2913,6 +2910,11 @@ void nudge_steamcompmgr( void )
perror( "nudge_steamcompmgr: write failed" );
}
void take_screenshot( void )
{
g_bTakeScreenshot = true;
}
void check_new_wayland_res( void )
{
// When importing buffer, we'll potentially need to perform operations with

View file

@ -89,3 +89,4 @@ extern float focusedWindowOffsetX;
extern float focusedWindowOffsetY;
void nudge_steamcompmgr( void );
void take_screenshot( void );

View file

@ -71,7 +71,7 @@ void sig_handler(int signal)
{
if ( signal == SIGUSR2 )
{
g_bTakeScreenshot = true;
take_screenshot();
return;
}