Example #1
0
        internal void ShowBars(Workspace workspace)
        {
            var newBarsAtTop = workspace.barsAtTop[monitorIndex];
            var newBarsAtBottom = workspace.barsAtBottom[monitorIndex];

            newBarsAtTop.Concat(newBarsAtBottom).ForEach(b => b.Show());
        }
Example #2
0
 private static void DoWorkspaceLayoutChanged(Workspace workspace, ILayout oldLayout)
 {
     if (WorkspaceLayoutChanged != null)
     {
         WorkspaceLayoutChanged(workspace, oldLayout);
     }
 }
Example #3
0
 private static void DoWorkspaceWindowOrderChanged(Workspace workspace, Window window, int positions, bool backwards)
 {
     if (WorkspaceWindowOrderChanged != null)
     {
         WorkspaceWindowOrderChanged(workspace, window, positions, backwards);
     }
 }
Example #4
0
 private void SetWorkspaceLabelColor(Workspace workspace)
 {
     var workspaceLabel = workspaceLabels[workspace.id - 1];
     if (workspace.IsCurrentWorkspace)
     {
         workspaceLabel.BackColor = highlightedBackgroundColor;
         workspaceLabel.ForeColor = highlightedForegroundColor;
     }
     else if (workspace.IsWorkspaceVisible)
     {
         workspaceLabel.BackColor = highlightedInactiveBackgroundColor;
         workspaceLabel.ForeColor = highlightedInactiveForegroundColor;
     }
     else
     {
         var count = workspace.GetWindowsCount();
         if (count > 9)
         {
             count = 9;
         }
         workspaceLabel.BackColor = normalBackgroundColor[count];
         workspaceLabel.ForeColor = normalForegroundColor[count];
     }
 }
Example #5
0
 private static void DoWorkspaceDeactivated(Workspace workspace)
 {
     if (WorkspaceDeactivated != null)
     {
         WorkspaceDeactivated(workspace);
     }
 }
Example #6
0
        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;
        }
Example #7
0
 void ILayout.Initialize(Workspace workspace)
 {
     this.workspace = workspace;
 }
Example #8
0
 private void OnWorkspaceHidden(Workspace workspace)
 {
     writer.WriteLine("Workspace '{0}' hidden", workspace.id);
 }
Example #9
0
 private void OnWorkspaceShown(Workspace workspace)
 {
     writer.WriteLine("Workspace '{0}' shown", workspace.id);
 }
Example #10
0
 private void OnWorkspaceLayoutChanged(Workspace workspace)
 {
     if (workspace.Monitor == bar.Monitor && workspace.IsWorkspaceVisible)
     {
         var oldLeft = layoutLabel.Left;
         var oldRight = layoutLabel.Right;
         var oldWidth = layoutLabel.Width;
         layoutLabel.Text = workspace.Layout.LayoutSymbol();
         layoutLabel.Width = TextRenderer.MeasureText(layoutLabel.Text, layoutLabel.Font).Width;
         if (layoutLabel.Width != oldWidth)
         {
             this.RepositionControls(oldLeft, oldRight);
             bar.DoFixedWidthWidgetWidthChanged(this);
         }
     }
 }
Example #11
0
 private void OnWorkspaceDeactivated(Workspace workspace)
 {
     writer.WriteLine("Workspace '{0}' deactivated", workspace.id);
 }
Example #12
0
        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);
        }
Example #13
0
        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();
        }
Example #14
0
        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);
            }
        }
Example #15
0
        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;
        }
Example #16
0
 private void OnWorkspaceWindowMinimized(Workspace workspace, Window window)
 {
     writer.WriteLine("MINIMIZED - class '{0}'; caption '{1}'; workspace '{2}'",
         window.className, window.DisplayName, workspace.id);
 }
Example #17
0
 private static void DoWindowTitleOrIconChanged(Workspace workspace, Window window, string newText, Bitmap newIcon)
 {
     if (WindowTitleOrIconChanged != null)
     {
         WindowTitleOrIconChanged(workspace, window, newText, newIcon);
     }
 }
Example #18
0
 private void OnWorkspaceWindowRestored(Workspace workspace, Window window)
 {
     writer.WriteLine("RESTORED - class '{0}'; caption '{1}'; workspace '{2}'",
         window.className, window.DisplayName, workspace.id);
 }
Example #19
0
        private void DawsomeOnWindowTitleOrIconChanged(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);
                }
            }
        }
Example #20
0
 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);
     }
 }
Example #21
0
 private void OnWorkspaceChangedFromTo(Workspace workspace)
 {
     SetWorkspaceLabelColor(workspace);
 }
Example #22
0
        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);
            }
        }
Example #23
0
 internal static void DoWorkspaceMonitorChanged(Workspace workspace, Monitor oldMonitor, Monitor newMonitor)
 {
     if (WorkspaceMonitorChanged != null)
     {
         WorkspaceMonitorChanged(workspace, oldMonitor, newMonitor);
     }
 }
Example #24
0
        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);
        }
Example #25
0
 private static void DoWorkspaceHidden(Workspace workspace)
 {
     if (WorkspaceHidden != null)
     {
         WorkspaceHidden(workspace);
     }
 }
Example #26
0
        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);
            }
        }
Example #27
0
 private static void DoWorkspaceShown(Workspace workspace)
 {
     if (WorkspaceShown != null)
     {
         WorkspaceShown(workspace);
     }
 }
Example #28
0
        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));
            }
        }
Example #29
0
 private static void DoWorkspaceWindowRestored(Workspace workspace, Window window)
 {
     if (WorkspaceWindowRestored != null)
     {
         WorkspaceWindowRestored(workspace, window);
     }
 }
Example #30
0
 internal void SetStartingWorkspace(Workspace startingWorkspace)
 {
     CurrentVisibleWorkspace = startingWorkspace;
 }