Пример #1
0
        private static void SwapDesktops(VirtualDesktop source, VirtualDesktop target)
        {
            var srcWindows = new List <IntPtr>();
            var dstWindows = new List <IntPtr>();

            foreach (var window in GetAllWindows())
            {
                var desktop = VirtualDesktop.FromHwnd(window);
                if (desktop == source)
                {
                    srcWindows.Add(window);
                }
                else if (desktop == target)
                {
                    dstWindows.Add(window);
                }
            }

            foreach (var window in srcWindows)
            {
                VirtualDesktopHelper.MoveToDesktop(window, target);
            }
            foreach (var window in dstWindows)
            {
                VirtualDesktopHelper.MoveToDesktop(window, source);
            }

            // Swap the names as well
            int sourceNumber = DesktopHelper.GetNumber(source);
            int targetNumber = DesktopHelper.GetNumber(target);
            var sourceName   = SettingsHelper.GetDesktopName(sourceNumber);
            var targetName   = SettingsHelper.GetDesktopName(targetNumber);

            SettingsHelper.SetDesktopName(sourceNumber, targetName);
            SettingsHelper.SetDesktopName(targetNumber, sourceName);
        }