1
0
Эх сурвалжийг харах

updated OnFocusChanged to use timer to avoid tons of focus change processing. Was causeing problems with double clicking on things in windows, double click wouldn't happen.

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@456 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 16 жил өмнө
parent
commit
a3b49a6b55
12 өөрчлөгдсөн 100 нэмэгдсэн , 57 устгасан
  1. 0 2
      CP_Main.cpp
  2. 4 4
      CP_Main.rc
  3. 2 2
      DittoSetup/DittoSetup.iss
  4. 32 5
      ExternalWindowTracker.cpp
  5. 2 3
      ExternalWindowTracker.h
  6. 50 14
      MainFrm.cpp
  7. 2 0
      MainFrm.h
  8. 0 23
      Misc.cpp
  9. 0 2
      Misc.h
  10. 6 1
      Options.cpp
  11. 1 0
      Options.h
  12. 1 1
      QuickPaste.cpp

+ 0 - 2
CP_Main.cpp

@@ -254,8 +254,6 @@ BOOL CCP_MainApp::InitInstance()
 	CMainFrame* pFrame = new CMainFrame;
 	m_pMainWnd = m_pMainFrame = pFrame;
 
-	m_activeWnd.TrackActiveWnd();
-
 	pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);
 	pFrame->ShowWindow(SW_SHOW);
 	pFrame->UpdateWindow();

+ 4 - 4
CP_Main.rc

@@ -919,8 +919,8 @@ END
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 3,16,2,0
- PRODUCTVERSION 3,16,2,0
+ FILEVERSION 3,16,4,0
+ PRODUCTVERSION 3,16,4,0
  FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -936,12 +936,12 @@ BEGIN
         BLOCK "040904b0"
         BEGIN
             VALUE "FileDescription", "Ditto"
-            VALUE "FileVersion", "3, 16, 2, 0"
+            VALUE "FileVersion", "3, 16, 4, 0"
             VALUE "InternalName", "CP_Main"
             VALUE "LegalCopyright", "Copyright (C) 2003"
             VALUE "OriginalFilename", "Ditto"
             VALUE "ProductName", "Ditto"
-            VALUE "ProductVersion", "3, 16, 2, 0"
+            VALUE "ProductVersion", "3, 16, 4, 0"
         END
     END
     BLOCK "VarFileInfo"

+ 2 - 2
DittoSetup/DittoSetup.iss

@@ -3,8 +3,8 @@
 
 [Setup]
 AppName=Ditto
-AppVerName=Ditto 3.16.3.0
-OutputBaseFilename=DittoSetup_3_16_3_0
+AppVerName=Ditto 3.16.4.0
+OutputBaseFilename=DittoSetup_3_16_4_0
 AppPublisher=Scott Brogden
 AppPublisherURL=ditto-cp.sourceforge.net
 AppSupportURL=ditto-cp.sourceforge.net

+ 32 - 5
ExternalWindowTracker.cpp

@@ -16,12 +16,16 @@ ExternalWindowTracker::~ExternalWindowTracker(void)
 {
 }
 
-bool ExternalWindowTracker::TrackActiveWnd()
+bool ExternalWindowTracker::TrackActiveWnd(HWND focus)
 {
+	HWND newFocus = focus;
 	HWND newActive = ::GetForegroundWindow();
-	AttachThreadInput(GetWindowThreadProcessId(newActive, NULL), GetCurrentThreadId(), TRUE);
-	HWND newFocus = GetFocus();
-	AttachThreadInput(GetWindowThreadProcessId(newActive, NULL), GetCurrentThreadId(), FALSE);
+	if(newFocus == NULL)
+	{
+		AttachThreadInput(GetWindowThreadProcessId(newActive, NULL), GetCurrentThreadId(), TRUE);
+		newFocus = GetFocus();
+		AttachThreadInput(GetWindowThreadProcessId(newActive, NULL), GetCurrentThreadId(), FALSE);
+	}
 
 	if(newFocus == 0 && newActive != 0)
 	{
@@ -224,4 +228,27 @@ bool ExternalWindowTracker::ReleaseFocus()
 	}
 
 	return false;
-}
+}
+
+CPoint ExternalWindowTracker::FocusCaret()
+{
+	CPoint pt(-1, -1);
+
+	if(m_activeWnd)
+	{
+		GUITHREADINFO guiThreadInfo;
+		guiThreadInfo.cbSize = sizeof(GUITHREADINFO);
+		DWORD OtherThreadID = GetWindowThreadProcessId(m_activeWnd, NULL);
+		if(GetGUIThreadInfo(OtherThreadID, &guiThreadInfo))
+		{
+			CRect rc(guiThreadInfo.rcCaret);
+			if(rc.IsRectEmpty() == FALSE)
+			{
+				pt = rc.BottomRight();
+				::ClientToScreen(m_focusWnd, &pt);
+			}
+		}
+	}
+
+	return pt;
+}

+ 2 - 3
ExternalWindowTracker.h

@@ -11,16 +11,15 @@ public:
 	bool DittoHasFocus() const { return m_dittoHasFocus; }
 
 	CString ActiveWndName();
-	bool TrackActiveWnd();
+	bool TrackActiveWnd(HWND focus);
 	bool ActivateTarget();
 	bool ReleaseFocus();
+	CPoint FocusCaret();
 
 	void SendPaste(bool activateTarget);
 	void SendCut();
 	void SendCopy();
 
-	
-
 protected:
 	HWND m_activeWnd;
 	HWND m_focusWnd;

+ 50 - 14
MainFrm.cpp

@@ -102,7 +102,7 @@ CMainFrame::CMainFrame()
 
 CMainFrame::~CMainFrame()
 {
-	if(g_Opt.m_bUseHookDllForFocus)
+	//if(g_Opt.m_bUseHookDllForFocus)
 		StopMonitoringFocusChanges();
 	
 	CGetSetOptions::SetMainHWND(0);
@@ -125,14 +125,14 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
 
 	SetWindowText(_T(""));
 
-	if(g_Opt.m_bUseHookDllForFocus)
+	//if(g_Opt.m_bUseHookDllForFocus)
 	{
 		MonitorFocusChanges(m_hWnd, WM_FOCUS_CHANGED);
 	}
-	else
-	{
-		SetTimer(ACTIVE_WINDOW_TIMER, 5000, 0);
-	}
+	//else
+	//{
+	//	SetTimer(ACTIVE_WINDOW_TIMER, 5000, 0);
+	//}
 	
 	SetWindowText(_T("Ditto"));
 
@@ -271,7 +271,10 @@ LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
 			m_startKeyStateTime = GetTickCount();
 			m_keyStateModifiers = GetKeyStateModifiers();
 			SetTimer(KEY_STATE_MODIFIERS, 50, NULL);
-			theApp.m_activeWnd.TrackActiveWnd();
+			if(g_Opt.m_bUseHookDllForFocus == false)
+			{
+				theApp.m_activeWnd.TrackActiveWnd(NULL);
+			}
 			QuickPaste.ShowQPasteWnd(this, false, true, FALSE);
 		}		
 	}
@@ -295,7 +298,7 @@ LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
 				CRect rcScreen;
 				GetMonitorRect(0, &rcScreen);
 
-				m_ToolTipPoint = GetFocusedCaretPos();
+				m_ToolTipPoint = theApp.m_activeWnd.FocusCaret();
 				if(m_ToolTipPoint.x < 0 || m_ToolTipPoint.y < 0)
 				{
 					CRect cr;
@@ -329,7 +332,7 @@ LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
 
 				CRect rcScreen;
 
-				m_ToolTipPoint = GetFocusedCaretPos();
+				m_ToolTipPoint = theApp.m_activeWnd.FocusCaret();
 				if(m_ToolTipPoint.x < 0 || m_ToolTipPoint.y < 0)
 				{
 					CRect cr;
@@ -594,7 +597,13 @@ void CMainFrame::OnTimer(UINT nIDEvent)
 		}
 		break;
 	case ACTIVE_WINDOW_TIMER:
-		theApp.m_activeWnd.TrackActiveWnd();
+		theApp.m_activeWnd.TrackActiveWnd(NULL);
+		break;
+
+	case FOCUS_CHANGED_TIMER:
+		KillTimer(FOCUS_CHANGED_TIMER);
+		//Log(StrF(_T("Focus Timer %d"), m_tempFocusWnd));
+		theApp.m_activeWnd.TrackActiveWnd(m_tempFocusWnd);
 		break;
 	}
 
@@ -696,7 +705,10 @@ BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
 	if( theApp.m_bShowingQuickPaste &&
 		WM_MOUSEFIRST <= pMsg->message && pMsg->message <= WM_MOUSELAST )
 	{	
-		theApp.m_activeWnd.TrackActiveWnd();
+		if(g_Opt.m_bUseHookDllForFocus == false)
+		{
+			theApp.m_activeWnd.TrackActiveWnd(NULL);
+		}
 	}
 
 	return CFrameWnd::PreTranslateMessage(pMsg);
@@ -909,10 +921,34 @@ LRESULT CMainFrame::OnKeyBoardChanged(WPARAM wParam, LPARAM lParam)
 
 LRESULT CMainFrame::OnFocusChanged(WPARAM wParam, LPARAM lParam)
 {
-	if(g_Opt.m_bUseHookDllForFocus == FALSE)
+	//if(g_Opt.m_bUseHookDllForFocus == FALSE)
+	//	return TRUE;
+
+	HWND focus = (HWND)wParam;
+	static DWORD dLastDittoHasFocusTick = 0;
+
+	//Sometimes when we bring ditto up there will come a null focus 
+	//rite after that
+	if(focus == NULL && (GetTickCount() - dLastDittoHasFocusTick < 500))
+	{
+		Log(_T("NULL focus within 500 ticks of bringing up ditto"));
 		return TRUE;
-	
-	theApp.m_activeWnd.TrackActiveWnd();
+	}
+	else if(focus == NULL)
+	{
+		Log(_T("NULL focus received"));
+	}
+
+	if(theApp.m_activeWnd.DittoHasFocus())
+	{
+		dLastDittoHasFocusTick = GetTickCount();
+	}
+
+	//Log(StrF(_T("OnFocusChanged %d"), focus));
+	m_tempFocusWnd = focus;
+
+	KillTimer(FOCUS_CHANGED_TIMER);
+	SetTimer(FOCUS_CHANGED_TIMER, g_Opt.FocusChangedDelay(), NULL);
 
 	return TRUE;
 }

+ 2 - 0
MainFrm.h

@@ -26,6 +26,7 @@
 #define END_DITTO_BUFFER_CLIPBOARD_TIMER	10
 #define KEY_STATE_MODIFIERS				11
 #define ACTIVE_WINDOW_TIMER				12
+#define FOCUS_CHANGED_TIMER				13
 
 class CMainFrame : public CFrameWnd
 {
@@ -70,6 +71,7 @@ public:
 	DWORD m_startKeyStateTime;
 	bool m_bMovedSelectionMoveKeyState;
 	short m_keyModifiersTimerCount;
+	HWND m_tempFocusWnd;
 
 	void DoDittoCopyBufferPaste(int nCopyBuffer);
 	void DoFirstTenPositionsPaste(int nPos);

+ 0 - 23
Misc.cpp

@@ -203,29 +203,6 @@ bool IsAppWnd( HWND hWnd )
 	return dwMyPID == dwTestPID;
 }
 
-CPoint GetFocusedCaretPos()
-{
-	CPoint pt(-1, -1);
-
-	if(theApp.m_activeWnd.ActiveWnd())
-	{
-		GUITHREADINFO guiThreadInfo;
-		guiThreadInfo.cbSize = sizeof(GUITHREADINFO);
-		DWORD OtherThreadID = GetWindowThreadProcessId(theApp.m_activeWnd.ActiveWnd(), NULL);
-		if(GetGUIThreadInfo(OtherThreadID, &guiThreadInfo))
-		{
-			CRect rc(guiThreadInfo.rcCaret);
-			if(rc.IsRectEmpty() == FALSE)
-			{
-				pt = rc.BottomRight();
-				::ClientToScreen(theApp.m_activeWnd.FocusWnd(), &pt);
-			}
-		}
-	}
-	
-	return pt;
-}
-
 /*----------------------------------------------------------------------------*\
 Global Memory Helper Functions
 \*----------------------------------------------------------------------------*/

+ 0 - 2
Misc.h

@@ -66,8 +66,6 @@ CString RemoveEscapes( const TCHAR* str );
 CString GetWndText( HWND hWnd );
 // returns true if the given window is owned by this process
 bool IsAppWnd( HWND hWnd );
-// returns the current Focus window even if it is not owned by our thread.
-CPoint GetFocusedCaretPos();
 
 // Global Memory Helper Functions
 BOOL IsValid( HGLOBAL hGlobal );

+ 6 - 1
Options.cpp

@@ -162,7 +162,7 @@ void CGetSetOptions::LoadSettings()
 	GetExtraNetworkPassword(true);
 
 #ifdef _DEBUG
-	m_bUseHookDllForFocus = FALSE;
+	//m_bUseHookDllForFocus = FALSE;
 #endif
 
 	for(int i = 0; i < MAX_SEND_CLIENTS; i++)
@@ -1881,4 +1881,9 @@ DWORD CGetSetOptions::SendKeysDelay()
 DWORD CGetSetOptions::WaitForFocusTimeout()
 {
 	return (DWORD)GetProfileLong(_T("WaitForFocusTimeout"), 100);
+}
+
+DWORD CGetSetOptions::FocusChangedDelay()
+{
+	return (DWORD)GetProfileLong(_T("FocusChangedDelay"), 100);
 }

+ 1 - 0
Options.h

@@ -385,6 +385,7 @@ public:
 	static DWORD	GetDittoHotKey();
 	static DWORD	SendKeysDelay();
 	static DWORD	WaitForFocusTimeout();
+	static DWORD	FocusChangedDelay();
 };
 
 // global for easy access and for initialization of fast access variables

+ 1 - 1
QuickPaste.cpp

@@ -128,7 +128,7 @@ void CQuickPaste::ShowQPasteWnd(CWnd *pParent, bool bAtPrevPos, bool bFromKeyboa
 		CGetSetOptions::GetQuickPasteSize(csSize);
 	}
 
-	CPoint ptCaret = GetFocusedCaretPos();
+	CPoint ptCaret = theApp.m_activeWnd.FocusCaret();
 	if(ptCaret.x <= 0 || ptCaret.y <= 0)
 	{
 		CRect cr;