private void OnWorkspaceApplicationAdded(Workspace workspace, Window window) { if (workspace.Layout.LayoutName() == "Tile" || workspace.Layout.LayoutName() == "Full Screen") { if (!IsMatch(window.className, window.DisplayName)) { if (Environment.Is64BitProcess && window.is64BitProcess) { if (subclassedWindows[workspace.id - 1].Add(window) == HashMultiSet<Window>.AddResult.AddedFirst) { NativeMethods.SubclassWindow64(windawesome.Handle, window.hWnd); } if (workspace.IsCurrentWorkspace) { NativeMethods.SendNotifyMessage(window.hWnd, startWindowProcMessage, UIntPtr.Zero, IntPtr.Zero); } } else if (!Environment.Is64BitOperatingSystem) { if (subclassedWindows[workspace.id - 1].Add(window) == HashMultiSet<Window>.AddResult.AddedFirst) { NativeMethods.SubclassWindow32(windawesome.Handle, window.hWnd); } if (workspace.IsCurrentWorkspace) { NativeMethods.SendNotifyMessage(window.hWnd, startWindowProcMessage, UIntPtr.Zero, IntPtr.Zero); } } } } }
internal void AddWorkspace(Workspace workspace) { var workspaceBarsAtTop = workspace.barsAtTop[monitorIndex]; var workspaceBarsAtBottom = workspace.barsAtBottom[monitorIndex]; var matchingBar = workspaces.Keys.FirstOrDefault(ws => workspaceBarsAtTop.SequenceEqual(ws.barsAtTop[monitorIndex]) && workspaceBarsAtBottom.SequenceEqual(ws.barsAtBottom[monitorIndex])); if (matchingBar != null) { var matchingWorkspace = workspaces[matchingBar]; this.workspaces[workspace] = Tuple.Create(matchingWorkspace.Item1, matchingWorkspace.Item2, matchingWorkspace.Item3); return ; } var workspaceBarsEquivalentClass = (this.workspaces.Count == 0 ? 0 : this.workspaces.Values.Max(t => t.Item1)) + 1; AppBarNativeWindow appBarTopWindow; var topBarsHeight = workspaceBarsAtTop.Sum(bar => bar.GetBarHeight()); var matchingAppBar = workspaces.Values.Select(t => t.Item2).FirstOrDefault(ab => (ab == null && topBarsHeight == 0) || (ab != null && topBarsHeight == ab.height)); if (matchingAppBar != null || topBarsHeight == 0) { appBarTopWindow = matchingAppBar; } else { appBarTopWindow = new AppBarNativeWindow(topBarsHeight, true); } AppBarNativeWindow appBarBottomWindow; var bottomBarsHeight = workspaceBarsAtBottom.Sum(bar => bar.GetBarHeight()); matchingAppBar = workspaces.Values.Select(t => t.Item3).FirstOrDefault(uniqueAppBar => (uniqueAppBar == null && bottomBarsHeight == 0) || (uniqueAppBar != null && bottomBarsHeight == uniqueAppBar.height)); if (matchingAppBar != null || bottomBarsHeight == 0) { appBarBottomWindow = matchingAppBar; } else { appBarBottomWindow = new AppBarNativeWindow(bottomBarsHeight, false); } this.workspaces[workspace] = Tuple.Create(workspaceBarsEquivalentClass, appBarTopWindow, appBarBottomWindow); }
private static void DoWindowTitleOrIconChanged(Workspace workspace, Window window, string newText, Bitmap newIcon) { if (WindowTitleOrIconChanged != null) { WindowTitleOrIconChanged(workspace, window, newText, newIcon); } }
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)); } }
private void SwapWorkspacesMonitorsAndSwitchTo(Workspace workspace) { var currentWorkspaceMonitor = CurrentWorkspace.Monitor; var newWorkspaceMonitor = workspace.Monitor; currentWorkspaceMonitor.HideBars(workspace, CurrentWorkspace); newWorkspaceMonitor.HideBars(CurrentWorkspace, workspace); // first add the workspaces to their new monitors newWorkspaceMonitor.AddWorkspace(CurrentWorkspace); currentWorkspaceMonitor.AddWorkspace(workspace); // show the new bars while hiding the old ones newWorkspaceMonitor.ShowHideAppBars(workspace, CurrentWorkspace); currentWorkspaceMonitor.ShowHideAppBars(CurrentWorkspace, workspace); // only then remove the old workspaces from the monitors newWorkspaceMonitor.RemoveWorkspace(workspace); currentWorkspaceMonitor.RemoveWorkspace(CurrentWorkspace); // swap the workspaces' monitors CurrentWorkspace.Monitor = newWorkspaceMonitor; workspace.Monitor = currentWorkspaceMonitor; // swap the monitors' current visible workspaces currentWorkspaceMonitor.CurrentVisibleWorkspace = workspace; newWorkspaceMonitor.CurrentVisibleWorkspace = CurrentWorkspace; currentWorkspaceMonitor.ShowBars(workspace); newWorkspaceMonitor.ShowBars(CurrentWorkspace); // reposition the windows in the two workspaces workspace.Reposition(); CurrentWorkspace.Reposition(); // finally switch to the workspace SwitchToWorkspace(workspace.id); Workspace.DoWorkspaceMonitorChanged(workspace, newWorkspaceMonitor, currentWorkspaceMonitor); Workspace.DoWorkspaceMonitorChanged(CurrentWorkspace, currentWorkspaceMonitor, newWorkspaceMonitor); }
private void FollowWindow(Workspace fromWorkspace, Workspace toWorkspace, bool follow, WindowBase window) { if (follow) { SwitchToWorkspace(toWorkspace.id, false); ActivateWindow(window); } else if (fromWorkspace.IsCurrentWorkspace) { DoForTopmostWindowForWorkspace(CurrentWorkspace, ActivateWindow); } }
private static void DoWorkspaceWindowOrderChanged(Workspace workspace, Window window, int positions, bool backwards) { if (WorkspaceWindowOrderChanged != null) { WorkspaceWindowOrderChanged(workspace, window, positions, backwards); } }
private static void DoWorkspaceLayoutChanged(Workspace workspace, ILayout oldLayout) { if (WorkspaceLayoutChanged != null) { WorkspaceLayoutChanged(workspace, oldLayout); } }
private void ShowHideAppBarsAndRepositionBars(AppBarNativeWindow previousAppBarTopWindow, AppBarNativeWindow previousAppBarBottomWindow, AppBarNativeWindow newAppBarTopWindow, AppBarNativeWindow newAppBarBottomWindow, Workspace newWorkspace) { ShowHideAppBarForms(previousAppBarTopWindow, newAppBarTopWindow); ShowHideAppBarForms(previousAppBarBottomWindow, newAppBarBottomWindow); var newBarsAtTop = newWorkspace.barsAtTop[monitorIndex]; var newBarsAtBottom = newWorkspace.barsAtBottom[monitorIndex]; var winPosInfo = NativeMethods.BeginDeferWindowPos(newBarsAtTop.Count + newBarsAtBottom.Count); if (newAppBarTopWindow != null) { winPosInfo = newAppBarTopWindow.PositionBars(winPosInfo, newBarsAtTop); } if (newAppBarBottomWindow != null) { winPosInfo = newAppBarBottomWindow.PositionBars(winPosInfo, newBarsAtBottom); } NativeMethods.EndDeferWindowPos(winPosInfo); }
internal void SwitchToWorkspace(Workspace workspace) { CurrentVisibleWorkspace.Unswitch(); HideBars(workspace, CurrentVisibleWorkspace); // hides or shows the Windows taskbar if (screen.Primary && workspace.ShowWindowsTaskbar != isWindowsTaskbarShown) { ShowHideWindowsTaskbar(workspace.ShowWindowsTaskbar); } ShowHideAppBars(CurrentVisibleWorkspace, workspace); CurrentVisibleWorkspace = workspace; ShowBars(CurrentVisibleWorkspace); workspace.SwitchTo(); }
internal void ShowHideAppBars(Workspace oldWorkspace, Workspace newWorkspace) { var oldWorkspaceTuple = oldWorkspace == null ? null : workspaces[oldWorkspace]; var newWorkspaceTuple = workspaces[newWorkspace]; if (oldWorkspaceTuple == null || newWorkspaceTuple.Item1 != oldWorkspaceTuple.Item1) { ShowHideAppBarsAndRepositionBars( oldWorkspaceTuple == null ? null : oldWorkspaceTuple.Item2, oldWorkspaceTuple == null ? null : oldWorkspaceTuple.Item3, newWorkspaceTuple.Item2, newWorkspaceTuple.Item3, newWorkspace); } }
internal void ShowBars(Workspace workspace) { var newBarsAtTop = workspace.barsAtTop[monitorIndex]; var newBarsAtBottom = workspace.barsAtBottom[monitorIndex]; newBarsAtTop.Concat(newBarsAtBottom).ForEach(b => b.Show()); }
internal void SetStartingWorkspace(Workspace startingWorkspace) { CurrentVisibleWorkspace = startingWorkspace; }
internal void RemoveWorkspace(Workspace workspace) { var workspaceTuple = workspaces[workspace]; workspaces.Remove(workspace); if (workspaceTuple.Item2 != null && workspaces.All(kv => kv.Value.Item2 != workspaceTuple.Item2)) { workspaceTuple.Item2.Destroy(); } if (workspaceTuple.Item3 != null && workspaces.All(kv => kv.Value.Item3 != workspaceTuple.Item3)) { workspaceTuple.Item3.Destroy(); } }
internal void HideBars(Workspace newWorkspace, Workspace oldWorkspace) { var oldBarsAtTop = oldWorkspace.barsAtTop[monitorIndex]; var oldBarsAtBottom = oldWorkspace.barsAtBottom[monitorIndex]; var newBarsAtTop = newWorkspace.barsAtTop[monitorIndex]; var newBarsAtBottom = newWorkspace.barsAtBottom[monitorIndex]; oldBarsAtTop.Concat(oldBarsAtBottom).Except(newBarsAtTop.Concat(newBarsAtBottom)).ForEach(b => b.Hide()); }
private static void DoWorkspaceDeactivated(Workspace workspace) { if (WorkspaceDeactivated != null) { WorkspaceDeactivated(workspace); } }
private static void DoWorkspaceHidden(Workspace workspace) { if (WorkspaceHidden != null) { WorkspaceHidden(workspace); } }
private void WindawesomeOnWindowTitleOrIconChanged(Workspace workspace, Window window, string newText, Bitmap newIcon) { if (window.className == windowClassName) { var oldLeft = label.Left; var oldRight = label.Right; var oldWidth = label.Width; var newWidth = TextRenderer.MeasureText(newText, label.Font).Width; label.Text = newText; label.Width = newWidth; if (oldWidth != newWidth) { this.RepositionControls(oldLeft, oldRight); bar.DoFixedWidthWidgetWidthChanged(this); } } }
private static void DoWorkspaceShown(Workspace workspace) { if (WorkspaceShown != null) { WorkspaceShown(workspace); } }
private void OnWorkspaceDeactivated(Workspace workspace) { writer.WriteLine("Workspace '{0}' deactivated", workspace.id); }
private static void DoWorkspaceWindowRestored(Workspace workspace, Window window) { if (WorkspaceWindowRestored != null) { WorkspaceWindowRestored(workspace, window); } }
private void OnWorkspaceHidden(Workspace workspace) { writer.WriteLine("Workspace '{0}' hidden", workspace.id); }
private void ShowHideWindows(Workspace oldWorkspace, Workspace newWorkspace, bool setForeground) { var winPosInfo = NativeMethods.BeginDeferWindowPos(newWorkspace.GetWindowsCount() + oldWorkspace.GetWindowsCount()); var showWindows = newWorkspace.GetWindows(); foreach (var window in showWindows.Where(Utilities.WindowIsNotHung)) { winPosInfo = window.GetOwnedWindows().Aggregate(winPosInfo, (current, hWnd) => NativeMethods.DeferWindowPos(current, hWnd, IntPtr.Zero, 0, 0, 0, 0, NativeMethods.SWP.SWP_NOACTIVATE | NativeMethods.SWP.SWP_NOMOVE | NativeMethods.SWP.SWP_NOSIZE | NativeMethods.SWP.SWP_NOZORDER | NativeMethods.SWP.SWP_NOOWNERZORDER | NativeMethods.SWP.SWP_SHOWWINDOW)); if (window.redrawOnShow) { window.Redraw(); } } var hideWindows = oldWorkspace.sharedWindowsCount > 0 && newWorkspace.sharedWindowsCount > 0 ? oldWorkspace.GetWindows().Except(showWindows) : oldWorkspace.GetWindows(); // if the window is not visible we shouldn't add it to hiddenApplications as EVENT_OBJECT_HIDE won't be sent foreach (var window in hideWindows.Where(Utilities.IsVisibleAndNotHung)) { hiddenApplications.Add(window.hWnd); winPosInfo = window.GetOwnedWindows().Aggregate(winPosInfo, (current, hWnd) => NativeMethods.DeferWindowPos(current, hWnd, IntPtr.Zero, 0, 0, 0, 0, NativeMethods.SWP.SWP_NOACTIVATE | NativeMethods.SWP.SWP_NOMOVE | NativeMethods.SWP.SWP_NOSIZE | NativeMethods.SWP.SWP_NOZORDER | NativeMethods.SWP.SWP_NOOWNERZORDER | NativeMethods.SWP.SWP_HIDEWINDOW)); } NativeMethods.EndDeferWindowPos(winPosInfo); // activates the topmost non-minimized window if (setForeground) { DoForTopmostWindowForWorkspace(newWorkspace, ForceForegroundWindow); } }
private void OnWorkspaceShown(Workspace workspace) { writer.WriteLine("Workspace '{0}' shown", workspace.id); }
public void MoveWorkspaceToMonitor(Workspace workspace, Monitor newMonitor, bool showOnNewMonitor = true, bool switchTo = true) { var oldMonitor = workspace.Monitor; if (oldMonitor != newMonitor && oldMonitor.Workspaces.Count() > 1) { // unswitch the current workspace if (CurrentWorkspace != workspace && switchTo) { CurrentWorkspace.IsCurrentWorkspace = false; // remove windows from ALT-TAB menu and Taskbar if (CurrentWorkspace.hideFromAltTabWhenOnInactiveWorkspaceCount > 0) { CurrentWorkspace.GetWindows().Where(w => w.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace).ForEach(w => w.ShowInAltTabAndTaskbar(false)); } } // if the workspace to be moved is visible on the old monitor, switch to another one if (oldMonitor.CurrentVisibleWorkspace == workspace) { var oldMonitorNewWorkspace = oldMonitor.Workspaces.First(ws => !ws.IsWorkspaceVisible); ShowHideWindows(workspace, oldMonitorNewWorkspace, false); oldMonitor.SwitchToWorkspace(oldMonitorNewWorkspace); } // remove from old/add to new monitor oldMonitor.RemoveWorkspace(workspace); workspace.Monitor = newMonitor; newMonitor.AddWorkspace(workspace); if (switchTo || showOnNewMonitor) // if the workspace must be switched to, it must be shown too { // switch to the workspace now on the new monitor ShowHideWindows(newMonitor.CurrentVisibleWorkspace, workspace, true); newMonitor.SwitchToWorkspace(workspace); } // switch to the moved workspace if (CurrentWorkspace != workspace && switchTo) { workspace.IsCurrentWorkspace = true; // add windows to ALT-TAB menu and Taskbar if (workspace.hideFromAltTabWhenOnInactiveWorkspaceCount > 0) { workspace.GetWindows().Where(w => w.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace).ForEach(w => w.ShowInAltTabAndTaskbar(true)); } CurrentWorkspace = workspace; } if (CurrentWorkspace == workspace && config.MoveMouseOverMonitorsOnSwitch) { Utilities.MoveMouseToMiddleOf(workspace.Monitor.Bounds); } // reposition the windows on the workspace workspace.Reposition(); Workspace.DoWorkspaceMonitorChanged(workspace, oldMonitor, newMonitor); } }
private void OnWorkspaceWindowMinimized(Workspace workspace, Window window) { writer.WriteLine("MINIMIZED - class '{0}'; caption '{1}'; workspace '{2}'", window.className, window.DisplayName, workspace.id); }
public bool TryGetManagedWindowForWorkspace(IntPtr hWnd, Workspace workspace, out Window window, out LinkedList<Tuple<Workspace, Window>> list) { if (ApplicationsTryGetValue(hWnd, out list)) { var tuple = list.FirstOrDefault(t => t.Item1 == workspace); if (tuple != null) { window = tuple.Item2; return true; } } window = null; return false; }
private void OnWorkspaceWindowRestored(Workspace workspace, Window window) { writer.WriteLine("RESTORED - class '{0}'; caption '{1}'; workspace '{2}'", window.className, window.DisplayName, workspace.id); }
private IntPtr DoForTopmostWindowForWorkspace(Workspace workspace, Action<WindowBase> action) { var window = topmostWindows[workspace.id - 1]; if (window == null || !NativeMethods.IsWindowVisible(window.hWnd) || NativeMethods.IsIconic(window.hWnd) || workspace.GetWindow(window.hWnd) == null) { NativeMethods.EnumWindows((hWnd, _) => { if (!Utilities.IsAppWindow(hWnd) || NativeMethods.IsIconic(hWnd)) { return true; } if ((topmostWindows[workspace.id - 1] = workspace.GetWindow(hWnd)) != null) { // the workspace contains this window so make it the topmost one return false; } if ((Utilities.IsAltTabWindow(hWnd) && !applications.ContainsKey(hWnd)) || workspace.Monitor.temporarilyShownWindows.Contains(hWnd)) { // the window is not a managed-by-another-visible-workspace one so make it the topmost one topmostWindows[workspace.id - 1] = new WindowBase(hWnd); return false; } return true; }, IntPtr.Zero); if (topmostWindows[workspace.id - 1] == null) { topmostWindows[workspace.id - 1] = new WindowBase(NativeMethods.shellWindow); } window = topmostWindows[workspace.id - 1]; } action(window); return window.hWnd; }
internal static void DoWorkspaceMonitorChanged(Workspace workspace, Monitor oldMonitor, Monitor newMonitor) { if (WorkspaceMonitorChanged != null) { WorkspaceMonitorChanged(workspace, oldMonitor, newMonitor); } }