Inheritance: WindowBase
Exemple #1
0
        internal Window(Window window)
            : base(window)
        {
            this.IsFloating = window.IsFloating;
            this.Titlebar = window.Titlebar;
            this.InAltTabAndTaskbar = window.InAltTabAndTaskbar;
            this.WindowBorders = window.WindowBorders;
            this.WorkspacesCount = window.WorkspacesCount;
            this.DisplayName = window.DisplayName;
            className = window.className;
            processName = window.processName;
            is64BitProcess = window.is64BitProcess;
            redrawOnShow = window.redrawOnShow;
            ShowMenu = window.ShowMenu;
            updateIcon = window.updateIcon;
            onHiddenWindowShownAction = window.onHiddenWindowShownAction;
            menu = window.menu;
            this.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace = window.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace;

            this.originalStyle = window.originalStyle;
            this.originalExStyle = window.originalExStyle;

            windowPlacement = window.windowPlacement;
            originalWindowPlacement = window.originalWindowPlacement;

            this.customOwnedWindowMatchingFunction = window.customOwnedWindowMatchingFunction;
            ownedWindows = window.ownedWindows;
        }
 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);
                 }
             }
         }
     }
 }
Exemple #3
0
 void ILayout.WindowMinimized(Window window)
 {
     (this as ILayout).WindowDestroyed(window);
 }
Exemple #4
0
 private static void DoWindowTitleOrIconChanged(Workspace workspace, Window window, string newText, Bitmap newIcon)
 {
     if (WindowTitleOrIconChanged != null)
     {
         WindowTitleOrIconChanged(workspace, window, newText, newIcon);
     }
 }
Exemple #5
0
 public void TemporarilyShowWindowOnCurrentWorkspace(Window window)
 {
     if (!NativeMethods.IsWindowVisible(window.hWnd))
     {
         CurrentWorkspace.Monitor.temporarilyShownWindows.Add(window.hWnd);
         window.ShowAsync();
     }
 }
Exemple #6
0
 private void HideWindow(Window window)
 {
     if (Utilities.IsVisibleAndNotHung(window))
     {
         hiddenApplications.Add(window.hWnd);
         window.GetOwnedWindows().ForEach(hWnd => NativeMethods.ShowWindow(hWnd, NativeMethods.SW.SW_HIDE));
     }
 }
Exemple #7
0
 private void RestoreSharedWindowState(Window window, bool doNotShow)
 {
     // TODO: when a shared window is removed from its next to last workspace,
     // if it was on a full-screen or the last one is on a full-screen layout,
     // it is not repositioned correctly
     window.Initialize();
     if (ShouldSaveAndRestoreSharedWindowsPosition(window))
     {
         window.RestorePosition(doNotShow);
     }
 }
Exemple #8
0
 private void DoWindowBorderToggled(Window window)
 {
     if (WindowBorderToggled != null)
     {
         WindowBorderToggled(window);
     }
 }
Exemple #9
0
 private static void DoWorkspaceWindowOrderChanged(Workspace workspace, Window window, int positions, bool backwards)
 {
     if (WorkspaceWindowOrderChanged != null)
     {
         WorkspaceWindowOrderChanged(workspace, window, positions, backwards);
     }
 }
Exemple #10
0
 public Window GetPreviousWindow(Window window)
 {
     var node = windows.Find(window);
     if (node != null)
     {
         return node.Previous != null ? node.Previous.Value : windows.Last.Value;
     }
     return null;
 }
Exemple #11
0
 public Window GetNextWindow(Window window)
 {
     var node = windows.Find(window);
     if (node != null)
     {
         return node.Next != null ? node.Next.Value : windows.First.Value;
     }
     return null;
 }
 private void OnWorkspaceWindowRestored(Workspace workspace, Window window)
 {
     writer.WriteLine("RESTORED - class '{0}'; caption '{1}'; workspace '{2}'",
         window.className, window.DisplayName, workspace.id);
 }
 private void OnWorkspaceWindowMinimized(Workspace workspace, Window window)
 {
     writer.WriteLine("MINIMIZED - class '{0}'; caption '{1}'; workspace '{2}'",
         window.className, window.DisplayName, workspace.id);
 }
        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);
                }
            }
        }
Exemple #15
0
 void ILayout.WindowRestored(Window window)
 {
     (this as ILayout).WindowCreated(window);
 }
Exemple #16
0
        internal void WindowCreated(Window window)
        {
            windows.AddFirst(window);
            if (window.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace)
            {
                hideFromAltTabWhenOnInactiveWorkspaceCount++;
            }
            if (window.WorkspacesCount > 1)
            {
                sharedWindowsCount++;
            }
            if (IsWorkspaceVisible || window.WorkspacesCount == 1)
            {
                window.Initialize();
            }

            if (!NativeMethods.IsIconic(window.hWnd) && !window.IsFloating)
            {
                Layout.WindowCreated(window);

                hasChanges |= !IsWorkspaceVisible;
            }

            DoWorkspaceWindowAdded(this, window);
        }
Exemple #17
0
        internal void WindowDestroyed(Window window)
        {
            windows.Remove(window);
            if (window.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace)
            {
                hideFromAltTabWhenOnInactiveWorkspaceCount--;
            }
            if (window.WorkspacesCount > 1)
            {
                sharedWindowsCount--;
            }

            if (!NativeMethods.IsIconic(window.hWnd) && !window.IsFloating)
            {
                Layout.WindowDestroyed(window);

                hasChanges |= !IsWorkspaceVisible;
            }

            DoWorkspaceWindowRemoved(this, window);
        }
Exemple #18
0
        public void ShiftWindowBackwards(Window window, int positions = 1)
        {
            if (windows.Count > 1 && windows.First.Value != window)
            {
                var node = windows.Find(window);
                if (node != null)
                {
                    var previousNode = node.Previous;
                    windows.Remove(node);
                    var i = 0;
                    while (++i < positions && previousNode != null)
                    {
                        previousNode = previousNode.Previous;
                    }
                    if (previousNode != null)
                    {
                        windows.AddBefore(previousNode, node);
                    }
                    else
                    {
                        windows.AddFirst(node);
                    }

                    this.Reposition();
                    DoWorkspaceWindowOrderChanged(this, window, i, true);
                }
            }
        }
Exemple #19
0
 private static void DoWorkspaceWindowRestored(Workspace workspace, Window window)
 {
     if (WorkspaceWindowRestored != null)
     {
         WorkspaceWindowRestored(workspace, window);
     }
 }
Exemple #20
0
        public void ShiftWindowForward(Window window, int positions = 1)
        {
            if (windows.Count > 1 && windows.Last.Value != window)
            {
                var node = windows.Find(window);
                if (node != null)
                {
                    var nextNode = node.Next;
                    windows.Remove(node);
                    var i = 0;
                    while (++i < positions && nextNode != null)
                    {
                        nextNode = nextNode.Next;
                    }
                    if (nextNode != null)
                    {
                        windows.AddAfter(nextNode, node);
                    }
                    else
                    {
                        windows.AddLast(node);
                    }

                    this.Reposition();
                    DoWorkspaceWindowOrderChanged(this, window, i, false);
                }
            }
        }
Exemple #21
0
 private void DoWindowTitlebarToggled(Window window)
 {
     if (WindowTitlebarToggled != null)
     {
         WindowTitlebarToggled(window);
     }
 }
Exemple #22
0
        public void ShiftWindowToMainPosition(Window window)
        {
            if (windows.Count > 1 && windows.First.Value != window)
            {
                var node = windows.First;
                var i = 0;
                for ( ; node != null && node.Value != window; node = node.Next, i++)
                {
                }
                if (node != null)
                {
                    windows.Remove(node);
                    windows.AddFirst(node);

                    this.Reposition();
                    DoWorkspaceWindowOrderChanged(this, window, i, true);
                }
            }
        }
Exemple #23
0
 private bool ShouldSaveAndRestoreSharedWindowsPosition(Window window)
 {
     return !NeedsToReposition() || window.IsFloating || Layout.ShouldSaveAndRestoreSharedWindowsPosition();
 }
Exemple #24
0
 internal void RemoveFromSharedWindows(Window window)
 {
     RestoreSharedWindowState(window, !IsWorkspaceVisible);
     sharedWindowsCount--;
 }
Exemple #25
0
        public void AddApplicationToWorkspace(IntPtr hWnd, int toWorkspaceId = 0, int fromWorkspaceId = 0, bool follow = true)
        {
            var oldWorkspace = fromWorkspaceId == 0 ? CurrentWorkspace : config.Workspaces[fromWorkspaceId - 1];
            var newWorkspace = toWorkspaceId == 0 ? CurrentWorkspace : config.Workspaces[toWorkspaceId - 1];

            if (newWorkspace.id != oldWorkspace.id)
            {
                Window window;
                LinkedList<Tuple<Workspace, Window>> list;
                if (TryGetManagedWindowForWorkspace(hWnd, oldWorkspace, out window, out list) &&
                    list.All(t => t.Item1 != newWorkspace))
                {
                    var newWindow = new Window(window);

                    newWorkspace.WindowCreated(newWindow);
                    if (!follow && !oldWorkspace.IsWorkspaceVisible && newWorkspace.IsWorkspaceVisible)
                    {
                        newWindow.ShowAsync();
                    }

                    list.AddFirst(Tuple.Create(newWorkspace, newWindow));
                    list.Where(t => ++t.Item2.WorkspacesCount == 2).ForEach(t => t.Item1.sharedWindowsCount++);

                    FollowWindow(oldWorkspace, newWorkspace, follow, newWindow);
                }
            }
        }
Exemple #26
0
 internal void ToggleShowHideWindowBorder(Window window)
 {
     window.ToggleShowHideWindowBorder();
     DoWindowBorderToggled(window);
 }
Exemple #27
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;
 }
Exemple #28
0
 internal void ToggleShowHideWindowTitlebar(Window window)
 {
     window.ToggleShowHideTitlebar();
     DoWindowTitlebarToggled(window);
 }
Exemple #29
0
        private bool AddWindowToWorkspace(IntPtr hWnd, bool firstTry = true, bool finishedInitializing = true)
        {
            LinkedList<Tuple<Workspace, Window>> workspacesWindowsList;
            if (ApplicationsTryGetValue(hWnd, out workspacesWindowsList))
            {
                return workspacesWindowsList.First.Value.Item2.hWnd != hWnd && workspacesWindowsList.First.Value.Item2.AddToOwnedWindows(hWnd);
            }

            var className = NativeMethods.GetWindowClassName(hWnd);
            var displayName = NativeMethods.GetText(hWnd);
            var style = NativeMethods.GetWindowStyleLongPtr(hWnd);
            var exStyle = NativeMethods.GetWindowExStyleLongPtr(hWnd);
            int processId;
            NativeMethods.GetWindowThreadProcessId(hWnd, out processId);

            using (var process = System.Diagnostics.Process.GetProcessById(processId))
            {
                // TODO: this line could throw an exception (as well as all others which use a Process instance)
                var processName = process.ProcessName;

                var programRule = config.ProgramRules.FirstOrDefault(r => r.IsMatch(hWnd, className, displayName, processName, style, exStyle));
                DoProgramRuleMatched(programRule, hWnd, className, displayName, processName, style, exStyle);
                if (programRule == null || !programRule.isManaged)
                {
                    return false;
                }
                if (programRule.tryAgainAfter >= 0 && firstTry && finishedInitializing)
                {
                    System.Threading.Thread.Sleep(programRule.tryAgainAfter);
                    return Utilities.IsAppWindow(hWnd) && AddWindowToWorkspace(hWnd, false);
                }

                IEnumerable<ProgramRule.Rule> matchingRules = programRule.rules;
                var workspacesCount = programRule.rules.Length;
                var hasWorkspaceZeroRule = matchingRules.Any(r => r.workspace == 0);
                var hasCurrentWorkspaceRule = matchingRules.Any(r => r.workspace == CurrentWorkspace.id);
                // matchingRules.workspaces could be { 0, 1 } and you could be at workspace 1.
                // Then, "hWnd" would be added twice if it were not for this check
                // TODO: it could be added twice on two different workspaces which are shown at the same time
                if (hasWorkspaceZeroRule && hasCurrentWorkspaceRule)
                {
                    matchingRules = matchingRules.Where(r => r.workspace != 0);
                    workspacesCount--;
                }

                if (finishedInitializing)
                {
                    if (!hasWorkspaceZeroRule && !hasCurrentWorkspaceRule)
                    {
                        var hasVisibleWorkspaceRule = matchingRules.Any(r => config.Workspaces[r.workspace - 1].IsWorkspaceVisible);
                        switch (programRule.onWindowCreatedAction)
                        {
                            case OnWindowCreatedOrShownAction.TemporarilyShowWindowOnCurrentWorkspace:
                                if (!hasVisibleWorkspaceRule)
                                {
                                    CurrentWorkspace.Monitor.temporarilyShownWindows.Add(hWnd);
                                    OnWindowCreatedOnCurrentWorkspace(hWnd, programRule);
                                }
                                break;
                            case OnWindowCreatedOrShownAction.HideWindow:
                                if (!hasVisibleWorkspaceRule)
                                {
                                    hiddenApplications.Add(hWnd);
                                    NativeMethods.ShowWindow(hWnd, NativeMethods.SW.SW_HIDE);
                                }
                                if (NativeMethods.GetForegroundWindow() == hWnd)
                                {
                                    DoForTopmostWindowForWorkspace(CurrentWorkspace, ActivateWindow);
                                }
                                break;
                        }
                    }

                    if (programRule.windowCreatedDelay == -1)
                    {
                        try
                        {
                            process.WaitForInputIdle(10000);
                        }
                        catch (InvalidOperationException)
                        {
                        }
                        catch (System.ComponentModel.Win32Exception)
                        {
                        }
                    }
                    else if (programRule.windowCreatedDelay > 0)
                    {
                        System.Threading.Thread.Sleep(programRule.windowCreatedDelay);
                    }
                }

                if (programRule.redrawDesktopOnWindowCreated)
                {
                    // If you have a Windows Explorer window open on one workspace (and it is the only non-minimized window open) and you start
                    // mintty (which defaults to another workspace) then the desktop is not redrawn right (you can see that if mintty
                    // is set to be transparent
                    // On Windows XP SP3
                    NativeMethods.RedrawWindow(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero,
                        NativeMethods.RDW.RDW_ALLCHILDREN | NativeMethods.RDW.RDW_ERASE | NativeMethods.RDW.RDW_INVALIDATE);
                }

                var list = new LinkedList<Tuple<Workspace, Window>>();
                applications[hWnd] = list;

                var menu = NativeMethods.GetMenu(hWnd);
                var is64BitProcess = NativeMethods.Is64BitProcess(hWnd);

                var isMinimized = NativeMethods.IsIconic(hWnd);

                foreach (var rule in matchingRules)
                {
                    var window = new Window(hWnd, className, displayName, processName, workspacesCount,
                        is64BitProcess, style, exStyle, rule, programRule, menu);

                    var workspace = rule.workspace == 0 ? CurrentWorkspace : config.Workspaces[rule.workspace - 1];
                    list.AddLast(Tuple.Create(workspace, window));

                    workspace.WindowCreated(window);

                    if (!workspace.IsCurrentWorkspace && !isMinimized)
                    {
                        if (hasWorkspaceZeroRule || hasCurrentWorkspaceRule ||
                            list.Count > 1 ||
                            programRule.onWindowCreatedAction == OnWindowCreatedOrShownAction.HideWindow ||
                            programRule.onWindowCreatedAction == OnWindowCreatedOrShownAction.TemporarilyShowWindowOnCurrentWorkspace)
                        {
                            // this workspace is not going to be switched to because of this window addition
                            switch (programRule.onWindowCreatedOnInactiveWorkspaceAction)
                            {
                                case OnWindowCreatedOnWorkspaceAction.MoveToTop:
                                    topmostWindows[workspace.id - 1] = window;
                                    break;
                            }
                        }
                    }
                }

                if (!programRule.showMenu)
                {
                    list.First.Value.Item2.ShowHideWindowMenu();
                }

                if (finishedInitializing)
                {
                    if (!hasWorkspaceZeroRule && !hasCurrentWorkspaceRule)
                    {
                        switch (programRule.onWindowCreatedAction)
                        {
                            case OnWindowCreatedOrShownAction.SwitchToWindowsWorkspace:
                                SwitchToWorkspace(list.First.Value.Item1.id, false);
                                OnWindowCreatedOnCurrentWorkspace(hWnd, programRule);
                                break;
                            case OnWindowCreatedOrShownAction.MoveWindowToCurrentWorkspace:
                                ChangeApplicationToWorkspace(hWnd, CurrentWorkspace.id, matchingRules.First().workspace);
                                OnWindowCreatedOnCurrentWorkspace(hWnd, programRule);
                                break;
                        }
                    }
                    else
                    {
                        OnWindowCreatedOnCurrentWorkspace(hWnd, programRule);
                    }
                }
            }

            return true;
        }
Exemple #30
0
 internal void ToggleWindowFloating(Window window)
 {
     window.IsFloating = !window.IsFloating;
     if (!NativeMethods.IsIconic(window.hWnd))
     {
         if (window.IsFloating)
         {
             Layout.WindowDestroyed(window);
         }
         else
         {
             Layout.WindowCreated(window);
         }
     }
 }