示例#1
0
        public void WriteDiagnosticOnTextFile()
        {
            string diagnosticFilePath = Util.ExePath + "diagnostic.txt";

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("DesktopSbS diagnostic");
            sb.AppendLine($"Date: {DateTime.Now}");
            sb.AppendLine();

            sb.AppendLine("Options");
            sb.AppendLine("------------------------------------");
            sb.AppendLine($"ScreenWidth: {DesktopSbS.Options.ScreenWidth}");
            sb.AppendLine($"ScreenHeight: {DesktopSbS.Options.ScreenHeight}");
            sb.AppendLine($"ScreenScale: {DesktopSbS.Options.ScreenScale}");
            sb.AppendLine($"TaskBarHeight: {DesktopSbS.Options.TaskBarHeight}");
            sb.AppendLine($"HideAboutOnStartup: {DesktopSbS.Options.HideAboutOnStartup}");
            sb.AppendLine($"ModeSbS: {DesktopSbS.Options.ModeSbS}");
            sb.AppendLine($"ParallaxEffect: {DesktopSbS.Options.ParallaxEffect}");
            sb.AppendLine($"ExcludedApplications: {DesktopSbS.Options.ExcludedApplications}");

            User32.EnumWindows(windowFound, 0);

            sb.AppendLine();
            sb.AppendLine("Windows to display");
            sb.AppendLine("------------------------------------");
            for (int i = this.windowsToDisplay.Count - 1; i >= 0; --i)
            {
                WinSbS win = this.windowsToDisplay[i];
                sb.AppendLine($"{win.Title}, handle: {win.Handle}, {win.SourceRect}, ws: {win.WinStyle}, wsEx: {win.WinStyleEx}");
            }

            sb.AppendLine();
            sb.AppendLine("Windows rejected");
            sb.AppendLine("------------------------------------");
            for (int i = this.windowsRejected.Count - 1; i >= 0; --i)
            {
                WinSbS win = this.windowsRejected[i];
                sb.AppendLine($"{win.Title}, handle: {win.Handle}, {win.SourceRect}, ws: {win.WinStyle}, wsEx: {win.WinStyleEx}");
            }

            try
            {
                File.WriteAllText(diagnosticFilePath, sb.ToString());
                Process.Start(diagnosticFilePath);
            }
            catch (Exception e)
            {
                MessageBox.Show(sb.ToString(), "Unable to save diagnostic file");
            }
        }
示例#2
0
        private bool windowFound(IntPtr hwnd, int lParam)
        {
            StringBuilder sb = new StringBuilder(100);

            User32.GetWindowText(hwnd, sb, sb.Capacity);
            string title = sb.ToString();

            // don't consider our own windows
            if (title == "ThumbWindows")
            {
                return(true);
            }

            WS   winStyle   = (WS)User32.GetWindowLongA(hwnd, User32.GWL_STYLE);
            WSEX winStyleEx = (WSEX)User32.GetWindowLongA(hwnd, User32.GWL_EXSTYLE);

            RECT sourceRect = new RECT();


            User32.GetWindowRect(hwnd, ref sourceRect);

            WinSbS win = new WinSbS(hwnd);

            win.SourceRect = sourceRect;
            win.Title      = title;
            win.WinStyle   = winStyle;
            win.WinStyleEx = winStyleEx;

            int cloaked = 0;

            DwmApi.DwmGetWindowAttribute(hwnd, DwmApi.DwmWindowAttribute.DWMWA_CLOAKED, out cloaked, sizeof(int));

            if (cloaked == 0 &&
                !sourceRect.IsEmpty() &&
                (winStyle & WS.WS_VISIBLE) == WS.WS_VISIBLE &&
                (winStyle & WS.WS_ICONIC) == 0 &&
                (winStyle & WS.WS_DISABLED) == 0)
            {
                this.windowsToDisplay.Add(win);
            }
            else
            {
                this.windowsRejected.Add(win);
            }

            return(true); //continue enumeration
        }
示例#3
0
        private void updateWindows()
        {
            this.tmpWindows = new List <WinSbS>();


            if (this.Is3DActive)
            {
                User32.EnumWindows(windowFound, 0);
            }

            int updateAllIndex = -1;

            int offsetLevel = 0;

            WinSbS taskBarWindow = null;

            WinSbS tmpWindow = this.tmpWindows.FirstOrDefault(w => w.SourceRect.IsMaximized());

            try
            {
                if (tmpWindow != null &&
                    Options.ExcludedApplications.Contains(Path.GetFileName(User32.GetFilePath(tmpWindow.Handle))))
                {
                    this.tmpWindows.Clear();
                }
            }
            catch (Exception e)
            {
            }


            for (int i = this.tmpWindows.Count - 1; i >= 0; --i)
            {
                tmpWindow = this.tmpWindows[i];

                if (i < this.tmpWindows.Count - 1)
                {
                    tmpWindow.Owner = this.tmpWindows[i + 1];
                }
                else
                {
                    tmpWindow.Owner = null;
                }


                if (tmpWindow.SourceRect.Left <= 0 && tmpWindow.SourceRect.Right >= Options.ScreenWidth)
                {
                    offsetLevel = 0;
                }
                else
                {
                    offsetLevel++;
                }
                tmpWindow.OffsetLevel = offsetLevel;

                int oldIndex = this.windows.FindIndex(w => w.Handle == tmpWindow.Handle);
                if (oldIndex < 0)
                {
                    tmpWindow.RegisterThumbs();
                }
                else
                {
                    tmpWindow.CopyThumbInstances(this.windows[oldIndex]);

                    if (updateAllIndex < 0 && this.windows[oldIndex].Owner?.Handle != tmpWindow.Owner?.Handle)
                    {
                        updateAllIndex = i;
                    }
                    else if (!this.windows[oldIndex].SourceRect.Equals(tmpWindow.SourceRect))
                    {
                        tmpWindow.UpdateThumbs();
                    }
                    this.windows.RemoveAt(oldIndex);
                }

                if (tmpWindow.SourceRect.Left <= 0 &&
                    tmpWindow.SourceRect.Right >= Options.ScreenWidth &&
                    tmpWindow.SourceRect.Bottom - tmpWindow.SourceRect.Top == Options.TaskBarHeight)
                {
                    taskBarWindow = tmpWindow;
                }
            }
            for (int i = 0; i < this.windows.Count; ++i)
            {
                this.windows[i].UnRegisterThumbs();
            }

            this.windows = this.tmpWindows;

            if (this.hasToUpdate)
            {
                updateAllIndex   = this.windows.Count - 1;
                this.hasToUpdate = false;
            }

            if (updateAllIndex > -1)
            {
                for (int i = updateAllIndex; i >= 0; --i)
                {
                    if (this.windows[i] != taskBarWindow)
                    {
                        this.windows[i].UpdateThumbs();
                    }
                }
            }

            taskBarWindow?.UpdateThumbs(true);
            this.cursorSbS.UpdateThumbs((this.windows.Any() ? this.windows.Max(w => w.OffsetLevel) : 0) + 1);
        }
示例#4
0
        public void WriteDiagnosticOnTextFile()
        {
            string diagnosticFilePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\{DesktopSbS.App.APP_NAME}.Diagnostic.txt";

            StringBuilder sb = new StringBuilder();

            Process proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = $"{Util.ExePath}{DesktopSbS.App.APP_NAME}.exe",
                    Arguments              = "/read-settings",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true
                }
            };

            sb.AppendLine($"{DesktopSbS.App.APP_NAME} diagnostic v{DesktopSbS.App.VERSION}");
            sb.AppendLine($"Windows version: {Util.GetWindowsVersion()}");
            sb.AppendLine($"Date: {DateTime.Now}");
            sb.AppendLine();

            sb.AppendLine("Options");
            sb.AppendLine("------------------------------------");
            proc.Start();
            while (!proc.StandardOutput.EndOfStream)
            {
                string setting = proc.StandardOutput.ReadLine();
                if (!string.IsNullOrEmpty(setting))
                {
                    sb.AppendLine(setting);
                }
            }

            User32.EnumWindows(windowFound, 0);

            sb.AppendLine();
            sb.AppendLine("Windows to display");
            sb.AppendLine("------------------------------------");
            for (int i = this.windowsToDisplay.Count - 1; i >= 0; --i)
            {
                WinSbS win = this.windowsToDisplay[i];
                sb.AppendLine($"{win.Title}, handle: {win.Handle}, {win.SourceRect}, ws: {win.WinStyle}, wsEx: {win.WinStyleEx}");
            }

            sb.AppendLine();
            sb.AppendLine("Windows rejected");
            sb.AppendLine("------------------------------------");
            for (int i = this.windowsRejected.Count - 1; i >= 0; --i)
            {
                WinSbS win = this.windowsRejected[i];
                sb.AppendLine($"{win.Title}, handle: {win.Handle}, {win.SourceRect}, ws: {win.WinStyle}, wsEx: {win.WinStyleEx}");
            }

            try
            {
                File.WriteAllText(diagnosticFilePath, sb.ToString());
                Process.Start(diagnosticFilePath);
            }
            catch (Exception e)
            {
                MessageBox.Show($"{e} : {sb}", "Unable to save diagnostic file");
            }
        }
        private void updateWindows()
        {
            this.tmpWindows = new List <WinSbS>();

            if (this.Is3DActive)
            {
                User32.EnumWindows(windowFound, 0);
            }

            int updateAllIndex = -1;

            int offsetLevel = 0;

            WinSbS taskBarWindow = null;

            WinSbS tmpWindow = this.tmpWindows.FirstOrDefault(w => w.SourceRect.IsMaximized());

            try
            {
                if (tmpWindow != null &&
                    Options.ExcludedApplications?.Contains(Path.GetFileName(User32.GetFilePath(tmpWindow.Handle))) == true)
                {
                    this.tmpWindows.Clear();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"{e}");
            }


            for (int i = this.tmpWindows.Count - 1; i >= 0; --i)
            {
                tmpWindow = this.tmpWindows[i];

                if (i < this.tmpWindows.Count - 1)
                {
                    tmpWindow.Owner = this.tmpWindows[i + 1];
                }
                else
                {
                    tmpWindow.Owner = null;
                }


                if (tmpWindow.SourceRect.Left <= Options.AreaSrcBounds.Left && tmpWindow.SourceRect.Right >= Options.AreaSrcBounds.Right)
                {
                    offsetLevel = 0;
                }
                else
                {
                    offsetLevel++;
                }
                tmpWindow.OffsetLevel = offsetLevel;

                int oldIndex = this.windows.FindIndex(w => w.Handle == tmpWindow.Handle);
                if (oldIndex < 0)
                {
                    App.Current.Dispatcher.Invoke(tmpWindow.RegisterThumbs);
                }
                else
                {
                    tmpWindow.CopyThumbInstances(this.windows[oldIndex]);

                    if (updateAllIndex < 0 && this.windows[oldIndex].Owner?.Handle != tmpWindow.Owner?.Handle)
                    {
                        updateAllIndex = i;
                    }
                    else if (!this.windows[oldIndex].SourceRect.Equals(tmpWindow.SourceRect))
                    {
                        tmpWindow.UpdateThumbs();
                    }
                    this.windows.RemoveAt(oldIndex);
                }

                if (tmpWindow.SourceRect.Left <= Options.ScreenSrcBounds.Left &&
                    tmpWindow.SourceRect.Right >= Options.ScreenSrcBounds.Right &&
                    tmpWindow.SourceRect.Bottom - tmpWindow.SourceRect.Top == Options.ScreenSrcBounds.Height - Options.ScreenSrcWorkspace.Height)
                {
                    taskBarWindow = tmpWindow;
                }
            }
            for (int i = 0; i < this.windows.Count; ++i)
            {
                App.Current.Dispatcher.Invoke(this.windows[i].UnRegisterThumbs);
            }

            this.windows = this.tmpWindows;

            if (this.isAboutOpened)
            {
                return;
            }


            if (this.hasToUpdate)
            {
                Options.ComputedVariables.UpdateVariables();
                updateAllIndex   = this.windows.Count - 1;
                this.hasToUpdate = false;
            }

            if (updateAllIndex > -1)
            {
                for (int i = updateAllIndex; i >= 0; --i)
                {
                    if (this.windows[i] != taskBarWindow)
                    {
                        this.windows[i].UpdateThumbs();
                    }
                }
            }

            taskBarWindow?.UpdateThumbs(true);
            this.cursorSbS.UpdateThumbs((this.windows.Any() ? this.windows.Max(w => w.OffsetLevel) : 0) + 1);
        }