Move focus handling from StepMania.cpp to ArchHooks. Arch-specific

code calls HOOKS->SetHasFocus when focus is lost or regained; user
code calls HOOKS->AppHasFocus as needed.  This moves the very
simple task of remembering focus to ArchHooks, and removes a
few annoying dependencies on StepMania.cpp.  (That's the highest-
level code there is, so very few things should depend on it.)

The original design of HOOKS is to be a place where portable
code calls to do platform-specific things, not to be a place
for nonportable code to call to do generic things.  These
state calls (SetHasFocus, SetToggleWindowed, SetUserQuit) don't
quite fit that.  But there's currently no better place to put
these, and they're just as low-level, so it's not really a
layering violation.  Hmm.

(This also eliminates GameLoop's dependency on StepMania.cpp.  Keeping
GL.cpp independent of SM.cpp is helpful.  It's not as useful to
split apart two files, if the two files are cross-dependent anyway;
you still have to know how both files work in order to understand
either of them.)
This commit is contained in:
Glenn Maynard
2005-12-30 03:57:01 +00:00
parent f06fd4b416
commit fcdb6602ab
2 changed files with 26 additions and 0 deletions
@@ -1,9 +1,11 @@
#include "global.h"
#include "ArchHooks.h"
#include "RageLog.h"
#include "RageThreads.h"
bool ArchHooks::s_bQuitting = false;
bool ArchHooks::s_bToggleWindowed = false;
static bool g_bHasFocus = true;
// Keep from pulling RageThreads.h into ArchHooks.h
static RageMutex s_AHLock( "ArchHooks lock" );
ArchHooks *HOOKS = NULL;
@@ -29,6 +31,20 @@ ArchHooks *MakeArchHooks()
return new ARCH_HOOKS;
}
void ArchHooks::SetHasFocus( bool bHasFocus )
{
if( bHasFocus == g_bHasFocus )
return;
g_bHasFocus = bHasFocus;
LOG->Trace( "App %s focus", bHasFocus? "has":"doesn't have" );
}
bool ArchHooks::AppHasFocus()
{
return g_bHasFocus;
}
/*
* (c) 2003-2004 Glenn Maynard, Chris Danford
* All rights reserved.
+10
View File
@@ -90,6 +90,16 @@ public:
*/
static void MountInitialFilesystems( const RString &sDirOfExecutable );
/*
* Platform-specific code calls this to indicate focus changes.
*/
void SetHasFocus( bool bAppHasFocus );
/*
* Return true if the application has input focus.
*/
bool AppHasFocus();
private:
/* This are helpers for GetMicrosecondsSinceStart on systems with a timer
* that may loop or move backwards. */