public void SwitchToWorkspace(int workspaceId, bool setForeground = true) { var newWorkspace = workspaceId == 0 ? CurrentWorkspace : config.Workspaces[workspaceId - 1]; if (newWorkspace.id != CurrentWorkspace.id) { if (newWorkspace.IsWorkspaceVisible) { // workspace is already visible on another monitor if (setForeground) { DoForTopmostWindowForWorkspace(newWorkspace, ForceForegroundWindow); } CurrentWorkspace.IsCurrentWorkspace = false; newWorkspace.IsCurrentWorkspace = true; } else { // TODO: must check if there are shared windows on two different monitors if (CurrentWorkspace.Monitor.temporarilyShownWindows.Count > 0) { CurrentWorkspace.Monitor.temporarilyShownWindows.ForEach(hWnd => HideWindow(applications[hWnd].First.Value.Item2)); CurrentWorkspace.Monitor.temporarilyShownWindows.Clear(); } var currentVisibleWorkspace = newWorkspace.Monitor.CurrentVisibleWorkspace; var needsToReposition = newWorkspace.NeedsToReposition(); if (!needsToReposition) { // first show and hide if there are no changes ShowHideWindows(currentVisibleWorkspace, newWorkspace, setForeground); } CurrentWorkspace.IsCurrentWorkspace = false; newWorkspace.Monitor.SwitchToWorkspace(newWorkspace); newWorkspace.IsCurrentWorkspace = true; if (needsToReposition) { // show and hide only after Reposition has been called if there are changes ShowHideWindows(currentVisibleWorkspace, newWorkspace, setForeground); } } if (monitors.Length > 1) { if (CurrentWorkspace.Monitor != newWorkspace.Monitor) { if (config.MoveMouseOverMonitorsOnSwitch) { Utilities.MoveMouseToMiddleOf(newWorkspace.Monitor.Bounds); } // remove windows from ALT-TAB menu and Taskbar if (CurrentWorkspace.hideFromAltTabWhenOnInactiveWorkspaceCount > 0) { CurrentWorkspace.GetWindows().Where(w => w.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace).ForEach(w => w.ShowInAltTabAndTaskbar(false)); } } // add windows to ALT-TAB menu and Taskbar if (newWorkspace.hideFromAltTabWhenOnInactiveWorkspaceCount > 0) { newWorkspace.GetWindows().Where(w => w.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace).ForEach(w => w.ShowInAltTabAndTaskbar(true)); } } CurrentWorkspace = newWorkspace; DoForTopmostWindowForWorkspace(CurrentWorkspace, w => CurrentWorkspace.WindowActivated(w.hWnd)); } }