Update SDL window title from the focused window's title
* Update SDL window title from the focused window's title. Instead of using the default "gamescope" title for the SDL window, this makes the SDL window title be updated with the focused window's title whenever a window is focused or whenever the focused window's title is changed. "gamescope" is still used whenever a title cannot be obtained. * Call SDL_SetWindowTitle from the sdlwindow thread. This calls SDL_SetWindowTitle from the sdlwindow thread instead of from wherever sdlwindow_title is called. sdlwindow_title stores the title locally to be picked up by sdlwindow_update. * Make SDL title update bool check atomic and use a mutex for title change. * Ensure *all* accesses to g_SDLWindowTitle are behind the mutex lock. * The atomic bool isn't really necessary with the mutex in place, so remove it.
This commit is contained in:
parent
c1958be1d9
commit
bbfbf0dd8d
3 changed files with 35 additions and 1 deletions
|
@ -13,6 +13,8 @@
|
|||
|
||||
#include "sdlscancodetable.hpp"
|
||||
|
||||
#define DEFAULT_TITLE "gamescope"
|
||||
|
||||
static bool g_bSDLInitOK = false;
|
||||
static std::mutex g_SDLInitLock;
|
||||
|
||||
|
@ -25,6 +27,10 @@ SDL_Window *g_SDLWindow;
|
|||
static uint32_t g_unSDLUserEventID;
|
||||
static SDL_Event g_SDLUserEvent;
|
||||
|
||||
static std::mutex g_SDLWindowTitleLock;
|
||||
static std::string g_SDLWindowTitle;
|
||||
static bool g_bUpdateSDLWindowTitle = false;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Convert from the remote scancode to a Linux event keycode
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -84,7 +90,7 @@ void inputSDLThreadRun( void )
|
|||
nSDLWindowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
|
||||
g_SDLWindow = SDL_CreateWindow( "gamescope",
|
||||
g_SDLWindow = SDL_CreateWindow( DEFAULT_TITLE,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
g_nOutputWidth,
|
||||
|
@ -242,6 +248,27 @@ void sdlwindow_update( void )
|
|||
SDL_HideWindow( g_SDLWindow );
|
||||
}
|
||||
}
|
||||
|
||||
g_SDLWindowTitleLock.lock();
|
||||
if ( g_bUpdateSDLWindowTitle )
|
||||
{
|
||||
g_bUpdateSDLWindowTitle = false;
|
||||
SDL_SetWindowTitle( g_SDLWindow, g_SDLWindowTitle.c_str() );
|
||||
}
|
||||
g_SDLWindowTitleLock.unlock();
|
||||
}
|
||||
|
||||
void sdlwindow_title( const char* title )
|
||||
{
|
||||
title = title ? title : DEFAULT_TITLE;
|
||||
g_SDLWindowTitleLock.lock();
|
||||
if ( g_SDLWindowTitle != title )
|
||||
{
|
||||
g_SDLWindowTitle = title ? title : DEFAULT_TITLE;
|
||||
g_bUpdateSDLWindowTitle = true;
|
||||
sdlwindow_pushupdate();
|
||||
}
|
||||
g_SDLWindowTitleLock.unlock();
|
||||
}
|
||||
|
||||
void sdlwindow_pushupdate( void )
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
bool sdlwindow_init( void );
|
||||
|
||||
void sdlwindow_update( void );
|
||||
void sdlwindow_title( const char* title );
|
||||
|
||||
// called from other threads with interesting things have happened with clients that might warrant updating the nested window
|
||||
void sdlwindow_pushupdate( void );
|
||||
|
|
|
@ -2218,6 +2218,8 @@ found:
|
|||
}
|
||||
|
||||
XFree(children);
|
||||
|
||||
sdlwindow_title( w->title );
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -3199,6 +3201,10 @@ handle_property_notify(Display *dpy, XPropertyEvent *ev)
|
|||
win *w = find_win(dpy, ev->window);
|
||||
if (w) {
|
||||
get_win_title(dpy, w, ev->atom);
|
||||
if (w == currentFocusWin)
|
||||
{
|
||||
sdlwindow_title( w->title );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue