From fcdb6602ab87b06fe0c957b1d222fde602092c22 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 30 Dec 2005 03:57:01 +0000 Subject: [PATCH] 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.) --- stepmania/src/arch/ArchHooks/ArchHooks.cpp | 16 ++++++++++++++++ stepmania/src/arch/ArchHooks/ArchHooks.h | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/stepmania/src/arch/ArchHooks/ArchHooks.cpp b/stepmania/src/arch/ArchHooks/ArchHooks.cpp index 90fd71673c..64997c5550 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks.cpp @@ -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. diff --git a/stepmania/src/arch/ArchHooks/ArchHooks.h b/stepmania/src/arch/ArchHooks/ArchHooks.h index b574fc8054..3c38d40a85 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks.h @@ -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. */