Esempio n. 1
0
        private static IDisposable ShowRenameWindow()
        {
            var current = VirtualDesktop.Current;
            int number  = DesktopHelper.GetNumber(current);

            var source = new CancellationTokenSource();

            var vmodel = new RenameWindowViewModel
            {
                Number = number,
            };
            var window = new RenameWindow(MonitorService.GetCurrentArea().WorkArea)
            {
                DataContext = vmodel,
            };

            window.Show();

            Task.Delay(TimeSpan.FromMilliseconds(30000), source.Token)
            .ContinueWith(_ => window.Close(), TaskScheduler.FromCurrentSynchronizationContext());

            return(Disposable.Create(() => source.Cancel()));
        }
Esempio n. 2
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);
        }