Browse Source

check for minimum idle time before getting the current focused window, i think this was causing some double click issues on folders

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@622 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 14 years ago
parent
commit
31bd95378b
10 changed files with 34 additions and 18 deletions
  1. 1 1
      CP_Main.cpp
  2. 2 2
      DatabaseUtilities.cpp
  3. 8 2
      ExternalWindowTracker.cpp
  4. 1 1
      ExternalWindowTracker.h
  5. 5 5
      MainFrm.cpp
  6. 9 4
      Misc.cpp
  7. 1 1
      Misc.h
  8. 0 2
      MultiLanguage.cpp
  9. 5 0
      Options.cpp
  10. 2 0
      Options.h

+ 1 - 1
CP_Main.cpp

@@ -81,7 +81,7 @@ END_MESSAGE_MAP()
 
 CCP_MainApp::CCP_MainApp()
 {
-	theApp.m_activeWnd.TrackActiveWnd(NULL);
+	theApp.m_activeWnd.TrackActiveWnd(NULL, false);
 
 	m_bAppRunning = false;
 	m_bAppExiting = false;

+ 2 - 2
DatabaseUtilities.cpp

@@ -629,7 +629,7 @@ BOOL RemoveOldEntries()
 
 		int toDeleteCount = db.execScalar(_T("SELECT COUNT(clipID) FROM MainDeletes"));
 
-		Log(StrF(_T("Before Deleting emptied out data, count: %d, Idle Seconds: %d"), toDeleteCount, IdleSeconds()));
+		Log(StrF(_T("Before Deleting emptied out data, count: %d, Idle Seconds: %f"), toDeleteCount, IdleSeconds()));
 
 		//Only delete 1 at a time, was finding that it was taking a long time to delete clips, locking the db and causing other queries
 		//to lock up
@@ -638,7 +638,7 @@ BOOL RemoveOldEntries()
 
 		while(q.eof() == false)
 		{
-			DWORD idleSeconds = IdleSeconds();
+			double idleSeconds = IdleSeconds();
 			if(idleSeconds > CGetSetOptions::GetIdleSecondsBeforeDelete())
 			{
 				//delete any data items sitting out there that the main table data was deleted

+ 8 - 2
ExternalWindowTracker.cpp

@@ -16,8 +16,14 @@ ExternalWindowTracker::~ExternalWindowTracker(void)
 {
 }
 
-bool ExternalWindowTracker::TrackActiveWnd(HWND focus)
+bool ExternalWindowTracker::TrackActiveWnd(HWND focus, bool force)
 {
+	if(force == false && IdleSeconds() < (CGetSetOptions::GetMinIdleTimeBeforeTrackFocus() / 1000.0))
+	{
+		Log(StrF(_T("Not Idle for long enough, IdleTime: %f, MinIdle %f"), IdleSeconds(), (CGetSetOptions::GetMinIdleTimeBeforeTrackFocus() / 1000.0)));
+		return false;
+	}
+
 	BOOL fromHook = true;
 	HWND newFocus = focus;
 	HWND newActive = ::GetForegroundWindow();
@@ -81,7 +87,7 @@ bool ExternalWindowTracker::TrackActiveWnd(HWND focus)
 	if(theApp.QPasteWnd())
 		theApp.QPasteWnd()->UpdateStatus(true);
 
-	Log(StrF(_T("TargetActiveWindow Active: %s (%d), Focus: %s (%d), FromHook %d"), WndName(m_activeWnd), m_activeWnd, WndName(m_focusWnd), m_focusWnd, fromHook));
+	Log(StrF(_T("TargetActiveWindow Active: %s (%d), Focus: %s (%d), FromHook %d, IdleTime: %f"), WndName(m_activeWnd), m_activeWnd, WndName(m_focusWnd), m_focusWnd, fromHook, IdleSeconds()));
 
 	return true;
 }

+ 1 - 1
ExternalWindowTracker.h

@@ -12,7 +12,7 @@ public:
 
 	CString ActiveWndName();
 	CString WndName(HWND hWnd);
-	bool TrackActiveWnd(HWND focus);
+	bool TrackActiveWnd(HWND focus, bool force);
 	bool ActivateTarget();
 	bool ReleaseFocus();
 	CPoint FocusCaret();

+ 5 - 5
MainFrm.cpp

@@ -257,7 +257,7 @@ LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
             SetTimer(KEY_STATE_MODIFIERS, 50, NULL);
 
 			//Before we show our window find the current focused window for paste into
-			theApp.m_activeWnd.TrackActiveWnd(NULL);
+			theApp.m_activeWnd.TrackActiveWnd(NULL, true);
 
             m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
         }
@@ -535,7 +535,7 @@ void CMainFrame::OnTimer(UINT_PTR nIDEvent)
 			{
 				if(m_TrayIcon.Visible())
 				{
-					theApp.m_activeWnd.TrackActiveWnd(NULL);
+					theApp.m_activeWnd.TrackActiveWnd(NULL, false);
 				}
 			}
 			break;
@@ -544,7 +544,7 @@ void CMainFrame::OnTimer(UINT_PTR nIDEvent)
 			{
 				KillTimer(FOCUS_CHANGED_TIMER);
 	            //Log(StrF(_T("Focus Timer %d"), m_tempFocusWnd));
-	            theApp.m_activeWnd.TrackActiveWnd(m_tempFocusWnd);
+	            theApp.m_activeWnd.TrackActiveWnd(m_tempFocusWnd, false);
 			}
             break;
 
@@ -620,7 +620,7 @@ BOOL CMainFrame::PreTranslateMessage(MSG *pMsg)
     {
         if(g_Opt.m_bUseHookDllForFocus == false)
         {
-            theApp.m_activeWnd.TrackActiveWnd(NULL);
+            theApp.m_activeWnd.TrackActiveWnd(NULL, false);
         }
     }
 
@@ -691,7 +691,7 @@ bool CMainFrame::CloseAllOpenDialogs()
 
 LRESULT CMainFrame::OnSystemTrayMouseMove(WPARAM wParam, LPARAM lParam)
 {
-	theApp.m_activeWnd.TrackActiveWnd(NULL);
+	theApp.m_activeWnd.TrackActiveWnd(NULL, false);
 	return 0;
 }
 

+ 9 - 4
Misc.cpp

@@ -134,7 +134,7 @@ CString GetErrorString( int err )
 
 int g_funnyGetTickCountAdjustment = -1;
 
-DWORD IdleSeconds()
+double IdleSeconds()
 {
 	LASTINPUTINFO info; 
 	info.cbSize = sizeof(info);
@@ -153,13 +153,18 @@ DWORD IdleSeconds()
 		}		
 	}
 	
-	if(g_funnyGetTickCountAdjustment == 1)
+	if(g_funnyGetTickCountAdjustment == 1 || g_funnyGetTickCountAdjustment == 2)
 	{
-		Log(StrF(_T("Adjusting time of get tickcount by: %d, on startup we found GetTickCount to be less than last input"), CGetSetOptions::GetFunnyTickCountAdjustment()));
+		//Output message the first time
+		if(g_funnyGetTickCountAdjustment == 1)
+		{
+			Log(StrF(_T("Adjusting time of get tickcount by: %d, on startup we found GetTickCount to be less than last input"), CGetSetOptions::GetFunnyTickCountAdjustment()));
+			g_funnyGetTickCountAdjustment = 2;
+		}
 		currentTick += CGetSetOptions::GetFunnyTickCountAdjustment();
 	}
 
-	DWORD idleSeconds = (currentTick - info.dwTime)/1000;
+	double idleSeconds = (currentTick - info.dwTime)/1000.0;
 
 	return idleSeconds;
 }

+ 1 - 1
Misc.h

@@ -51,7 +51,7 @@ void AppendToFile(const TCHAR* fn, const TCHAR *msg);
 void log(const TCHAR* msg, bool bFromSendRecieve = false, CString csFile = _T(""), long lLine = -1);
 CString GetErrorString(int err);
 
-DWORD IdleSeconds();
+double IdleSeconds();
 
 #define LogSendRecieveInfo(cs) logsendrecieveinfo(cs, __FILE__, __LINE__)
 void logsendrecieveinfo(CString cs, CString csFile = _T(""), long lLine = -1);

+ 0 - 2
MultiLanguage.cpp

@@ -108,8 +108,6 @@ CString CMultiLanguage::GetString(CString csID, CString csDefault)
 
 CString CMultiLanguage::GetGlobalHotKeyString(CString csID, CString csDefault)
 {
-	CLangItem *pItem;
-
 	INT_PTR size = m_GlobalHotKeys.GetSize();
 	for(int i = 0; i < size; i++)
 	{

+ 5 - 0
Options.cpp

@@ -2013,4 +2013,9 @@ DWORD CGetSetOptions::GetDbTimeout()
 DWORD CGetSetOptions::GetFunnyTickCountAdjustment()
 {  
 	return GetProfileLong(_T("FunnyTickCountAdjustment"), 300001);
+}
+
+DWORD CGetSetOptions::GetMinIdleTimeBeforeTrackFocus()
+{
+	return GetProfileLong(_T("MinIdleTimeBeforeTrackFocus"), 100);
 }

+ 2 - 0
Options.h

@@ -417,6 +417,8 @@ public:
 	static DWORD	GetDbTimeout();
 
 	static DWORD	GetFunnyTickCountAdjustment();
+
+	static DWORD	GetMinIdleTimeBeforeTrackFocus();
 };
 
 // global for easy access and for initialization of fast access variables