Example #1
0
 internal static void Initialize()
 {
     VirtualDesktopManager         = Utils.CreateInstance <IVirtualDesktopManager>(CLSID.VirtualDesktopManager);
     VirtualDesktopManagerInternal = VirtualDesktopManagerInternal.GetInstance();
     VirtualDesktopPinnedApps      = Utils.FromShell <IVirtualDesktopPinnedApps>(CLSID.VirtualDesktopPinnedApps);
     ApplicationViewCollection     = Utils.FromShell <IApplicationViewCollection>();
 }
        public WindowsShellAdapter(IConfigurationFactory factory)
        {
            _factory = factory;

            try
            {
                _desktop = CreateInstance <IDesktopWallpaper>(CLSID.DesktopWallpaper);

                _manager = CreateInstance <IVirtualDesktopManager>(CLSID.VirtualDesktopManager);

                var shell = CreateInstance <uIServiceProvider>(CLSID.ImmersiveShell);

                object managerResult;
                shell.QueryService(
                    IID.VirtualDesktopAPIUnknown,
                    typeof(IVirtualDesktopManagerInternal).GUID,
                    out managerResult);

                _managerInternal = (IVirtualDesktopManagerInternal)managerResult;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Example #3
0
        static DesktopManager()
        {
            var shell = (IServiceProvider10)Activator.CreateInstance(Type.GetTypeFromCLSID(Guids.CLSID_ImmersiveShell));

            VirtualDesktopManagerInternal = (IVirtualDesktopManagerInternal)shell.QueryService(Guids.CLSID_VirtualDesktopManagerInternal, typeof(IVirtualDesktopManagerInternal).GUID);
            VirtualDesktopManager         = (IVirtualDesktopManager)Activator.CreateInstance(Type.GetTypeFromCLSID(Guids.CLSID_VirtualDesktopManager));
            ApplicationViewCollection     = (IApplicationViewCollection)shell.QueryService(typeof(IApplicationViewCollection).GUID, typeof(IApplicationViewCollection).GUID);
            VirtualDesktopPinnedApps      = (IVirtualDesktopPinnedApps)shell.QueryService(Guids.CLSID_VirtualDesktopPinnedApps, typeof(IVirtualDesktopPinnedApps).GUID);
        }
Example #4
0
        public static void InitializeVdmInterface()
        {
            Type vdmType = Type.GetTypeFromCLSID(new Guid("aa509086-5ca9-4c25-8f95-589d3c07b48a"));

            s_manager = (IVirtualDesktopManager)Activator.CreateInstance(vdmType);

            Type             spType          = Type.GetTypeFromCLSID(new Guid("c2f03a33-21f5-47fa-b4bb-156362a2f239"));
            IServiceProvider serviceProvider = (IServiceProvider)Activator.CreateInstance(spType);

            serviceProvider.QueryService(new Guid("a501fdec-4a09-464c-ae4e-1b9c21b84918"), typeof(IVirtualDesktopNotificationService).GUID, out object ppvObject);
            s_notificationService = (IVirtualDesktopNotificationService)ppvObject;

            IsInitialized = s_manager is not null;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VirtualDesktopHelper"/> class.
        /// </summary>
        /// <param name="desktopListUpdate">Setting to configure if the list of available desktops should update automatically or only when calling <see cref="UpdateDesktopList"/>. Per default this is set to manual update (false) to have less registry queries.</param>
        public VirtualDesktopHelper(bool desktopListUpdate = false)
        {
            try
            {
                _virtualDesktopManager = (IVirtualDesktopManager) new CVirtualDesktopManager();
            }
            catch (COMException ex)
            {
                Log.Exception("Initialization of <VirtualDesktopHelper> failed: An exception was thrown when creating the instance of COM interface <IVirtualDesktopManager>.", ex, typeof(VirtualDesktopHelper));
                return;
            }

            _desktopListAutoUpdate = desktopListUpdate;
            UpdateDesktopList();
        }
Example #6
0
        public MainForm(Option option)
        {
            this.Option            = option;
            _VirtualDesktopManager = VirtualDesktopManager.CreateInstance();
            _GetCurrentDesktop     = VirtualDesktopManagerInternal._GetCurrentDesktopGetter();

            this.ControlAdded += MainForm_ControlAdded;
            InitializeComponent();
            ResetCounter();

            if (!string.IsNullOrEmpty(AppSettings.Debug.TimerInterval))
            {
                timer1.Interval = int.Parse(AppSettings.Debug.TimerInterval);
            }
        }
Example #7
0
        public SoftwareTool(ICommandManager commandManager, IKeyboard keyboard, IConfig <Config> config,
                            IShell shell,
                            IVirtualDesktopManager virtualDesktopManager, IWindowManager windowManager,
                            IContextVariable contextVariable)
        {
            _shell = shell;
            _virtualDesktopManager = virtualDesktopManager;
            _windowManager         = windowManager;
            _contextVariable       = contextVariable;

            var folders = config.CurrentValue.ConfigFolders;

            foreach (var folder in folders)
            {
                loadConfigInFolder(folder);
            }

            RegisterCommands();
        }
 public VirtualDesktopManager()
 {
     try {
         // NOTE: the code below will throw an COMException on the OSes older than Windows 10
         cmanager = new CVirtualDesktopManager();
         manager  = (IVirtualDesktopManager)cmanager;
     }
     catch (COMException) {
         manager  = null;
         cmanager = null;
     }
 }
Example #9
0
 public VirtualDesktopManager()
 {
     cmanager = new CVirtualDesktopManager();
     manager = (IVirtualDesktopManager)cmanager;
 }
Example #10
0
        public Software(IShell shell, INotify notify, IWindowManager windowManager, IVirtualDesktopManager virtualDesktopManager, IFileExplorer fileExplorer, IConfig <Config> config)
        {
            RegisterCommands();
            var software = config.CurrentValue.SoftwarePackage;
            var hotKeys  = software.Hotkeys;
            var swPaths  = software.SoftwarePaths;

            hotKeys.DoublePinyinSwitch.OnEvent(e =>
            {
                e.Handled              = true;
                const string keyName   = @"HKEY_CURRENT_USER\Software\Microsoft\InputMethod\Settings\CHS";
                const string valueName = "Enable Double Pinyin";
                var k = (int)Registry.GetValue(keyName, valueName, -1);
                if (k == 0 || k == -1)
                {
                    notify.ShowMessage("Double Pinyin Enabled");
                    Registry.SetValue(keyName, valueName, 1);
                }
                else if (k == 1)
                {
                    notify.ShowMessage("Full Pinyin Enabled");
                    Registry.SetValue(keyName, valueName, 0);
                }
            });

            //hotKeys.Find.OnEvent(async e =>
            //{
            //    e.Handled = true;
            //    var shiftDown = e.KeyboardState.IsDown(Shift);

            //    var c = windowManager.CurrentWindow.Class;
            //    var arg = shiftDown
            //        ? "-newwindow"
            //        : "-toggle-window";

            //    if ("CabinetWClass" == c)
            //    {
            //        var path = await fileExplorer.CurrentDirectory(windowManager.CurrentWindow.Handle);
            //        shell.RunWithCmd(shell.NormalizeCmd(swPaths.Everything, arg, "-path",
            //            path));
            //        return;
            //    }

            //    shell.RunWithCmd(shell.NormalizeCmd(swPaths.Everything, arg));
            //});

            //hotKeys.OpenTerminal.OnEvent(async e =>
            //{
            //    e.Handled = true;
            //    var    shiftDown = e.KeyboardState.IsDown(Shift);
            //    string path;
            //    var    c = windowManager.CurrentWindow.Class;
            //    if ("CabinetWClass" != c)
            //        path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            //    else
            //        path = await fileExplorer.CurrentDirectory(windowManager.CurrentWindow.Handle);
            //    // https://github.com/nt4f04uNd/wt-contextmenu
            //    if (shiftDown) shell.RunWithCmd(swPaths.Terminal, true); // powershell -Command "Start-Process shell:appsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App -Verb RunAs"
            //    else shell.RunWithExplorer(swPaths.Terminal);
            //});

            // hotKeys.OpenCodeEditor.OnEvent(async e =>
            // {
            //     e.Handled = true;
            //     if (!windowManager.CurrentWindow.IsExplorerOrOpenSaveDialog)
            //     {
            //         shell.RunWithExplorer(swPaths.Code);
            //         return;
            //     }
            //
            //     var paths = await fileExplorer.GetSelectedPaths(windowManager.CurrentWindow.Handle);
            //
            //     if (paths.Length == 0)
            //     {
            //         var path = await fileExplorer.Path(windowManager.CurrentWindow.Handle);
            //         shell.RunWithCmd(shell.NormalizeCmd(swPaths.Code, path));
            //         return;
            //     }
            //
            //     foreach (var path in paths)
            //     {
            //         shell.RunWithCmd(shell.NormalizeCmd(swPaths.Code, path));
            //     }
            // });

            //hotKeys.WebSearch.OnEvent(async e =>
            //{
            //    e.Handled = true;

            //    var altDown = e.KeyboardState.IsDown(Keys.Menu);
            //    var url = altDown
            //        ? swPaths.SearchEngineSecondary
            //        : swPaths.SearchEngine;

            //    var defaultPath = Browser.DefaultPath;
            //    var exeName     = Path.GetFileNameWithoutExtension(defaultPath);
            //    var process     = await virtualDesktopManager.GetFirstProcessOnCurrentVirtualDesktop(exeName);
            //    if (process == null)
            //    {
            //        shell.RunAsNormalUser(defaultPath, url, "--new-window", "--new-instance");
            //        return;
            //    }

            //    new Process
            //    {
            //        StartInfo =
            //        {
            //            UseShellExecute = true,
            //            FileName        = url
            //        }
            //    }.Start();
            //});
            // hotKeys.StartTaskExplorer.WithAliases(software.KeyAliases).OnEvent(e =>
            // {
            //     e.Handled = true;
            //     shell.RunWithCmd(swPaths.ProcessExplorer);
            // });
            //
            // hotKeys.OpenScreenRuler.WithAliases(software.KeyAliases).OnEvent(e =>
            // {
            //     e.Handled = true;
            //     shell.RunWithCmd(swPaths.Ruler);
            // });

            //hotKeys.OpenScreenRuler.WithAliases(software.KeyAliases).OnEvent(async e =>
            //{
            //    var exeName = "Inspect";

            //    var processes = await
            //        virtualDesktopManager.GetProcessesOnCurrentVirtualDesktop(exeName);

            //    var process = processes.FirstOrDefault();

            //    var hWnd = process?.MainWindowHandle;

            //    if (hWnd != null)
            //    {
            //        windowManager.Show(hWnd.Value);
            //        return;
            //    }

            //    shell.RunWithExplorer(swPaths.Inspect);
            //});

            //hotKeys.StartNotepad.WithAliases(software.KeyAliases).OnEvent(async e =>
            //{
            //    e.Handled = true;
            //    var exeName = "Notepad";

            //    var notePads = await
            //        virtualDesktopManager.GetProcessesOnCurrentVirtualDesktop(exeName,
            //            p => p.MainWindowTitle == "Untitled - Notepad");

            //    var notePad = notePads.FirstOrDefault();

            //    var hWnd = notePad?.MainWindowHandle;

            //    if (hWnd != null)
            //    {
            //        windowManager.Show(hWnd.Value);
            //        return;
            //    }

            //    shell.RunWithCmd("Notepad");
            //});

            hotKeys.StartVisualStudio.WithAliases(software.KeyAliases).OnEvent(async e =>
            {
                if (!windowManager.CurrentWindow.IsExplorerOrOpenSaveDialog)
                {
                    return;
                }

                e.Handled = true;

                var path = await fileExplorer.CurrentDirectory(windowManager.CurrentWindow.Handle);
                if (string.IsNullOrEmpty(path))
                {
                    shell.RunWithExplorer(swPaths.VisualStudio);
                    return;
                }

                Directory.CreateDirectory(path).EnumerateFiles("*.sln").Select(f => f.FullName).AsParallel().ForAll(s =>
                {
                    Process.Start(new ProcessStartInfo(swPaths.VisualStudio)
                    {
                        UseShellExecute = true, Arguments = s, WorkingDirectory = path
                    });
                });
            });

            // hotKeys.StartGifRecord.WithAliases(software.KeyAliases).OnEvent(e =>
            // {
            //     e.Handled = true;
            //     shell.RunWithCmd(swPaths.GifTool);
            // });

            hotKeys.ToggleDictionary.MapOnAllUp(Shift + LAlt + D);
        }
Example #11
0
 static DesktopManager()
 {
     var shell = (IServiceProvider10)Activator.CreateInstance(Type.GetTypeFromCLSID(Guids.CLSID_ImmersiveShell));
     Manager = (IVirtualDesktopManagerInternal)shell.QueryService(Guids.CLSID_VirtualDesktopManagerInternal, Guids.IID_IVirtualDesktopManagerInternal);
     WManager = (IVirtualDesktopManager)Activator.CreateInstance(Type.GetTypeFromCLSID(Guids.CLSID_VirtualDesktopManager));
 }