private void DoActivateBrowser(int newDesktop) { var browserInfo = settings.GetBrowserToActivateInfo(); if (movingWindow == IntPtr.Zero || !IsWindowDefaultBrowser(movingWindow, browserInfo)) { var fgHwnd = WinAPI.GetForegroundWindow(); var lastActiveWindow = activeWindows[Current]; if (browserInfo != null) { if (lastActiveBrowserWindows[Current] != activeWindows[Current]) { FindActivateBrowserWindow(lastActiveBrowserWindows[Current], browserInfo); } } if (!ActivateWindow(lastActiveWindow)) { if (fgHwnd != WinAPI.GetForegroundWindow()) { Debug.WriteLine("Reactivate " + Current + " " + fgHwnd); WinAPI.SetForegroundWindow(fgHwnd); } } } movingWindow = IntPtr.Zero; }
private void VirtualDesktop_CurrentChanged(object sender, VirtualDesktopChangedEventArgs e) { lock (callbackMutex) { var newDesktop = desktopIdLookup[VirtualDesktop.Current]; Debug.WriteLine("Switched to " + newDesktop); _current = newDesktop; sysTrayProcess.ShowIconForDesktop(Current); MoveStickyWindows(_current); var fgHwnd = WinAPI.GetForegroundWindow(); var lastActiveWindow = activeWindows[Current]; var browserInfo = settings.GetBrowserToActivateInfo(); if (browserInfo != null) { if (lastActiveBrowserWindows[Current] != activeWindows[Current]) { FindActivateBrowserWindow(lastActiveBrowserWindows[Current], browserInfo); } } if (!ActivateWindow(lastActiveWindow)) { Debug.WriteLine("Reactivate " + Current + " " + fgHwnd); WinAPI.SetForegroundWindow(fgHwnd); } movingWindow = IntPtr.Zero; SendSwitchedDesktopMessage(); } }