/// <summary>
        /// Initializes the virtual desktop manager.
        /// </summary>
        /// <param name="num">The number of desktops the user wants
        /// to initialize</param>
        public static void InitDesktops(int num)
        {
            //Initialize settings
            if (num < 1)
                num = 1;
            if (DesktopNames == null)
            {
                DesktopNames = new StringCollection();
                for (int i = 0; i < num; i++)
                    DesktopNames.Add("Desktop" + (i + 1).ToString());
            }
            if (StickyPrograms == null)
            {
                StickyPrograms = new StringCollection();
                StickyPrograms.Add("sidebar");
                StickyPrograms.Add("taskmgr");
            }
            if (MinimizePrograms == null)
            {
                MinimizePrograms = new StringCollection();
            }

            //Only use select monitors
            StringCollection useMonStrs = new StringCollection();
            useMonStrs.AddRange(UseMonitors.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries));
            if (useMons == null)
                useMons = new int[4];
            else
                useMons = new int[useMons.Count()];

            for (int i = 0; i <= useMonStrs.Count - 1; i++)
            {
                useMons[i] = int.Parse(useMonStrs[i]);
            }

            //Add desktops
            for (int i = 0; i <= num - 1; i++)
            {
                _desktops.Add(new VirtualDesktop());
                if (DesktopNames.Count > i)
                {
                    _desktops[i].Name = DesktopNames[i];
                }
                else
                {
                    _desktops[i].Name = "Desktop" + " " + (i + 1).ToString();
                }
            }
            _currentDesktop = _desktops[0];
            _currentDesktop.ShowWindows(false);
            initDone = true;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Switches to a virtual desktop
 /// </summary>
 /// <param name="desktop">The virtual desktop to which the manager has to switch</param>
 private void SwitchToVirtualDesktop(VirtualDesktop desktop)
 {
     try
     {
         VirtualDesktopManager.CurrentDesktop = desktop;
     }
     catch
     {
         VirtualDesktopManager.UninitDesktops();
     }
 }