Repository: newlooper/VirtualSpace Branch: main Commit: 237d97eee27b Files: 313 Total size: 2.4 MB Directory structure: gitextract_c1e7rff4/ ├── .gitignore ├── Bridge/ │ ├── Agent.cs │ ├── Behavior.cs │ ├── Bridge.csproj │ ├── COPYING │ ├── Channels.cs │ ├── Interfaces/ │ │ ├── IAppController.cs │ │ └── IDesktop.cs │ ├── Resources/ │ │ ├── Images/ │ │ │ ├── Images.Designer.cs │ │ │ └── Images.resx │ │ └── Langs/ │ │ ├── WinFormStrings.Designer.cs │ │ ├── WinFormStrings.resx │ │ ├── WinFormStrings.zh-Hans.Designer.cs │ │ └── WinFormStrings.zh-Hans.resx │ ├── VirtualDesktopNotification.cs │ └── Window.cs ├── COPYING ├── Configuration/ │ ├── COPYING │ ├── ConfigTemplate.cs │ ├── Configuration.csproj │ ├── Const.cs │ ├── Converter/ │ │ └── EntityConverter.cs │ ├── DataAnnotations/ │ │ └── PropertyProtectorAttribute.cs │ ├── Entity/ │ │ ├── Cluster.cs │ │ ├── Colour.cs │ │ ├── KeyBinding.cs │ │ ├── LogConfig.cs │ │ ├── Margin.cs │ │ ├── Mouse.cs │ │ ├── Navigation.cs │ │ └── UserInterface.cs │ ├── Events/ │ │ ├── Entity/ │ │ │ ├── ExpressionTemplate.cs │ │ │ └── RuleTemplate.cs │ │ └── Expression/ │ │ ├── Conditions.cs │ │ └── Conditions.test.cs │ ├── FodyWeavers.xml │ ├── Manager.cs │ ├── Profile.cs │ └── Profiles/ │ └── Default.cs ├── Helpers/ │ ├── COPYING │ ├── DwmApi.cs │ ├── GlobalHotKey.cs │ ├── Helpers.csproj │ ├── Images.cs │ ├── Kernel32.cs │ ├── LowLevelHooks.cs │ ├── StringHelper.cs │ ├── SysInfo.cs │ ├── TaskSchedulerHelper.cs │ ├── User32.cs │ ├── UserMessage.cs │ ├── VisualEffects.cs │ ├── Win32.cs │ ├── WinForms.cs │ ├── WinMsg.cs │ └── WinRegistry.cs ├── Ipc/ │ ├── Commons/ │ │ ├── Config.cs │ │ ├── HostInfo.cs │ │ ├── Ipc.csproj │ │ ├── PipeMessage.cs │ │ └── PipeMessageType.cs │ ├── IpcClient/ │ │ ├── IpcClient.csproj │ │ └── IpcPipeClient.cs │ └── IpcServer/ │ ├── IpcPipeServer.cs │ └── IpcServer.csproj ├── LinqExpressionBuilder/ │ ├── COPYING │ ├── Keywords.cs │ ├── LinqExpressionBuilder.cs │ └── LinqExpressionBuilder.csproj ├── Logger/ │ ├── COPYING │ ├── LogMessage.cs │ ├── Logger.cs │ ├── Logger.csproj │ └── Manager.cs ├── Plugin/ │ ├── Commons/ │ │ ├── Plugin.csproj │ │ ├── PluginInfo.cs │ │ ├── PluginManager.cs │ │ └── WinApi.cs │ └── PluginHost/ │ ├── PluginConst.cs │ ├── PluginHost.cs │ └── PluginHost.csproj ├── Plugins.sln/ │ ├── .gitignore │ ├── COPYING │ ├── Cube3D/ │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── AssemblyInfo.cs │ │ ├── AutoVersion.tt │ │ ├── COPYING │ │ ├── Config/ │ │ │ ├── Const.cs │ │ │ ├── Settings.cs │ │ │ └── SettingsManager.cs │ │ ├── Cube3D.csproj │ │ ├── D3DImages/ │ │ │ └── D3DImages.cs │ │ ├── Effects/ │ │ │ ├── Cube.cs │ │ │ ├── Effect.cs │ │ │ ├── Fade.cs │ │ │ ├── Flip.cs │ │ │ ├── InsideCube.cs │ │ │ ├── Reveal.cs │ │ │ └── Slide.cs │ │ ├── FrameToD3DImage.cs │ │ ├── Helpers/ │ │ │ ├── User32.cs │ │ │ ├── Win32.cs │ │ │ ├── WinMsg.cs │ │ │ └── WpfConverters.cs │ │ ├── MainWindow.2D.cs │ │ ├── MainWindow.3D.cs │ │ ├── MainWindow.animation.cs │ │ ├── MainWindow.frame.cs │ │ ├── MainWindow.hotkeys.cs │ │ ├── MainWindow.xaml │ │ ├── MainWindow.xaml.cs │ │ ├── SettingsWindow.xaml │ │ ├── SettingsWindow.xaml.cs │ │ ├── app.manifest │ │ ├── plugin.json │ │ └── settings.json │ ├── Plugins.sln │ ├── ScreenCapture/ │ │ ├── COPYING │ │ ├── CaptureHelper.cs │ │ ├── D3D9ShareCapture.cs │ │ ├── Direct3D11Helper.cs │ │ ├── FrameProcessor.cs │ │ ├── MonitorEnumerationHelper.cs │ │ ├── ScreenCapture.csproj │ │ └── WindowEnumerationHelper.cs │ └── Updater/ │ ├── AutoVersion.tt │ ├── COPYING │ ├── Config/ │ │ └── Const.cs │ ├── HttpClientProgress.cs │ ├── MainForm.Designer.cs │ ├── MainForm.cs │ ├── MainForm.resx │ ├── Program.cs │ ├── Resources/ │ │ └── Langs/ │ │ ├── WinFormStrings.resx │ │ └── WinFormStrings.zh-Hans.resx │ ├── Updater.csproj │ └── plugin.json ├── Readme.md ├── Resources/ │ ├── COPYING │ ├── Images.Designer.cs │ ├── Images.resx │ └── Resources.csproj ├── UiAutomation/ │ ├── COPYING │ ├── UIA.cs │ └── UiAutomation.csproj ├── VirtualDesktop/ │ ├── VirtualDesktop10/ │ │ ├── COM.cs │ │ ├── VirtualDesktop.cs │ │ ├── VirtualDesktop10.csproj │ │ └── VirtualDesktopManager.cs │ ├── VirtualDesktop11/ │ │ ├── COM.cs │ │ ├── VirtualDesktop.cs │ │ ├── VirtualDesktop11.csproj │ │ └── VirtualDesktopManager.cs │ ├── VirtualDesktop11_21H2/ │ │ ├── COM.cs │ │ ├── VirtualDesktop.cs │ │ ├── VirtualDesktop11_21H2.csproj │ │ └── VirtualDesktopManager.cs │ ├── VirtualDesktop11_23H2/ │ │ ├── COM.cs │ │ ├── VirtualDesktop.cs │ │ ├── VirtualDesktop11_23H2.csproj │ │ └── VirtualDesktopManager.cs │ ├── VirtualDesktop11_23H2_3085/ │ │ ├── COM.cs │ │ ├── VirtualDesktop.cs │ │ ├── VirtualDesktop11_23H2_3085.csproj │ │ └── VirtualDesktopManager.cs │ └── VirtualDesktop11_24H2/ │ ├── COM.cs │ ├── VirtualDesktop.cs │ ├── VirtualDesktop11_24H2.csproj │ └── VirtualDesktopManager.cs ├── VirtualDesktopWrapper/ │ ├── DesktopManagerWrapper.cs │ ├── DesktopManagerWrapper.events.cs │ ├── DesktopManagerWrapper.wallpaper.cs │ ├── DesktopWrapper.cs │ ├── VirtualDesktopWrapper.csproj │ └── Wrapper11.cs ├── VirtualSpace/ │ ├── App.xaml │ ├── App.xaml.cs │ ├── AssemblyInfo.cs │ ├── AutoVersion.tt │ ├── COPYING │ ├── Factory/ │ │ └── AppControllerFactory.cs │ ├── MainWindow.filter.cs │ ├── MainWindow.hotkeys.cs │ ├── MainWindow.layout.cs │ ├── MainWindow.main.cs │ ├── MainWindow.message.cs │ ├── MainWindow.style.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Program.cs │ ├── Tools/ │ │ ├── SystemTool.cs │ │ ├── TrayIcon.cs │ │ └── WindowTool.cs │ ├── VirtualDesktop/ │ │ ├── Daemon.cs │ │ ├── DragWindow.Designer.cs │ │ ├── DragWindow.cs │ │ ├── DragWindow.resx │ │ ├── Filters.cs │ │ ├── Manager.arrangement.cs │ │ ├── Manager.cs │ │ ├── Manager.events.cs │ │ ├── Manager.layout.cs │ │ ├── Menus.cs │ │ ├── Navigation.cs │ │ ├── VirtualDesktopWindow.Designer.cs │ │ ├── VirtualDesktopWindow.Mouse.cs │ │ ├── VirtualDesktopWindow.Thumbs.cs │ │ ├── VirtualDesktopWindow.cs │ │ ├── VirtualDesktopWindow.resx │ │ └── VisibleWindow.cs │ ├── VirtualSpace.csproj │ ├── WindowFilter.xaml │ ├── WindowFilter.xaml.cs │ └── app.manifest ├── VirtualSpace.sln ├── WPF/ │ └── ControlPanel/ │ ├── App.xaml │ ├── App.xaml.cs │ ├── AssemblyInfo.cs │ ├── COPYING │ ├── ControlPanel.csproj │ ├── ControlPanel.xaml │ ├── Converters/ │ │ ├── CheckBoxConverter.cs │ │ ├── CheckBoxStateByIndexConverter.cs │ │ ├── DrawerStateMutexConverter.cs │ │ ├── LocConverter.cs │ │ ├── MouseActionConverter.cs │ │ ├── RuleFieldConverter.cs │ │ ├── RuleFieldFromControlNameConverter.cs │ │ ├── RuleFormDefaultValueConverter.cs │ │ ├── RuleHeaderByStateConverter.cs │ │ ├── ThemeConverter.cs │ │ ├── UIButtonStyleByVdAConverter.cs │ │ └── WidthHeightConverter.cs │ ├── ExportResourceDictionary.cs │ ├── ExportResourceDictionary.xaml │ ├── Factories/ │ │ ├── NavBarItem.cs │ │ └── PageFactory.cs │ ├── FodyWeavers.xml │ ├── MainWindow.logs.cs │ ├── MainWindow.theme.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Pages/ │ │ ├── Control.keyboard.cs │ │ ├── Control.mouse.cs │ │ ├── Control.tree.cs │ │ ├── Control.xaml │ │ ├── Control.xaml.cs │ │ ├── Dialogs/ │ │ │ ├── ProfileNameDialog.xaml │ │ │ ├── ProfileNameDialog.xaml.cs │ │ │ ├── YesNoWithNote.xaml │ │ │ └── YesNoWithNote.xaml.cs │ │ ├── General.xaml │ │ ├── General.xaml.cs │ │ ├── Help.xaml │ │ ├── Help.xaml.cs │ │ ├── Logs.xaml │ │ ├── Logs.xaml.cs │ │ ├── Menus/ │ │ │ ├── Commons/ │ │ │ │ ├── MenuContainer.xaml │ │ │ │ └── MenuContainer.xaml.cs │ │ │ ├── LogsMenu.xaml │ │ │ └── LogsMenu.xaml.cs │ │ ├── Plugins.xaml │ │ ├── Plugins.xaml.cs │ │ ├── Rules.ue.cs │ │ ├── Rules.xaml │ │ ├── Rules.xaml.cs │ │ ├── Settings.xaml │ │ ├── Settings.xaml.cs │ │ ├── UI.xaml │ │ ├── UI.xaml.cs │ │ └── UserControls/ │ │ ├── RuleForm.xaml │ │ └── RuleForm.xaml.cs │ ├── Resources/ │ │ ├── Definitions/ │ │ │ ├── KeyboardTree.json │ │ │ └── MouseTree.json │ │ ├── Langs.Designer.cs │ │ ├── Langs.resx │ │ └── Langs.zh-Hans.resx │ ├── RuleEditorWindow.xaml │ ├── RuleEditorWindow.xaml.cs │ ├── Validation/ │ │ ├── Helper.cs │ │ ├── NotEmptyValidationRule.cs │ │ └── NumberRangeValidationRule.cs │ └── ViewModels/ │ ├── ControlViewModel.cs │ ├── FullObservableCollection.cs │ ├── GeneralViewModel.cs │ ├── LogsViewModel.cs │ ├── MenuContainerViewModel.cs │ ├── PluginsViewModel.cs │ ├── RulesViewModel.cs │ ├── SettingsViewModel.cs │ ├── UIViewModel.cs │ └── ViewModelBase.cs └── WinForms/ └── AppController/ ├── AppController.Designer.cs ├── AppController.DesktopArrangement.cs ├── AppController.cluster.cs ├── AppController.cs ├── AppController.csproj ├── AppController.keyboard.cs ├── AppController.lang.cs ├── AppController.logs.cs ├── AppController.mouse.cs ├── AppController.nav.cs ├── AppController.plugins.cs ├── AppController.profile.cs ├── AppController.resx ├── AppController.rules.cs ├── AppController.ui.cs ├── AppController.zh-Hans.resx ├── RuleForm.Designer.cs ├── RuleForm.cs ├── RuleForm.resx └── RuleForm.zh-Hans.resx ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.rsuser *.suo *.user *.userosscache *.sln.docstates # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs # Mono auto generated files mono_crash.* # Build results [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ x64/ x86/ [Ww][Ii][Nn]32/ [Aa][Rr][Mm]/ [Aa][Rr][Mm]64/ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ [Ll]ogs/ # Visual Studio 2015/2017 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot #wwwroot/ # Visual Studio 2017 auto generated files Generated\ Files/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* # NUnit *.VisualState.xml TestResult.xml nunit-*.xml # Build Results of an ATL Project [Dd]ebugPS/ [Rr]eleasePS/ dlldata.c # Benchmark Results BenchmarkDotNet.Artifacts/ # .NET Core project.lock.json project.fragment.lock.json artifacts/ # ASP.NET Scaffolding ScaffoldingReadMe.txt # StyleCop StyleCopReport.xml # Files built by Visual Studio *_i.c *_p.c *_h.h *.ilk *.meta *.obj *.iobj *.pch *.pdb *.ipdb *.pgc *.pgd *.rsp *.sbr *.tlb *.tli *.tlh *.tmp *.tmp_proj *_wpftmp.csproj *.log *.tlog *.vspscc *.vssscc .builds *.pidb *.svclog *.scc # Chutzpah Test files _Chutzpah* # Visual C++ cache files ipch/ *.aps *.ncb *.opendb *.opensdf *.sdf *.cachefile *.VC.db *.VC.VC.opendb # Visual Studio profiler *.psess *.vsp *.vspx *.sap # Visual Studio Trace Files *.e2e # TFS 2012 Local Workspace $tf/ # Guidance Automation Toolkit *.gpState # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user # TeamCity is a build add-in _TeamCity* # DotCover is a Code Coverage Tool *.dotCover # AxoCover is a Code Coverage Tool .axoCover/* !.axoCover/settings.json # Coverlet is a free, cross platform Code Coverage Tool coverage*.json coverage*.xml coverage*.info # Visual Studio code coverage results *.coverage *.coveragexml # NCrunch _NCrunch_* .*crunch*.local.xml nCrunchTemp_* # MightyMoose *.mm.* AutoTest.Net/ # Web workbench (sass) .sass-cache/ # Installshield output folder [Ee]xpress/ # DocProject is a documentation generator add-in DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC DocProject/Help/*.hhc DocProject/Help/*.hhk DocProject/Help/*.hhp DocProject/Help/Html2 DocProject/Help/html # Click-Once directory publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml # Note: Comment the next line if you want to checkin your web deploy settings, # but database connection strings (with potential passwords) will be unencrypted *.pubxml *.publishproj # Microsoft Azure Web App publish settings. Comment the next line if you want to # checkin your Azure Web App publish settings, but sensitive information contained # in these scripts will be unencrypted PublishScripts/ # NuGet Packages *.nupkg # NuGet Symbol Packages *.snupkg # The packages folder can be ignored because of Package Restore **/[Pp]ackages/* # except build/, which is used as an MSBuild target. !**/[Pp]ackages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/[Pp]ackages/repositories.config # NuGet v3's project.json files produces more ignorable files *.nuget.props *.nuget.targets # Nuget personal access tokens and Credentials # nuget.config # Microsoft Azure Build Output csx/ *.build.csdef # Microsoft Azure Emulator ecf/ rcf/ # Windows Store app package directories and files AppPackages/ BundleArtifacts/ Package.StoreAssociation.xml _pkginfo.txt *.appx *.appxbundle *.appxupload # Visual Studio cache files # files ending in .cache can be ignored *.[Cc]ache # but keep track of directories ending in .cache !?*.[Cc]ache/ # Others ClientBin/ ~$* *~ *.dbmdl *.dbproj.schemaview *.jfm *.pfx *.publishsettings orleans.codegen.cs # Including strong name files can present a security risk # (https://github.com/github/gitignore/pull/2483#issue-259490424) #*.snk # Since there are multiple workflows, uncomment next line to ignore bower_components # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) #bower_components/ # RIA/Silverlight projects Generated_Code/ # Backup & report files from converting an old project file # to a newer Visual Studio version. Backup files are not needed, # because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm ServiceFabricBackup/ *.rptproj.bak # SQL Server files *.mdf *.ldf *.ndf # Business Intelligence projects *.rdl.data *.bim.layout *.bim_*.settings *.rptproj.rsuser *- [Bb]ackup.rdl *- [Bb]ackup ([0-9]).rdl *- [Bb]ackup ([0-9][0-9]).rdl # Microsoft Fakes FakesAssemblies/ # GhostDoc plugin setting file *.GhostDoc.xml # Node.js Tools for Visual Studio .ntvs_analysis.dat node_modules/ # Visual Studio 6 build log *.plg # Visual Studio 6 workspace options file *.opt # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) *.vbw # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts **/*.DesktopClient/ModelManifest.xml **/*.Server/GeneratedArtifacts **/*.Server/ModelManifest.xml _Pvt_Extensions # Paket dependency manager .paket/paket.exe paket-files/ # FAKE - F# Make .fake/ # CodeRush personal settings .cr/personal # Python Tools for Visual Studio (PTVS) __pycache__/ *.pyc # Cake - Uncomment if you are using it # tools/** # !tools/packages.config # Tabs Studio *.tss # Telerik's JustMock configuration file *.jmconfig # BizTalk build output *.btp.cs *.btm.cs *.odx.cs *.xsd.cs # OpenCover UI analysis results OpenCover/ # Azure Stream Analytics local run output ASALocalRun/ # MSBuild Binary and Structured Log *.binlog # NVidia Nsight GPU debugger configuration file *.nvuser # MFractors (Xamarin productivity tool) working folder .mfractor/ # Local History for Visual Studio .localhistory/ # BeatPulse healthcheck temp database healthchecksdb # Backup folder for Package Reference Convert tool in Visual Studio 2017 MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ # Fody - auto-generated XML schema FodyWeavers.xsd # VS Code files for those working on multiple tools .vscode/* !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json *.code-workspace # Local History for Visual Studio Code .history/ # Windows Installer files from build outputs *.cab *.msi *.msix *.msm *.msp # JetBrains Rider .idea/ *.sln.iml AutoVersion.cs ================================================ FILE: Bridge/Agent.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System.Collections.Generic; using System.Reflection; using System.Resources; namespace VirtualSpace { public static class Agent { public static readonly Dictionary ValidLangs = new() { {"en", "English"}, {"zh-Hans", "中文(简体)"} }; public static ResourceManager Langs = new( Assembly.GetExecutingAssembly().GetName().Name + ".Resources.Langs.WinFormStrings", typeof( Agent ).Assembly ); public static ResourceManager Images = new( Assembly.GetExecutingAssembly().GetName().Name + ".Resources.Images.Images", typeof( Agent ).Assembly ); } } ================================================ FILE: Bridge/Behavior.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; namespace VirtualSpace.Config.Events.Entity { public class Behavior { public IntPtr Handle; public string RuleName; public string WindowTitle; public int MoveToDesktop { get; set; } = -1; public bool FollowWindow { get; set; } = true; public bool PinWindow { get; set; } public bool PinApp { get; set; } public int MoveToScreen { get; set; } = -1; public bool HideFromView { get; set; } public Behavior Clone() { return new Behavior { Handle = Handle, RuleName = RuleName, WindowTitle = WindowTitle, MoveToDesktop = MoveToDesktop, FollowWindow = FollowWindow, PinWindow = PinWindow, PinApp = PinApp, MoveToScreen = MoveToScreen, HideFromView = HideFromView }; } } } ================================================ FILE: Bridge/Bridge.csproj ================================================ net6.0-windows enable 9 WinFormStrings.resx True True WinFormStrings.zh-Hans.resx True True True True Images.resx WinFormStrings.Designer.cs ResXFileCodeGenerator WinFormStrings.zh-Hans.Designer.cs ResXFileCodeGenerator ResXFileCodeGenerator Images.Designer.cs ================================================ FILE: Bridge/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Bridge/Channels.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System.Threading.Channels; using VirtualSpace.Config.Events.Entity; namespace VirtualSpace.Commons { public static class Channels { public static readonly Channel ActionChannel = Channel.CreateUnbounded(); public static readonly Channel VisibleWindowsChannel = Channel.CreateUnbounded(); public static readonly Channel VirtualDesktopNotifications = Channel.CreateUnbounded(); } } ================================================ FILE: Bridge/Interfaces/IAppController.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; namespace VirtualSpace { public interface IAppController { public void BringToTop(); public void SetMainWindowHandle( IntPtr handle ); public void Quit(); public void RenderDesktopArrangementButtons( string selectedDa ); public void CreateRuleFromWindowHandle( IntPtr handle ); } } ================================================ FILE: Bridge/Interfaces/IDesktop.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . namespace VirtualSpace { public interface IDesktop { public void MakeVisible(); } } ================================================ FILE: Bridge/Resources/Images/Images.Designer.cs ================================================ //------------------------------------------------------------------------------ // // 此代码由工具生成。 // 运行时版本:4.0.30319.42000 // // 对此文件的更改可能会导致不正确的行为,并且如果 // 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ namespace Bridge.Resources.Images { using System; /// /// 一个强类型的资源类,用于查找本地化的字符串等。 /// // 此类是由 StronglyTypedResourceBuilder // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // (以 /str 作为命令选项),或重新生成 VS 项目。 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Images { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Images() { } /// /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Bridge.Resources.Images.Images", typeof(Images).Assembly); resourceMan = temp; } return resourceMan; } } /// /// 重写当前线程的 CurrentUICulture 属性,对 /// 使用此强类型资源类的所有资源查找执行重写。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] AboutLogo_2 { get { object obj = ResourceManager.GetObject("AboutLogo_2", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big0Black { get { object obj = ResourceManager.GetObject("Big0Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big0White { get { object obj = ResourceManager.GetObject("Big0White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big1Black { get { object obj = ResourceManager.GetObject("Big1Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big1White { get { object obj = ResourceManager.GetObject("Big1White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big2Black { get { object obj = ResourceManager.GetObject("Big2Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big2White { get { object obj = ResourceManager.GetObject("Big2White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big3Black { get { object obj = ResourceManager.GetObject("Big3Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big3White { get { object obj = ResourceManager.GetObject("Big3White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big4Black { get { object obj = ResourceManager.GetObject("Big4Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big4White { get { object obj = ResourceManager.GetObject("Big4White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big5Black { get { object obj = ResourceManager.GetObject("Big5Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big5White { get { object obj = ResourceManager.GetObject("Big5White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big6Black { get { object obj = ResourceManager.GetObject("Big6Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big6White { get { object obj = ResourceManager.GetObject("Big6White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big7Black { get { object obj = ResourceManager.GetObject("Big7Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big7White { get { object obj = ResourceManager.GetObject("Big7White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big8Black { get { object obj = ResourceManager.GetObject("Big8Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big8White { get { object obj = ResourceManager.GetObject("Big8White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big9Black { get { object obj = ResourceManager.GetObject("Big9Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Big9White { get { object obj = ResourceManager.GetObject("Big9White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small0Black { get { object obj = ResourceManager.GetObject("Small0Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small0White { get { object obj = ResourceManager.GetObject("Small0White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small1Black { get { object obj = ResourceManager.GetObject("Small1Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small1White { get { object obj = ResourceManager.GetObject("Small1White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small2Black { get { object obj = ResourceManager.GetObject("Small2Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small2White { get { object obj = ResourceManager.GetObject("Small2White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small3Black { get { object obj = ResourceManager.GetObject("Small3Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small3White { get { object obj = ResourceManager.GetObject("Small3White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small4Black { get { object obj = ResourceManager.GetObject("Small4Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small4White { get { object obj = ResourceManager.GetObject("Small4White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small5Black { get { object obj = ResourceManager.GetObject("Small5Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small5White { get { object obj = ResourceManager.GetObject("Small5White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small6Black { get { object obj = ResourceManager.GetObject("Small6Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small6White { get { object obj = ResourceManager.GetObject("Small6White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small7Black { get { object obj = ResourceManager.GetObject("Small7Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small7White { get { object obj = ResourceManager.GetObject("Small7White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small8Black { get { object obj = ResourceManager.GetObject("Small8Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small8White { get { object obj = ResourceManager.GetObject("Small8White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small9Black { get { object obj = ResourceManager.GetObject("Small9Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] Small9White { get { object obj = ResourceManager.GetObject("Small9White", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] TrayIcon { get { object obj = ResourceManager.GetObject("TrayIcon", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] TrayIconBack_Black { get { object obj = ResourceManager.GetObject("TrayIconBack_Black", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] TrayIconBack_Default { get { object obj = ResourceManager.GetObject("TrayIconBack_Default", resourceCulture); return ((byte[])(obj)); } } /// /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] TrayIconBack_White { get { object obj = ResourceManager.GetObject("TrayIconBack_White", resourceCulture); return ((byte[])(obj)); } } } } ================================================ FILE: Bridge/Resources/Images/Images.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\aboutlogo_2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big0black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big0white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big1black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big1white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big2black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big2white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big3black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big3white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big4black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big4white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big5black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big5white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big6black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big6white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big7black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big7white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big8black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big8white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big9black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\big9white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small0black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small0white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small1black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small1white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small2black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small2white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small3black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small3white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small4black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small4white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small5black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small5white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small6black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small6white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small7black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small7white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small8black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small8white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small9black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\small9white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\trayicon.ico;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\trayiconback_black.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\trayiconback_default.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\trayiconback_white.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: Bridge/Resources/Langs/WinFormStrings.Designer.cs ================================================ //------------------------------------------------------------------------------ // // 此代码由工具生成。 // 运行时版本:4.0.30319.42000 // // 对此文件的更改可能会导致不正确的行为,并且如果 // 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ namespace Bridge.Resources.Langs { using System; /// /// 一个强类型的资源类,用于查找本地化的字符串等。 /// // 此类是由 StronglyTypedResourceBuilder // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // (以 /str 作为命令选项),或重新生成 VS 项目。 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class WinFormStrings { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal WinFormStrings() { } /// /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Bridge.Resources.Langs.WinFormStrings", typeof(WinFormStrings).Assembly); resourceMan = temp; } return resourceMan; } } /// /// 重写当前线程的 CurrentUICulture 属性,对 /// 使用此强类型资源类的所有资源查找执行重写。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } /// /// 查找类似 Current Desktop: 的本地化字符串。 /// internal static string Cluster_Notification_SVD_Current { get { return ResourceManager.GetString("Cluster.Notification.SVD.Current", resourceCulture); } } /// /// 查找类似 Last Desktop: 的本地化字符串。 /// internal static string Cluster_Notification_SVD_Last { get { return ResourceManager.GetString("Cluster.Notification.SVD.Last", resourceCulture); } } /// /// 查找类似 Window 【{0}】 match rule 【{1}】, but error occur when moving. ///possible reason: ///- window invalid. ///- target desktop not exists. ///- target desktop invalid. 的本地化字符串。 /// internal static string Error_MoveWindowToDesktop { get { return ResourceManager.GetString("Error.MoveWindowToDesktop", resourceCulture); } } /// /// 查找类似 Error! 的本地化字符串。 /// internal static string Error_Title { get { return ResourceManager.GetString("Error.Title", resourceCulture); } } /// /// 查找类似 Cannot access task with your current permissions level. ///You need to run this application 'as administrator' even if you are using an administrator account. 的本地化字符串。 /// internal static string General_RunOnStartup_Error_Permission { get { return ResourceManager.GetString("General.RunOnStartup.Error.Permission", resourceCulture); } } /// /// 查找类似 Down 的本地化字符串。 /// internal static string hk_node_nav_down { get { return ResourceManager.GetString("hk_node_nav_down", resourceCulture); } } /// /// 查找类似 Left 的本地化字符串。 /// internal static string hk_node_nav_left { get { return ResourceManager.GetString("hk_node_nav_left", resourceCulture); } } /// /// 查找类似 Right 的本地化字符串。 /// internal static string hk_node_nav_right { get { return ResourceManager.GetString("hk_node_nav_right", resourceCulture); } } /// /// 查找类似 Up 的本地化字符串。 /// internal static string hk_node_nav_up { get { return ResourceManager.GetString("hk_node_nav_up", resourceCulture); } } /// /// 查找类似 Open AppController 的本地化字符串。 /// internal static string hk_node_open_app_controller { get { return ResourceManager.GetString("hk_node_open_app_controller", resourceCulture); } } /// /// 查找类似 Rise MainView 的本地化字符串。 /// internal static string hk_node_rise_mainview { get { return ResourceManager.GetString("hk_node_rise_mainview", resourceCulture); } } /// /// 查找类似 Rise MainView For Active App 的本地化字符串。 /// internal static string hk_node_rise_mainview_for_active_app { get { return ResourceManager.GetString("hk_node_rise_mainview_for_active_app", resourceCulture); } } /// /// 查找类似 Rise MainView For Active App In Current Desktop 的本地化字符串。 /// internal static string hk_node_rise_mainview_for_active_app_in_current_vd { get { return ResourceManager.GetString("hk_node_rise_mainview_for_active_app_in_current_vd", resourceCulture); } } /// /// 查找类似 Rise MainView For Current Desktop 的本地化字符串。 /// internal static string hk_node_rise_mainview_for_current_vd { get { return ResourceManager.GetString("hk_node_rise_mainview_for_current_vd", resourceCulture); } } /// /// 查找类似 Toggle Window Filter 的本地化字符串。 /// internal static string hk_node_toggle_window_filter { get { return ResourceManager.GetString("hk_node_toggle_window_filter", resourceCulture); } } /// /// 查找类似 Desktop 的本地化字符串。 /// internal static string K_D { get { return ResourceManager.GetString("K_D", resourceCulture); } } /// /// 查找类似 Navigation 的本地化字符串。 /// internal static string K_D_N { get { return ResourceManager.GetString("K_D_N", resourceCulture); } } /// /// 查找类似 Switch 的本地化字符串。 /// internal static string K_D_S { get { return ResourceManager.GetString("K_D_S", resourceCulture); } } /// /// 查找类似 General 的本地化字符串。 /// internal static string K_G { get { return ResourceManager.GetString("K_G", resourceCulture); } } /// /// 查找类似 Window 的本地化字符串。 /// internal static string K_W { get { return ResourceManager.GetString("K_W", resourceCulture); } } /// /// 查找类似 Move 的本地化字符串。 /// internal static string K_W_M { get { return ResourceManager.GetString("K_W_M", resourceCulture); } } /// /// 查找类似 Move and Follow 的本地化字符串。 /// internal static string K_W_MF { get { return ResourceManager.GetString("K_W_MF", resourceCulture); } } /// /// 查找类似 Hotkey Cleared. 的本地化字符串。 /// internal static string KB_Hotkey_Cleared { get { return ResourceManager.GetString("KB.Hotkey.Cleared", resourceCulture); } } /// /// 查找类似 Must choose a none-modifier Key. 的本地化字符串。 /// internal static string KB_Hotkey_KeyCheck { get { return ResourceManager.GetString("KB.Hotkey.KeyCheck", resourceCulture); } } /// /// 查找类似 At least one modifier Key. 的本地化字符串。 /// internal static string KB_Hotkey_MKeyCheck { get { return ResourceManager.GetString("KB.Hotkey.MKeyCheck", resourceCulture); } } /// /// 查找类似 Move To Desktop 的本地化字符串。 /// internal static string KB_Hotkey_MW { get { return ResourceManager.GetString("KB.Hotkey.MW", resourceCulture); } } /// /// 查找类似 Move and Follow To Desktop 的本地化字符串。 /// internal static string KB_Hotkey_MWF { get { return ResourceManager.GetString("KB.Hotkey.MWF", resourceCulture); } } /// /// 查找类似 Register new Hotkey Failed. 的本地化字符串。 /// internal static string KB_Hotkey_Reg_Fail { get { return ResourceManager.GetString("KB.Hotkey.Reg.Fail", resourceCulture); } } /// /// 查找类似 Register new Hotkey Success. 的本地化字符串。 /// internal static string KB_Hotkey_Reg_Success { get { return ResourceManager.GetString("KB.Hotkey.Reg.Success", resourceCulture); } } /// /// 查找类似 Settings Saved. 的本地化字符串。 /// internal static string KB_Hotkey_SettingsSaved { get { return ResourceManager.GetString("KB.Hotkey.SettingsSaved", resourceCulture); } } /// /// 查找类似 Switch To Desktop 的本地化字符串。 /// internal static string KB_Hotkey_SVD { get { return ResourceManager.GetString("KB.Hotkey.SVD", resourceCulture); } } /// /// 查找类似 Switch Back To Last Desktop 的本地化字符串。 /// internal static string KB_Hotkey_SVD_BACK_LAST { get { return ResourceManager.GetString("KB.Hotkey.SVD_BACK_LAST", resourceCulture); } } /// /// 查找类似 Left 的本地化字符串。 /// internal static string Keys_Left { get { return ResourceManager.GetString("Keys.Left", resourceCulture); } } /// /// 查找类似 Middle 的本地化字符串。 /// internal static string Keys_Middle { get { return ResourceManager.GetString("Keys.Middle", resourceCulture); } } /// /// 查找类似 Right 的本地化字符串。 /// internal static string Keys_Right { get { return ResourceManager.GetString("Keys.Right", resourceCulture); } } /// /// 查找类似 Show ContextMenu 的本地化字符串。 /// internal static string M_ContextMenu { get { return ResourceManager.GetString("M.ContextMenu", resourceCulture); } } /// /// 查找类似 Desktop 的本地化字符串。 /// internal static string M_D { get { return ResourceManager.GetString("M.D", resourceCulture); } } /// /// 查找类似 Show Only Selected Desktop in View 的本地化字符串。 /// internal static string M_D_DesktopShowForSelectedDesktop { get { return ResourceManager.GetString("M.D.DesktopShowForSelectedDesktop", resourceCulture); } } /// /// 查找类似 Switch Desktop and Close View 的本地化字符串。 /// internal static string M_D_DesktopVisibleAndCloseView { get { return ResourceManager.GetString("M.D.DesktopVisibleAndCloseView", resourceCulture); } } /// /// 查找类似 Switch Desktop Only 的本地化字符串。 /// internal static string M_D_DesktopVisibleOnly { get { return ResourceManager.GetString("M.D.DesktopVisibleOnly", resourceCulture); } } /// /// 查找类似 MainView 的本地化字符串。 /// internal static string M_ROOT { get { return ResourceManager.GetString("M.ROOT", resourceCulture); } } /// /// 查找类似 Window 的本地化字符串。 /// internal static string M_W { get { return ResourceManager.GetString("M.W", resourceCulture); } } /// /// 查找类似 Active Window, Switch Desktop and Close View 的本地化字符串。 /// internal static string M_W_WindowActiveDesktopVisibleAndCloseView { get { return ResourceManager.GetString("M.W.WindowActiveDesktopVisibleAndCloseView", resourceCulture); } } /// /// 查找类似 Active Window, Switch Desktop Only 的本地化字符串。 /// internal static string M_W_WindowActiveDesktopVisibleOnly { get { return ResourceManager.GetString("M.W.WindowActiveDesktopVisibleOnly", resourceCulture); } } /// /// 查找类似 Close Window 的本地化字符串。 /// internal static string M_W_WindowClose { get { return ResourceManager.GetString("M.W.WindowClose", resourceCulture); } } /// /// 查找类似 Hide From View 的本地化字符串。 /// internal static string M_W_WindowHideFromView { get { return ResourceManager.GetString("M.W.WindowHideFromView", resourceCulture); } } /// /// 查找类似 Show Windows Only From Selected App in Selected Desktop 的本地化字符串。 /// internal static string M_W_WindowShowForSelectedProcessInSelectedDesktop { get { return ResourceManager.GetString("M.W.WindowShowForSelectedProcessInSelectedDesktop", resourceCulture); } } /// /// 查找类似 Show Windows Only From Selected App 的本地化字符串。 /// internal static string M_W_WindowShowForSelectedProcessOnly { get { return ResourceManager.GetString("M.W.WindowShowForSelectedProcessOnly", resourceCulture); } } /// /// 查找类似 Show Context Menu 的本地化字符串。 /// internal static string Mouse_Action_ContextMenu { get { return ResourceManager.GetString("Mouse.Action.ContextMenu", resourceCulture); } } /// /// 查找类似 Show Only Selected Desktop in MainView 的本地化字符串。 /// internal static string Mouse_Action_DesktopShowForSelectedDesktop { get { return ResourceManager.GetString("Mouse.Action.DesktopShowForSelectedDesktop", resourceCulture); } } /// /// 查找类似 Switch Desktop And Close View 的本地化字符串。 /// internal static string Mouse_Action_DesktopVisibleAndCloseView { get { return ResourceManager.GetString("Mouse.Action.DesktopVisibleAndCloseView", resourceCulture); } } /// /// 查找类似 Switch Desktop Only 的本地化字符串。 /// internal static string Mouse_Action_DesktopVisibleOnly { get { return ResourceManager.GetString("Mouse.Action.DesktopVisibleOnly", resourceCulture); } } /// /// 查找类似 Do Nothing 的本地化字符串。 /// internal static string Mouse_Action_DoNothing { get { return ResourceManager.GetString("Mouse.Action.DoNothing", resourceCulture); } } /// /// 查找类似 Active Window, Switch Virtual Desktop And Close View 的本地化字符串。 /// internal static string Mouse_Action_WindowActiveDesktopVisibleAndCloseView { get { return ResourceManager.GetString("Mouse.Action.WindowActiveDesktopVisibleAndCloseView", resourceCulture); } } /// /// 查找类似 Active Window, Switch Virtual Desktop Only 的本地化字符串。 /// internal static string Mouse_Action_WindowActiveDesktopVisibleOnly { get { return ResourceManager.GetString("Mouse.Action.WindowActiveDesktopVisibleOnly", resourceCulture); } } /// /// 查找类似 Close Window 的本地化字符串。 /// internal static string Mouse_Action_WindowClose { get { return ResourceManager.GetString("Mouse.Action.WindowClose", resourceCulture); } } /// /// 查找类似 Show Windows Only From Selected App in Selected Desktop 的本地化字符串。 /// internal static string Mouse_Action_WindowShowForSelectedProcessInSelectedDesktop { get { return ResourceManager.GetString("Mouse.Action.WindowShowForSelectedProcessInSelectedDesktop", resourceCulture); } } /// /// 查找类似 Show Windows Only From Selected App 的本地化字符串。 /// internal static string Mouse_Action_WindowShowForSelectedProcessOnly { get { return ResourceManager.GetString("Mouse.Action.WindowShowForSelectedProcessOnly", resourceCulture); } } /// /// 查找类似 MouseAction Exists, try another combine or Mousebutton 的本地化字符串。 /// internal static string Mouse_Tips_Exists { get { return ResourceManager.GetString("Mouse.Tips.Exists", resourceCulture); } } /// /// 查找类似 Confirm 的本地化字符串。 /// internal static string MsgBox_Caption_Confirm { get { return ResourceManager.GetString("MsgBox.Caption.Confirm", resourceCulture); } } /// /// 查找类似 Warning 的本地化字符串。 /// internal static string MsgBox_Caption_Warning { get { return ResourceManager.GetString("MsgBox.Caption.Warning", resourceCulture); } } /// /// 查找类似 Next row 的本地化字符串。 /// internal static string Nav_CircleHType_NextRow { get { return ResourceManager.GetString("Nav.CircleHType.NextRow", resourceCulture); } } /// /// 查找类似 Same row 的本地化字符串。 /// internal static string Nav_CircleHType_SameRow { get { return ResourceManager.GetString("Nav.CircleHType.SameRow", resourceCulture); } } /// /// 查找类似 Are you sure to delete this profile? ///All files related with this profile will be deleted too. 的本地化字符串。 /// internal static string Profile_Confirm_Delete { get { return ResourceManager.GetString("Profile.Confirm.Delete", resourceCulture); } } /// /// 查找类似 Invalid profile name, or profile name already exists. 的本地化字符串。 /// internal static string Profile_Warning_InvalidProfileName { get { return ResourceManager.GetString("Profile.Warning.InvalidProfileName", resourceCulture); } } /// /// 查找类似 Can not rename or delete the last profile. ///Duplicate one and edit it. 的本地化字符串。 /// internal static string Profile_Warning_LastProfileProtect { get { return ResourceManager.GetString("Profile.Warning.LastProfileProtect", resourceCulture); } } /// /// 查找类似 At least one common rule is required. 的本地化字符串。 /// internal static string Rule_AtLeastOne { get { return ResourceManager.GetString("Rule.AtLeastOne", resourceCulture); } } /// /// 查找类似 Invalid Regex. 的本地化字符串。 /// internal static string Rule_InvalidRegex { get { return ResourceManager.GetString("Rule.InvalidRegex", resourceCulture); } } /// /// 查找类似 is required. 的本地化字符串。 /// internal static string Rule_NameRequired { get { return ResourceManager.GetString("Rule.NameRequired", resourceCulture); } } /// /// 查找类似 New Rule 的本地化字符串。 /// internal static string Rule_New { get { return ResourceManager.GetString("Rule.New", resourceCulture); } } /// /// 查找类似 is 的本地化字符串。 /// internal static string Rule_Op_Eq { get { return ResourceManager.GetString("Rule.Op.Eq", resourceCulture); } } /// /// 查找类似 ends with 的本地化字符串。 /// internal static string Rule_Op_Esw { get { return ResourceManager.GetString("Rule.Op.Esw", resourceCulture); } } /// /// 查找类似 regex 的本地化字符串。 /// internal static string Rule_Op_Regex { get { return ResourceManager.GetString("Rule.Op.Regex", resourceCulture); } } /// /// 查找类似 contains 的本地化字符串。 /// internal static string Rule_Op_Sc { get { return ResourceManager.GetString("Rule.Op.Sc", resourceCulture); } } /// /// 查找类似 starts with 的本地化字符串。 /// internal static string Rule_Op_Ssw { get { return ResourceManager.GetString("Rule.Op.Ssw", resourceCulture); } } /// /// 查找类似 Quit 的本地化字符串。 /// internal static string Tray_Menu_Quit { get { return ResourceManager.GetString("Tray.Menu.Quit", resourceCulture); } } /// /// 查找类似 Settings 的本地化字符串。 /// internal static string Tray_Menu_Settings { get { return ResourceManager.GetString("Tray.Menu.Settings", resourceCulture); } } /// /// 查找类似 Mouse Button Required 的本地化字符串。 /// internal static string Validation_Mouse_Button_Required { get { return ResourceManager.GetString("Validation.Mouse.Button.Required", resourceCulture); } } /// /// 查找类似 Create Virtual Desktop 的本地化字符串。 /// internal static string VDW_CTM_Desktop_Create { get { return ResourceManager.GetString("VDW.CTM.Desktop.Create", resourceCulture); } } /// /// 查找类似 Remove Virtual Desktop 的本地化字符串。 /// internal static string VDW_CTM_Desktop_Remove { get { return ResourceManager.GetString("VDW.CTM.Desktop.Remove", resourceCulture); } } /// /// 查找类似 Unhide Window 的本地化字符串。 /// internal static string VDW_CTM_Desktop_UnHideWindow { get { return ResourceManager.GetString("VDW.CTM.Desktop.UnHideWindow", resourceCulture); } } /// /// 查找类似 Close 的本地化字符串。 /// internal static string VDW_CTM_Window_Close { get { return ResourceManager.GetString("VDW.CTM.Window.Close", resourceCulture); } } /// /// 查找类似 Hide from view 的本地化字符串。 /// internal static string VDW_CTM_Window_HideFromView { get { return ResourceManager.GetString("VDW.CTM.Window.HideFromView", resourceCulture); } } /// /// 查找类似 Create Rule from this Window... 的本地化字符串。 /// internal static string VDW_CTM_Window_NewRule { get { return ResourceManager.GetString("VDW.CTM.Window.NewRule", resourceCulture); } } /// /// 查找类似 Show windows from this app on all desktops 的本地化字符串。 /// internal static string VDW_CTM_Window_PinApp { get { return ResourceManager.GetString("VDW.CTM.Window.PinApp", resourceCulture); } } /// /// 查找类似 Show this window on all desktops 的本地化字符串。 /// internal static string VDW_CTM_Window_PinWin { get { return ResourceManager.GetString("VDW.CTM.Window.PinWin", resourceCulture); } } /// /// 查找类似 Screen 的本地化字符串。 /// internal static string VDW_CTM_Window_Screen { get { return ResourceManager.GetString("VDW.CTM.Window.Screen", resourceCulture); } } /// /// 查找类似 Unsupported Windows Version. ///Application Will Quit. /// ///Support List ///==================================== ///Windows 10 Redstone5(17763) ///Windows 10 19H1(18362) ///Windows 10 19H2(18363) ///Windows 10 20H1(19041) ///Windows 10 20H2(19042) ///Windows 10 21H1(19043) ///Windows 10 21H2(19044) ///Windows 10 22H2(19045) ///Windows 11 21H2(22000) ///Windows 11 22H2(22621) ///Windows 11 23H2(22631) ///==================================== 的本地化字符串。 /// internal static string VersionCheckFail { get { return ResourceManager.GetString("VersionCheckFail", resourceCulture); } } } } ================================================ FILE: Bridge/Resources/Langs/WinFormStrings.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Create Virtual Desktop Remove Virtual Desktop Close Show windows from this app on all desktops Show this window on all desktops Unsupported Windows Version. Application Will Quit. Support List ==================================== Windows 10 Redstone5(17763) Windows 10 19H1(18362) Windows 10 19H2(18363) Windows 10 20H1(19041) Windows 10 20H2(19042) Windows 10 21H1(19043) Windows 10 21H2(19044) Windows 10 22H2(19045) Windows 11 21H2(22000) Windows 11 22H2(22621) Windows 11 23H2(22631) ==================================== is required. is starts with ends with contains regex At least one common rule is required. Invalid Regex. Create Rule from this Window... New Rule Window 【{0}】 match rule 【{1}】, but error occur when moving. possible reason: - window invalid. - target desktop not exists. - target desktop invalid. Error! Hide from view Unhide Window Screen Next row Same row Hotkey Cleared. Register new Hotkey Success. Register new Hotkey Failed. Settings Saved. Must choose a none-modifier Key. Do Nothing Switch Desktop And Close View Switch Desktop Only Show Context Menu Active Window, Switch Virtual Desktop And Close View Active Window, Switch Virtual Desktop Only Close Window Current Desktop: Last Desktop: Cannot access task with your current permissions level. You need to run this application 'as administrator' even if you are using an administrator account. Show Windows Only From Selected App Switch To Desktop Move To Desktop Move and Follow To Desktop Show Windows Only From Selected App in Selected Desktop Left Middle Right Show Only Selected Desktop in MainView Switch Back To Last Desktop Are you sure to delete this profile? All files related with this profile will be deleted too. Can not rename or delete the last profile. Duplicate one and edit it. Invalid profile name, or profile name already exists. Warning Confirm Settings Quit General Rise MainView Open AppController Rise MainView For Active App Rise MainView For Current Desktop Rise MainView For Active App In Current Desktop Desktop Switch Navigation Window Move Move and Follow Right Up Down Left At least one modifier Key. Desktop Window MainView Switch Desktop and Close View Switch Desktop Only Show ContextMenu Show Only Selected Desktop in View Active Window, Switch Desktop and Close View Active Window, Switch Desktop Only Hide From View Close Window Show Windows Only From Selected App Show Windows Only From Selected App in Selected Desktop Mouse Button Required MouseAction Exists, try another combine or Mousebutton Toggle Window Filter ================================================ FILE: Bridge/Resources/Langs/WinFormStrings.zh-Hans.Designer.cs ================================================ //------------------------------------------------------------------------------ // // This code was generated by a tool. // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ namespace VirtualSpace.Resources.Langs { using System; /// /// A strongly-typed resource class, for looking up localized strings, etc. /// // This class was auto-generated by the StronglyTypedResourceBuilder // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class WinFormStrings_zh_Hans { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal WinFormStrings_zh_Hans() { } /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Bridge.Resources.Langs.WinFormStrings.zh-Hans", typeof(WinFormStrings_zh_Hans).Assembly); resourceMan = temp; } return resourceMan; } } /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } /// /// Looks up a localized string similar to 当前桌面:. /// internal static string Cluster_Notification_SVD_Current { get { return ResourceManager.GetString("Cluster.Notification.SVD.Current", resourceCulture); } } /// /// Looks up a localized string similar to 上一个桌面:. /// internal static string Cluster_Notification_SVD_Last { get { return ResourceManager.GetString("Cluster.Notification.SVD.Last", resourceCulture); } } /// /// Looks up a localized string similar to 窗口 【{0}】 匹配规则 【{1}】,但移动时发生错误。 ///可能的原因: ///- 窗口无效。 ///- 目标桌面不存在。 ///- 目标桌面无效。. /// internal static string Error_MoveWindowToDesktop { get { return ResourceManager.GetString("Error.MoveWindowToDesktop", resourceCulture); } } /// /// Looks up a localized string similar to 错误!. /// internal static string Error_Title { get { return ResourceManager.GetString("Error.Title", resourceCulture); } } /// /// Looks up a localized string similar to 当前权限级别无法访问计划任务, ///请确保当前账户是此计算机的管理员并且“以管理员身份运行”运行此程序。. /// internal static string General_RunOnStartup_Error_Permission { get { return ResourceManager.GetString("General.RunOnStartup.Error.Permission", resourceCulture); } } /// /// Looks up a localized string similar to 桌面. /// internal static string K_D { get { return ResourceManager.GetString("K.D", resourceCulture); } } /// /// Looks up a localized string similar to 导航. /// internal static string K_D_N { get { return ResourceManager.GetString("K.D.N", resourceCulture); } } /// /// Looks up a localized string similar to 向左. /// internal static string K_D_N_D { get { return ResourceManager.GetString("K.D.N.D", resourceCulture); } } /// /// Looks up a localized string similar to 向右. /// internal static string K_D_N_L { get { return ResourceManager.GetString("K.D.N.L", resourceCulture); } } /// /// Looks up a localized string similar to 向上. /// internal static string K_D_N_R { get { return ResourceManager.GetString("K.D.N.R", resourceCulture); } } /// /// Looks up a localized string similar to 向下. /// internal static string K_D_N_U { get { return ResourceManager.GetString("K.D.N.U", resourceCulture); } } /// /// Looks up a localized string similar to 切换桌面. /// internal static string K_D_S { get { return ResourceManager.GetString("K.D.S", resourceCulture); } } /// /// Looks up a localized string similar to 通用. /// internal static string K_G { get { return ResourceManager.GetString("K.G", resourceCulture); } } /// /// Looks up a localized string similar to 打开程序控制. /// internal static string K_G_oac { get { return ResourceManager.GetString("K.G.oac", resourceCulture); } } /// /// Looks up a localized string similar to 唤起主视图. /// internal static string K_G_rmv { get { return ResourceManager.GetString("K.G.rmv", resourceCulture); } } /// /// Looks up a localized string similar to 为当前活动程序唤起主视图. /// internal static string K_G_rmvfaa { get { return ResourceManager.GetString("K.G.rmvfaa", resourceCulture); } } /// /// Looks up a localized string similar to 为当前桌面中的活动程序唤起主视图. /// internal static string K_G_rmvfaaicvd { get { return ResourceManager.GetString("K.G.rmvfaaicvd", resourceCulture); } } /// /// Looks up a localized string similar to 为当前桌面唤起主视图. /// internal static string K_G_rmvfcd { get { return ResourceManager.GetString("K.G.rmvfcd", resourceCulture); } } /// /// Looks up a localized string similar to 窗口. /// internal static string K_W { get { return ResourceManager.GetString("K.W", resourceCulture); } } /// /// Looks up a localized string similar to 移动. /// internal static string K_W_M { get { return ResourceManager.GetString("K.W.M", resourceCulture); } } /// /// Looks up a localized string similar to 移动并跟随. /// internal static string K_W_MF { get { return ResourceManager.GetString("K.W.MF", resourceCulture); } } /// /// Looks up a localized string similar to 热键已清除。. /// internal static string KB_Hotkey_Cleared { get { return ResourceManager.GetString("KB.Hotkey.Cleared", resourceCulture); } } /// /// Looks up a localized string similar to 必须选择一个非修改类键。. /// internal static string KB_Hotkey_KeyCheck { get { return ResourceManager.GetString("KB.Hotkey.KeyCheck", resourceCulture); } } /// /// Looks up a localized string similar to 移动到桌面 . /// internal static string KB_Hotkey_MW { get { return ResourceManager.GetString("KB.Hotkey.MW", resourceCulture); } } /// /// Looks up a localized string similar to 移动并跟随到桌面 . /// internal static string KB_Hotkey_MWF { get { return ResourceManager.GetString("KB.Hotkey.MWF", resourceCulture); } } /// /// Looks up a localized string similar to 热键注册失败。. /// internal static string KB_Hotkey_Reg_Fail { get { return ResourceManager.GetString("KB.Hotkey.Reg.Fail", resourceCulture); } } /// /// Looks up a localized string similar to 热键注册成功。. /// internal static string KB_Hotkey_Reg_Success { get { return ResourceManager.GetString("KB.Hotkey.Reg.Success", resourceCulture); } } /// /// Looks up a localized string similar to 设置已保存。. /// internal static string KB_Hotkey_SettingsSaved { get { return ResourceManager.GetString("KB.Hotkey.SettingsSaved", resourceCulture); } } /// /// Looks up a localized string similar to 切换到桌面 . /// internal static string KB_Hotkey_SVD { get { return ResourceManager.GetString("KB.Hotkey.SVD", resourceCulture); } } /// /// Looks up a localized string similar to 切换回上一个桌面. /// internal static string KB_Hotkey_SVD_BACK_LAST { get { return ResourceManager.GetString("KB.Hotkey.SVD_BACK_LAST", resourceCulture); } } /// /// Looks up a localized string similar to 左键. /// internal static string Keys_Left { get { return ResourceManager.GetString("Keys.Left", resourceCulture); } } /// /// Looks up a localized string similar to 中键. /// internal static string Keys_Middle { get { return ResourceManager.GetString("Keys.Middle", resourceCulture); } } /// /// Looks up a localized string similar to 右键. /// internal static string Keys_Right { get { return ResourceManager.GetString("Keys.Right", resourceCulture); } } /// /// Looks up a localized string similar to 显示上下文菜单. /// internal static string Mouse_Action_ContextMenu { get { return ResourceManager.GetString("Mouse.Action.ContextMenu", resourceCulture); } } /// /// Looks up a localized string similar to 仅显示所选桌面. /// internal static string Mouse_Action_DesktopShowForSelectedDesktop { get { return ResourceManager.GetString("Mouse.Action.DesktopShowForSelectedDesktop", resourceCulture); } } /// /// Looks up a localized string similar to 切换虚拟桌面并关闭视图. /// internal static string Mouse_Action_DesktopVisibleAndCloseView { get { return ResourceManager.GetString("Mouse.Action.DesktopVisibleAndCloseView", resourceCulture); } } /// /// Looks up a localized string similar to 仅切换虚拟桌面. /// internal static string Mouse_Action_DesktopVisibleOnly { get { return ResourceManager.GetString("Mouse.Action.DesktopVisibleOnly", resourceCulture); } } /// /// Looks up a localized string similar to 什么都不做. /// internal static string Mouse_Action_DoNothing { get { return ResourceManager.GetString("Mouse.Action.DoNothing", resourceCulture); } } /// /// Looks up a localized string similar to 激活窗口,切换桌面并关闭视图. /// internal static string Mouse_Action_WindowActiveDesktopVisibleAndCloseView { get { return ResourceManager.GetString("Mouse.Action.WindowActiveDesktopVisibleAndCloseView", resourceCulture); } } /// /// Looks up a localized string similar to 激活窗口,切换桌面. /// internal static string Mouse_Action_WindowActiveDesktopVisibleOnly { get { return ResourceManager.GetString("Mouse.Action.WindowActiveDesktopVisibleOnly", resourceCulture); } } /// /// Looks up a localized string similar to 关闭窗口. /// internal static string Mouse_Action_WindowClose { get { return ResourceManager.GetString("Mouse.Action.WindowClose", resourceCulture); } } /// /// Looks up a localized string similar to 仅显示所选桌面中的活动程序窗口. /// internal static string Mouse_Action_WindowShowForSelectedProcessInSelectedDesktop { get { return ResourceManager.GetString("Mouse.Action.WindowShowForSelectedProcessInSelectedDesktop", resourceCulture); } } /// /// Looks up a localized string similar to 仅显示此程序的窗口. /// internal static string Mouse_Action_WindowShowForSelectedProcessOnly { get { return ResourceManager.GetString("Mouse.Action.WindowShowForSelectedProcessOnly", resourceCulture); } } /// /// Looks up a localized string similar to 确认. /// internal static string MsgBox_Caption_Confirm { get { return ResourceManager.GetString("MsgBox.Caption.Confirm", resourceCulture); } } /// /// Looks up a localized string similar to 警告. /// internal static string MsgBox_Caption_Warning { get { return ResourceManager.GetString("MsgBox.Caption.Warning", resourceCulture); } } /// /// Looks up a localized string similar to 切换到下一行. /// internal static string Nav_CircleHType_NextRow { get { return ResourceManager.GetString("Nav.CircleHType.NextRow", resourceCulture); } } /// /// Looks up a localized string similar to 在同一行内循环. /// internal static string Nav_CircleHType_SameRow { get { return ResourceManager.GetString("Nav.CircleHType.SameRow", resourceCulture); } } /// /// Looks up a localized string similar to 确定要删除这个配置文件吗? ///所有与此配置文件相关的文件都将被删除。. /// internal static string Profile_Confirm_Delete { get { return ResourceManager.GetString("Profile.Confirm.Delete", resourceCulture); } } /// /// Looks up a localized string similar to 配置文件名无效,或该文件已存在。. /// internal static string Profile_Warning_InvalidProfileName { get { return ResourceManager.GetString("Profile.Warning.InvalidProfileName", resourceCulture); } } /// /// Looks up a localized string similar to 不能重命名或删除最后一个配置文件。. /// internal static string Profile_Warning_LastProfileProtect { get { return ResourceManager.GetString("Profile.Warning.LastProfileProtect", resourceCulture); } } /// /// Looks up a localized string similar to 至少需要一条窗口规则。. /// internal static string Rule_AtLeastOne { get { return ResourceManager.GetString("Rule.AtLeastOne", resourceCulture); } } /// /// Looks up a localized string similar to 无效的正则表达式。. /// internal static string Rule_InvalidRegex { get { return ResourceManager.GetString("Rule.InvalidRegex", resourceCulture); } } /// /// Looks up a localized string similar to 是必须的。. /// internal static string Rule_NameRequired { get { return ResourceManager.GetString("Rule.NameRequired", resourceCulture); } } /// /// Looks up a localized string similar to 新规则. /// internal static string Rule_New { get { return ResourceManager.GetString("Rule.New", resourceCulture); } } /// /// Looks up a localized string similar to 是. /// internal static string Rule_Op_Eq { get { return ResourceManager.GetString("Rule.Op.Eq", resourceCulture); } } /// /// Looks up a localized string similar to 以...结尾. /// internal static string Rule_Op_Esw { get { return ResourceManager.GetString("Rule.Op.Esw", resourceCulture); } } /// /// Looks up a localized string similar to 正则表达式. /// internal static string Rule_Op_Regex { get { return ResourceManager.GetString("Rule.Op.Regex", resourceCulture); } } /// /// Looks up a localized string similar to 包含. /// internal static string Rule_Op_Sc { get { return ResourceManager.GetString("Rule.Op.Sc", resourceCulture); } } /// /// Looks up a localized string similar to 以...开头. /// internal static string Rule_Op_Ssw { get { return ResourceManager.GetString("Rule.Op.Ssw", resourceCulture); } } /// /// Looks up a localized string similar to 退出. /// internal static string Tray_Menu_Quit { get { return ResourceManager.GetString("Tray.Menu.Quit", resourceCulture); } } /// /// Looks up a localized string similar to 设置. /// internal static string Tray_Menu_Settings { get { return ResourceManager.GetString("Tray.Menu.Settings", resourceCulture); } } /// /// Looks up a localized string similar to 创建新的虚拟桌面. /// internal static string VDW_CTM_Desktop_Create { get { return ResourceManager.GetString("VDW.CTM.Desktop.Create", resourceCulture); } } /// /// Looks up a localized string similar to 删除虚拟桌面. /// internal static string VDW_CTM_Desktop_Remove { get { return ResourceManager.GetString("VDW.CTM.Desktop.Remove", resourceCulture); } } /// /// Looks up a localized string similar to 取消隐藏窗口. /// internal static string VDW_CTM_Desktop_UnHideWindow { get { return ResourceManager.GetString("VDW.CTM.Desktop.UnHideWindow", resourceCulture); } } /// /// Looks up a localized string similar to 关闭. /// internal static string VDW_CTM_Window_Close { get { return ResourceManager.GetString("VDW.CTM.Window.Close", resourceCulture); } } /// /// Looks up a localized string similar to 从视图中隐藏. /// internal static string VDW_CTM_Window_HideFromView { get { return ResourceManager.GetString("VDW.CTM.Window.HideFromView", resourceCulture); } } /// /// Looks up a localized string similar to 为此窗口创建规则.... /// internal static string VDW_CTM_Window_NewRule { get { return ResourceManager.GetString("VDW.CTM.Window.NewRule", resourceCulture); } } /// /// Looks up a localized string similar to 在所有桌面上显示此应用的窗口. /// internal static string VDW_CTM_Window_PinApp { get { return ResourceManager.GetString("VDW.CTM.Window.PinApp", resourceCulture); } } /// /// Looks up a localized string similar to 在所有桌面上显示此窗口. /// internal static string VDW_CTM_Window_PinWin { get { return ResourceManager.GetString("VDW.CTM.Window.PinWin", resourceCulture); } } /// /// Looks up a localized string similar to 屏幕. /// internal static string VDW_CTM_Window_Screen { get { return ResourceManager.GetString("VDW.CTM.Window.Screen", resourceCulture); } } /// /// Looks up a localized string similar to 不支持的 Windows 版本 ///应用程序将退出 /// ///支持的列表 ///==================================== ///Windows 10 Redstone5(17763) ///Windows 10 19H1(18362) ///Windows 10 19H2(18363) ///Windows 10 20H1(19041) ///Windows 10 20H2(19042) ///Windows 10 21H1(19043) ///Windows 10 21H2(19044) ///Windows 10 22H2(19045) ///Windows 11 21H2(22000) ///Windows 11 22H2(22621) ///====================================. /// internal static string VersionCheckFail { get { return ResourceManager.GetString("VersionCheckFail", resourceCulture); } } } } ================================================ FILE: Bridge/Resources/Langs/WinFormStrings.zh-Hans.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 创建新的虚拟桌面 删除虚拟桌面 关闭 在所有桌面上显示此应用的窗口 在所有桌面上显示此窗口 不支持的 Windows 版本 应用程序将退出 支持的列表 ==================================== Windows 10 Redstone5(17763) Windows 10 19H1(18362) Windows 10 19H2(18363) Windows 10 20H1(19041) Windows 10 20H2(19042) Windows 10 21H1(19043) Windows 10 21H2(19044) Windows 10 22H2(19045) Windows 11 21H2(22000) Windows 11 22H2(22621) Windows 11 23H2(22631) ==================================== 以...开头 以...结尾 包含 正则表达式 至少需要一条窗口规则。 无效的正则表达式。 是必须的。 为此窗口创建规则... 新规则 窗口 【{0}】 匹配规则 【{1}】,但移动时发生错误。 可能的原因: - 窗口无效。 - 目标桌面不存在。 - 目标桌面无效。 错误! 从视图中隐藏 取消隐藏窗口 屏幕 切换到下一行 在同一行内循环 热键已清除。 热键注册成功。 热键注册失败。 设置已保存。 必须选择一个非修改类键。 什么都不做 仅切换桌面 切换桌面并关闭视图 显示上下文菜单 关闭窗口 激活窗口,切换桌面并关闭视图 激活窗口,切换桌面 当前桌面: 上一个桌面: 当前权限级别无法访问计划任务, 请确保当前账户是此计算机的管理员并且“以管理员身份运行”运行此程序。 仅显示此程序的窗口 切换到桌面 移动到桌面 移动并跟随到桌面 仅显示所选桌面中的活动程序窗口 左键 中键 右键 仅显示所选桌面 切换回上一个桌面 不能重命名或删除最后一个配置文件。 复制一个新的配置文件后即可操作。 确定要删除这个配置文件吗? 所有与此配置文件相关的文件都将被删除。 配置文件名无效,或该文件已存在。 确认 警告 设置 退出 通用 打开程序控制 唤起主视图 为当前活动程序唤起主视图 为当前桌面唤起主视图 为当前桌面中的活动程序唤起主视图 桌面 导航 切换桌面 窗口 移动 移动并跟随 向左 向右 向上 向下 至少需要一个修改类键。 桌面 窗口 主视图 切换桌面并关闭视图 仅切换桌面 仅显示所选桌面 显示上下文菜单 激活窗口,切换桌面并关闭视图 激活窗口,切换桌面 从视图中隐藏 关闭窗口 仅显示此程序的窗口 仅显示所选桌面中的活动程序窗口 必须选择鼠标键 相同的鼠标动作已存在,尝试换一种组合或鼠标键 开关窗口过滤器 ================================================ FILE: Bridge/VirtualDesktopNotification.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; namespace VirtualSpace.Commons { public enum VirtualDesktopNotificationType { CREATED, DELETED, CURRENT_CHANGED } public class VirtualDesktopNotification { public VirtualDesktopNotificationType Type { get; set; } public Guid NewId { get; set; } public Guid OldId { get; set; } } } ================================================ FILE: Bridge/Window.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; namespace VirtualSpace.Config.Events.Entity { public class Window { public IntPtr Handle { get; set; } public string Title { get; set; } public string WndClass { get; set; } public string? WinInScreen { get; set; } public int VdIndex { get; set; } public int? ProcessId { get; set; } public string? ProcessName { get; set; } public string? ProcessPath { get; set; } public string? CommandLine { get; set; } public static Window Create( IntPtr handle, string title, string wndClass, int pId ) { return new Window { Handle = handle, Title = title, WndClass = wndClass, ProcessId = pId }; } } } ================================================ FILE: COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Configuration/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Configuration/ConfigTemplate.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System.Collections.Generic; using VirtualSpace.Config.DataAnnotations; using VirtualSpace.Config.Entity; namespace VirtualSpace.Config { public class ConfigTemplate { [PropertyProtector] public Dictionary Profiles { get; set; } public string CurrentProfileName { get; set; } public string Version { get; set; } public LogConfig LogConfig { get; set; } public Dictionary? KeyBindings { get; set; } = new() { {Const.Hotkey.RISE_VIEW, new KeyBinding {GhkCode = "_+Ctrl+_+Shift+Tab", MessageId = Const.Hotkey.Info[Const.Hotkey.RISE_VIEW].MessageId}}, {Const.Hotkey.RISE_VIEW_FOR_ACTIVE_APP, new KeyBinding {GhkCode = "", MessageId = Const.Hotkey.Info[Const.Hotkey.RISE_VIEW_FOR_ACTIVE_APP].MessageId}}, {Const.Hotkey.RISE_VIEW_FOR_CURRENT_VD, new KeyBinding {GhkCode = "", MessageId = Const.Hotkey.Info[Const.Hotkey.RISE_VIEW_FOR_CURRENT_VD].MessageId}}, { Const.Hotkey.RISE_VIEW_FOR_ACTIVE_APP_IN_CURRENT_VD, new KeyBinding {GhkCode = "", MessageId = Const.Hotkey.Info[Const.Hotkey.RISE_VIEW_FOR_ACTIVE_APP_IN_CURRENT_VD].MessageId} }, {Const.Hotkey.SHOW_APP_CONTROLLER, new KeyBinding {GhkCode = "_+Ctrl+Alt+_+F12", MessageId = Const.Hotkey.Info[Const.Hotkey.SHOW_APP_CONTROLLER].MessageId}}, {Const.Hotkey.NAV_LEFT, new KeyBinding {GhkCode = "", MessageId = Const.Hotkey.Info[Const.Hotkey.NAV_LEFT].MessageId}}, {Const.Hotkey.NAV_RIGHT, new KeyBinding {GhkCode = "", MessageId = Const.Hotkey.Info[Const.Hotkey.NAV_RIGHT].MessageId}}, {Const.Hotkey.NAV_UP, new KeyBinding {GhkCode = "", MessageId = Const.Hotkey.Info[Const.Hotkey.NAV_UP].MessageId}}, {Const.Hotkey.NAV_DOWN, new KeyBinding {GhkCode = "", MessageId = Const.Hotkey.Info[Const.Hotkey.NAV_DOWN].MessageId}}, {Const.Hotkey.SWITCH_BACK_LAST, new KeyBinding {GhkCode = "", MessageId = Const.Hotkey.Info[Const.Hotkey.SWITCH_BACK_LAST].MessageId}} }; public Dictionary? MouseAction { get; set; } = new(); public Dictionary MouseActions { get; set; } = new(); [PropertyProtector] public Cluster Cluster { get; set; } = new() { HideMainViewIfItsShown = false, NotificationOnVdChanged = false, ShowVDIndexOnTrayIcon = false, HideOnStart = false }; public MouseAction.Action GetMouseActionById( string id ) { if ( MouseActions.Count == 0 ) { MouseActions = Config.MouseAction.Info; } return MouseActions.ContainsKey( id ) ? MouseActions[id] : Config.MouseAction.Action.DoNothing; } } } ================================================ FILE: Configuration/Configuration.csproj ================================================  net6.0-windows 9 true enable all runtime; build; native; contentfiles; analyzers; buildtransitive true ================================================ FILE: Configuration/Const.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System.Collections.Generic; using System.Windows.Forms; using VirtualSpace.Helpers; using KeyBinding = VirtualSpace.Config.Entity.KeyBinding; namespace VirtualSpace.Config { public static class Const { public const int WindowTitleMaxLength = 2048; public const int WindowClassMaxLength = 512; public const int WindowCheckTimesLimit = 10; public const int OneSecond = 1000; public const int OneMinute = 60 * OneSecond; public const int WindowCloseTimeout = 60 * OneSecond; public const int RiseViewInterval = 500; public const int SwitchDesktopInterval = 100; public const int FakeHideX = -10000; public const int FakeHideY = -10000; public const string ApplicationFrameWindow = "ApplicationFrameWindow"; public const string WindowsUiCoreWindow = "Windows.UI.Core.CoreWindow"; public const string TaskbarCreated = "TaskbarCreated"; public const string TaskbarWndClass = "Shell_TrayWnd"; public const string WindowsCRLF = "\r\n"; public const string AppName = "VirtualSpace"; public const string HideWindowSplitter = "🔙🔜"; public static class Window { public const string VD_FRAME_TITLE = "VirtualSpace__VirtualDesktopFrame!"; public const string VD_CONTAINER_TITLE = "VirtualSpace__VirtualDesktopWindow!"; public const string VD_DRAG_TITLE = "VirtualSpace__VirtualDesktopDragWindow!"; public const string VS_CONTROLLER_TITLE = "[Virtual Space Controller]"; public const string VS_WINDOW_FILTER_TITLE = "VirtualSpace__WindowFilter!"; public const int WINDOW_FILTER_BAR_HEIGHT = 100; } public static class VirtualDesktop { public const int NavHTypeNextRow = 0; public const int NavHTypeSameRow = 1; public const int VdwSizeFloor = 100; } public static class Settings { public const string RuleFileExt = ".rules"; public const string ClusterFileExt = ".cluster"; public const string ProfilesFolder = "Profiles"; public const string CacheFolder = "Cache"; public const string PluginsFolder = "Plugins"; public const string LogsFolder = "Logs"; public const string SettingsFile = "settings.json"; public const string DefaultVersion = "2.0"; public const string DefaultLogLevel = "EVENT"; } public static class Reg { public const string RegKeyApp = @"Software\newlooper.com\VirtualSpace"; public const string RegKeyConfigRoot = "ConfigRoot"; } public static class Args { public const string HIDE_ON_START = "--HideOnStart"; } public static class Hotkey { public const string SPLITTER = "+"; public const string NONE = "_"; public const string WIN = "Win"; public const string CTRL = "Ctrl"; public const string ALT = "Alt"; public const string SHIFT = "Shift"; public const string SVD_TREE_NODE_PREFIX = "hk_node_svd_"; private const string SVD_FUNC_DESC_PREFIX = "Switch To Desktop "; public const string MW_TREE_NODE_PREFIX = "hk_node_mw_"; private const string MW_FUNC_DESC_PREFIX = "Move To Desktop "; public const string MWF_TREE_NODE_PREFIX = "hk_node_mwf_"; private const string MWF_FUNC_DESC_PREFIX = "Move and Follow To Desktop "; /////////////////////////////////////////////////// // 值与控件名称一一对应,若控件名被修改,则此处也须对应改变 public const string RISE_VIEW = "hk_node_rise_mainview"; public const string RISE_VIEW_FOR_ACTIVE_APP = "hk_node_rise_mainview_for_active_app"; public const string RISE_VIEW_FOR_CURRENT_VD = "hk_node_rise_mainview_for_current_vd"; public const string RISE_VIEW_FOR_ACTIVE_APP_IN_CURRENT_VD = "hk_node_rise_mainview_for_active_app_in_current_vd"; public const string SHOW_APP_CONTROLLER = "hk_node_open_app_controller"; public const string NAV_LEFT = "hk_node_nav_left"; public const string NAV_RIGHT = "hk_node_nav_right"; public const string NAV_UP = "hk_node_nav_up"; public const string NAV_DOWN = "hk_node_nav_down"; public const string SWITCH_BACK_LAST = "hk_node_svd_back_last"; public const string TOGGLE_WINDOW_FILTER = "hk_node_toggle_window_filter"; //////////////////////////////////////////////////////////////// // 可由热键调用的程序功能表 // tuple.Item1 => friendly name // tuple.Item2 => UserMessageId // tuple.Item3 => alternate hotkey, 由程序保留,只能在源码中修改 public static readonly Dictionary Info = new() { {RISE_VIEW, ( "Rise MainView", UserMessage.RiseView, "LWin+Tab" )}, {RISE_VIEW_FOR_ACTIVE_APP, ( "Rise MainView For Active App", UserMessage.RiseViewForActiveApp, "" )}, {RISE_VIEW_FOR_CURRENT_VD, ( "Rise MainView For Current Desktop", UserMessage.RiseViewForCurrentVD, "" )}, { RISE_VIEW_FOR_ACTIVE_APP_IN_CURRENT_VD, ( "Rise MainView For Active App In Current Virtual Desktop", UserMessage.RiseViewForActiveAppInCurrentVD, "" ) }, {SHOW_APP_CONTROLLER, ( "Open AppController", UserMessage.ShowAppController, "" )}, {NAV_LEFT, ( "Left", UserMessage.NavLeft, "LWin+Ctrl+Left" )}, {NAV_RIGHT, ( "Right", UserMessage.NavRight, "LWin+Ctrl+Right" )}, {NAV_UP, ( "Up", UserMessage.NavUp, "LWin+Ctrl+Up" )}, {NAV_DOWN, ( "Down", UserMessage.NavDown, "LWin+Ctrl+Down" )}, {SWITCH_BACK_LAST, ( "Switch Back To Last Desktop", UserMessage.SwitchBackToLastDesktop, "" )}, {TOGGLE_WINDOW_FILTER, ( "Toggle Window Filter", UserMessage.ToggleWindowFilter, "" )} }; public static string GetFuncDesc( string key ) { var func = ""; if ( Info.ContainsKey( key ) ) { func = Info[key].FuncDesc; } else if ( key.StartsWith( SVD_TREE_NODE_PREFIX ) ) { func = SVD_FUNC_DESC_PREFIX + key.Replace( SVD_TREE_NODE_PREFIX, "" ); } else if ( key.StartsWith( MW_TREE_NODE_PREFIX ) ) { func = MW_FUNC_DESC_PREFIX + key.Replace( MW_TREE_NODE_PREFIX, "" ); } else if ( key.StartsWith( MWF_TREE_NODE_PREFIX ) ) { func = MWF_FUNC_DESC_PREFIX + key.Replace( MWF_TREE_NODE_PREFIX, "" ); } return func; } public static KeyBinding GetKeyBinding( string key ) { var kb = new KeyBinding(); if ( Info.ContainsKey( key ) ) { kb.MessageId = Info[key].MessageId; } else if ( key.StartsWith( SVD_TREE_NODE_PREFIX ) ) { kb.MessageId = UserMessage.Meta.SVD_START + int.Parse( key.Replace( SVD_TREE_NODE_PREFIX, "" ) ); } else if ( key.StartsWith( MW_TREE_NODE_PREFIX ) ) { kb.MessageId = UserMessage.Meta.MW_START + int.Parse( key.Replace( MW_TREE_NODE_PREFIX, "" ) ); } else if ( key.StartsWith( MWF_TREE_NODE_PREFIX ) ) { kb.MessageId = UserMessage.Meta.MWF_START + int.Parse( key.Replace( MWF_TREE_NODE_PREFIX, "" ) ); } return kb; } public static string GetHotkeyExtra( string key ) { var extra = ""; if ( Info.ContainsKey( key ) ) { extra = Info[key].AltHotKey; } return extra; } } } public static class MouseAction { public enum Action { DoNothing, ContextMenu, DesktopVisibleAndCloseView, DesktopVisibleOnly, WindowActiveDesktopVisibleAndCloseView, WindowActiveDesktopVisibleOnly, WindowClose, WindowHideFromView, WindowShowForSelectedProcessOnly, WindowShowForSelectedProcessInSelectedDesktop, DesktopShowForSelectedDesktop } public static string MOUSE_NODE_DESKTOP_PREFIX = "mouse_node_d_"; public static string MOUSE_NODE_WINDOW_PREFIX = "mouse_node_w_"; public const string KEY_SPLITTER = "+"; public static readonly string NoneKeyCode = ( (int)Keys.None ).ToString( "X2" ); private static readonly Dictionary MouseButtonsName; public static readonly Dictionary KeysName; //////////////////////////////////////////////////////////////// // 鼠标动作表,信息包含默认行为 public static readonly Dictionary Info1; // ver 1.0 //////////////////////////////////////////////////////////////// // 鼠标动作表,信息包含默认行为 public static readonly Dictionary Info; // ver 2.0 static MouseAction() { MouseButtonsName = new Dictionary { {MouseButtons.Left, "Left"}, {MouseButtons.Middle, "Middle"}, {MouseButtons.Right, "Right"} }; KeysName = new Dictionary { {Keys.Control, "Ctrl"}, {Keys.Alt, "Alt"}, {Keys.Shift, "Shift"} }; Info = new Dictionary { {MOUSE_NODE_DESKTOP_PREFIX + NoneKeyCode + KEY_SPLITTER + MouseButtonsName[MouseButtons.Left], Action.DesktopVisibleAndCloseView}, {MOUSE_NODE_DESKTOP_PREFIX + NoneKeyCode + KEY_SPLITTER + MouseButtonsName[MouseButtons.Middle], Action.DesktopVisibleOnly}, {MOUSE_NODE_DESKTOP_PREFIX + NoneKeyCode + KEY_SPLITTER + MouseButtonsName[MouseButtons.Right], Action.ContextMenu}, {MOUSE_NODE_WINDOW_PREFIX + NoneKeyCode + KEY_SPLITTER + MouseButtonsName[MouseButtons.Left], Action.WindowActiveDesktopVisibleAndCloseView}, {MOUSE_NODE_WINDOW_PREFIX + NoneKeyCode + KEY_SPLITTER + MouseButtonsName[MouseButtons.Middle], Action.WindowActiveDesktopVisibleOnly}, {MOUSE_NODE_WINDOW_PREFIX + NoneKeyCode + KEY_SPLITTER + MouseButtonsName[MouseButtons.Right], Action.ContextMenu}, }; Info1 = new Dictionary { {MOUSE_NODE_DESKTOP_PREFIX + MouseButtonsName[MouseButtons.Left], Action.DesktopVisibleAndCloseView}, {MOUSE_NODE_DESKTOP_PREFIX + MouseButtonsName[MouseButtons.Middle], Action.DesktopVisibleOnly}, {MOUSE_NODE_DESKTOP_PREFIX + MouseButtonsName[MouseButtons.Right], Action.ContextMenu}, {MOUSE_NODE_DESKTOP_PREFIX + KeysName[Keys.Control] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Left], Action.DoNothing}, {MOUSE_NODE_DESKTOP_PREFIX + KeysName[Keys.Control] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Middle], Action.DoNothing}, {MOUSE_NODE_DESKTOP_PREFIX + KeysName[Keys.Control] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Right], Action.DoNothing}, {MOUSE_NODE_DESKTOP_PREFIX + KeysName[Keys.Alt] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Left], Action.DoNothing}, {MOUSE_NODE_DESKTOP_PREFIX + KeysName[Keys.Alt] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Middle], Action.DoNothing}, {MOUSE_NODE_DESKTOP_PREFIX + KeysName[Keys.Alt] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Right], Action.DoNothing}, {MOUSE_NODE_DESKTOP_PREFIX + KeysName[Keys.Shift] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Left], Action.DoNothing}, {MOUSE_NODE_DESKTOP_PREFIX + KeysName[Keys.Shift] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Middle], Action.DoNothing}, {MOUSE_NODE_DESKTOP_PREFIX + KeysName[Keys.Shift] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Right], Action.DoNothing}, {MOUSE_NODE_WINDOW_PREFIX + MouseButtonsName[MouseButtons.Left], Action.WindowActiveDesktopVisibleAndCloseView}, {MOUSE_NODE_WINDOW_PREFIX + MouseButtonsName[MouseButtons.Middle], Action.WindowActiveDesktopVisibleOnly}, {MOUSE_NODE_WINDOW_PREFIX + MouseButtonsName[MouseButtons.Right], Action.ContextMenu}, {MOUSE_NODE_WINDOW_PREFIX + KeysName[Keys.Control] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Left], Action.DoNothing}, {MOUSE_NODE_WINDOW_PREFIX + KeysName[Keys.Control] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Middle], Action.DoNothing}, {MOUSE_NODE_WINDOW_PREFIX + KeysName[Keys.Control] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Right], Action.DoNothing}, {MOUSE_NODE_WINDOW_PREFIX + KeysName[Keys.Alt] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Left], Action.DoNothing}, {MOUSE_NODE_WINDOW_PREFIX + KeysName[Keys.Alt] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Middle], Action.DoNothing}, {MOUSE_NODE_WINDOW_PREFIX + KeysName[Keys.Alt] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Right], Action.DoNothing}, {MOUSE_NODE_WINDOW_PREFIX + KeysName[Keys.Shift] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Left], Action.DoNothing}, {MOUSE_NODE_WINDOW_PREFIX + KeysName[Keys.Shift] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Middle], Action.DoNothing}, {MOUSE_NODE_WINDOW_PREFIX + KeysName[Keys.Shift] + KEY_SPLITTER + MouseButtonsName[MouseButtons.Right], Action.DoNothing} }; } public static string GetActionId( MouseButtons mb, Keys key, string prefix ) { if ( User32.GetKeyState( (int)Keys.LWin ) < 0 ) { key |= Keys.LWin; } var keyCode = ( (int)key ).ToString( "X2" ); var actionId = prefix + keyCode + KEY_SPLITTER + MouseButtonsName[mb]; return actionId; } } } ================================================ FILE: Configuration/Converter/EntityConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System.Collections.Generic; using System.Linq; namespace VirtualSpace.Config.Converter { public static class EntityConverter { public static void ConvertMouseAction( Dictionary oldFormat, Dictionary newFormat ) { var prefix = string.Empty; var combined = string.Empty; var modifier = string.Empty; var mouseButton = string.Empty; foreach ( var (maId, ma) in oldFormat ) { if ( maId.StartsWith( MouseAction.MOUSE_NODE_DESKTOP_PREFIX ) ) { prefix = MouseAction.MOUSE_NODE_DESKTOP_PREFIX; combined = maId[MouseAction.MOUSE_NODE_DESKTOP_PREFIX.Length..]; } else if ( maId.StartsWith( MouseAction.MOUSE_NODE_WINDOW_PREFIX ) ) { prefix = MouseAction.MOUSE_NODE_WINDOW_PREFIX; combined = maId[MouseAction.MOUSE_NODE_WINDOW_PREFIX.Length..]; } if ( combined.Contains( MouseAction.KEY_SPLITTER ) ) { var arrMK = combined.Split( MouseAction.KEY_SPLITTER ); var key = MouseAction.KeysName.Single( x => x.Value == arrMK[0] ).Key; modifier = ( (int)key ).ToString( "X2" ); mouseButton = arrMK[1]; } else { modifier = MouseAction.NoneKeyCode; mouseButton = combined; } newFormat.Add( prefix + modifier + MouseAction.KEY_SPLITTER + mouseButton, ma ); } } } } ================================================ FILE: Configuration/DataAnnotations/PropertyProtectorAttribute.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Linq; namespace VirtualSpace.Config.DataAnnotations { public class PropertyProtectorAttribute : Attribute { public object[] Values { get; private set; } public PropertyProtectorAttribute() { } public PropertyProtectorAttribute( byte defaultV, byte min ) { Values = new object[] {defaultV, min}; } public PropertyProtectorAttribute( int defaultV, int min, int max ) { Values = new object[] {defaultV, min, max}; } public PropertyProtectorAttribute( long defaultV, long min, long max ) { Values = new object[] {defaultV, min, max}; } } public abstract class PropertyProtector { public static void Walk( object obj ) { var props = from prop in obj.GetType().GetProperties() let attrs = prop.GetCustomAttributes( typeof( PropertyProtectorAttribute ), false ) where attrs.Any() select new {Obj = obj, Property = prop, Attr = (PropertyProtectorAttribute)attrs.First()}; foreach ( var pair in props ) { if ( pair.Attr.Values is null ) // an object that have some properties which modified by [PropertyProtector( xxx )] { var type = pair.Property.PropertyType; if ( type.FullName.StartsWith( "System.Collections.Generic.Dictionary" ) ) // for collection Type, only Dictionary supported for now { var dict = pair.Property.GetValue( pair.Obj ); var values = ( (dynamic)dict ).Values; foreach ( var v in values ) { Walk( v ); } } else { Walk( pair.Property.GetValue( pair.Obj ) ); // a class instance } } else { ////////////////////////////////////////////// // if validation fail, reset to default value // only support byte, int, long for now switch ( pair.Attr.Values[0] ) { case byte: { var current = (byte)pair.Property.GetValue( obj ); if ( current < (byte)pair.Attr.Values[1] || current > byte.MaxValue ) { pair.Property.SetValue( obj, pair.Attr.Values[0], null ); } break; } case int: { var current = (int)pair.Property.GetValue( obj ); if ( current < (int)pair.Attr.Values[1] || current > (int)pair.Attr.Values[2] ) { pair.Property.SetValue( obj, pair.Attr.Values[0], null ); } break; } case long: { var current = (long)pair.Property.GetValue( obj ); if ( current < (long)pair.Attr.Values[1] || current > (long)pair.Attr.Values[2] ) { pair.Property.SetValue( obj, pair.Attr.Values[0], null ); } break; } } } } } } } ================================================ FILE: Configuration/Entity/Cluster.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using VirtualSpace.Config.DataAnnotations; namespace VirtualSpace.Config.Entity { public class Cluster { public bool HideMainViewIfItsShown { get; set; } public bool NotificationOnVdChanged { get; set; } public bool ShowVDIndexOnTrayIcon { get; set; } public int StyleOfVDIndexOnTrayIcon { get; set; } = 0; public bool HideOnStart { get; set; } public bool ForceFocusForegroundWindow { get; set; } = true; public bool EnableDoubleBufferedForVDW { get; set; } = true; public bool EnableWindowFilter { get; set; } = false; [PropertyProtector( 50L, 30L, 100L )] public long VdwWallpaperQuality { get; set; } [PropertyProtector( 200, 100, 1000 )] public int ToggleWindowFilterDoublePressMaxInterval { get; set; } [PropertyProtector( 1000, 100, 1000 )] public int WindowFilterKeywordScanningInterval { get; set; } } } ================================================ FILE: Configuration/Entity/Colour.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using VirtualSpace.Config.DataAnnotations; namespace VirtualSpace.Config.Entity { public class Colour { [PropertyProtector( 55, 1 )] public byte R { get; set; } [PropertyProtector( 55, 1 )] public byte G { get; set; } [PropertyProtector( 55, 1 )] public byte B { get; set; } public uint GetLongOfColor() { return (uint)( R * 0x10000 + G * 0x100 + B ); } } } ================================================ FILE: Configuration/Entity/KeyBinding.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ namespace VirtualSpace.Config.Entity { public class KeyBinding { public string GhkCode { get; set; } = ""; public int MessageId { get; set; } } } ================================================ FILE: Configuration/Entity/LogConfig.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . namespace VirtualSpace.Config.Entity { public class LogConfig { public bool ShowLogsInGui { get; set; } = false; public string LogLevel { get; set; } } } ================================================ FILE: Configuration/Entity/Margin.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using VirtualSpace.Config.DataAnnotations; namespace VirtualSpace.Config.Entity { public class Margin { public Margin() { } public Margin( int all ) { Top = all; Right = all; Bottom = all; Left = all; } [PropertyProtector( 10, 0, 50 )] public int Top { get; set; } [PropertyProtector( 10, 0, 50 )] public int Right { get; set; } [PropertyProtector( 10, 0, 50 )] public int Bottom { get; set; } [PropertyProtector( 10, 0, 50 )] public int Left { get; set; } } } ================================================ FILE: Configuration/Entity/Mouse.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using VirtualSpace.Config.DataAnnotations; namespace VirtualSpace.Config.Entity { public class Mouse { public int LeftClickOnCanvas { get; set; } public int RightClickOnCanvas { get; set; } public int MiddleClickOnCanvas { get; set; } public bool UseWheelSwitchDesktopWhenOnTaskbar { get; set; } [PropertyProtector( 10, 1, 100 )] public int DragSizeFactor { get; set; } [PropertyProtector( 100, 100, 1000 )] public int TaskbarVisibilityThreshold { get; set; } } } ================================================ FILE: Configuration/Entity/Navigation.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . namespace VirtualSpace.Config.Entity { public class Navigation { public bool CirculationH { get; set; } public int CirculationHType { get; set; } public bool CirculationV { get; set; } } } ================================================ FILE: Configuration/Entity/UserInterface.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using VirtualSpace.Config.DataAnnotations; namespace VirtualSpace.Config.Entity { public class UserInterface { [PropertyProtector] public Colour? CanvasBackColor { get; set; } [PropertyProtector] public Colour? VDWDefaultBackColor { get; set; } [PropertyProtector] public Colour? VDWCurrentBackColor { get; set; } [PropertyProtector] public Colour? VDWHighlightBackColor { get; set; } public float VDWDragTargetOpacity { get; set; } public string Language { get; set; } public bool ShowVdName { get; set; } = true; public bool ShowVdIndex { get; set; } = true; [PropertyProtector( 0, 0, 1 )] public int ShowVdIndexType { get; set; } [PropertyProtector( 0, 0, 50 )] public int VDWPadding { get; set; } [PropertyProtector( 5, 0, 50 )] public int VDWBorderSize { get; set; } [PropertyProtector( 8, 8, 50 )] public int VDWMargin { get; set; } [PropertyProtector( 1, 1 )] public byte CanvasOpacity { get; set; } [PropertyProtector] public Margin? ThumbMargin { get; set; } public byte ThumbDragSourceOpacity { get; set; } [PropertyProtector( 0, 0, 7 )] public int? DesktopArrangement { get; set; } public int Theme { get; set; } } } ================================================ FILE: Configuration/Events/Entity/ExpressionTemplate.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; namespace VirtualSpace.Config.Events.Entity { public class ExpressionTemplate { public Guid id { get; set; } = Guid.NewGuid(); public string? condition { get; set; } public List? rules { get; set; } public string? type { get; set; } public string? field { get; set; } public string? @operator { get; set; } public Value? value { get; set; } } public class Value { public string? V { get; set; } public List? L { get; set; } } } ================================================ FILE: Configuration/Events/Entity/RuleTemplate.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Text.Json; using PropertyChanged; namespace VirtualSpace.Config.Events.Entity { [AddINotifyPropertyChangedInterface] public partial class RuleTemplate { [DoNotNotify] public Guid Id { get; set; } = Guid.NewGuid(); [DoNotNotify] public string? Name { get; set; } [DoNotNotify] public string? Tag { get; set; } [DoNotNotify] public int Weight { get; set; } = 50; public bool Enabled { get; set; } public bool ContinueAfterHit { get; set; } [DoNotNotify] public Func? Exp; [DoNotNotify] public JsonDocument? Expression { get; set; } [DoNotNotify] public Behavior? Action { get; set; } public DateTime? Created { get; set; } public DateTime? Updated { get; set; } } public static class RuleFields { public const string Title = nameof( Title ); public const string ProcessName = nameof( ProcessName ); public const string ProcessPath = nameof( ProcessPath ); public const string CommandLine = nameof( CommandLine ); public const string WndClass = nameof( WndClass ); public const string WinInScreen = nameof( WinInScreen ); } } ================================================ FILE: Configuration/Events/Expression/Conditions.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Json.Serialization; using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; using System.Windows.Forms; using LinqExpressionBuilder; using VirtualSpace.AppLogs; using VirtualSpace.Commons; using VirtualSpace.Config.Events.Entity; using VirtualSpace.Helpers; using Process = System.Diagnostics.Process; namespace VirtualSpace.Config.Events.Expression { public static partial class Conditions { private static readonly JsonParser Jp = new(); private static List _rules; private static readonly Channel ActionProducer = Channels.ActionChannel; private static readonly Channel VisibleWindowsConsumer = Channels.VisibleWindowsChannel; private static readonly ConcurrentDictionary WindowCheckTimes = new(); public static readonly ConcurrentBag WndHandleIgnoreListByRule = new(); private static long _updateRuleLock; static Conditions() { _rules = InitRules(); BuildRuleExp( _rules ); RuleChecker(); } private static async void RuleChecker() { while ( await VisibleWindowsConsumer.Reader.WaitToReadAsync() ) { if ( VisibleWindowsConsumer.Reader.TryRead( out var win ) ) { CheckRulesForWindow( win ); } } } private static List InitRules() { var path = Manager.GetRuleFilePath(); var rules = new List(); if ( !File.Exists( path ) ) return rules; rules = ReadRuleFromFile( path ); return rules; } private static void BuildRuleExp( List rules ) { foreach ( var rule in rules ) { rule.Exp = Jp.ExpressionFromJsonDoc( rule.Expression ); } _rules.Sort( ( x, y ) => -x.Weight.CompareTo( y.Weight ) ); } public static List FetchRules() { return _rules; } private static async void CheckRulesForWindow( Window win ) { if ( _rules.Count == 0 || Interlocked.Read( ref _updateRuleLock ) != 0 ) return; var rules = new List( _rules ); WindowCheckTimes.TryAdd( win.Handle, 0 ); var isOnePeriod = WindowCheckTimes[win.Handle] % Const.WindowCheckTimesLimit == 0; if ( isOnePeriod ) { Logger.Debug( $"Checking rules for {win.Title}, current profile: {Manager.Configs.CurrentProfileName}" ); } await Task.Run( () => { _ = User32.GetWindowThreadProcessId( win.Handle, out var pId ); using var pInfo = Process.GetProcessById( pId ); win.ProcessName = pInfo.ProcessName; try { win.ProcessPath = pInfo.MainModule?.FileName; win.CommandLine = pInfo.GetCommandLineArgs(); } catch ( Exception ex ) { Logger.Warning( "Get Process Info: " + ex.Message ); } var screen = Screen.FromHandle( win.Handle ); var screenIndex = 0; var allScreens = Screen.AllScreens; for ( var i = 0; i < allScreens.Length; i++ ) { if ( screen.DeviceName == allScreens[i].DeviceName ) { screenIndex = i; break; } } win.WinInScreen = screenIndex.ToString(); if ( !User32.IsWindow( win.Handle ) ) return; var hasMatchedRule = false; var l = new List(); foreach ( var r in rules ) { if ( !r.Enabled ) continue; l.Add( win ); var match = l.Where( r.Exp ).Any(); l.Clear(); if ( match ) { hasMatchedRule = true; Logger.Debug( win.Title + $" match rule [{r.Name}]" ); r.Action.Handle = win.Handle; r.Action.RuleName = r.Name; r.Action.WindowTitle = win.Title; ActionProducer.Writer.TryWrite( r.Action ); //////////////////////////////////////////////////////////////// // 某个窗口可能与多条规则匹配,继续循环就表示所有相应的动作都会按顺序执行 // 最终的方案:给规则添加一个属性,用于指定是否在匹配到规则后继续检查其他规则 // 默认为 false,即匹配到规则后立即退出循环 if ( !r.ContinueAfterHit ) break; } } if ( hasMatchedRule ) { WndHandleIgnoreListByRule.Add( win.Handle ); return; } if ( isOnePeriod ) { Logger.Debug( $"Window [{win.Title}] has no matched rules." ); } if ( Manager.CurrentProfile.IgnoreWindowOnRuleCheckTimeout ) { if ( WindowCheckTimes[win.Handle] >= Const.WindowCheckTimesLimit ) { Logger.Debug( $"Try find rules for [{win.Title}] too many times, ignore the window." ); WndHandleIgnoreListByRule.Add( win.Handle ); } } WindowCheckTimes[win.Handle]++; } ).ConfigureAwait( false ); } private static List ReadRuleFromFile( string path ) { using var fs = new FileStream( path, FileMode.Open, FileAccess.Read ); var buffer = new byte[fs.Length]; _ = fs.Read( buffer, 0, (int)fs.Length ); var utf8Reader = new Utf8JsonReader( buffer ); var readOptions = GetJsonDeserializerOptions(); return JsonSerializer.Deserialize>( ref utf8Reader, readOptions ); } public static ExpressionTemplate ParseExpressionTemplate( JsonDocument doc ) { var readOptions = GetJsonDeserializerOptions(); return JsonSerializer.Deserialize( doc, readOptions ); } private static JsonSerializerOptions? _readOptions; private static JsonSerializerOptions? _writeOptions; private static JsonSerializerOptions GetJsonDeserializerOptions() { return _readOptions ??= new JsonSerializerOptions(); } public static JsonSerializerOptions GetJsonSerializerOptions() { return _writeOptions ??= new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; } public static async void SaveRules( List ruleList, string? path = null ) { Interlocked.Increment( ref _updateRuleLock ); _rules = ruleList; BuildRuleExp( _rules ); Interlocked.Decrement( ref _updateRuleLock ); path ??= Manager.GetRuleFilePath(); await File.WriteAllBytesAsync( path, JsonSerializer.SerializeToUtf8Bytes( ruleList, GetJsonSerializerOptions() ) ); Logger.Info( $"[RULE]Rules.{Manager.Configs.CurrentProfileName} Saved." ); } public static void SwitchRuleProfile() { Interlocked.Increment( ref _updateRuleLock ); _rules = InitRules(); BuildRuleExp( _rules ); Interlocked.Decrement( ref _updateRuleLock ); Logger.Info( $"[RULE]Switch Rule Profile: {Manager.Configs.CurrentProfileName}" ); } } } ================================================ FILE: Configuration/Events/Expression/Conditions.test.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ #if TEST_TEST_TEST using System; using System.Collections.Generic; using System.Text.Json; using LinqExpressionBuilder; using VirtualSpace.Config.Events.Entity; namespace VirtualSpace.Config.Events.Expression { public static partial class Conditions { private static void TestData( string path ) { var test1 = new ExpressionTemplate { field = RuleFields.Title, @operator = Keywords.EndsWith[0], type = Keywords.String, value = new Value {V = "Notepad3"} }; var test2 = new ExpressionTemplate { condition = Keywords.Or, rules = new List { new() { field = RuleFields.Title, @operator = Keywords.EndsWith[0], type = Keywords.String, value = new Value {V = "Notepad3"} }, new() { field = RuleFields.Title, @operator = Keywords.Contains[0], type = Keywords.String, value = new Value {V = "炉石传说"} } } }; var writeOptions = GetJsonSerializerOptions(); var tempE1 = new RuleTemplate { Name = "test1", Expression = JsonDocument.Parse( JsonSerializer.Serialize( test1, writeOptions ) ), Action = new Behavior {MoveToDesktop = 1}, Enabled = true, Created = new DateTime( 2021, 10, 11 ) }; var tempE2 = new RuleTemplate { Name = "test2", Expression = JsonDocument.Parse( JsonSerializer.Serialize( test2, writeOptions ) ), Action = new Behavior {MoveToDesktop = 2}, Enabled = true, Created = DateTime.Now }; SaveRules( path, new List {tempE1, tempE2} ); } } } #endif ================================================ FILE: Configuration/FodyWeavers.xml ================================================  ================================================ FILE: Configuration/Manager.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; using System.Text.Json; using System.Threading.Tasks; using System.Windows; using Microsoft.Win32; using VirtualSpace.AppLogs; using VirtualSpace.Config.Converter; using VirtualSpace.Config.DataAnnotations; using VirtualSpace.Config.Entity; using VirtualSpace.Config.Events.Expression; using VirtualSpace.Config.Profiles; using Settings = VirtualSpace.Config.Const.Settings; namespace VirtualSpace.Config { public static class Manager { public static ConfigTemplate Configs; public static string AppPath; public static string AppRootFolder; public static string ProfileFolder; public static string CacheFolder; public static string PluginsFolder; public static string ConfigRootFolder; public static string ConfigFilePath; public static Profile CurrentProfile => Configs.Profiles[Configs.CurrentProfileName]; public static bool Init() { try { AppPath = Environment.ProcessPath!; AppRootFolder = Directory.GetParent( AppPath )!.FullName; ConfigRootFolder = GetConfigRoot(); ConfigFilePath = Path.Combine( ConfigRootFolder, Settings.SettingsFile ); CheckFolders(); InitConfig( ConfigFilePath ); LogManager.SetLogLevel( Configs.LogConfig.LogLevel ); } catch ( Exception ex ) { MessageBox.Show( "File Access Error.\n" + ex.Message, @"Error", MessageBoxButton.OK, MessageBoxImage.Error ); return false; } return true; } private static void InitConfig( string filePath ) { if ( File.Exists( filePath ) ) { using var fs = new FileStream( filePath, FileMode.Open, FileAccess.Read ); var buffer = new byte[fs.Length]; _ = fs.Read( buffer, 0, (int)fs.Length ); var utf8Reader = new Utf8JsonReader( buffer ); Configs = JsonSerializer.Deserialize( ref utf8Reader ); var cluster = ReadCluster(); if ( cluster is not null ) { Configs.Cluster = cluster; } PropertyProtector.Walk( Configs ); if ( Configs.MouseActions.Count == 0 ) { Logger.Info( "Missing MouseActions, Try find old version from configs." ); if ( Configs.MouseAction is null || Configs.MouseAction.Count == 0 ) { Logger.Info( "Old version MouseActions not found, Using native default." ); Configs.MouseActions = MouseAction.Info; } else { Logger.Info( "Old version MouseActions found, try to convert to new version." ); try { EntityConverter.ConvertMouseAction( Configs.MouseAction, Configs.MouseActions ); } catch { Logger.Info( "Convert MouseAction failed, Using native default." ); Configs.MouseActions = MouseAction.Info; } } } Logger.Info( $"Settings File Loaded, Version: {Configs.Version}, Current Profile: {Configs.CurrentProfileName}" ); } else { Logger.Info( "Settings File Not Found, Create From Default Template." ); Configs = new ConfigTemplate { CurrentProfileName = nameof( Default ), Version = Settings.DefaultVersion, LogConfig = new LogConfig {LogLevel = Settings.DefaultLogLevel}, Profiles = new Dictionary { {nameof( Default ), new Default()} }, MouseActions = MouseAction.Info }; PropertyProtector.Walk( Configs ); Save( filePath, "init", "Setting File" ); SaveCluster( Configs.Cluster ); } } public static async void Save( string? filePath = null, object? reason = null, [CallerArgumentExpression( "reason" )] string reasonName = "" ) { filePath ??= ConfigFilePath; try { var contents = JsonSerializer.SerializeToUtf8Bytes( Configs, JsonWriteOptions ); await File.WriteAllBytesAsync( filePath, contents ).ConfigureAwait( false ); Logger.Info( $"Settings Saved [{reasonName}: {reason}]." ); if ( reasonName.Contains( ".Configs.Cluster" ) ) SaveCluster( Configs.Cluster ); } catch ( Exception ex ) { Logger.Error( "Failed to save Settings: " + ex.Message ); } } public static async void SwitchProfile( string name ) { Configs.CurrentProfileName = name; var cluster = ReadCluster(); // after CurrentProfileName changed if ( cluster is not null ) { Configs.Cluster = cluster; } Conditions.SwitchRuleProfile(); // after CurrentProfileName changed try { var contents = JsonSerializer.SerializeToUtf8Bytes( Configs, JsonWriteOptions ); await File.WriteAllBytesAsync( ConfigFilePath, contents ).ConfigureAwait( false ); Logger.Info( $"[Profile]Switch: {name}" ); } catch ( Exception ex ) { Logger.Error( "Failed to save Settings: " + ex.Message ); } ProfileChanged?.Invoke( null, null ); } public static event EventHandler? ProfileChanged; public static void SaveCluster( Cluster cluster ) { SaveProfile( Path.Combine( ProfileFolder, Configs.CurrentProfileName + Settings.ClusterFileExt ), cluster ); } private static Cluster? ReadCluster() { return ReadProfile( Path.Combine( ProfileFolder, Configs.CurrentProfileName + Settings.ClusterFileExt ) ); } private static async void SaveProfile( string path, T p ) { try { var content = JsonSerializer.SerializeToUtf8Bytes( p, JsonWriteOptions ); await File.WriteAllBytesAsync( path, content ); Logger.Info( $"[Profile]{typeof( T ).Name}.{Configs.CurrentProfileName} Saved." ); } catch ( Exception ex ) { Logger.Error( $"Failed to save profile of {typeof( T ).Name}: {ex.Message}" ); } } private static T? ReadProfile( string path ) { if ( !File.Exists( path ) ) return default; try { using var fs = new FileStream( path, FileMode.Open, FileAccess.Read ); var buffer = new byte[fs.Length]; _ = fs.Read( buffer, 0, (int)fs.Length ); var utf8Reader = new Utf8JsonReader( buffer ); return JsonSerializer.Deserialize( ref utf8Reader ); } catch ( Exception ex ) { Logger.Error( $"Failed to read profile of {typeof( T ).Name}: {ex.Message}" ); return default; } } public static async void DeleteFilesOfProfile( string profileName ) { var dir = new DirectoryInfo( ProfileFolder ); await Task.Run( () => { try { foreach ( var file in dir.EnumerateFiles( profileName + ".*" ) ) // such violent { file.Delete(); } } catch ( Exception ex ) { Logger.Error( $"Failed to delete related files of profile {profileName}: {ex.Message}" ); } } ); } public static void SetConfigRoot( string path ) { using var vsReg = Registry.CurrentUser.CreateSubKey( Const.Reg.RegKeyApp ); vsReg.SetValue( Const.Reg.RegKeyConfigRoot, path ); ConfigRootFolder = path; } private static string GetConfigRoot() { using var vsReg = Registry.CurrentUser.CreateSubKey( Const.Reg.RegKeyApp ); var configRootReg = vsReg.GetValue( Const.Reg.RegKeyConfigRoot ); if ( configRootReg is null || !Directory.Exists( configRootReg.ToString() ) ) { return AppRootFolder; } return configRootReg.ToString(); } private static void CheckFolders() { ProfileFolder = Path.Combine( ConfigRootFolder, Settings.ProfilesFolder ); Directory.CreateDirectory( ProfileFolder ); CacheFolder = Path.Combine( AppRootFolder, Settings.CacheFolder ); Directory.CreateDirectory( CacheFolder ); PluginsFolder = Path.Combine( AppRootFolder, Settings.PluginsFolder ); Directory.CreateDirectory( PluginsFolder ); } public static string GetRuleFilePath( string? profile = null ) { CheckFolders(); return string.IsNullOrEmpty( profile ) ? Path.Combine( ProfileFolder, Configs.CurrentProfileName + Settings.RuleFileExt ) : Path.Combine( ProfileFolder, profile + Settings.RuleFileExt ); } public static string GetCachePath() { CheckFolders(); return CacheFolder; } public static string GetPluginsPath() { CheckFolders(); return PluginsFolder; } private static readonly JsonSerializerOptions JsonWriteOptions = new() {WriteIndented = true}; } } ================================================ FILE: Configuration/Profile.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.Text.Json; using VirtualSpace.Config.DataAnnotations; using VirtualSpace.Config.Entity; namespace VirtualSpace.Config { public class Profile { [PropertyProtector] public UserInterface UI { get; set; } public bool DaemonAutoStart { get; set; } [PropertyProtector( 0, 0, 3600 )] public int DaemonAutoStartDelay { get; set; } public List? DesktopOrder { get; set; } [PropertyProtector] public Mouse Mouse { get; set; } public bool IgnoreWindowOnRuleCheckTimeout { get; set; } = true; public Navigation Navigation { get; set; } = new() { CirculationH = false, CirculationV = false, CirculationHType = 0 }; public Profile Clone() { var profile = JsonSerializer.Deserialize( JsonSerializer.Serialize( this ) ); return profile!; } } } ================================================ FILE: Configuration/Profiles/Default.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System.Drawing; using VirtualSpace.Config.Entity; namespace VirtualSpace.Config.Profiles { public class Default : Profile { public Default() { UI = new UserInterface { CanvasOpacity = 100, CanvasBackColor = new Colour {R = 55, G = 55, B = 55}, VDWMargin = 8, VDWBorderSize = 1, VDWPadding = 0, VDWDefaultBackColor = new Colour {R = 55, G = 55, B = 55}, VDWCurrentBackColor = new Colour {R = Color.Beige.R, G = Color.Beige.G, B = Color.Beige.B}, VDWHighlightBackColor = new Colour {R = Color.Tomato.R, G = Color.Tomato.G, B = Color.Tomato.B}, VDWDragTargetOpacity = 0.8f, ThumbMargin = new Margin {Top = 20, Left = 10}, ThumbDragSourceOpacity = 150, Language = "en", DesktopArrangement = 0, ShowVdName = true, ShowVdIndex = true, ShowVdIndexType = 0 }; DaemonAutoStart = true; Mouse = new Mouse { DragSizeFactor = 10, LeftClickOnCanvas = 1, RightClickOnCanvas = 0, MiddleClickOnCanvas = 0, UseWheelSwitchDesktopWhenOnTaskbar = false, TaskbarVisibilityThreshold = 100 }; Navigation = new Navigation { CirculationH = false, CirculationV = false, CirculationHType = 0 }; } } } ================================================ FILE: Helpers/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Helpers/DwmApi.cs ================================================ using System; using System.Runtime.InteropServices; namespace VirtualSpace.Helpers { public static class DwmApi { [Flags] public enum DwmWindowAttribute : uint { /// /// Determines whether non-client rendering is enabled. Use this value only with DwmGetWindowAttribute. The retrieved value is of type BOOL. TRUE if non-client /// rendering is enabled; otherwise, FALSE. /// DWMWA_NCRENDERING_ENABLED = 1, /// /// The non-client rendering policy. Use this value only with DwmSetWindowAttribute, with its pvAttribute pointing to a value from the DWMNCRENDERINGPOLICY /// enumeration. /// DWMWA_NCRENDERING_POLICY, /// /// Enable or forcibly disable DWM transitions. Use this value only with DwmSetWindowAttribute, with its pvAttribute pointing to a value of TRUE to disable /// transitions or FALSE to enable transitions. /// DWMWA_TRANSITIONS_FORCEDISABLED, /// /// Allow content rendered in the non-client area to be visible on the frame drawn by DWM. Use this value only with DwmSetWindowAttribute, with its pvAttribute /// pointing to a value of TRUE to allow content rendered in the non-client area to be visible on the frame; otherwise, FALSE. /// DWMWA_ALLOW_NCPAINT, /// /// Retrieves the bounds of the caption button area in the window-relative space. Use this value only with DwmGetWindowAttribute. The retrieved value is of /// type RECT. /// DWMWA_CAPTION_BUTTON_BOUNDS, /// /// Specifies whether non-client content is right-to-left (RTL) mirrored. Use this value only with DwmSetWindowAttribute, with its pvAttribute pointing to a /// value of TRUE if the non-client content is right-to-left (RTL) mirrored; otherwise, FALSE. /// DWMWA_NONCLIENT_RTL_LAYOUT, /// /// Force the window to display an iconic thumbnail or peek representation (a static bitmap), even if a live or snapshot representation of the window is /// available. This value normally is set during a window's creation and not changed throughout the window's lifetime. Some scenarios, however, might require /// the value to change over time. Use this value only with DwmSetWindowAttribute, with its pvAttribute pointing to a value of TRUE to require a iconic /// thumbnail or peek representation; otherwise, FALSE. /// DWMWA_FORCE_ICONIC_REPRESENTATION, /// /// Sets how Flip3D treats the window. Use this value only with DwmSetWindowAttribute, with its pvAttribute pointing to a value from the DWMFLIP3DWINDOWPOLICY /// enumeration. /// DWMWA_FLIP3D_POLICY, /// /// Retrieves the extended frame bounds rectangle in screen space. Use this value only with DwmGetWindowAttribute. The retrieved value is of type RECT. /// DWMWA_EXTENDED_FRAME_BOUNDS, /// /// The window can provide a bitmap for use by DWM as an iconic thumbnail or peek representation (a static bitmap) for the window. This value can be specified /// with DWMWA_FORCE_ICONIC_REPRESENTATION. This value normally is set during a window's creation and not changed throughout the window's lifetime. Some /// scenarios, however, might require the value to change over time. Use this value only with DwmSetWindowAttribute, with its pvAttribute pointing to a value /// of TRUE to inform DWM that the window will provide an iconic thumbnail or peek representation; otherwise, FALSE. /// DWMWA_HAS_ICONIC_BITMAP, /// /// Do not show peek preview for the window. The peek view shows a full-sized preview of the window when the mouse hovers over the window's thumbnail in the /// taskbar. If this attribute is set, hovering the mouse pointer over the window's thumbnail dismisses peek (in case another window in the group has a peek /// preview showing). Use this value only with DwmSetWindowAttribute, with its pvAttribute pointing to a value of TRUE to prevent peek functionality; FALSE to /// allow it. /// DWMWA_DISALLOW_PEEK, /// /// Prevents a window from fading to a glass sheet when peek is invoked. Use this value only with DwmSetWindowAttribute, with its pvAttribute pointing to a /// value of TRUE to prevent the window from fading during another window's peek; FALSE for normal behavior. /// DWMWA_EXCLUDED_FROM_PEEK, /// /// Do not use. /// DWMWA_CLOAK, /// /// Use with DwmGetWindowAttribute. /// DWMWA_CLOAKED, /// /// Use with DwmSetWindowAttribute. Freeze the window's thumbnail image with its current visuals. Do no further live updates on the thumbnail image to match /// the window's contents. /// DWMWA_FREEZE_REPRESENTATION, /// /// The maximum recognized DWMWA value, used for validation purposes. /// DWMWA_LAST } public static readonly int DWM_TNP_VISIBLE = 0x8; public static readonly int DWM_TNP_OPACITY = 0x4; public static readonly int DWM_TNP_RECTDESTINATION = 0x1; [DllImport( "dwmapi.dll" )] public static extern int DwmRegisterThumbnail( IntPtr dest, IntPtr src, out IntPtr thumb ); [DllImport( "dwmapi.dll" )] public static extern int DwmUnregisterThumbnail( IntPtr thumb ); [DllImport( "dwmapi.dll" )] public static extern int DwmQueryThumbnailSourceSize( IntPtr thumb, out SIZE size ); [DllImport( "dwmapi.dll" )] public static extern int DwmUpdateThumbnailProperties( IntPtr hThumb, ref DWM_THUMBNAIL_PROPERTIES props ); [DllImport( "dwmapi.dll" )] public static extern int DwmGetWindowAttribute( IntPtr hWnd, uint dwAttribute, out int pvAttribute, int cbAttribute ); } [StructLayout( LayoutKind.Sequential )] public struct DWM_THUMBNAIL_PROPERTIES { public int dwFlags; public RECT rcDestination; public RECT rcSource; public byte opacity; public bool fVisible; public bool fSourceClientAreaOnly; } } ================================================ FILE: Helpers/GlobalHotKey.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.Runtime.InteropServices; namespace VirtualSpace.Helpers { public static class GlobalHotKey { [Flags] public enum KeyModifiers { None = 0, Alt = 1, Ctrl = 2, Shift = 4, WindowsKey = 8 } private static IntPtr _handle = IntPtr.Zero; private static readonly List Ids = new(); public static bool RegHotKey( IntPtr hWnd, int id, KeyModifiers fsModifiers, int vk ) { _handle = hWnd; Ids.Add( id ); return RegisterHotKey( hWnd, id, fsModifiers, vk ); } [DllImport( "user32.dll", SetLastError = true )] private static extern bool RegisterHotKey( IntPtr hWnd, int id, KeyModifiers fsModifiers, int vk ); [DllImport( "user32.dll", SetLastError = true )] public static extern bool UnregisterHotKey( IntPtr hWnd, int id ); public static void UnRegAllHotKey() { foreach ( var id in Ids ) { UnregisterHotKey( _handle, id ); } } } } ================================================ FILE: Helpers/Helpers.csproj ================================================  net6.0-windows enable True 9 ================================================ FILE: Helpers/Images.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using VirtualSpace.AppLogs; namespace VirtualSpace.Helpers { internal static class PathInfo { public const string WIDTH_HEIGHT_SPLITTER = "x"; } public static class Images { public static Bitmap GetScaledBitmap( int width, int height, string path, ref Wallpaper wp, string cachePath, long quality ) { var cached = Wallpaper.CachedWallPaper( path, cachePath, width, height ); if ( cached != null ) return cached; using ( var src = new Bitmap( path ) ) { var dest = new Bitmap( width, height, PixelFormat.Format32bppPArgb ); using ( var gr = Graphics.FromImage( dest ) ) { gr.DrawImage( src, new Rectangle( Point.Empty, dest.Size ) ); } var md5Path = Wallpaper.Md5Hash( path ); var file = Path.Combine( cachePath, md5Path.Str0, md5Path.Str1, width + PathInfo.WIDTH_HEIGHT_SPLITTER + height, md5Path.FullString + "_" + Environment.CurrentManagedThreadId ); // dest.Save( file, ImageFormat.Jpeg ); var jpgEncoder = GetEncoder( ImageFormat.Jpeg ); var encoder = System.Drawing.Imaging.Encoder.Quality; var encoderParameters = new EncoderParameters( 1 ); var encoderParameter = new EncoderParameter( encoder, quality ); encoderParameters.Param[0] = encoderParameter; dest.Save( file, jpgEncoder, encoderParameters ); wp.Fullpath = file; return dest; } } private static ImageCodecInfo GetEncoder( ImageFormat format ) { var codecs = ImageCodecInfo.GetImageEncoders(); foreach ( var codec in codecs ) { if ( codec.FormatID == format.Guid ) { return codec; } } return null; } public static Icon BytesToIcon( object bytes ) { using var ms = new MemoryStream( (byte[])bytes ); return new Icon( ms ); } public static Bitmap BytesToBitmap( object bytes ) { using var ms = new MemoryStream( (byte[])bytes ); return new Bitmap( ms ); } } public class Wallpaper { public Bitmap? Image { get; set; } public Color Color { get; set; } public string? Fullpath { get; set; } public static Bitmap? CachedWallPaper( string path, string cachePath, int width, int height ) { var cached = CachedWallPaperInfo( path, cachePath, width, height ); return cached.Exists ? new Bitmap( cached.Path ) : null; } public static (bool Exists, string Path) CachedWallPaperInfo( string path, string cachePath, int width, int height ) { var md5Path = Md5Hash( path ); var targetPath = Path.Combine( cachePath, md5Path.Str0, md5Path.Str1, width + PathInfo.WIDTH_HEIGHT_SPLITTER + height ); Directory.CreateDirectory( targetPath ); var filepath = Path.Combine( targetPath, md5Path.FullString ); return new ValueTuple( File.Exists( filepath ), filepath ); } public static (string FullString, string Str0, string Str1) Md5Hash( string input ) { var md5 = MD5.Create(); var inputBytes = Encoding.ASCII.GetBytes( input ); var hashBytes = md5.ComputeHash( inputBytes ); var sb = new StringBuilder(); foreach ( var b in hashBytes ) { sb.Append( b.ToString( "x2" ) ); } var md5Str = sb.ToString(); return new ValueTuple( md5Str, md5Str.Substring( 0, 1 ), md5Str.Substring( 1, 1 ) ); } public void Release() { Image?.Dispose(); Image = null; if ( string.IsNullOrEmpty( Fullpath ) ) return; try { var file = Regex.Replace( Fullpath, @"(.*?)_\d+$", "$1" ); if ( !File.Exists( file ) ) File.Move( Fullpath, file ); } catch ( Exception ex ) { Logger.Warning( "Delete cache file: " + ex.Message ); } finally { File.Delete( Fullpath ); } } } } ================================================ FILE: Helpers/Kernel32.cs ================================================ using System; using System.Runtime.InteropServices; namespace VirtualSpace.Helpers { public static class Kernel32 { [DllImport( "kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true )] public static extern IntPtr GetModuleHandle( string lpModuleName ); } } ================================================ FILE: Helpers/LowLevelHooks.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Windows.Forms; namespace VirtualSpace.Helpers { public static class LowLevelHooks { public static readonly IntPtr Handled = (IntPtr)1; } public static class LowLevelKeyboardHook { public const int WM_KEYDOWN = 0x0100; public const int WM_KEYUP = 0x0101; public const int DUMMY_KEY = 0xFF; private const int WH_KEYBOARD_LL = 13; private static User32.HookProc _hookProc; public static IntPtr HookId { get; private set; } = IntPtr.Zero; public static void SetHook( User32.HookProc proc ) { _hookProc = proc; HookId = User32.SetWindowsHookEx( WH_KEYBOARD_LL, _hookProc, Kernel32.GetModuleHandle( null ), 0 ); } public static void MultipleKeyDown( List keys ) { SendKeys( keys, 0 ); } public static void MultipleKeyUp( List keys ) { SendKeys( keys, KEYEVENTF.KEYUP ); } public static void MultipleKeyPress( List keys ) { SendKeysCombine( keys ); } private static void SendKeys( List keys, KEYEVENTF flags ) { var inputs = new INPUT[keys.Count]; for ( var pos = 0; pos < keys.Count; pos++ ) { inputs[pos].Type = InputType.INPUT_KEYBOARD; inputs[pos].Data.Keyboard = new KEYBDINPUT { Vk = (ushort)keys[pos], Scan = 0, Flags = flags, Time = 0, ExtraInfo = IntPtr.Zero }; } var result = User32.SendInput( Convert.ToUInt32( inputs.Length ), inputs, Marshal.SizeOf( typeof( INPUT ) ) ); if ( result == 0 ) throw new Exception(); } private static void SendKeysCombine( List keys ) { var inputs = new INPUT[keys.Count * 2]; for ( var i = 0; i < keys.Count; i++ ) { inputs[i].Type = InputType.INPUT_KEYBOARD; inputs[i].Data.Keyboard = new KEYBDINPUT { Vk = (ushort)keys[i], Scan = 0, Flags = 0, Time = 0, ExtraInfo = IntPtr.Zero }; inputs[inputs.Length - i - 1].Type = InputType.INPUT_KEYBOARD; inputs[inputs.Length - i - 1].Data.Keyboard = new KEYBDINPUT { Vk = (ushort)keys[i], Scan = 0, Flags = KEYEVENTF.KEYUP, Time = 0, ExtraInfo = IntPtr.Zero }; } var result = User32.SendInput( Convert.ToUInt32( inputs.Length ), inputs, Marshal.SizeOf( typeof( INPUT ) ) ); if ( result == 0 ) throw new Exception(); } public static bool IsKeyHold( Keys key ) { return User32.GetAsyncKeyState( (int)key ) < 0; } public static void UnHook() { User32.UnhookWindowsHookEx( HookId ); } public struct KBDLLHOOKSTRUCT { public int vkCode; private int scanCode; public KBDLLHOOKSTRUCTFlags flags; private int time; private int dwExtraInfo; } [Flags] public enum KBDLLHOOKSTRUCTFlags : uint { LLKHF_EXTENDED = 0x01, LLKHF_INJECTED = 0x10, LLKHF_ALTDOWN = 0x20, LLKHF_UP = 0x80, } } public static class LowLevelMouseHook { private const int WH_MOUSE_LL = 14; public const int WM_MOUSEWHEEL = 0x020A; private static User32.HookProc _hookProc; public static IntPtr HookId { get; private set; } = IntPtr.Zero; public static void SetHook( User32.HookProc proc ) { _hookProc = proc; HookId = User32.SetWindowsHookEx( WH_MOUSE_LL, _hookProc, Kernel32.GetModuleHandle( null ), 0 ); } public static void UnHook() { User32.UnhookWindowsHookEx( HookId ); } [StructLayout( LayoutKind.Sequential )] public struct MSLLHOOKSTRUCT { public POINT pt; public int mouseData; // be careful, this must be ints, not uints. public int flags; public int time; public UIntPtr dwExtraInfo; } } } ================================================ FILE: Helpers/StringHelper.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Text.RegularExpressions; namespace VirtualSpace.Helpers { public static class StringHelper { public static bool IsValidRegex( string pattern ) { if ( string.IsNullOrWhiteSpace( pattern ) ) return false; try { _ = Regex.Match( "", pattern ); } catch ( ArgumentException ) { return false; } return true; } } } ================================================ FILE: Helpers/SysInfo.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Security.Principal; using System.Windows.Forms; using Microsoft.Win32; using System.Management; using System.Runtime.CompilerServices; using System.Windows; [assembly: InternalsVisibleTo( "ControlPanel" )] namespace VirtualSpace.Helpers { public static class SysInfo { private const int DefaultDpi = 96; public static (float ScaleX, float ScaleY) Dpi => GetDpi(); public static readonly bool IsWin10; public static readonly bool IsAdministrator; static SysInfo() { IsWin10 = Environment.OSVersion.Version is {Major: 10, Build: < 22000}; var windowsPrincipal = new WindowsPrincipal( WindowsIdentity.GetCurrent() ); IsAdministrator = windowsPrincipal.IsInRole( WindowsBuiltInRole.Administrator ); } private static (float ScaleX, float ScaleY) GetDpi() { using var g = Graphics.FromHwnd( IntPtr.Zero ); return new ValueTuple( g.DpiX / DefaultDpi, g.DpiY / DefaultDpi ); } public static Version OSVersion { get { var winVer = Environment.OSVersion.Version; if ( winVer.Revision == 0 ) { using var registryKey = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\Windows NT\CurrentVersion" ); var ubr = registryKey?.GetValue( "UBR" ); if ( ubr != null ) { var buildNumber = int.Parse( ubr.ToString() ); winVer = new Version( winVer.Major, winVer.Minor, winVer.Build, buildNumber ); } } return winVer; } } public static (int W, int H) GetAspectRadioOfScreen() { var nGCD = GetGreatestCommonDivisor( Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height ); return new ValueTuple( Screen.PrimaryScreen.Bounds.Width / nGCD, Screen.PrimaryScreen.Bounds.Height / nGCD ); } private static int GetGreatestCommonDivisor( int a, int b ) { while ( true ) { if ( b == 0 ) return a; var a1 = a; a = b; b = a1 % b; } } public static bool IsTaskbarVisible() { return Math.Abs( SystemParameters.PrimaryScreenHeight - SystemParameters.WorkArea.Height ) > 0; } public enum WinAppsTheme { LIGHT, DARK } public static WinAppsTheme GetAppsTheme() { return WinRegistry.AppThemeIsLight() ? WinAppsTheme.LIGHT : WinAppsTheme.DARK; } private static RegValueMonitor _rkm = new( "HKEY_USERS", @"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme" ); public static List GetAllScreens() { var screens = new List(); var allScreens = Screen.AllScreens; for ( var i = 0; i < allScreens.Length; i++ ) { screens.Add( new {Value = i, Text = $"{allScreens[i].DeviceName} ({allScreens[i].DeviceFriendlyName()})"} ); } return screens; } } /// /// https://stackoverflow.com/questions/52875087/getting-device-friendly-name-incorrect-result /// public static class ScreenInterrogatory { private const int ERROR_SUCCESS = 0; private static string MonitorFriendlyName( LUID adapterId, uint targetId ) { var deviceName = new DISPLAYCONFIG_TARGET_DEVICE_NAME { header = { size = (uint)Marshal.SizeOf( typeof( DISPLAYCONFIG_TARGET_DEVICE_NAME ) ), adapterId = adapterId, id = targetId, type = DISPLAYCONFIG_DEVICE_INFO_TYPE.DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME } }; var error = DisplayConfigGetDeviceInfo( ref deviceName ); if ( error != ERROR_SUCCESS ) throw new Win32Exception( error ); return deviceName.monitorFriendlyDeviceName; } private static IEnumerable GetAllMonitorsFriendlyNames() { var error = GetDisplayConfigBufferSizes( QUERY_DEVICE_CONFIG_FLAGS.QDC_ONLY_ACTIVE_PATHS, out var pathCount, out var modeCount ); if ( error != ERROR_SUCCESS ) throw new Win32Exception( error ); var displayPaths = new DISPLAYCONFIG_PATH_INFO[pathCount]; var displayModes = new DISPLAYCONFIG_MODE_INFO[modeCount]; error = QueryDisplayConfig( QUERY_DEVICE_CONFIG_FLAGS.QDC_ONLY_ACTIVE_PATHS, ref pathCount, displayPaths, ref modeCount, displayModes, IntPtr.Zero ); if ( error != ERROR_SUCCESS ) throw new Win32Exception( error ); for ( var i = 0; i < modeCount; i++ ) if ( displayModes[i].infoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_TARGET ) yield return MonitorFriendlyName( displayModes[i].adapterId, displayModes[i].id ); } public static string DeviceFriendlyName( this Screen screen ) { var allFriendlyNames = GetAllMonitorsFriendlyNames(); for ( var index = 0; index < Screen.AllScreens.Length; index++ ) if ( Equals( screen, Screen.AllScreens[index] ) ) return allFriendlyNames.ToArray()[index]; return null; } #region enums public enum QUERY_DEVICE_CONFIG_FLAGS : uint { QDC_ALL_PATHS = 0x00000001, QDC_ONLY_ACTIVE_PATHS = 0x00000002, QDC_DATABASE_CURRENT = 0x00000004 } public enum DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY : uint { DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER = 0xFFFFFFFF, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15 = 0, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO = 1, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPOSITE_VIDEO = 2, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPONENT_VIDEO = 3, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DVI = 4, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI = 5, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_LVDS = 6, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_D_JPN = 8, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDI = 9, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EXTERNAL = 10, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED = 11, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EXTERNAL = 12, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED = 13, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDTVDONGLE = 14, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_MIRACAST = 15, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL = 0x80000000, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_FORCE_UINT32 = 0xFFFFFFFF } public enum DISPLAYCONFIG_SCANLINE_ORDERING : uint { DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED = 0, DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE = 1, DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED = 2, DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST = DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED, DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST = 3, DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32 = 0xFFFFFFFF } private enum DISPLAYCONFIG_ROTATION : uint { DISPLAYCONFIG_ROTATION_IDENTITY = 1, DISPLAYCONFIG_ROTATION_ROTATE90 = 2, DISPLAYCONFIG_ROTATION_ROTATE180 = 3, DISPLAYCONFIG_ROTATION_ROTATE270 = 4, DISPLAYCONFIG_ROTATION_FORCE_UINT32 = 0xFFFFFFFF } private enum DISPLAYCONFIG_SCALING : uint { DISPLAYCONFIG_SCALING_IDENTITY = 1, DISPLAYCONFIG_SCALING_CENTERED = 2, DISPLAYCONFIG_SCALING_STRETCHED = 3, DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX = 4, DISPLAYCONFIG_SCALING_CUSTOM = 5, DISPLAYCONFIG_SCALING_PREFERRED = 128, DISPLAYCONFIG_SCALING_FORCE_UINT32 = 0xFFFFFFFF } public enum DISPLAYCONFIG_PIXELFORMAT : uint { DISPLAYCONFIG_PIXELFORMAT_8BPP = 1, DISPLAYCONFIG_PIXELFORMAT_16BPP = 2, DISPLAYCONFIG_PIXELFORMAT_24BPP = 3, DISPLAYCONFIG_PIXELFORMAT_32BPP = 4, DISPLAYCONFIG_PIXELFORMAT_NONGDI = 5, DISPLAYCONFIG_PIXELFORMAT_FORCE_UINT32 = 0xffffffff } public enum DISPLAYCONFIG_MODE_INFO_TYPE : uint { DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE = 1, DISPLAYCONFIG_MODE_INFO_TYPE_TARGET = 2, DISPLAYCONFIG_MODE_INFO_TYPE_FORCE_UINT32 = 0xFFFFFFFF } public enum DISPLAYCONFIG_DEVICE_INFO_TYPE : uint { DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1, DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 2, DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE = 3, DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME = 4, DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE = 5, DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE = 6, DISPLAYCONFIG_DEVICE_INFO_FORCE_UINT32 = 0xFFFFFFFF } #endregion #region structs [StructLayout( LayoutKind.Sequential )] public struct LUID { public uint LowPart; public int HighPart; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_PATH_SOURCE_INFO { public LUID adapterId; public uint id; public uint modeInfoIdx; public uint statusFlags; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_PATH_TARGET_INFO { public LUID adapterId; public uint id; public uint modeInfoIdx; private readonly DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology; private readonly DISPLAYCONFIG_ROTATION rotation; private readonly DISPLAYCONFIG_SCALING scaling; private readonly DISPLAYCONFIG_RATIONAL refreshRate; private readonly DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering; public bool targetAvailable; public uint statusFlags; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_RATIONAL { public uint Numerator; public uint Denominator; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_PATH_INFO { public DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo; public DISPLAYCONFIG_PATH_TARGET_INFO targetInfo; public uint flags; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_2DREGION { public uint cx; public uint cy; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO { public ulong pixelRate; public DISPLAYCONFIG_RATIONAL hSyncFreq; public DISPLAYCONFIG_RATIONAL vSyncFreq; public DISPLAYCONFIG_2DREGION activeSize; public DISPLAYCONFIG_2DREGION totalSize; public uint videoStandard; public DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_TARGET_MODE { public DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo; } [StructLayout( LayoutKind.Sequential )] public struct POINTL { private readonly int x; private readonly int y; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_SOURCE_MODE { public uint width; public uint height; public DISPLAYCONFIG_PIXELFORMAT pixelFormat; public POINTL position; } [StructLayout( LayoutKind.Explicit )] public struct DISPLAYCONFIG_MODE_INFO_UNION { [FieldOffset( 0 )] public DISPLAYCONFIG_TARGET_MODE targetMode; [FieldOffset( 0 )] public DISPLAYCONFIG_SOURCE_MODE sourceMode; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_MODE_INFO { public DISPLAYCONFIG_MODE_INFO_TYPE infoType; public uint id; public LUID adapterId; public DISPLAYCONFIG_MODE_INFO_UNION modeInfo; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS { public uint value; } [StructLayout( LayoutKind.Sequential )] public struct DISPLAYCONFIG_DEVICE_INFO_HEADER { public DISPLAYCONFIG_DEVICE_INFO_TYPE type; public uint size; public LUID adapterId; public uint id; } [StructLayout( LayoutKind.Sequential, CharSet = CharSet.Unicode )] public struct DISPLAYCONFIG_TARGET_DEVICE_NAME { public DISPLAYCONFIG_DEVICE_INFO_HEADER header; public DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS flags; public DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology; public ushort edidManufactureId; public ushort edidProductCodeId; public uint connectorInstance; [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 64 )] public string monitorFriendlyDeviceName; [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 128 )] public string monitorDevicePath; } #endregion #region DLLImports [DllImport( "user32.dll" )] public static extern int GetDisplayConfigBufferSizes( QUERY_DEVICE_CONFIG_FLAGS flags, out uint numPathArrayElements, out uint numModeInfoArrayElements ); [DllImport( "user32.dll" )] public static extern int QueryDisplayConfig( QUERY_DEVICE_CONFIG_FLAGS flags, ref uint numPathArrayElements, [Out] DISPLAYCONFIG_PATH_INFO[] PathInfoArray, ref uint numModeInfoArrayElements, [Out] DISPLAYCONFIG_MODE_INFO[] ModeInfoArray, IntPtr currentTopologyId ); [DllImport( "user32.dll" )] public static extern int DisplayConfigGetDeviceInfo( ref DISPLAYCONFIG_TARGET_DEVICE_NAME deviceName ); #endregion } public static class ProcessTools { public static string GetCommandLineArgs( this Process process ) { if ( process is null ) throw new ArgumentNullException( nameof( process ) ); try { return GetCommandLineArgsCore(); } catch { return string.Empty; } string GetCommandLineArgsCore() { using var searcher = new ManagementObjectSearcher( $"SELECT CommandLine FROM Win32_Process WHERE ProcessId = {process.Id.ToString()}" ); using var objects = searcher.Get(); var obj = objects.Cast().SingleOrDefault(); return obj?["CommandLine"]?.ToString() ?? ""; } } } } ================================================ FILE: Helpers/TaskSchedulerHelper.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Diagnostics; using Microsoft.Win32.TaskScheduler; namespace VirtualSpace.Helpers { public static class TaskSchedulerHelper { public static void CreateAutoRunTask( string taskName, string fullAppPath, string taskFolder = "" ) { if ( !SysInfo.IsAdministrator ) { throw new Exception( "General.RunOnStartup.Error.Permission" ); } var td = TaskService.Instance.NewTask(); td.RegistrationInfo.Description = "autorun " + taskName + " at system startup."; td.Principal.RunLevel = TaskRunLevel.Highest; td.Principal.LogonType = TaskLogonType.InteractiveToken; td.Settings.ExecutionTimeLimit = TimeSpan.FromSeconds( 0 ); var lt = new LogonTrigger(); lt.Delay = TimeSpan.FromSeconds( 5 ); td.Triggers.Add( lt ); var ea = new ExecAction( fullAppPath, "" ); td.Actions.Add( ea ); TaskService.Instance.RootFolder.RegisterTaskDefinition( GetTaskPath( taskName, taskFolder ), td ); } public static void DeleteTaskByName( string taskName, string taskFolder = "" ) { if ( !SysInfo.IsAdministrator ) { throw new Exception( "General.RunOnStartup.Error.Permission" ); } using var ts = new TaskService(); ts.RootFolder.DeleteTask( GetTaskPath( taskName, taskFolder ) ); } public static bool IsTaskExistsByName( string taskName, string taskFolder = "" ) { using var ts = new TaskService(); var t = ts.GetTask( GetTaskPath( taskName, taskFolder ) ); return t != null; } private static string GetTaskPath( string taskName, string taskFolder ) { return string.IsNullOrEmpty( taskFolder ) ? taskName : taskFolder + @"\" + taskName; } public static void OpenWinTaskScheduler() { var psi = new ProcessStartInfo { FileName = "taskschd.msc", UseShellExecute = true }; Process.Start( psi ); } } } ================================================ FILE: Helpers/User32.cs ================================================ using System; using System.Runtime.InteropServices; using System.Text; namespace VirtualSpace.Helpers { public static class User32 { public delegate bool EnumChildWindowsProc( IntPtr hWnd, int lParam ); public delegate bool EnumWindowsProc( IntPtr hWnd, int lParam ); public delegate IntPtr HookProc( int nCode, IntPtr wParam, IntPtr lParam ); [DllImport( "user32.dll", SetLastError = true )] public static extern IntPtr FindWindow( string lpClassName, string lpWindowName ); [DllImport( "user32.dll", CharSet = CharSet.Auto )] public static extern int GetWindowLong( IntPtr hWnd, int nIndex ); [DllImport( "user32.dll", SetLastError = true )] public static extern IntPtr GetWindow( IntPtr hWnd, GetWindowType uCmd ); [DllImport( "user32.dll" )] [return: MarshalAs( UnmanagedType.Bool )] public static extern bool IsWindowEnabled( IntPtr hWnd ); [DllImport( "user32.dll", CharSet = CharSet.Auto )] public static extern bool PostMessage( IntPtr hWnd, int msg, ulong wParam, ulong lParam ); [DllImport( "user32.dll", CharSet = CharSet.Auto )] public static extern bool SendMessage( IntPtr hWnd, int msg, ulong wParam, ulong lParam ); public static IntPtr SetWindowLongPtr( HandleRef hWnd, int nIndex, int dwNewLong ) { if ( IntPtr.Size == 8 ) return SetWindowLongPtr64( hWnd, nIndex, (IntPtr)dwNewLong ); else return new IntPtr( SetWindowLong32( hWnd, nIndex, dwNewLong ) ); } [DllImport( "user32.dll", EntryPoint = "SetWindowLong" )] private static extern int SetWindowLong32( HandleRef hWnd, int nIndex, int dwNewLong ); [DllImport( "user32.dll", EntryPoint = "SetWindowLongPtr" )] private static extern IntPtr SetWindowLongPtr64( HandleRef hWnd, int nIndex, IntPtr dwNewLong ); [DllImport( "user32.dll", CharSet = CharSet.Auto )] public static extern int ShowWindow( IntPtr hWnd, short cmdShow ); [DllImport( "user32.dll" )] public static extern int GetWindowText( IntPtr hWnd, StringBuilder buf, int nMaxCount ); [DllImport( "user32.dll", SetLastError = true, CharSet = CharSet.Auto )] public static extern int GetClassName( IntPtr hWnd, StringBuilder lpClassName, int nMaxCount ); [DllImport( "user32.dll" )] public static extern bool IsWindowVisible( IntPtr hWnd ); [DllImport( "user32.dll" )] [return: MarshalAs( UnmanagedType.Bool )] public static extern bool IsWindow( IntPtr hWnd ); [DllImport( "user32.dll" )] public static extern bool IsIconic( IntPtr hWnd ); [DllImport( "user32.dll" )] public static extern int EnumWindows( EnumWindowsProc func, int lParam ); [DllImport( "user32.dll" )] [return: MarshalAs( UnmanagedType.Bool )] public static extern bool EnumChildWindows( IntPtr hWndParent, EnumChildWindowsProc lpEnumFunc, int lParam ); [DllImport( "user32.dll" )] public static extern IntPtr GetForegroundWindow(); [DllImport( "user32.dll" )] [return: MarshalAs( UnmanagedType.Bool )] public static extern bool SetForegroundWindow( IntPtr hWnd ); [DllImport( "user32.dll", SetLastError = true )] public static extern bool BringWindowToTop( IntPtr hWnd ); [DllImport( "user32.dll", SetLastError = true )] public static extern IntPtr SetParent( IntPtr hWndChild, IntPtr hWndNewParent ); [DllImport( "user32.dll" )] public static extern int GetWindowThreadProcessId( IntPtr hWnd, out int processId ); [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )] public static extern IntPtr SetWindowsHookEx( int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId ); [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )] [return: MarshalAs( UnmanagedType.Bool )] public static extern bool UnhookWindowsHookEx( IntPtr hhk ); [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )] public static extern IntPtr CallNextHookEx( IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam ); [DllImport( "user32.dll" )] public static extern short GetAsyncKeyState( int vKey ); [DllImport( "user32.dll" )] public static extern short GetKeyState( int vKey ); [DllImport( "user32.dll", SetLastError = true )] public static extern uint SendInput( uint numberOfInputs, INPUT[] inputs, int sizeOfInputStructure ); [DllImport( "user32.dll", CharSet = CharSet.Unicode )] public static extern uint RegisterWindowMessage( string lpProcName ); [DllImport( "user32.dll" )] public static extern bool GetWindowRect( IntPtr hWnd, ref RECT rectangle ); [DllImport( "user32.dll" )] [return: MarshalAs( UnmanagedType.Bool )] public static extern bool SetWindowPos( IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SetWindowPosFlags uFlags ); [DllImport( "user32.dll", SetLastError = true )] [return: MarshalAs( UnmanagedType.Bool )] public static extern bool GetWindowPlacement( IntPtr hWnd, ref WINDOWPLACEMENT lpWndPl ); [DllImport( "Shell32.dll", SetLastError = false )] public static extern int SHGetStockIconInfo( SHSTOCKICONID siid, SHGSI uFlags, ref SHSTOCKICONINFO psii ); [DllImport( "user32.dll", SetLastError = true )] public static extern void SwitchToThisWindow( IntPtr hWnd, bool fAltTab ); } } ================================================ FILE: Helpers/UserMessage.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . namespace VirtualSpace.Helpers { public static class UserMessage { public const int RiseView = 1000; public const int ShowAppController = 1001; public const int AppControllerClosed = 1002; public const int SwitchDesktop = 1003; public const int DesktopArrangement = 1004; public const int RunAsAdministrator = 1005; public const int RestartApp = 1006; public const int EnableMouseHook = 1007; public const int DisableMouseHook = 1008; public const int RiseViewForActiveApp = 1009; public const int RestartAppController = 1010; public const int RiseViewForCurrentVD = 1011; public const int RiseViewForActiveAppInCurrentVD = 1012; public const int RefreshVdw = 1013; public const int SwitchBackToLastDesktop = 1014; public const int ShowVdw = 1015; public const int ShowThumbsOfVdw = 1016; public const int RefreshTrayIcon = 1017; public const int UpdateTrayLang = 1018; public const int ToggleWindowFilter = 1019; public const int NavLeft = 1201; public const int NavRight = 1202; public const int NavUp = 1203; public const int NavDown = 1204; public static class Meta { public const int SVD_START = 1100; public const int SVD_END = 1200; public const int MW_START = 1300; public const int MW_END = 1400; public const int MWF_START = 1500; public const int MWF_END = 1600; } } } ================================================ FILE: Helpers/VisualEffects.cs ================================================ using System; using System.Runtime.InteropServices; namespace VirtualSpace.Helpers { public static class VisualEffects { public enum AccentState { ACCENT_DISABLED = 0, ACCENT_ENABLE_GRADIENT = 1, ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, ACCENT_ENABLE_BLURBEHIND = 3, ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, ACCENT_INVALID_STATE = 5 } public enum WindowCompositionAttribute { // ... WCA_ACCENT_POLICY = 19 // ... } [DllImport( "user32.dll" )] public static extern int SetWindowCompositionAttribute( IntPtr hWnd, ref WindowCompositionAttributeData data ); [StructLayout( LayoutKind.Sequential )] public struct AccentPolicy { public AccentState AccentState; public uint AccentFlags; public uint GradientColor; public uint AnimationId; } [StructLayout( LayoutKind.Sequential )] public struct WindowCompositionAttributeData { public WindowCompositionAttribute Attribute; public IntPtr Data; public int SizeOfData; } } } ================================================ FILE: Helpers/Win32.cs ================================================ using System; using System.Runtime.InteropServices; namespace VirtualSpace.Helpers { /// /// Contains information about the placement of a window on the screen. /// [Serializable] [StructLayout( LayoutKind.Sequential )] public struct WINDOWPLACEMENT { /// /// The length of the structure, in bytes. Before calling the GetWindowPlacement or SetWindowPlacement functions, set this member to sizeof(WINDOWPLACEMENT). /// /// GetWindowPlacement and SetWindowPlacement fail if this member is not set correctly. /// /// public int Length; /// /// Specifies flags that control the position of the minimized window and the method by which the window is restored. /// public int Flags; /// /// The current show state of the window. /// public ShowState ShowCmd; /// /// The coordinates of the window's upper-left corner when the window is minimized. /// public POINT MinPosition; /// /// The coordinates of the window's upper-left corner when the window is maximized. /// public POINT MaxPosition; /// /// The window's coordinates when the window is in the restored position. /// public RECT NormalPosition; /// /// Gets the default (empty) value. /// public static WINDOWPLACEMENT Default { get { var result = new WINDOWPLACEMENT(); result.Length = Marshal.SizeOf( result ); return result; } } } public enum ShowState : int { SW_HIDE = 0, SW_SHOWNORMAL = 1, SW_NORMAL = 1, SW_SHOWMINIMIZED = 2, SW_SHOWMAXIMIZED = 3, SW_MAXIMIZE = 3, SW_SHOWNOACTIVATE = 4, SW_SHOW = 5, SW_MINIMIZE = 6, SW_SHOWMINNOACTIVE = 7, SW_SHOWNA = 8, SW_RESTORE = 9, SW_SHOWDEFAULT = 10, SW_FORCEMINIMIZE = 11 } [StructLayout( LayoutKind.Sequential )] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; public RECT( int left, int top, int right, int bottom ) { Left = left; Top = top; Right = right; Bottom = bottom; } } [StructLayout( LayoutKind.Sequential )] public struct SIZE { public int cx; public int cy; } [StructLayout( LayoutKind.Sequential )] public struct POINT { public int X; public int Y; public POINT( int x, int y ) { X = x; Y = y; } } [Flags] public enum WindowStyles : uint { WS_CHILD = 0x40000000 } public enum GetWindowLongFields { GWL_USERDATA = -21, // 0xFFFFFFEB GWL_EXSTYLE = -20, // 0xFFFFFFEC GWL_STYLE = -16, // 0xFFFFFFF0 GWL_ID = -12, // 0xFFFFFFF4 GWL_HWNDPARENT = -8, // 0xFFFFFFF8 GWL_HINSTANCE = -6, // 0xFFFFFFFA GWL_WNDPROC = -4 // 0xFFFFFFFC } [StructLayout( LayoutKind.Sequential )] public struct INPUT { public InputType Type; public MOUSEKEYBDHARDWAREINPUT Data; } public enum InputType : uint { INPUT_MOUSE, INPUT_KEYBOARD, INPUT_HARDWARE } [StructLayout( LayoutKind.Explicit )] public struct MOUSEKEYBDHARDWAREINPUT { [FieldOffset( 0 )] public HARDWAREINPUT Hardware; [FieldOffset( 0 )] public KEYBDINPUT Keyboard; [FieldOffset( 0 )] public MOUSEINPUT Mouse; } [StructLayout( LayoutKind.Sequential )] public struct HARDWAREINPUT { public uint Msg; public ushort ParamL; public ushort ParamH; } [StructLayout( LayoutKind.Sequential )] public struct KEYBDINPUT { public ushort Vk; public ushort Scan; public KEYEVENTF Flags; public uint Time; public IntPtr ExtraInfo; } [Flags] public enum KEYEVENTF : uint { EXTENDEDKEY = 0x0001, KEYUP = 0x0002, SCANCODE = 0x0008, UNICODE = 0x0004 } [StructLayout( LayoutKind.Sequential )] public struct MOUSEINPUT { public int X; public int Y; public uint MouseData; public uint Flags; public uint Time; public IntPtr ExtraInfo; } [Flags] public enum SHGSI : uint { SHGSI_ICON = 0x000000100, SHGSI_SMALLICON = 0x000000001 } public enum SHSTOCKICONID : uint { SIID_SHIELD = 77 } [StructLayout( LayoutKind.Sequential, CharSet = CharSet.Unicode )] public struct SHSTOCKICONINFO { public uint cbSize; public IntPtr hIcon; public int iSysIconIndex; public int iIcon; [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 260 )] public string szPath; } public enum GetWindowType : uint { /// /// The retrieved handle identifies the window of the same type that is highest in the Z order. /// /// If the specified window is a topmost window, the handle identifies a topmost window. /// If the specified window is a top-level window, the handle identifies a top-level window. /// If the specified window is a child window, the handle identifies a sibling window. /// GW_HWNDFIRST = 0, /// /// The retrieved handle identifies the window of the same type that is lowest in the Z order. /// /// If the specified window is a topmost window, the handle identifies a topmost window. /// If the specified window is a top-level window, the handle identifies a top-level window. /// If the specified window is a child window, the handle identifies a sibling window. /// GW_HWNDLAST = 1, /// /// The retrieved handle identifies the window below the specified window in the Z order. /// /// If the specified window is a topmost window, the handle identifies a topmost window. /// If the specified window is a top-level window, the handle identifies a top-level window. /// If the specified window is a child window, the handle identifies a sibling window. /// GW_HWNDNEXT = 2, /// /// The retrieved handle identifies the window above the specified window in the Z order. /// /// If the specified window is a topmost window, the handle identifies a topmost window. /// If the specified window is a top-level window, the handle identifies a top-level window. /// If the specified window is a child window, the handle identifies a sibling window. /// GW_HWNDPREV = 3, /// /// The retrieved handle identifies the specified window's owner window, if any. /// GW_OWNER = 4, /// /// The retrieved handle identifies the child window at the top of the Z order, /// if the specified window is a parent window; otherwise, the retrieved handle is NULL. /// The function examines only child windows of the specified window. It does not examine descendant windows. /// GW_CHILD = 5, /// /// The retrieved handle identifies the enabled popup window owned by the specified window (the /// search uses the first such window found using GW_HWNDNEXT); otherwise, if there are no enabled /// popup windows, the retrieved handle is that of the specified window. /// GW_ENABLEDPOPUP = 6 } /// /// Special window handles /// public enum SpecialWindowHandles { // ReSharper disable InconsistentNaming /// /// Places the window at the top of the Z order. /// HWND_TOP = 0, /// /// Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the bottom of all other windows. /// HWND_BOTTOM = 1, /// /// Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated. /// HWND_TOPMOST = -1, /// /// Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window. /// HWND_NOTOPMOST = -2 // ReSharper restore InconsistentNaming } [Flags] public enum SetWindowPosFlags : uint { // ReSharper disable InconsistentNaming /// /// If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request. /// SWP_ASYNCWINDOWPOS = 0x4000, /// /// Prevents generation of the WM_SYNCPAINT message. /// SWP_DEFERERASE = 0x2000, /// /// Draws a frame (defined in the window's class description) around the window. /// SWP_DRAWFRAME = 0x0020, /// /// Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed. /// SWP_FRAMECHANGED = 0x0020, /// /// Hides the window. /// SWP_HIDEWINDOW = 0x0080, /// /// Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter). /// SWP_NOACTIVATE = 0x0010, /// /// Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned. /// SWP_NOCOPYBITS = 0x0100, /// /// Retains the current position (ignores X and Y parameters). /// SWP_NOMOVE = 0x0002, /// /// Does not change the owner window's position in the Z order. /// SWP_NOOWNERZORDER = 0x0200, /// /// Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing. /// SWP_NOREDRAW = 0x0008, /// /// Same as the SWP_NOOWNERZORDER flag. /// SWP_NOREPOSITION = 0x0200, /// /// Prevents the window from receiving the WM_WINDOWPOSCHANGING message. /// SWP_NOSENDCHANGING = 0x0400, /// /// Retains the current size (ignores the cx and cy parameters). /// SWP_NOSIZE = 0x0001, /// /// Retains the current Z order (ignores the hWndInsertAfter parameter). /// SWP_NOZORDER = 0x0004, /// /// Displays the window. /// SWP_SHOWWINDOW = 0x0040, } } ================================================ FILE: Helpers/WinForms.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System.Collections.Generic; using System.Windows.Forms; namespace VirtualSpace.Helpers { public static class WinForms { private const string ComboBoxDisplayMember = "Text"; private const string ComboBoxValueMember = "Value"; public static void SetComboBoxDataSource( ComboBox cbb, List dataSource, string displayMember = ComboBoxDisplayMember, string valueMember = ComboBoxValueMember ) { cbb.DisplayMember = ComboBoxDisplayMember; cbb.ValueMember = ComboBoxValueMember; cbb.DataSource = dataSource; } } } ================================================ FILE: Helpers/WinMsg.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . namespace VirtualSpace.Helpers { public static class WinMsg { public const int WM_SYSCOMMAND = 0x0112; public const int SC_MAXIMIZE = 0xF030; public const int SC_MINIMIZE = 0xF020; public const int SC_RESTORE = 0xF120; public const int SC_SIZE = 0xF000; public const int SC_MOVE = 0xF010; public const int SC_CLOSE = 0xF060; public const int WM_HOTKEY = 0x0312; public const int WM_CLOSE = 0x0010; public const int WM_QUIT = 0x0012; public const int WM_DESTROY = 0x0002; public const int WM_MOUSEACTIVATE = 0x0021; public const int MA_NOACTIVATE = 0x3; } } ================================================ FILE: Helpers/WinRegistry.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Drawing; using System.Management; using System.Security.Principal; using Microsoft.Win32; using VirtualSpace.AppLogs; namespace VirtualSpace.Helpers { public static class WinRegistry { private const string PATH_VD_WALLPAPER_REGISTRY = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops\Desktops\"; private const string PATH_WALLPAPER_REGISTRY = @"HKEY_CURRENT_USER\Control Panel\Desktop\"; private const string PATH_COLOR_REGISTRY = @"HKEY_CURRENT_USER\Control Panel\Colors\"; private const string PATH_APP_USE_LIGHT_THEME = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\"; public static Wallpaper GetWallpaperByDesktopGuid( Guid guid, int width, int height, string cachePath, long quality ) { var wallpaper = new Wallpaper(); var path = GetWallPaperPathByGuid( guid ); if ( string.IsNullOrEmpty( path ) ) { wallpaper.Color = GetBackColor(); } else { wallpaper.Image = Images.GetScaledBitmap( width, height, path, ref wallpaper, cachePath, quality ); } return wallpaper; } public static Wallpaper GetWallpaperByPath( string path, int width, int height, string cachePath, long quality ) { var wallpaper = new Wallpaper(); wallpaper.Image = Images.GetScaledBitmap( width, height, path, ref wallpaper, cachePath, quality ); return wallpaper; } public static string? GetDefaultWallpaperPath() { return Registry.GetValue( PATH_WALLPAPER_REGISTRY, "Wallpaper", "" ).ToString(); } public static string? GetWallPaperPathByGuid( Guid guid ) { var path = Registry.GetValue( PATH_VD_WALLPAPER_REGISTRY + "{" + guid + "}", "Wallpaper", "" )?.ToString(); if ( string.IsNullOrEmpty( path ) ) path = GetDefaultWallpaperPath(); return string.IsNullOrEmpty( path ) ? null : path; } public static Color GetBackColor() { var color = Registry.GetValue( PATH_COLOR_REGISTRY, "Background", "" ).ToString(); var strColor = color.Split( ' ' ); return Color.FromArgb( int.Parse( strColor[0] ), int.Parse( strColor[1] ), int.Parse( strColor[2] ) ); } public static bool AppThemeIsLight() { return Registry.GetValue( PATH_APP_USE_LIGHT_THEME, "AppsUseLightTheme", "1" ).ToString() == "1"; } } public class RegValueMonitor : IDisposable { private readonly ManagementEventWatcher? _watcher; public RegValueMonitor( string hive, string keyPath, string valueName ) { var currentUser = WindowsIdentity.GetCurrent(); var sid = currentUser.User.Value; var q = $"SELECT * FROM RegistryValueChangeEvent WHERE Hive='{hive}' " + @$"AND KeyPath='{sid}\\{keyPath}' AND ValueName='{valueName}'"; var query = new WqlEventQuery( q ); try { _watcher = new ManagementEventWatcher( query ); _watcher.EventArrived += HandleEvent; _watcher.Start(); } catch ( ManagementException managementException ) { Logger.Error( "[Registry]: " + managementException.Message ); } } private static void HandleEvent( object sender, EventArrivedEventArgs e ) { var keyPath = e.NewEvent.Properties["Hive"].Value + @"\" + e.NewEvent.Properties["KeyPath"].Value; var valueName = e.NewEvent.Properties["ValueName"].Value.ToString(); var v = Registry.GetValue( keyPath, valueName, "" ); OnRegValueChanged?.Invoke( null, new RegValueChangedEventArgs( v.ToString() ) ); } public void Dispose() { _watcher?.Stop(); } public static event EventHandler? OnRegValueChanged; public class RegValueChangedEventArgs : EventArgs { public string Value { get; set; } public RegValueChangedEventArgs( string value ) { Value = value; } } } } ================================================ FILE: Ipc/Commons/Config.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . namespace VirtualSpace.Commons { public static class Config { public const string PIPE_NAME = "VIRTUAL_SPACE_IPC_PIPE"; public const string PIPE_SERVER = "."; } } ================================================ FILE: Ipc/Commons/HostInfo.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Diagnostics; using System.Reflection; namespace VirtualSpace.Commons { public class HostInfo { public Version Version { get; set; } public string Product { get; set; } public string InfoVersion { get; set; } public string AppPath { get; set; } public int MainWindowHandle { get; set; } } public static class HostInfoHelper { public static HostInfo GetHostInfo() { var entryAssembly = Assembly.GetEntryAssembly(); var product = ( (AssemblyProductAttribute)Attribute.GetCustomAttribute( entryAssembly, typeof( AssemblyProductAttribute ), false ) ).Product; var fileVersion = ( (AssemblyFileVersionAttribute)Attribute.GetCustomAttribute( entryAssembly, typeof( AssemblyFileVersionAttribute ), false ) ).Version; var infoVersion = ( (AssemblyInformationalVersionAttribute)Attribute.GetCustomAttribute( entryAssembly, typeof( AssemblyInformationalVersionAttribute ), false ) ).InformationalVersion; return new HostInfo { Version = new Version( fileVersion ), Product = product, InfoVersion = infoVersion, AppPath = Process.GetCurrentProcess().MainModule.FileName }; } } } ================================================ FILE: Ipc/Commons/Ipc.csproj ================================================ net6.0-windows enable 9 ================================================ FILE: Ipc/Commons/PipeMessage.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Runtime.InteropServices; namespace VirtualSpace.Commons { public class PipeMessage { public PipeMessageType Type { get; set; } public int Handle { get; set; } public int ProcessId { get; set; } public string Name { get; set; } } [StructLayout( LayoutKind.Sequential )] public struct COPYDATASTRUCT { public IntPtr dwData; public int cbData; public IntPtr lpData; } [StructLayout( LayoutKind.Sequential )] public struct VirtualDesktopSwitchInfo { public IntPtr hostHandle; public int vdCount; public int fromIndex; public int dir; public int targetIndex; } } ================================================ FILE: Ipc/Commons/PipeMessageType.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . namespace VirtualSpace.Commons { public enum PipeMessageType { INSTANCE, PLUGIN_VD_SWITCH_OBSERVER, PLUGIN_CHECK_ALIVE, PLUGIN_UPDATER, RESTART } } ================================================ FILE: Ipc/IpcClient/IpcClient.csproj ================================================ net6.0-windows enable 9 ================================================ FILE: Ipc/IpcClient/IpcPipeClient.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Diagnostics; using System.IO; using System.IO.Pipes; using System.Text.Json; using System.Threading.Tasks; namespace VirtualSpace.Commons { public static class IpcPipeClient { private const string PIPE_NAME = Config.PIPE_NAME; private const string PIPE_SERVER = Config.PIPE_SERVER; private static bool CheckIn( PipeMessage pipeMessage ) { using var client = new NamedPipeClientStream( PIPE_SERVER, PIPE_NAME, PipeDirection.InOut, PipeOptions.None ); try { client.Connect( 1000 ); if ( client.IsConnected ) { using var writer = new StreamWriter( client ); writer.WriteLine( JsonSerializer.Serialize( pipeMessage ) ); writer.Flush(); return true; } } catch { // ignored } return false; } private static bool CheckInAndWaitResponse( PipeMessage pipeMessage, Action callback ) { using var client = new NamedPipeClientStream( PIPE_SERVER, PIPE_NAME, PipeDirection.InOut, PipeOptions.None ); try { client.Connect( 1000 ); if ( client.IsConnected ) { using var reader = new StreamReader( client ); using var writer = new StreamWriter( client ); writer.WriteLine( JsonSerializer.Serialize( pipeMessage ) ); writer.Flush(); var line = reader.ReadLine(); callback( JsonSerializer.Deserialize( line ) ); return true; } } catch { // ignored } return false; } private static bool AskAlive( string name, int handle, int pId ) { using var client = new NamedPipeClientStream( PIPE_SERVER, PIPE_NAME, PipeDirection.InOut, PipeOptions.None ); try { client.Connect( 1000 ); if ( client.IsConnected ) { var msg = new PipeMessage {Type = PipeMessageType.PLUGIN_CHECK_ALIVE, Handle = handle, ProcessId = pId, Name = name}; using var writer = new StreamWriter( client ); writer.WriteLine( JsonSerializer.Serialize( msg ) ); writer.Flush(); return true; } } catch { // ignored } return false; } public static async void CheckAlive( string name, int handle, int pId, int interval, Action exit ) { while ( AskAlive( name, handle, pId ) ) { await Task.Delay( interval * 1000 ); } exit(); } public static void PluginCheckIn( PipeMessage pipeMessage, Action error, Action exit ) { var pId = Process.GetCurrentProcess().Id; pipeMessage.ProcessId = pId; if ( CheckIn( pipeMessage ) ) return; error(); exit(); } public static void PluginCheckIn( PipeMessage pipeMessage, Action error, Action exit, Action callback ) { var pId = Process.GetCurrentProcess().Id; pipeMessage.ProcessId = pId; if ( CheckInAndWaitResponse( pipeMessage, callback ) ) return; error(); exit(); } public static void NotifyHostRestart() { using var client = new NamedPipeClientStream( PIPE_SERVER, PIPE_NAME, PipeDirection.InOut, PipeOptions.None ); try { client.Connect( 1000 ); if ( client.IsConnected ) { using var writer = new StreamWriter( client ); writer.WriteLine( JsonSerializer.Serialize( new PipeMessage {Type = PipeMessageType.RESTART} ) ); writer.Flush(); } } catch { // ignored } } } } ================================================ FILE: Ipc/IpcServer/IpcPipeServer.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.IO; using System.IO.Pipes; using System.Linq; using System.Text.Json; using System.Threading.Tasks; using VirtualSpace.AppLogs; using VirtualSpace.Helpers; using VirtualSpace.Plugin; namespace VirtualSpace.Commons { public static class IpcPipeServer { private const string PIPE_NAME = Config.PIPE_NAME; private const string PIPE_SERVER = Config.PIPE_SERVER; private static bool _isRunning = true; public static IntPtr MainWindowHandle { get; set; } public static void Start() { Task.Factory.StartNew( () => { Logger.Info( "Ipc Pipe Server Wait For Connections." ); while ( _isRunning ) { using var server = new NamedPipeServerStream( PIPE_NAME ); server.WaitForConnection(); using var reader = new StreamReader( server ); var line = reader.ReadLine(); if ( !string.IsNullOrEmpty( line ) ) { MessageProcessing( line, server ); } } Logger.Info( "Ipc Pipe Server Shutdown." ); }, TaskCreationOptions.LongRunning ); return; void MessageProcessing( string line, NamedPipeServerStream server ) { var msg = JsonSerializer.Deserialize( line ); switch ( msg?.Type ) { case PipeMessageType.INSTANCE: Logger.Info( "Only single instance allowed, just bring to top." ); User32.PostMessage( MainWindowHandle, WinMsg.WM_HOTKEY, UserMessage.RiseView, 0 ); break; case PipeMessageType.PLUGIN_VD_SWITCH_OBSERVER: { if ( !server.CanWrite ) break; using var writer = new StreamWriter( server ); var hostInfo = HostInfoHelper.GetHostInfo(); hostInfo.MainWindowHandle = MainWindowHandle.ToInt32(); writer.WriteLine( JsonSerializer.Serialize( hostInfo ) ); writer.Flush(); ///////////////////////////////// // 只接受已注册成功的插件 // 同时若插件名相同,则后启动的覆盖先启动的 foreach ( var p in PluginHost.Plugins.Where( p => p.Name == msg.Name ) ) { Logger.Info( $"[PLUGIN\\Virtual Desktop Switch Observer] {p.Display} Started." ); p.Handle = (IntPtr)msg.Handle; p.ProcessId = msg.ProcessId; p.Type = PluginType.VD_SWITCH_OBSERVER; break; } break; } case PipeMessageType.PLUGIN_CHECK_ALIVE: { var runningPlugin = PluginHost.Plugins.Find( p => p.Name == msg.Name && p.Handle == (IntPtr)msg.Handle && p.ProcessId == msg.ProcessId ); //////////////////////////////////////////////// // 若插件提供的信息在宿主中查不到,就通知该插件自行关闭 // 这通常是因为有同名插件启动,覆盖了先启动的插件的信息 if ( runningPlugin == null ) { PluginHost.ClosePlugin( new PluginInfo {Handle = (IntPtr)msg.Handle} ); } break; } case PipeMessageType.PLUGIN_UPDATER: { if ( !server.CanWrite ) break; using var writer = new StreamWriter( server ); writer.WriteLine( JsonSerializer.Serialize( HostInfoHelper.GetHostInfo() ) ); writer.Flush(); foreach ( var p in PluginHost.Plugins.Where( p => p.Name == msg.Name ) ) { Logger.Info( $"[PLUGIN\\App Updater] {p.Display} Started." ); p.Handle = (IntPtr)msg.Handle; p.ProcessId = msg.ProcessId; p.Type = PluginType.UPDATER; break; } break; } case PipeMessageType.RESTART: { User32.PostMessage( MainWindowHandle, WinMsg.WM_HOTKEY, UserMessage.RestartApp, 0 ); break; } default: break; } } } public static void AsClient() { using var client = new NamedPipeClientStream( PIPE_SERVER, PIPE_NAME, PipeDirection.InOut, PipeOptions.None ); try { client.Connect( 3000 ); using var writer = new StreamWriter( client ); var msg = new PipeMessage {Type = PipeMessageType.INSTANCE}; writer.WriteLine( JsonSerializer.Serialize( msg ) ); writer.Flush(); } catch { // ignored } } public static void SimpleShutdown() { _isRunning = false; foreach ( var pluginInfo in PluginHost.Plugins ) { PluginHost.ClosePlugin( pluginInfo ); } using var client = new NamedPipeClientStream( PIPE_SERVER, PIPE_NAME, PipeDirection.InOut, PipeOptions.None ); try { client.Connect( 10 ); client.Close(); } catch { // ignored } } } } ================================================ FILE: Ipc/IpcServer/IpcServer.csproj ================================================ net6.0-windows enable 9 ================================================ FILE: LinqExpressionBuilder/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: LinqExpressionBuilder/Keywords.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of LinqExpressionBuilder. LinqExpressionBuilder is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. LinqExpressionBuilder is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with LinqExpressionBuilder. If not, see . */ namespace LinqExpressionBuilder { public static class Keywords { public const string String = "string"; public const string V = nameof( V ); public const string L = nameof( L ); public static readonly string Operator = nameof( Operator ).ToLower(); public static readonly string Type = nameof( Type ).ToLower(); public static readonly string Field = nameof( Field ).ToLower(); public static readonly string Value = nameof( Value ).ToLower(); public static readonly string[] Eq = {"=", "is", "==", "eq", "equal", "equals"}; public static readonly string[] In = {"in", "∈"}; public static readonly string[] StartsWith = {"ssw", "starts with", "|-"}; public static readonly string[] EndsWith = {"esw", "ends with", "-|"}; public static readonly string[] Contains = {"sc", "contains", "∋"}; public static readonly string[] RegexIsMatch = {"rim", "regex", "/r/"}; public static readonly string Condition = nameof( Condition ).ToLower(); public static readonly string And = nameof( And ).ToLower(); public static readonly string Or = nameof( Or ).ToLower(); public static readonly string Rules = nameof( Rules ).ToLower(); public static readonly string Boolean = nameof( Boolean ).ToLower(); public static readonly string Number = nameof( Number ).ToLower(); public static readonly string Id = nameof( Id ).ToLower(); } } ================================================ FILE: LinqExpressionBuilder/LinqExpressionBuilder.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of LinqExpressionBuilder. LinqExpressionBuilder is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. LinqExpressionBuilder is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with LinqExpressionBuilder. If not, see . */ using System; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text.Json; using System.Text.RegularExpressions; namespace LinqExpressionBuilder { public class JsonParser { private readonly MethodInfo _listContains = typeof( Enumerable ) .GetMethods( BindingFlags.Static | BindingFlags.Public ) .Single( m => m.Name == nameof( Enumerable.Contains ) && m.GetParameters().Length == 2 ); private readonly MethodInfo? _regexIsMatch = typeof( Regex ).GetMethod( nameof( Regex.IsMatch ), new Type[] {typeof( string ), typeof( string )} ); private readonly MethodInfo? _strContains = typeof( string ).GetMethod( nameof( string.Contains ), new Type[] {typeof( string )} ); private readonly MethodInfo? _strEndsWith = typeof( string ).GetMethod( nameof( string.EndsWith ), new Type[] {typeof( string )} ); private readonly MethodInfo? _strStartsWith = typeof( string ).GetMethod( nameof( string.StartsWith ), new Type[] {typeof( string )} ); private Expression? ParseTree( JsonElement condition, ParameterExpression param ) { if ( condition.TryGetProperty( Keywords.Condition, out var combine ) ) { var gate = condition.GetProperty( Keywords.Condition ).GetString(); Binder binder; if ( gate == Keywords.And ) binder = Expression.And; else binder = Expression.Or; Expression? Bind( Expression? l, Expression? r ) { return l == null ? r : binder( l, r ); } Expression? left = null; var rules = condition.GetProperty( Keywords.Rules ); foreach ( var rule in rules.EnumerateArray() ) { if ( rule.TryGetProperty( Keywords.Condition, out var nested ) ) { left = Bind( left, ParseTree( rule, param ) ); } else { left = Bind( left, SimpleCondition( rule, param ) ); } } return left; } return SimpleCondition( condition, param ); } private Expression? SimpleCondition( JsonElement rule, ParameterExpression param ) { var @operator = rule.GetProperty( Keywords.Operator ).GetString().ToLower(); var type = rule.GetProperty( Keywords.Type ).GetString().ToLower(); var field = rule.GetProperty( Keywords.Field ).GetString(); var value = rule.GetProperty( Keywords.Value ); var V = value.GetProperty( Keywords.In.Contains( @operator ) ? Keywords.L : Keywords.V ); var property = Expression.Property( param, field ); object target; Expression? right = default; if ( Keywords.Eq.Contains( @operator ) ) { if ( type == Keywords.String || type == Keywords.Boolean ) target = V.GetString(); else target = V.GetDecimal(); var toCompare = Expression.Constant( target ); right = Expression.Equal( property, toCompare ); } else if ( Keywords.In.Contains( @operator ) ) { var listContains = _listContains.MakeGenericMethod( typeof( string ) ); target = V.EnumerateArray().Select( e => e.GetString() ).ToList(); right = Expression.Call( listContains, Expression.Constant( target ), property ); } else if ( Keywords.StartsWith.Contains( @operator ) ) { right = Expression.Call( property, _strStartsWith, Expression.Constant( V.GetString() ) ); } else if ( Keywords.EndsWith.Contains( @operator ) ) { right = Expression.Call( property, _strEndsWith, Expression.Constant( V.GetString() ) ); } else if ( Keywords.Contains.Contains( @operator ) ) { right = Expression.Call( property, _strContains, Expression.Constant( V.GetString() ) ); } else if ( Keywords.RegexIsMatch.Contains( @operator ) ) { right = Expression.Call( _regexIsMatch, property, Expression.Constant( V.GetString() ) ); } return right; } private Expression> BuildPredicate( JsonDocument doc ) { var itemTypeExpr = Expression.Parameter( typeof( T ) ); var conditions = ParseTree( doc.RootElement, itemTypeExpr ); if ( conditions.CanReduce ) { conditions = conditions.ReduceAndCheck(); } return Expression.Lambda>( conditions, itemTypeExpr ); } public Func ExpressionFromJsonDoc( JsonDocument doc ) { return BuildPredicate( doc ).Compile(); } private delegate Expression? Binder( Expression left, Expression right ); } } ================================================ FILE: LinqExpressionBuilder/LinqExpressionBuilder.csproj ================================================  net6.0-windows enable 9 ================================================ FILE: Logger/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Logger/LogMessage.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ namespace VirtualSpace.AppLogs { public class LogMessage { public string Type { get; set; } public string Message { get; set; } public static LogMessage CreateMessage( string type, string msg ) { return new LogMessage { Type = type, Message = msg }; } } } ================================================ FILE: Logger/Logger.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Runtime.InteropServices; using System.Text; using System.Threading.Channels; using System.Windows.Media; using Notification.Wpf; using Notification.Wpf.Constants; namespace VirtualSpace.AppLogs { public static class Logger { public static readonly Channel LogChannel = Channel.CreateUnbounded(); public static bool ShowLogsInGui { get; set; } = false; public static void Verbose( string str ) { LogToGui( "VERBOSE", str ); LogManager.RootLogger.Verbose( str ); } public static void Debug( string str ) { LogToGui( "DEBUG", str ); LogManager.RootLogger.Debug( str ); } public static void Event( string str ) { LogToGui( "EVENT", str ); LogManager.RootLogger.Write( LogManager.LOG_LEVEL_EVENT, str ); } public static void Info( string str ) { LogToGui( "INFO", str ); LogManager.RootLogger.Information( str ); } public static void Warning( string str ) { LogToGui( "WARNING", str ); LogManager.RootLogger.Warning( str ); } public static void Error( string str, NotifyObject? notify = null ) { LogToGui( "ERROR", str ); LogManager.RootLogger.Error( str ); if ( notify != null ) { notify.Background = new SolidColorBrush( Colors.DarkRed ); notify.Foreground = new SolidColorBrush( Colors.White ); notify.Type = NotificationType.Error; Notify( notify ); } } private static async void LogToGui( string type, string str ) { if ( !ShowLogsInGui ) return; var logMessage = LogMessage.CreateMessage( type, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}][{type}] {str} {{ThreadId:{Environment.CurrentManagedThreadId.ToString()}}}\r\n" ); await LogChannel.Writer.WriteAsync( logMessage ).ConfigureAwait( false ); } public static void Notify( NotifyObject no ) { var notificationManager = new NotificationManager(); var content = new NotificationContent { Title = no.Title, Message = no.Message, Type = no.Type, TrimType = NotificationTextTrimType.NoTrim, // will show attach button on message RowsCount = 5, // Will show 5 rows and trim after LeftButtonContent = "", // Left button content (string or what u want RightButtonContent = "", // Right button content (string or what u want CloseOnClick = true // Set true if u want close message when left mouse button click on message (base = true) }; if ( no.Background != null ) { content.Background = no.Background; } if ( no.Foreground != null ) { content.Foreground = no.Foreground; } NotificationConstants.MaxWidth = 1024; notificationManager.Show( content, "", no.ExpTime ); NotificationConstants.MaxWidth = 350; _ = User32.EnumWindows( ToastWindowFilter, 0 ); } private static bool ToastWindowFilter( IntPtr hWnd, int lParam ) { var sbTitle = new StringBuilder( 128 ); User32.GetWindowText( hWnd, sbTitle, sbTitle.Capacity ); var title = sbTitle.ToString(); var sbCName = new StringBuilder( 512 ); _ = User32.GetClassName( hWnd, sbCName, sbCName.Capacity ); var classname = sbCName.ToString(); if ( title == "ToastWindow" && classname.StartsWith( "HwndWrapper[VirtualSpace" ) ) { var exStyle = User32.GetWindowLong( hWnd, (int)GetWindowLongFields.GWL_EXSTYLE ); exStyle |= User32.WS_EX_TOOLWINDOW; User32.SetWindowLongPtr( new HandleRef( null, hWnd ), (int)GetWindowLongFields.GWL_EXSTYLE, exStyle ); return false; } return true; } private enum GetWindowLongFields { GWL_USERDATA = -21, // 0xFFFFFFEB GWL_EXSTYLE = -20, // 0xFFFFFFEC GWL_STYLE = -16, // 0xFFFFFFF0 GWL_ID = -12, // 0xFFFFFFF4 GWL_HWNDPARENT = -8, // 0xFFFFFFF8 GWL_HINSTANCE = -6, // 0xFFFFFFFA GWL_WNDPROC = -4 // 0xFFFFFFFC } private static class User32 { public delegate bool EnumWindowsProc( IntPtr hWnd, int lParam ); public const int WS_EX_TOOLWINDOW = 0x80; [DllImport( "user32.dll", CharSet = CharSet.Auto )] public static extern int GetWindowLong( IntPtr hWnd, int nIndex ); public static IntPtr SetWindowLongPtr( HandleRef hWnd, int nIndex, int dwNewLong ) { if ( IntPtr.Size == 8 ) return SetWindowLongPtr64( hWnd, nIndex, (IntPtr)dwNewLong ); else return new IntPtr( SetWindowLong32( hWnd, nIndex, dwNewLong ) ); } [DllImport( "user32.dll", EntryPoint = "SetWindowLong" )] private static extern int SetWindowLong32( HandleRef hWnd, int nIndex, int dwNewLong ); [DllImport( "user32.dll", EntryPoint = "SetWindowLongPtr" )] private static extern IntPtr SetWindowLongPtr64( HandleRef hWnd, int nIndex, IntPtr dwNewLong ); [DllImport( "user32.dll" )] public static extern int GetWindowText( IntPtr hWnd, StringBuilder buf, int nMaxCount ); [DllImport( "user32.dll", SetLastError = true, CharSet = CharSet.Auto )] public static extern int GetClassName( IntPtr hWnd, StringBuilder lpClassName, int nMaxCount ); [DllImport( "user32.dll" )] public static extern int EnumWindows( EnumWindowsProc func, int lParam ); } } public class NotifyObject { public string Title { get; set; } = ""; public string Message { get; set; } = ""; public NotificationType Type { get; set; } public SolidColorBrush? Background { get; set; } public SolidColorBrush? Foreground { get; set; } public TimeSpan ExpTime { get; set; } = TimeSpan.FromSeconds( 10 ); } } ================================================ FILE: Logger/Logger.csproj ================================================  net6.0-windows 9 enable ================================================ FILE: Logger/Manager.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Configuration; using System.IO; using Serilog; using Serilog.Core; using Serilog.Events; namespace VirtualSpace.AppLogs { public static class LogManager { private static readonly LoggingLevelSwitch LevelSwitch = new( LogEventLevel.Verbose ); public const LogEventLevel LOG_LEVEL_EVENT = (LogEventLevel)0xFF; public static Serilog.Core.Logger RootLogger; private static string _logsFolder = "Logs"; public static string LogsPath { get { var appPath = Environment.ProcessPath!; var appRootFolder = Directory.GetParent( appPath )!.FullName; return Path.Combine( appRootFolder, _logsFolder ); } } public static void InitLogger( string folder ) { _logsFolder = folder; folder = LogsPath; RootLogger = new LoggerConfiguration() .MinimumLevel.ControlledBy( LevelSwitch ) .WriteTo.Logger( c => c.Filter.ByIncludingOnly( evt => evt.Level == LogEventLevel.Verbose ).WriteTo.File( $"{folder}/verbose.txt", LogEventLevel.Verbose ) ) .WriteTo.Logger( c => c.Filter.ByIncludingOnly( evt => evt.Level == LogEventLevel.Debug ).WriteTo.File( $"{folder}/debug.txt", LogEventLevel.Debug ) ) .WriteTo.Logger( c => c.Filter.ByIncludingOnly( evt => evt.Level == LogEventLevel.Information ).WriteTo.File( $"{folder}/info.txt", LogEventLevel.Information ) ) .WriteTo.Logger( c => c.Filter.ByIncludingOnly( evt => evt.Level == LogEventLevel.Warning ).WriteTo.File( $"{folder}/warning.txt", LogEventLevel.Warning ) ) .WriteTo.Logger( c => c.Filter.ByIncludingOnly( evt => evt.Level == LogEventLevel.Error ).WriteTo.File( $"{folder}/error.txt", LogEventLevel.Error ) ) .WriteTo.Logger( c => c.Filter.ByIncludingOnly( evt => evt.Level == LogEventLevel.Fatal ).WriteTo.File( $"{folder}/fatal.txt", LogEventLevel.Fatal ) ) .WriteTo.Logger( c => c.Filter.ByIncludingOnly( evt => evt.Level == LOG_LEVEL_EVENT ).WriteTo.File( $"{folder}/event.txt", LOG_LEVEL_EVENT ) ) .CreateLogger(); } public static void GorgeousDividingLine() { const string line = "=================================================="; RootLogger.Verbose( line ); RootLogger.Debug( line ); RootLogger.Information( line ); RootLogger.Warning( line ); RootLogger.Error( line ); RootLogger.Fatal( line ); RootLogger.Write( LOG_LEVEL_EVENT, line ); } public static void SetLogLevel( string level ) { LevelSwitch.MinimumLevel = level switch { "DEBUG" => LogEventLevel.Verbose, "EVENT" => LogEventLevel.Debug, "INFO" => LogEventLevel.Information, "WARNING" => LogEventLevel.Warning, "ERROR" => LogEventLevel.Error, "FATAL" => LogEventLevel.Fatal, _ => LogEventLevel.Information }; } } } ================================================ FILE: Plugin/Commons/Plugin.csproj ================================================ net6.0-windows enable 9 ================================================ FILE: Plugin/Commons/PluginInfo.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Collections.Generic; namespace VirtualSpace.Plugin { public class PluginInfo { public string Folder; public IntPtr Handle; public int ProcessId; public PluginType Type; public string Name { get; set; } public string Display { get; set; } public string Version { get; set; } public string Author { get; set; } public string Email { get; set; } public string Entry { get; set; } public bool AutoStart { get; set; } public AutoStartTiming AutoStartTiming { get; set; } = AutoStartTiming.MainWindowLoaded; public Policy? RestartPolicy { get; set; } public Policy? ClosePolicy { get; set; } public Requirements? Requirements { get; set; } } public class Policy { public PolicyTrigger Trigger { get; set; } public List Values { get; set; } public bool Enabled { get; set; } } public enum PolicyTrigger { WINDOWS_MESSAGE } public enum PluginType { NONE, VD_SWITCH_OBSERVER, UPDATER } public class Requirements { public WinVer WinVer { get; set; } public Version? HostVersion { get; set; } } public class WinVer { public Ver Min { get; set; } public Ver? Max { get; set; } } public class Ver { public int Major { get; set; } public int Build { get; set; } } public enum AutoStartTiming { AppStart, MainWindowLoaded } } ================================================ FILE: Plugin/Commons/PluginManager.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Diagnostics; using System.IO; using System.Text.Json; namespace VirtualSpace.Plugin { public static class PluginManager { public const string PluginInfoFile = "plugin.json"; public static readonly PluginInfo PluginInfo = GetPluginInfo(); private static PluginInfo GetPluginInfo() { var file = Path.Combine( GetAppFolder(), PluginInfoFile ); return LoadFromJson( file ); } public static string GetAppPath() { return Process.GetCurrentProcess().MainModule.FileName; } public static string GetAppFolder() { return Directory.GetParent( GetAppPath() ).FullName; } public static T? LoadFromJson( string infoFile ) { using var fs = new FileStream( infoFile, FileMode.Open, FileAccess.Read ); var buffer = new byte[fs.Length]; _ = fs.Read( buffer, 0, (int)fs.Length ); var utf8Reader = new Utf8JsonReader( buffer ); return JsonSerializer.Deserialize( ref utf8Reader ); } public static bool CheckRequirements( Requirements? req ) { var check = false; var version = Environment.OSVersion.Version; if ( version.Major >= req?.WinVer.Min.Major && version.Build >= req.WinVer.Min.Build ) check = true; if ( req?.WinVer.Max != null && ( version.Major > req.WinVer.Max.Major || version.Build > req.WinVer.Max.Build ) ) check = false; return check; } public static void SavePluginInfo( PluginInfo pi ) { var file = Path.Combine( pi.Folder, PluginInfoFile ); var contents = JsonSerializer.SerializeToUtf8Bytes( pi, new JsonSerializerOptions {WriteIndented = true} ); File.WriteAllBytesAsync( file, contents ); } } } ================================================ FILE: Plugin/Commons/WinApi.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Runtime.InteropServices; namespace VirtualSpace.Plugin { public static class WinApi { public const int WM_SYSCOMMAND = 0x0112; public const int SC_MAXIMIZE = 0xF030; public const int SC_MINIMIZE = 0xF020; public const int SC_RESTORE = 0xF120; public const int SC_SIZE = 0xF000; public const int SC_MOVE = 0xF010; public const int SC_CLOSE = 0xF060; public const int WM_HOTKEY = 0x0312; public const int WM_CLOSE = 0x0010; public const int WM_QUIT = 0x0012; public const int WM_DESTROY = 0x0002; public const int WM_MOUSEACTIVATE = 0x0021; public const int MA_NOACTIVATE = 0x3; public const int WM_COPYDATA = 0x004A; private const int WM_USER = 0x0400; public const int UM_SWITCHDESKTOP = WM_USER + 1; public const int UM_PLUGINSETTINGS = WM_USER + 2; public const int UM_OTHERSCREENS = WM_USER + 3; public const int UM_RESTART = WM_USER + 4; [DllImport( "user32.dll", CharSet = CharSet.Auto )] public static extern bool PostMessage( IntPtr hWnd, int msg, uint wParam, uint lParam ); } } ================================================ FILE: Plugin/PluginHost/PluginConst.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . namespace VirtualSpace.Plugin { public static class PluginConst { public const string UxdDisplayChangeMessage = "UxdDisplayChangeMessage"; public const string HotPlugDetected = "HotplugDetected"; public const string DirectInputNotificationMsgString = "DIRECTINPUT_NOTIFICATION_MSGSTRING"; public const int RestartDelay = 5000; } } ================================================ FILE: Plugin/PluginHost/PluginHost.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Threading.Tasks; using VirtualSpace.AppLogs; namespace VirtualSpace.Plugin { public static class PluginHost { public static readonly List Plugins = new(); public static readonly Dictionary CareAboutMessages = new() { {PluginConst.DirectInputNotificationMsgString, 0}, {PluginConst.HotPlugDetected, 0} }; /// /// 此处注册的是插件的静态信息; /// 插件的运行时信息,则在插件启动后通过 IPC 自行报道给宿主 /// /// public static void RegisterPlugins( string pluginsPath ) { var pluginFolders = Directory.GetDirectories( pluginsPath ); foreach ( var path in pluginFolders ) { var infoFile = Path.Combine( path, PluginManager.PluginInfoFile ); if ( !File.Exists( infoFile ) ) { Logger.Warning( $"[PLUGIN] missing {PluginManager.PluginInfoFile} in {path}" ); continue; } var pluginInfo = PluginManager.LoadFromJson( infoFile ); if ( pluginInfo == null ) { Logger.Warning( $"[PLUGIN] invalid {PluginManager.PluginInfoFile}" ); continue; } var alreadyLoaded = Plugins.Find( p => p.Name == pluginInfo.Name ); if ( alreadyLoaded != null ) continue; if ( pluginInfo.Requirements is null ) { Logger.Warning( $"[PLUGIN] {pluginInfo.Display} has no 'Requirements' info" ); continue; } if ( pluginInfo.Requirements.HostVersion == null || pluginInfo.Requirements.HostVersion > GetHostVersion() ) { Logger.Warning( $"[PLUGIN] {pluginInfo.Display} not satisfy the host version" ); continue; } pluginInfo.Folder = path; Plugins.Add( pluginInfo ); Logger.Info( $"[PLUGIN] {pluginInfo.Display} Registered." ); if ( pluginInfo is {AutoStart: true, AutoStartTiming: AutoStartTiming.AppStart} ) StartPlugin( pluginInfo ); } } public static void AutoStartAfterMainWindowLoaded() { foreach ( var pi in Plugins.Where( pi => pi is {AutoStart: true, AutoStartTiming: AutoStartTiming.MainWindowLoaded} ) ) { StartPlugin( pi ); } } private static void StartExe( string exe ) { Task.Run( () => Process.Start( exe ) ); } public static void PluginSettings( PluginInfo pluginInfo ) { WinApi.PostMessage( pluginInfo.Handle, WinApi.UM_PLUGINSETTINGS, 0, 0 ); } public static void StartPlugin( PluginInfo pluginInfo ) { if ( !PluginManager.CheckRequirements( pluginInfo.Requirements ) ) return; Logger.Info( $"[PLUGIN.Start] {pluginInfo.Display}" ); StartExe( Path.Combine( pluginInfo.Folder, pluginInfo.Entry ) ); } public static void ClosePlugin( PluginInfo pluginInfo ) { if ( !string.IsNullOrEmpty( pluginInfo.Display ) ) Logger.Info( $"[PLUGIN.Close] {pluginInfo.Display}" ); WinApi.PostMessage( pluginInfo.Handle, WinApi.WM_CLOSE, 0, 0 ); // WinApi.PostMessage( pluginInfo.Handle, WinApi.WM_QUIT, 0, 0 ); // WinApi.PostMessage( pluginInfo.Handle, WinApi.WM_DESTROY, 0, 0 ); } public static void RestartPlugin( PluginInfo pluginInfo ) { try { WinApi.PostMessage( pluginInfo.Handle, WinApi.UM_RESTART, 0, PluginConst.RestartDelay ); Logger.Info( $"[PLUGIN] {pluginInfo.Display} Restarted." ); } catch ( Exception ex ) { Logger.Warning( "Failed Restart Plugin, Abort Operation." ); Logger.Warning( ex.Message ); } } private static Version GetHostVersion() { var fileVersion = ( (AssemblyFileVersionAttribute)Attribute.GetCustomAttribute( Assembly.GetEntryAssembly(), typeof( AssemblyFileVersionAttribute ), false ) ).Version; return new Version( fileVersion ); } } } ================================================ FILE: Plugin/PluginHost/PluginHost.csproj ================================================ net6.0-windows enable 9 ================================================ FILE: Plugins.sln/.gitignore ================================================ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.rsuser *.suo *.user *.userosscache *.sln.docstates # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs # Mono auto generated files mono_crash.* # Build results [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ x64/ x86/ [Ww][Ii][Nn]32/ [Aa][Rr][Mm]/ [Aa][Rr][Mm]64/ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ [Ll]ogs/ # Visual Studio 2015/2017 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot #wwwroot/ # Visual Studio 2017 auto generated files Generated\ Files/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* # NUnit *.VisualState.xml TestResult.xml nunit-*.xml # Build Results of an ATL Project [Dd]ebugPS/ [Rr]eleasePS/ dlldata.c # Benchmark Results BenchmarkDotNet.Artifacts/ # .NET Core project.lock.json project.fragment.lock.json artifacts/ # Tye .tye/ # ASP.NET Scaffolding ScaffoldingReadMe.txt # StyleCop StyleCopReport.xml # Files built by Visual Studio *_i.c *_p.c *_h.h *.ilk *.meta *.obj *.iobj *.pch *.pdb *.ipdb *.pgc *.pgd *.rsp *.sbr *.tlb *.tli *.tlh *.tmp *.tmp_proj *_wpftmp.csproj *.log *.vspscc *.vssscc .builds *.pidb *.svclog *.scc # Chutzpah Test files _Chutzpah* # Visual C++ cache files ipch/ *.aps *.ncb *.opendb *.opensdf *.sdf *.cachefile *.VC.db *.VC.VC.opendb # Visual Studio profiler *.psess *.vsp *.vspx *.sap # Visual Studio Trace Files *.e2e # TFS 2012 Local Workspace $tf/ # Guidance Automation Toolkit *.gpState # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user # TeamCity is a build add-in _TeamCity* # DotCover is a Code Coverage Tool *.dotCover # AxoCover is a Code Coverage Tool .axoCover/* !.axoCover/settings.json # Coverlet is a free, cross platform Code Coverage Tool coverage*.json coverage*.xml coverage*.info # Visual Studio code coverage results *.coverage *.coveragexml # NCrunch _NCrunch_* .*crunch*.local.xml nCrunchTemp_* # MightyMoose *.mm.* AutoTest.Net/ # Web workbench (sass) .sass-cache/ # Installshield output folder [Ee]xpress/ # DocProject is a documentation generator add-in DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC DocProject/Help/*.hhc DocProject/Help/*.hhk DocProject/Help/*.hhp DocProject/Help/Html2 DocProject/Help/html # Click-Once directory publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml # Note: Comment the next line if you want to checkin your web deploy settings, # but database connection strings (with potential passwords) will be unencrypted *.pubxml *.publishproj # Microsoft Azure Web App publish settings. Comment the next line if you want to # checkin your Azure Web App publish settings, but sensitive information contained # in these scripts will be unencrypted PublishScripts/ # NuGet Packages *.nupkg # NuGet Symbol Packages *.snupkg # The packages folder can be ignored because of Package Restore **/[Pp]ackages/* # except build/, which is used as an MSBuild target. !**/[Pp]ackages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/[Pp]ackages/repositories.config # NuGet v3's project.json files produces more ignorable files *.nuget.props *.nuget.targets # Microsoft Azure Build Output csx/ *.build.csdef # Microsoft Azure Emulator ecf/ rcf/ # Windows Store app package directories and files AppPackages/ BundleArtifacts/ Package.StoreAssociation.xml _pkginfo.txt *.appx *.appxbundle *.appxupload # Visual Studio cache files # files ending in .cache can be ignored *.[Cc]ache # but keep track of directories ending in .cache !?*.[Cc]ache/ # Others ClientBin/ ~$* *~ *.dbmdl *.dbproj.schemaview *.jfm *.pfx *.publishsettings orleans.codegen.cs # Including strong name files can present a security risk # (https://github.com/github/gitignore/pull/2483#issue-259490424) #*.snk # Since there are multiple workflows, uncomment next line to ignore bower_components # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) #bower_components/ # RIA/Silverlight projects Generated_Code/ # Backup & report files from converting an old project file # to a newer Visual Studio version. Backup files are not needed, # because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm ServiceFabricBackup/ *.rptproj.bak # SQL Server files *.mdf *.ldf *.ndf # Business Intelligence projects *.rdl.data *.bim.layout *.bim_*.settings *.rptproj.rsuser *- [Bb]ackup.rdl *- [Bb]ackup ([0-9]).rdl *- [Bb]ackup ([0-9][0-9]).rdl # Microsoft Fakes FakesAssemblies/ # GhostDoc plugin setting file *.GhostDoc.xml # Node.js Tools for Visual Studio .ntvs_analysis.dat node_modules/ # Visual Studio 6 build log *.plg # Visual Studio 6 workspace options file *.opt # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) *.vbw # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts **/*.DesktopClient/ModelManifest.xml **/*.Server/GeneratedArtifacts **/*.Server/ModelManifest.xml _Pvt_Extensions # Paket dependency manager .paket/paket.exe paket-files/ # FAKE - F# Make .fake/ # CodeRush personal settings .cr/personal # Python Tools for Visual Studio (PTVS) __pycache__/ *.pyc # Cake - Uncomment if you are using it # tools/** # !tools/packages.config # Tabs Studio *.tss # Telerik's JustMock configuration file *.jmconfig # BizTalk build output *.btp.cs *.btm.cs *.odx.cs *.xsd.cs # OpenCover UI analysis results OpenCover/ # Azure Stream Analytics local run output ASALocalRun/ # MSBuild Binary and Structured Log *.binlog # NVidia Nsight GPU debugger configuration file *.nvuser # MFractors (Xamarin productivity tool) working folder .mfractor/ # Local History for Visual Studio .localhistory/ # BeatPulse healthcheck temp database healthchecksdb # Backup folder for Package Reference Convert tool in Visual Studio 2017 MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ # Fody - auto-generated XML schema FodyWeavers.xsd ## ## Visual studio for Mac ## # globs Makefile.in *.userprefs *.usertasks config.make config.status aclocal.m4 install-sh autom4te.cache/ *.tar.gz tarballs/ test-results/ # Mac bundle stuff *.dmg *.app # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore # General .DS_Store .AppleDouble .LSOverride # Icon must end with two \r Icon # Thumbnails ._* # Files that might appear in the root of a volume .DocumentRevisions-V100 .fseventsd .Spotlight-V100 .TemporaryItems .Trashes .VolumeIcon.icns .com.apple.timemachine.donotpresent # Directories potentially created on remote AFP share .AppleDB .AppleDesktop Network Trash Folder Temporary Items .apdisk # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore # Windows thumbnail cache files Thumbs.db ehthumbs.db ehthumbs_vista.db # Dump file *.stackdump # Folder config file [Dd]esktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ # Windows Installer files *.cab *.msi *.msix *.msm *.msp # Windows shortcuts *.lnk # JetBrains Rider .idea/ *.sln.iml ## ## Visual Studio Code ## .vscode/* !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json ================================================ FILE: Plugins.sln/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Plugins.sln/Cube3D/App.xaml ================================================  Transparent ================================================ FILE: Plugins.sln/Cube3D/App.xaml.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of Cube3D. Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Cube3D. If not, see . */ using System.Diagnostics; using System.Windows; using VirtualSpace.Plugin; namespace Cube3D { /// /// Interaction logic for App.xaml /// public partial class App : Application { protected override void OnStartup( StartupEventArgs e ) { base.OnStartup( e ); var pluginInfo = PluginManager.PluginInfo; if ( pluginInfo == null || string.IsNullOrEmpty( pluginInfo.Name ) ) { MessageBox.Show( $"{PluginManager.PluginInfoFile} invalid." ); Current.Shutdown(); } if ( !PluginManager.CheckRequirements( pluginInfo.Requirements ) ) { MessageBox.Show( "Plugin Error.\nThe system does not meet the Requirements." ); Current.Shutdown(); } } public static void Restart() { Process.Start( PluginManager.GetAppPath() ); Current.Shutdown(); } } } ================================================ FILE: Plugins.sln/Cube3D/AssemblyInfo.cs ================================================ using System.Windows; [assembly: ThemeInfo( ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located //(used if a resource is not found in the page, // or application resource dictionaries) ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries) )] ================================================ FILE: Plugins.sln/Cube3D/AutoVersion.tt ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of Cube3D. Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Cube3D. If not, see . */ <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".cs" #> <#@ Assembly Name="System.Core.dll" #> <#@ Assembly Name="System.Windows.Forms.dll" #> <#@ import namespace="System.IO" #> using System.Reflection; [assembly: AssemblyProduct("<#= AppName #>")] [assembly: AssemblyTitle("<#= AppDesc #>")] [assembly: AssemblyDescription("<#= AppDesc #>")] [assembly: AssemblyCompany("https://github.com/newlooper")] [assembly: AssemblyCopyright("Copyright © <#= Copyright #>")] [assembly: AssemblyVersion("<#= MAJOR #>.<#= MINOR #>.<#= DaysSinceProjectStarted #>.<#= MinutesSinceMidnight #>")] [assembly: AssemblyFileVersion("<#= MAJOR #>.<#= MINOR #>.<#= DaysSinceProjectStarted #>.<#= MinutesSinceMidnight #>")] <#+ private static readonly DateTime ProjectStartedDate = new( 2022, 2, 28 ); private static readonly string Copyright = ProjectStartedDate.Year + " - " + DateTime.Now.Year; private static readonly string AppName = new DirectoryInfo( "." ).Name; private static readonly string AppDesc = "VirtualSpace.Plugin - Cube3D"; private const int MAJOR = 1; private const int MINOR = 0; private static readonly int DaysSinceProjectStarted = (int)( DateTime.UtcNow - ProjectStartedDate ).TotalDays; private static readonly int MinutesSinceMidnight = (int)DateTime.UtcNow.TimeOfDay.TotalMinutes; #> ================================================ FILE: Plugins.sln/Cube3D/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Plugins.sln/Cube3D/Config/Const.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . namespace Cube3D.Config { public static class Const { public const double FakeHideX = -10000.0; public const double FakeHideY = -10000.0; public const int AnimationDurationMin = 100; public const int AnimationDurationMax = 1000; public const int CheckAliveIntervalMin = 1; public const int CheckAliveIntervalMax = 60; public const int CheckAliveIntervalDefault = 10; public const string Front = nameof( Front ); public const string Others = nameof( Others ); } } ================================================ FILE: Plugins.sln/Cube3D/Config/Settings.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . using System; using Cube3D.Effects; namespace Cube3D.Config { public class Settings { private int _animationDuration; private int _checkAliveInterval; public int AnimationDuration { get => _animationDuration; set { if ( value < Const.AnimationDurationMin || value > Const.AnimationDurationMax ) { _animationDuration = Const.AnimationDurationMin; } else { _animationDuration = value; } } } public int CheckAliveInterval { get => _checkAliveInterval; set { if ( value < Const.CheckAliveIntervalMin || value > Const.CheckAliveIntervalMax ) { _checkAliveInterval = Const.CheckAliveIntervalDefault; } else { _checkAliveInterval = value; } } } public EffectType SelectedEffect { get; set; } public EaseType EaseType { get; set; } = EaseType.None; public EaseMode EaseMode { get; set; } = EaseMode.EaseOut; public TransitionType TransitionType { get; set; } = TransitionType.AnimationAndNotificationGrid; public bool ShowNotificationGridOnAllScreens { get; set; } } [Flags] public enum TransitionType { AnimationOnly = 0b0001, NotificationGridOnly = 0b0010, AnimationAndNotificationGrid = AnimationOnly | NotificationGridOnly } } ================================================ FILE: Plugins.sln/Cube3D/Config/SettingsManager.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Plugins. // // Plugins is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Plugins is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Plugins. If not, see . using System.IO; using System.Text.Json; using VirtualSpace.Plugin; namespace Cube3D.Config { public class SettingsManager { private const string PluginSettingFile = "settings.json"; public static readonly Settings Settings = GetSettings(); private static Settings GetSettings() { var file = Path.Combine( PluginManager.GetAppFolder(), PluginSettingFile ); return PluginManager.LoadFromJson( file ); } public static void SaveJson( string file = null ) { file ??= Path.Combine( PluginManager.GetAppFolder(), PluginSettingFile ); var contents = JsonSerializer.SerializeToUtf8Bytes( Settings, new JsonSerializerOptions {WriteIndented = true} ); File.WriteAllBytesAsync( file, contents ); } } } ================================================ FILE: Plugins.sln/Cube3D/Cube3D.csproj ================================================  WinExe net6.0-windows10.0.20348.0;net6.0-windows10.0.22000.0; 9 true false app.manifest false true True AutoVersion.tt Always Always ================================================ FILE: Plugins.sln/Cube3D/D3DImages/D3DImages.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . using System.Collections.Generic; using System.Windows; using System.Windows.Interop; using Cube3D.Config; namespace Cube3D.D3DImages { public static class D3DImages { public static readonly D3DImage FrontD3DImage = Application.Current.Resources[Const.Front] as D3DImage; public static readonly D3DImage OthersD3DImage = Application.Current.Resources[Const.Others] as D3DImage; public static readonly Dictionary D3DImageDict = new() { { Const.Front, new D3DImageInfo { Image = FrontD3DImage } }, { Const.Others, new D3DImageInfo { Image = OthersD3DImage } } }; } } ================================================ FILE: Plugins.sln/Cube3D/Effects/Cube.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . using System; using System.Collections.Generic; using System.Windows; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; using Cube3D.Config; namespace Cube3D.Effects { public class Cube : Effect { private static readonly Dictionary TransformDirections = new() { { KeyCode.Left, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( 0, 1, 0 ), 0 ) ) { CenterX = MeshWidth / 2, CenterZ = -MeshWidth / 2 } }, { KeyCode.Right, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( 0, -1, 0 ), 0 ) ) { CenterX = MeshWidth / 2, CenterZ = -MeshWidth / 2 } }, { KeyCode.Up, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( 1, 0, 0 ), 0 ) ) { CenterY = MeshHeight / 2, CenterZ = -MeshHeight / 2 } }, { KeyCode.Down, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( -1, 0, 0 ), 0 ) ) { CenterY = MeshHeight / 2, CenterZ = -MeshHeight / 2 } } }; ///////////////////////////// // 立方体 // 前/后表面 —— 水平/垂直旋转 // 左/右表面 —— 水平旋转 // 上/下表面 —— 垂直旋转 private readonly Model3DGroup _cube = new(); private readonly GeometryModel3D _cubeBack = new(); private readonly MeshGeometry3D _cubeBackMesh = new(); private readonly GeometryModel3D _cubeBottom = new(); private readonly MeshGeometry3D _cubeBottomMesh = new(); private readonly GeometryModel3D _cubeFront = new(); private readonly MeshGeometry3D _cubeFrontMesh = new(); private readonly GeometryModel3D _cubeLeft = new(); private readonly MeshGeometry3D _cubeLeftMesh = new(); private readonly GeometryModel3D _cubeRight = new(); private readonly MeshGeometry3D _cubeRightMesh = new(); private readonly GeometryModel3D _cubeTop = new(); private readonly MeshGeometry3D _cubeTopMesh = new(); public Cube() { Animation = new DoubleAnimation { From = 0, To = 90, FillBehavior = FillBehavior.Stop }; } public override void Build( Model3DGroup model3DGroup ) { //////////////////////////////////////////////////////////////// // front _cubeFrontMesh.Positions.Add( new Point3D( 0, 0, 0 ) ); _cubeFrontMesh.Positions.Add( new Point3D( MeshWidth, 0, 0 ) ); _cubeFrontMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, 0 ) ); _cubeFrontMesh.Positions.Add( new Point3D( 0, MeshHeight, 0 ) ); AddTriangleIndices( _cubeFrontMesh ); AddTextureCoordinatesFront( _cubeFrontMesh ); //////////////////////////////////////////////////////////////// // back // _cubeBackMesh.Positions.Add( new Point3D( MeshWidth, 0, -MeshWidth ) ); // _cubeBackMesh.Positions.Add( new Point3D( 0, 0, -MeshWidth ) ); // _cubeBackMesh.Positions.Add( new Point3D( 0, MeshHeight, -MeshWidth ) ); // _cubeBackMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, -MeshWidth ) ); // AddTriangleIndices( _cubeBackMesh ); // AddTextureCoordinatesFront( _cubeBackMesh ); ////////////////////////////////////////////////////////////////////////////////////////////////////////// // CubeH //////////////////////////////////////////////////////////////// // left _cubeLeftMesh.Positions.Add( new Point3D( 0, 0, -MeshWidth ) ); _cubeLeftMesh.Positions.Add( new Point3D( 0, 0, 0 ) ); _cubeLeftMesh.Positions.Add( new Point3D( 0, MeshHeight, 0 ) ); _cubeLeftMesh.Positions.Add( new Point3D( 0, MeshHeight, -MeshWidth ) ); AddTriangleIndices( _cubeLeftMesh ); AddTextureCoordinatesFront( _cubeLeftMesh ); //////////////////////////////////////////////////////////////// // right _cubeRightMesh.Positions.Add( new Point3D( MeshWidth, 0, 0 ) ); _cubeRightMesh.Positions.Add( new Point3D( MeshWidth, 0, -MeshWidth ) ); _cubeRightMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, -MeshWidth ) ); _cubeRightMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, 0 ) ); AddTriangleIndices( _cubeRightMesh ); AddTextureCoordinatesFront( _cubeRightMesh ); ////////////////////////////////////////////////////////////////////////////////////////////////////////// // CubeV //////////////////////////////////////////////////////////////// // top _cubeTopMesh.Positions.Add( new Point3D( 0 * MeshWidth, 1 * MeshHeight, 0 ) ); _cubeTopMesh.Positions.Add( new Point3D( 1 * MeshWidth, 1 * MeshHeight, 0 ) ); _cubeTopMesh.Positions.Add( new Point3D( 1 * MeshWidth, 1 * MeshHeight, -MeshHeight ) ); _cubeTopMesh.Positions.Add( new Point3D( 0 * MeshWidth, 1 * MeshHeight, -MeshHeight ) ); AddTriangleIndices( _cubeTopMesh ); AddTextureCoordinatesFront( _cubeTopMesh ); //////////////////////////////////////////////////////////////// // bottom _cubeBottomMesh.Positions.Add( new Point3D( 0 * MeshWidth, 0 * MeshHeight, -MeshHeight ) ); _cubeBottomMesh.Positions.Add( new Point3D( 1 * MeshWidth, 0 * MeshHeight, -MeshHeight ) ); _cubeBottomMesh.Positions.Add( new Point3D( 1 * MeshWidth, 0 * MeshHeight, 0 ) ); _cubeBottomMesh.Positions.Add( new Point3D( 0 * MeshWidth, 0 * MeshHeight, 0 ) ); AddTriangleIndices( _cubeBottomMesh ); AddTextureCoordinatesFront( _cubeBottomMesh ); //////////////////////////////////////////////////////////////// // Front 永远显示当前桌面;其在动画中定格,动画结束后归位并继续截屏 var frontMaterial = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.FrontD3DImage ) ); _cubeFront.Material = frontMaterial; //////////////////////////////////////////////////////////////// // 其他位面永远显示目标桌面,可以共享同一个材质;其在动画中持续截屏,动画结束后归位并停止截屏 var othersMaterial = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.OthersD3DImage ) ); // _cubeBack.Material = othersMaterial; _cubeLeft.Material = othersMaterial; _cubeRight.Material = othersMaterial; _cubeTop.Material = othersMaterial; _cubeBottom.Material = othersMaterial; // _cubeFront.BackMaterial = frontMaterial; // _cubeRight.BackMaterial = rightMaterial; // _cubeBack.BackMaterial = backMaterial; // _cubeLeft.BackMaterial = leftMaterial; // _cubeTop.BackMaterial = topMaterial; // _cubeBottom.BackMaterial = bottomMaterial; //////////////////////////////////////////// // set GeometryModel3D' mesh _cubeFront.Geometry = _cubeFrontMesh; // _cubeBack.Geometry = _cubeBackMesh; _cubeLeft.Geometry = _cubeLeftMesh; _cubeRight.Geometry = _cubeRightMesh; _cubeTop.Geometry = _cubeTopMesh; _cubeBottom.Geometry = _cubeBottomMesh; //////////////////////////////////////////// // Model3D/Model3DGroup _cube.Children.Add( _cubeFront ); // _cube.Children.Add( _cubeBack ); _cube.Children.Add( _cubeLeft ); _cube.Children.Add( _cubeRight ); _cube.Children.Add( _cubeTop ); _cube.Children.Add( _cubeBottom ); model3DGroup.Children.Clear(); model3DGroup.Children.Add( _cube ); model3DGroup.Children.Add( CommonLight ); } public override void AnimationInDirection( KeyCode dir, Model3DGroup model3DGroup, IEasingFunction ef = null ) { switch ( dir ) { case KeyCode.Left: Transform3D = TransformDirections[KeyCode.Left]; break; case KeyCode.Right: Transform3D = TransformDirections[KeyCode.Right]; break; case KeyCode.Up: Transform3D = TransformDirections[KeyCode.Up]; break; case KeyCode.Down: Transform3D = TransformDirections[KeyCode.Down]; break; } if ( TransGroup.Children.Count == 0 ) { TransGroup.Children.Add( Transform3D ); } else { TransGroup.Children[0] = Transform3D; } model3DGroup.Transform = TransGroup; var animation = (DoubleAnimation)Animation; animation.Duration = new Duration( TimeSpan.FromMilliseconds( SettingsManager.Settings.AnimationDuration ) ); animation.EasingFunction = ef; var transform = (RotateTransform3D)Transform3D; transform.Rotation.BeginAnimation( AxisAngleRotation3D.AngleProperty, animation ); } } } ================================================ FILE: Plugins.sln/Cube3D/Effects/Effect.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . using System; using System.Windows; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; namespace Cube3D.Effects { public abstract class Effect { protected static readonly double MeshHeight = SystemParameters.PrimaryScreenHeight / SystemParameters.PrimaryScreenWidth; protected static readonly double MeshWidth = 1.0; protected static readonly AmbientLight CommonLight = new() {Color = Colors.White}; protected readonly Transform3DGroup TransGroup = new(); protected Timeline Animation; protected Transform3D Transform3D; protected static void AddTriangleIndices( MeshGeometry3D meshGeometry3D ) { meshGeometry3D.TriangleIndices.Add( 0 ); meshGeometry3D.TriangleIndices.Add( 1 ); meshGeometry3D.TriangleIndices.Add( 2 ); meshGeometry3D.TriangleIndices.Add( 2 ); meshGeometry3D.TriangleIndices.Add( 3 ); meshGeometry3D.TriangleIndices.Add( 0 ); } protected static void AddTextureCoordinatesFront( MeshGeometry3D meshGeometry3D ) { meshGeometry3D.TextureCoordinates.Add( new Point( 0, 1 ) ); meshGeometry3D.TextureCoordinates.Add( new Point( 1, 1 ) ); meshGeometry3D.TextureCoordinates.Add( new Point( 1, 0 ) ); meshGeometry3D.TextureCoordinates.Add( new Point( 0, 0 ) ); } public abstract void Build( Model3DGroup model3DGroup ); public abstract void AnimationInDirection( KeyCode dir, Model3DGroup model3DGroup, IEasingFunction ef = null ); public void AddAnimationCompletedListener( EventHandler handler ) { Animation.Completed += handler; } } public enum EffectType { Cube, InsideCube, Slide, Reveal, Fade, Flip } public enum KeyCode { Left = 0x25, Up = 0x26, Right = 0x27, Down = 0x28 } public enum EaseType { None, BounceEase, CircleEase, CubicEase, ExponentialEase, PowerEase, QuadraticEase, QuarticEase, QuinticEase, SineEase } public enum EaseMode { EaseIn, EaseOut, EaseInOut } public static class EaseFactory { public static IEasingFunction GetEaseByName( EaseType et, EasingMode em ) { IEasingFunction ef = et switch { EaseType.BounceEase => new BounceEase {EasingMode = em}, EaseType.CircleEase => new CircleEase {EasingMode = em}, EaseType.CubicEase => new CubicEase {EasingMode = em}, EaseType.ExponentialEase => new ExponentialEase {EasingMode = em}, EaseType.PowerEase => new PowerEase {EasingMode = em}, EaseType.QuadraticEase => new QuadraticEase {EasingMode = em}, EaseType.QuarticEase => new QuarticEase {EasingMode = em}, EaseType.QuinticEase => new QuinticEase {EasingMode = em}, EaseType.SineEase => new SineEase {EasingMode = em}, EaseType.None => null, _ => null }; return ef; } public static EasingMode GetEaseModeByName( EaseMode em ) { var eMode = em switch { EaseMode.EaseIn => EasingMode.EaseIn, EaseMode.EaseOut => EasingMode.EaseOut, EaseMode.EaseInOut => EasingMode.EaseInOut, _ => EasingMode.EaseOut }; return eMode; } } } ================================================ FILE: Plugins.sln/Cube3D/Effects/Fade.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . using System; using System.Windows; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; using Cube3D.Config; namespace Cube3D.Effects { public class Fade : Effect { private readonly DoubleAnimation _animationOfFace2 = new() { From = 0, To = 1, FillBehavior = FillBehavior.Stop }; ///////////////////////////// // 重叠的两个面 private readonly Model3DGroup _face = new(); private readonly GeometryModel3D _face1 = new(); private readonly MeshGeometry3D _face1Mesh = new(); private readonly GeometryModel3D _face2 = new(); private readonly MeshGeometry3D _face2Mesh = new(); private readonly ImageBrush _frontD3DImage = new( D3DImages.D3DImages.FrontD3DImage ); private readonly ImageBrush _othersD3DImage = new( D3DImages.D3DImages.OthersD3DImage ); public Fade() { Animation = new DoubleAnimation { From = 1, To = 0, FillBehavior = FillBehavior.Stop }; } public override void Build( Model3DGroup model3DGroup ) { _face1Mesh.Positions.Add( new Point3D( 0, 0, 0 ) ); _face1Mesh.Positions.Add( new Point3D( MeshWidth, 0, 0 ) ); _face1Mesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, 0 ) ); _face1Mesh.Positions.Add( new Point3D( 0, MeshHeight, 0 ) ); AddTriangleIndices( _face1Mesh ); AddTextureCoordinatesFront( _face1Mesh ); _face2Mesh.Positions.Add( new Point3D( 0, 0, 0 ) ); _face2Mesh.Positions.Add( new Point3D( MeshWidth, 0, 0 ) ); _face2Mesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, 0 ) ); _face2Mesh.Positions.Add( new Point3D( 0, MeshHeight, 0 ) ); AddTriangleIndices( _face2Mesh ); AddTextureCoordinatesFront( _face2Mesh ); //////////////////////////////////////////////////////////////// // Front 永远显示当前桌面;其在动画中定格,动画结束后归位并继续截屏 var frontMaterial = new DiffuseMaterial( _frontD3DImage ); _face1.Material = frontMaterial; //////////////////////////////////////////////////////////////// // 其他位面永远显示目标桌面,可以共享同一个材质;其在动画中持续截屏,动画结束后归位并停止截屏 var othersMaterial = new DiffuseMaterial( _othersD3DImage ); _face2.Material = othersMaterial; //////////////////////////////////////////// // set GeometryModel3D' mesh _face1.Geometry = _face1Mesh; _face2.Geometry = _face2Mesh; //////////////////////////////////////////// // Model3D/Model3DGroup _face.Children.Add( _face2 ); _face.Children.Add( _face1 ); // _face1 above _face2 model3DGroup.Children.Clear(); model3DGroup.Children.Add( _face ); model3DGroup.Children.Add( CommonLight ); } public override void AnimationInDirection( KeyCode dir, Model3DGroup model3DGroup, IEasingFunction ef = null ) { var animationOfFace1 = (DoubleAnimation)Animation; animationOfFace1.Duration = new Duration( TimeSpan.FromMilliseconds( SettingsManager.Settings.AnimationDuration ) ); animationOfFace1.EasingFunction = ef; _animationOfFace2.Duration = animationOfFace1.Duration; _animationOfFace2.EasingFunction = ef; _frontD3DImage.BeginAnimation( Brush.OpacityProperty, animationOfFace1 ); _othersD3DImage.BeginAnimation( Brush.OpacityProperty, _animationOfFace2 ); } } } ================================================ FILE: Plugins.sln/Cube3D/Effects/Flip.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . using System; using System.Collections.Generic; using System.Windows; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; using Cube3D.Config; namespace Cube3D.Effects { public class Flip : Effect { private static readonly Dictionary TransformDirections = new() { { KeyCode.Left, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( 0, 1, 0 ), 0 ) ) { CenterX = MeshWidth / 2 } }, { KeyCode.Right, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( 0, -1, 0 ), 0 ) ) { CenterX = MeshWidth / 2 } }, { KeyCode.Up, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( 1, 0, 0 ), 0 ) ) { CenterY = MeshHeight / 2 } }, { KeyCode.Down, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( -1, 0, 0 ), 0 ) ) { CenterY = MeshHeight / 2 } } }; ///////////////////////////// // 单面翻转 private readonly Model3DGroup _face = new(); private readonly GeometryModel3D _faceFront = new(); private readonly MeshGeometry3D _faceFrontMesh = new(); private DiffuseMaterial _backH; private DiffuseMaterial _backV; public Flip() { Animation = new DoubleAnimation { From = 0, To = 180, FillBehavior = FillBehavior.Stop }; } public override void Build( Model3DGroup model3DGroup ) { //////////////////////////////////////////////////////////////// // front _faceFrontMesh.Positions.Add( new Point3D( 0, 0, 0 ) ); _faceFrontMesh.Positions.Add( new Point3D( MeshWidth, 0, 0 ) ); _faceFrontMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, 0 ) ); _faceFrontMesh.Positions.Add( new Point3D( 0, MeshHeight, 0 ) ); AddTriangleIndices( _faceFrontMesh ); AddTextureCoordinatesFront( _faceFrontMesh ); //////////////////////////////////////////////////////////////// // Front 永远显示当前桌面;其在动画中定格,动画结束后归位并继续截屏 var frontMaterial = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.FrontD3DImage ) ); _faceFront.Material = frontMaterial; //////////////////////////////////////////////////////////////// // Flip 特效利用了 BackMaterial, 水平/垂直翻转的贴图映射需要差异化 _backH = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.OthersD3DImage ) { RelativeTransform = new ScaleTransform { ScaleX = -1, CenterX = 0.5 } } ); _backV = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.OthersD3DImage ) { RelativeTransform = new ScaleTransform { ScaleY = -1, CenterY = 0.5 } } ); //////////////////////////////////////////// // set GeometryModel3D' mesh _faceFront.Geometry = _faceFrontMesh; //////////////////////////////////////////// // Model3D/Model3DGroup _face.Children.Add( _faceFront ); model3DGroup.Children.Clear(); model3DGroup.Children.Add( _face ); model3DGroup.Children.Add( CommonLight ); } public override void AnimationInDirection( KeyCode dir, Model3DGroup model3DGroup, IEasingFunction ef = null ) { switch ( dir ) { case KeyCode.Left: Transform3D = TransformDirections[KeyCode.Left]; FlipInDirection( "H" ); break; case KeyCode.Right: Transform3D = TransformDirections[KeyCode.Right]; FlipInDirection( "H" ); break; case KeyCode.Up: Transform3D = TransformDirections[KeyCode.Up]; FlipInDirection( "V" ); break; case KeyCode.Down: Transform3D = TransformDirections[KeyCode.Down]; FlipInDirection( "V" ); break; } if ( TransGroup.Children.Count == 0 ) { TransGroup.Children.Add( Transform3D ); } else { TransGroup.Children[0] = Transform3D; } model3DGroup.Transform = TransGroup; var animation = (DoubleAnimation)Animation; animation.Duration = new Duration( TimeSpan.FromMilliseconds( SettingsManager.Settings.AnimationDuration ) ); animation.EasingFunction = ef; var transform = (RotateTransform3D)Transform3D; transform.Rotation.BeginAnimation( AxisAngleRotation3D.AngleProperty, animation ); } private void FlipInDirection( string dir ) { _faceFront.BackMaterial = dir == "H" ? _backH : _backV; } } } ================================================ FILE: Plugins.sln/Cube3D/Effects/InsideCube.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . using System; using System.Collections.Generic; using System.Windows; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; using Cube3D.Config; namespace Cube3D.Effects { public class InsideCube : Effect { private static readonly Dictionary TransformDirections = new() { { KeyCode.Left, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( 0, -1, 0 ), 0 ) ) { CenterX = MeshWidth / 2, CenterZ = MeshWidth / 2 } }, { KeyCode.Right, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( 0, 1, 0 ), 0 ) ) { CenterX = MeshWidth / 2, CenterZ = MeshWidth / 2 } }, { KeyCode.Up, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( -1, 0, 0 ), 0 ) ) { CenterY = MeshHeight / 2, CenterZ = MeshHeight / 2 } }, { KeyCode.Down, new RotateTransform3D( new AxisAngleRotation3D( new Vector3D( 1, 0, 0 ), 0 ) ) { CenterY = MeshHeight / 2, CenterZ = MeshHeight / 2 } } }; ///////////////////////////// // 立方体 // 前/后表面 —— 水平/垂直旋转 // 左/右表面 —— 水平旋转 // 上/下表面 —— 垂直旋转 private readonly Model3DGroup _cube = new(); private readonly GeometryModel3D _cubeBack = new(); private readonly MeshGeometry3D _cubeBackMesh = new(); private readonly GeometryModel3D _cubeBottom = new(); private readonly MeshGeometry3D _cubeBottomMesh = new(); private readonly GeometryModel3D _cubeFront = new(); private readonly MeshGeometry3D _cubeFrontMesh = new(); private readonly GeometryModel3D _cubeLeft = new(); private readonly MeshGeometry3D _cubeLeftMesh = new(); private readonly GeometryModel3D _cubeRight = new(); private readonly MeshGeometry3D _cubeRightMesh = new(); private readonly GeometryModel3D _cubeTop = new(); private readonly MeshGeometry3D _cubeTopMesh = new(); public InsideCube() { Animation = new DoubleAnimation { From = 0, To = 90, FillBehavior = FillBehavior.Stop }; } public override void Build( Model3DGroup model3DGroup ) { //////////////////////////////////////////////////////////////// // front _cubeFrontMesh.Positions.Add( new Point3D( 0, 0, 0 ) ); _cubeFrontMesh.Positions.Add( new Point3D( MeshWidth, 0, 0 ) ); _cubeFrontMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, 0 ) ); _cubeFrontMesh.Positions.Add( new Point3D( 0, MeshHeight, 0 ) ); AddTriangleIndices( _cubeFrontMesh ); AddTextureCoordinatesFront( _cubeFrontMesh ); //////////////////////////////////////////////////////////////// // back // _cubeBackMesh.Positions.Add( new Point3D( MeshWidth, 0, MeshWidth ) ); // _cubeBackMesh.Positions.Add( new Point3D( 0, 0, MeshWidth ) ); // _cubeBackMesh.Positions.Add( new Point3D( 0, MeshHeight, MeshWidth ) ); // _cubeBackMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, MeshWidth ) ); // AddTriangleIndices( _cubeBackMesh ); // AddTextureCoordinatesFront( _cubeBackMesh ); ////////////////////////////////////////////////////////////////////////////////////////////////////////// // CubeH //////////////////////////////////////////////////////////////// // left _cubeLeftMesh.Positions.Add( new Point3D( 0, 0, MeshWidth ) ); _cubeLeftMesh.Positions.Add( new Point3D( 0, 0, 0 ) ); _cubeLeftMesh.Positions.Add( new Point3D( 0, MeshHeight, 0 ) ); _cubeLeftMesh.Positions.Add( new Point3D( 0, MeshHeight, MeshWidth ) ); AddTriangleIndices( _cubeLeftMesh ); AddTextureCoordinatesFront( _cubeLeftMesh ); //////////////////////////////////////////////////////////////// // right _cubeRightMesh.Positions.Add( new Point3D( MeshWidth, 0, 0 ) ); _cubeRightMesh.Positions.Add( new Point3D( MeshWidth, 0, MeshWidth ) ); _cubeRightMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, MeshWidth ) ); _cubeRightMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, 0 ) ); AddTriangleIndices( _cubeRightMesh ); AddTextureCoordinatesFront( _cubeRightMesh ); ////////////////////////////////////////////////////////////////////////////////////////////////////////// // CubeV //////////////////////////////////////////////////////////////// // top _cubeTopMesh.Positions.Add( new Point3D( 0, MeshHeight, 0 ) ); _cubeTopMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, 0 ) ); _cubeTopMesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, MeshHeight ) ); _cubeTopMesh.Positions.Add( new Point3D( 0, MeshHeight, MeshHeight ) ); AddTriangleIndices( _cubeTopMesh ); AddTextureCoordinatesFront( _cubeTopMesh ); //////////////////////////////////////////////////////////////// // bottom _cubeBottomMesh.Positions.Add( new Point3D( 0, 0, MeshHeight ) ); _cubeBottomMesh.Positions.Add( new Point3D( MeshWidth, 0, MeshHeight ) ); _cubeBottomMesh.Positions.Add( new Point3D( MeshWidth, 0, 0 ) ); _cubeBottomMesh.Positions.Add( new Point3D( 0, 0, 0 ) ); AddTriangleIndices( _cubeBottomMesh ); AddTextureCoordinatesFront( _cubeBottomMesh ); //////////////////////////////////////////////////////////////// // Front 永远显示当前桌面;其在动画中定格,动画结束后归位并继续截屏 var frontMaterial = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.FrontD3DImage ) ); _cubeFront.Material = frontMaterial; //////////////////////////////////////////////////////////////// // 其他位面永远显示目标桌面,可以共享同一个材质;其在动画中持续截屏,动画结束后归位并停止截屏 var othersMaterial = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.OthersD3DImage ) ); // _cubeBack.Material = othersMaterial; _cubeLeft.Material = othersMaterial; _cubeRight.Material = othersMaterial; _cubeTop.Material = othersMaterial; _cubeBottom.Material = othersMaterial; //////////////////////////////////////////// // set GeometryModel3D' mesh _cubeFront.Geometry = _cubeFrontMesh; // _cubeBack.Geometry = _cubeBackMesh; _cubeLeft.Geometry = _cubeLeftMesh; _cubeRight.Geometry = _cubeRightMesh; _cubeTop.Geometry = _cubeTopMesh; _cubeBottom.Geometry = _cubeBottomMesh; //////////////////////////////////////////// // Model3D/Model3DGroup _cube.Children.Add( _cubeFront ); // _cube.Children.Add( _cubeBack ); _cube.Children.Add( _cubeLeft ); _cube.Children.Add( _cubeRight ); _cube.Children.Add( _cubeTop ); _cube.Children.Add( _cubeBottom ); model3DGroup.Children.Clear(); model3DGroup.Children.Add( _cube ); model3DGroup.Children.Add( CommonLight ); } public override void AnimationInDirection( KeyCode dir, Model3DGroup model3DGroup, IEasingFunction ef = null ) { switch ( dir ) { case KeyCode.Left: Transform3D = TransformDirections[KeyCode.Left]; break; case KeyCode.Right: Transform3D = TransformDirections[KeyCode.Right]; break; case KeyCode.Up: Transform3D = TransformDirections[KeyCode.Up]; break; case KeyCode.Down: Transform3D = TransformDirections[KeyCode.Down]; break; } if ( TransGroup.Children.Count == 0 ) { TransGroup.Children.Add( Transform3D ); } else { TransGroup.Children[0] = Transform3D; } model3DGroup.Transform = TransGroup; var animation = (DoubleAnimation)Animation; animation.Duration = new Duration( TimeSpan.FromMilliseconds( SettingsManager.Settings.AnimationDuration ) ); animation.EasingFunction = ef; var transform = (RotateTransform3D)Transform3D; transform.Rotation.BeginAnimation( AxisAngleRotation3D.AngleProperty, animation ); } } } ================================================ FILE: Plugins.sln/Cube3D/Effects/Reveal.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . using System; using System.Collections.Generic; using System.Windows; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; using Cube3D.Config; namespace Cube3D.Effects { public class Reveal : Effect { private static readonly Dictionary TransformDirections = new() { { KeyCode.Left, new TranslateTransform3D() }, { KeyCode.Right, new TranslateTransform3D() }, { KeyCode.Up, new TranslateTransform3D() }, { KeyCode.Down, new TranslateTransform3D() } }; ///////////////////////////// // 重叠的两个面 private readonly Model3DGroup _face = new(); private readonly GeometryModel3D _face1 = new(); private readonly MeshGeometry3D _face1Mesh = new(); private readonly GeometryModel3D _face2 = new(); private readonly MeshGeometry3D _face2Mesh = new(); public Reveal() { Animation = new DoubleAnimation { From = 0, FillBehavior = FillBehavior.Stop }; } public override void Build( Model3DGroup model3DGroup ) { _face1Mesh.Positions.Add( new Point3D( 0, 0, 0 ) ); _face1Mesh.Positions.Add( new Point3D( MeshWidth, 0, 0 ) ); _face1Mesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, 0 ) ); _face1Mesh.Positions.Add( new Point3D( 0, MeshHeight, 0 ) ); AddTriangleIndices( _face1Mesh ); AddTextureCoordinatesFront( _face1Mesh ); _face2Mesh.Positions.Add( new Point3D( 0, 0, 0 ) ); _face2Mesh.Positions.Add( new Point3D( MeshWidth, 0, 0 ) ); _face2Mesh.Positions.Add( new Point3D( MeshWidth, MeshHeight, 0 ) ); _face2Mesh.Positions.Add( new Point3D( 0, MeshHeight, 0 ) ); AddTriangleIndices( _face2Mesh ); AddTextureCoordinatesFront( _face2Mesh ); //////////////////////////////////////////////////////////////// // Front 永远显示当前桌面;其在动画中定格,动画结束后归位并继续截屏 var frontMaterial = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.FrontD3DImage ) ); _face1.Material = frontMaterial; //////////////////////////////////////////////////////////////// // 其他位面永远显示目标桌面,可以共享同一个材质;其在动画中持续截屏,动画结束后归位并停止截屏 var othersMaterial = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.OthersD3DImage ) ); _face2.Material = othersMaterial; //////////////////////////////////////////// // set GeometryModel3D' mesh _face1.Geometry = _face1Mesh; _face2.Geometry = _face2Mesh; //////////////////////////////////////////// // Model3D/Model3DGroup _face.Children.Add( _face2 ); _face.Children.Add( _face1 ); // _face1 above _face2 model3DGroup.Children.Clear(); model3DGroup.Children.Add( _face ); model3DGroup.Children.Add( CommonLight ); } public override void AnimationInDirection( KeyCode dir, Model3DGroup model3DGroup, IEasingFunction ef = null ) { var offsetProperty = TranslateTransform3D.OffsetXProperty; var animation = (DoubleAnimation)Animation; animation.Duration = new Duration( TimeSpan.FromMilliseconds( SettingsManager.Settings.AnimationDuration ) ); animation.EasingFunction = ef; switch ( dir ) { case KeyCode.Left: Transform3D = TransformDirections[KeyCode.Left]; animation.To = MeshWidth; break; case KeyCode.Right: Transform3D = TransformDirections[KeyCode.Right]; animation.To = -MeshWidth; break; case KeyCode.Up: Transform3D = TransformDirections[KeyCode.Up]; animation.To = -MeshHeight; offsetProperty = TranslateTransform3D.OffsetYProperty; break; case KeyCode.Down: Transform3D = TransformDirections[KeyCode.Down]; animation.To = MeshHeight; offsetProperty = TranslateTransform3D.OffsetYProperty; break; } if ( TransGroup.Children.Count == 0 ) { TransGroup.Children.Add( Transform3D ); } else { TransGroup.Children[0] = Transform3D; } _face1.Transform = TransGroup; var transform = (TranslateTransform3D)Transform3D; transform.BeginAnimation( offsetProperty, animation ); } } } ================================================ FILE: Plugins.sln/Cube3D/Effects/Slide.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . using System; using System.Collections.Generic; using System.Windows; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; using Cube3D.Config; namespace Cube3D.Effects { public class Slide : Effect { private static readonly Dictionary TransformDirections = new() { { KeyCode.Left, new TranslateTransform3D() }, { KeyCode.Right, new TranslateTransform3D() }, { KeyCode.Up, new TranslateTransform3D() }, { KeyCode.Down, new TranslateTransform3D() } }; ///////////////////////////// // 十字排列的五个全等面 private readonly Model3DGroup _face = new(); private readonly GeometryModel3D _faceBottom = new(); private readonly MeshGeometry3D _faceBottomMesh = new(); private readonly GeometryModel3D _faceCenter = new(); private readonly MeshGeometry3D _faceCenterMesh = new(); private readonly GeometryModel3D _faceLeft = new(); private readonly MeshGeometry3D _faceLeftMesh = new(); private readonly GeometryModel3D _faceRight = new(); private readonly MeshGeometry3D _faceRightMesh = new(); private readonly GeometryModel3D _faceTop = new(); private readonly MeshGeometry3D _faceTopMesh = new(); public Slide() { Animation = new DoubleAnimation { From = 0, FillBehavior = FillBehavior.Stop }; } public override void Build( Model3DGroup model3DGroup ) { //////////////////////////////////////////////////////////////// // center var centerPoints = new Point3D[] { new( 0, 0, 0 ), new( MeshWidth, 0, 0 ), new( MeshWidth, MeshHeight, 0 ), new( 0, MeshHeight, 0 ) }; _faceCenterMesh.Positions.Add( centerPoints[0] ); _faceCenterMesh.Positions.Add( centerPoints[1] ); _faceCenterMesh.Positions.Add( centerPoints[2] ); _faceCenterMesh.Positions.Add( centerPoints[3] ); AddTriangleIndices( _faceCenterMesh ); AddTextureCoordinatesFront( _faceCenterMesh ); //////////////////////////////////////////////////////////////// // left var left = new Vector3D( -MeshWidth, 0, 0 ); _faceLeftMesh.Positions.Add( centerPoints[0] + left ); _faceLeftMesh.Positions.Add( centerPoints[1] + left ); _faceLeftMesh.Positions.Add( centerPoints[2] + left ); _faceLeftMesh.Positions.Add( centerPoints[3] + left ); AddTriangleIndices( _faceLeftMesh ); AddTextureCoordinatesFront( _faceLeftMesh ); //////////////////////////////////////////////////////////////// // right var right = new Vector3D( MeshWidth, 0, 0 ); _faceRightMesh.Positions.Add( centerPoints[0] + right ); _faceRightMesh.Positions.Add( centerPoints[1] + right ); _faceRightMesh.Positions.Add( centerPoints[2] + right ); _faceRightMesh.Positions.Add( centerPoints[3] + right ); AddTriangleIndices( _faceRightMesh ); AddTextureCoordinatesFront( _faceRightMesh ); //////////////////////////////////////////////////////////////// // top var top = new Vector3D( 0, MeshHeight, 0 ); _faceTopMesh.Positions.Add( centerPoints[0] + top ); _faceTopMesh.Positions.Add( centerPoints[1] + top ); _faceTopMesh.Positions.Add( centerPoints[2] + top ); _faceTopMesh.Positions.Add( centerPoints[3] + top ); AddTriangleIndices( _faceTopMesh ); AddTextureCoordinatesFront( _faceTopMesh ); //////////////////////////////////////////////////////////////// // bottom var bottom = new Vector3D( 0, -MeshHeight, 0 ); _faceBottomMesh.Positions.Add( centerPoints[0] + bottom ); _faceBottomMesh.Positions.Add( centerPoints[1] + bottom ); _faceBottomMesh.Positions.Add( centerPoints[2] + bottom ); _faceBottomMesh.Positions.Add( centerPoints[3] + bottom ); AddTriangleIndices( _faceBottomMesh ); AddTextureCoordinatesFront( _faceBottomMesh ); //////////////////////////////////////////////////////////////// // Front 永远显示当前桌面;其在动画中定格,动画结束后归位并继续截屏 var frontMaterial = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.FrontD3DImage ) ); _faceCenter.Material = frontMaterial; //////////////////////////////////////////////////////////////// // 其他位面永远显示目标桌面,可以共享同一个材质;其在动画中持续截屏,动画结束后归位并停止截屏 var othersMaterial = new DiffuseMaterial( new ImageBrush( D3DImages.D3DImages.OthersD3DImage ) ); _faceLeft.Material = othersMaterial; _faceRight.Material = othersMaterial; _faceTop.Material = othersMaterial; _faceBottom.Material = othersMaterial; //////////////////////////////////////////// // set GeometryModel3D' mesh _faceCenter.Geometry = _faceCenterMesh; _faceLeft.Geometry = _faceLeftMesh; _faceRight.Geometry = _faceRightMesh; _faceTop.Geometry = _faceTopMesh; _faceBottom.Geometry = _faceBottomMesh; //////////////////////////////////////////// // Model3D/Model3DGroup _face.Children.Add( _faceCenter ); _face.Children.Add( _faceLeft ); _face.Children.Add( _faceRight ); _face.Children.Add( _faceTop ); _face.Children.Add( _faceBottom ); model3DGroup.Children.Clear(); model3DGroup.Children.Add( _face ); model3DGroup.Children.Add( CommonLight ); } public override void AnimationInDirection( KeyCode dir, Model3DGroup model3DGroup, IEasingFunction ef = null ) { var offsetProperty = TranslateTransform3D.OffsetXProperty; var animation = (DoubleAnimation)Animation; animation.Duration = new Duration( TimeSpan.FromMilliseconds( SettingsManager.Settings.AnimationDuration ) ); animation.EasingFunction = ef; switch ( dir ) { case KeyCode.Left: Transform3D = TransformDirections[KeyCode.Left]; animation.To = MeshWidth; break; case KeyCode.Right: Transform3D = TransformDirections[KeyCode.Right]; animation.To = -MeshWidth; break; case KeyCode.Up: Transform3D = TransformDirections[KeyCode.Up]; animation.To = -MeshHeight; offsetProperty = TranslateTransform3D.OffsetYProperty; break; case KeyCode.Down: Transform3D = TransformDirections[KeyCode.Down]; animation.To = MeshHeight; offsetProperty = TranslateTransform3D.OffsetYProperty; break; } if ( TransGroup.Children.Count == 0 ) { TransGroup.Children.Add( Transform3D ); } else { TransGroup.Children[0] = Transform3D; } model3DGroup.Transform = TransGroup; var transform = (TranslateTransform3D)Transform3D; transform.BeginAnimation( offsetProperty, animation ); } } } ================================================ FILE: Plugins.sln/Cube3D/FrameToD3DImage.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of Cube3D. Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Cube3D. If not, see . */ using System; using System.Collections.Generic; using System.Windows; using System.Windows.Interop; using System.Windows.Media; using Cube3D.Config; using ScreenCapture; namespace Cube3D { public class FrameToD3DImage : FrameProcessor { private readonly Dictionary _d3DImageDict; private readonly Duration _duration = new( new TimeSpan( 0, 0, 0, 0, 5 ) ); private Action _animation; private FrameToD3DImage() { } public FrameToD3DImage( Dictionary d3dImageDict ) { _d3DImageDict = d3dImageDict; } public void SetAction( Action action ) { _animation = action; } public override void Proceed( IntPtr pointer, ulong frameNumber ) { if ( frameNumber == 1 ) { Paint( _d3DImageDict[Const.Front], pointer ); } else { if ( frameNumber == 2 ) { _animation?.Invoke(); } Paint( _d3DImageDict[Const.Others], pointer ); } } private void Paint( D3DImageInfo dii, IntPtr pointer ) { var useSoftRender = IsSoftRender(); var d3DImage = dii.Image; if ( !useSoftRender && !d3DImage.IsFrontBufferAvailable ) return; if ( d3DImage.TryLock( _duration ) ) { d3DImage.SetBackBuffer( D3DResourceType.IDirect3DSurface9, pointer, useSoftRender ); d3DImage.AddDirtyRect( new Int32Rect( 0, 0, d3DImage.PixelWidth, d3DImage.PixelHeight ) ); } d3DImage.Unlock(); } private static bool IsSoftRender() { var level = RenderCapability.Tier >> 16; return level == 0; } } public class D3DImageInfo { public D3DImage Image { get; set; } } } ================================================ FILE: Plugins.sln/Cube3D/Helpers/User32.cs ================================================ using System; using System.Runtime.InteropServices; using System.Text; namespace VirtualSpace.Helpers { public static class User32 { public delegate bool EnumWindowsProc( IntPtr hWnd, int lParam ); public enum MonitorDpiType { MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2 } [Flags] public enum SetWindowPosFlags : uint { // ReSharper disable InconsistentNaming /// /// If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This /// prevents the calling thread from blocking its execution while other threads process the request. /// SWP_ASYNCWINDOWPOS = 0x4000, /// /// Prevents generation of the WM_SYNCPAINT message. /// SWP_DEFERERASE = 0x2000, /// /// Draws a frame (defined in the window's class description) around the window. /// SWP_DRAWFRAME = 0x0020, /// /// Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not /// specified, WM_NCCALCSIZE is sent only when the window's size is being changed. /// SWP_FRAMECHANGED = 0x0020, /// /// Hides the window. /// SWP_HIDEWINDOW = 0x0080, /// /// Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the /// hWndInsertAfter parameter). /// SWP_NOACTIVATE = 0x0010, /// /// Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the /// window is sized or repositioned. /// SWP_NOCOPYBITS = 0x0100, /// /// Retains the current position (ignores X and Y parameters). /// SWP_NOMOVE = 0x0002, /// /// Does not change the owner window's position in the Z order. /// SWP_NOOWNERZORDER = 0x0200, /// /// Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), /// and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the /// window and parent window that need redrawing. /// SWP_NOREDRAW = 0x0008, /// /// Same as the SWP_NOOWNERZORDER flag. /// SWP_NOREPOSITION = 0x0200, /// /// Prevents the window from receiving the WM_WINDOWPOSCHANGING message. /// SWP_NOSENDCHANGING = 0x0400, /// /// Retains the current size (ignores the cx and cy parameters). /// SWP_NOSIZE = 0x0001, /// /// Retains the current Z order (ignores the hWndInsertAfter parameter). /// SWP_NOZORDER = 0x0004, /// /// Displays the window. /// SWP_SHOWWINDOW = 0x0040 } /// /// Special window handles /// public enum SpecialWindowHandles { // ReSharper disable InconsistentNaming /// /// Places the window at the top of the Z order. /// HWND_TOP = 0, /// /// Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the bottom of all other /// windows. /// HWND_BOTTOM = 1, /// /// Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated. /// HWND_TOPMOST = -1, /// /// Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window. /// HWND_NOTOPMOST = -2 // ReSharper restore InconsistentNaming } public const uint WDA_EXCLUDEFROMCAPTURE = 0x00000011; [DllImport( "user32.dll" )] public static extern uint SetWindowDisplayAffinity( IntPtr hWnd, uint dwAffinity ); [DllImport( "user32.dll", CharSet = CharSet.Auto )] public static extern int GetWindowLong( IntPtr hWnd, int nIndex ); public static IntPtr SetWindowLongPtr( HandleRef hWnd, int nIndex, int dwNewLong ) { if ( IntPtr.Size == 8 ) return SetWindowLongPtr64( hWnd, nIndex, (IntPtr)dwNewLong ); else return new IntPtr( SetWindowLong32( hWnd, nIndex, dwNewLong ) ); } [DllImport( "user32.dll", EntryPoint = "SetWindowLong" )] private static extern int SetWindowLong32( HandleRef hWnd, int nIndex, int dwNewLong ); [DllImport( "user32.dll", EntryPoint = "SetWindowLongPtr" )] private static extern IntPtr SetWindowLongPtr64( HandleRef hWnd, int nIndex, IntPtr dwNewLong ); [DllImport( "user32.dll", SetLastError = true )] public static extern bool SetWindowPos( IntPtr hWnd, SpecialWindowHandles hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags ); [DllImport( "user32.dll" )] public static extern bool IsWindowVisible( IntPtr hWnd ); [DllImport( "user32.dll" )] public static extern int EnumWindows( EnumWindowsProc func, int lParam ); [DllImport( "user32.dll" )] public static extern int GetWindowText( IntPtr hWnd, StringBuilder buf, int nMaxCount ); [DllImport( "shcore.dll" )] public static extern uint GetDpiForMonitor( IntPtr hmonitor, MonitorDpiType dpiType, out uint dpiX, out uint dpiY ); } } ================================================ FILE: Plugins.sln/Cube3D/Helpers/Win32.cs ================================================ using System; using System.Runtime.InteropServices; namespace VirtualSpace.Helpers { public enum GetWindowLongFields { GWL_USERDATA = -21, // 0xFFFFFFEB GWL_EXSTYLE = -20, // 0xFFFFFFEC GWL_STYLE = -16, // 0xFFFFFFF0 GWL_ID = -12, // 0xFFFFFFF4 GWL_HWNDPARENT = -8, // 0xFFFFFFF8 GWL_HINSTANCE = -6, // 0xFFFFFFFA GWL_WNDPROC = -4 // 0xFFFFFFFC } [StructLayout( LayoutKind.Sequential )] public struct INPUT { public uint Type; public MOUSEKEYBDHARDWAREINPUT Data; } [StructLayout( LayoutKind.Explicit )] public struct MOUSEKEYBDHARDWAREINPUT { [FieldOffset( 0 )] public HARDWAREINPUT Hardware; [FieldOffset( 0 )] public KEYBDINPUT Keyboard; [FieldOffset( 0 )] public MOUSEINPUT Mouse; } [StructLayout( LayoutKind.Sequential )] public struct HARDWAREINPUT { public uint Msg; public ushort ParamL; public ushort ParamH; } [StructLayout( LayoutKind.Sequential )] public struct KEYBDINPUT { public ushort Vk; public ushort Scan; public uint Flags; public uint Time; public IntPtr ExtraInfo; } [StructLayout( LayoutKind.Sequential )] public struct MOUSEINPUT { public int X; public int Y; public uint MouseData; public uint Flags; public uint Time; public IntPtr ExtraInfo; } } ================================================ FILE: Plugins.sln/Cube3D/Helpers/WinMsg.cs ================================================ namespace VirtualSpace.Helpers { public static class WinMsg { public const int WM_SYSCOMMAND = 0x0112; public const int SC_MAXIMIZE = 0xF030; public const int SC_MINIMIZE = 0xF020; public const int SC_RESTORE = 0xF120; public const int SC_SIZE = 0xF000; public const int SC_MOVE = 0xF010; public const int SC_CLOSE = 0xF060; public const int WM_HOTKEY = 0x0312; public const int WM_CLOSE = 0x0010; public const int WM_QUIT = 0x0012; public const int WM_DESTROY = 0x0002; public const int WM_MOUSEACTIVATE = 0x0021; public const int MA_NOACTIVATE = 0x3; public const int WM_DISPLAYCHANGE = 0x007E; } } ================================================ FILE: Plugins.sln/Cube3D/Helpers/WpfConverters.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of Plugins. // // Plugins is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Plugins is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Plugins. If not, see . using System; using System.Globalization; using System.Windows.Data; using Cube3D.Config; namespace VirtualSpace.Helpers { public class TransitionTypeConverter : IValueConverter { public object Convert( object value, Type targetType, object parameters, CultureInfo culture ) { if ( value is null ) return null; var t = (TransitionType)value; return ( t & TransitionType.NotificationGridOnly ) > 0; } public object ConvertBack( object value, Type targetType, object parameters, CultureInfo culture ) { throw new NotImplementedException(); } } } ================================================ FILE: Plugins.sln/Cube3D/MainWindow.2D.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of Cube3D. Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Cube3D. If not, see . */ using System; using System.Windows; using System.Windows.Controls; namespace Cube3D { public partial class MainWindow { private void NotificationGridLayout( int vdCount ) { //////////////////////////////////////////////////////////////// // position and size var screenW = SystemParameters.PrimaryScreenWidth; var screenH = SystemParameters.PrimaryScreenHeight; var centerX = screenW / 2; var centerY = screenH * 5 / 16; NotifyContainer.Width = screenW / 6; NotifyContainer.Height = NotifyContainer.Width * 3 / 4; NotifyContainer.Margin = new Thickness { Top = centerY + NotifyContainer.Height }; //////////////////////////////////////////////////////////////// // contents var rowsCols = (int)Math.Ceiling( Math.Sqrt( vdCount ) ); var maxCount = rowsCols * rowsCols; if ( NotifyGrid.Children.Count != maxCount ) { NotifyGrid.Children.Clear(); for ( var i = 0; i < maxCount; i++ ) { NotifyGrid.Children.Add( new Button { // Content = i.ToString(), Template = Resources["NotifyButtonTemplate"] as ControlTemplate } ); } } UpdateLayout(); var firstCell = (Button)NotifyGrid.Children[0]; // 因为至少有一个桌面,所以 0 索引子元素必然存在 var buttonMargin = new Thickness { Left = firstCell.ActualWidth / 10.0, Top = firstCell.ActualHeight / 10.0 }; Resources["NotifyButtonMargin"] = buttonMargin; NotifyBorder.Padding = new Thickness {Right = buttonMargin.Left, Bottom = buttonMargin.Top}; UpdateLayout(); CurrentIndicator.Width = firstCell.ActualWidth; CurrentIndicator.Height = firstCell.ActualHeight; } } } ================================================ FILE: Plugins.sln/Cube3D/MainWindow.3D.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of Cube3D. Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Cube3D. If not, see . */ using System; using System.Windows.Media.Media3D; using Cube3D.Config; using Cube3D.Effects; using ScreenCapture; namespace Cube3D { public partial class MainWindow { private static Effect _effect; private void CameraPosition( MonitorInfo mi ) { var ratio = mi.ScreenSize.Y / mi.ScreenSize.X; var workAreaWidth = 1.0; var workAreaHeight = workAreaWidth * ratio; var radianFov = MainCamera.FieldOfView * ( Math.PI / 180 ); var cameraX = workAreaWidth / 2; var cameraY = workAreaHeight / 2; var cameraZ = workAreaWidth / 2 / Math.Tan( radianFov / 2 ); MainCamera = new PerspectiveCamera { LookDirection = new Vector3D( 0, 0, -1 ), Position = new Point3D( cameraX, cameraY, cameraZ ) }; Vp3D.Camera = MainCamera; } public void Build3D() { var settings = SettingsManager.Settings; _effect = settings.SelectedEffect switch { EffectType.Cube => new Cube(), EffectType.Flip => new Flip(), EffectType.Slide => new Slide(), EffectType.Reveal => new Reveal(), EffectType.Fade => new Fade(), EffectType.InsideCube => new InsideCube(), _ => new Cube() }; _effect.Build( MainModel3DGroup ); _effect.AddAnimationCompletedListener( AnimationCompleted ); } } } ================================================ FILE: Plugins.sln/Cube3D/MainWindow.animation.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of Cube3D. Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Cube3D. If not, see . */ using System; using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; using Cube3D.Config; namespace Cube3D { public partial class MainWindow { private static long _mainWindowRunningAnimationCount; private readonly ThicknessAnimation _animationNotifyGrid = new() { FillBehavior = FillBehavior.Stop }; private void AnimationCompleted( object sender, EventArgs e ) { if ( _monitorInfo.IsPrimary ) { Interlocked.Decrement( ref _mainWindowRunningAnimationCount ); if ( _mainWindowRunningAnimationCount == 0 ) FakeHide( true ); } else { FakeHide( true ); } } private void NotificationGridAnimation( int fromIndex, int toIndex, int vdCount, IEasingFunction ef = null ) { var oneCell = (Button)NotifyGrid.Children[fromIndex]; // 用 0 也行,UniformGrid 的 cell 尺寸一样 var rowsCols = (int)Math.Ceiling( Math.Sqrt( vdCount ) ); var fromRow = fromIndex / rowsCols; // divide var fromCol = fromIndex % rowsCols; // modulus var toRow = toIndex / rowsCols; // divide var toCol = toIndex % rowsCols; // modulus var buttonMargin = (Thickness)Resources["NotifyButtonMargin"]; var cellCenterToCell00Distance = rowsCols - 1; // 默认 margin all=0 在中心,需计算与左上角的单位距离 var cell00Margin = new Thickness // 左上角 cell 的 margin,行索引=列索引=子元素索引=0,便于计算 { Left = -buttonMargin.Left - cellCenterToCell00Distance * oneCell.ActualWidth, Top = -buttonMargin.Top - cellCenterToCell00Distance * oneCell.ActualHeight }; /////////////////////////////////////////////////////////////////// // 所有非 0 索引的 cell,其 margin 都基于左上角 cell 计算,籍此进行定位 CurrentIndicator.Margin = new Thickness // 当前索引作为动画起始 cell { Left = cell00Margin.Left + 2 * fromCol * oneCell.ActualWidth, // 宽度对应列系数 Top = cell00Margin.Top + 2 * fromRow * oneCell.ActualHeight // 高度对应行系数 }; var targetCellMargin = new Thickness // 目标 cell 作为动画结束 cell { Left = cell00Margin.Left + 2 * toCol * oneCell.ActualWidth, // 宽度对应列系数 Top = cell00Margin.Top + 2 * toRow * oneCell.ActualHeight // 高度对应行系数 }; //////////////////////////////////////////////////////////////// // animation _animationNotifyGrid.From = CurrentIndicator.Margin; _animationNotifyGrid.To = targetCellMargin; _animationNotifyGrid.Duration = new Duration( TimeSpan.FromMilliseconds( SettingsManager.Settings.AnimationDuration ) ); _animationNotifyGrid.EasingFunction = ef; CurrentIndicator.BeginAnimation( MarginProperty, _animationNotifyGrid ); } private void CameraAnimation() { var animationCamera = new Point3DAnimation { From = new Point3D( MainCamera.Position.X, MainCamera.Position.Y, MainCamera.Position.Z + 0.1 ), To = new Point3D( MainCamera.Position.X, MainCamera.Position.Y, MainCamera.Position.Z + 0.5 ), Duration = new Duration( TimeSpan.FromMilliseconds( SettingsManager.Settings.AnimationDuration / 2.0 ) ), FillBehavior = FillBehavior.Stop, AutoReverse = true }; MainCamera.BeginAnimation( ProjectionCamera.PositionProperty, animationCamera ); } } } ================================================ FILE: Plugins.sln/Cube3D/MainWindow.frame.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of Cube3D. Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Cube3D. If not, see . */ using System.Linq; using System.Threading.Tasks; using ScreenCapture; namespace Cube3D { public partial class MainWindow { private D3D9ShareCapture _capture; private FrameToD3DImage _frameProcessor; private Task StartPrimaryMonitorCapture() { var monitor = ( from m in MonitorEnumerationHelper.GetMonitors() where m.IsPrimary select m ).First(); return StartMonitorCapture( monitor ); } private async Task StartMonitorCapture( MonitorInfo mi ) { _frameProcessor = new FrameToD3DImage( D3DImages.D3DImages.D3DImageDict ); try { _capture = D3D9ShareCapture.Create( mi, _frameProcessor ); } catch { await Task.Delay( 1000 ); App.Restart(); return; } if ( _capture != null ) { _capture.StartCaptureSession(); #if DEBUG await Task.Delay( 50 ); #endif } StopCapture(); } } } ================================================ FILE: Plugins.sln/Cube3D/MainWindow.hotkeys.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of Cube3D. Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Cube3D. If not, see . */ using System; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; using Cube3D.Config; using Cube3D.Effects; using ScreenCapture; using VirtualSpace.Commons; using VirtualSpace.Helpers; using VirtualSpace.Plugin; #pragma warning disable CA1416 namespace Cube3D { public partial class MainWindow { private static SettingsWindow _sw; private readonly StringBuilder _sbWinInfo = new( 1024 ); private bool _isTopmost; private void FakeHide( bool stopCapture = false ) { Left = Const.FakeHideX; Top = Const.FakeHideY; if ( stopCapture ) StopCapture(); } private void StopCapture() { _capture?.StopCaptureSession(); } private bool WindowFilter( IntPtr hWnd, int lParam ) { if ( !User32.IsWindowVisible( hWnd ) ) return true; _sbWinInfo.Clear(); _ = User32.GetWindowText( hWnd, _sbWinInfo, _sbWinInfo.Capacity ); if ( _sbWinInfo.Length == 0 ) return true; _isTopmost = Handle == hWnd; // if the first visible non-empty title window is Cube3D, then Cube3D is on the top. return false; } private void RealShow( bool forceTop = false ) { if ( forceTop ) { _ = User32.EnumWindows( WindowFilter, 0 ); if ( !_isTopmost ) { User32.SetWindowPos( Handle, User32.SpecialWindowHandles.HWND_TOP, 0, 0, 0, 0, User32.SetWindowPosFlags.SWP_NOSIZE | User32.SetWindowPosFlags.SWP_NOMOVE | User32.SetWindowPosFlags.SWP_NOACTIVATE | User32.SetWindowPosFlags.SWP_NOREDRAW | User32.SetWindowPosFlags.SWP_NOCOPYBITS | User32.SetWindowPosFlags.SWP_DEFERERASE | User32.SetWindowPosFlags.SWP_NOSENDCHANGING ); } } var dpi = GetDpiForMonitor( _monitorInfo.Hmon ); Left = _monitorInfo.WorkArea.Left / dpi.ScaleX; Top = _monitorInfo.WorkArea.Top / dpi.ScaleY; Width = _monitorInfo.ScreenSize.X / dpi.ScaleX; Height = _monitorInfo.ScreenSize.Y / dpi.ScaleY; } private IntPtr WndProc( IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled ) { switch ( msg ) { case WinMsg.WM_SYSCOMMAND: var wP = wParam.ToInt32(); if ( wP is WinMsg.SC_RESTORE or WinMsg.SC_MINIMIZE or WinMsg.SC_MAXIMIZE ) handled = true; break; case WinApi.WM_COPYDATA: var copyDataStruct = (COPYDATASTRUCT)Marshal.PtrToStructure( lParam, typeof( COPYDATASTRUCT ) ); switch ( copyDataStruct.dwData.ToInt32() ) { case WinApi.UM_SWITCHDESKTOP: if ( _mainWindowRunningAnimationCount == 0 ) { var vdSwitchInfo = (VirtualDesktopSwitchInfo)Marshal.PtrToStructure( copyDataStruct.lpData, typeof( VirtualDesktopSwitchInfo ) ); Task.Run( () => { Dispatcher.Invoke( () => PerformAnimationPrimary( vdSwitchInfo ) ); } ); foreach ( var other in OtherScreens ) { other.PerformAnimationOthers( vdSwitchInfo ); } } break; } break; case WinApi.UM_PLUGINSETTINGS: if ( _sw is null || PresentationSource.FromVisual( _sw ) == null ) { _sw = new SettingsWindow(); _sw.SetMainWindow( this ); _sw.ShowDialog(); } else { _sw.Activate(); } break; case WinApi.UM_OTHERSCREENS: switch ( wParam.ToInt32() ) { case 0: ClearOtherScreens(); break; case 1: CreateOtherScreens(); break; } break; case WinMsg.WM_DISPLAYCHANGE: App.Restart(); break; case WinApi.UM_RESTART: App.Restart(); break; case WinMsg.WM_MOUSEACTIVATE: handled = true; return new IntPtr( WinMsg.MA_NOACTIVATE ); } return IntPtr.Zero; } private void PerformAnimationPrimary( VirtualDesktopSwitchInfo vdSwitchInfo ) { var mi = ( from m in MonitorEnumerationHelper.GetMonitors() where m.IsPrimary select m ).First(); _capture = D3D9ShareCapture.Create( mi, _frameProcessor ); _capture?.StartCaptureSession(); if ( ( SettingsManager.Settings.TransitionType & TransitionType.NotificationGridOnly ) > 0 ) NotificationGridLayout( vdSwitchInfo.vdCount ); var em = EaseFactory.GetEaseModeByName( SettingsManager.Settings.EaseMode ); var ef = EaseFactory.GetEaseByName( SettingsManager.Settings.EaseType, em ); _frameProcessor.SetAction( () => { ////////////////////////////////////////////////////// // trigger action only after first frame be handled, // see FrameToD3DImage.Proceed() for detail. RealShow( true ); if ( ( SettingsManager.Settings.TransitionType & TransitionType.NotificationGridOnly ) > 0 ) { NotificationGridAnimation( vdSwitchInfo.fromIndex, vdSwitchInfo.targetIndex, vdSwitchInfo.vdCount, ef ); Interlocked.Increment( ref _mainWindowRunningAnimationCount ); } if ( vdSwitchInfo.targetIndex != vdSwitchInfo.fromIndex && ( SettingsManager.Settings.TransitionType & TransitionType.AnimationOnly ) > 0 ) { _effect.AnimationInDirection( (KeyCode)vdSwitchInfo.dir, MainModel3DGroup, ef ); Interlocked.Increment( ref _mainWindowRunningAnimationCount ); } WinApi.PostMessage( vdSwitchInfo.hostHandle, WinApi.UM_SWITCHDESKTOP, (uint)vdSwitchInfo.targetIndex, 0 ); } ); } private void PerformAnimationOthers( VirtualDesktopSwitchInfo vdSwitchInfo ) { if ( ( SettingsManager.Settings.TransitionType & TransitionType.NotificationGridOnly ) == 0 ) return; NotificationGridLayout( vdSwitchInfo.vdCount ); var em = EaseFactory.GetEaseModeByName( SettingsManager.Settings.EaseMode ); var ef = EaseFactory.GetEaseByName( SettingsManager.Settings.EaseType, em ); RealShow(); NotificationGridAnimation( vdSwitchInfo.fromIndex, vdSwitchInfo.targetIndex, vdSwitchInfo.vdCount, ef ); } } } #pragma warning restore CA1416 ================================================ FILE: Plugins.sln/Cube3D/MainWindow.xaml ================================================  Show NotificationGrid on All Screens ================================================ FILE: Plugins.sln/Cube3D/SettingsWindow.xaml.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Cube3D. // // Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Cube3D. If not, see . using System; using System.Windows; using System.Windows.Controls; using Cube3D.Config; using Cube3D.Effects; using VirtualSpace.Plugin; namespace Cube3D { public partial class SettingsWindow : Window { private bool _isLoaded = false; private MainWindow _mainWindow; public SettingsWindow() { DataContext = this; InitializeComponent(); } public int AnimationDuration { get => SettingsManager.Settings.AnimationDuration; set => SettingsManager.Settings.AnimationDuration = value; } public int CheckAliveInterval { get => SettingsManager.Settings.CheckAliveInterval; set => SettingsManager.Settings.CheckAliveInterval = value; } private void Window_Loaded( object sender, RoutedEventArgs e ) { foreach ( EffectType effect in Enum.GetValues( typeof( EffectType ) ) ) { ComboBoxEffects.Items.Add( effect ); } ComboBoxEffects.SelectedItem = SettingsManager.Settings.SelectedEffect; foreach ( EaseType ease in Enum.GetValues( typeof( EaseType ) ) ) { ComboBoxEase.Items.Add( ease ); } ComboBoxEase.SelectedItem = SettingsManager.Settings.EaseType; foreach ( EaseMode easeMode in Enum.GetValues( typeof( EaseMode ) ) ) { ComboBoxEaseMode.Items.Add( easeMode ); } ComboBoxEaseMode.SelectedItem = SettingsManager.Settings.EaseMode; foreach ( TransitionType tt in Enum.GetValues( typeof( TransitionType ) ) ) { ComboBoxTransitionType.Items.Add( tt ); } ComboBoxTransitionType.SelectedItem = SettingsManager.Settings.TransitionType; CbNgOnAllScreens.IsChecked = SettingsManager.Settings.ShowNotificationGridOnAllScreens; _isLoaded = true; } private void ComboBoxEffects_SelectionChanged( object sender, SelectionChangedEventArgs e ) { if ( !_isLoaded ) return; SettingsManager.Settings.SelectedEffect = (EffectType)ComboBoxEffects.SelectedItem; SettingsManager.SaveJson(); } private void ComboBoxEase_OnSelectionChanged( object sender, SelectionChangedEventArgs e ) { if ( !_isLoaded ) return; SettingsManager.Settings.EaseType = (EaseType)ComboBoxEase.SelectedItem; SettingsManager.SaveJson(); } private void ComboBoxEaseMode_OnSelectionChanged( object sender, SelectionChangedEventArgs e ) { if ( !_isLoaded ) return; SettingsManager.Settings.EaseMode = (EaseMode)ComboBoxEaseMode.SelectedItem; SettingsManager.SaveJson(); } private void ComboBoxTransitionType_OnSelectionChanged( object sender, SelectionChangedEventArgs e ) { if ( !_isLoaded ) return; SettingsManager.Settings.TransitionType = (TransitionType)ComboBoxTransitionType.SelectedItem; if ( ( SettingsManager.Settings.TransitionType & TransitionType.NotificationGridOnly ) == 0 ) CbNgOnAllScreens.IsChecked = false; SettingsManager.SaveJson(); _mainWindow.SetTransitionType(); } public void SetMainWindow( MainWindow mw ) { _mainWindow = mw; } private void ApplyEffect_OnClick( object sender, RoutedEventArgs e ) { _mainWindow.Build3D(); } private void Close_OnClick( object sender, RoutedEventArgs e ) { SettingsManager.SaveJson(); Close(); } private void CbNgOnAllScreens_OnChecked( object sender, RoutedEventArgs e ) { if ( !_isLoaded ) return; SettingsManager.Settings.ShowNotificationGridOnAllScreens = true; SettingsManager.SaveJson(); WinApi.PostMessage( _mainWindow.Handle, WinApi.UM_OTHERSCREENS, 1, 0 ); } private void CbNgOnAllScreens_OnUnchecked( object sender, RoutedEventArgs e ) { if ( !_isLoaded ) return; SettingsManager.Settings.ShowNotificationGridOnAllScreens = false; SettingsManager.SaveJson(); WinApi.PostMessage( _mainWindow.Handle, WinApi.UM_OTHERSCREENS, 0, 0 ); } } } ================================================ FILE: Plugins.sln/Cube3D/app.manifest ================================================  PerMonitorV2 ================================================ FILE: Plugins.sln/Cube3D/plugin.json ================================================ { "Name": "Cube3D", "Display": "Cube3D", "Version": "2.1", "Author": "Dylan Cheng", "Email": "newlooper@hotmail.com", "Entry": "Cube3D.exe", "AutoStart": true, "AutoStartTiming": 1, "RestartPolicy": { "Trigger": 0, "Values": [ "HotplugDetected" ], "Enabled": false }, "ClosePolicy": { "Trigger": 0, "Values": [ "DIRECTINPUT_NOTIFICATION_MSGSTRING" ], "Enabled": false }, "Requirements": { "WinVer": { "Min": { "Major": 10, "Build": 19041 } }, "HostVersion": "0.1.454" } } ================================================ FILE: Plugins.sln/Cube3D/settings.json ================================================ { "AnimationDuration": 500, "CheckAliveInterval": 30, "SelectedEffect": 0, "TransitionType": 3 } ================================================ FILE: Plugins.sln/Plugins.sln ================================================  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.1.32210.238 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cube3D", "Cube3D\Cube3D.csproj", "{10B545AA-DE50-4D87-A7F4-804BA41E0035}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScreenCapture", "ScreenCapture\ScreenCapture.csproj", "{7BDE967F-E467-4775-8BFE-3F63F02499F0}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin", "..\Plugin\Commons\Plugin.csproj", "{A60FFB45-5547-4CEB-9B41-3D9C58ED9B86}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ipc", "..\Ipc\Commons\Ipc.csproj", "{498FD176-AB55-466C-80A5-C11B51C6B8C4}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IpcClient", "..\Ipc\IpcClient\IpcClient.csproj", "{EA025C92-FE84-42D7-993E-F94D8CAEFBA9}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Updater", "Updater\Updater.csproj", "{C95060EF-BFD3-4FBB-B8A2-C9A1F5543934}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {10B545AA-DE50-4D87-A7F4-804BA41E0035}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {10B545AA-DE50-4D87-A7F4-804BA41E0035}.Debug|Any CPU.Build.0 = Debug|Any CPU {10B545AA-DE50-4D87-A7F4-804BA41E0035}.Release|Any CPU.ActiveCfg = Release|Any CPU {10B545AA-DE50-4D87-A7F4-804BA41E0035}.Release|Any CPU.Build.0 = Release|Any CPU {7BDE967F-E467-4775-8BFE-3F63F02499F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7BDE967F-E467-4775-8BFE-3F63F02499F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {7BDE967F-E467-4775-8BFE-3F63F02499F0}.Release|Any CPU.ActiveCfg = Release|Any CPU {7BDE967F-E467-4775-8BFE-3F63F02499F0}.Release|Any CPU.Build.0 = Release|Any CPU {A60FFB45-5547-4CEB-9B41-3D9C58ED9B86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A60FFB45-5547-4CEB-9B41-3D9C58ED9B86}.Debug|Any CPU.Build.0 = Debug|Any CPU {A60FFB45-5547-4CEB-9B41-3D9C58ED9B86}.Release|Any CPU.ActiveCfg = Release|Any CPU {A60FFB45-5547-4CEB-9B41-3D9C58ED9B86}.Release|Any CPU.Build.0 = Release|Any CPU {498FD176-AB55-466C-80A5-C11B51C6B8C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {498FD176-AB55-466C-80A5-C11B51C6B8C4}.Debug|Any CPU.Build.0 = Debug|Any CPU {498FD176-AB55-466C-80A5-C11B51C6B8C4}.Release|Any CPU.ActiveCfg = Release|Any CPU {498FD176-AB55-466C-80A5-C11B51C6B8C4}.Release|Any CPU.Build.0 = Release|Any CPU {EA025C92-FE84-42D7-993E-F94D8CAEFBA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EA025C92-FE84-42D7-993E-F94D8CAEFBA9}.Debug|Any CPU.Build.0 = Debug|Any CPU {EA025C92-FE84-42D7-993E-F94D8CAEFBA9}.Release|Any CPU.ActiveCfg = Release|Any CPU {EA025C92-FE84-42D7-993E-F94D8CAEFBA9}.Release|Any CPU.Build.0 = Release|Any CPU {C95060EF-BFD3-4FBB-B8A2-C9A1F5543934}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C95060EF-BFD3-4FBB-B8A2-C9A1F5543934}.Debug|Any CPU.Build.0 = Debug|Any CPU {C95060EF-BFD3-4FBB-B8A2-C9A1F5543934}.Release|Any CPU.ActiveCfg = Release|Any CPU {C95060EF-BFD3-4FBB-B8A2-C9A1F5543934}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {80A9A318-A8BB-43ED-8290-5E75FC73F82B} EndGlobalSection EndGlobal ================================================ FILE: Plugins.sln/ScreenCapture/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Plugins.sln/ScreenCapture/CaptureHelper.cs ================================================ // --------------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // // The MIT License (MIT) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // --------------------------------------------------------------------------------- // based on https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/blob/master/dotnet/WPF/ScreenCapture/Composition.WindowsRuntimeHelpers/CaptureHelper.cs using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Graphics.Capture; #if NET5_0_OR_GREATER using WinRT; #endif namespace ScreenCapture { public static class CaptureHelper { private static readonly Guid GraphicsCaptureItemGuid = new( "79C3F95B-31F7-4EC2-A464-632EF5D30760" ); public static void SetWindow( this GraphicsCapturePicker picker, IntPtr hwnd ) { var interop = (IInitializeWithWindow)(object)picker; interop.Initialize( hwnd ); } public static GraphicsCaptureItem CreateItemForWindow( IntPtr hwnd ) { #if NET5_0_OR_GREATER var interop = GraphicsCaptureItem.As(); #else var factory = WindowsRuntimeMarshal.GetActivationFactory( typeof( GraphicsCaptureItem ) ); var interop = (IGraphicsCaptureItemInterop)factory; #endif var temp = typeof( GraphicsCaptureItem ); var itemPointer = interop.CreateForWindow( hwnd, GraphicsCaptureItemGuid ); #if NET5_0_OR_GREATER var item = MarshalInterface.FromAbi( itemPointer ); #else var item = Marshal.GetObjectForIUnknown( itemPointer ) as GraphicsCaptureItem; #endif Marshal.Release( itemPointer ); return item; } public static GraphicsCaptureItem CreateItemForMonitor( IntPtr hmon ) { #if NET5_0_OR_GREATER var interop = GraphicsCaptureItem.As(); #else var factory = WindowsRuntimeMarshal.GetActivationFactory( typeof( GraphicsCaptureItem ) ); var interop = (IGraphicsCaptureItemInterop)factory; #endif var temp = typeof( GraphicsCaptureItem ); var itemPointer = interop.CreateForMonitor( hmon, GraphicsCaptureItemGuid ); #if NET5_0_OR_GREATER var item = MarshalInterface.FromAbi( itemPointer ); #else var item = Marshal.GetObjectForIUnknown( itemPointer ) as GraphicsCaptureItem; #endif Marshal.Release( itemPointer ); return item; } [ComImport] [Guid( "3E68D4BD-7135-4D10-8018-9FB6D9F33FA1" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [ComVisible( true )] private interface IInitializeWithWindow { void Initialize( IntPtr hwnd ); } [ComImport] [Guid( "3628E81B-3CAC-4C60-B7F4-23CE0E0C3356" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [ComVisible( true )] private interface IGraphicsCaptureItemInterop { IntPtr CreateForWindow( [In] IntPtr window, [In] ref Guid iid ); IntPtr CreateForMonitor( [In] IntPtr monitor, [In] ref Guid iid ); } } } ================================================ FILE: Plugins.sln/ScreenCapture/D3D9ShareCapture.cs ================================================ // --------------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // // The MIT License (MIT) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // --------------------------------------------------------------------------------- // based on https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/blob/master/dotnet/WPF/ScreenCapture/CaptureSampleCore/BasicCapture.cs using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using Windows.Graphics; using Windows.Graphics.Capture; using Windows.Graphics.DirectX; using Windows.Graphics.DirectX.Direct3D11; using SharpDX.DXGI; using D3D11 = SharpDX.Direct3D11; using D3D9 = SharpDX.Direct3D9; namespace ScreenCapture { public class D3D9ShareCapture : IDisposable { private static D3D9.Direct3DEx _d3D9Context; private static D3D9.DeviceEx _d3D9Device; private static IDirect3DDevice _d3D11Device; private static D3D11.Device _sharpDxD3D11Device; private static PropertyInfo _propertyInfoIsBorderRequired; private static PropertyInfo _propertyInfoIsCursorCaptureEnabled; private readonly Dictionary _frameCopyPool = new(); private readonly Dictionary _renderTargetPool = new(); private Direct3D11CaptureFramePool _captureFramePool; private GraphicsCaptureItem _captureItem; private GraphicsCaptureSession _captureSession; private FrameProcessor _fp; private ulong _frameCount; private SizeInt32 _lastSize; private MonitorInfo _monitorInfo; private D3D9ShareCapture() { if ( _propertyInfoIsCursorCaptureEnabled != default ) return; _d3D9Context = new D3D9.Direct3DEx(); _d3D9Device = new D3D9.DeviceEx( _d3D9Context, 0, D3D9.DeviceType.Hardware, IntPtr.Zero, D3D9.CreateFlags.HardwareVertexProcessing | D3D9.CreateFlags.Multithreaded | D3D9.CreateFlags.FpuPreserve, GetPresentParameters() ); _d3D11Device = Direct3D11Helper.CreateDevice(); _sharpDxD3D11Device = Direct3D11Helper.CreateSharpDXDevice( _d3D11Device ); var typeGraphicsCaptureSession = typeof( GraphicsCaptureSession ); _propertyInfoIsBorderRequired = typeGraphicsCaptureSession.GetProperty( "IsBorderRequired" ); _propertyInfoIsCursorCaptureEnabled = typeGraphicsCaptureSession.GetProperty( "IsCursorCaptureEnabled" ); } public void Dispose() { _captureFramePool?.Dispose(); _captureSession?.Dispose(); _captureSession = null; _captureFramePool = null; _captureItem = null; _fp = null; foreach ( var key in _renderTargetPool.Keys ) { _renderTargetPool[key].Dispose(); _renderTargetPool[key] = null; } _renderTargetPool.Clear(); foreach ( var key in _frameCopyPool.Keys ) { _frameCopyPool[key].Dispose(); _frameCopyPool[key] = null; } _frameCopyPool.Clear(); } public static D3D9ShareCapture Create( MonitorInfo mi, FrameProcessor fp ) { var item = CaptureHelper.CreateItemForMonitor( mi.Hmon ); if ( item == null ) return null; var capture = new D3D9ShareCapture { _captureItem = item, _fp = fp, _lastSize = item.Size, _monitorInfo = mi }; return capture; } public void UpdateCapturePrimaryMonitor() { var monitor = ( from m in MonitorEnumerationHelper.GetMonitors() where m.IsPrimary select m ).First(); if ( monitor.Hmon == _monitorInfo.Hmon ) return; _monitorInfo = monitor; var item = CaptureHelper.CreateItemForMonitor( _monitorInfo.Hmon ); if ( item != null ) _captureItem = item; } public void StartCaptureSession() { if ( _captureItem == null ) return; _captureFramePool = Direct3D11CaptureFramePool.Create( _d3D11Device, DirectXPixelFormat.B8G8R8A8UIntNormalized, 1, _captureItem.Size ); _captureFramePool.FrameArrived += OnCaptureFrameArrived; _captureSession = _captureFramePool.CreateCaptureSession( _captureItem ); if ( _propertyInfoIsCursorCaptureEnabled != null ) { _propertyInfoIsCursorCaptureEnabled.SetValue( _captureSession, false ); } if ( _propertyInfoIsBorderRequired != null ) { try { _propertyInfoIsBorderRequired.SetValue( _captureSession, false ); } catch { // ignored } } _captureSession.StartCapture(); } public void StopCaptureSession() { Dispose(); } private void OnCaptureFrameArrived( Direct3D11CaptureFramePool sender, object args ) { var newSize = false; using ( var frame = sender.TryGetNextFrame() ) { if ( frame.ContentSize.Width != _lastSize.Width || frame.ContentSize.Height != _lastSize.Height ) { // The thing we have been capturing has changed size. // We need to resize the swap chain first, then blit the pixels. // After we do that, retire the frame and then recreate the frame pool. newSize = true; _lastSize = frame.ContentSize; } using ( var bitmap = Direct3D11Helper.CreateSharpDXTexture2D( frame.Surface ) ) { if ( !_frameCopyPool.ContainsKey( bitmap.NativePointer ) || newSize ) { var desc = new D3D11.Texture2DDescription { BindFlags = D3D11.BindFlags.RenderTarget | D3D11.BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = bitmap.Description.Width, Height = bitmap.Description.Height, MipLevels = 1, SampleDescription = new SampleDescription( 1, 0 ), Usage = D3D11.ResourceUsage.Default, OptionFlags = D3D11.ResourceOptionFlags.Shared, CpuAccessFlags = D3D11.CpuAccessFlags.None, ArraySize = 1 }; _frameCopyPool[bitmap.NativePointer] = new D3D11.Texture2D( _sharpDxD3D11Device, desc ); } var copy = _frameCopyPool[bitmap.NativePointer]; _sharpDxD3D11Device.ImmediateContext.CopyResource( bitmap, copy ); var sharedHandle = GetSharedHandle( copy ); if ( !_renderTargetPool.ContainsKey( sharedHandle ) ) { try { _renderTargetPool[sharedHandle] = new D3D9.Texture( _d3D9Device, copy.Description.Width, copy.Description.Height, 1, D3D9.Usage.RenderTarget, TranslateFormat( bitmap.Description.Format ), D3D9.Pool.Default, ref sharedHandle ); } catch { _d3D9Context = new D3D9.Direct3DEx(); _d3D9Device = new D3D9.DeviceEx( _d3D9Context, 0, D3D9.DeviceType.Hardware, IntPtr.Zero, D3D9.CreateFlags.HardwareVertexProcessing | D3D9.CreateFlags.Multithreaded | D3D9.CreateFlags.FpuPreserve, GetPresentParameters() ); _renderTargetPool[sharedHandle] = new D3D9.Texture( _d3D9Device, copy.Description.Width, copy.Description.Height, 1, D3D9.Usage.RenderTarget, TranslateFormat( bitmap.Description.Format ), D3D9.Pool.Default, ref sharedHandle ); } } using var targetSurface = _renderTargetPool[sharedHandle].GetSurfaceLevel( 0 ); _fp?.Proceed( targetSurface.NativePointer, ++_frameCount ); } } // Retire the frame. if ( newSize ) { _captureFramePool.Recreate( _d3D11Device, DirectXPixelFormat.B8G8R8A8UIntNormalized, 1, _lastSize ); } } private static D3D9.PresentParameters GetPresentParameters() { var presentParams = new D3D9.PresentParameters { Windowed = true, SwapEffect = D3D9.SwapEffect.Discard, DeviceWindowHandle = NativeMethods.GetDesktopWindow(), PresentationInterval = D3D9.PresentInterval.Default }; return presentParams; } private static IntPtr GetSharedHandle( D3D11.Texture2D texture ) { using var resource = texture.QueryInterface(); return resource.SharedHandle; } private static D3D9.Format TranslateFormat( Format format ) { return format switch { Format.R10G10B10A2_UNorm => D3D9.Format.A2B10G10R10, Format.R16G16B16A16_Float => D3D9.Format.A16B16G16R16F, Format.B8G8R8A8_UNorm => D3D9.Format.A8R8G8B8, _ => D3D9.Format.Unknown }; } } public static class NativeMethods { [DllImport( "user32.dll", SetLastError = false )] public static extern IntPtr GetDesktopWindow(); } } ================================================ FILE: Plugins.sln/ScreenCapture/Direct3D11Helper.cs ================================================ // --------------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // // The MIT License (MIT) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // --------------------------------------------------------------------------------- // based on https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/blob/master/dotnet/WPF/ScreenCapture/Composition.WindowsRuntimeHelpers/Direct3D11Helper.cs using System; using System.Runtime.InteropServices; using Windows.Graphics.DirectX.Direct3D11; using SharpDX.Direct3D; using SharpDX.Direct3D11; using SharpDX.DXGI; using Device = SharpDX.Direct3D11.Device; using Device3 = SharpDX.DXGI.Device3; #if NET5_0_OR_GREATER using WinRT; #endif namespace ScreenCapture { public static class Direct3D11Helper { private static Guid IInspectable = new( "AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90" ); private static Guid ID3D11Resource = new( "dc8e63f3-d12b-4952-b47b-5e45026a862d" ); private static Guid IDXGIAdapter3 = new( "645967A4-1392-4310-A798-8053CE3E93FD" ); private static readonly Guid ID3D11Device = new( "db6f6ddb-ac77-4e88-8253-819df9bbf140" ); private static readonly Guid ID3D11Texture2D = new( "6f15aaf2-d208-4e89-9ab4-489535d34f9c" ); [DllImport( "d3d11.dll", EntryPoint = "CreateDirect3D11DeviceFromDXGIDevice", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall )] private static extern uint CreateDirect3D11DeviceFromDXGIDevice( IntPtr dxgiDevice, out IntPtr graphicsDevice ); [DllImport( "d3d11.dll", EntryPoint = "CreateDirect3D11SurfaceFromDXGISurface", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall )] private static extern uint CreateDirect3D11SurfaceFromDXGISurface( IntPtr dxgiSurface, out IntPtr graphicsSurface ); public static IDirect3DDevice CreateDevice() { return CreateDevice( false ); } public static IDirect3DDevice CreateDevice( bool useWARP ) { var d3dDevice = new Device( useWARP ? DriverType.Software : DriverType.Hardware, DeviceCreationFlags.BgraSupport ); var device = CreateDirect3DDeviceFromSharpDXDevice( d3dDevice ); return device; } public static IDirect3DDevice CreateDirect3DDeviceFromSharpDXDevice( Device d3dDevice ) { IDirect3DDevice device = null; // Acquire the DXGI interface for the Direct3D device. using ( var dxgiDevice = d3dDevice.QueryInterface() ) { // Wrap the native device using a WinRT interop object. var hr = CreateDirect3D11DeviceFromDXGIDevice( dxgiDevice.NativePointer, out var pUnknown ); if ( hr == 0 ) { #if NET5_0_OR_GREATER device = MarshalInterface.FromAbi( pUnknown ); #else device = Marshal.GetObjectForIUnknown( pUnknown ) as IDirect3DDevice; #endif Marshal.Release( pUnknown ); } } return device; } public static IDirect3DSurface CreateDirect3DSurfaceFromSharpDXTexture( Texture2D texture ) { IDirect3DSurface surface = null; // Acquire the DXGI interface for the Direct3D surface. using ( var dxgiSurface = texture.QueryInterface() ) { // Wrap the native device using a WinRT interop object. var hr = CreateDirect3D11SurfaceFromDXGISurface( dxgiSurface.NativePointer, out var pUnknown ); if ( hr == 0 ) { #if NET5_0_OR_GREATER surface = MarshalInterface.FromAbi( pUnknown ); #else surface = Marshal.GetObjectForIUnknown( pUnknown ) as IDirect3DSurface; #endif Marshal.Release( pUnknown ); } } return surface; } public static Device CreateSharpDXDevice( IDirect3DDevice device ) { #if NET5_0_OR_GREATER var access = device.As(); #else var access = (IDirect3DDxgiInterfaceAccess)device; #endif var d3dPointer = access.GetInterface( ID3D11Device ); var d3dDevice = new Device( d3dPointer ); return d3dDevice; } public static Texture2D CreateSharpDXTexture2D( IDirect3DSurface surface ) { #if NET5_0_OR_GREATER var access = surface.As(); #else var access = (IDirect3DDxgiInterfaceAccess)surface; #endif var d3dPointer = access.GetInterface( ID3D11Texture2D ); var d3dSurface = new Texture2D( d3dPointer ); return d3dSurface; } [ComImport] [Guid( "A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [ComVisible( true )] private interface IDirect3DDxgiInterfaceAccess { IntPtr GetInterface( [In] ref Guid iid ); }; } } ================================================ FILE: Plugins.sln/ScreenCapture/FrameProcessor.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of Cube3D. Cube3D is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cube3D is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Cube3D. If not, see . */ using System; namespace ScreenCapture { public abstract class FrameProcessor { public abstract void Proceed( IntPtr pointer, ulong frameNumber ); } } ================================================ FILE: Plugins.sln/ScreenCapture/MonitorEnumerationHelper.cs ================================================ // --------------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // // The MIT License (MIT) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // --------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Numerics; using System.Runtime.InteropServices; using Windows.Foundation; namespace ScreenCapture { public class MonitorInfo { public bool IsPrimary { get; set; } public Vector2 ScreenSize { get; set; } public Rect MonitorArea { get; set; } public Rect WorkArea { get; set; } public string DeviceName { get; set; } public IntPtr Hmon { get; set; } } public static class MonitorEnumerationHelper { private const int CCHDEVICENAME = 32; [DllImport( "user32.dll" )] private static extern bool EnumDisplayMonitors( IntPtr hdc, IntPtr lprcClip, EnumMonitorsDelegate lpfnEnum, IntPtr dwData ); [DllImport( "user32.dll", CharSet = CharSet.Auto )] private static extern bool GetMonitorInfo( IntPtr hMonitor, ref MonitorInfoEx lpmi ); public static IEnumerable GetMonitors() { var result = new List(); EnumDisplayMonitors( IntPtr.Zero, IntPtr.Zero, delegate( IntPtr hMonitor, IntPtr hdcMonitor, ref RECT lprcMonitor, IntPtr dwData ) { var mi = new MonitorInfoEx(); mi.Size = Marshal.SizeOf( mi ); var success = GetMonitorInfo( hMonitor, ref mi ); if ( success ) { var info = new MonitorInfo { ScreenSize = new Vector2( mi.Monitor.right - mi.Monitor.left, mi.Monitor.bottom - mi.Monitor.top ), MonitorArea = new Rect( mi.Monitor.left, mi.Monitor.top, mi.Monitor.right - mi.Monitor.left, mi.Monitor.bottom - mi.Monitor.top ), WorkArea = new Rect( mi.WorkArea.left, mi.WorkArea.top, mi.WorkArea.right - mi.WorkArea.left, mi.WorkArea.bottom - mi.WorkArea.top ), IsPrimary = mi.Flags > 0, Hmon = hMonitor, DeviceName = mi.DeviceName }; result.Add( info ); } return true; }, IntPtr.Zero ); return result; } private delegate bool EnumMonitorsDelegate( IntPtr hMonitor, IntPtr hdcMonitor, ref RECT lprcMonitor, IntPtr dwData ); [StructLayout( LayoutKind.Sequential )] public struct RECT { public int left; public int top; public int right; public int bottom; } [StructLayout( LayoutKind.Sequential, CharSet = CharSet.Auto )] internal struct MonitorInfoEx { public int Size; public RECT Monitor; public RECT WorkArea; public uint Flags; [MarshalAs( UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME )] public string DeviceName; } } } ================================================ FILE: Plugins.sln/ScreenCapture/ScreenCapture.csproj ================================================  net6.0-windows10.0.20348.0;net6.0-windows10.0.22000.0; all runtime; build; native; contentfiles; analyzers; buildtransitive ================================================ FILE: Plugins.sln/ScreenCapture/WindowEnumerationHelper.cs ================================================ // --------------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // // The MIT License (MIT) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // --------------------------------------------------------------------------------- using System; using System.Runtime.InteropServices; namespace ScreenCapture { internal static class WindowEnumerationHelper { public enum GWL { GWL_WNDPROC = -4, GWL_HINSTANCE = -6, GWL_HWNDPARENT = -8, GWL_STYLE = -16, GWL_EXSTYLE = -20, GWL_USERDATA = -21, GWL_ID = -12 } [DllImport( "user32.dll" )] private static extern IntPtr GetShellWindow(); [DllImport( "user32.dll" )] [return: MarshalAs( UnmanagedType.Bool )] private static extern bool IsWindowVisible( IntPtr hWnd ); [DllImport( "user32.dll", ExactSpelling = true )] private static extern IntPtr GetAncestor( IntPtr hwnd, GetAncestorFlags flags ); [DllImport( "user32.dll", EntryPoint = "GetWindowLong" )] private static extern IntPtr GetWindowLongPtr32( IntPtr hWnd, int nIndex ); [DllImport( "user32.dll", EntryPoint = "GetWindowLongPtr" )] private static extern IntPtr GetWindowLongPtr64( IntPtr hWnd, int nIndex ); // This static method is required because Win32 does not support // GetWindowLongPtr directly. // http://pinvoke.net/default.aspx/user32/GetWindowLong.html private static IntPtr GetWindowLongPtr( IntPtr hWnd, int nIndex ) { if ( IntPtr.Size == 8 ) return GetWindowLongPtr64( hWnd, nIndex ); else return GetWindowLongPtr32( hWnd, nIndex ); } [DllImport( "dwmapi.dll" )] private static extern int DwmGetWindowAttribute( IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, out bool pvAttribute, int cbAttribute ); public static bool IsWindowValidForCapture( IntPtr hwnd ) { if ( hwnd.ToInt32() == 0 ) { return false; } if ( hwnd == GetShellWindow() ) { return false; } if ( !IsWindowVisible( hwnd ) ) { return false; } if ( GetAncestor( hwnd, GetAncestorFlags.GetRoot ) != hwnd ) { return false; } var style = (WindowStyles)(uint)GetWindowLongPtr( hwnd, (int)GWL.GWL_STYLE ).ToInt32(); if ( style.HasFlag( WindowStyles.WS_DISABLED ) ) { return false; } var cloaked = false; var hrTemp = DwmGetWindowAttribute( hwnd, DWMWINDOWATTRIBUTE.Cloaked, out cloaked, Marshal.SizeOf() ); if ( hrTemp == 0 && cloaked ) { return false; } return true; } private enum GetAncestorFlags { // Retrieves the parent window. This does not include the owner, as it does with the GetParent function. GetParent = 1, // Retrieves the root window by walking the chain of parent windows. GetRoot = 2, // Retrieves the owned root window by walking the chain of parent and owner windows returned by GetParent. GetRootOwner = 3 } [Flags] private enum WindowStyles : uint { WS_BORDER = 0x800000, WS_CAPTION = 0xc00000, WS_CHILD = 0x40000000, WS_CLIPCHILDREN = 0x2000000, WS_CLIPSIBLINGS = 0x4000000, WS_DISABLED = 0x8000000, WS_DLGFRAME = 0x400000, WS_GROUP = 0x20000, WS_HSCROLL = 0x100000, WS_MAXIMIZE = 0x1000000, WS_MAXIMIZEBOX = 0x10000, WS_MINIMIZE = 0x20000000, WS_MINIMIZEBOX = 0x20000, WS_OVERLAPPED = 0x0, WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_SIZEFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, WS_POPUP = 0x80000000u, WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU, WS_SIZEFRAME = 0x40000, WS_SYSMENU = 0x80000, WS_TABSTOP = 0x10000, WS_VISIBLE = 0x10000000, WS_VSCROLL = 0x200000 } private enum DWMWINDOWATTRIBUTE : uint { NCRenderingEnabled = 1, NCRenderingPolicy, TransitionsForceDisabled, AllowNCPaint, CaptionButtonBounds, NonClientRtlLayout, ForceIconicRepresentation, Flip3DPolicy, ExtendedFrameBounds, HasIconicBitmap, DisallowPeek, ExcludedFromPeek, Cloak, Cloaked, FreezeRepresentation } } } ================================================ FILE: Plugins.sln/Updater/AutoVersion.tt ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of Updater. Updater is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Updater is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Updater. If not, see . */ <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".cs" #> <#@ Assembly Name="System.Core.dll" #> <#@ Assembly Name="System.Windows.Forms.dll" #> <#@ import namespace="System.IO" #> using System.Reflection; [assembly: AssemblyProduct("<#= AppName #>")] [assembly: AssemblyTitle("<#= AppDesc #>")] [assembly: AssemblyDescription("<#= AppDesc #>")] [assembly: AssemblyCompany("https://github.com/newlooper")] [assembly: AssemblyCopyright("Copyright © <#= Copyright #>")] [assembly: AssemblyVersion("<#= MAJOR #>.<#= MINOR #>.<#= DaysSinceProjectStarted #>.<#= MinutesSinceMidnight #>")] [assembly: AssemblyFileVersion("<#= MAJOR #>.<#= MINOR #>.<#= DaysSinceProjectStarted #>.<#= MinutesSinceMidnight #>")] <#+ private static readonly DateTime ProjectStartedDate = new( 2022, 12, 22 ); private static readonly string Copyright = ProjectStartedDate.Year + " - " + DateTime.Now.Year; private static readonly string AppName = new DirectoryInfo( "." ).Name; private static readonly string AppDesc = "VirtualSpace.Plugin - Updater"; private const int MAJOR = 1; private const int MINOR = 0; private static readonly int DaysSinceProjectStarted = (int)( DateTime.UtcNow - ProjectStartedDate ).TotalDays; private static readonly int MinutesSinceMidnight = (int)DateTime.UtcNow.TimeOfDay.TotalMinutes; #> ================================================ FILE: Plugins.sln/Updater/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Plugins.sln/Updater/Config/Const.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Updater. // // Updater is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Updater is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Updater. If not, see . namespace Updater.Config; public static class Const { public const string HttpHeaderUserAgent = "User-Agent"; public const string HttpUserAgent = "C# App"; public const string GitHubApiLatestRelease = "https://api.github.com/repos/newlooper/VirtualSpace/releases/latest"; public const string PatternTag = @"""tag_name"": ?""(.*?)"""; public const string PatternVersion = @"\d+\.\d+\.\d+(\.\d+)?"; public const string PatternDownloadUrl = @"""browser_download_url"": ?""(.*?)"""; public const string DownloadZip = "download.zip"; public const int WaitInterval = 500; } ================================================ FILE: Plugins.sln/Updater/HttpClientProgress.cs ================================================ namespace Updater; // https://gist.github.com/dalexsoto/9fd3c5bdbe9f61a717d47c5843384d11 public static class HttpClientProgressExtensions { public static async Task DownloadDataAsync( this HttpClient client, string requestUrl, Stream destination, IProgress progress = null, CancellationToken cancellationToken = default ) { using var response = await client.GetAsync( requestUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken ); var contentLength = response.Content.Headers.ContentLength; await using var downloadStream = await response.Content.ReadAsStreamAsync( cancellationToken ); // no progress... no contentLength... very sad if ( progress is null || !contentLength.HasValue ) { await downloadStream.CopyToAsync( destination, cancellationToken ); return; } // Such progress and contentLength much reporting! float GetProgressPercentage( float read, float total ) { return read / total * 100f; } var progressWrapper = new Progress( bytes => progress.Report( GetProgressPercentage( bytes, contentLength.Value ) ) ); await downloadStream.CopyToAsync( destination, 81920, progressWrapper, cancellationToken ); } private static async Task CopyToAsync( this Stream source, Stream destination, int bufferSize, IProgress progress = null, CancellationToken cancellationToken = default ) { if ( bufferSize < 0 ) throw new ArgumentOutOfRangeException( nameof( bufferSize ) ); if ( source is null ) throw new ArgumentNullException( nameof( source ) ); if ( !source.CanRead ) throw new InvalidOperationException( $"'{nameof( source )}' is not readable." ); if ( destination == null ) throw new ArgumentNullException( nameof( destination ) ); if ( !destination.CanWrite ) throw new InvalidOperationException( $"'{nameof( destination )}' is not writable." ); var buffer = new byte[bufferSize]; long totalBytesRead = 0; int bytesRead; while ( ( bytesRead = await source.ReadAsync( buffer, cancellationToken ).ConfigureAwait( false ) ) != 0 ) { await destination.WriteAsync( buffer.AsMemory( 0, bytesRead ), cancellationToken ).ConfigureAwait( false ); totalBytesRead += bytesRead; progress?.Report( totalBytesRead ); } } } ================================================ FILE: Plugins.sln/Updater/MainForm.Designer.cs ================================================ namespace Updater { partial class MainForm { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { progbarDownload = new ProgressBar(); tableLayoutPanel1 = new TableLayoutPanel(); lb_progress = new Label(); tableLayoutPanel1.SuspendLayout(); SuspendLayout(); // // progbarDownload // progbarDownload.Dock = DockStyle.Fill; progbarDownload.Location = new Point(10, 60); progbarDownload.Margin = new Padding(10); progbarDownload.Name = "progbarDownload"; progbarDownload.Size = new Size(480, 30); progbarDownload.TabIndex = 0; // // tableLayoutPanel1 // tableLayoutPanel1.ColumnCount = 1; tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); tableLayoutPanel1.Controls.Add(progbarDownload, 0, 1); tableLayoutPanel1.Controls.Add(lb_progress, 0, 0); tableLayoutPanel1.Dock = DockStyle.Fill; tableLayoutPanel1.Location = new Point(0, 0); tableLayoutPanel1.Name = "tableLayoutPanel1"; tableLayoutPanel1.RowCount = 2; tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 50F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 50F)); tableLayoutPanel1.Size = new Size(500, 100); tableLayoutPanel1.TabIndex = 1; // // lb_progress // lb_progress.AutoSize = true; lb_progress.Dock = DockStyle.Fill; lb_progress.Location = new Point(10, 10); lb_progress.Margin = new Padding(10); lb_progress.Name = "lb_progress"; lb_progress.Size = new Size(480, 30); lb_progress.TabIndex = 1; lb_progress.TextAlign = ContentAlignment.MiddleCenter; // // MainForm // AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(500, 100); Controls.Add(tableLayoutPanel1); FormBorderStyle = FormBorderStyle.None; Margin = new Padding(2); Name = "MainForm"; StartPosition = FormStartPosition.CenterScreen; Text = "MainForm"; TopMost = true; Load += MainForm_Load; tableLayoutPanel1.ResumeLayout(false); tableLayoutPanel1.PerformLayout(); ResumeLayout(false); } #endregion private ProgressBar progbarDownload; private TableLayoutPanel tableLayoutPanel1; private Label lb_progress; } } ================================================ FILE: Plugins.sln/Updater/MainForm.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Updater. // // Updater is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Updater is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Updater. If not, see . using System.IO.Compression; using System.Reflection; using System.Resources; using System.Text.RegularExpressions; using Updater.Config; using VirtualSpace.Commons; using VirtualSpace.Plugin; namespace Updater { public partial class MainForm : Form { private static readonly ResourceManager Langs = new( Assembly.GetExecutingAssembly().GetName().Name + ".Resources.Langs.WinFormStrings", typeof( MainForm ).Assembly ); public MainForm() { InitializeComponent(); } protected override void OnLoad( EventArgs e ) { Visible = false; // Hide form window. ShowInTaskbar = false; // Remove from taskbar. base.OnLoad( e ); } private void MainForm_Load( object sender, EventArgs e ) { var pipeMessage = new PipeMessage { Type = PipeMessageType.PLUGIN_UPDATER, Name = PluginManager.PluginInfo.Name, Handle = Handle.ToInt32() }; try { IpcPipeClient.PluginCheckIn( pipeMessage, () => { MessageBox.Show( Langs.GetString( "Error.CheckHost" ) ); }, Application.Exit, CheckUpdate ); } catch { Application.Exit(); } } private async void CheckUpdate( HostInfo hostInfo ) { try { using var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add( Const.HttpHeaderUserAgent, Const.HttpUserAgent ); var jsonReleaseInfo = await httpClient.GetStringAsync( Const.GitHubApiLatestRelease ); var mTag = Regex.Match( jsonReleaseInfo, Const.PatternTag ); if ( !mTag.Success ) throw new Exception( "release info not found." ); var mVer = Regex.Match( mTag.Groups[1].Value, Const.PatternVersion ); if ( !mVer.Success ) throw new Exception( "version info not found." ); var latestVersion = new Version( mVer.Groups[0].Value ); if ( latestVersion <= hostInfo.Version ) throw new Exception( "no update." ); var dialogResult = MessageBox.Show( string.Format( Langs.GetString( "Updater.Confirm" ), hostInfo.Product, latestVersion, hostInfo.Version ), Langs.GetString( "Updater.Confirm.Title" ), MessageBoxButtons.YesNo, MessageBoxIcon.Information ); if ( !dialogResult.Equals( DialogResult.Yes ) && !dialogResult.Equals( DialogResult.OK ) ) throw new Exception( "user canceled." ); var mcUrls = Regex.Matches( jsonReleaseInfo, Const.PatternDownloadUrl ); var zipUrl = ""; foreach ( Match mUrl in mcUrls ) { var url = mUrl.Groups[1].Value; if ( url.Contains( "noplugin" ) ) { zipUrl = url; break; } } if ( string.IsNullOrEmpty( zipUrl ) ) throw new Exception( "file url not found." ); Visible = true; var downloadZip = Path.Combine( PluginManager.GetAppFolder(), Const.DownloadZip ); var progress = new Progress(); progress.ProgressChanged += ( s, progressValue ) => { progbarDownload.Value = (int)progressValue; }; lb_progress.Text = Langs.GetString( "Progress.Downloading" ); if ( File.Exists( downloadZip ) ) File.Delete( downloadZip ); await using var file = new FileStream( downloadZip, FileMode.Create, FileAccess.Write, FileShare.None ); await httpClient.DownloadDataAsync( zipUrl, file, progress ); file.Close(); while ( progbarDownload.Value < 100 ) { await Task.Delay( Const.WaitInterval ); } lb_progress.Text = Langs.GetString( "Progress.Clean" ); await Task.Delay( Const.WaitInterval ); var exeInZip = hostInfo.Product + ".exe"; var backup = hostInfo.AppPath + ".bak"; if ( File.Exists( backup ) ) File.Delete( backup ); lb_progress.Text = Langs.GetString( "Progress.Extract" ); await Task.Delay( Const.WaitInterval ); using var zip = ZipFile.Open( downloadZip, ZipArchiveMode.Read ); foreach ( var entry in zip.Entries ) { if ( !entry.Name.Contains( exeInZip ) ) continue; File.Move( hostInfo.AppPath, backup ); entry.ExtractToFile( hostInfo.AppPath ); lb_progress.Text = Langs.GetString( "Progress.NotifyHostRestart" ); await Task.Delay( Const.WaitInterval ); IpcPipeClient.NotifyHostRestart(); break; } Visible = false; } catch { // ignored } finally { Application.Exit(); } } } } ================================================ FILE: Plugins.sln/Updater/MainForm.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: Plugins.sln/Updater/Program.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of Updater. // // Updater is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Updater is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Updater. If not, see . using VirtualSpace.Plugin; namespace Updater { internal static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); var pluginInfo = PluginManager.PluginInfo; if ( pluginInfo == null || string.IsNullOrEmpty( pluginInfo.Name ) ) { MessageBox.Show( $"{PluginManager.PluginInfoFile} invalid." ); } else { Application.Run( new MainForm() ); } } } } ================================================ FILE: Plugins.sln/Updater/Resources/Langs/WinFormStrings.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 This Program require VirtualSpace running first. New version of {0} {1} available, You are using {2} Do you want to update now? Update Available Downloading... Clean Old Files... Extract Files... Notify Host Restart. ================================================ FILE: Plugins.sln/Updater/Resources/Langs/WinFormStrings.zh-Hans.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 运行本程序需要先运行 VirtualSpace。 新版本 {0} {1} 可用,当前运行的是 {2} 是否执行更新? 有更新可用 下载中... 清理旧文件... 解压中... 通知主程序重启 ================================================ FILE: Plugins.sln/Updater/Updater.csproj ================================================  WinExe net6.0-windows enable true enable false true True AutoVersion.tt Always ================================================ FILE: Plugins.sln/Updater/plugin.json ================================================ { "Name": "Updater", "Display": "Updater", "Version": "1.2", "Author": "Dylan Cheng", "Email": "newlooper@hotmail.com", "Entry": "Updater.exe", "AutoStart": true, "AutoStartTiming": 0, "RestartPolicy": { "Trigger": 0, "Values": [], "Enabled": false }, "ClosePolicy": { "Trigger": 0, "Values": [], "Enabled": false }, "Requirements": { "WinVer": { "Min": { "Major": 10, "Build": 19041 } }, "HostVersion": "0.1.454" } } ================================================ FILE: Readme.md ================================================ # VirtualSpace > A Virtual Desktop Enhancement GUI Program For Win10 & Win11 [![License](https://img.shields.io/github/license/newlooper/VirtualSpace "License")](https://github.com/newlooper/VirtualSpace/blob/main/COPYING) [![Download Lastest](https://img.shields.io/github/v/release/newlooper/VirtualSpace "Download Lastest")](https://github.com/newlooper/VirtualSpace/releases) [![Total Downloads](https://img.shields.io/github/downloads/newlooper/VirtualSpace/total "Total Downloads")](https://github.com/newlooper/VirtualSpace/releases) ## 1. Intro ### 1.1 Design memo cn: https://newlooper.com/post/original/cs/os/windows/virtualdesktop/ ## 2. Download & Installation Download from [Releases](https://github.com/newlooper/VirtualSpace/releases) page. VirtualSpace is green software, All used files are in its own directory, just unzip to a local dir (eg. `your desktop`\VirtualSpace) and run. or build the program yourself (see below). ## 3. Build > Suggested Target Platform `x64` ### 3.1 main program - build VirtualSpace > Note > > WinForms\AppController is currently not used by VirtualSpace, you may unload it in your IDE ### 3.2 plugins - Cube3D —— plugin for virtual desktop switch effects - build Cube3D project - put `all generated files` into main program's plugins Folder eg: `plugins\Cube3D` - Run Cube3D.exe after VirtualSpace started ## 4. HowTo ### 4.1 Default Hotkey - LWin+Tab —— rise main view - Ctrl+Alt+F12 —— config panel - LWin+LCtrl+<↑ ↓ ← →> —— switch virtual desktop ## 5. Q&A - Q1: Why hotkey not working sometimes. - A1: This is usually due to Windows UIPI (UAC). - S1: Run VirtualSpace as Administrator to fix this. [Others](https://github.com/newlooper/VirtualSpace/issues?q=is%3Aissue) ## 6. Demos ### Video [![](https://res.cloudinary.com/marcomontalbano/image/upload/v1662744032/video_to_markdown/images/youtube--aFUo2kLYUy0-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=aFUo2kLYUy0 "") ### Image ![05](https://github.com/newlooper/images/blob/main/VirtualSpace/05-SwitchVirtualDesktopInDirecti.gif?raw=true '05') ================================================ FILE: Resources/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Resources/Images.Designer.cs ================================================ //------------------------------------------------------------------------------ // // 此代码由工具生成。 // 运行时版本:4.0.30319.42000 // // 对此文件的更改可能会导致不正确的行为,并且如果 // 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ namespace Resources { using System; /// /// 一个强类型的资源类,用于查找本地化的字符串等。 /// // 此类是由 StronglyTypedResourceBuilder // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // (以 /str 作为命令选项),或重新生成 VS 项目。 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Images { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Images() { } /// /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Resources.Images", typeof(Images).Assembly); resourceMan = temp; } return resourceMan; } } /// /// 重写当前线程的 CurrentUICulture 属性,对 /// 使用此强类型资源类的所有资源查找执行重写。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } } } ================================================ FILE: Resources/Images.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: Resources/Resources.csproj ================================================ net6.0-windows enable 9 True True Images.resx ResXFileCodeGenerator Images.Designer.cs ================================================ FILE: UiAutomation/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: UiAutomation/UIA.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Windows.Automation; namespace VirtualSpace.UIA { public static class Uia { public static void CloseButtonInvokeByWindowHandle( IntPtr hWnd ) { var window = AutomationElement.FromHandle( hWnd ); var closeButton = window?.FindFirst( TreeScope.Descendants, new PropertyCondition( AutomationElement.AutomationIdProperty, "Close" ) ); if ( closeButton != null ) { var invokePattern = (InvokePattern)closeButton.GetCurrentPattern( InvokePattern.Pattern ); invokePattern.Invoke(); } } } } ================================================ FILE: UiAutomation/UiAutomation.csproj ================================================  net6.0-windows 9 true enable ================================================ FILE: VirtualDesktop/VirtualDesktop10/COM.cs ================================================ // Author: Markus Scholtes, 2021 // Version 1.9, 2021-10-08 // Version for Windows 10 1809 to 21H1 // Compile with: // C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe VirtualDesktop.cs // Based on http://stackoverflow.com/a/32417530, Windows 10 SDK, github project Grabacr07/VirtualDesktop and own research ///////////////////////////////////////////////// // Dylan Cheng (https://github.com/newlooper) // added Notifications about desktop // added conditional compile for C#/WinRT breaking change on .NET 5.0+ using System; using System.Runtime.InteropServices; namespace VirtualDesktop { internal static class Guids { public static readonly Guid CLSID_ImmersiveShell = new( "C2F03A33-21F5-47FA-B4BB-156362A2F239" ); public static readonly Guid CLSID_VirtualDesktopManagerInternal = new( "C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B" ); public static readonly Guid CLSID_VirtualDesktopManager = new( "AA509086-5CA9-4C25-8F95-589D3C07B48A" ); public static readonly Guid CLSID_VirtualDesktopPinnedApps = new( "B5A399E7-1C87-46B8-88E9-FC5747B171BD" ); public static readonly Guid CLSID_VirtualDesktopNotificationService = new( "A501FDEC-4A09-464C-AE4E-1B9C21B84918" ); } [StructLayout( LayoutKind.Sequential )] public struct Size { public int X; public int Y; } [StructLayout( LayoutKind.Sequential )] public struct Rect { public int Left; public int Top; public int Right; public int Bottom; } public enum APPLICATION_VIEW_CLOAK_TYPE : int { AVCT_NONE = 0, AVCT_DEFAULT = 1, AVCT_VIRTUAL_DESKTOP = 2 } public enum APPLICATION_VIEW_COMPATIBILITY_POLICY : int { AVCP_NONE = 0, AVCP_SMALL_SCREEN = 1, AVCP_TABLET_SMALL_SCREEN = 2, AVCP_VERY_SMALL_SCREEN = 3, AVCP_HIGH_SCALE_FACTOR = 4 } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "372E1D3B-38D3-42E4-A15B-8AB2B178F513" )] public interface IApplicationView { void GetIIdsSlot(); void GetRuntimeClassNameSlot(); void GetTrustLevelSlot(); int SetFocus(); int SwitchTo(); int TryInvokeBack( IntPtr /* IAsyncCallback* */ callback ); int GetThumbnailWindow( out IntPtr hWnd ); int GetMonitor( out IntPtr /* IImmersiveMonitor */ immersiveMonitor ); int GetVisibility( out int visibility ); int SetCloak( APPLICATION_VIEW_CLOAK_TYPE cloakType, int unknown ); int GetPosition( ref Guid guid /* GUID for IApplicationViewPosition */, out IntPtr /* IApplicationViewPosition** */ position ); int SetPosition( ref IntPtr /* IApplicationViewPosition* */ position ); int InsertAfterWindow( IntPtr hWnd ); int GetExtendedFramePosition( out Rect rect ); int GetAppUserModelId( [MarshalAs( UnmanagedType.LPWStr )] out string id ); int SetAppUserModelId( string id ); int IsEqualByAppUserModelId( string id, out int result ); int GetViewState( out uint state ); int SetViewState( uint state ); int GetNeediness( out int neediness ); int GetLastActivationTimestamp( out ulong timestamp ); int SetLastActivationTimestamp( ulong timestamp ); int GetVirtualDesktopId( out Guid guid ); int SetVirtualDesktopId( ref Guid guid ); int GetShowInSwitchers( out int flag ); int SetShowInSwitchers( int flag ); int GetScaleFactor( out int factor ); int CanReceiveInput( out bool canReceiveInput ); int GetCompatibilityPolicyType( out APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int SetCompatibilityPolicyType( APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int GetSizeConstraints( IntPtr /* IImmersiveMonitor* */ monitor, out Size size1, out Size size2 ); int GetSizeConstraintsForDpi( uint uint1, out Size size1, out Size size2 ); int SetSizeConstraintsForDpi( ref uint uint1, ref Size size1, ref Size size2 ); int OnMinSizePreferencesUpdated( IntPtr hWnd ); int ApplyOperation( IntPtr /* IApplicationViewOperation* */ operation ); int IsTray( out bool isTray ); int IsInHighZOrderBand( out bool isInHighZOrderBand ); int IsSplashScreenPresented( out bool isSplashScreenPresented ); int Flash(); int GetRootSwitchableOwner( out IApplicationView rootSwitchableOwner ); int EnumerateOwnershipTree( out IObjectArray ownershipTree ); int GetEnterpriseId( [MarshalAs( UnmanagedType.LPWStr )] out string enterpriseId ); int IsMirrored( out bool isMirrored ); int Unknown1( out int unknown ); int Unknown2( out int unknown ); int Unknown3( out int unknown ); int Unknown4( out int unknown ); int Unknown5( out int unknown ); int Unknown6( int unknown ); int Unknown7(); int Unknown8( out int unknown ); int Unknown9( int unknown ); int Unknown10( int unknownX, int unknownY ); int Unknown11( int unknown ); int Unknown12( out Size size1 ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "1841C6D7-4F9D-42C0-AF41-8747538F10E5" )] public interface IApplicationViewCollection { int GetViews( out IObjectArray array ); int GetViewsByZOrder( out IObjectArray array ); int GetViewsByAppUserModelId( string id, out IObjectArray array ); int GetViewForHWnd( IntPtr hWnd, out IApplicationView view ); int GetViewForApplication( object application, out IApplicationView view ); int GetViewForAppUserModelId( string id, out IApplicationView view ); int GetViewInFocus( out IntPtr view ); int Unknown1( out IntPtr view ); void RefreshCollection(); int RegisterForApplicationViewChanges( object listener, out int cookie ); int UnregisterForApplicationViewChanges( int cookie ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "FF72FFDD-BE7E-43FC-9C03-AD81681E88E4" )] public interface IVirtualDesktop { bool IsViewVisible( IApplicationView view ); Guid GetId(); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "F31574D6-B682-4CDC-BD56-1827860ABEC6" )] internal interface IVirtualDesktopManagerInternal { int GetCount(); void MoveViewToDesktop( IApplicationView view, IVirtualDesktop desktop ); bool CanViewMoveDesktops( IApplicationView view ); IVirtualDesktop GetCurrentDesktop(); void GetDesktops( out IObjectArray desktops ); [PreserveSig] int GetAdjacentDesktop( IVirtualDesktop from, int direction, out IVirtualDesktop desktop ); void SwitchDesktop( IVirtualDesktop desktop ); IVirtualDesktop CreateDesktop(); void RemoveDesktop( IVirtualDesktop desktop, IVirtualDesktop fallback ); IVirtualDesktop FindDesktop( ref Guid desktopId ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "0F3A72B0-4566-487E-9A33-4ED302F6D6CE" )] internal interface IVirtualDesktopManagerInternal2 { int GetCount(); void MoveViewToDesktop( IApplicationView view, IVirtualDesktop desktop ); bool CanViewMoveDesktops( IApplicationView view ); IVirtualDesktop GetCurrentDesktop(); void GetDesktops( out IObjectArray desktops ); [PreserveSig] int GetAdjacentDesktop( IVirtualDesktop from, int direction, out IVirtualDesktop desktop ); void SwitchDesktop( IVirtualDesktop desktop ); IVirtualDesktop CreateDesktop(); void RemoveDesktop( IVirtualDesktop desktop, IVirtualDesktop fallback ); IVirtualDesktop FindDesktop( ref Guid desktopId ); void Unknown1( IVirtualDesktop desktop, out IntPtr unknown1, out IntPtr unknown2 ); #if NET5_0_OR_GREATER void SetName( IVirtualDesktop desktop, IntPtr newName ); #else void SetName( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string name ); #endif } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "A5CD92FF-29BE-454C-8D04-D82879FB3F1B" )] internal interface IVirtualDesktopManager { bool IsWindowOnCurrentVirtualDesktop( IntPtr topLevelWindow ); Guid GetWindowDesktopId( IntPtr topLevelWindow ); void MoveWindowToDesktop( IntPtr topLevelWindow, ref Guid desktopId ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "4CE81583-1E4C-4632-A621-07A53543148F" )] internal interface IVirtualDesktopPinnedApps { bool IsAppIdPinned( string appId ); void PinAppID( string appId ); void UnpinAppID( string appId ); bool IsViewPinned( IApplicationView applicationView ); void PinView( IApplicationView applicationView ); void UnpinView( IApplicationView applicationView ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "92CA9DCD-5622-4BBA-A805-5E9F541BD8C9" )] public interface IObjectArray { void GetCount( out int count ); void GetAt( int index, ref Guid iid, [MarshalAs( UnmanagedType.Interface )] out object obj ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "6D5140C1-7436-11CE-8034-00AA006009FA" )] internal interface IServiceProvider10 { [return: MarshalAs( UnmanagedType.IUnknown )] object QueryService( ref Guid service, ref Guid riid ); } [ComImport] [Guid( "C179334C-4295-40D3-BEA1-C654D965605A" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotification { void VirtualDesktopCreated( IVirtualDesktop pDesktop ); void VirtualDesktopDestroyBegin( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyFailed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void ViewVirtualDesktopChanged( IApplicationView pView ); void CurrentVirtualDesktopChanged( IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ); } [ComImport] [Guid( "0CD45E71-D927-4F15-8B0A-8FEF525337BF" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotificationService { uint Register( IVirtualDesktopNotification pNotification ); void Unregister( uint dwCookie ); } } ================================================ FILE: VirtualDesktop/VirtualDesktop10/VirtualDesktop.cs ================================================ // Author: Markus Scholtes, 2021 // Version 1.9, 2021-10-08 // Version for Windows 10 1809 to 21H1 // Compile with: // C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe VirtualDesktop.cs // Based on http://stackoverflow.com/a/32417530, Windows 10 SDK, github project Grabacr07/VirtualDesktop and own research ///////////////////////////////////////////////// // Dylan Cheng (https://github.com/newlooper) // added Notifications about desktop // added conditional compile for C#/WinRT breaking change on .NET 5.0+ using System; using System.Diagnostics; using System.Runtime.InteropServices; using Microsoft.Win32; using VirtualSpace; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public class Desktop : IDesktop { private readonly IVirtualDesktop _ivd; private Desktop( IVirtualDesktop desktop ) { _ivd = desktop; } public Guid Guid => _ivd.GetId(); public static int Count => // return the number of desktops DesktopManager.GetDesktopCount(); public static Desktop Current { get { // returns current desktop try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); } catch { DesktopManager.ResetDesktopManager(); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); } } } public bool IsVisible => // return true if this desktop is the current displayed one ReferenceEquals( _ivd, DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); public Desktop Left { // return desktop at the left of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out var desktop ); // 3 = LeftDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } public Desktop Right { // return desktop at the right of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out var desktop ); // 4 = RightDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } // get process id to window handle [DllImport( "user32.dll" )] private static extern int GetWindowThreadProcessId( IntPtr hWnd, out int lpdwProcessId ); // get handle of active window [DllImport( "user32.dll" )] private static extern IntPtr GetForegroundWindow(); public override int GetHashCode() { // get hash return _ivd.GetHashCode(); } public override bool Equals( object? obj ) { // compare with object return obj is Desktop desk && ReferenceEquals( _ivd, desk._ivd ); } public static Desktop FromIndex( int index ) { // return desktop object from index (-> index = 0..Count-1) return new Desktop( DesktopManager.GetDesktop( index ) ); } public static Desktop? FromWindow( IntPtr hWnd ) { // return desktop object to desktop on which window is displayed if ( hWnd == IntPtr.Zero ) return null; var id = DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.FindDesktop( ref id ) ); } public static int SysIndexFromDesktop( Desktop desktop ) { // return index of desktop object or -1 if not found if ( desktop == null ) return -1; return DesktopManager.GetDesktopIndex( desktop._ivd ); } public static string DesktopNameFromDesktop( Desktop desktop ) { // return name of desktop or "Desktop n" if it has no name var guid = desktop._ivd.GetId(); // read desktop name in registry string desktopName = null; try { desktopName = (string)Registry.GetValue( "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VirtualDesktops\\Desktops\\{" + guid.ToString() + "}", "Name", null ); } catch { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( DesktopManager.GetDesktopIndex( desktop._ivd ) + 1 ).ToString(); } return desktopName; } public static string DesktopNameFromIndex( int index ) { // return name of desktop from index (-> index = 0..Count-1) or "Desktop n" if it has no name var guid = DesktopManager.GetDesktop( index ).GetId(); // read desktop name in registry string desktopName = null; try { desktopName = (string)Registry.GetValue( "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VirtualDesktops\\Desktops\\{" + guid.ToString() + "}", "Name", null ); } catch { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( index + 1 ).ToString(); } return desktopName; } public static bool HasDesktopNameFromIndex( int index ) { // return true is desktop is named or false if it has no name var guid = DesktopManager.GetDesktop( index ).GetId(); // read desktop name in registry string desktopName = null; try { desktopName = (string)Registry.GetValue( "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VirtualDesktops\\Desktops\\{" + guid.ToString() + "}", "Name", null ); } catch { } // name found? if ( string.IsNullOrEmpty( desktopName ) ) return false; else return true; } public static int SearchDesktop( string partialName ) { // get index of desktop with partial name, return -1 if no desktop found var index = -1; for ( var i = 0; i < DesktopManager.GetDesktopCount(); i++ ) { // loop through all virtual desktops and compare partial name to desktop name if ( DesktopNameFromIndex( i ).ToUpper().IndexOf( partialName.ToUpper() ) >= 0 ) { index = i; break; } } return index; } public static Desktop Create() { // create a new desktop return new Desktop( DesktopManager.VirtualDesktopManagerInternal.CreateDesktop() ); } public void Remove( Desktop? fallback = null ) { // destroy desktop and switch to IVirtualDesktop fallbackDesktop; if ( fallback == null ) { // if no fallback is given use desktop to the left except for desktop 0. var dtToCheck = new Desktop( DesktopManager.GetDesktop( 0 ) ); if ( Equals( dtToCheck ) ) { // desktop 0: set fallback to second desktop (= "right" desktop) DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out fallbackDesktop ); // 4 = RightDirection } else { // set fallback to "left" desktop DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out fallbackDesktop ); // 3 = LeftDirection } } else // set fallback desktop fallbackDesktop = fallback._ivd; DesktopManager.VirtualDesktopManagerInternal.RemoveDesktop( _ivd, fallbackDesktop ); } public void SetName( string name ) { // set name for desktop, empty string removes name if ( DesktopManager.VirtualDesktopManagerInternal2 != null ) // only if interface to set name is present { #if NET5_0_OR_GREATER var newName = MarshalString.CreateMarshaler( name ); DesktopManager.VirtualDesktopManagerInternal2.SetName( _ivd, MarshalString.GetAbi( newName ) ); #else DesktopManager.VirtualDesktopManagerInternal2.SetName( _ivd, name ); #endif } } public void MakeVisible() { // make this desktop visible DesktopManager.VirtualDesktopManagerInternal.SwitchDesktop( _ivd ); } public void MoveWindow( IntPtr hWnd ) { // move window to this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); _ = GetWindowThreadProcessId( hWnd, out var processId ); if ( Process.GetCurrentProcess().Id == processId ) { // window of process try // the easy way (if we are owner) { DesktopManager.VirtualDesktopManager.MoveWindowToDesktop( hWnd, _ivd.GetId() ); } catch // window of process, but we are not the owner { DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } else { // window of other process DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); try { DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } catch { // could not move active window, try main window (or whatever windows thinks is the main window) DesktopManager.ApplicationViewCollection.GetViewForHWnd( Process.GetProcessById( processId ).MainWindowHandle, out view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } } public void MoveActiveWindow() { // move active window to this desktop MoveWindow( GetForegroundWindow() ); } public bool HasWindow( IntPtr hWnd ) { // return true if window is on this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return _ivd.GetId() == DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); } public static bool IsWindowPinned( IntPtr hWnd ) { // return true if window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( hWnd.GetApplicationView() ); } public static void PinWindow( IntPtr hWnd ) { // pin window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( !DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinView( view ); } } public static void UnpinWindow( IntPtr hWnd ) { // unpin window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // unpin only if not already unpinned DesktopManager.VirtualDesktopPinnedApps.UnpinView( view ); } } public static bool IsApplicationPinned( IntPtr hWnd ) { // return true if application for window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( DesktopManager.GetAppId( hWnd ) ); } public static void PinApplication( IntPtr hWnd ) { // pin application for window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var appId = DesktopManager.GetAppId( hWnd ); if ( !DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinAppID( appId ); } } public static void UnpinApplication( IntPtr hWnd ) { // unpin application for window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); var appId = DesktopManager.GetAppId( hWnd ); if ( DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // unpin only if pinned DesktopManager.VirtualDesktopPinnedApps.UnpinAppID( appId ); } } public static Desktop? FromId( Guid guid ) { try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.FindDesktop( ref guid ) ); } catch { return null; } } } } ================================================ FILE: VirtualDesktop/VirtualDesktop10/VirtualDesktop10.csproj ================================================  net6.0-windows enable false 9 ================================================ FILE: VirtualDesktop/VirtualDesktop10/VirtualDesktopManager.cs ================================================ // Author: Markus Scholtes, 2021 // Version 1.9, 2021-10-08 // Version for Windows 10 1809 to 21H1 // Compile with: // C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe VirtualDesktop.cs // Based on http://stackoverflow.com/a/32417530, Windows 10 SDK, github project Grabacr07/VirtualDesktop and own research ///////////////////////////////////////////////// // Dylan Cheng (https://github.com/newlooper) // added Notifications about desktop // added conditional compile for C#/WinRT breaking change on .NET 5.0+ using System; using System.Runtime.InteropServices; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public static class DesktopManager { private static DisposableNotification _disposableNotification; private static IVirtualDesktopNotificationService VirtualDesktopNotificationService; internal static IVirtualDesktopManagerInternal VirtualDesktopManagerInternal; internal static IVirtualDesktopManagerInternal2 VirtualDesktopManagerInternal2; internal static IVirtualDesktopManager VirtualDesktopManager; internal static IVirtualDesktopPinnedApps VirtualDesktopPinnedApps; public static IApplicationViewCollection ApplicationViewCollection; static DesktopManager() { if ( Environment.OSVersion.Version is {Major: 10, Build: < 22000} ) Init(); } public static void ResetDesktopManager() { Init(); } private static void Init() { var shell = (IServiceProvider10)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_ImmersiveShell ) ); VirtualDesktopManager = (IVirtualDesktopManager)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_VirtualDesktopManager ) ); VirtualDesktopManagerInternal = (IVirtualDesktopManagerInternal)shell.QueryService( Guids.CLSID_VirtualDesktopManagerInternal, typeof( IVirtualDesktopManagerInternal ).GUID ); try { VirtualDesktopManagerInternal2 = (IVirtualDesktopManagerInternal2)shell.QueryService( Guids.CLSID_VirtualDesktopManagerInternal, typeof( IVirtualDesktopManagerInternal2 ).GUID ); } catch { VirtualDesktopManagerInternal2 = null; } ApplicationViewCollection = (IApplicationViewCollection)shell.QueryService( typeof( IApplicationViewCollection ).GUID, typeof( IApplicationViewCollection ).GUID ); VirtualDesktopPinnedApps = (IVirtualDesktopPinnedApps)shell.QueryService( Guids.CLSID_VirtualDesktopPinnedApps, typeof( IVirtualDesktopPinnedApps ).GUID ); VirtualDesktopNotificationService = (IVirtualDesktopNotificationService)shell.QueryService( Guids.CLSID_VirtualDesktopNotificationService, typeof( IVirtualDesktopNotificationService ).GUID ); _disposableNotification = new DisposableNotification(); _disposableNotification.DwCookie = VirtualDesktopNotificationService.Register( new EventProxy() ); } public static int GetDesktopCount() { try { return VirtualDesktopManagerInternal.GetCount(); } catch { ResetDesktopManager(); return VirtualDesktopManagerInternal.GetCount(); } } public static IVirtualDesktop GetDesktop( int index ) { // get desktop with index var count = GetDesktopCount(); if ( index < 0 || index >= count ) throw new ArgumentOutOfRangeException( nameof( index ) ); VirtualDesktopManagerInternal.GetDesktops( out var desktops ); desktops.GetAt( index, typeof( IVirtualDesktop ).GUID, out var objDesktop ); Marshal.ReleaseComObject( desktops ); return (IVirtualDesktop)objDesktop; } internal static int GetDesktopIndex( IVirtualDesktop desktop ) { // get index of desktop var count = GetDesktopCount(); var index = -1; var idSearch = desktop.GetId(); VirtualDesktopManagerInternal.GetDesktops( out var desktops ); for ( var i = 0; i < count; i++ ) { desktops.GetAt( i, typeof( IVirtualDesktop ).GUID, out var objDesktop ); if ( idSearch.CompareTo( ( (IVirtualDesktop)objDesktop ).GetId() ) == 0 ) { index = i; break; } } Marshal.ReleaseComObject( desktops ); return index; } internal static IApplicationView GetApplicationView( this IntPtr hWnd ) { // get application view to window handle ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); return view; } internal static string GetAppId( IntPtr hWnd ) { // get Application ID to window handle hWnd.GetApplicationView().GetAppUserModelId( out var appId ); return appId; } public static int GetViewCount() { ApplicationViewCollection.GetViews( out var objectArray ); objectArray.GetCount( out var count ); Marshal.ReleaseComObject( objectArray ); return count; } public static event EventHandler? Created; public static event EventHandler? DestroyBegin; public static event EventHandler? DestroyFailed; public static event EventHandler? Destroyed; public static event EventHandler? CurrentChanged; private class DisposableNotification : IDisposable { private bool _isDisposed; public uint DwCookie { private get; set; } public void Dispose() { if ( _isDisposed ) return; VirtualDesktopNotificationService.Unregister( DwCookie ); _isDisposed = true; } } // public static event EventHandler? Renamed; // public static event EventHandler? WallpaperChanged; private class EventProxy : IVirtualDesktopNotification { public void VirtualDesktopCreated( IVirtualDesktop pDesktop ) { Created?.Invoke( this, pDesktop ); } public void VirtualDesktopDestroyBegin( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyBegin?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyFailed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyFailed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { Destroyed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void ViewVirtualDesktopChanged( IApplicationView pView ) { // throw new NotImplementedException(); } public void CurrentVirtualDesktopChanged( IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ) { CurrentChanged?.Invoke( this, new VirtualDesktopChangedEventArgs( pDesktopOld, pDesktopNew ) ); } // public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, string chName ) // { // Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, chName ) ); // } } } public class VirtualDesktopRenamedEventArgs : EventArgs { public VirtualDesktopRenamedEventArgs( IVirtualDesktop desktop, string name ) { Desktop = desktop; Name = name; } public IVirtualDesktop Desktop { get; } public string Name { get; } } // public class VirtualDesktopWallpaperChangedEventArgs : EventArgs // { // public VirtualDesktopWallpaperChangedEventArgs( IVirtualDesktop desktop, string path ) // { // Desktop = desktop; // Path = path; // } // // public IVirtualDesktop Desktop { get; } // public string Path { get; } // } public class VirtualDesktopChangedEventArgs : EventArgs { public VirtualDesktopChangedEventArgs( IVirtualDesktop oldDesktop, IVirtualDesktop newDesktop ) { OldDesktop = oldDesktop; NewDesktop = newDesktop; } public IVirtualDesktop OldDesktop { get; } public IVirtualDesktop NewDesktop { get; } } // public class VirtualDesktopMovedEventArgs : EventArgs // { // public VirtualDesktopMovedEventArgs( IVirtualDesktop desktop, int oldIndex, int newIndex ) // { // Desktop = desktop; // OldIndex = oldIndex; // NewIndex = newIndex; // } // // public IVirtualDesktop Desktop { get; } // public int OldIndex { get; } // public int NewIndex { get; } // } public class VirtualDesktopDestroyEventArgs : EventArgs { public VirtualDesktopDestroyEventArgs( IVirtualDesktop destroyed, IVirtualDesktop fallback ) { Destroyed = destroyed; Fallback = fallback; } public IVirtualDesktop Destroyed { get; } public IVirtualDesktop Fallback { get; } } } ================================================ FILE: VirtualDesktop/VirtualDesktop11/COM.cs ================================================ // Author: Markus Scholtes, 2021 // Version 1.9, 2021-10-08 // Version for Windows 10 21H2 and Windows 11 // Compile with: // C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe VirtualDesktop11.cs // Based on http://stackoverflow.com/a/32417530, Windows 10 SDK, github project Grabacr07/VirtualDesktop and own research ///////////////////////////////////////////////// // Dylan Cheng (https://github.com/newlooper) // added Notifications about desktop // added conditional compile for C#/WinRT breaking change on .NET 5.0+ using System; using System.Runtime.InteropServices; namespace VirtualDesktop { internal static class Guids { public static readonly Guid CLSID_ImmersiveShell = new( "C2F03A33-21F5-47FA-B4BB-156362A2F239" ); public static readonly Guid CLSID_VirtualDesktopManagerInternal = new( "C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B" ); public static readonly Guid CLSID_VirtualDesktopManager = new( "AA509086-5CA9-4C25-8F95-589D3C07B48A" ); public static readonly Guid CLSID_VirtualDesktopPinnedApps = new( "B5A399E7-1C87-46B8-88E9-FC5747B171BD" ); public static readonly Guid CLSID_VirtualDesktopNotificationService = new( "A501FDEC-4A09-464C-AE4E-1B9C21B84918" ); } [StructLayout( LayoutKind.Sequential )] public struct Size { public int X; public int Y; } [StructLayout( LayoutKind.Sequential )] public struct Rect { public int Left; public int Top; public int Right; public int Bottom; } public enum APPLICATION_VIEW_CLOAK_TYPE : int { AVCT_NONE = 0, AVCT_DEFAULT = 1, AVCT_VIRTUAL_DESKTOP = 2 } public enum APPLICATION_VIEW_COMPATIBILITY_POLICY : int { AVCP_NONE = 0, AVCP_SMALL_SCREEN = 1, AVCP_TABLET_SMALL_SCREEN = 2, AVCP_VERY_SMALL_SCREEN = 3, AVCP_HIGH_SCALE_FACTOR = 4 } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "372E1D3B-38D3-42E4-A15B-8AB2B178F513" )] public interface IApplicationView { void GetIIdsSlot(); void GetRuntimeClassNameSlot(); void GetTrustLevelSlot(); int SetFocus(); int SwitchTo(); int TryInvokeBack( IntPtr /* IAsyncCallback* */ callback ); int GetThumbnailWindow( out IntPtr hWnd ); int GetMonitor( out IntPtr /* IImmersiveMonitor */ immersiveMonitor ); int GetVisibility( out int visibility ); int SetCloak( APPLICATION_VIEW_CLOAK_TYPE cloakType, int unknown ); int GetPosition( ref Guid guid /* GUID for IApplicationViewPosition */, out IntPtr /* IApplicationViewPosition** */ position ); int SetPosition( ref IntPtr /* IApplicationViewPosition* */ position ); int InsertAfterWindow( IntPtr hWnd ); int GetExtendedFramePosition( out Rect rect ); int GetAppUserModelId( [MarshalAs( UnmanagedType.LPWStr )] out string id ); int SetAppUserModelId( string id ); int IsEqualByAppUserModelId( string id, out int result ); int GetViewState( out uint state ); int SetViewState( uint state ); int GetNeediness( out int neediness ); int GetLastActivationTimestamp( out ulong timestamp ); int SetLastActivationTimestamp( ulong timestamp ); int GetVirtualDesktopId( out Guid guid ); int SetVirtualDesktopId( ref Guid guid ); int GetShowInSwitchers( out int flag ); int SetShowInSwitchers( int flag ); int GetScaleFactor( out int factor ); int CanReceiveInput( out bool canReceiveInput ); int GetCompatibilityPolicyType( out APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int SetCompatibilityPolicyType( APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int GetSizeConstraints( IntPtr /* IImmersiveMonitor* */ monitor, out Size size1, out Size size2 ); int GetSizeConstraintsForDpi( uint uint1, out Size size1, out Size size2 ); int SetSizeConstraintsForDpi( ref uint uint1, ref Size size1, ref Size size2 ); int OnMinSizePreferencesUpdated( IntPtr hWnd ); int ApplyOperation( IntPtr /* IApplicationViewOperation* */ operation ); int IsTray( out bool isTray ); int IsInHighZOrderBand( out bool isInHighZOrderBand ); int IsSplashScreenPresented( out bool isSplashScreenPresented ); int Flash(); int GetRootSwitchableOwner( out IApplicationView rootSwitchableOwner ); int EnumerateOwnershipTree( out IObjectArray ownershipTree ); int GetEnterpriseId( [MarshalAs( UnmanagedType.LPWStr )] out string enterpriseId ); int IsMirrored( out bool isMirrored ); int Unknown1( out int unknown ); int Unknown2( out int unknown ); int Unknown3( out int unknown ); int Unknown4( out int unknown ); int Unknown5( out int unknown ); int Unknown6( int unknown ); int Unknown7(); int Unknown8( out int unknown ); int Unknown9( int unknown ); int Unknown10( int unknownX, int unknownY ); int Unknown11( int unknown ); int Unknown12( out Size size1 ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "1841C6D7-4F9D-42C0-AF41-8747538F10E5" )] public interface IApplicationViewCollection { int GetViews( out IObjectArray array ); int GetViewsByZOrder( out IObjectArray array ); int GetViewsByAppUserModelId( string id, out IObjectArray array ); int GetViewForHWnd( IntPtr hWnd, out IApplicationView view ); int GetViewForApplication( object application, out IApplicationView view ); int GetViewForAppUserModelId( string id, out IApplicationView view ); int GetViewInFocus( out IntPtr view ); int Unknown1( out IntPtr view ); void RefreshCollection(); int RegisterForApplicationViewChanges( object listener, out int cookie ); int UnregisterForApplicationViewChanges( int cookie ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "536D3495-B208-4CC9-AE26-DE8111275BF8" )] public interface IVirtualDesktop { bool IsViewVisible( IApplicationView view ); Guid GetId(); IntPtr Unknown1(); #if NET5_0_OR_GREATER public void GetString( out IntPtr hstr ); #else [return: MarshalAs( UnmanagedType.HString )] string GetName(); #endif [return: MarshalAs( UnmanagedType.HString )] string GetWallpaperPath(); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "B2F925B9-5A0F-4D2E-9F4D-2B1507593C10" )] internal interface IVirtualDesktopManagerInternal { int GetCount( IntPtr hWndOrMon ); void MoveViewToDesktop( IApplicationView view, IVirtualDesktop desktop ); bool CanViewMoveDesktops( IApplicationView view ); IVirtualDesktop GetCurrentDesktop( IntPtr hWndOrMon ); IObjectArray GetAllCurrentDesktops(); void GetDesktops( IntPtr hWndOrMon, out IObjectArray desktops ); [PreserveSig] int GetAdjacentDesktop( IVirtualDesktop from, int direction, out IVirtualDesktop desktop ); void SwitchDesktop( IntPtr hWndOrMon, IVirtualDesktop desktop ); IVirtualDesktop CreateDesktop( IntPtr hWndOrMon ); void MoveDesktop( IVirtualDesktop desktop, IntPtr hWndOrMon, int nIndex ); void RemoveDesktop( IVirtualDesktop desktop, IVirtualDesktop fallback ); IVirtualDesktop FindDesktop( ref Guid desktopId ); void GetDesktopSwitchIncludeExcludeViews( IVirtualDesktop desktop, out IObjectArray unknown1, out IObjectArray unknown2 ); #if NET5_0_OR_GREATER void SetName( IVirtualDesktop desktop, IntPtr newName ); void SetWallpaper( IVirtualDesktop desktop, IntPtr path ); #else void SetDesktopName( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string name ); void SetDesktopWallpaper( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string path ); #endif void UpdateWallpaperPathForAllDesktops( [MarshalAs( UnmanagedType.HString )] string path ); void CopyDesktopState( IApplicationView pView0, IApplicationView pView1 ); int GetDesktopIsPerMonitor(); void SetDesktopIsPerMonitor( bool state ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "A5CD92FF-29BE-454C-8D04-D82879FB3F1B" )] internal interface IVirtualDesktopManager { bool IsWindowOnCurrentVirtualDesktop( IntPtr topLevelWindow ); Guid GetWindowDesktopId( IntPtr topLevelWindow ); void MoveWindowToDesktop( IntPtr topLevelWindow, ref Guid desktopId ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "4CE81583-1E4C-4632-A621-07A53543148F" )] internal interface IVirtualDesktopPinnedApps { bool IsAppIdPinned( string appId ); void PinAppID( string appId ); void UnpinAppID( string appId ); bool IsViewPinned( IApplicationView applicationView ); void PinView( IApplicationView applicationView ); void UnpinView( IApplicationView applicationView ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "92CA9DCD-5622-4BBA-A805-5E9F541BD8C9" )] public interface IObjectArray { void GetCount( out int count ); void GetAt( int index, ref Guid iid, [MarshalAs( UnmanagedType.Interface )] out object obj ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "6D5140C1-7436-11CE-8034-00AA006009FA" )] internal interface IServiceProvider10 { [return: MarshalAs( UnmanagedType.IUnknown )] object QueryService( ref Guid service, ref Guid riid ); } [ComImport] [Guid( "cd403e52-deed-4c13-b437-b98380f2b1e8" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotification { void VirtualDesktopCreated( IObjectArray p0, IVirtualDesktop pDesktop ); void VirtualDesktopDestroyBegin( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyFailed( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyed( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void Proc7( int p0 ); void VirtualDesktopMoved( IObjectArray p0, IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo ); #if NET5_0_OR_GREATER void VirtualDesktopRenamed( IVirtualDesktop pDesktop, IntPtr newName ); #else void VirtualDesktopRenamed( IVirtualDesktop pDesktop, [MarshalAs( UnmanagedType.HString )] string chName ); #endif void ViewVirtualDesktopChanged( IApplicationView pView ); void CurrentVirtualDesktopChanged( IObjectArray p0, IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ); #if NET5_0_OR_GREATER void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, IntPtr newPath ); #else void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, [MarshalAs( UnmanagedType.HString )] string chPath ); #endif } [ComImport] [Guid( "0cd45e71-d927-4f15-8b0a-8fef525337bf" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotificationService { uint Register( IVirtualDesktopNotification pNotification ); void Unregister( uint dwCookie ); } } ================================================ FILE: VirtualDesktop/VirtualDesktop11/VirtualDesktop.cs ================================================ // Author: Markus Scholtes, 2021 // Version 1.9, 2021-10-08 // Version for Windows 10 21H2 and Windows 11 // Compile with: // C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe VirtualDesktop11.cs // Based on http://stackoverflow.com/a/32417530, Windows 10 SDK, github project Grabacr07/VirtualDesktop and own research ///////////////////////////////////////////////// // Dylan Cheng (https://github.com/newlooper) // added Notifications about desktop // added conditional compile for C#/WinRT breaking change on .NET 5.0+ using System; using System.Diagnostics; using System.Runtime.InteropServices; using VirtualSpace; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public class Desktop: IDesktop { private readonly IVirtualDesktop _ivd; private Desktop( IVirtualDesktop desktop ) { _ivd = desktop; } public Guid Guid => _ivd.GetId(); public static int Count => // return the number of desktops DesktopManager.GetDesktopCount(); public static Desktop Current { get { // returns current desktop try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop( IntPtr.Zero ) ); } catch { DesktopManager.ResetDesktopManager(); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop( IntPtr.Zero ) ); } } } public bool IsVisible => // return true if this desktop is the current displayed one ReferenceEquals( _ivd, DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop( IntPtr.Zero ) ); public Desktop Left { // return desktop at the left of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out var desktop ); // 3 = LeftDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } public Desktop Right { // return desktop at the right of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out var desktop ); // 4 = RightDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } // get process id to window handle [DllImport( "user32.dll" )] private static extern int GetWindowThreadProcessId( IntPtr hWnd, out int lpdwProcessId ); // get handle of active window [DllImport( "user32.dll" )] private static extern IntPtr GetForegroundWindow(); public override int GetHashCode() { // get hash return _ivd.GetHashCode(); } public override bool Equals( object? obj ) { // compare with object return obj is Desktop desk && ReferenceEquals( _ivd, desk._ivd ); } public static Desktop FromIndex( int index ) { // return desktop object from index (-> index = 0..Count-1) return new Desktop( DesktopManager.GetDesktop( index ) ); } public static Desktop FromWindow( IntPtr hWnd ) { // return desktop object to desktop on which window is displayed if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var id = DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.FindDesktop( ref id ) ); } public static int SysIndexFromDesktop( Desktop desktop ) { // return index of desktop object or -1 if not found if ( desktop == null ) return -1; return DesktopManager.GetDesktopIndex( desktop._ivd ); } public static string DesktopNameFromDesktop( Desktop desktop ) { // return name of desktop or "Desktop n" if it has no name // get desktop name string desktopName = null; try { #if NET5_0_OR_GREATER desktop._ivd.GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = desktop._ivd.GetName(); #endif } catch ( Exception ) { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( DesktopManager.GetDesktopIndex( desktop._ivd ) + 1 ).ToString(); } return desktopName; } public static string DesktopNameFromIndex( int index ) { // return name of desktop from index (-> index = 0..Count-1) or "Desktop n" if it has no name // get desktop name string desktopName = null; try { #if NET5_0_OR_GREATER DesktopManager.GetDesktop( index ).GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = DesktopManager.GetDesktop( index ).GetName(); #endif } catch { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( index + 1 ).ToString(); } return desktopName; } public static bool HasDesktopNameFromIndex( int index ) { // return true is desktop is named or false if it has no name // read desktop name in registry string desktopName = null; try { #if NET5_0_OR_GREATER DesktopManager.GetDesktop( index ).GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = DesktopManager.GetDesktop( index ).GetName(); #endif } catch { } // name found? if ( string.IsNullOrEmpty( desktopName ) ) return false; else return true; } public static string DesktopWallpaperFromIndex( int index ) { // return name of desktop wallpaper from index (-> index = 0..Count-1) // get desktop name var desktopWpPath = ""; try { desktopWpPath = DesktopManager.GetDesktop( index ).GetWallpaperPath(); } catch { } return desktopWpPath; } public static int SearchDesktop( string partialName ) { // get index of desktop with partial name, return -1 if no desktop found var index = -1; for ( var i = 0; i < DesktopManager.GetDesktopCount(); i++ ) { // loop through all virtual desktops and compare partial name to desktop name if ( DesktopNameFromIndex( i ).ToUpper().IndexOf( partialName.ToUpper() ) >= 0 ) { index = i; break; } } return index; } public static Desktop Create() { // create a new desktop return new Desktop( DesktopManager.VirtualDesktopManagerInternal.CreateDesktop( IntPtr.Zero ) ); } public void Remove( Desktop? fallback = null ) { // destroy desktop and switch to IVirtualDesktop fallbackDesktop; if ( fallback == null ) { // if no fallback is given use desktop to the left except for desktop 0. var dtToCheck = new Desktop( DesktopManager.GetDesktop( 0 ) ); if ( Equals( dtToCheck ) ) { // desktop 0: set fallback to second desktop (= "right" desktop) DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out fallbackDesktop ); // 4 = RightDirection } else { // set fallback to "left" desktop DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out fallbackDesktop ); // 3 = LeftDirection } } else // set fallback desktop fallbackDesktop = fallback._ivd; DesktopManager.VirtualDesktopManagerInternal.RemoveDesktop( _ivd, fallbackDesktop ); } public static void RemoveAll() { // remove all desktops but visible DesktopManager.VirtualDesktopManagerInternal.SetDesktopIsPerMonitor( true ); } public void Move( int index ) { // move current desktop to desktop in index (-> index = 0..Count-1) DesktopManager.VirtualDesktopManagerInternal.MoveDesktop( _ivd, IntPtr.Zero, index ); } public void SetName( string name ) { // set name for desktop, empty string removes name #if NET5_0_OR_GREATER var newName = MarshalString.CreateMarshaler( name ); DesktopManager.VirtualDesktopManagerInternal.SetName( _ivd, MarshalString.GetAbi( newName ) ); #else DesktopManager.VirtualDesktopManagerInternal.SetDesktopName( _ivd, name ); #endif } public void SetWallpaperPath( string path ) { // set path for wallpaper, empty string removes path if ( string.IsNullOrEmpty( path ) ) throw new ArgumentNullException(); #if NET5_0_OR_GREATER var newPath = MarshalString.CreateMarshaler( path ); DesktopManager.VirtualDesktopManagerInternal.SetWallpaper( _ivd, MarshalString.GetAbi( newPath ) ); #else DesktopManager.VirtualDesktopManagerInternal.SetDesktopWallpaper( _ivd, path ); #endif } public static void SetAllWallpaperPaths( string path ) { // set wallpaper path for all desktops if ( string.IsNullOrEmpty( path ) ) throw new ArgumentNullException(); DesktopManager.VirtualDesktopManagerInternal.UpdateWallpaperPathForAllDesktops( path ); } public void MakeVisible() { // make this desktop visible DesktopManager.VirtualDesktopManagerInternal.SwitchDesktop( IntPtr.Zero, _ivd ); } public void MoveWindow( IntPtr hWnd ) { // move window to this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); _ = GetWindowThreadProcessId( hWnd, out var processId ); if ( Process.GetCurrentProcess().Id == processId ) { // window of process try // the easy way (if we are owner) { DesktopManager.VirtualDesktopManager.MoveWindowToDesktop( hWnd, _ivd.GetId() ); } catch // window of process, but we are not the owner { DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } else { // window of other process DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); try { DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } catch { // could not move active window, try main window (or whatever windows thinks is the main window) DesktopManager.ApplicationViewCollection.GetViewForHWnd( Process.GetProcessById( processId ).MainWindowHandle, out view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } } public void MoveActiveWindow() { // move active window to this desktop MoveWindow( GetForegroundWindow() ); } public bool HasWindow( IntPtr hWnd ) { // return true if window is on this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return _ivd.GetId() == DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); } public static bool IsWindowPinned( IntPtr hWnd ) { // return true if window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( hWnd.GetApplicationView() ); } public static void PinWindow( IntPtr hWnd ) { // pin window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( !DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinView( view ); } } public static void UnpinWindow( IntPtr hWnd ) { // unpin window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // unpin only if not already unpinned DesktopManager.VirtualDesktopPinnedApps.UnpinView( view ); } } public static bool IsApplicationPinned( IntPtr hWnd ) { // return true if application for window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( DesktopManager.GetAppId( hWnd ) ); } public static void PinApplication( IntPtr hWnd ) { // pin application for window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var appId = DesktopManager.GetAppId( hWnd ); if ( !DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinAppID( appId ); } } public static void UnpinApplication( IntPtr hWnd ) { // unpin application for window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); var appId = DesktopManager.GetAppId( hWnd ); if ( DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // unpin only if pinned DesktopManager.VirtualDesktopPinnedApps.UnpinAppID( appId ); } } public static Desktop? FromId( Guid guid ) { try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.FindDesktop( ref guid ) ); } catch { return null; } } } } ================================================ FILE: VirtualDesktop/VirtualDesktop11/VirtualDesktop11.csproj ================================================  net6.0-windows enable false 9 ================================================ FILE: VirtualDesktop/VirtualDesktop11/VirtualDesktopManager.cs ================================================ // Author: Markus Scholtes, 2021 // Version 1.9, 2021-10-08 // Version for Windows 10 21H2 and Windows 11 // Compile with: // C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe VirtualDesktop11.cs // Based on http://stackoverflow.com/a/32417530, Windows 10 SDK, github project Grabacr07/VirtualDesktop and own research ///////////////////////////////////////////////// // Dylan Cheng (https://github.com/newlooper) // added Notifications about desktop // added conditional compile for C#/WinRT breaking change on .NET 5.0+ using System; using System.Runtime.InteropServices; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public static class DesktopManager { private static DisposableNotification _disposableNotification; private static IVirtualDesktopNotificationService VirtualDesktopNotificationService; internal static IVirtualDesktopManagerInternal VirtualDesktopManagerInternal; internal static IVirtualDesktopManager VirtualDesktopManager; internal static IVirtualDesktopPinnedApps VirtualDesktopPinnedApps; public static IApplicationViewCollection ApplicationViewCollection; static DesktopManager() { if ( Environment.OSVersion.Version is {Major: 10, Build: >= 22000} ) Init(); } public static void ResetDesktopManager() { Init(); } private static void Init() { var shell = (IServiceProvider10)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_ImmersiveShell ) ); VirtualDesktopManager = (IVirtualDesktopManager)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_VirtualDesktopManager ) ); VirtualDesktopManagerInternal = (IVirtualDesktopManagerInternal)shell.QueryService( Guids.CLSID_VirtualDesktopManagerInternal, typeof( IVirtualDesktopManagerInternal ).GUID ); ApplicationViewCollection = (IApplicationViewCollection)shell.QueryService( typeof( IApplicationViewCollection ).GUID, typeof( IApplicationViewCollection ).GUID ); VirtualDesktopPinnedApps = (IVirtualDesktopPinnedApps)shell.QueryService( Guids.CLSID_VirtualDesktopPinnedApps, typeof( IVirtualDesktopPinnedApps ).GUID ); VirtualDesktopNotificationService = (IVirtualDesktopNotificationService)shell.QueryService( Guids.CLSID_VirtualDesktopNotificationService, typeof( IVirtualDesktopNotificationService ).GUID ); _disposableNotification = new DisposableNotification(); _disposableNotification.DwCookie = VirtualDesktopNotificationService.Register( new EventProxy() ); } public static int GetDesktopCount() { try { return VirtualDesktopManagerInternal.GetCount( IntPtr.Zero ); } catch { ResetDesktopManager(); return VirtualDesktopManagerInternal.GetCount( IntPtr.Zero ); } } public static IVirtualDesktop GetDesktop( int index ) { // get desktop with index var count = GetDesktopCount(); if ( index < 0 || index >= count ) throw new ArgumentOutOfRangeException( nameof( index ) ); VirtualDesktopManagerInternal.GetDesktops( IntPtr.Zero, out var desktops ); desktops.GetAt( index, typeof( IVirtualDesktop ).GUID, out var objDesktop ); Marshal.ReleaseComObject( desktops ); return (IVirtualDesktop)objDesktop; } internal static int GetDesktopIndex( IVirtualDesktop desktop ) { // get index of desktop var count = GetDesktopCount(); var index = -1; var idSearch = desktop.GetId(); VirtualDesktopManagerInternal.GetDesktops( IntPtr.Zero, out var desktops ); for ( var i = 0; i < count; i++ ) { desktops.GetAt( i, typeof( IVirtualDesktop ).GUID, out var objDesktop ); if ( idSearch.CompareTo( ( (IVirtualDesktop)objDesktop ).GetId() ) == 0 ) { index = i; break; } } Marshal.ReleaseComObject( desktops ); return index; } internal static IApplicationView GetApplicationView( this IntPtr hWnd ) { // get application view to window handle ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); return view; } internal static string GetAppId( IntPtr hWnd ) { // get Application ID to window handle hWnd.GetApplicationView().GetAppUserModelId( out var appId ); return appId; } public static int GetViewCount() { ApplicationViewCollection.GetViews( out var objectArray ); objectArray.GetCount( out var count ); Marshal.ReleaseComObject( objectArray ); return count; } public static event EventHandler? Created; public static event EventHandler? DestroyBegin; public static event EventHandler? DestroyFailed; public static event EventHandler? Destroyed; public static event EventHandler? CurrentChanged; public static event EventHandler? Moved; public static event EventHandler? Renamed; public static event EventHandler? WallpaperChanged; private class DisposableNotification : IDisposable { private bool _isDisposed; public uint DwCookie { private get; set; } public void Dispose() { if ( _isDisposed ) return; VirtualDesktopNotificationService.Unregister( DwCookie ); _isDisposed = true; } } private class EventProxy : IVirtualDesktopNotification { public void ViewVirtualDesktopChanged( IApplicationView pView ) { // throw new NotImplementedException(); } public void CurrentVirtualDesktopChanged( IObjectArray p0, IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ) { CurrentChanged?.Invoke( this, new VirtualDesktopChangedEventArgs( pDesktopOld, pDesktopNew ) ); } public void VirtualDesktopCreated( IObjectArray p0, IVirtualDesktop pDesktop ) { Created?.Invoke( this, pDesktop ); } public void VirtualDesktopDestroyBegin( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyBegin?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyFailed( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyFailed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyed( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { Destroyed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void Proc7( int p0 ) { // throw new NotImplementedException(); } public void VirtualDesktopMoved( IObjectArray p0, IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo ) { Moved?.Invoke( this, new VirtualDesktopMovedEventArgs( pDesktop, nIndexFrom, nIndexTo ) ); } #if NET5_0_OR_GREATER public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, IntPtr newName ) { var name = MarshalString.FromAbi( newName ); Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, name ) ); } #else public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, string chName ) { Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, chName ) ); } #endif #if NET5_0_OR_GREATER public void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, IntPtr newPath ) { var path = MarshalString.FromAbi( newPath ); WallpaperChanged?.Invoke( this, new VirtualDesktopWallpaperChangedEventArgs( pDesktop, path ) ); } #else public void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, string chPath ) { WallpaperChanged?.Invoke( this, new VirtualDesktopWallpaperChangedEventArgs( pDesktop, chPath ) ); } #endif } } public class VirtualDesktopRenamedEventArgs : EventArgs { public VirtualDesktopRenamedEventArgs( IVirtualDesktop desktop, string name ) { Desktop = desktop; Name = name; } public IVirtualDesktop Desktop { get; } public string Name { get; } } public class VirtualDesktopWallpaperChangedEventArgs : EventArgs { public VirtualDesktopWallpaperChangedEventArgs( IVirtualDesktop desktop, string path ) { Desktop = desktop; Path = path; } public IVirtualDesktop Desktop { get; } public string Path { get; } } public class VirtualDesktopChangedEventArgs : EventArgs { public VirtualDesktopChangedEventArgs( IVirtualDesktop oldDesktop, IVirtualDesktop newDesktop ) { OldDesktop = oldDesktop; NewDesktop = newDesktop; } public IVirtualDesktop OldDesktop { get; } public IVirtualDesktop NewDesktop { get; } } public class VirtualDesktopMovedEventArgs : EventArgs { public VirtualDesktopMovedEventArgs( IVirtualDesktop desktop, int oldIndex, int newIndex ) { Desktop = desktop; OldIndex = oldIndex; NewIndex = newIndex; } public IVirtualDesktop Desktop { get; } public int OldIndex { get; } public int NewIndex { get; } } public class VirtualDesktopDestroyEventArgs : EventArgs { public VirtualDesktopDestroyEventArgs( IVirtualDesktop destroyed, IVirtualDesktop fallback ) { Destroyed = destroyed; Fallback = fallback; } public IVirtualDesktop Destroyed { get; } public IVirtualDesktop Fallback { get; } } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_21H2/COM.cs ================================================ // Author: Markus Scholtes, 2021 // Version 1.9, 2021-10-08 // Version for Windows 10 21H2 and Windows 11 // Compile with: // C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe VirtualDesktop11.cs // Based on http://stackoverflow.com/a/32417530, Windows 10 SDK, github project Grabacr07/VirtualDesktop and own research ///////////////////////////////////////////////// // Dylan Cheng (https://github.com/newlooper) // added Notifications about desktop // added conditional compile for C#/WinRT breaking change on .NET 5.0+ using System; using System.Runtime.InteropServices; namespace VirtualDesktop { internal static class Guids { public static readonly Guid CLSID_ImmersiveShell = new( "C2F03A33-21F5-47FA-B4BB-156362A2F239" ); public static readonly Guid CLSID_VirtualDesktopManagerInternal = new( "C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B" ); public static readonly Guid CLSID_VirtualDesktopManager = new( "AA509086-5CA9-4C25-8F95-589D3C07B48A" ); public static readonly Guid CLSID_VirtualDesktopPinnedApps = new( "B5A399E7-1C87-46B8-88E9-FC5747B171BD" ); public static readonly Guid CLSID_VirtualDesktopNotificationService = new( "A501FDEC-4A09-464C-AE4E-1B9C21B84918" ); } [StructLayout( LayoutKind.Sequential )] public struct Size { public int X; public int Y; } [StructLayout( LayoutKind.Sequential )] public struct Rect { public int Left; public int Top; public int Right; public int Bottom; } public enum APPLICATION_VIEW_CLOAK_TYPE : int { AVCT_NONE = 0, AVCT_DEFAULT = 1, AVCT_VIRTUAL_DESKTOP = 2 } public enum APPLICATION_VIEW_COMPATIBILITY_POLICY : int { AVCP_NONE = 0, AVCP_SMALL_SCREEN = 1, AVCP_TABLET_SMALL_SCREEN = 2, AVCP_VERY_SMALL_SCREEN = 3, AVCP_HIGH_SCALE_FACTOR = 4 } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "372E1D3B-38D3-42E4-A15B-8AB2B178F513" )] public interface IApplicationView { void GetIIdsSlot(); void GetRuntimeClassNameSlot(); void GetTrustLevelSlot(); int SetFocus(); int SwitchTo(); int TryInvokeBack( IntPtr /* IAsyncCallback* */ callback ); int GetThumbnailWindow( out IntPtr hWnd ); int GetMonitor( out IntPtr /* IImmersiveMonitor */ immersiveMonitor ); int GetVisibility( out int visibility ); int SetCloak( APPLICATION_VIEW_CLOAK_TYPE cloakType, int unknown ); int GetPosition( ref Guid guid /* GUID for IApplicationViewPosition */, out IntPtr /* IApplicationViewPosition** */ position ); int SetPosition( ref IntPtr /* IApplicationViewPosition* */ position ); int InsertAfterWindow( IntPtr hWnd ); int GetExtendedFramePosition( out Rect rect ); int GetAppUserModelId( [MarshalAs( UnmanagedType.LPWStr )] out string id ); int SetAppUserModelId( string id ); int IsEqualByAppUserModelId( string id, out int result ); int GetViewState( out uint state ); int SetViewState( uint state ); int GetNeediness( out int neediness ); int GetLastActivationTimestamp( out ulong timestamp ); int SetLastActivationTimestamp( ulong timestamp ); int GetVirtualDesktopId( out Guid guid ); int SetVirtualDesktopId( ref Guid guid ); int GetShowInSwitchers( out int flag ); int SetShowInSwitchers( int flag ); int GetScaleFactor( out int factor ); int CanReceiveInput( out bool canReceiveInput ); int GetCompatibilityPolicyType( out APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int SetCompatibilityPolicyType( APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int GetSizeConstraints( IntPtr /* IImmersiveMonitor* */ monitor, out Size size1, out Size size2 ); int GetSizeConstraintsForDpi( uint uint1, out Size size1, out Size size2 ); int SetSizeConstraintsForDpi( ref uint uint1, ref Size size1, ref Size size2 ); int OnMinSizePreferencesUpdated( IntPtr hWnd ); int ApplyOperation( IntPtr /* IApplicationViewOperation* */ operation ); int IsTray( out bool isTray ); int IsInHighZOrderBand( out bool isInHighZOrderBand ); int IsSplashScreenPresented( out bool isSplashScreenPresented ); int Flash(); int GetRootSwitchableOwner( out IApplicationView rootSwitchableOwner ); int EnumerateOwnershipTree( out IObjectArray ownershipTree ); int GetEnterpriseId( [MarshalAs( UnmanagedType.LPWStr )] out string enterpriseId ); int IsMirrored( out bool isMirrored ); int Unknown1( out int unknown ); int Unknown2( out int unknown ); int Unknown3( out int unknown ); int Unknown4( out int unknown ); int Unknown5( out int unknown ); int Unknown6( int unknown ); int Unknown7(); int Unknown8( out int unknown ); int Unknown9( int unknown ); int Unknown10( int unknownX, int unknownY ); int Unknown11( int unknown ); int Unknown12( out Size size1 ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "1841C6D7-4F9D-42C0-AF41-8747538F10E5" )] public interface IApplicationViewCollection { int GetViews( out IObjectArray array ); int GetViewsByZOrder( out IObjectArray array ); int GetViewsByAppUserModelId( string id, out IObjectArray array ); int GetViewForHWnd( IntPtr hWnd, out IApplicationView view ); int GetViewForApplication( object application, out IApplicationView view ); int GetViewForAppUserModelId( string id, out IApplicationView view ); int GetViewInFocus( out IntPtr view ); int Unknown1( out IntPtr view ); void RefreshCollection(); int RegisterForApplicationViewChanges( object listener, out int cookie ); int UnregisterForApplicationViewChanges( int cookie ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "536D3495-B208-4CC9-AE26-DE8111275BF8" )] public interface IVirtualDesktop { bool IsViewVisible( IApplicationView view ); Guid GetId(); IntPtr Unknown1(); #if NET5_0_OR_GREATER public void GetString( out IntPtr hstr ); #else [return: MarshalAs( UnmanagedType.HString )] string GetName(); #endif [return: MarshalAs( UnmanagedType.HString )] string GetWallpaperPath(); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "B2F925B9-5A0F-4D2E-9F4D-2B1507593C10" )] internal interface IVirtualDesktopManagerInternal { int GetCount( IntPtr hWndOrMon ); void MoveViewToDesktop( IApplicationView view, IVirtualDesktop desktop ); bool CanViewMoveDesktops( IApplicationView view ); IVirtualDesktop GetCurrentDesktop( IntPtr hWndOrMon ); void GetDesktops( IntPtr hWndOrMon, out IObjectArray desktops ); [PreserveSig] int GetAdjacentDesktop( IVirtualDesktop from, int direction, out IVirtualDesktop desktop ); void SwitchDesktop( IntPtr hWndOrMon, IVirtualDesktop desktop ); IVirtualDesktop CreateDesktop( IntPtr hWndOrMon ); void MoveDesktop( IVirtualDesktop desktop, IntPtr hWndOrMon, int nIndex ); void RemoveDesktop( IVirtualDesktop desktop, IVirtualDesktop fallback ); IVirtualDesktop FindDesktop( ref Guid desktopId ); void GetDesktopSwitchIncludeExcludeViews( IVirtualDesktop desktop, out IObjectArray unknown1, out IObjectArray unknown2 ); #if NET5_0_OR_GREATER void SetName( IVirtualDesktop desktop, IntPtr newName ); void SetWallpaper( IVirtualDesktop desktop, IntPtr path ); #else void SetDesktopName( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string name ); void SetDesktopWallpaper( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string path ); #endif void UpdateWallpaperPathForAllDesktops( [MarshalAs( UnmanagedType.HString )] string path ); void CopyDesktopState( IApplicationView pView0, IApplicationView pView1 ); int GetDesktopIsPerMonitor(); void SetDesktopIsPerMonitor( bool state ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "A5CD92FF-29BE-454C-8D04-D82879FB3F1B" )] internal interface IVirtualDesktopManager { bool IsWindowOnCurrentVirtualDesktop( IntPtr topLevelWindow ); Guid GetWindowDesktopId( IntPtr topLevelWindow ); void MoveWindowToDesktop( IntPtr topLevelWindow, ref Guid desktopId ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "4CE81583-1E4C-4632-A621-07A53543148F" )] internal interface IVirtualDesktopPinnedApps { bool IsAppIdPinned( string appId ); void PinAppID( string appId ); void UnpinAppID( string appId ); bool IsViewPinned( IApplicationView applicationView ); void PinView( IApplicationView applicationView ); void UnpinView( IApplicationView applicationView ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "92CA9DCD-5622-4BBA-A805-5E9F541BD8C9" )] public interface IObjectArray { void GetCount( out int count ); void GetAt( int index, ref Guid iid, [MarshalAs( UnmanagedType.Interface )] out object obj ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "6D5140C1-7436-11CE-8034-00AA006009FA" )] internal interface IServiceProvider10 { [return: MarshalAs( UnmanagedType.IUnknown )] object QueryService( ref Guid service, ref Guid riid ); } [ComImport] [Guid( "cd403e52-deed-4c13-b437-b98380f2b1e8" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotification { void VirtualDesktopCreated( IObjectArray p0, IVirtualDesktop pDesktop ); void VirtualDesktopDestroyBegin( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyFailed( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyed( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void Proc7( int p0 ); void VirtualDesktopMoved( IObjectArray p0, IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo ); #if NET5_0_OR_GREATER void VirtualDesktopRenamed( IVirtualDesktop pDesktop, IntPtr newName ); #else void VirtualDesktopRenamed( IVirtualDesktop pDesktop, [MarshalAs( UnmanagedType.HString )] string chName ); #endif void ViewVirtualDesktopChanged( IApplicationView pView ); void CurrentVirtualDesktopChanged( IObjectArray p0, IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ); #if NET5_0_OR_GREATER void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, IntPtr newPath ); #else void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, [MarshalAs( UnmanagedType.HString )] string chPath ); #endif } [ComImport] [Guid( "0cd45e71-d927-4f15-8b0a-8fef525337bf" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotificationService { uint Register( IVirtualDesktopNotification pNotification ); void Unregister( uint dwCookie ); } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_21H2/VirtualDesktop.cs ================================================ // Author: Markus Scholtes, 2021 // Version 1.9, 2021-10-08 // Version for Windows 10 21H2 and Windows 11 // Compile with: // C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe VirtualDesktop11.cs // Based on http://stackoverflow.com/a/32417530, Windows 10 SDK, github project Grabacr07/VirtualDesktop and own research ///////////////////////////////////////////////// // Dylan Cheng (https://github.com/newlooper) // added Notifications about desktop // added conditional compile for C#/WinRT breaking change on .NET 5.0+ using System; using System.Diagnostics; using System.Runtime.InteropServices; using VirtualSpace; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public class Desktop: IDesktop { private readonly IVirtualDesktop _ivd; private Desktop( IVirtualDesktop desktop ) { _ivd = desktop; } public Guid Guid => _ivd.GetId(); public static int Count => // return the number of desktops DesktopManager.GetDesktopCount(); public static Desktop Current { get { // returns current desktop try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop( IntPtr.Zero ) ); } catch { DesktopManager.ResetDesktopManager(); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop( IntPtr.Zero ) ); } } } public bool IsVisible => // return true if this desktop is the current displayed one ReferenceEquals( _ivd, DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop( IntPtr.Zero ) ); public Desktop Left { // return desktop at the left of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out var desktop ); // 3 = LeftDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } public Desktop Right { // return desktop at the right of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out var desktop ); // 4 = RightDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } // get process id to window handle [DllImport( "user32.dll" )] private static extern int GetWindowThreadProcessId( IntPtr hWnd, out int lpdwProcessId ); // get handle of active window [DllImport( "user32.dll" )] private static extern IntPtr GetForegroundWindow(); public override int GetHashCode() { // get hash return _ivd.GetHashCode(); } public override bool Equals( object? obj ) { // compare with object return obj is Desktop desk && ReferenceEquals( _ivd, desk._ivd ); } public static Desktop FromIndex( int index ) { // return desktop object from index (-> index = 0..Count-1) return new Desktop( DesktopManager.GetDesktop( index ) ); } public static Desktop FromWindow( IntPtr hWnd ) { // return desktop object to desktop on which window is displayed if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var id = DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.FindDesktop( ref id ) ); } public static int SysIndexFromDesktop( Desktop desktop ) { // return index of desktop object or -1 if not found if ( desktop == null ) return -1; return DesktopManager.GetDesktopIndex( desktop._ivd ); } public static string DesktopNameFromDesktop( Desktop desktop ) { // return name of desktop or "Desktop n" if it has no name // get desktop name string desktopName = null; try { #if NET5_0_OR_GREATER desktop._ivd.GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = desktop._ivd.GetName(); #endif } catch ( Exception ) { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( DesktopManager.GetDesktopIndex( desktop._ivd ) + 1 ).ToString(); } return desktopName; } public static string DesktopNameFromIndex( int index ) { // return name of desktop from index (-> index = 0..Count-1) or "Desktop n" if it has no name // get desktop name string desktopName = null; try { #if NET5_0_OR_GREATER DesktopManager.GetDesktop( index ).GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = DesktopManager.GetDesktop( index ).GetName(); #endif } catch { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( index + 1 ).ToString(); } return desktopName; } public static bool HasDesktopNameFromIndex( int index ) { // return true is desktop is named or false if it has no name // read desktop name in registry string desktopName = null; try { #if NET5_0_OR_GREATER DesktopManager.GetDesktop( index ).GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = DesktopManager.GetDesktop( index ).GetName(); #endif } catch { } // name found? if ( string.IsNullOrEmpty( desktopName ) ) return false; else return true; } public static string DesktopWallpaperFromIndex( int index ) { // return name of desktop wallpaper from index (-> index = 0..Count-1) // get desktop name var desktopWpPath = ""; try { desktopWpPath = DesktopManager.GetDesktop( index ).GetWallpaperPath(); } catch { } return desktopWpPath; } public static int SearchDesktop( string partialName ) { // get index of desktop with partial name, return -1 if no desktop found var index = -1; for ( var i = 0; i < DesktopManager.GetDesktopCount(); i++ ) { // loop through all virtual desktops and compare partial name to desktop name if ( DesktopNameFromIndex( i ).ToUpper().IndexOf( partialName.ToUpper() ) >= 0 ) { index = i; break; } } return index; } public static Desktop Create() { // create a new desktop return new Desktop( DesktopManager.VirtualDesktopManagerInternal.CreateDesktop( IntPtr.Zero ) ); } public void Remove( Desktop? fallback = null ) { // destroy desktop and switch to IVirtualDesktop fallbackDesktop; if ( fallback == null ) { // if no fallback is given use desktop to the left except for desktop 0. var dtToCheck = new Desktop( DesktopManager.GetDesktop( 0 ) ); if ( Equals( dtToCheck ) ) { // desktop 0: set fallback to second desktop (= "right" desktop) DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out fallbackDesktop ); // 4 = RightDirection } else { // set fallback to "left" desktop DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out fallbackDesktop ); // 3 = LeftDirection } } else // set fallback desktop fallbackDesktop = fallback._ivd; DesktopManager.VirtualDesktopManagerInternal.RemoveDesktop( _ivd, fallbackDesktop ); } public static void RemoveAll() { // remove all desktops but visible DesktopManager.VirtualDesktopManagerInternal.SetDesktopIsPerMonitor( true ); } public void Move( int index ) { // move current desktop to desktop in index (-> index = 0..Count-1) DesktopManager.VirtualDesktopManagerInternal.MoveDesktop( _ivd, IntPtr.Zero, index ); } public void SetName( string name ) { // set name for desktop, empty string removes name #if NET5_0_OR_GREATER var newName = MarshalString.CreateMarshaler( name ); DesktopManager.VirtualDesktopManagerInternal.SetName( _ivd, MarshalString.GetAbi( newName ) ); #else DesktopManager.VirtualDesktopManagerInternal.SetDesktopName( _ivd, name ); #endif } public void SetWallpaperPath( string path ) { // set path for wallpaper, empty string removes path if ( string.IsNullOrEmpty( path ) ) throw new ArgumentNullException(); #if NET5_0_OR_GREATER var newPath = MarshalString.CreateMarshaler( path ); DesktopManager.VirtualDesktopManagerInternal.SetWallpaper( _ivd, MarshalString.GetAbi( newPath ) ); #else DesktopManager.VirtualDesktopManagerInternal.SetDesktopWallpaper( _ivd, path ); #endif } public static void SetAllWallpaperPaths( string path ) { // set wallpaper path for all desktops if ( string.IsNullOrEmpty( path ) ) throw new ArgumentNullException(); DesktopManager.VirtualDesktopManagerInternal.UpdateWallpaperPathForAllDesktops( path ); } public void MakeVisible() { // make this desktop visible DesktopManager.VirtualDesktopManagerInternal.SwitchDesktop( IntPtr.Zero, _ivd ); } public void MoveWindow( IntPtr hWnd ) { // move window to this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); _ = GetWindowThreadProcessId( hWnd, out var processId ); if ( Process.GetCurrentProcess().Id == processId ) { // window of process try // the easy way (if we are owner) { DesktopManager.VirtualDesktopManager.MoveWindowToDesktop( hWnd, _ivd.GetId() ); } catch // window of process, but we are not the owner { DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } else { // window of other process DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); try { DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } catch { // could not move active window, try main window (or whatever windows thinks is the main window) DesktopManager.ApplicationViewCollection.GetViewForHWnd( Process.GetProcessById( processId ).MainWindowHandle, out view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } } public void MoveActiveWindow() { // move active window to this desktop MoveWindow( GetForegroundWindow() ); } public bool HasWindow( IntPtr hWnd ) { // return true if window is on this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return _ivd.GetId() == DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); } public static bool IsWindowPinned( IntPtr hWnd ) { // return true if window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( hWnd.GetApplicationView() ); } public static void PinWindow( IntPtr hWnd ) { // pin window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( !DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinView( view ); } } public static void UnpinWindow( IntPtr hWnd ) { // unpin window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // unpin only if not already unpinned DesktopManager.VirtualDesktopPinnedApps.UnpinView( view ); } } public static bool IsApplicationPinned( IntPtr hWnd ) { // return true if application for window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( DesktopManager.GetAppId( hWnd ) ); } public static void PinApplication( IntPtr hWnd ) { // pin application for window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var appId = DesktopManager.GetAppId( hWnd ); if ( !DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinAppID( appId ); } } public static void UnpinApplication( IntPtr hWnd ) { // unpin application for window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); var appId = DesktopManager.GetAppId( hWnd ); if ( DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // unpin only if pinned DesktopManager.VirtualDesktopPinnedApps.UnpinAppID( appId ); } } public static Desktop? FromId( Guid guid ) { try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.FindDesktop( ref guid ) ); } catch { return null; } } } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_21H2/VirtualDesktop11_21H2.csproj ================================================ net6.0-windows enable false 9 ================================================ FILE: VirtualDesktop/VirtualDesktop11_21H2/VirtualDesktopManager.cs ================================================ // Author: Markus Scholtes, 2021 // Version 1.9, 2021-10-08 // Version for Windows 10 21H2 and Windows 11 // Compile with: // C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe VirtualDesktop11.cs // Based on http://stackoverflow.com/a/32417530, Windows 10 SDK, github project Grabacr07/VirtualDesktop and own research ///////////////////////////////////////////////// // Dylan Cheng (https://github.com/newlooper) // added Notifications about desktop // added conditional compile for C#/WinRT breaking change on .NET 5.0+ using System; using System.Runtime.InteropServices; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public static class DesktopManager { private static DisposableNotification _disposableNotification; private static IVirtualDesktopNotificationService VirtualDesktopNotificationService; internal static IVirtualDesktopManagerInternal VirtualDesktopManagerInternal; internal static IVirtualDesktopManager VirtualDesktopManager; internal static IVirtualDesktopPinnedApps VirtualDesktopPinnedApps; public static IApplicationViewCollection ApplicationViewCollection; static DesktopManager() { if ( Environment.OSVersion.Version is {Major: 10, Build: >= 22000} ) Init(); } public static void ResetDesktopManager() { Init(); } private static void Init() { var shell = (IServiceProvider10)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_ImmersiveShell ) ); VirtualDesktopManager = (IVirtualDesktopManager)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_VirtualDesktopManager ) ); VirtualDesktopManagerInternal = (IVirtualDesktopManagerInternal)shell.QueryService( Guids.CLSID_VirtualDesktopManagerInternal, typeof( IVirtualDesktopManagerInternal ).GUID ); ApplicationViewCollection = (IApplicationViewCollection)shell.QueryService( typeof( IApplicationViewCollection ).GUID, typeof( IApplicationViewCollection ).GUID ); VirtualDesktopPinnedApps = (IVirtualDesktopPinnedApps)shell.QueryService( Guids.CLSID_VirtualDesktopPinnedApps, typeof( IVirtualDesktopPinnedApps ).GUID ); VirtualDesktopNotificationService = (IVirtualDesktopNotificationService)shell.QueryService( Guids.CLSID_VirtualDesktopNotificationService, typeof( IVirtualDesktopNotificationService ).GUID ); _disposableNotification = new DisposableNotification(); _disposableNotification.DwCookie = VirtualDesktopNotificationService.Register( new EventProxy() ); } public static int GetDesktopCount() { try { return VirtualDesktopManagerInternal.GetCount( IntPtr.Zero ); } catch { ResetDesktopManager(); return VirtualDesktopManagerInternal.GetCount( IntPtr.Zero ); } } public static IVirtualDesktop GetDesktop( int index ) { // get desktop with index var count = GetDesktopCount(); if ( index < 0 || index >= count ) throw new ArgumentOutOfRangeException( nameof( index ) ); VirtualDesktopManagerInternal.GetDesktops( IntPtr.Zero, out var desktops ); desktops.GetAt( index, typeof( IVirtualDesktop ).GUID, out var objDesktop ); Marshal.ReleaseComObject( desktops ); return (IVirtualDesktop)objDesktop; } internal static int GetDesktopIndex( IVirtualDesktop desktop ) { // get index of desktop var count = GetDesktopCount(); var index = -1; var idSearch = desktop.GetId(); VirtualDesktopManagerInternal.GetDesktops( IntPtr.Zero, out var desktops ); for ( var i = 0; i < count; i++ ) { desktops.GetAt( i, typeof( IVirtualDesktop ).GUID, out var objDesktop ); if ( idSearch.CompareTo( ( (IVirtualDesktop)objDesktop ).GetId() ) == 0 ) { index = i; break; } } Marshal.ReleaseComObject( desktops ); return index; } internal static IApplicationView GetApplicationView( this IntPtr hWnd ) { // get application view to window handle ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); return view; } internal static string GetAppId( IntPtr hWnd ) { // get Application ID to window handle hWnd.GetApplicationView().GetAppUserModelId( out var appId ); return appId; } public static int GetViewCount() { ApplicationViewCollection.GetViews( out var objectArray ); objectArray.GetCount( out var count ); Marshal.ReleaseComObject( objectArray ); return count; } public static event EventHandler? Created; public static event EventHandler? DestroyBegin; public static event EventHandler? DestroyFailed; public static event EventHandler? Destroyed; public static event EventHandler? CurrentChanged; public static event EventHandler? Moved; public static event EventHandler? Renamed; public static event EventHandler? WallpaperChanged; private class DisposableNotification : IDisposable { private bool _isDisposed; public uint DwCookie { private get; set; } public void Dispose() { if ( _isDisposed ) return; VirtualDesktopNotificationService.Unregister( DwCookie ); _isDisposed = true; } } private class EventProxy : IVirtualDesktopNotification { public void ViewVirtualDesktopChanged( IApplicationView pView ) { // throw new NotImplementedException(); } public void CurrentVirtualDesktopChanged( IObjectArray p0, IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ) { CurrentChanged?.Invoke( this, new VirtualDesktopChangedEventArgs( pDesktopOld, pDesktopNew ) ); } public void VirtualDesktopCreated( IObjectArray p0, IVirtualDesktop pDesktop ) { Created?.Invoke( this, pDesktop ); } public void VirtualDesktopDestroyBegin( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyBegin?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyFailed( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyFailed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyed( IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { Destroyed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void Proc7( int p0 ) { // throw new NotImplementedException(); } public void VirtualDesktopMoved( IObjectArray p0, IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo ) { Moved?.Invoke( this, new VirtualDesktopMovedEventArgs( pDesktop, nIndexFrom, nIndexTo ) ); } #if NET5_0_OR_GREATER public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, IntPtr newName ) { var name = MarshalString.FromAbi( newName ); Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, name ) ); } #else public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, string chName ) { Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, chName ) ); } #endif #if NET5_0_OR_GREATER public void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, IntPtr newPath ) { var path = MarshalString.FromAbi( newPath ); WallpaperChanged?.Invoke( this, new VirtualDesktopWallpaperChangedEventArgs( pDesktop, path ) ); } #else public void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, string chPath ) { WallpaperChanged?.Invoke( this, new VirtualDesktopWallpaperChangedEventArgs( pDesktop, chPath ) ); } #endif } } public class VirtualDesktopRenamedEventArgs : EventArgs { public VirtualDesktopRenamedEventArgs( IVirtualDesktop desktop, string name ) { Desktop = desktop; Name = name; } public IVirtualDesktop Desktop { get; } public string Name { get; } } public class VirtualDesktopWallpaperChangedEventArgs : EventArgs { public VirtualDesktopWallpaperChangedEventArgs( IVirtualDesktop desktop, string path ) { Desktop = desktop; Path = path; } public IVirtualDesktop Desktop { get; } public string Path { get; } } public class VirtualDesktopChangedEventArgs : EventArgs { public VirtualDesktopChangedEventArgs( IVirtualDesktop oldDesktop, IVirtualDesktop newDesktop ) { OldDesktop = oldDesktop; NewDesktop = newDesktop; } public IVirtualDesktop OldDesktop { get; } public IVirtualDesktop NewDesktop { get; } } public class VirtualDesktopMovedEventArgs : EventArgs { public VirtualDesktopMovedEventArgs( IVirtualDesktop desktop, int oldIndex, int newIndex ) { Desktop = desktop; OldIndex = oldIndex; NewIndex = newIndex; } public IVirtualDesktop Desktop { get; } public int OldIndex { get; } public int NewIndex { get; } } public class VirtualDesktopDestroyEventArgs : EventArgs { public VirtualDesktopDestroyEventArgs( IVirtualDesktop destroyed, IVirtualDesktop fallback ) { Destroyed = destroyed; Fallback = fallback; } public IVirtualDesktop Destroyed { get; } public IVirtualDesktop Fallback { get; } } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_23H2/COM.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Runtime.InteropServices; namespace VirtualDesktop { internal static class Guids { public static readonly Guid CLSID_ImmersiveShell = new( "C2F03A33-21F5-47FA-B4BB-156362A2F239" ); public static readonly Guid CLSID_VirtualDesktopManagerInternal = new( "C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B" ); public static readonly Guid CLSID_VirtualDesktopManager = new( "AA509086-5CA9-4C25-8F95-589D3C07B48A" ); public static readonly Guid CLSID_VirtualDesktopPinnedApps = new( "B5A399E7-1C87-46B8-88E9-FC5747B171BD" ); public static readonly Guid CLSID_VirtualDesktopNotificationService = new( "A501FDEC-4A09-464C-AE4E-1B9C21B84918" ); } [StructLayout( LayoutKind.Sequential )] public struct Size { public int X; public int Y; } [StructLayout( LayoutKind.Sequential )] public struct Rect { public int Left; public int Top; public int Right; public int Bottom; } public enum APPLICATION_VIEW_CLOAK_TYPE : int { AVCT_NONE = 0, AVCT_DEFAULT = 1, AVCT_VIRTUAL_DESKTOP = 2 } public enum APPLICATION_VIEW_COMPATIBILITY_POLICY : int { AVCP_NONE = 0, AVCP_SMALL_SCREEN = 1, AVCP_TABLET_SMALL_SCREEN = 2, AVCP_VERY_SMALL_SCREEN = 3, AVCP_HIGH_SCALE_FACTOR = 4 } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "372E1D3B-38D3-42E4-A15B-8AB2B178F513" )] public interface IApplicationView { void GetIIdsSlot(); void GetRuntimeClassNameSlot(); void GetTrustLevelSlot(); int SetFocus(); int SwitchTo(); int TryInvokeBack( IntPtr /* IAsyncCallback* */ callback ); int GetThumbnailWindow( out IntPtr hWnd ); int GetMonitor( out IntPtr /* IImmersiveMonitor */ immersiveMonitor ); int GetVisibility( out int visibility ); int SetCloak( APPLICATION_VIEW_CLOAK_TYPE cloakType, int unknown ); int GetPosition( ref Guid guid /* GUID for IApplicationViewPosition */, out IntPtr /* IApplicationViewPosition** */ position ); int SetPosition( ref IntPtr /* IApplicationViewPosition* */ position ); int InsertAfterWindow( IntPtr hWnd ); int GetExtendedFramePosition( out Rect rect ); int GetAppUserModelId( [MarshalAs( UnmanagedType.LPWStr )] out string id ); int SetAppUserModelId( string id ); int IsEqualByAppUserModelId( string id, out int result ); int GetViewState( out uint state ); int SetViewState( uint state ); int GetNeediness( out int neediness ); int GetLastActivationTimestamp( out ulong timestamp ); int SetLastActivationTimestamp( ulong timestamp ); int GetVirtualDesktopId( out Guid guid ); int SetVirtualDesktopId( ref Guid guid ); int GetShowInSwitchers( out int flag ); int SetShowInSwitchers( int flag ); int GetScaleFactor( out int factor ); int CanReceiveInput( out bool canReceiveInput ); int GetCompatibilityPolicyType( out APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int SetCompatibilityPolicyType( APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int GetSizeConstraints( IntPtr /* IImmersiveMonitor* */ monitor, out Size size1, out Size size2 ); int GetSizeConstraintsForDpi( uint uint1, out Size size1, out Size size2 ); int SetSizeConstraintsForDpi( ref uint uint1, ref Size size1, ref Size size2 ); int OnMinSizePreferencesUpdated( IntPtr hWnd ); int ApplyOperation( IntPtr /* IApplicationViewOperation* */ operation ); int IsTray( out bool isTray ); int IsInHighZOrderBand( out bool isInHighZOrderBand ); int IsSplashScreenPresented( out bool isSplashScreenPresented ); int Flash(); int GetRootSwitchableOwner( out IApplicationView rootSwitchableOwner ); int EnumerateOwnershipTree( out IObjectArray ownershipTree ); int GetEnterpriseId( [MarshalAs( UnmanagedType.LPWStr )] out string enterpriseId ); int IsMirrored( out bool isMirrored ); int Unknown1( out int unknown ); int Unknown2( out int unknown ); int Unknown3( out int unknown ); int Unknown4( out int unknown ); int Unknown5( out int unknown ); int Unknown6( int unknown ); int Unknown7(); int Unknown8( out int unknown ); int Unknown9( int unknown ); int Unknown10( int unknownX, int unknownY ); int Unknown11( int unknown ); int Unknown12( out Size size1 ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "1841C6D7-4F9D-42C0-AF41-8747538F10E5" )] public interface IApplicationViewCollection { int GetViews( out IObjectArray array ); int GetViewsByZOrder( out IObjectArray array ); int GetViewsByAppUserModelId( string id, out IObjectArray array ); int GetViewForHWnd( IntPtr hWnd, out IApplicationView view ); int GetViewForApplication( object application, out IApplicationView view ); int GetViewForAppUserModelId( string id, out IApplicationView view ); int GetViewInFocus( out IntPtr view ); int Unknown1( out IntPtr view ); void RefreshCollection(); int RegisterForApplicationViewChanges( object listener, out int cookie ); int UnregisterForApplicationViewChanges( int cookie ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "3F07F4BE-B107-441A-AF0F-39D82529072C" )] public interface IVirtualDesktop { bool IsViewVisible( IApplicationView view ); Guid GetId(); #if NET5_0_OR_GREATER public void GetString( out IntPtr hstr ); #else [return: MarshalAs( UnmanagedType.HString )] string GetName(); #endif [return: MarshalAs( UnmanagedType.HString )] string GetWallpaperPath(); bool IsRemote(); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "A3175F2D-239C-4BD2-8AA0-EEBA8B0B138E" )] internal interface IVirtualDesktopManagerInternal { int GetCount(); void MoveViewToDesktop( IApplicationView view, IVirtualDesktop desktop ); bool CanViewMoveDesktops( IApplicationView view ); IVirtualDesktop GetCurrentDesktop(); void GetDesktops( out IObjectArray desktops ); [PreserveSig] int GetAdjacentDesktop( IVirtualDesktop from, int direction, out IVirtualDesktop desktop ); void SwitchDesktop( IVirtualDesktop desktop ); IVirtualDesktop CreateDesktop(); void MoveDesktop( IVirtualDesktop desktop, int nIndex ); void RemoveDesktop( IVirtualDesktop desktop, IVirtualDesktop fallback ); IVirtualDesktop FindDesktop( ref Guid desktopId ); void GetDesktopSwitchIncludeExcludeViews( IVirtualDesktop desktop, out IObjectArray unknown1, out IObjectArray unknown2 ); #if NET5_0_OR_GREATER void SetName( IVirtualDesktop desktop, IntPtr newName ); void SetWallpaper( IVirtualDesktop desktop, IntPtr path ); #else void SetDesktopName( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string name ); void SetDesktopWallpaper( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string path ); #endif void UpdateWallpaperPathForAllDesktops( [MarshalAs( UnmanagedType.HString )] string path ); void CopyDesktopState( IApplicationView pView0, IApplicationView pView1 ); void CreateRemoteDesktop( [MarshalAs( UnmanagedType.HString )] string path, out IVirtualDesktop desktop ); void SwitchRemoteDesktop( IVirtualDesktop desktop ); void SwitchDesktopWithAnimation( IVirtualDesktop desktop ); void GetLastActiveDesktop( out IVirtualDesktop desktop ); void WaitForAnimationToComplete(); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "A5CD92FF-29BE-454C-8D04-D82879FB3F1B" )] internal interface IVirtualDesktopManager { bool IsWindowOnCurrentVirtualDesktop( IntPtr topLevelWindow ); Guid GetWindowDesktopId( IntPtr topLevelWindow ); void MoveWindowToDesktop( IntPtr topLevelWindow, ref Guid desktopId ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "4CE81583-1E4C-4632-A621-07A53543148F" )] internal interface IVirtualDesktopPinnedApps { bool IsAppIdPinned( string appId ); void PinAppID( string appId ); void UnpinAppID( string appId ); bool IsViewPinned( IApplicationView applicationView ); void PinView( IApplicationView applicationView ); void UnpinView( IApplicationView applicationView ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "92CA9DCD-5622-4BBA-A805-5E9F541BD8C9" )] public interface IObjectArray { void GetCount( out int count ); void GetAt( int index, ref Guid iid, [MarshalAs( UnmanagedType.Interface )] out object obj ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "6D5140C1-7436-11CE-8034-00AA006009FA" )] internal interface IServiceProvider10 { [return: MarshalAs( UnmanagedType.IUnknown )] object QueryService( ref Guid service, ref Guid riid ); } [ComImport] [Guid( "B287FA1C-7771-471A-A2DF-9B6B21F0D675" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotification { void VirtualDesktopCreated( IVirtualDesktop pDesktop ); void VirtualDesktopDestroyBegin( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyFailed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopMoved( IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo ); #if NET5_0_OR_GREATER void VirtualDesktopRenamed( IVirtualDesktop pDesktop, IntPtr newName ); #else void VirtualDesktopRenamed( IVirtualDesktop pDesktop, [MarshalAs( UnmanagedType.HString )] string chName ); #endif void ViewVirtualDesktopChanged( IApplicationView pView ); void CurrentVirtualDesktopChanged( IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ); #if NET5_0_OR_GREATER void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, IntPtr newPath ); #else void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, [MarshalAs( UnmanagedType.HString )] string chPath ); #endif void VirtualDesktopSwitched( IVirtualDesktop pDesktop ); void RemoteVirtualDesktopConnected( IVirtualDesktop pDesktop ); } [ComImport] [Guid( "0cd45e71-d927-4f15-8b0a-8fef525337bf" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotificationService { uint Register( IVirtualDesktopNotification pNotification ); void Unregister( uint dwCookie ); } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_23H2/VirtualDesktop.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Diagnostics; using System.Runtime.InteropServices; using VirtualSpace; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public class Desktop : IDesktop { private readonly IVirtualDesktop _ivd; private Desktop( IVirtualDesktop desktop ) { _ivd = desktop; } public Guid Guid => _ivd.GetId(); public static int Count => // return the number of desktops DesktopManager.GetDesktopCount(); public static Desktop Current { get { // returns current desktop try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); } catch { DesktopManager.ResetDesktopManager(); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); } } } public bool IsVisible => // return true if this desktop is the current displayed one ReferenceEquals( _ivd, DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); public Desktop Left { // return desktop at the left of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out var desktop ); // 3 = LeftDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } public Desktop Right { // return desktop at the right of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out var desktop ); // 4 = RightDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } // get process id to window handle [DllImport( "user32.dll" )] private static extern int GetWindowThreadProcessId( IntPtr hWnd, out int lpdwProcessId ); // get handle of active window [DllImport( "user32.dll" )] private static extern IntPtr GetForegroundWindow(); public override int GetHashCode() { // get hash return _ivd.GetHashCode(); } public override bool Equals( object? obj ) { // compare with object return obj is Desktop desk && ReferenceEquals( _ivd, desk._ivd ); } public static Desktop FromIndex( int index ) { // return desktop object from index (-> index = 0..Count-1) return new Desktop( DesktopManager.GetDesktop( index ) ); } public static Desktop FromWindow( IntPtr hWnd ) { // return desktop object to desktop on which window is displayed if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var id = DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.FindDesktop( ref id ) ); } public static int SysIndexFromDesktop( Desktop desktop ) { // return index of desktop object or -1 if not found if ( desktop == null ) return -1; return DesktopManager.GetDesktopIndex( desktop._ivd ); } public static string DesktopNameFromDesktop( Desktop desktop ) { // return name of desktop or "Desktop n" if it has no name // get desktop name string desktopName = null; try { #if NET5_0_OR_GREATER desktop._ivd.GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = desktop._ivd.GetName(); #endif } catch ( Exception ) { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( DesktopManager.GetDesktopIndex( desktop._ivd ) + 1 ).ToString(); } return desktopName; } public static string DesktopNameFromIndex( int index ) { // return name of desktop from index (-> index = 0..Count-1) or "Desktop n" if it has no name // get desktop name string desktopName = null; try { #if NET5_0_OR_GREATER DesktopManager.GetDesktop( index ).GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = DesktopManager.GetDesktop( index ).GetName(); #endif } catch { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( index + 1 ).ToString(); } return desktopName; } public static bool HasDesktopNameFromIndex( int index ) { // return true is desktop is named or false if it has no name // read desktop name in registry string desktopName = null; try { #if NET5_0_OR_GREATER DesktopManager.GetDesktop( index ).GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = DesktopManager.GetDesktop( index ).GetName(); #endif } catch { } // name found? if ( string.IsNullOrEmpty( desktopName ) ) return false; else return true; } public static string DesktopWallpaperFromIndex( int index ) { // return name of desktop wallpaper from index (-> index = 0..Count-1) // get desktop name var desktopWpPath = ""; try { desktopWpPath = DesktopManager.GetDesktop( index ).GetWallpaperPath(); } catch { } return desktopWpPath; } public static int SearchDesktop( string partialName ) { // get index of desktop with partial name, return -1 if no desktop found var index = -1; for ( var i = 0; i < DesktopManager.GetDesktopCount(); i++ ) { // loop through all virtual desktops and compare partial name to desktop name if ( DesktopNameFromIndex( i ).ToUpper().IndexOf( partialName.ToUpper() ) >= 0 ) { index = i; break; } } return index; } public static Desktop Create() { // create a new desktop return new Desktop( DesktopManager.VirtualDesktopManagerInternal.CreateDesktop() ); } public void Remove( Desktop? fallback = null ) { // destroy desktop and switch to IVirtualDesktop fallbackDesktop; if ( fallback == null ) { // if no fallback is given use desktop to the left except for desktop 0. var dtToCheck = new Desktop( DesktopManager.GetDesktop( 0 ) ); if ( Equals( dtToCheck ) ) { // desktop 0: set fallback to second desktop (= "right" desktop) DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out fallbackDesktop ); // 4 = RightDirection } else { // set fallback to "left" desktop DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out fallbackDesktop ); // 3 = LeftDirection } } else // set fallback desktop fallbackDesktop = fallback._ivd; DesktopManager.VirtualDesktopManagerInternal.RemoveDesktop( _ivd, fallbackDesktop ); } public static void RemoveAll() { // remove all desktops but visible // DesktopManager.VirtualDesktopManagerInternal.SetDesktopIsPerMonitor( true ); } public void Move( int index ) { // move current desktop to desktop in index (-> index = 0..Count-1) DesktopManager.VirtualDesktopManagerInternal.MoveDesktop( _ivd, index ); } public void SetName( string name ) { // set name for desktop, empty string removes name #if NET5_0_OR_GREATER var newName = MarshalString.CreateMarshaler( name ); DesktopManager.VirtualDesktopManagerInternal.SetName( _ivd, MarshalString.GetAbi( newName ) ); #else DesktopManager.VirtualDesktopManagerInternal.SetDesktopName( _ivd, name ); #endif } public void SetWallpaperPath( string path ) { // set path for wallpaper, empty string removes path if ( string.IsNullOrEmpty( path ) ) throw new ArgumentNullException(); #if NET5_0_OR_GREATER var newPath = MarshalString.CreateMarshaler( path ); DesktopManager.VirtualDesktopManagerInternal.SetWallpaper( _ivd, MarshalString.GetAbi( newPath ) ); #else DesktopManager.VirtualDesktopManagerInternal.SetDesktopWallpaper( _ivd, path ); #endif } public static void SetAllWallpaperPaths( string path ) { // set wallpaper path for all desktops if ( string.IsNullOrEmpty( path ) ) throw new ArgumentNullException(); DesktopManager.VirtualDesktopManagerInternal.UpdateWallpaperPathForAllDesktops( path ); } public void MakeVisible() { // make this desktop visible DesktopManager.VirtualDesktopManagerInternal.SwitchDesktop( _ivd ); } public void MoveWindow( IntPtr hWnd ) { // move window to this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); _ = GetWindowThreadProcessId( hWnd, out var processId ); if ( Process.GetCurrentProcess().Id == processId ) { // window of process try // the easy way (if we are owner) { DesktopManager.VirtualDesktopManager.MoveWindowToDesktop( hWnd, _ivd.GetId() ); } catch // window of process, but we are not the owner { DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } else { // window of other process DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); try { DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } catch { // could not move active window, try main window (or whatever windows thinks is the main window) DesktopManager.ApplicationViewCollection.GetViewForHWnd( Process.GetProcessById( processId ).MainWindowHandle, out view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } } public void MoveActiveWindow() { // move active window to this desktop MoveWindow( GetForegroundWindow() ); } public bool HasWindow( IntPtr hWnd ) { // return true if window is on this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return _ivd.GetId() == DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); } public static bool IsWindowPinned( IntPtr hWnd ) { // return true if window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( hWnd.GetApplicationView() ); } public static void PinWindow( IntPtr hWnd ) { // pin window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( !DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinView( view ); } } public static void UnpinWindow( IntPtr hWnd ) { // unpin window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // unpin only if not already unpinned DesktopManager.VirtualDesktopPinnedApps.UnpinView( view ); } } public static bool IsApplicationPinned( IntPtr hWnd ) { // return true if application for window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( DesktopManager.GetAppId( hWnd ) ); } public static void PinApplication( IntPtr hWnd ) { // pin application for window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var appId = DesktopManager.GetAppId( hWnd ); if ( !DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinAppID( appId ); } } public static void UnpinApplication( IntPtr hWnd ) { // unpin application for window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); var appId = DesktopManager.GetAppId( hWnd ); if ( DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // unpin only if pinned DesktopManager.VirtualDesktopPinnedApps.UnpinAppID( appId ); } } public static Desktop? FromId( Guid guid ) { try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.FindDesktop( ref guid ) ); } catch { return null; } } } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_23H2/VirtualDesktop11_23H2.csproj ================================================ net6.0-windows enable false 9 ================================================ FILE: VirtualDesktop/VirtualDesktop11_23H2/VirtualDesktopManager.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Runtime.InteropServices; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public static class DesktopManager { private static DisposableNotification _disposableNotification; private static IVirtualDesktopNotificationService VirtualDesktopNotificationService; internal static IVirtualDesktopManagerInternal VirtualDesktopManagerInternal; internal static IVirtualDesktopManager VirtualDesktopManager; internal static IVirtualDesktopPinnedApps VirtualDesktopPinnedApps; public static IApplicationViewCollection ApplicationViewCollection; static DesktopManager() { if ( Environment.OSVersion.Version is {Major: 10, Build: >= 22000} ) Init(); } public static void ResetDesktopManager() { Init(); } private static void Init() { var shell = (IServiceProvider10)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_ImmersiveShell ) ); VirtualDesktopManager = (IVirtualDesktopManager)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_VirtualDesktopManager ) ); VirtualDesktopManagerInternal = (IVirtualDesktopManagerInternal)shell.QueryService( Guids.CLSID_VirtualDesktopManagerInternal, typeof( IVirtualDesktopManagerInternal ).GUID ); ApplicationViewCollection = (IApplicationViewCollection)shell.QueryService( typeof( IApplicationViewCollection ).GUID, typeof( IApplicationViewCollection ).GUID ); VirtualDesktopPinnedApps = (IVirtualDesktopPinnedApps)shell.QueryService( Guids.CLSID_VirtualDesktopPinnedApps, typeof( IVirtualDesktopPinnedApps ).GUID ); VirtualDesktopNotificationService = (IVirtualDesktopNotificationService)shell.QueryService( Guids.CLSID_VirtualDesktopNotificationService, typeof( IVirtualDesktopNotificationService ).GUID ); _disposableNotification = new DisposableNotification(); _disposableNotification.DwCookie = VirtualDesktopNotificationService.Register( new EventProxy() ); } public static int GetDesktopCount() { try { return VirtualDesktopManagerInternal.GetCount(); } catch { ResetDesktopManager(); return VirtualDesktopManagerInternal.GetCount(); } } public static IVirtualDesktop GetDesktop( int index ) { // get desktop with index var count = GetDesktopCount(); if ( index < 0 || index >= count ) throw new ArgumentOutOfRangeException( nameof( index ) ); VirtualDesktopManagerInternal.GetDesktops( out var desktops ); desktops.GetAt( index, typeof( IVirtualDesktop ).GUID, out var objDesktop ); Marshal.ReleaseComObject( desktops ); return (IVirtualDesktop)objDesktop; } internal static int GetDesktopIndex( IVirtualDesktop desktop ) { // get index of desktop var count = GetDesktopCount(); var index = -1; var idSearch = desktop.GetId(); VirtualDesktopManagerInternal.GetDesktops( out var desktops ); for ( var i = 0; i < count; i++ ) { desktops.GetAt( i, typeof( IVirtualDesktop ).GUID, out var objDesktop ); if ( idSearch.CompareTo( ( (IVirtualDesktop)objDesktop ).GetId() ) == 0 ) { index = i; break; } } Marshal.ReleaseComObject( desktops ); return index; } internal static IApplicationView GetApplicationView( this IntPtr hWnd ) { // get application view to window handle ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); return view; } internal static string GetAppId( IntPtr hWnd ) { // get Application ID to window handle hWnd.GetApplicationView().GetAppUserModelId( out var appId ); return appId; } public static int GetViewCount() { ApplicationViewCollection.GetViews( out var objectArray ); objectArray.GetCount( out var count ); Marshal.ReleaseComObject( objectArray ); return count; } public static event EventHandler? Created; public static event EventHandler? DestroyBegin; public static event EventHandler? DestroyFailed; public static event EventHandler? Destroyed; public static event EventHandler? CurrentChanged; public static event EventHandler? Moved; public static event EventHandler? Renamed; public static event EventHandler? WallpaperChanged; private class DisposableNotification : IDisposable { private bool _isDisposed; public uint DwCookie { private get; set; } public void Dispose() { if ( _isDisposed ) return; VirtualDesktopNotificationService.Unregister( DwCookie ); _isDisposed = true; } } private class EventProxy : IVirtualDesktopNotification { public void ViewVirtualDesktopChanged( IApplicationView pView ) { // throw new NotImplementedException(); } public void CurrentVirtualDesktopChanged( IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ) { CurrentChanged?.Invoke( this, new VirtualDesktopChangedEventArgs( pDesktopOld, pDesktopNew ) ); } public void VirtualDesktopCreated( IVirtualDesktop pDesktop ) { Created?.Invoke( this, pDesktop ); } public void VirtualDesktopDestroyBegin( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyBegin?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyFailed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyFailed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { Destroyed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopMoved( IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo ) { Moved?.Invoke( this, new VirtualDesktopMovedEventArgs( pDesktop, nIndexFrom, nIndexTo ) ); } #if NET5_0_OR_GREATER public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, IntPtr newName ) { var name = MarshalString.FromAbi( newName ); Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, name ) ); } #else public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, string chName ) { Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, chName ) ); } #endif #if NET5_0_OR_GREATER public void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, IntPtr newPath ) { var path = MarshalString.FromAbi( newPath ); WallpaperChanged?.Invoke( this, new VirtualDesktopWallpaperChangedEventArgs( pDesktop, path ) ); } #else public void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, string chPath ) { WallpaperChanged?.Invoke( this, new VirtualDesktopWallpaperChangedEventArgs( pDesktop, chPath ) ); } #endif public void VirtualDesktopSwitched( IVirtualDesktop pDesktop ) { // throw new NotImplementedException(); } public void RemoteVirtualDesktopConnected( IVirtualDesktop pDesktop ) { // throw new NotImplementedException(); } } } public class VirtualDesktopRenamedEventArgs : EventArgs { public VirtualDesktopRenamedEventArgs( IVirtualDesktop desktop, string name ) { Desktop = desktop; Name = name; } public IVirtualDesktop Desktop { get; } public string Name { get; } } public class VirtualDesktopWallpaperChangedEventArgs : EventArgs { public VirtualDesktopWallpaperChangedEventArgs( IVirtualDesktop desktop, string path ) { Desktop = desktop; Path = path; } public IVirtualDesktop Desktop { get; } public string Path { get; } } public class VirtualDesktopChangedEventArgs : EventArgs { public VirtualDesktopChangedEventArgs( IVirtualDesktop oldDesktop, IVirtualDesktop newDesktop ) { OldDesktop = oldDesktop; NewDesktop = newDesktop; } public IVirtualDesktop OldDesktop { get; } public IVirtualDesktop NewDesktop { get; } } public class VirtualDesktopMovedEventArgs : EventArgs { public VirtualDesktopMovedEventArgs( IVirtualDesktop desktop, int oldIndex, int newIndex ) { Desktop = desktop; OldIndex = oldIndex; NewIndex = newIndex; } public IVirtualDesktop Desktop { get; } public int OldIndex { get; } public int NewIndex { get; } } public class VirtualDesktopDestroyEventArgs : EventArgs { public VirtualDesktopDestroyEventArgs( IVirtualDesktop destroyed, IVirtualDesktop fallback ) { Destroyed = destroyed; Fallback = fallback; } public IVirtualDesktop Destroyed { get; } public IVirtualDesktop Fallback { get; } } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_23H2_3085/COM.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Runtime.InteropServices; namespace VirtualDesktop { internal static class Guids { public static readonly Guid CLSID_ImmersiveShell = new( "C2F03A33-21F5-47FA-B4BB-156362A2F239" ); public static readonly Guid CLSID_VirtualDesktopManagerInternal = new( "C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B" ); public static readonly Guid CLSID_VirtualDesktopManager = new( "AA509086-5CA9-4C25-8F95-589D3C07B48A" ); public static readonly Guid CLSID_VirtualDesktopPinnedApps = new( "B5A399E7-1C87-46B8-88E9-FC5747B171BD" ); public static readonly Guid CLSID_VirtualDesktopNotificationService = new( "A501FDEC-4A09-464C-AE4E-1B9C21B84918" ); } [StructLayout( LayoutKind.Sequential )] public struct Size { public int X; public int Y; } [StructLayout( LayoutKind.Sequential )] public struct Rect { public int Left; public int Top; public int Right; public int Bottom; } public enum APPLICATION_VIEW_CLOAK_TYPE : int { AVCT_NONE = 0, AVCT_DEFAULT = 1, AVCT_VIRTUAL_DESKTOP = 2 } public enum APPLICATION_VIEW_COMPATIBILITY_POLICY : int { AVCP_NONE = 0, AVCP_SMALL_SCREEN = 1, AVCP_TABLET_SMALL_SCREEN = 2, AVCP_VERY_SMALL_SCREEN = 3, AVCP_HIGH_SCALE_FACTOR = 4 } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "372E1D3B-38D3-42E4-A15B-8AB2B178F513" )] public interface IApplicationView { void GetIIdsSlot(); void GetRuntimeClassNameSlot(); void GetTrustLevelSlot(); int SetFocus(); int SwitchTo(); int TryInvokeBack( IntPtr /* IAsyncCallback* */ callback ); int GetThumbnailWindow( out IntPtr hWnd ); int GetMonitor( out IntPtr /* IImmersiveMonitor */ immersiveMonitor ); int GetVisibility( out int visibility ); int SetCloak( APPLICATION_VIEW_CLOAK_TYPE cloakType, int unknown ); int GetPosition( ref Guid guid /* GUID for IApplicationViewPosition */, out IntPtr /* IApplicationViewPosition** */ position ); int SetPosition( ref IntPtr /* IApplicationViewPosition* */ position ); int InsertAfterWindow( IntPtr hWnd ); int GetExtendedFramePosition( out Rect rect ); int GetAppUserModelId( [MarshalAs( UnmanagedType.LPWStr )] out string id ); int SetAppUserModelId( string id ); int IsEqualByAppUserModelId( string id, out int result ); int GetViewState( out uint state ); int SetViewState( uint state ); int GetNeediness( out int neediness ); int GetLastActivationTimestamp( out ulong timestamp ); int SetLastActivationTimestamp( ulong timestamp ); int GetVirtualDesktopId( out Guid guid ); int SetVirtualDesktopId( ref Guid guid ); int GetShowInSwitchers( out int flag ); int SetShowInSwitchers( int flag ); int GetScaleFactor( out int factor ); int CanReceiveInput( out bool canReceiveInput ); int GetCompatibilityPolicyType( out APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int SetCompatibilityPolicyType( APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int GetSizeConstraints( IntPtr /* IImmersiveMonitor* */ monitor, out Size size1, out Size size2 ); int GetSizeConstraintsForDpi( uint uint1, out Size size1, out Size size2 ); int SetSizeConstraintsForDpi( ref uint uint1, ref Size size1, ref Size size2 ); int OnMinSizePreferencesUpdated( IntPtr hWnd ); int ApplyOperation( IntPtr /* IApplicationViewOperation* */ operation ); int IsTray( out bool isTray ); int IsInHighZOrderBand( out bool isInHighZOrderBand ); int IsSplashScreenPresented( out bool isSplashScreenPresented ); int Flash(); int GetRootSwitchableOwner( out IApplicationView rootSwitchableOwner ); int EnumerateOwnershipTree( out IObjectArray ownershipTree ); int GetEnterpriseId( [MarshalAs( UnmanagedType.LPWStr )] out string enterpriseId ); int IsMirrored( out bool isMirrored ); int Unknown1( out int unknown ); int Unknown2( out int unknown ); int Unknown3( out int unknown ); int Unknown4( out int unknown ); int Unknown5( out int unknown ); int Unknown6( int unknown ); int Unknown7(); int Unknown8( out int unknown ); int Unknown9( int unknown ); int Unknown10( int unknownX, int unknownY ); int Unknown11( int unknown ); int Unknown12( out Size size1 ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "1841C6D7-4F9D-42C0-AF41-8747538F10E5" )] public interface IApplicationViewCollection { int GetViews( out IObjectArray array ); int GetViewsByZOrder( out IObjectArray array ); int GetViewsByAppUserModelId( string id, out IObjectArray array ); int GetViewForHWnd( IntPtr hWnd, out IApplicationView view ); int GetViewForApplication( object application, out IApplicationView view ); int GetViewForAppUserModelId( string id, out IApplicationView view ); int GetViewInFocus( out IntPtr view ); int Unknown1( out IntPtr view ); void RefreshCollection(); int RegisterForApplicationViewChanges( object listener, out int cookie ); int UnregisterForApplicationViewChanges( int cookie ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "3F07F4BE-B107-441A-AF0F-39D82529072C" )] public interface IVirtualDesktop { bool IsViewVisible( IApplicationView view ); Guid GetId(); #if NET5_0_OR_GREATER public void GetString( out IntPtr hstr ); #else [return: MarshalAs( UnmanagedType.HString )] string GetName(); #endif [return: MarshalAs( UnmanagedType.HString )] string GetWallpaperPath(); bool IsRemote(); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "53F5CA0B-158F-4124-900C-057158060B27" )] internal interface IVirtualDesktopManagerInternal { int GetCount(); void MoveViewToDesktop( IApplicationView view, IVirtualDesktop desktop ); bool CanViewMoveDesktops( IApplicationView view ); IVirtualDesktop GetCurrentDesktop(); void GetDesktops( out IObjectArray desktops ); [PreserveSig] int GetAdjacentDesktop( IVirtualDesktop from, int direction, out IVirtualDesktop desktop ); void SwitchDesktop( IVirtualDesktop desktop ); IVirtualDesktop CreateDesktop(); void MoveDesktop( IVirtualDesktop desktop, int nIndex ); void RemoveDesktop( IVirtualDesktop desktop, IVirtualDesktop fallback ); IVirtualDesktop FindDesktop( ref Guid desktopId ); void GetDesktopSwitchIncludeExcludeViews( IVirtualDesktop desktop, out IObjectArray unknown1, out IObjectArray unknown2 ); #if NET5_0_OR_GREATER void SetName( IVirtualDesktop desktop, IntPtr newName ); void SetWallpaper( IVirtualDesktop desktop, IntPtr path ); #else void SetDesktopName( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string name ); void SetDesktopWallpaper( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string path ); #endif void UpdateWallpaperPathForAllDesktops( [MarshalAs( UnmanagedType.HString )] string path ); void CopyDesktopState( IApplicationView pView0, IApplicationView pView1 ); void CreateRemoteDesktop( [MarshalAs( UnmanagedType.HString )] string path, out IVirtualDesktop desktop ); void SwitchRemoteDesktop( IVirtualDesktop desktop ); void SwitchDesktopWithAnimation( IVirtualDesktop desktop ); void GetLastActiveDesktop( out IVirtualDesktop desktop ); void WaitForAnimationToComplete(); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "A5CD92FF-29BE-454C-8D04-D82879FB3F1B" )] internal interface IVirtualDesktopManager { bool IsWindowOnCurrentVirtualDesktop( IntPtr topLevelWindow ); Guid GetWindowDesktopId( IntPtr topLevelWindow ); void MoveWindowToDesktop( IntPtr topLevelWindow, ref Guid desktopId ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "4CE81583-1E4C-4632-A621-07A53543148F" )] internal interface IVirtualDesktopPinnedApps { bool IsAppIdPinned( string appId ); void PinAppID( string appId ); void UnpinAppID( string appId ); bool IsViewPinned( IApplicationView applicationView ); void PinView( IApplicationView applicationView ); void UnpinView( IApplicationView applicationView ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "92CA9DCD-5622-4BBA-A805-5E9F541BD8C9" )] public interface IObjectArray { void GetCount( out int count ); void GetAt( int index, ref Guid iid, [MarshalAs( UnmanagedType.Interface )] out object obj ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "6D5140C1-7436-11CE-8034-00AA006009FA" )] internal interface IServiceProvider10 { [return: MarshalAs( UnmanagedType.IUnknown )] object QueryService( ref Guid service, ref Guid riid ); } [ComImport] [Guid( "B9E5E94D-233E-49AB-AF5C-2B4541C3AADE" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotification { void VirtualDesktopCreated( IVirtualDesktop pDesktop ); void VirtualDesktopDestroyBegin( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyFailed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopMoved( IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo ); #if NET5_0_OR_GREATER void VirtualDesktopRenamed( IVirtualDesktop pDesktop, IntPtr newName ); #else void VirtualDesktopRenamed( IVirtualDesktop pDesktop, [MarshalAs( UnmanagedType.HString )] string chName ); #endif void ViewVirtualDesktopChanged( IApplicationView pView ); void CurrentVirtualDesktopChanged( IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ); #if NET5_0_OR_GREATER void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, IntPtr newPath ); #else void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, [MarshalAs( UnmanagedType.HString )] string chPath ); #endif void VirtualDesktopSwitched( IVirtualDesktop pDesktop ); void RemoteVirtualDesktopConnected( IVirtualDesktop pDesktop ); } [ComImport] [Guid( "0cd45e71-d927-4f15-8b0a-8fef525337bf" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotificationService { uint Register( IVirtualDesktopNotification pNotification ); void Unregister( uint dwCookie ); } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_23H2_3085/VirtualDesktop.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Diagnostics; using System.Runtime.InteropServices; using VirtualSpace; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public class Desktop : IDesktop { private readonly IVirtualDesktop _ivd; private Desktop( IVirtualDesktop desktop ) { _ivd = desktop; } public Guid Guid => _ivd.GetId(); public static int Count => // return the number of desktops DesktopManager.GetDesktopCount(); public static Desktop Current { get { // returns current desktop try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); } catch { DesktopManager.ResetDesktopManager(); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); } } } public bool IsVisible => // return true if this desktop is the current displayed one ReferenceEquals( _ivd, DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); public Desktop Left { // return desktop at the left of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out var desktop ); // 3 = LeftDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } public Desktop Right { // return desktop at the right of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out var desktop ); // 4 = RightDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } // get process id to window handle [DllImport( "user32.dll" )] private static extern int GetWindowThreadProcessId( IntPtr hWnd, out int lpdwProcessId ); // get handle of active window [DllImport( "user32.dll" )] private static extern IntPtr GetForegroundWindow(); public override int GetHashCode() { // get hash return _ivd.GetHashCode(); } public override bool Equals( object? obj ) { // compare with object return obj is Desktop desk && ReferenceEquals( _ivd, desk._ivd ); } public static Desktop FromIndex( int index ) { // return desktop object from index (-> index = 0..Count-1) return new Desktop( DesktopManager.GetDesktop( index ) ); } public static Desktop FromWindow( IntPtr hWnd ) { // return desktop object to desktop on which window is displayed if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var id = DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.FindDesktop( ref id ) ); } public static int SysIndexFromDesktop( Desktop desktop ) { // return index of desktop object or -1 if not found if ( desktop == null ) return -1; return DesktopManager.GetDesktopIndex( desktop._ivd ); } public static string DesktopNameFromDesktop( Desktop desktop ) { // return name of desktop or "Desktop n" if it has no name // get desktop name string desktopName = null; try { #if NET5_0_OR_GREATER desktop._ivd.GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = desktop._ivd.GetName(); #endif } catch ( Exception ) { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( DesktopManager.GetDesktopIndex( desktop._ivd ) + 1 ).ToString(); } return desktopName; } public static string DesktopNameFromIndex( int index ) { // return name of desktop from index (-> index = 0..Count-1) or "Desktop n" if it has no name // get desktop name string desktopName = null; try { #if NET5_0_OR_GREATER DesktopManager.GetDesktop( index ).GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = DesktopManager.GetDesktop( index ).GetName(); #endif } catch { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( index + 1 ).ToString(); } return desktopName; } public static bool HasDesktopNameFromIndex( int index ) { // return true is desktop is named or false if it has no name // read desktop name in registry string desktopName = null; try { #if NET5_0_OR_GREATER DesktopManager.GetDesktop( index ).GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = DesktopManager.GetDesktop( index ).GetName(); #endif } catch { } // name found? if ( string.IsNullOrEmpty( desktopName ) ) return false; else return true; } public static string DesktopWallpaperFromIndex( int index ) { // return name of desktop wallpaper from index (-> index = 0..Count-1) // get desktop name var desktopWpPath = ""; try { desktopWpPath = DesktopManager.GetDesktop( index ).GetWallpaperPath(); } catch { } return desktopWpPath; } public static int SearchDesktop( string partialName ) { // get index of desktop with partial name, return -1 if no desktop found var index = -1; for ( var i = 0; i < DesktopManager.GetDesktopCount(); i++ ) { // loop through all virtual desktops and compare partial name to desktop name if ( DesktopNameFromIndex( i ).ToUpper().IndexOf( partialName.ToUpper() ) >= 0 ) { index = i; break; } } return index; } public static Desktop Create() { // create a new desktop return new Desktop( DesktopManager.VirtualDesktopManagerInternal.CreateDesktop() ); } public void Remove( Desktop? fallback = null ) { // destroy desktop and switch to IVirtualDesktop fallbackDesktop; if ( fallback == null ) { // if no fallback is given use desktop to the left except for desktop 0. var dtToCheck = new Desktop( DesktopManager.GetDesktop( 0 ) ); if ( Equals( dtToCheck ) ) { // desktop 0: set fallback to second desktop (= "right" desktop) DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out fallbackDesktop ); // 4 = RightDirection } else { // set fallback to "left" desktop DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out fallbackDesktop ); // 3 = LeftDirection } } else // set fallback desktop fallbackDesktop = fallback._ivd; DesktopManager.VirtualDesktopManagerInternal.RemoveDesktop( _ivd, fallbackDesktop ); } public static void RemoveAll() { // remove all desktops but visible // DesktopManager.VirtualDesktopManagerInternal.SetDesktopIsPerMonitor( true ); } public void Move( int index ) { // move current desktop to desktop in index (-> index = 0..Count-1) DesktopManager.VirtualDesktopManagerInternal.MoveDesktop( _ivd, index ); } public void SetName( string name ) { // set name for desktop, empty string removes name #if NET5_0_OR_GREATER var newName = MarshalString.CreateMarshaler( name ); DesktopManager.VirtualDesktopManagerInternal.SetName( _ivd, MarshalString.GetAbi( newName ) ); #else DesktopManager.VirtualDesktopManagerInternal.SetDesktopName( _ivd, name ); #endif } public void SetWallpaperPath( string path ) { // set path for wallpaper, empty string removes path if ( string.IsNullOrEmpty( path ) ) throw new ArgumentNullException(); #if NET5_0_OR_GREATER var newPath = MarshalString.CreateMarshaler( path ); DesktopManager.VirtualDesktopManagerInternal.SetWallpaper( _ivd, MarshalString.GetAbi( newPath ) ); #else DesktopManager.VirtualDesktopManagerInternal.SetDesktopWallpaper( _ivd, path ); #endif } public static void SetAllWallpaperPaths( string path ) { // set wallpaper path for all desktops if ( string.IsNullOrEmpty( path ) ) throw new ArgumentNullException(); DesktopManager.VirtualDesktopManagerInternal.UpdateWallpaperPathForAllDesktops( path ); } public void MakeVisible() { // make this desktop visible DesktopManager.VirtualDesktopManagerInternal.SwitchDesktop( _ivd ); } public void MoveWindow( IntPtr hWnd ) { // move window to this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); _ = GetWindowThreadProcessId( hWnd, out var processId ); if ( Process.GetCurrentProcess().Id == processId ) { // window of process try // the easy way (if we are owner) { DesktopManager.VirtualDesktopManager.MoveWindowToDesktop( hWnd, _ivd.GetId() ); } catch // window of process, but we are not the owner { DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } else { // window of other process DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); try { DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } catch { // could not move active window, try main window (or whatever windows thinks is the main window) DesktopManager.ApplicationViewCollection.GetViewForHWnd( Process.GetProcessById( processId ).MainWindowHandle, out view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } } public void MoveActiveWindow() { // move active window to this desktop MoveWindow( GetForegroundWindow() ); } public bool HasWindow( IntPtr hWnd ) { // return true if window is on this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return _ivd.GetId() == DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); } public static bool IsWindowPinned( IntPtr hWnd ) { // return true if window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( hWnd.GetApplicationView() ); } public static void PinWindow( IntPtr hWnd ) { // pin window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( !DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinView( view ); } } public static void UnpinWindow( IntPtr hWnd ) { // unpin window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // unpin only if not already unpinned DesktopManager.VirtualDesktopPinnedApps.UnpinView( view ); } } public static bool IsApplicationPinned( IntPtr hWnd ) { // return true if application for window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( DesktopManager.GetAppId( hWnd ) ); } public static void PinApplication( IntPtr hWnd ) { // pin application for window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var appId = DesktopManager.GetAppId( hWnd ); if ( !DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinAppID( appId ); } } public static void UnpinApplication( IntPtr hWnd ) { // unpin application for window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); var appId = DesktopManager.GetAppId( hWnd ); if ( DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // unpin only if pinned DesktopManager.VirtualDesktopPinnedApps.UnpinAppID( appId ); } } public static Desktop? FromId( Guid guid ) { try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.FindDesktop( ref guid ) ); } catch { return null; } } } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_23H2_3085/VirtualDesktop11_23H2_3085.csproj ================================================ net6.0-windows enable false 9 ================================================ FILE: VirtualDesktop/VirtualDesktop11_23H2_3085/VirtualDesktopManager.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Runtime.InteropServices; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public static class DesktopManager { private static DisposableNotification _disposableNotification; private static IVirtualDesktopNotificationService VirtualDesktopNotificationService; internal static IVirtualDesktopManagerInternal VirtualDesktopManagerInternal; internal static IVirtualDesktopManager VirtualDesktopManager; internal static IVirtualDesktopPinnedApps VirtualDesktopPinnedApps; public static IApplicationViewCollection ApplicationViewCollection; static DesktopManager() { if ( Environment.OSVersion.Version is {Major: 10, Build: >= 22000} ) Init(); } public static void ResetDesktopManager() { Init(); } private static void Init() { var shell = (IServiceProvider10)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_ImmersiveShell ) ); VirtualDesktopManager = (IVirtualDesktopManager)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_VirtualDesktopManager ) ); VirtualDesktopManagerInternal = (IVirtualDesktopManagerInternal)shell.QueryService( Guids.CLSID_VirtualDesktopManagerInternal, typeof( IVirtualDesktopManagerInternal ).GUID ); ApplicationViewCollection = (IApplicationViewCollection)shell.QueryService( typeof( IApplicationViewCollection ).GUID, typeof( IApplicationViewCollection ).GUID ); VirtualDesktopPinnedApps = (IVirtualDesktopPinnedApps)shell.QueryService( Guids.CLSID_VirtualDesktopPinnedApps, typeof( IVirtualDesktopPinnedApps ).GUID ); VirtualDesktopNotificationService = (IVirtualDesktopNotificationService)shell.QueryService( Guids.CLSID_VirtualDesktopNotificationService, typeof( IVirtualDesktopNotificationService ).GUID ); _disposableNotification = new DisposableNotification(); _disposableNotification.DwCookie = VirtualDesktopNotificationService.Register( new EventProxy() ); } public static int GetDesktopCount() { try { return VirtualDesktopManagerInternal.GetCount(); } catch { ResetDesktopManager(); return VirtualDesktopManagerInternal.GetCount(); } } public static IVirtualDesktop GetDesktop( int index ) { // get desktop with index var count = GetDesktopCount(); if ( index < 0 || index >= count ) throw new ArgumentOutOfRangeException( nameof( index ) ); VirtualDesktopManagerInternal.GetDesktops( out var desktops ); desktops.GetAt( index, typeof( IVirtualDesktop ).GUID, out var objDesktop ); Marshal.ReleaseComObject( desktops ); return (IVirtualDesktop)objDesktop; } internal static int GetDesktopIndex( IVirtualDesktop desktop ) { // get index of desktop var count = GetDesktopCount(); var index = -1; var idSearch = desktop.GetId(); VirtualDesktopManagerInternal.GetDesktops( out var desktops ); for ( var i = 0; i < count; i++ ) { desktops.GetAt( i, typeof( IVirtualDesktop ).GUID, out var objDesktop ); if ( idSearch.CompareTo( ( (IVirtualDesktop)objDesktop ).GetId() ) == 0 ) { index = i; break; } } Marshal.ReleaseComObject( desktops ); return index; } internal static IApplicationView GetApplicationView( this IntPtr hWnd ) { // get application view to window handle ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); return view; } internal static string GetAppId( IntPtr hWnd ) { // get Application ID to window handle hWnd.GetApplicationView().GetAppUserModelId( out var appId ); return appId; } public static int GetViewCount() { ApplicationViewCollection.GetViews( out var objectArray ); objectArray.GetCount( out var count ); Marshal.ReleaseComObject( objectArray ); return count; } public static event EventHandler? Created; public static event EventHandler? DestroyBegin; public static event EventHandler? DestroyFailed; public static event EventHandler? Destroyed; public static event EventHandler? CurrentChanged; public static event EventHandler? Moved; public static event EventHandler? Renamed; public static event EventHandler? WallpaperChanged; private class DisposableNotification : IDisposable { private bool _isDisposed; public uint DwCookie { private get; set; } public void Dispose() { if ( _isDisposed ) return; VirtualDesktopNotificationService.Unregister( DwCookie ); _isDisposed = true; } } private class EventProxy : IVirtualDesktopNotification { public void ViewVirtualDesktopChanged( IApplicationView pView ) { // throw new NotImplementedException(); } public void CurrentVirtualDesktopChanged( IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ) { CurrentChanged?.Invoke( this, new VirtualDesktopChangedEventArgs( pDesktopOld, pDesktopNew ) ); } public void VirtualDesktopCreated( IVirtualDesktop pDesktop ) { Created?.Invoke( this, pDesktop ); } public void VirtualDesktopDestroyBegin( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyBegin?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyFailed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyFailed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { Destroyed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopMoved( IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo ) { Moved?.Invoke( this, new VirtualDesktopMovedEventArgs( pDesktop, nIndexFrom, nIndexTo ) ); } #if NET5_0_OR_GREATER public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, IntPtr newName ) { var name = MarshalString.FromAbi( newName ); Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, name ) ); } #else public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, string chName ) { Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, chName ) ); } #endif #if NET5_0_OR_GREATER public void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, IntPtr newPath ) { var path = MarshalString.FromAbi( newPath ); WallpaperChanged?.Invoke( this, new VirtualDesktopWallpaperChangedEventArgs( pDesktop, path ) ); } #else public void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, string chPath ) { WallpaperChanged?.Invoke( this, new VirtualDesktopWallpaperChangedEventArgs( pDesktop, chPath ) ); } #endif public void VirtualDesktopSwitched( IVirtualDesktop pDesktop ) { // throw new NotImplementedException(); } public void RemoteVirtualDesktopConnected( IVirtualDesktop pDesktop ) { // throw new NotImplementedException(); } } } public class VirtualDesktopRenamedEventArgs : EventArgs { public VirtualDesktopRenamedEventArgs( IVirtualDesktop desktop, string name ) { Desktop = desktop; Name = name; } public IVirtualDesktop Desktop { get; } public string Name { get; } } public class VirtualDesktopWallpaperChangedEventArgs : EventArgs { public VirtualDesktopWallpaperChangedEventArgs( IVirtualDesktop desktop, string path ) { Desktop = desktop; Path = path; } public IVirtualDesktop Desktop { get; } public string Path { get; } } public class VirtualDesktopChangedEventArgs : EventArgs { public VirtualDesktopChangedEventArgs( IVirtualDesktop oldDesktop, IVirtualDesktop newDesktop ) { OldDesktop = oldDesktop; NewDesktop = newDesktop; } public IVirtualDesktop OldDesktop { get; } public IVirtualDesktop NewDesktop { get; } } public class VirtualDesktopMovedEventArgs : EventArgs { public VirtualDesktopMovedEventArgs( IVirtualDesktop desktop, int oldIndex, int newIndex ) { Desktop = desktop; OldIndex = oldIndex; NewIndex = newIndex; } public IVirtualDesktop Desktop { get; } public int OldIndex { get; } public int NewIndex { get; } } public class VirtualDesktopDestroyEventArgs : EventArgs { public VirtualDesktopDestroyEventArgs( IVirtualDesktop destroyed, IVirtualDesktop fallback ) { Destroyed = destroyed; Fallback = fallback; } public IVirtualDesktop Destroyed { get; } public IVirtualDesktop Fallback { get; } } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_24H2/COM.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Runtime.InteropServices; namespace VirtualDesktop { internal static class Guids { public static readonly Guid CLSID_ImmersiveShell = new( "C2F03A33-21F5-47FA-B4BB-156362A2F239" ); public static readonly Guid CLSID_VirtualDesktopManagerInternal = new( "C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B" ); public static readonly Guid CLSID_VirtualDesktopManager = new( "AA509086-5CA9-4C25-8F95-589D3C07B48A" ); public static readonly Guid CLSID_VirtualDesktopPinnedApps = new( "B5A399E7-1C87-46B8-88E9-FC5747B171BD" ); public static readonly Guid CLSID_VirtualDesktopNotificationService = new( "A501FDEC-4A09-464C-AE4E-1B9C21B84918" ); } [StructLayout( LayoutKind.Sequential )] public struct Size { public int X; public int Y; } [StructLayout( LayoutKind.Sequential )] public struct Rect { public int Left; public int Top; public int Right; public int Bottom; } public enum APPLICATION_VIEW_CLOAK_TYPE : int { AVCT_NONE = 0, AVCT_DEFAULT = 1, AVCT_VIRTUAL_DESKTOP = 2 } public enum APPLICATION_VIEW_COMPATIBILITY_POLICY : int { AVCP_NONE = 0, AVCP_SMALL_SCREEN = 1, AVCP_TABLET_SMALL_SCREEN = 2, AVCP_VERY_SMALL_SCREEN = 3, AVCP_HIGH_SCALE_FACTOR = 4 } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "372E1D3B-38D3-42E4-A15B-8AB2B178F513" )] public interface IApplicationView { void GetIIdsSlot(); void GetRuntimeClassNameSlot(); void GetTrustLevelSlot(); int SetFocus(); int SwitchTo(); int TryInvokeBack( IntPtr /* IAsyncCallback* */ callback ); int GetThumbnailWindow( out IntPtr hWnd ); int GetMonitor( out IntPtr /* IImmersiveMonitor */ immersiveMonitor ); int GetVisibility( out int visibility ); int SetCloak( APPLICATION_VIEW_CLOAK_TYPE cloakType, int unknown ); int GetPosition( ref Guid guid /* GUID for IApplicationViewPosition */, out IntPtr /* IApplicationViewPosition** */ position ); int SetPosition( ref IntPtr /* IApplicationViewPosition* */ position ); int InsertAfterWindow( IntPtr hWnd ); int GetExtendedFramePosition( out Rect rect ); int GetAppUserModelId( [MarshalAs( UnmanagedType.LPWStr )] out string id ); int SetAppUserModelId( string id ); int IsEqualByAppUserModelId( string id, out int result ); int GetViewState( out uint state ); int SetViewState( uint state ); int GetNeediness( out int neediness ); int GetLastActivationTimestamp( out ulong timestamp ); int SetLastActivationTimestamp( ulong timestamp ); int GetVirtualDesktopId( out Guid guid ); int SetVirtualDesktopId( ref Guid guid ); int GetShowInSwitchers( out int flag ); int SetShowInSwitchers( int flag ); int GetScaleFactor( out int factor ); int CanReceiveInput( out bool canReceiveInput ); int GetCompatibilityPolicyType( out APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int SetCompatibilityPolicyType( APPLICATION_VIEW_COMPATIBILITY_POLICY flags ); int GetSizeConstraints( IntPtr /* IImmersiveMonitor* */ monitor, out Size size1, out Size size2 ); int GetSizeConstraintsForDpi( uint uint1, out Size size1, out Size size2 ); int SetSizeConstraintsForDpi( ref uint uint1, ref Size size1, ref Size size2 ); int OnMinSizePreferencesUpdated( IntPtr hWnd ); int ApplyOperation( IntPtr /* IApplicationViewOperation* */ operation ); int IsTray( out bool isTray ); int IsInHighZOrderBand( out bool isInHighZOrderBand ); int IsSplashScreenPresented( out bool isSplashScreenPresented ); int Flash(); int GetRootSwitchableOwner( out IApplicationView rootSwitchableOwner ); int EnumerateOwnershipTree( out IObjectArray ownershipTree ); int GetEnterpriseId( [MarshalAs( UnmanagedType.LPWStr )] out string enterpriseId ); int IsMirrored( out bool isMirrored ); int Unknown1( out int unknown ); int Unknown2( out int unknown ); int Unknown3( out int unknown ); int Unknown4( out int unknown ); int Unknown5( out int unknown ); int Unknown6( int unknown ); int Unknown7(); int Unknown8( out int unknown ); int Unknown9( int unknown ); int Unknown10( int unknownX, int unknownY ); int Unknown11( int unknown ); int Unknown12( out Size size1 ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "1841C6D7-4F9D-42C0-AF41-8747538F10E5" )] public interface IApplicationViewCollection { int GetViews( out IObjectArray array ); int GetViewsByZOrder( out IObjectArray array ); int GetViewsByAppUserModelId( string id, out IObjectArray array ); int GetViewForHWnd( IntPtr hWnd, out IApplicationView view ); int GetViewForApplication( object application, out IApplicationView view ); int GetViewForAppUserModelId( string id, out IApplicationView view ); int GetViewInFocus( out IntPtr view ); int Unknown1( out IntPtr view ); void RefreshCollection(); int RegisterForApplicationViewChanges( object listener, out int cookie ); int UnregisterForApplicationViewChanges( int cookie ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "3F07F4BE-B107-441A-AF0F-39D82529072C" )] public interface IVirtualDesktop { bool IsViewVisible( IApplicationView view ); Guid GetId(); #if NET5_0_OR_GREATER public void GetString( out IntPtr hstr ); #else [return: MarshalAs( UnmanagedType.HString )] string GetName(); #endif [return: MarshalAs( UnmanagedType.HString )] string GetWallpaperPath(); bool IsRemote(); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "53F5CA0B-158F-4124-900C-057158060B27" )] internal interface IVirtualDesktopManagerInternal { int GetCount(); void MoveViewToDesktop( IApplicationView view, IVirtualDesktop desktop ); bool CanViewMoveDesktops( IApplicationView view ); IVirtualDesktop GetCurrentDesktop(); void GetDesktops( out IObjectArray desktops ); [PreserveSig] int GetAdjacentDesktop( IVirtualDesktop from, int direction, out IVirtualDesktop desktop ); void SwitchDesktop( IVirtualDesktop desktop ); void SwitchDesktopAndMoveForegroundView( IVirtualDesktop desktop ); IVirtualDesktop CreateDesktop(); void MoveDesktop( IVirtualDesktop desktop, int nIndex ); void RemoveDesktop( IVirtualDesktop desktop, IVirtualDesktop fallback ); IVirtualDesktop FindDesktop( ref Guid desktopId ); void GetDesktopSwitchIncludeExcludeViews( IVirtualDesktop desktop, out IObjectArray unknown1, out IObjectArray unknown2 ); #if NET5_0_OR_GREATER void SetName( IVirtualDesktop desktop, IntPtr newName ); void SetWallpaper( IVirtualDesktop desktop, IntPtr path ); #else void SetDesktopName( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string name ); void SetDesktopWallpaper( IVirtualDesktop desktop, [MarshalAs( UnmanagedType.HString )] string path ); #endif void UpdateWallpaperPathForAllDesktops( [MarshalAs( UnmanagedType.HString )] string path ); void CopyDesktopState( IApplicationView pView0, IApplicationView pView1 ); void CreateRemoteDesktop( [MarshalAs( UnmanagedType.HString )] string path, out IVirtualDesktop desktop ); void SwitchRemoteDesktop( IVirtualDesktop desktop ); void SwitchDesktopWithAnimation( IVirtualDesktop desktop ); void GetLastActiveDesktop( out IVirtualDesktop desktop ); void WaitForAnimationToComplete(); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "A5CD92FF-29BE-454C-8D04-D82879FB3F1B" )] internal interface IVirtualDesktopManager { bool IsWindowOnCurrentVirtualDesktop( IntPtr topLevelWindow ); Guid GetWindowDesktopId( IntPtr topLevelWindow ); void MoveWindowToDesktop( IntPtr topLevelWindow, ref Guid desktopId ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "4CE81583-1E4C-4632-A621-07A53543148F" )] internal interface IVirtualDesktopPinnedApps { bool IsAppIdPinned( string appId ); void PinAppID( string appId ); void UnpinAppID( string appId ); bool IsViewPinned( IApplicationView applicationView ); void PinView( IApplicationView applicationView ); void UnpinView( IApplicationView applicationView ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "92CA9DCD-5622-4BBA-A805-5E9F541BD8C9" )] public interface IObjectArray { void GetCount( out int count ); void GetAt( int index, ref Guid iid, [MarshalAs( UnmanagedType.Interface )] out object obj ); } [ComImport] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] [Guid( "6D5140C1-7436-11CE-8034-00AA006009FA" )] internal interface IServiceProvider10 { [return: MarshalAs( UnmanagedType.IUnknown )] object QueryService( ref Guid service, ref Guid riid ); } [ComImport] [Guid( "B9E5E94D-233E-49AB-AF5C-2B4541C3AADE" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotification { void VirtualDesktopCreated( IVirtualDesktop pDesktop ); void VirtualDesktopDestroyBegin( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyFailed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopDestroyed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ); void VirtualDesktopMoved( IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo ); #if NET5_0_OR_GREATER void VirtualDesktopRenamed( IVirtualDesktop pDesktop, IntPtr newName ); #else void VirtualDesktopRenamed( IVirtualDesktop pDesktop, [MarshalAs( UnmanagedType.HString )] string chName ); #endif void ViewVirtualDesktopChanged( IApplicationView pView ); void CurrentVirtualDesktopChanged( IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ); #if NET5_0_OR_GREATER void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, IntPtr newPath ); #else void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, [MarshalAs( UnmanagedType.HString )] string chPath ); #endif void VirtualDesktopSwitched( IVirtualDesktop pDesktop ); void RemoteVirtualDesktopConnected( IVirtualDesktop pDesktop ); } [ComImport] [Guid( "0cd45e71-d927-4f15-8b0a-8fef525337bf" )] [InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] public interface IVirtualDesktopNotificationService { uint Register( IVirtualDesktopNotification pNotification ); void Unregister( uint dwCookie ); } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_24H2/VirtualDesktop.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Diagnostics; using System.Reflection; using System.Runtime.InteropServices; using VirtualSpace; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public class Desktop : IDesktop { private readonly IVirtualDesktop _ivd; private Desktop( IVirtualDesktop desktop ) { _ivd = desktop; } public Guid Guid => _ivd.GetId(); public static int Count => // return the number of desktops DesktopManager.GetDesktopCount(); public static Desktop Current { get { // returns current desktop try { return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); } catch { DesktopManager.ResetDesktopManager(); return new Desktop( DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); } } } public bool IsVisible => // return true if this desktop is the current displayed one ReferenceEquals( _ivd, DesktopManager.VirtualDesktopManagerInternal.GetCurrentDesktop() ); public Desktop Left { // return desktop at the left of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out var desktop ); // 3 = LeftDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } public Desktop Right { // return desktop at the right of this one, null if none get { var hr = DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out var desktop ); // 4 = RightDirection if ( hr == 0 ) return new Desktop( desktop ); else return null; } } // get process id to window handle [DllImport( "user32.dll" )] private static extern int GetWindowThreadProcessId( IntPtr hWnd, out int lpdwProcessId ); // get handle of active window [DllImport( "user32.dll" )] private static extern IntPtr GetForegroundWindow(); public override int GetHashCode() { // get hash return _ivd.GetHashCode(); } public override bool Equals( object? obj ) { // compare with object return obj is Desktop desk && ReferenceEquals( _ivd, desk._ivd ); } public static Desktop FromIndex( int index ) { // return desktop object from index (-> index = 0..Count-1) return new Desktop( DesktopManager.GetDesktop( index ) ); } public static Desktop? FromWindow( IntPtr hWnd ) { // return desktop object to desktop on which window is displayed if ( hWnd == IntPtr.Zero ) return null; var id = DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); return GetDesktopByGuid( id ); } public static int SysIndexFromDesktop( Desktop desktop ) { // return index of desktop object or -1 if not found if ( desktop == null ) return -1; return DesktopManager.GetDesktopIndex( desktop._ivd ); } public static string DesktopNameFromDesktop( Desktop desktop ) { // return name of desktop or "Desktop n" if it has no name // get desktop name string desktopName = null; try { #if NET5_0_OR_GREATER desktop._ivd.GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = desktop._ivd.GetName(); #endif } catch ( Exception ) { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( DesktopManager.GetDesktopIndex( desktop._ivd ) + 1 ).ToString(); } return desktopName; } public static string DesktopNameFromIndex( int index ) { // return name of desktop from index (-> index = 0..Count-1) or "Desktop n" if it has no name // get desktop name string desktopName = null; try { #if NET5_0_OR_GREATER DesktopManager.GetDesktop( index ).GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = DesktopManager.GetDesktop( index ).GetName(); #endif } catch { } // no name found, generate generic name if ( string.IsNullOrEmpty( desktopName ) ) { // create name "Desktop n" (n = number starting with 1) desktopName = "Desktop " + ( index + 1 ).ToString(); } return desktopName; } public static bool HasDesktopNameFromIndex( int index ) { // return true is desktop is named or false if it has no name // read desktop name in registry string desktopName = null; try { #if NET5_0_OR_GREATER DesktopManager.GetDesktop( index ).GetString( out var hstr ); desktopName = MarshalString.FromAbi( hstr ); #else desktopName = DesktopManager.GetDesktop( index ).GetName(); #endif } catch { } // name found? if ( string.IsNullOrEmpty( desktopName ) ) return false; else return true; } public static string DesktopWallpaperFromIndex( int index ) { // return name of desktop wallpaper from index (-> index = 0..Count-1) // get desktop name var desktopWpPath = ""; try { desktopWpPath = DesktopManager.GetDesktop( index ).GetWallpaperPath(); } catch { } return desktopWpPath; } public static int SearchDesktop( string partialName ) { // get index of desktop with partial name, return -1 if no desktop found var index = -1; for ( var i = 0; i < DesktopManager.GetDesktopCount(); i++ ) { // loop through all virtual desktops and compare partial name to desktop name if ( DesktopNameFromIndex( i ).ToUpper().IndexOf( partialName.ToUpper() ) >= 0 ) { index = i; break; } } return index; } public static Desktop Create() { // create a new desktop return new Desktop( DesktopManager.VirtualDesktopManagerInternal.CreateDesktop() ); } public void Remove( Desktop? fallback = null ) { // destroy desktop and switch to IVirtualDesktop fallbackDesktop; if ( fallback == null ) { // if no fallback is given use desktop to the left except for desktop 0. var dtToCheck = new Desktop( DesktopManager.GetDesktop( 0 ) ); if ( Equals( dtToCheck ) ) { // desktop 0: set fallback to second desktop (= "right" desktop) DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 4, out fallbackDesktop ); // 4 = RightDirection } else { // set fallback to "left" desktop DesktopManager.VirtualDesktopManagerInternal.GetAdjacentDesktop( _ivd, 3, out fallbackDesktop ); // 3 = LeftDirection } } else // set fallback desktop fallbackDesktop = fallback._ivd; DesktopManager.VirtualDesktopManagerInternal.RemoveDesktop( _ivd, fallbackDesktop ); } public static void RemoveAll() { // remove all desktops but visible // DesktopManager.VirtualDesktopManagerInternal.SetDesktopIsPerMonitor( true ); } public void Move( int index ) { // move current desktop to desktop in index (-> index = 0..Count-1) DesktopManager.VirtualDesktopManagerInternal.MoveDesktop( _ivd, index ); } public void SetName( string name ) { // set name for desktop, empty string removes name #if NET5_0_OR_GREATER var newName = MarshalString.CreateMarshaler( name ); DesktopManager.VirtualDesktopManagerInternal.SetName( _ivd, MarshalString.GetAbi( newName ) ); #else DesktopManager.VirtualDesktopManagerInternal.SetDesktopName( _ivd, name ); #endif } public void SetWallpaperPath( string path ) { // set path for wallpaper, empty string removes path if ( string.IsNullOrEmpty( path ) ) throw new ArgumentNullException(); #if NET5_0_OR_GREATER var newPath = MarshalString.CreateMarshaler( path ); DesktopManager.VirtualDesktopManagerInternal.SetWallpaper( _ivd, MarshalString.GetAbi( newPath ) ); #else DesktopManager.VirtualDesktopManagerInternal.SetDesktopWallpaper( _ivd, path ); #endif } public static void SetAllWallpaperPaths( string path ) { // set wallpaper path for all desktops if ( string.IsNullOrEmpty( path ) ) throw new ArgumentNullException(); DesktopManager.VirtualDesktopManagerInternal.UpdateWallpaperPathForAllDesktops( path ); } public void MakeVisible() { // make this desktop visible DesktopManager.VirtualDesktopManagerInternal.SwitchDesktop( _ivd ); } public void MoveWindow( IntPtr hWnd ) { // move window to this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); _ = GetWindowThreadProcessId( hWnd, out var processId ); if ( Process.GetCurrentProcess().Id == processId ) { // window of process try // the easy way (if we are owner) { DesktopManager.VirtualDesktopManager.MoveWindowToDesktop( hWnd, _ivd.GetId() ); } catch // window of process, but we are not the owner { DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } else { // window of other process DesktopManager.ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); try { DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } catch { // could not move active window, try main window (or whatever windows thinks is the main window) DesktopManager.ApplicationViewCollection.GetViewForHWnd( Process.GetProcessById( processId ).MainWindowHandle, out view ); DesktopManager.VirtualDesktopManagerInternal.MoveViewToDesktop( view, _ivd ); } } } public void MoveActiveWindow() { // move active window to this desktop MoveWindow( GetForegroundWindow() ); } public bool HasWindow( IntPtr hWnd ) { // return true if window is on this desktop if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return _ivd.GetId() == DesktopManager.VirtualDesktopManager.GetWindowDesktopId( hWnd ); } public static bool IsWindowPinned( IntPtr hWnd ) { // return true if window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( hWnd.GetApplicationView() ); } public static void PinWindow( IntPtr hWnd ) { // pin window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( !DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinView( view ); } } public static void UnpinWindow( IntPtr hWnd ) { // unpin window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); if ( DesktopManager.VirtualDesktopPinnedApps.IsViewPinned( view ) ) { // unpin only if not already unpinned DesktopManager.VirtualDesktopPinnedApps.UnpinView( view ); } } public static bool IsApplicationPinned( IntPtr hWnd ) { // return true if application for window is pinned to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); return DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( DesktopManager.GetAppId( hWnd ) ); } public static void PinApplication( IntPtr hWnd ) { // pin application for window to all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var appId = DesktopManager.GetAppId( hWnd ); if ( !DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // pin only if not already pinned DesktopManager.VirtualDesktopPinnedApps.PinAppID( appId ); } } public static void UnpinApplication( IntPtr hWnd ) { // unpin application for window from all desktops if ( hWnd == IntPtr.Zero ) throw new ArgumentNullException(); var view = hWnd.GetApplicationView(); var appId = DesktopManager.GetAppId( hWnd ); if ( DesktopManager.VirtualDesktopPinnedApps.IsAppIdPinned( appId ) ) { // unpin only if pinned DesktopManager.VirtualDesktopPinnedApps.UnpinAppID( appId ); } } public static Desktop? FromId( Guid guid ) { return GetDesktopByGuid( guid ); } private static Desktop? GetDesktopByGuid( Guid guid ) { Desktop? desktop = null; try { var count = DesktopManager.GetDesktopCount(); DesktopManager.VirtualDesktopManagerInternal.GetDesktops( out var desktops ); for ( var i = 0; i < count; i++ ) { desktops.GetAt( i, typeof( IVirtualDesktop ).GUID, out var objDesktop ); if ( guid.CompareTo( ( (IVirtualDesktop)objDesktop ).GetId() ) != 0 ) continue; desktop = new Desktop( (IVirtualDesktop)objDesktop ); } Marshal.ReleaseComObject( desktops ); return desktop; } catch { return desktop; } } } } ================================================ FILE: VirtualDesktop/VirtualDesktop11_24H2/VirtualDesktop11_24H2.csproj ================================================ net6.0-windows enable false 9 ================================================ FILE: VirtualDesktop/VirtualDesktop11_24H2/VirtualDesktopManager.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Runtime.InteropServices; #if NET5_0_OR_GREATER using WinRT; #endif namespace VirtualDesktop { public static class DesktopManager { private static DisposableNotification _disposableNotification; private static IVirtualDesktopNotificationService VirtualDesktopNotificationService; internal static IVirtualDesktopManagerInternal VirtualDesktopManagerInternal; internal static IVirtualDesktopManager VirtualDesktopManager; internal static IVirtualDesktopPinnedApps VirtualDesktopPinnedApps; public static IApplicationViewCollection ApplicationViewCollection; static DesktopManager() { if ( Environment.OSVersion.Version is {Major: 10, Build: >= 22000} ) Init(); } public static void ResetDesktopManager() { Init(); } private static void Init() { var shell = (IServiceProvider10)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_ImmersiveShell ) ); VirtualDesktopManager = (IVirtualDesktopManager)Activator.CreateInstance( Type.GetTypeFromCLSID( Guids.CLSID_VirtualDesktopManager ) ); VirtualDesktopManagerInternal = (IVirtualDesktopManagerInternal)shell.QueryService( Guids.CLSID_VirtualDesktopManagerInternal, typeof( IVirtualDesktopManagerInternal ).GUID ); ApplicationViewCollection = (IApplicationViewCollection)shell.QueryService( typeof( IApplicationViewCollection ).GUID, typeof( IApplicationViewCollection ).GUID ); VirtualDesktopPinnedApps = (IVirtualDesktopPinnedApps)shell.QueryService( Guids.CLSID_VirtualDesktopPinnedApps, typeof( IVirtualDesktopPinnedApps ).GUID ); VirtualDesktopNotificationService = (IVirtualDesktopNotificationService)shell.QueryService( Guids.CLSID_VirtualDesktopNotificationService, typeof( IVirtualDesktopNotificationService ).GUID ); _disposableNotification = new DisposableNotification(); _disposableNotification.DwCookie = VirtualDesktopNotificationService.Register( new EventProxy() ); } public static int GetDesktopCount() { try { return VirtualDesktopManagerInternal.GetCount(); } catch { ResetDesktopManager(); return VirtualDesktopManagerInternal.GetCount(); } } public static IVirtualDesktop GetDesktop( int index ) { // get desktop with index var count = GetDesktopCount(); if ( index < 0 || index >= count ) throw new ArgumentOutOfRangeException( nameof( index ) ); VirtualDesktopManagerInternal.GetDesktops( out var desktops ); desktops.GetAt( index, typeof( IVirtualDesktop ).GUID, out var objDesktop ); Marshal.ReleaseComObject( desktops ); return (IVirtualDesktop)objDesktop; } internal static int GetDesktopIndex( IVirtualDesktop desktop ) { // get index of desktop var count = GetDesktopCount(); var index = -1; var idSearch = desktop.GetId(); VirtualDesktopManagerInternal.GetDesktops( out var desktops ); for ( var i = 0; i < count; i++ ) { desktops.GetAt( i, typeof( IVirtualDesktop ).GUID, out var objDesktop ); if ( idSearch.CompareTo( ( (IVirtualDesktop)objDesktop ).GetId() ) == 0 ) { index = i; break; } } Marshal.ReleaseComObject( desktops ); return index; } internal static IApplicationView GetApplicationView( this IntPtr hWnd ) { // get application view to window handle ApplicationViewCollection.GetViewForHWnd( hWnd, out var view ); return view; } internal static string GetAppId( IntPtr hWnd ) { // get Application ID to window handle hWnd.GetApplicationView().GetAppUserModelId( out var appId ); return appId; } public static int GetViewCount() { ApplicationViewCollection.GetViews( out var objectArray ); objectArray.GetCount( out var count ); Marshal.ReleaseComObject( objectArray ); return count; } public static event EventHandler? Created; public static event EventHandler? DestroyBegin; public static event EventHandler? DestroyFailed; public static event EventHandler? Destroyed; public static event EventHandler? CurrentChanged; public static event EventHandler? Moved; public static event EventHandler? Renamed; public static event EventHandler? WallpaperChanged; private class DisposableNotification : IDisposable { private bool _isDisposed; public uint DwCookie { private get; set; } public void Dispose() { if ( _isDisposed ) return; VirtualDesktopNotificationService.Unregister( DwCookie ); _isDisposed = true; } } private class EventProxy : IVirtualDesktopNotification { public void ViewVirtualDesktopChanged( IApplicationView pView ) { // throw new NotImplementedException(); } public void CurrentVirtualDesktopChanged( IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew ) { CurrentChanged?.Invoke( this, new VirtualDesktopChangedEventArgs( pDesktopOld, pDesktopNew ) ); } public void VirtualDesktopCreated( IVirtualDesktop pDesktop ) { Created?.Invoke( this, pDesktop ); } public void VirtualDesktopDestroyBegin( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyBegin?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyFailed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { DestroyFailed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopDestroyed( IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback ) { Destroyed?.Invoke( this, new VirtualDesktopDestroyEventArgs( pDesktopDestroyed, pDesktopFallback ) ); } public void VirtualDesktopMoved( IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo ) { Moved?.Invoke( this, new VirtualDesktopMovedEventArgs( pDesktop, nIndexFrom, nIndexTo ) ); } #if NET5_0_OR_GREATER public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, IntPtr newName ) { var name = MarshalString.FromAbi( newName ); Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, name ) ); } #else public void VirtualDesktopRenamed( IVirtualDesktop pDesktop, string chName ) { Renamed?.Invoke( this, new VirtualDesktopRenamedEventArgs( pDesktop, chName ) ); } #endif #if NET5_0_OR_GREATER public void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, IntPtr newPath ) { var path = MarshalString.FromAbi( newPath ); WallpaperChanged?.Invoke( this, new VirtualDesktopWallpaperChangedEventArgs( pDesktop, path ) ); } #else public void VirtualDesktopWallpaperChanged( IVirtualDesktop pDesktop, string chPath ) { WallpaperChanged?.Invoke( this, new VirtualDesktopWallpaperChangedEventArgs( pDesktop, chPath ) ); } #endif public void VirtualDesktopSwitched( IVirtualDesktop pDesktop ) { // throw new NotImplementedException(); } public void RemoteVirtualDesktopConnected( IVirtualDesktop pDesktop ) { // throw new NotImplementedException(); } } } public class VirtualDesktopRenamedEventArgs : EventArgs { public VirtualDesktopRenamedEventArgs( IVirtualDesktop desktop, string name ) { Desktop = desktop; Name = name; } public IVirtualDesktop Desktop { get; } public string Name { get; } } public class VirtualDesktopWallpaperChangedEventArgs : EventArgs { public VirtualDesktopWallpaperChangedEventArgs( IVirtualDesktop desktop, string path ) { Desktop = desktop; Path = path; } public IVirtualDesktop Desktop { get; } public string Path { get; } } public class VirtualDesktopChangedEventArgs : EventArgs { public VirtualDesktopChangedEventArgs( IVirtualDesktop oldDesktop, IVirtualDesktop newDesktop ) { OldDesktop = oldDesktop; NewDesktop = newDesktop; } public IVirtualDesktop OldDesktop { get; } public IVirtualDesktop NewDesktop { get; } } public class VirtualDesktopMovedEventArgs : EventArgs { public VirtualDesktopMovedEventArgs( IVirtualDesktop desktop, int oldIndex, int newIndex ) { Desktop = desktop; OldIndex = oldIndex; NewIndex = newIndex; } public IVirtualDesktop Desktop { get; } public int OldIndex { get; } public int NewIndex { get; } } public class VirtualDesktopDestroyEventArgs : EventArgs { public VirtualDesktopDestroyEventArgs( IVirtualDesktop destroyed, IVirtualDesktop fallback ) { Destroyed = destroyed; Fallback = fallback; } public IVirtualDesktop Destroyed { get; } public IVirtualDesktop Fallback { get; } } } ================================================ FILE: VirtualDesktopWrapper/DesktopManagerWrapper.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ extern alias VirtualDesktop10; extern alias VirtualDesktop11; using VirtualSpace.Helpers; namespace VirtualSpace.VirtualDesktop.Api { public static partial class DesktopManagerWrapper { public static Guid GetIdByIndex( int index ) { try { if ( SysInfo.IsWin10 ) { return VirtualDesktop10::VirtualDesktop.DesktopManager.GetDesktop( index ).GetId(); } return VirtualDesktop11::VirtualDesktop.DesktopManager.GetDesktop( index ).GetId(); } catch { return default; } } public static int GetViewCount() { if ( SysInfo.IsWin10 ) { return VirtualDesktop10::VirtualDesktop.DesktopManager.GetViewCount(); } return VirtualDesktop11::VirtualDesktop.DesktopManager.GetViewCount(); } public static void ResetDesktopManager() { if ( SysInfo.IsWin10 ) { VirtualDesktop10::VirtualDesktop.DesktopManager.ResetDesktopManager(); } else { VirtualDesktop11::VirtualDesktop.DesktopManager.ResetDesktopManager(); } } } } ================================================ FILE: VirtualDesktopWrapper/DesktopManagerWrapper.events.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ extern alias VirtualDesktop10; extern alias VirtualDesktop11; using System.Threading.Channels; using VirtualSpace.Commons; using VirtualSpace.Helpers; using VD10 = VirtualDesktop10::VirtualDesktop; using VD11 = VirtualDesktop11::VirtualDesktop; namespace VirtualSpace.VirtualDesktop.Api { public static partial class DesktopManagerWrapper { private static readonly Channel VirtualDesktopNotifications = Channels.VirtualDesktopNotifications; public static void RegisterVirtualDesktopEvents( WallpaperChanged wc10, Action wc11 ) { if ( SysInfo.IsWin10 ) { RegisterVirtualDesktopEvents10( wc10 ); } else { RegisterVirtualDesktopEvents11( wc11 ); } } private static void RegisterVirtualDesktopEvents10( WallpaperChanged wc ) { VD10.DesktopManager.Created += ( _, e ) => { VirtualDesktopNotifications.Writer.TryWrite( new VirtualDesktopNotification {Type = VirtualDesktopNotificationType.CREATED} ); }; VD10.DesktopManager.Destroyed += ( _, e ) => { VirtualDesktopNotifications.Writer.TryWrite( new VirtualDesktopNotification { Type = VirtualDesktopNotificationType.DELETED, NewId = e.Fallback.GetId() } ); }; VD10.DesktopManager.CurrentChanged += ( _, e ) => { VirtualDesktopNotifications.Writer.TryWrite( new VirtualDesktopNotification { Type = VirtualDesktopNotificationType.CURRENT_CHANGED, NewId = e.NewDesktop.GetId(), OldId = e.OldDesktop.GetId() } ); }; WatchWallpaperEvents( wc ); } private static void RegisterVirtualDesktopEvents11( Action wc11 ) { VD11.DesktopManager.Created += ( _, e ) => { VirtualDesktopNotifications.Writer.TryWrite( new VirtualDesktopNotification {Type = VirtualDesktopNotificationType.CREATED} ); }; VD11.DesktopManager.Destroyed += ( _, e ) => { VirtualDesktopNotifications.Writer.TryWrite( new VirtualDesktopNotification { Type = VirtualDesktopNotificationType.DELETED, NewId = e.Fallback.GetId() } ); }; VD11.DesktopManager.CurrentChanged += ( _, e ) => { VirtualDesktopNotifications.Writer.TryWrite( new VirtualDesktopNotification { Type = VirtualDesktopNotificationType.CURRENT_CHANGED, NewId = e.NewDesktop.GetId(), OldId = e.OldDesktop.GetId() } ); }; VD11.DesktopManager.WallpaperChanged += ( _, e ) => { if ( string.IsNullOrEmpty( e.Path ) ) return; wc11( e.Desktop.GetId(), e.Path ); }; } public delegate void DesktopCreated(); public delegate void DesktopDeleted( VirtualDesktopNotification vdn ); public delegate void DesktopChanged( VirtualDesktopNotification vdn ); public static event DesktopCreated DesktopCreatedEvent; public static event DesktopDeleted DesktopDeletedEvent; public static event DesktopChanged DesktopChangedEvent; public static async void ListenVirtualDesktopEvents() { while ( await VirtualDesktopNotifications.Reader.WaitToReadAsync() ) { if ( VirtualDesktopNotifications.Reader.TryRead( out var vdn ) ) { switch ( vdn.Type ) { case VirtualDesktopNotificationType.CREATED: DesktopCreatedEvent(); break; case VirtualDesktopNotificationType.DELETED: DesktopDeletedEvent( vdn ); break; case VirtualDesktopNotificationType.CURRENT_CHANGED: DesktopChangedEvent( vdn ); break; default: throw new ArgumentOutOfRangeException(); } } } } } } ================================================ FILE: VirtualDesktopWrapper/DesktopManagerWrapper.wallpaper.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using Microsoft.Win32; namespace VirtualSpace.VirtualDesktop.Api { public static partial class DesktopManagerWrapper { public delegate void WallpaperChanged(); private const string WALLPAPER_REGISTRY_PREFIX = @"HKEY_CURRENT_USER\Control Panel\Desktop\"; private const string COLOR_REGISTRY_PREFIX = @"HKEY_CURRENT_USER\Control Panel\Colors\"; private static string? _lastPath; private static string? _lastColor; private static void WatchWallpaperEvents( WallpaperChanged wc ) { Task.Factory.StartNew( () => { while ( true ) { var path = Registry.GetValue( WALLPAPER_REGISTRY_PREFIX, "Wallpaper", "" ).ToString(); var color = Registry.GetValue( COLOR_REGISTRY_PREFIX, "Background", "" ).ToString(); if ( string.IsNullOrEmpty( _lastColor ) ) { _lastPath = path; _lastColor = color; } if ( _lastPath != path || _lastColor != color ) { _lastPath = path; _lastColor = color; wc(); } Thread.Sleep( 1000 ); } }, TaskCreationOptions.LongRunning ); } } } ================================================ FILE: VirtualDesktopWrapper/DesktopWrapper.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . extern alias VirtualDesktop10; extern alias VirtualDesktop11; using VirtualSpace.AppLogs; using VirtualSpace.Helpers; using VD10 = VirtualDesktop10::VirtualDesktop; using VD11 = VirtualDesktop11::VirtualDesktop; namespace VirtualSpace.VirtualDesktop.Api { public static partial class DesktopWrapper { public delegate void OnDesktopVisible( IDesktop desktop, bool? forceFocusForegroundWindow = null ); public static int CurrentIndex => SysInfo.IsWin10 ? VD10.Desktop.SysIndexFromDesktop( VD10.Desktop.Current ) : VD11.Desktop.SysIndexFromDesktop( VD11.Desktop.Current ); public static int Count => SysInfo.IsWin10 ? VD10.Desktop.Count : VD11.Desktop.Count; public static Guid CurrentGuid => SysInfo.IsWin10 ? VD10.Desktop.Current.Guid : VD11.Desktop.Current.Guid; public static bool RemoveDesktopByGuid( Guid guid ) { if ( Count <= 1 ) return false; try { if ( SysInfo.IsWin10 ) { var desktop = VD10.Desktop.FromId( guid ); desktop.Remove( null ); } else { var desktop = VD11.Desktop.FromId( guid ); desktop.Remove( null ); } return true; } catch ( Exception e ) { Logger.Error( "Remove Desktop: " + e.Message ); return false; } } public static void PinWindow( IntPtr handle, bool isPinned ) { if ( SysInfo.IsWin10 ) { if ( isPinned ) VD10.Desktop.UnpinWindow( handle ); else VD10.Desktop.PinWindow( handle ); } else { if ( isPinned ) VD11.Desktop.UnpinWindow( handle ); else VD11.Desktop.PinWindow( handle ); } } public static void PinApp( IntPtr handle, bool isPinned ) { if ( SysInfo.IsWin10 ) { if ( isPinned ) VD10.Desktop.UnpinApplication( handle ); else VD10.Desktop.PinApplication( handle ); } else { if ( isPinned ) VD11.Desktop.UnpinApplication( handle ); else VD11.Desktop.PinApplication( handle ); } } public static bool IsWindowPinned( IntPtr handle ) { return SysInfo.IsWin10 ? VD10.Desktop.IsWindowPinned( handle ) : VD11.Desktop.IsWindowPinned( handle ); } public static bool IsApplicationPinned( IntPtr handle ) { return SysInfo.IsWin10 ? VD10.Desktop.IsApplicationPinned( handle ) : VD11.Desktop.IsApplicationPinned( handle ); } public static string DesktopNameFromIndex( int sysIndex ) { return SysInfo.IsWin10 ? VD10.Desktop.DesktopNameFromIndex( sysIndex ) : VD11.Desktop.DesktopNameFromIndex( sysIndex ); } public static string DesktopNameFromGuid( Guid guid ) { if ( SysInfo.IsWin10 ) { var desktop = VD10.Desktop.FromId( guid ); return desktop == null ? "" : VD10.Desktop.DesktopNameFromDesktop( desktop ); } else { var desktop = VD11.Desktop.FromId( guid ); return desktop == null ? "" : VD11.Desktop.DesktopNameFromDesktop( desktop ); } } public static int IndexFromGuid( Guid guid ) { if ( SysInfo.IsWin10 ) { var desktop = VD10.Desktop.FromId( guid ); return VD10.Desktop.SysIndexFromDesktop( desktop ); } else { var desktop = VD11.Desktop.FromId( guid ); return VD11.Desktop.SysIndexFromDesktop( desktop ); } } public static void MoveWindowToDesktop( IntPtr handle, int sysIndex ) { if ( SysInfo.IsWin10 ) { var desktop = VD10.Desktop.FromIndex( sysIndex ); desktop.MoveWindow( handle ); } else { var desktop = VD11.Desktop.FromIndex( sysIndex ); desktop.MoveWindow( handle ); } } public static void MakeVisibleByIndex( int sysIndex ) { if ( SysInfo.IsWin10 ) { VD10.Desktop.FromIndex( sysIndex ).MakeVisible(); } else { VD11.Desktop.FromIndex( sysIndex ).MakeVisible(); } } public static void MakeVisibleByGuid( Guid guid, bool? forceFocusForegroundWindow = null ) { IDesktop? desktop; if ( SysInfo.IsWin10 ) { desktop = VD10.Desktop.FromId( guid ); } else { desktop = VD11.Desktop.FromId( guid ); } if ( desktop is null ) return; OnDesktopVisibleEvent( desktop, forceFocusForegroundWindow ); } public static void SetNameByGuid( Guid guid, string name ) { if ( SysInfo.IsWin10 ) { VD10.Desktop.FromId( guid )?.SetName( name ); } else { VD11.Desktop.FromId( guid )?.SetName( name ); } } public static Guid GuidFromWindow( IntPtr handle ) { if ( SysInfo.IsWin10 ) { var desktop10 = VD10.Desktop.FromWindow( handle ); return desktop10?.Guid ?? Guid.Empty; } var desktop11 = VD11.Desktop.FromWindow( handle ); return desktop11?.Guid ?? Guid.Empty; } public static event OnDesktopVisible OnDesktopVisibleEvent; } } ================================================ FILE: VirtualDesktopWrapper/VirtualDesktopWrapper.csproj ================================================  net6.0-windows enable enable VirtualDesktop10 VirtualDesktop11 ================================================ FILE: VirtualDesktopWrapper/Wrapper11.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ extern alias VirtualDesktop10; extern alias VirtualDesktop11; using VirtualSpace.Helpers; using VD10 = VirtualDesktop10::VirtualDesktop; using VD11 = VirtualDesktop11::VirtualDesktop; namespace VirtualSpace.VirtualDesktop.Api { public static partial class DesktopWrapper { public static void Create() { if ( SysInfo.IsWin10 ) { VD10.Desktop.Create(); } else { var desk = VD11.Desktop.Create(); var path = WinRegistry.GetDefaultWallpaperPath(); if ( !string.IsNullOrEmpty( path ) ) desk.SetWallpaperPath( path ); } } } } ================================================ FILE: VirtualSpace/App.xaml ================================================  ================================================ FILE: VirtualSpace/App.xaml.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Threading; using System.Windows; using System.Windows.Forms; using VirtualSpace.AppLogs; using VirtualSpace.Commons; using VirtualSpace.Config; using VirtualSpace.Factory; using VirtualSpace.Helpers; using VirtualSpace.Plugin; using VirtualSpace.Tools; using VirtualSpace.VirtualDesktop; using VirtualSpace.VirtualDesktop.Api; using Application = System.Windows.Application; using ConfigManager = VirtualSpace.Config.Manager; using Point = System.Drawing.Point; namespace VirtualSpace { /// /// Interaction logic for App.xaml /// public partial class App : Application { private static Mutex? _mutex; public bool HideOnStart; protected override void OnStartup( StartupEventArgs e ) { base.OnStartup( e ); LogManager.GorgeousDividingLine(); if ( SystemTool.VersionCheck() && SingleInstanceCheck() && ConfigManager.Init() ) { Bootstrap(); if ( e.Args.Contains( Const.Args.HIDE_ON_START ) ) HideOnStart = true; var mw = CreateCanvas( e ); Current.MainWindow = mw; IpcPipeServer.MainWindowHandle = mw.Handle; if ( ConfigManager.Configs.Cluster.HideOnStart || HideOnStart ) { mw.Left = Const.FakeHideX; mw.Top = Const.FakeHideY; } mw.Show(); if ( ConfigManager.Configs.Cluster.HideOnStart || HideOnStart ) { mw.FakeHide(); } PluginHost.AutoStartAfterMainWindowLoaded(); } else { Current.Shutdown(); } } protected override void OnExit( ExitEventArgs e ) { base.OnExit( e ); ReleaseMutex(); IpcPipeServer.SimpleShutdown(); } public void ReleaseMutex() { _mutex?.ReleaseMutex(); _mutex?.Dispose(); _mutex = null; } private static bool SingleInstanceCheck() { var createdNew = TryMutex(); if ( createdNew ) { IpcPipeServer.Start(); } else { IpcPipeServer.AsClient(); } return createdNew; } public static bool TryMutex() { _mutex = new Mutex( true, "乱花渐欲迷人眼", out var createdNew ); return createdNew; } private MainWindow CreateCanvas( StartupEventArgs args ) { var canvas = VirtualSpace.MainWindow.Create( AppControllerFactory.Create( mergedDictionaries: Resources.MergedDictionaries ) ); return canvas; } private static void Bootstrap() { Logger.ShowLogsInGui = ConfigManager.Configs.LogConfig.ShowLogsInGui; BootInfo(); TrayIcon.Show(); Daemon.Start(); PluginHost.RegisterPlugins( ConfigManager.GetPluginsPath() ); } private static void BootInfo() { var screen = Screen.FromPoint( new Point() ); var ar = SysInfo.GetAspectRadioOfScreen(); Logger.Info( $"Application Start Successfully: {ConfigManager.AppPath}" ); LogForVersion(); Logger.Info( $"System Version: {SysInfo.OSVersion}" ); Logger.Info( $".NET Runtime: {RuntimeInformation.FrameworkDescription}" ); Logger.Info( $"Total Screens: {Screen.AllScreens.Length}" ); Logger.Info( $"Total VirtualDesktops: {DesktopWrapper.Count}" ); Logger.Info( $"Start Screen: {screen.DeviceName} ({screen.DeviceFriendlyName()})" ); Logger.Info( $"Start Screen Aspect Ratio: [{ar.W}:{ar.H}]" ); Logger.Info( $"Start VirtualDesktop: Desktop[{DesktopWrapper.CurrentIndex}]" ); Logger.Info( $"Start Position: [{Screen.PrimaryScreen.Bounds.Location.X}, {Screen.PrimaryScreen.Bounds.Location.Y}]" ); Logger.Info( $"Start Size: {Screen.PrimaryScreen.Bounds.Width}*{Screen.PrimaryScreen.Bounds.Height}" ); Logger.Info( $"Is Running As Administrator: {SysInfo.IsAdministrator}" ); Logger.Info( $"Current Profile: {ConfigManager.Configs.CurrentProfileName}" ); Logger.Info( $"Language: {ConfigManager.CurrentProfile.UI.Language}" ); } private static void LogForVersion() { var version = string.Empty; try { version = ( (AssemblyInformationalVersionAttribute)Attribute.GetCustomAttribute( Assembly.GetEntryAssembly(), typeof( AssemblyInformationalVersionAttribute ), false ) ).InformationalVersion; } catch { // ignored } if ( !string.IsNullOrEmpty( version ) ) Logger.Info( $"Application Version: {version}" ); } } } ================================================ FILE: VirtualSpace/AssemblyInfo.cs ================================================ using System.Windows; [assembly: ThemeInfo( ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located //(used if a resource is not found in the page, // or application resource dictionaries) ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries) )] ================================================ FILE: VirtualSpace/AutoVersion.tt ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".cs" #> <#@ Assembly Name="System.Core.dll" #> <#@ import namespace="System.IO" #> using System.Reflection; [assembly: AssemblyProduct("<#= AppName #>")] [assembly: AssemblyTitle("<#= AppDesc #>")] [assembly: AssemblyDescription("<#= AppDesc #>")] [assembly: AssemblyCompany("https://github.com/newlooper")] [assembly: AssemblyCopyright("Copyright © <#= Copyright #>")] [assembly: AssemblyVersion("<#= MAJOR #>.<#= MINOR #>.<#= DaysSinceProjectStarted #>.<#= MinutesSinceMidnight #>")] [assembly: AssemblyFileVersion("<#= MAJOR #>.<#= MINOR #>.<#= DaysSinceProjectStarted #>.<#= MinutesSinceMidnight #>")] [assembly: AssemblyInformationalVersion("<#= MAJOR #>.<#= MINOR #>.<#= DaysSinceProjectStarted #>.<#= MinutesSinceMidnight/*+"."+WinVer*/ #>")] <#+ private static readonly DateTime ProjectStartedDate = new( 2021, 12, 5 ); private static readonly string Copyright = ProjectStartedDate.Year + " - " + DateTime.Now.Year; private static readonly string AppName = new DirectoryInfo( "." ).Name; private static readonly string AppDesc = "VirtualSpace - Windows VirtualDesktop Enhancement"; private const int MAJOR = 0; private const int MINOR = 2; private static readonly int DaysSinceProjectStarted = (int)( DateTime.UtcNow - ProjectStartedDate ).TotalDays; private static readonly int MinutesSinceMidnight = (int)DateTime.UtcNow.TimeOfDay.TotalMinutes; // private static readonly string WinVer = Environment.GetEnvironmentVariable("VirtualSpaceVersion"); // set in ENV before run `dotnet publish` #> ================================================ FILE: VirtualSpace/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: VirtualSpace/Factory/AppControllerFactory.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System.Collections.ObjectModel; using System.Windows; namespace VirtualSpace.Factory { public static class AppControllerFactory { public static IAppController Create( string name = "WPF", Collection? mergedDictionaries = null ) { switch ( name ) { case "WinForm": // return new AppController(); case "WPF": mergedDictionaries?.Add( ControlPanel.ExportResourceDictionary.Instance ); var mw = new ControlPanel.MainWindow(); mw.ForceLoad(); return mw; default: return null; } } } } ================================================ FILE: VirtualSpace/MainWindow.filter.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System.Windows; using VirtualSpace.Config; using VirtualSpace.VirtualDesktop; namespace VirtualSpace { public partial class MainWindow { private void ToggleWindowFilter() { if ( !IsShowing() ) return; var filterRow = Canvas.RowDefinitions[1]; if ( filterRow.Height.Value == 0 ) { filterRow.Height = new GridLength( Const.Window.WINDOW_FILTER_BAR_HEIGHT, GridUnitType.Pixel ); ShowFilterWindow(); } else { filterRow.Height = new GridLength( 0 ); HideFilterWindow( clearKeyword: false ); } UpdateLayout(); VirtualDesktopManager.ShowAllVirtualDesktops(); } private void ShowFilterWindow() { var wf = WindowFilter.GetInstance( _instance.Handle ); wf.Width = Width; wf.Left = Left; wf.Top = Height - Const.Window.WINDOW_FILTER_BAR_HEIGHT; wf.Show(); wf.SetFocus(); } private static void HideFilterWindow( bool clearKeyword = true ) { var filterRow = _instance.Canvas.RowDefinitions[1]; filterRow.Height = new GridLength( 0 ); var wf = WindowFilter.GetInstance( _instance.Handle ); wf.ClearAndHide( clearKeyword ); } } } ================================================ FILE: VirtualSpace/MainWindow.hotkeys.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Forms; using System.Windows.Input; using VirtualSpace.AppLogs; using VirtualSpace.Config; using VirtualSpace.Helpers; using VirtualSpace.Tools; using GHK = VirtualSpace.Helpers.GlobalHotKey; using LLKH = VirtualSpace.Helpers.LowLevelKeyboardHook; namespace VirtualSpace { public partial class MainWindow { private static readonly Stopwatch RiseTaskViewTimer = Stopwatch.StartNew(); private static readonly Stopwatch DoublePressTimer = Stopwatch.StartNew(); private void RegisterHotKey( IntPtr hWnd ) { foreach ( var (k, kbInProfile) in Manager.Configs.KeyBindings! ) { var ghkCode = kbInProfile.GhkCode; if ( ghkCode == "" ) continue; var func = Const.Hotkey.GetFuncDesc( k ); var messageId = Const.Hotkey.GetKeyBinding( k ).MessageId; var hotkeyStr = ghkCode.Replace( Const.Hotkey.NONE + Const.Hotkey.SPLITTER, "" ); var arr = ghkCode.Split( Const.Hotkey.SPLITTER ); if ( arr.Length == 5 ) { var km = arr[0] == Const.Hotkey.NONE ? GHK.KeyModifiers.None : GHK.KeyModifiers.WindowsKey; km |= arr[1] == Const.Hotkey.NONE ? GHK.KeyModifiers.None : GHK.KeyModifiers.Ctrl; km |= arr[2] == Const.Hotkey.NONE ? GHK.KeyModifiers.None : GHK.KeyModifiers.Alt; km |= arr[3] == Const.Hotkey.NONE ? GHK.KeyModifiers.None : GHK.KeyModifiers.Shift; try { var key = Enum.Parse( arr[4] ); Logger.Info( string.Format( "Register Global HotKey [{0}] For \"{1}\", {2}", hotkeyStr, func, GHK.RegHotKey( hWnd, messageId, km, KeyInterop.VirtualKeyFromKey( key ) ) ? "Success" : "Fail" ) ); } catch ( Exception ex ) { Logger.Error( string.Format( "Register Global HotKey [{0}] For \"{1}\" Error: {2}", hotkeyStr, func, ex.Message ) ); } } } var keyboardHookProc = new User32.HookProc( KeyboardHookCallback ); Logger.Info( "Set Windows LowLevelKeyboardProc Hook" ); LLKH.SetHook( keyboardHookProc ); if ( Manager.CurrentProfile.Mouse.UseWheelSwitchDesktopWhenOnTaskbar ) { EnableMouseHook(); } } private void EnableMouseHook() { Logger.Info( "Set Windows LowLevelMouseProc Hook" ); LowLevelMouseHook.SetHook( MouseHookCallback ); } private static void DisableMouseHook() { Logger.Info( "Unset Windows LowLevelMouseProc Hook" ); LowLevelMouseHook.UnHook(); } private IntPtr KeyboardHookCallback( int nCode, IntPtr wParam, IntPtr lParam ) { if ( nCode >= 0 ) { var info = (LLKH.KBDLLHOOKSTRUCT)Marshal.PtrToStructure( lParam, typeof( LLKH.KBDLLHOOKSTRUCT ) ); var keyType = (int)wParam; if ( IsShowing() && Manager.Configs.Cluster.EnableWindowFilter && info.vkCode == (int)Keys.LShiftKey ) { switch ( keyType ) { case LLKH.WM_KEYUP: DoublePressTimer.Restart(); break; case LLKH.WM_KEYDOWN: { if ( DoublePressTimer.ElapsedMilliseconds < Manager.Configs.Cluster.ToggleWindowFilterDoublePressMaxInterval ) { User32.PostMessage( Handle, WinMsg.WM_HOTKEY, UserMessage.ToggleWindowFilter, 0 ); return LowLevelHooks.Handled; } break; } } } if ( keyType != LLKH.WM_KEYDOWN ) goto NEXT; ///////////////////////////////////////////////////////////////////////////////// // hook [LWin+Tab] to replace TaskView if ( info.vkCode == (int)Keys.Tab && LLKH.IsKeyHold( Keys.LWin ) && !( LLKH.IsKeyHold( Keys.ControlKey ) || LLKH.IsKeyHold( Keys.ShiftKey ) ) ) { if ( ( info.flags & LLKH.KBDLLHOOKSTRUCTFlags.LLKHF_INJECTED ) == 0 ) // not come from fake input { LLKH.MultipleKeyPress( new List {(Keys)LLKH.DUMMY_KEY} ); User32.PostMessage( Handle, WinMsg.WM_HOTKEY, UserMessage.RiseView, 0 ); return LowLevelHooks.Handled; } goto NEXT; } ///////////////////////////////////////////////////////////////////////////////// // since we hook default [LWin+Tab], // we should use a alternative way to rise the TaskView in case user want it. // here choose [Ctrl+LWin+Shift+Tab] to try to avoid conflicts if ( info.vkCode == (int)Keys.Tab && LLKH.IsKeyHold( Keys.LWin ) && LLKH.IsKeyHold( Keys.ControlKey ) && LLKH.IsKeyHold( Keys.ShiftKey ) ) { if ( ( info.flags & LLKH.KBDLLHOOKSTRUCTFlags.LLKHF_INJECTED ) == 0 // not come from fake input && RiseTaskViewTimer.ElapsedMilliseconds > Const.RiseViewInterval ) { LLKH.MultipleKeyPress( new List {(Keys)LLKH.DUMMY_KEY} ); LLKH.MultipleKeyUp( new List {Keys.ControlKey, Keys.LWin, Keys.ShiftKey, Keys.Tab} ); LLKH.MultipleKeyPress( new List {Keys.LWin, Keys.Tab} ); LLKH.MultipleKeyDown( new List {Keys.ControlKey, Keys.LWin, Keys.ShiftKey} ); RiseTaskViewTimer.Restart(); } return LowLevelHooks.Handled; } ///////////////////////////////////////////////////////////////////////////////// // hook [LWin+LCtrl+] for switch virtual desktop if ( LLKH.IsKeyHold( Keys.LWin ) && LLKH.IsKeyHold( Keys.LControlKey ) && !( LLKH.IsKeyHold( Keys.ShiftKey ) || LLKH.IsKeyHold( Keys.Menu ) ) ) { var key = (Keys)info.vkCode; switch ( key ) { case Keys.Left: case Keys.Right: case Keys.Up: case Keys.Down: User32.PostMessage( Handle, WinMsg.WM_HOTKEY, UserMessage.SwitchDesktop, (ulong)key ); return LowLevelHooks.Handled; } goto NEXT; } ///////////////////////////////////////////////////////////////////////////////// // hook [Esc] to hide MainView if ( info.vkCode == (int)Keys.Escape && IsShowing() ) { HideAll(); return LowLevelHooks.Handled; } } NEXT: return User32.CallNextHookEx( LLKH.HookId, nCode, wParam, lParam ); } private IntPtr MouseHookCallback( int nCode, IntPtr wParam, IntPtr lParam ) { if ( nCode < 0 ) goto NEXT; var hTaskbar = User32.FindWindow( Const.TaskbarWndClass, "" ); if ( hTaskbar == IntPtr.Zero ) goto NEXT; var info = (LowLevelMouseHook.MSLLHOOKSTRUCT)Marshal.PtrToStructure( lParam, typeof( LowLevelMouseHook.MSLLHOOKSTRUCT ) ); var msg = (int)wParam; if ( msg == LowLevelMouseHook.WM_MOUSEWHEEL ) { var zOrder = WindowTool.GetZOrderByHandle( hTaskbar ); if ( zOrder > Manager.CurrentProfile.Mouse.TaskbarVisibilityThreshold ) goto NEXT; var rect = new RECT(); _ = User32.GetWindowRect( hTaskbar, ref rect ); if ( info.pt.X >= rect.Left && info.pt.Y > rect.Top ) { uint dir; if ( LLKH.IsKeyHold( Keys.ShiftKey ) ) { dir = (uint)( info.mouseData >> 16 > 0 ? Keys.Up : Keys.Down ); } else { dir = (uint)( info.mouseData >> 16 > 0 ? Keys.Left : Keys.Right ); } User32.PostMessage( Handle, WinMsg.WM_HOTKEY, UserMessage.SwitchDesktop, dir ); return LowLevelHooks.Handled; } } NEXT: return User32.CallNextHookEx( LowLevelMouseHook.HookId, nCode, wParam, lParam ); } private void Window_Closing( object sender, CancelEventArgs e ) { Logger.Info( "Unset Windows LowLevelKeyboardProc Hook" ); LLKH.UnHook(); DisableMouseHook(); Logger.Info( "Unregister Global HotKeys" ); GHK.UnRegAllHotKey(); } } } ================================================ FILE: VirtualSpace/MainWindow.layout.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Effects; using System.Windows.Threading; using VirtualSpace.Config; using VirtualSpace.Config.Entity; using VirtualSpace.Helpers; using VirtualSpace.VirtualDesktop; using VirtualSpace.VirtualDesktop.Api; namespace VirtualSpace { public partial class MainWindow { private static int _desktopCount; private static UserInterface Ui => Manager.CurrentProfile.UI; private static int RowsCols { get; set; } private static DropShadowEffect _borderShadowDefault; private static DropShadowEffect _borderShadowCurrent; public static void ResetMainGrid() { var vdCount = DesktopWrapper.Count; if ( vdCount == _desktopCount ) return; var rowsCols = (int)Math.Ceiling( Math.Sqrt( vdCount ) ); var mainGrid = _instance.MainGrid; mainGrid.Children.Clear(); mainGrid.RowDefinitions.Clear(); mainGrid.ColumnDefinitions.Clear(); if ( RowsCols != rowsCols ) { _instance.Dispatcher.Invoke( new Action( () => { } ), DispatcherPriority.ContextIdle, null ); } var borderBrushDefault = new SolidColorBrush {Color = Color.FromRgb( Ui.VDWDefaultBackColor.R, Ui.VDWDefaultBackColor.G, Ui.VDWDefaultBackColor.B )}; for ( var r = 0; r < rowsCols; r++ ) { mainGrid.RowDefinitions.Add( new RowDefinition() ); mainGrid.ColumnDefinitions.Add( new ColumnDefinition() ); for ( var c = 0; c < rowsCols; c++ ) { var border = new Border { Margin = new Thickness( Ui.VDWMargin ), BorderThickness = new Thickness( Ui.VDWBorderSize ), BorderBrush = borderBrushDefault, Effect = _borderShadowDefault, Background = Brushes.Transparent }; Grid.SetRow( border, r ); Grid.SetColumn( border, c ); mainGrid.Children.Add( border ); } } _desktopCount = vdCount; // remember last count RowsCols = rowsCols; _instance.UpdateLayout(); } public static void ResetMainGridForSingleDesktop( int vdIndex ) { var vdCount = DesktopWrapper.Count; var rowsCols = (int)Math.Ceiling( Math.Sqrt( vdCount ) ); vdIndex = VirtualDesktopManager.GetMatrixIndexByVdIndex( vdIndex ); var bigRow = vdIndex / rowsCols; var bigCol = vdIndex % rowsCols; var bigGridLength = new GridLength( 1, GridUnitType.Star ); var smallGridLength = new GridLength( 0 ); var mainGrid = _instance.MainGrid; mainGrid.Children.Clear(); mainGrid.RowDefinitions.Clear(); mainGrid.ColumnDefinitions.Clear(); _instance.Dispatcher.Invoke( new Action( () => { } ), DispatcherPriority.ContextIdle, null ); var borderBrushDefault = new SolidColorBrush {Color = Color.FromRgb( Ui.VDWDefaultBackColor.R, Ui.VDWDefaultBackColor.G, Ui.VDWDefaultBackColor.B )}; for ( var r = 0; r < rowsCols; r++ ) { var height = bigRow == r ? bigGridLength : smallGridLength; mainGrid.RowDefinitions.Add( new RowDefinition {Height = height} ); for ( var c = 0; c < rowsCols; c++ ) { if ( mainGrid.ColumnDefinitions.Count < rowsCols ) { var width = bigCol == c ? bigGridLength : smallGridLength; mainGrid.ColumnDefinitions.Add( new ColumnDefinition {Width = width} ); } var border = mainGrid.ColumnDefinitions[c].Width == smallGridLength ? new Border() : new Border { Margin = new Thickness( Ui.VDWMargin ), BorderThickness = new Thickness( Ui.VDWBorderSize ), BorderBrush = borderBrushDefault, Effect = _borderShadowDefault, Background = Brushes.Transparent }; Grid.SetRow( border, r ); Grid.SetColumn( border, c ); mainGrid.Children.Add( border ); } } _desktopCount = 1; // single, single, single RowsCols = rowsCols; _instance.UpdateLayout(); } public static void UpdateHoverBorder( int hover ) { var borderColorHover = new SolidColorBrush {Color = Color.FromRgb( Ui.VDWHighlightBackColor.R, Ui.VDWHighlightBackColor.G, Ui.VDWHighlightBackColor.B )}; var borderColorDefault = new SolidColorBrush {Color = Color.FromRgb( Ui.VDWDefaultBackColor.R, Ui.VDWDefaultBackColor.G, Ui.VDWDefaultBackColor.B )}; for ( var i = 0; i < _desktopCount; i++ ) { var border = (Border)_instance.MainGrid.Children[i]; border.BorderBrush = i == hover ? borderColorHover : borderColorDefault; } } public static void RenderCellBorder() { var currentMatrixIndex = VirtualDesktopManager.GetMatrixIndexByVdIndex( VirtualDesktopManager.GetVdIndexByGuid( DesktopWrapper.CurrentGuid ) ); var borderColorHover = Color.FromRgb( Ui.VDWHighlightBackColor.R, Ui.VDWHighlightBackColor.G, Ui.VDWHighlightBackColor.B ); var borderBrushDefault = new SolidColorBrush {Color = Color.FromRgb( Ui.VDWDefaultBackColor.R, Ui.VDWDefaultBackColor.G, Ui.VDWDefaultBackColor.B )}; var borderBrushCurrent = new SolidColorBrush {Color = Color.FromRgb( Ui.VDWCurrentBackColor.R, Ui.VDWCurrentBackColor.G, Ui.VDWCurrentBackColor.B )}; for ( var i = 0; i < Math.Pow( RowsCols, 2 ); i++ ) { var border = (Border)_instance.MainGrid.Children[i]; if ( i == currentMatrixIndex ) { border.Effect = _borderShadowCurrent; border.BorderBrush = borderBrushCurrent; } else { var effect = border.Effect as DropShadowEffect; var brush = border.BorderBrush as SolidColorBrush; if ( effect?.Color == Colors.White || brush?.Color == borderColorHover ) { border.Effect = _borderShadowDefault; border.BorderBrush = borderBrushDefault; } } } } public static Point GetCellLocationByMatrixIndex( int index ) { if ( _instance.Dispatcher.CheckAccess() ) { return _instance.MainGrid.Children[index].TranslatePoint( new Point(), _instance ); } return _instance.Dispatcher.Invoke( () => _instance.MainGrid.Children[index].TranslatePoint( new Point(), _instance ) ); } public static Size GetCellSizeByMatrixIndex( int index ) { return _instance.MainGrid.Children[index].RenderSize; } public static int InCell( Point p ) { var cells = _instance.MainGrid.Children; var index = -1; var dpi = SysInfo.Dpi; for ( var i = 0; i < cells.Count; i++ ) { var topLeft = cells[i].TranslatePoint( new Point(), _instance ); topLeft = new Point( topLeft.X * dpi.ScaleX, topLeft.Y * dpi.ScaleY ); var bottomRight = new Point( topLeft.X + cells[i].RenderSize.Width * dpi.ScaleX, topLeft.Y + cells[i].RenderSize.Height * dpi.ScaleY ); var rect = new Rect( topLeft, bottomRight ); if ( rect.Contains( p ) ) { index = i; break; } } return index; } private void InitCellBorderShadowEffect() { _borderShadowDefault = Resources["VdwShadowDefault"] as DropShadowEffect; _borderShadowCurrent = Resources["VdwShadowCurrent"] as DropShadowEffect; } } } ================================================ FILE: VirtualSpace/MainWindow.main.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Diagnostics; using System.Windows; using System.Windows.Interop; using System.Windows.Media; using VirtualSpace.Config; using VirtualSpace.Factory; using VirtualSpace.Helpers; using VirtualSpace.Tools; using VirtualSpace.VirtualDesktop; using VirtualSpace.VirtualDesktop.Api; using ConfigManager = VirtualSpace.Config.Manager; namespace VirtualSpace { public partial class MainWindow { private static readonly Stopwatch RiseViewTimer = Stopwatch.StartNew(); private static readonly Stopwatch SwitchDesktopTimer = Stopwatch.StartNew(); private static MainWindow _instance; private static long _forceSwitchOnTimeout; private IAppController _acForm; public static IAppController AcForm { get { if ( _instance._acForm is null ) { _instance._acForm = AppControllerFactory.Create(); _instance._acForm.SetMainWindowHandle( _instance.Handle ); } return _instance._acForm; } private set => _instance._acForm = value; } private MainWindow() { InitializeComponent(); DataContext = this; _instance = this; Left = 0; Top = 0; Width = SystemParameters.PrimaryScreenWidth; Height = SystemParameters.PrimaryScreenHeight; Topmost = true; Title = Const.Window.VD_FRAME_TITLE; } public IntPtr Handle { get; private set; } public static MainWindow GetMainWindow() { return _instance; } public static MainWindow Create( IAppController ac ) { var mw = new MainWindow { _acForm = ac, Background = new SolidColorBrush( Color.FromArgb( Ui.CanvasOpacity, Ui.CanvasBackColor.R, Ui.CanvasBackColor.G, Ui.CanvasBackColor.B ) ), BlurOpacity = Ui.CanvasOpacity, BlurBackgroundColor = Ui.CanvasBackColor.GetLongOfColor() }; new WindowInteropHelper( mw ).EnsureHandle(); mw.InitCellBorderShadowEffect(); return mw; } public static void NotifyDesktopManagerReset() { User32.SendMessage( _instance.Handle, (int)_instance._taskbarCreatedMessage, 0, 0 ); } protected override void OnSourceInitialized( EventArgs e ) { base.OnSourceInitialized( e ); Handle = new WindowInteropHelper( this ).EnsureHandle(); var source = HwndSource.FromHwnd( Handle ); source?.AddHook( WndProc ); Bootstrap(); } private async void Window_Loaded( object sender, RoutedEventArgs e ) { VirtualDesktopManager.Bootstrap(); await VirtualDesktopManager.InitLayout(); UpdateVDIndexOnTrayIcon( DesktopWrapper.CurrentGuid ); DesktopManagerWrapper.ListenVirtualDesktopEvents(); VirtualDesktopManager.RegisterVirtualDesktopEvents(); if ( ConfigManager.Configs.Cluster.HideOnStart || ( (App)Application.Current ).HideOnStart ) return; VirtualDesktopManager.ShowAllVirtualDesktops(); VirtualDesktopManager.ShowVisibleWindowsForDesktops(); } private void Bootstrap() { AcForm.SetMainWindowHandle( Handle ); RegisterHotKey( Handle ); FixStyle(); EnableBlur(); RegisterSystemMessages(); } public void FakeHide() { Hide(); } private static void BringToTop( int processId = 0 ) { TopShow(); VirtualDesktopManager.FixLayout(); VirtualDesktopManager.ShowAllVirtualDesktops(); if ( processId > 0 ) { VirtualDesktopManager.ShowVisibleWindowsForDesktops( null, processId ); } else { VirtualDesktopManager.ShowVisibleWindowsForDesktops(); } if ( _instance.Canvas.RowDefinitions[1].Height.Value > 0 ) _instance.ShowFilterWindow(); } private static void BringToTopForCurrentVd( int processId = 0 ) { TopShow(); var cvd = VirtualDesktopManager.GetCurrentVdw(); cvd.MakeTheOnlyOne( processId ); } private static void TopShow() { CheckScreenArea(); _instance.Left = 0; _instance.Top = 0; _instance.Show(); } private static void CheckScreenArea() { if ( (int)_instance.Width == (int)SystemParameters.PrimaryScreenWidth && (int)_instance.Height == (int)SystemParameters.PrimaryScreenHeight ) return; _instance.Width = SystemParameters.PrimaryScreenWidth; _instance.Height = SystemParameters.PrimaryScreenHeight; } public static void HideAll() { _instance.Hide(); HideFilterWindow(); VirtualDesktopManager.HideAllVirtualDesktops(); } public static bool IsShowing() { return _instance.IsVisible; } public static void UpdateVDIndexOnTrayIcon( Guid guid ) { if ( !Manager.Configs.Cluster.ShowVDIndexOnTrayIcon ) { TrayIcon.InitTrayIcon(); return; } var i = ConfigManager.CurrentProfile.DesktopOrder.IndexOf( guid ); var index = ConfigManager.CurrentProfile.UI.ShowVdIndexType == 0 ? i : i + 1; TrayIcon.UpdateVDIndexOnTrayIcon( index.ToString() ); } private static void TryRunAsAdmin() { RestartApp( true ); } private static void RestartApp( bool runas = false ) { var app = (App)Application.Current; var psi = new ProcessStartInfo { FileName = ConfigManager.AppPath, UseShellExecute = true }; if ( runas ) psi.Verb = "runas"; try { app.ReleaseMutex(); Process.Start( psi ); Application.Current.Shutdown(); } catch { App.TryMutex(); } } public static void Quit() { _instance.Close(); Application.Current.Shutdown(); } } } ================================================ FILE: VirtualSpace/MainWindow.message.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Input; using VirtualSpace.AppLogs; using VirtualSpace.Commons; using VirtualSpace.Config; using VirtualSpace.Factory; using VirtualSpace.Helpers; using VirtualSpace.Plugin; using VirtualSpace.Tools; using VirtualSpace.VirtualDesktop; using VirtualSpace.VirtualDesktop.Api; namespace VirtualSpace { public partial class MainWindow { private uint _taskbarCreatedMessage; private void RegisterSystemMessages() { _taskbarCreatedMessage = User32.RegisterWindowMessage( Const.TaskbarCreated ); foreach ( var strMsg in PluginHost.CareAboutMessages.Keys ) { PluginHost.CareAboutMessages[strMsg] = User32.RegisterWindowMessage( strMsg ); } } private void Window_MouseDown( object sender, MouseButtonEventArgs e ) { var profile = Manager.CurrentProfile; if ( e.ChangedButton == MouseButton.Left ) { switch ( profile.Mouse.LeftClickOnCanvas ) { case 0: break; case 1: HideAll(); break; default: HideAll(); break; } } else if ( e.ChangedButton == MouseButton.Right ) { switch ( profile.Mouse.RightClickOnCanvas ) { case 0: break; case 1: HideAll(); break; default: HideAll(); break; } } else if ( e.ChangedButton == MouseButton.Middle ) { switch ( profile.Mouse.MiddleClickOnCanvas ) { case 0: break; case 1: HideAll(); break; default: HideAll(); break; } } } private IntPtr WndProc( IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled ) { if ( msg == _taskbarCreatedMessage ) { Logger.Warning( "explorer.exe restarted, reset DesktopManager and restart all Plugins." ); DesktopManagerWrapper.ResetDesktopManager(); foreach ( var plugin in PluginHost.Plugins ) { PluginHost.RestartPlugin( plugin ); } goto RETURN; } if ( PluginHost.CareAboutMessages.ContainsValue( (uint)msg ) ) { var (key, _) = PluginHost.CareAboutMessages.First( m => m.Value == msg ); foreach ( var plugin in PluginHost.Plugins.Where( plugin => plugin.RestartPolicy?.Trigger == PolicyTrigger.WINDOWS_MESSAGE && plugin.RestartPolicy.Enabled && plugin.RestartPolicy.Values.Contains( key ) ) ) { Logger.Info( $"Restart Plugin {plugin.Display} because {key}" ); PluginHost.RestartPlugin( plugin ); } foreach ( var plugin in PluginHost.Plugins.Where( plugin => plugin.ClosePolicy?.Trigger == PolicyTrigger.WINDOWS_MESSAGE && plugin.ClosePolicy.Enabled && plugin.ClosePolicy.Values.Contains( key ) ) ) { Logger.Info( $"Close Plugin {plugin.Display} because {key}" ); PluginHost.ClosePlugin( plugin ); } goto RETURN; } void SwitchByIndex( int index ) { if ( Manager.CurrentProfile.DesktopOrder.Count > index ) DesktopWrapper.MakeVisibleByGuid( Manager.CurrentProfile.DesktopOrder[index] ); } void MoveForegroundWindowToDesktop( int sysIndex, bool follow = false ) { if ( sysIndex >= DesktopWrapper.Count ) return; var fw = User32.GetForegroundWindow(); if ( fw == IntPtr.Zero ) return; try { DesktopWrapper.MoveWindowToDesktop( fw, sysIndex ); if ( !follow ) return; WindowTool.ActiveWindow( fw, sysIndex ); } catch ( Exception ex ) { Logger.Error( $"Move Foreground Window To Desktop[{sysIndex}] ∵ " + ex.Message ); } } switch ( msg ) { case WinMsg.WM_SYSCOMMAND: var wP = wParam.ToInt32(); if ( wP is WinMsg.SC_RESTORE or WinMsg.SC_MINIMIZE or WinMsg.SC_MAXIMIZE ) handled = true; break; case WinMsg.WM_HOTKEY: var um = wParam.ToInt32(); switch ( um ) { case > UserMessage.Meta.SVD_START and <= UserMessage.Meta.SVD_END: SwitchByIndex( um % UserMessage.Meta.SVD_START - 1 ); break; case > UserMessage.Meta.MW_START and <= UserMessage.Meta.MW_END: MoveForegroundWindowToDesktop( um % UserMessage.Meta.MW_START - 1 ); break; case > UserMessage.Meta.MWF_START and <= UserMessage.Meta.MWF_END: MoveForegroundWindowToDesktop( um % UserMessage.Meta.MWF_START - 1, true ); break; case UserMessage.RiseView: if ( Manager.Configs.Cluster.HideMainViewIfItsShown && IsShowing() ) { HideAll(); } else if ( RiseViewTimer.ElapsedMilliseconds > Const.RiseViewInterval ) { BringToTop(); RiseViewTimer.Restart(); } break; case UserMessage.RiseViewForActiveApp: _ = User32.GetWindowThreadProcessId( User32.GetForegroundWindow(), out var processId ); if ( Manager.Configs.Cluster.HideMainViewIfItsShown && IsShowing() ) { HideAll(); } else if ( RiseViewTimer.ElapsedMilliseconds > Const.RiseViewInterval ) { BringToTop( processId ); RiseViewTimer.Restart(); } break; case UserMessage.RiseViewForCurrentVD: if ( Manager.Configs.Cluster.HideMainViewIfItsShown && IsShowing() ) { HideAll(); } else if ( RiseViewTimer.ElapsedMilliseconds > Const.RiseViewInterval ) { BringToTopForCurrentVd(); RiseViewTimer.Restart(); } break; case UserMessage.RiseViewForActiveAppInCurrentVD: _ = User32.GetWindowThreadProcessId( User32.GetForegroundWindow(), out var pId ); if ( Manager.Configs.Cluster.HideMainViewIfItsShown && IsShowing() ) { HideAll(); } else if ( RiseViewTimer.ElapsedMilliseconds > Const.RiseViewInterval ) { BringToTopForCurrentVd( pId ); RiseViewTimer.Restart(); } break; case UserMessage.ShowAppController: AcForm.BringToTop(); break; case UserMessage.ToggleWindowFilter: ToggleWindowFilter(); break; case UserMessage.RestartAppController: AcForm.Quit(); AcForm = AppControllerFactory.Create(); AcForm.SetMainWindowHandle( Handle ); AcForm.BringToTop(); UpdateVDIndexOnTrayIcon( DesktopWrapper.CurrentGuid ); break; case UserMessage.AppControllerClosed: AcForm = null; break; case UserMessage.SwitchDesktop: SwitchDesktopByDirection( lParam ); break; case UserMessage.SwitchBackToLastDesktop: SwitchToDesktopById( VirtualDesktopManager.LastDesktopId ); break; case UserMessage.DesktopArrangement: if ( IsShowing() ) { VirtualDesktopManager.ShowAllVirtualDesktops(); } break; case UserMessage.RefreshTrayIcon: UpdateVDIndexOnTrayIcon( DesktopWrapper.CurrentGuid ); break; case UserMessage.UpdateTrayLang: TrayIcon.SetLang(); break; case UserMessage.RunAsAdministrator: TryRunAsAdmin(); goto RETURN; case UserMessage.RestartApp: RestartApp(); goto RETURN; case UserMessage.EnableMouseHook: EnableMouseHook(); goto RETURN; case UserMessage.DisableMouseHook: DisableMouseHook(); goto RETURN; case UserMessage.NavLeft: SwitchDesktopByDirection( (IntPtr)Keys.Left ); break; case UserMessage.NavRight: SwitchDesktopByDirection( (IntPtr)Keys.Right ); break; case UserMessage.NavUp: SwitchDesktopByDirection( (IntPtr)Keys.Up ); break; case UserMessage.NavDown: SwitchDesktopByDirection( (IntPtr)Keys.Down ); break; } break; case WinApi.UM_SWITCHDESKTOP: var targetMatrixIndex = wParam.ToInt32(); if ( targetMatrixIndex >= 0 && targetMatrixIndex < DesktopWrapper.Count ) { Interlocked.Exchange( ref _forceSwitchOnTimeout, 0 ); DesktopWrapper.MakeVisibleByGuid( Manager.CurrentProfile.DesktopOrder[VirtualDesktopManager.GetVdIndexByMatrixIndex( targetMatrixIndex )] ); } break; // case WinMsg.WM_MOUSEACTIVATE: // handled = true; // return new IntPtr( WinMsg.MA_NOACTIVATE ); } RETURN: return IntPtr.Zero; } private static void SwitchToDesktopById( Guid guid ) { if ( guid == Guid.Empty ) return; if ( SwitchDesktopTimer.ElapsedMilliseconds <= Const.SwitchDesktopInterval ) return; DesktopWrapper.MakeVisibleByGuid( guid ); SwitchDesktopTimer.Restart(); } private void SwitchDesktopByDirection( IntPtr lParam ) { if ( SwitchDesktopTimer.ElapsedMilliseconds <= Const.SwitchDesktopInterval ) return; var desktopOrder = Manager.CurrentProfile.DesktopOrder; var currentVdIndex = desktopOrder.IndexOf( DesktopWrapper.CurrentGuid ); var currentDesktopMatrixIndex = VirtualDesktopManager.GetMatrixIndexByVdIndex( currentVdIndex ); var dir = lParam.ToInt32(); var targetMatrixIndex = Navigation.CalculateTargetIndex( DesktopWrapper.Count, currentVdIndex, (Keys)dir, Manager.CurrentProfile.Navigation ); var vDsi = new VirtualDesktopSwitchInfo { hostHandle = Handle, vdCount = DesktopWrapper.Count, fromIndex = currentDesktopMatrixIndex, dir = dir, targetIndex = targetMatrixIndex }; var vDsiSize = Marshal.SizeOf( typeof( VirtualDesktopSwitchInfo ) ); var pVDsi = Marshal.AllocHGlobal( vDsiSize ); Marshal.StructureToPtr( vDsi, pVDsi, true ); var cds = new COPYDATASTRUCT { dwData = (IntPtr)WinApi.UM_SWITCHDESKTOP, cbData = vDsiSize, lpData = pVDsi }; var pCds = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( COPYDATASTRUCT ) ) ); Marshal.StructureToPtr( cds, pCds, true ); foreach ( var pluginInfo in PluginHost.Plugins.Where( p => p.Type == PluginType.VD_SWITCH_OBSERVER && User32.IsWindow( p.Handle ) ) ) { User32.SendMessage( pluginInfo.Handle, WinApi.WM_COPYDATA, 0, (ulong)pCds ); } //////////////////////////////////////////////////////////////////////////////////// // if none of plugins send back message after 100 ms, host will force switch desktop Interlocked.Increment( ref _forceSwitchOnTimeout ); Task.Run( () => { Thread.Sleep( 100 ); if ( _forceSwitchOnTimeout == 0 ) return; DesktopWrapper.MakeVisibleByGuid( desktopOrder[VirtualDesktopManager.GetVdIndexByMatrixIndex( targetMatrixIndex )] ); } ); Marshal.FreeHGlobal( pVDsi ); Marshal.FreeHGlobal( pCds ); SwitchDesktopTimer.Restart(); } } } ================================================ FILE: VirtualSpace/MainWindow.style.cs ================================================ /* Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System.Runtime.InteropServices; using VirtualSpace.Helpers; namespace VirtualSpace { public partial class MainWindow { private uint _blurOpacity; private uint BlurBackgroundColor { get; set; } = 0x555555; private uint BlurOpacity { get => _blurOpacity; set { _blurOpacity = value; EnableBlur(); } } private void FixStyle() { var style = User32.GetWindowLong( Handle, (int)GetWindowLongFields.GWL_STYLE ); style = unchecked(style | (int)0x80000000); // WS_POPUP User32.SetWindowLongPtr( new HandleRef( this, Handle ), (int)GetWindowLongFields.GWL_STYLE, style ); var exStyle = User32.GetWindowLong( Handle, (int)GetWindowLongFields.GWL_EXSTYLE ); exStyle |= 0x08000000; // WS_EX_NOACTIVATE exStyle &= ~0x00040000; // WS_EX_APPWINDOW User32.SetWindowLongPtr( new HandleRef( this, Handle ), (int)GetWindowLongFields.GWL_EXSTYLE, exStyle ); } private void EnableBlur() { var accent = new VisualEffects.AccentPolicy { AccentState = VisualEffects.AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND, GradientColor = ( BlurOpacity << 24 ) | ( BlurBackgroundColor & 0xFFFFFF ) }; var accentStructSize = Marshal.SizeOf( accent ); var accentPtr = Marshal.AllocHGlobal( accentStructSize ); Marshal.StructureToPtr( accent, accentPtr, false ); var data = new VisualEffects.WindowCompositionAttributeData { Attribute = VisualEffects.WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; _ = VisualEffects.SetWindowCompositionAttribute( Handle, ref data ); Marshal.FreeHGlobal( accentPtr ); } } } ================================================ FILE: VirtualSpace/MainWindow.xaml ================================================  ================================================ FILE: VirtualSpace/MainWindow.xaml.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System.Windows; namespace VirtualSpace { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { } } ================================================ FILE: VirtualSpace/Program.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.IO; using System.Reflection; using System.Windows; using VirtualSpace.AppLogs; using VirtualSpace.Config; using VirtualSpace.Helpers; namespace VirtualSpace { public static class Program { [STAThread] public static void Main() { LogManager.InitLogger( Const.Settings.LogsFolder ); AppDomain.CurrentDomain.AssemblyResolve += AutoResolver; var app = new App { ShutdownMode = ShutdownMode.OnMainWindowClose }; app.Run(); } private static Assembly? AutoResolver( object? sender, ResolveEventArgs eventArgs ) { string dllName; const string resName = ".Resources."; const string dllExt = ".dll"; var programName = Assembly.GetExecutingAssembly().GetName().Name; var shortAssemblyName = new AssemblyName( eventArgs.Name ).Name; if ( shortAssemblyName.EndsWith( ".resources" ) ) return null; switch ( shortAssemblyName ) { case "VirtualDesktop10": Logger.Debug( "[Init]Load VirtualDesktop10.dll" ); dllName = programName + resName + "VirtualDesktop10" + dllExt; break; case "VirtualDesktop11": var ver = SysInfo.OSVersion; switch ( ver.Build ) { case <= 22489: Logger.Debug( "[Init]Load VirtualDesktop11.dll 21H2" ); dllName = programName + resName + "VirtualDesktop11_21H2.dll"; break; case 22621: Logger.Debug( "[Init]Load VirtualDesktop11.dll 22H2" ); dllName = ver.Revision switch { < 2215 => programName + resName + "VirtualDesktop11.dll", < 3085 => programName + resName + "VirtualDesktop11_23H2.dll", _ => programName + resName + "VirtualDesktop11_22H2_3085.dll" }; break; case 22631: Logger.Debug( "[Init]Load VirtualDesktop11.dll 23H2" ); if ( ver.Revision >= 3085 ) { dllName = programName + resName + "VirtualDesktop11_23H2_3085.dll"; } else { dllName = programName + resName + "VirtualDesktop11_23H2.dll"; } break; case 26100: Logger.Debug("[Init]Load VirtualDesktop11.dll 24H2"); if (ver.Revision >= 2152) { dllName = programName + resName + "VirtualDesktop11_24H2.dll"; } else { dllName = programName + resName + "VirtualDesktop11_23H2.dll"; } break; default: Logger.Debug( "[Init]Load VirtualDesktop11.dll 22H2" ); dllName = programName + resName + "VirtualDesktop11.dll"; break; } break; default: dllName = programName + resName + shortAssemblyName + dllExt; break; } using var stream = typeof( Program ).Assembly.GetManifestResourceStream( dllName ); var rawAssembly = new byte[stream.Length]; stream.Read( rawAssembly, 0, rawAssembly.Length ); // try // { // var filepath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, shortAssemblyName + dllExt ); // File.WriteAllBytesAsync( filepath, rawAssembly ); // } // catch // { // // ignored // } return Assembly.Load( rawAssembly ); } } } ================================================ FILE: VirtualSpace/Tools/SystemTool.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Windows; namespace VirtualSpace.Tools { public static class SystemTool { public static bool VersionCheck() { var version = Environment.OSVersion.Version; if ( version is {Major: >= 10, Build: >= 17763 and <= 26200} ) { return true; } MessageBox.Show( Agent.Langs.GetString( "VersionCheckFail" ), @"Error" ); return false; } } } ================================================ FILE: VirtualSpace/Tools/TrayIcon.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Globalization; using System.Resources; using System.Windows.Forms; using VirtualSpace.Helpers; using ConfigManager = VirtualSpace.Config.Manager; namespace VirtualSpace.Tools { public static class TrayIcon { private static readonly NotifyIcon Ti = new(); private static readonly ContextMenuStrip TiMenu = new(); private static readonly ToolStripMenuItem TraySettings = new(); private static readonly ToolStripSeparator ToolStripSeparator = new(); private static readonly ToolStripMenuItem TrayQuit = new(); private static readonly ResourceManager ImageManager = Agent.Images; static TrayIcon() { SetLang(); InitTrayIcon(); TraySettings.Click += ( sender, args ) => { MainWindow.AcForm.BringToTop(); }; TrayQuit.Click += ( sender, args ) => { MainWindow.Quit(); }; TiMenu.Items.AddRange( new ToolStripItem[] {TraySettings, ToolStripSeparator, TrayQuit} ); Ti.ContextMenuStrip = TiMenu; } public static void InitTrayIcon() { Ti.Icon = Images.BytesToIcon( ImageManager.GetObject( "TrayIcon" ) ); } public static void UpdateVDIndexOnTrayIcon( string index ) { if ( ConfigManager.Configs.Cluster.StyleOfVDIndexOnTrayIcon == 0 || index.Length > 2 ) { PaintVdIndexWithLogo( index ); return; } var backColor = "TrayIconBack_White"; var numberColor = "Black"; switch ( ConfigManager.Configs.Cluster.StyleOfVDIndexOnTrayIcon ) { case 1: backColor = "TrayIconBack_White"; numberColor = "Black"; break; case 2: backColor = "TrayIconBack_Black"; numberColor = "White"; break; } using var bitmap = Images.BytesToBitmap( ImageManager.GetObject( $@"{backColor}" ) ); if ( index.Length == 1 ) { using var number = Images.BytesToBitmap( ImageManager.GetObject( $@"Big{index}{numberColor}" ) ); using var gBack = Graphics.FromImage( bitmap ); gBack.CompositingMode = CompositingMode.SourceOver; number.MakeTransparent(); gBack.DrawImage( number, new Point( 0, 0 ) ); } else { using var number1 = Images.BytesToBitmap( ImageManager.GetObject( $@"Small{index[0]}{numberColor}" ) ); using var number2 = Images.BytesToBitmap( ImageManager.GetObject( $@"Small{index[1]}{numberColor}" ) ); number1.MakeTransparent(); number2.MakeTransparent(); using var gBack = Graphics.FromImage( bitmap ); gBack.CompositingMode = CompositingMode.SourceOver; gBack.DrawImage( number1, new Point( 0, 0 ) ); gBack.DrawImage( number2, new Point( bitmap.Width / 2, 0 ) ); } Ti.Icon = Icon.FromHandle( bitmap.GetHicon() ); } private static void PaintVdIndexWithLogo( string index ) { using var bitmap = Images.BytesToBitmap( ImageManager.GetObject( "TrayIconBack_Default" ) ); var rectF = new RectangleF( 0, 0, bitmap.Width, bitmap.Height ); var textFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; var fontSize = 210; var borderSize = 10; switch ( index.Length ) { case 1: fontSize = 210; borderSize = 20; break; case 2: fontSize = 160; borderSize = 30; break; case 3: fontSize = 110; borderSize = 30; break; } // fontSize and borderSize based on TrayIconBack_Default's size is 256x256 using var textFont = new Font( "Comic Sans MS", fontSize, FontStyle.Bold, GraphicsUnit.Pixel ); using var textBrush = new SolidBrush( ColorTranslator.FromHtml( "#FFFFFF" ) ); using var borderPen = new Pen( ColorTranslator.FromHtml( "#FF0000" ), borderSize ); borderPen.LineJoin = LineJoin.Round; // prevent "spikes" at the path using var gp = new GraphicsPath(); gp.AddString( index, textFont.FontFamily, (int)textFont.Style, textFont.Size, rectF, textFormat ); using var g = Graphics.FromImage( bitmap ); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; g.DrawPath( borderPen, gp ); g.FillPath( textBrush, gp ); g.Flush(); Ti.Icon = Icon.FromHandle( bitmap.GetHicon() ); } public static void SetLang() { CultureInfo.CurrentCulture = new CultureInfo( ConfigManager.CurrentProfile.UI.Language ); CultureInfo.CurrentUICulture = new CultureInfo( ConfigManager.CurrentProfile.UI.Language ); TraySettings.Text = Agent.Langs.GetString( "Tray.Menu.Settings" ); TrayQuit.Text = Agent.Langs.GetString( "Tray.Menu.Quit" ); } public static void Show() { Ti.Visible = true; } } } ================================================ FILE: VirtualSpace/Tools/WindowTool.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Runtime.InteropServices; using System.Windows.Forms; using VirtualSpace.AppLogs; using VirtualSpace.Helpers; using VirtualSpace.VirtualDesktop.Api; namespace VirtualSpace.Tools { public static class WindowTool { private static void MoveWindowToScreen( IntPtr hWnd, Screen destScreen ) { var srcScreen = Screen.FromHandle( hWnd ); if ( srcScreen.DeviceName == destScreen.DeviceName ) return; var wp = new WINDOWPLACEMENT(); wp.Length = Marshal.SizeOf( wp ); if ( !User32.GetWindowPlacement( hWnd, ref wp ) ) return; var rect = wp.NormalPosition; var targetX = destScreen.WorkingArea.X + rect.Left - srcScreen.WorkingArea.Left; var targetY = destScreen.WorkingArea.Y + rect.Top - srcScreen.WorkingArea.Top; var targetWidth = rect.Right - rect.Left; var targetHeight = rect.Bottom - rect.Top; switch ( wp.ShowCmd ) { case ShowState.SW_SHOWMAXIMIZED: _ = User32.ShowWindow( hWnd, (short)ShowState.SW_RESTORE ); User32.SetWindowPos( hWnd, IntPtr.Zero, targetX, targetY, targetWidth, targetHeight, 0 ); _ = User32.ShowWindow( hWnd, (short)ShowState.SW_MAXIMIZE ); break; case ShowState.SW_MINIMIZE: case ShowState.SW_SHOWMINIMIZED: _ = User32.ShowWindow( hWnd, (short)ShowState.SW_RESTORE ); User32.SetWindowPos( hWnd, IntPtr.Zero, targetX, targetY, targetWidth, targetHeight, 0 ); // User32.ShowWindow( mi.Vw.Handle, (short)ShowState.SW_SHOWMINIMIZED ); break; case ShowState.SW_NORMAL: User32.SetWindowPos( hWnd, IntPtr.Zero, targetX, targetY, targetWidth, targetHeight, 0 ); break; } } public static void MoveWindowToScreen( IntPtr hWnd, int index ) { var allScreens = Screen.AllScreens; if ( index < 0 || index > allScreens.Length ) return; MoveWindowToScreen( hWnd, allScreens[index] ); } public static void MoveWindowToScreen( IntPtr hWnd, string deviceName ) { var allScreens = Screen.AllScreens; var index = -1; for ( var i = 0; i < allScreens.Length; i++ ) { if ( deviceName == allScreens[i].DeviceName ) { index = i; break; } } if ( index < 0 ) return; MoveWindowToScreen( hWnd, allScreens[index] ); } public static int GetZOrderByHandle( IntPtr hWnd ) { var index = 0; _ = User32.EnumWindows( ( wnd, param ) => { index++; return hWnd != wnd; }, 0 ); return index; } public static void ActiveWindow( IntPtr hWnd, int desktopIndex ) { if ( DesktopWrapper.CurrentIndex != desktopIndex ) { Logger.Verbose( $"CHANGE CURRENT DESKTOP TO Desktop[{desktopIndex.ToString()}]" ); DesktopWrapper.MakeVisibleByIndex( desktopIndex ); } try { Logger.Verbose( "Try SwitchToThisWindow" ); User32.SwitchToThisWindow( hWnd, true ); Logger.Verbose( "SwitchToThisWindow success." ); } catch { ActiveWindowReserve( hWnd ); } } public static void ActiveWindow( IntPtr hWnd, Guid guid ) { if ( DesktopWrapper.CurrentGuid != guid ) { var sysIndex = DesktopWrapper.IndexFromGuid( guid ); Logger.Verbose( $"CHANGE CURRENT DESKTOP TO Desktop[{sysIndex.ToString()}]" ); DesktopWrapper.MakeVisibleByGuid( guid, false ); } try { Logger.Verbose( "Try SwitchToThisWindow" ); User32.SwitchToThisWindow( hWnd, true ); Logger.Verbose( "SwitchToThisWindow success." ); } catch { ActiveWindowReserve( hWnd ); } } private static void ActiveWindowReserve( IntPtr hWnd ) { if ( User32.IsIconic( hWnd ) ) { _ = User32.ShowWindow( hWnd, (short)ShowState.SW_RESTORE ); } else { User32.SetForegroundWindow( hWnd ); User32.BringWindowToTop( hWnd ); } } public static bool IsModalWindow( IntPtr hWnd ) { // child windows cannot have owners var style = User32.GetWindowLong( hWnd, (int)GetWindowLongFields.GWL_STYLE ); if ( ( style & (int)WindowStyles.WS_CHILD ) > 0 ) return false; var hWndOwner = User32.GetWindow( hWnd, GetWindowType.GW_OWNER ); if ( hWndOwner == IntPtr.Zero ) return false; // not an owned window if ( User32.IsWindowEnabled( hWndOwner ) ) return false; // owner is enabled return true; // an owned window whose owner is disabled } public static bool IsPopupToolWindow( IntPtr hWnd ) { var style = (uint)User32.GetWindowLong( hWnd, (int)GetWindowLongFields.GWL_STYLE ); return style == 0x96000000; // WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS } } } ================================================ FILE: VirtualSpace/VirtualDesktop/Daemon.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Text; using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; using VirtualSpace.AppLogs; using VirtualSpace.Commons; using VirtualSpace.Config; using VirtualSpace.Config.Events.Entity; using VirtualSpace.Config.Events.Expression; using VirtualSpace.Helpers; using VirtualSpace.Tools; using VirtualSpace.VirtualDesktop.Api; using ConfigManager = VirtualSpace.Config.Manager; namespace VirtualSpace.VirtualDesktop { internal static class Daemon { private static int _runlevel = 1; private static readonly ManualResetEvent CanRun = new( false ); private static readonly StringBuilder SbWinInfo = new( Const.WindowTitleMaxLength ); private static readonly Channel ActionConsumer = Channels.ActionChannel; private static readonly Channel VisibleWindowsProducer = Channels.VisibleWindowsChannel; private static async void WaitForAction() { while ( await ActionConsumer.Reader.WaitToReadAsync() ) { if ( !ActionConsumer.Reader.TryRead( out var action ) ) continue; if ( action.HideFromView ) { Logger.Debug( $"[RULE.Action]HIDE.Win {action.Handle.ToString( "X2" )}" ); Filters.WndHandleIgnoreListByManual.TryAdd( action.Handle, 0 ); } if ( action.MoveToScreen >= 0 ) { Logger.Debug( $"[RULE.Action]MOVE_TO_SCREEN.Win {action.Handle.ToString( "X2" )} TO Screen[{action.MoveToScreen.ToString()}]" ); WindowTool.MoveWindowToScreen( action.Handle, action.MoveToScreen ); } if ( action.PinApp ) { Logger.Debug( $"[RULE.Action]PIN.App of {action.Handle.ToString( "X2" )} TO All Desktops" ); try { DesktopWrapper.PinApp( action.Handle, false ); } catch { Logger.Error( $"[RULE.Action]PIN.App {action.Handle.ToString( "X2" )} Failed" ); } continue; // <- if PinApp, then PinWindow & MoveToDesktop is invalid } if ( action.PinWindow ) { Logger.Debug( $"[RULE.Action]PIN.Win {action.Handle.ToString( "X2" )} TO All Desktops" ); try { DesktopWrapper.PinWindow( action.Handle, false ); } catch { Logger.Error( $"[RULE.Action]PIN.Win {action.Handle.ToString( "X2" )} Failed" ); } continue; // <- if PinWindow, then MoveToDesktop is invalid } if ( action.MoveToDesktop >= 0 ) { try { Logger.Debug( $"[RULE.Action]MOVE.Win {action.Handle.ToString( "X2" )} TO Desktop[{action.MoveToDesktop.ToString()}]" ); DesktopWrapper.MoveWindowToDesktop( action.Handle, action.MoveToDesktop ); if ( action.FollowWindow ) { WindowTool.ActiveWindow( action.Handle, action.MoveToDesktop ); } } catch { CultureInfo.CurrentUICulture = new CultureInfo( ConfigManager.CurrentProfile.UI.Language ); Logger.Error( $"[RULE.Action]MOVE.Win {action.Handle.ToString( "X2" )} TO Desktop[{action.MoveToDesktop.ToString()}]", new NotifyObject { Title = Agent.Langs.GetString( "Error.Title" ), Message = string.Format( Agent.Langs.GetString( "Error.MoveWindowToDesktop" ), action.WindowTitle, action.RuleName ) } ); } } } } public static async void Start() { WaitForAction(); StartDaemon(); if ( ConfigManager.CurrentProfile.DaemonAutoStart ) { if ( ConfigManager.CurrentProfile.DaemonAutoStartDelay > 0 ) await Task.Delay( ConfigManager.CurrentProfile.DaemonAutoStartDelay * Const.OneSecond ); CanRun.Set(); } } public static void SetCanRun( bool isCanRun ) { if ( isCanRun ) { CanRun.Set(); } else { CanRun.Reset(); } } public static void SetRunLevel( int i ) { _runlevel = i < 1 ? 1 : i; } private static void StartDaemon() { Task.Factory.StartNew( () => { var sw = Stopwatch.StartNew(); while ( true ) { CanRun.WaitOne(); _ = User32.EnumWindows( WindowHandleFilter, 0 ); if ( sw.ElapsedMilliseconds >= Const.OneMinute ) { Logger.Debug( "Daemon running normally in last minute." ); sw.Restart(); } Thread.Sleep( _runlevel * Const.OneSecond ); } }, TaskCreationOptions.LongRunning ); } private static bool WindowHandleFilter( IntPtr hWnd, int lParam ) { if ( Conditions.WndHandleIgnoreListByRule.Contains( hWnd ) || Filters.WndHandleIgnoreListByError.Contains( hWnd ) || !User32.IsWindowVisible( hWnd ) || Filters.IsCloaked( hWnd ) ) return true; _ = User32.GetWindowText( hWnd, SbWinInfo, SbWinInfo.Capacity ); var title = SbWinInfo.ToString(); if ( string.IsNullOrEmpty( title ) || Filters.WndTitleIgnoreList.Contains( title ) ) return true; _ = User32.GetClassName( hWnd, SbWinInfo, SbWinInfo.Capacity ); var classname = SbWinInfo.ToString(); if ( Filters.WndClsIgnoreList.Contains( classname ) ) return true; switch ( classname ) { case "#32770" when WindowTool.IsModalWindow( hWnd ): case "Chrome_WidgetWin_1" or "MozillaDropShadowWindowClass" when WindowTool.IsPopupToolWindow( hWnd ): return true; } if ( classname != Const.WindowsUiCoreWindow ) { SendToCheckingRule( hWnd, title, classname ); } return true; } private static void SendToCheckingRule( IntPtr hWnd, string title, string classname ) { VisibleWindowsProducer.Writer.TryWrite( new Window { Title = title, WndClass = classname, Handle = hWnd } ); } } } ================================================ FILE: VirtualSpace/VirtualDesktop/DragWindow.Designer.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ namespace VirtualSpace.VirtualDesktop { partial class DragWindow { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose( bool disposing ) { if ( disposing && ( components != null ) ) { components.Dispose(); } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.SuspendLayout(); // // DragWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Black; this.ClientSize = new System.Drawing.Size(800, 450); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "DragWindow"; this.TransparencyKey = System.Drawing.Color.Black; this.ResumeLayout(false); } #endregion } } ================================================ FILE: VirtualSpace/VirtualDesktop/DragWindow.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Windows.Forms; using VirtualSpace.Config; namespace VirtualSpace.VirtualDesktop { public partial class DragWindow : Form { private DragWindow() { InitializeComponent(); } public IntPtr Thumb { get; set; } public static DragWindow CreateAndShow( int width, int height ) { var dw = new DragWindow(); dw.TopLevel = true; dw.TopMost = true; dw.ShowInTaskbar = false; dw.Width = width; dw.Height = height; dw.Text = Const.Window.VD_DRAG_TITLE; dw.Show(); return dw; } } } ================================================ FILE: VirtualSpace/VirtualDesktop/DragWindow.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: VirtualSpace/VirtualDesktop/Filters.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.Collections.Concurrent; using VirtualSpace.Config; using VirtualSpace.Helpers; namespace VirtualSpace.VirtualDesktop { public static class Filters { public static readonly string[] WndClsIgnoreList = { "Progman", "RainmeterMeterWindow", "SysDragImage", "DuiMenuWnd", "PerryShadowWnd", "SysShadow" }; public static readonly string[] WndTitleIgnoreList = { Const.Window.VD_FRAME_TITLE, Const.Window.VD_CONTAINER_TITLE, Const.Window.VD_DRAG_TITLE, Const.Window.VS_CONTROLLER_TITLE, Const.Window.VS_WINDOW_FILTER_TITLE, "WinFormsDesigner" }; public static readonly List WndHandleIgnoreListByError = new(); public static readonly ConcurrentDictionary WndHandleIgnoreListByManual = new(); public static bool IsCloaked( IntPtr handle ) { var HRESULT = DwmApi.DwmGetWindowAttribute( handle, (uint)DwmApi.DwmWindowAttribute.DWMWA_CLOAKED, out var cloaked, sizeof( uint ) ); return cloaked > 2; } } } ================================================ FILE: VirtualSpace/VirtualDesktop/Manager.arrangement.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using VirtualSpace.VirtualDesktop.Api; using ConfigManager = VirtualSpace.Config.Manager; namespace VirtualSpace.VirtualDesktop { internal static partial class VirtualDesktopManager { public static int GetMatrixIndexByVdIndex( int vdIndex ) { var rowsCols = (int)Math.Ceiling( Math.Sqrt( DesktopWrapper.Count ) ); var rc = Navigation.RowColFromIndex( rowsCols, vdIndex, ConfigManager.CurrentProfile.UI.DesktopArrangement ); var matrixIndex = Navigation.IndexFromRowCol( rowsCols, rc, 0 ); return matrixIndex; } public static int GetVdIndexByMatrixIndex( int matrixIndex ) { var rowsCols = (int)Math.Ceiling( Math.Sqrt( DesktopWrapper.Count ) ); var rc = Navigation.RowColFromIndex( rowsCols, matrixIndex, 0 ); var vdIndex = Navigation.IndexFromRowCol( rowsCols, rc, ConfigManager.CurrentProfile.UI.DesktopArrangement ); return vdIndex; } } } ================================================ FILE: VirtualSpace/VirtualDesktop/Manager.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using VirtualSpace.AppLogs; using VirtualSpace.Config; using VirtualSpace.Helpers; using VirtualSpace.VirtualDesktop.Api; namespace VirtualSpace.VirtualDesktop { internal static partial class VirtualDesktopManager { private static readonly List VisibleWindows = new(); private static readonly User32.EnumWindowsProc EnumWindowsProc = VisibleWindowFilter; private static readonly StringBuilder SbWinInfo = new( Const.WindowTitleMaxLength ); private static List _virtualDesktops = new(); public static bool IsBatchCreate { get; set; } public static Guid LastDesktopId = Guid.Empty; private static bool VisibleWindowFilter( IntPtr hWnd, int lParam ) { if ( Filters.WndHandleIgnoreListByError.Contains( hWnd ) || Filters.WndHandleIgnoreListByManual.TryGetValue( hWnd, out _ ) || !User32.IsWindowVisible( hWnd ) || Filters.IsCloaked( hWnd ) ) return true; _ = User32.GetWindowText( hWnd, SbWinInfo, SbWinInfo.Capacity ); var title = SbWinInfo.ToString(); if ( string.IsNullOrEmpty( title ) || Filters.WndTitleIgnoreList.Contains( title ) ) return true; _ = User32.GetClassName( hWnd, SbWinInfo, SbWinInfo.Capacity ); var classname = SbWinInfo.ToString(); if ( Filters.WndClsIgnoreList.Contains( classname ) ) return true; if ( classname != Const.WindowsUiCoreWindow ) { VisibleWindows.Add( new VisibleWindow( title, classname, hWnd ) ); } return true; } private static List GetVisibleWindows() { VisibleWindows.Clear(); _ = User32.EnumWindows( EnumWindowsProc, 0 ); return VisibleWindows; } public static void ShowVisibleWindowsForDesktops( List? vdwList = null, int processId = 0 ) { var visibleWindows = GetVisibleWindows(); Logger.Debug( $"VisibleWindows/ApplicationViews: {visibleWindows.Count.ToString()}/{DesktopManagerWrapper.GetViewCount().ToString()}" ); vdwList ??= _virtualDesktops; foreach ( var virtualDesktopWindow in vdwList ) { virtualDesktopWindow.ClearVisibleWindows(); } foreach ( var win in visibleWindows ) { try { if ( processId != 0 ) { _ = User32.GetWindowThreadProcessId( win.Handle, out var pId ); if ( processId != pId ) continue; } if ( DesktopWrapper.IsWindowPinned( win.Handle ) || DesktopWrapper.IsApplicationPinned( win.Handle ) ) { Logger.Debug( $"{win.Title} IS PINNED" ); foreach ( var vdw in _virtualDesktops ) vdw.AddWindow( new VisibleWindow( win.Title, win.Classname, win.Handle ) ); continue; } var ownerId = DesktopWrapper.GuidFromWindow( win.Handle ); if ( vdwList.Count == _virtualDesktops.Count ) // show for all VDs { var owner = vdwList.Find( v => v.VdId == ownerId ); if ( owner is null ) continue; owner.AddWindow( win ); Logger.Debug( $"Desktop[{owner.VdIndex.ToString()}]({DesktopWrapper.DesktopNameFromIndex( owner.VdIndex )}) CONTAINS {win.Title}" ); } else // show for specific VDs { foreach ( var vdw in vdwList.Where( vdw => vdw.VdId == ownerId ) ) { vdw.AddWindow( win ); Logger.Debug( $"Desktop[{vdw.VdIndex.ToString()}]({DesktopWrapper.DesktopNameFromIndex( vdw.VdIndex )}) CONTAINS {win.Title}" ); } } } catch ( Exception ex ) { if ( win.Classname != Const.ApplicationFrameWindow ) { Logger.Warning( $"{ex.Message} ∵ {win.Title}({win.Handle.ToString( "X2" )}), WndClass: {win.Classname}" ); Filters.WndHandleIgnoreListByError.Add( win.Handle ); } } } foreach ( var vdw in vdwList ) { vdw.ShowThumbnails(); } } public static void RefreshThumbs( IntPtr h, params VirtualDesktopWindow[] vdwList ) { if ( DesktopWrapper.IsWindowPinned( h ) || DesktopWrapper.IsApplicationPinned( h ) ) { ShowVisibleWindowsForDesktops(); } else { ShowVisibleWindowsForDesktops( vdwList.ToList() ); } } public static void ShowAllVirtualDesktops() { UpdateVdwBackground(); foreach ( var vdw in _virtualDesktops ) { User32.SendMessage( vdw.Handle, WinMsg.WM_HOTKEY, UserMessage.ShowVdw, 0 ); } } public static void HideAllVirtualDesktops() { Menus.CloseContextMenu(); foreach ( var vdw in _virtualDesktops ) { vdw.ResetOnlyOneStatus(); vdw.Hide(); vdw.ClearVisibleWindows(); } } public static List GetAllVirtualDesktops() { return _virtualDesktops; } public static VirtualDesktopWindow GetCurrentVdw() { return _virtualDesktops.Single( v => v.VdId == DesktopWrapper.CurrentGuid ); } } } ================================================ FILE: VirtualSpace/VirtualDesktop/Manager.events.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Media; using Notification.Wpf; using VirtualSpace.AppLogs; using VirtualSpace.Config; using VirtualSpace.Helpers; using VirtualSpace.VirtualDesktop.Api; using ConfigManager = VirtualSpace.Config.Manager; namespace VirtualSpace.VirtualDesktop { internal static partial class VirtualDesktopManager { public static void RegisterVirtualDesktopEvents() { DesktopManagerWrapper.DesktopCreatedEvent += () => { if ( !IsBatchCreate ) UpdateMainView(); }; DesktopManagerWrapper.DesktopDeletedEvent += vdn => { UpdateMainView( vdn: vdn ); }; DesktopManagerWrapper.DesktopChangedEvent += vdn => { LastDesktopId = vdn.OldId; if ( MainWindow.IsShowing() ) UpdateVdwBackground(); if ( ConfigManager.Configs.Cluster.NotificationOnVdChanged ) { CultureInfo.CurrentUICulture = new CultureInfo( ConfigManager.CurrentProfile.UI.Language ); Logger.Notify( new NotifyObject { Title = Agent.Langs.GetString( "Cluster.Notification.SVD.Current" ) + DesktopWrapper.DesktopNameFromGuid( vdn.NewId ), Message = Agent.Langs.GetString( "Cluster.Notification.SVD.Last" ) + DesktopWrapper.DesktopNameFromGuid( vdn.OldId ), Background = new SolidColorBrush( Colors.DarkSlateGray ), Foreground = new SolidColorBrush( Colors.White ), Type = NotificationType.Notification, ExpTime = TimeSpan.FromSeconds( 3 ) } ); } MainWindow.UpdateVDIndexOnTrayIcon( vdn.NewId ); }; DesktopManagerWrapper.RegisterVirtualDesktopEvents( () => { Logger.Event( $"Wallpaper Changed" ); Parallel.ForEach( GetAllVirtualDesktops(), ( vdw, _ ) => { vdw.UpdateWallpaper(); } ); }, ( guid, path ) => { var vdwList = GetAllVirtualDesktops(); var vd = ( from vdw in vdwList where vdw.VdId == guid select vdw ).FirstOrDefault(); if ( vd is null ) return; vd.UpdateWallpaper(); Logger.Event( $"Desktop[{vd.VdIndex.ToString()}] Wallpaper Changed: {path}" ); } ); DesktopWrapper.OnDesktopVisibleEvent += ( desktop, forceFocusForegroundWindow ) => { if ( MainWindow.IsShowing() ) { desktop.MakeVisible(); return; } forceFocusForegroundWindow ??= Manager.Configs.Cluster.ForceFocusForegroundWindow; if ( (bool)forceFocusForegroundWindow ) { var hTaskBar = User32.FindWindow( Const.TaskbarWndClass, "" ); if ( hTaskBar == IntPtr.Zero ) { Logger.Verbose( "Taskbar not found, switch desktop only." ); desktop.MakeVisible(); return; } if ( SysInfo.IsTaskbarVisible() ) { User32.SetForegroundWindow( hTaskBar ); desktop.MakeVisible(); if ( User32.GetForegroundWindow() != hTaskBar ) { Logger.Verbose( "Taskbar not active, switch desktop only." ); return; } if ( SysInfo.IsAdministrator ) { Logger.Verbose( "Send [Alt+Esc]." ); LowLevelKeyboardHook.MultipleKeyPress( new List {Keys.Menu, Keys.Escape} ); } else { Logger.Verbose( "Force minimize taskbar." ); _ = User32.ShowWindow( hTaskBar, (short)ShowState.SW_FORCEMINIMIZE ); } } else { Logger.Verbose( "Taskbar is hiding, switch desktop only." ); desktop.MakeVisible(); } } else { desktop.MakeVisible(); } }; } } } ================================================ FILE: VirtualSpace/VirtualDesktop/Manager.layout.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Threading.Tasks; using VirtualSpace.AppLogs; using VirtualSpace.Commons; using VirtualSpace.Config.Entity; using VirtualSpace.Helpers; using VirtualSpace.VirtualDesktop.Api; using ConfigManager = VirtualSpace.Config.Manager; namespace VirtualSpace.VirtualDesktop { internal static partial class VirtualDesktopManager { private static Color _vdwDefaultBackColor; public static UserInterface Ui => ConfigManager.CurrentProfile.UI; private static void SyncVirtualDesktops() { var commonSize = GetCommonVdwSize(); var survivalDesktops = new List(); for ( var index = 0; index < DesktopWrapper.Count; index++ ) // build new list according to current system vd list { var guid = DesktopManagerWrapper.GetIdByIndex( index ); if ( guid == default ) continue; var survival = _virtualDesktops.Find( v => v.VdId == guid ); if ( survival == null ) { survival = VirtualDesktopWindow.Create( index, guid, commonSize, _vdwDefaultBackColor, Ui.VDWPadding ); } else { survival.VdIndex = index; } survivalDesktops.Add( survival ); } var sysGuids = survivalDesktops.Select( v => v.VdId ).ToList(); foreach ( var old in _virtualDesktops.Where( old => !sysGuids.Contains( old.VdId ) ) ) { old.RealClose(); } _virtualDesktops = survivalDesktops; // system vd list order at this moment ReOrder(); // reorder by profile } private static Size GetCommonVdwSize() { var dpi = SysInfo.Dpi; var size = MainWindow.GetCellSizeByMatrixIndex( 0 ); var vdwWidth = ( size.Width - 2 * Ui.VDWBorderSize ) * dpi.ScaleX + 1; var vdwHeight = ( size.Height - 2 * Ui.VDWBorderSize ) * dpi.ScaleY + 1; return new Size( (int)vdwWidth, (int)vdwHeight ); } private static void ReOrder( bool needSort = false ) { if ( needSort ) _virtualDesktops.Sort( ( x, y ) => x.VdIndex.CompareTo( y.VdIndex ) ); var profile = ConfigManager.CurrentProfile; var sysGuids = _virtualDesktops.Select( vdw => vdw.VdId ).ToList(); if ( profile.DesktopOrder == null || profile.DesktopOrder.Count == 0 ) // no custom order, using system's { SaveOrder( sysGuids ); return; } profile.DesktopOrder.RemoveAll( g => !sysGuids.Contains( g ) ); var orderedByProfile = new List(); for ( var idx = 0; idx < profile.DesktopOrder.Count; idx++ ) { var vdw = _virtualDesktops.Find( vdw => vdw.VdId == profile.DesktopOrder[idx] ); if ( vdw is null ) continue; vdw.VdIndex = idx; // reposition orderedByProfile.Add( vdw ); _virtualDesktops.Remove( vdw ); } foreach ( var restVdw in _virtualDesktops ) { restVdw.VdIndex = orderedByProfile.Count; orderedByProfile.Add( restVdw ); // increase orderedByProfile.Count every turn, so that vdw.VdIndex can be set properly. profile.DesktopOrder.Add( restVdw.VdId ); // append to tail } _virtualDesktops = orderedByProfile; SaveOrder(); } private static void UpdateMainView( VirtualDesktopNotification? vdn = null ) { if ( !MainWindow.IsShowing() ) return; FixLayout(); ShowAllVirtualDesktops(); if ( vdn is null ) return; try { var fallback = _virtualDesktops[GetVdIndexByGuid( vdn.NewId )]; ShowVisibleWindowsForDesktops( new List {fallback} ); } catch ( Exception e ) { Logger.Warning( "Update MainView: " + e.StackTrace ); } } public static void FixLayout() { try { MainWindow.ResetMainGrid(); } catch { MainWindow.NotifyDesktopManagerReset(); return; } SyncVirtualDesktops(); } public static async Task InitLayout() { MainWindow.ResetMainGrid(); var commonSize = GetCommonVdwSize(); var tasks = new List(); for ( var i = 0; i < DesktopWrapper.Count; i++ ) { var index = i; tasks.Add( Task.Run( () => { var guid = DesktopManagerWrapper.GetIdByIndex( index ); var vdw = VirtualDesktopWindow.Create( index, guid, commonSize, _vdwDefaultBackColor, Ui.VDWPadding ); lock ( _virtualDesktops ) // thread safe { _virtualDesktops.Add( vdw ); // added in random order, need call "ReOrder( true )" afterwards } } ) ); } try { await Task.WhenAll( tasks.ToArray() ); } catch ( Exception ex ) { Logger.Error( "Init Layout: " + ex.Message ); return; } ReOrder( true ); } public static void UpdateVdwBackground() { MainWindow.RenderCellBorder(); } private static List _lastDesktopOrder = new(); public static void SaveOrder( List? newOrder = null ) { static bool IsSameGuidList( List a, List b ) { if ( a.Count != b.Count ) return false; return !a.Where( ( t, i ) => t != b[i] ).Any(); } if ( newOrder != null ) { ConfigManager.CurrentProfile.DesktopOrder = newOrder; } if ( IsSameGuidList( _lastDesktopOrder, ConfigManager.CurrentProfile.DesktopOrder! ) ) return; ConfigManager.Save( reason: "sync&save", reasonName: "ConfigManager.CurrentProfile.DesktopOrder" ); _lastDesktopOrder = new List( ConfigManager.CurrentProfile.DesktopOrder! ); } public static int GetVdIndexByGuid( Guid guid ) { return ( from vdw in _virtualDesktops where vdw.VdId == guid select vdw.VdIndex ).FirstOrDefault(); } public static void Bootstrap() { _vdwDefaultBackColor = Color.FromArgb( Ui.VDWDefaultBackColor.R, Ui.VDWDefaultBackColor.G, Ui.VDWDefaultBackColor.B ); } } } ================================================ FILE: VirtualSpace/VirtualDesktop/Menus.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; using VirtualSpace.Config; using VirtualSpace.Helpers; using VirtualSpace.Tools; using VirtualSpace.VirtualDesktop.Api; namespace VirtualSpace.VirtualDesktop { public static class Menus { private static ContextMenuStrip _ctm; public static void ThumbCtm( MenuInfo mi ) { _ctm ??= new ContextMenuStrip(); _ctm.Items.Clear(); //////////////////////////////////////////////////////////////// // pin window var pinWindow = new ToolStripMenuItem { Text = Agent.Langs.GetString( "VDW.CTM.Window.PinWin" ), Checked = DesktopWrapper.IsWindowPinned( mi.Vw.Handle ) }; pinWindow.Click += ( s, evt ) => { DesktopWrapper.PinWindow( mi.Vw.Handle, pinWindow.Checked ); VirtualDesktopManager.ShowVisibleWindowsForDesktops(); }; _ctm.Items.Add( pinWindow ); //////////////////////////////////////////////////////////////// // pin app var pinApp = new ToolStripMenuItem { Text = Agent.Langs.GetString( "VDW.CTM.Window.PinApp" ), Checked = DesktopWrapper.IsApplicationPinned( mi.Vw.Handle ) }; pinApp.Click += ( s, evt ) => { DesktopWrapper.PinApp( mi.Vw.Handle, pinApp.Checked ); VirtualDesktopManager.ShowVisibleWindowsForDesktops(); }; _ctm.Items.Add( pinApp ); //////////////////////////////////////////////////////////////// // hide from view var hideWindow = new ToolStripMenuItem { Text = Agent.Langs.GetString( "VDW.CTM.Window.HideFromView" ) }; void OnIgnoreWindowClick( object? s, EventArgs evt ) { Filters.WndHandleIgnoreListByManual.TryAdd( mi.Vw.Handle, 0 ); VirtualDesktopManager.RefreshThumbs( mi.Vw.Handle, mi.Self ); } hideWindow.Click += OnIgnoreWindowClick; _ctm.Items.Add( hideWindow ); _ctm.Items.Add( "-" ); //////////////////////////////////////////////////////////////// // move to screen var itemScreen = new ToolStripMenuItem( Agent.Langs.GetString( "VDW.CTM.Window.Screen" ) ); void MoveToScreen( object? s, EventArgs evt ) { var selectedScreen = s as ToolStripMenuItem; WindowTool.MoveWindowToScreen( mi.Vw.Handle, itemScreen.DropDownItems.IndexOf( selectedScreen ) ); } foreach ( var s in Screen.AllScreens ) { var screen = Screen.FromHandle( mi.Vw.Handle ); var item = new ToolStripMenuItem( $"{s.DeviceName} ({s.DeviceFriendlyName()})" ); item.Checked = screen.DeviceName == s.DeviceName; item.Click += MoveToScreen; itemScreen.DropDownItems.Add( item ); } _ctm.Items.Add( itemScreen ); _ctm.Items.Add( "-" ); //////////////////////////////////////////////////////////////// // rule for window var newRuleFromWindow = new ToolStripMenuItem { Text = Agent.Langs.GetString( "VDW.CTM.Window.NewRule" ) }; void OnCreateRuleFromWindow( object? s, EventArgs evt ) { MainWindow.AcForm.CreateRuleFromWindowHandle( mi.Vw.Handle ); } newRuleFromWindow.Click += OnCreateRuleFromWindow; _ctm.Items.Add( newRuleFromWindow ); _ctm.Items.Add( "-" ); //////////////////////////////////////////////////////////////// // close window var closeWindow = new ToolStripMenuItem { Text = Agent.Langs.GetString( "VDW.CTM.Window.Close" ) }; void OnCloseWindowClick( object? s, EventArgs evt ) { mi.Self.CloseSelectedWindow( mi.Vw ); } closeWindow.Click += OnCloseWindowClick; _ctm.Items.Add( closeWindow ); //////////////////////////////////////////////////////////////// // Show Window ContextMenu _ctm.Show( mi.Sender as Control, mi.Location ); } public static void VdCtm( MenuInfo mi ) { _ctm ??= new ContextMenuStrip(); _ctm.Items.Clear(); ////////////////////////////////////////////////////////////// // show & edit desktop's name var sysIndex = DesktopWrapper.IndexFromGuid( mi.Self.VdId ); var currentName = DesktopWrapper.DesktopNameFromIndex( sysIndex ); var desktopName = new ToolStripTextBox {Text = currentName, AutoSize = false, Width = 200}; desktopName.KeyPress += ( s, evt ) => { if ( evt.KeyChar != (char)Keys.Enter ) return; if ( currentName != desktopName.Text ) { DesktopWrapper.SetNameByGuid( mi.Self.VdId, desktopName.Text ); mi.Self.UpdateDesktopName( desktopName.Text ); } evt.Handled = true; _ctm.Close(); }; _ctm.Items.Add( desktopName ); _ctm.Items.Add( "-" ); ////////////////////////////////////////////////////////////// // UnHideWindow var unHideWindow = new ToolStripMenuItem( Agent.Langs.GetString( "VDW.CTM.Desktop.UnHideWindow" ) ); void OnUnHideWindow( object? s, EventArgs evt ) { var item = s as ToolStripMenuItem; var m = Regex.Match( item.Text, $@".*{Const.HideWindowSplitter}(.*)" ); var h = (IntPtr)int.Parse( m.Groups[1].Value ); Filters.WndHandleIgnoreListByManual.TryRemove( h, out _ ); VirtualDesktopManager.RefreshThumbs( h, mi.Self ); } var sb = new StringBuilder( Const.WindowTitleMaxLength ); foreach ( var handle in Filters.WndHandleIgnoreListByManual.Keys ) { if ( !User32.IsWindow( handle ) ) continue; if ( !DesktopWrapper.IsWindowPinned( handle ) && !DesktopWrapper.IsApplicationPinned( handle ) && DesktopWrapper.GuidFromWindow( handle ) != mi.Self.VdId ) continue; _ = User32.GetWindowThreadProcessId( handle, out var pId ); var process = Process.GetProcessById( pId ); _ = User32.GetWindowText( handle, sb, sb.Capacity ); var title = sb.ToString(); var item = new ToolStripMenuItem( $"[{title}] of {process.ProcessName}(.exe){Const.HideWindowSplitter}{handle}" ); item.Click += OnUnHideWindow; unHideWindow.DropDownItems.Add( item ); } unHideWindow.Enabled = unHideWindow.DropDownItems.Count > 0; _ctm.Items.Add( unHideWindow ); _ctm.Items.Add( "-" ); ////////////////////////////////////////////////////////////// // delete virtual desktop var delVirtualDesktop = new ToolStripMenuItem( Agent.Langs.GetString( "VDW.CTM.Desktop.Remove" ) ); delVirtualDesktop.Click += ( s, evt ) => { if ( DesktopWrapper.RemoveDesktopByGuid( mi.Self.VdId ) ) { var vdw = mi.Self; vdw.RealClose(); mi.Vdws.RemoveAt( mi.Self.VdIndex ); } }; _ctm.Items.Add( delVirtualDesktop ); ////////////////////////////////////////////////////////////// // create virtual desktop var createVirtualDesktop = new ToolStripMenuItem( Agent.Langs.GetString( "VDW.CTM.Desktop.Create" ) ); void BatchCreate( object? s, EventArgs evt ) { var item = s as ToolStripMenuItem; var count = int.Parse( item.Text ); if ( count > 1 ) { VirtualDesktopManager.IsBatchCreate = true; for ( var i = 0; i < count; i++ ) DesktopWrapper.Create(); VirtualDesktopManager.FixLayout(); VirtualDesktopManager.ShowAllVirtualDesktops(); VirtualDesktopManager.IsBatchCreate = false; } else { VirtualDesktopManager.IsBatchCreate = false; DesktopWrapper.Create(); } } for ( var i = 1; i <= 10; i++ ) { var count = new ToolStripMenuItem( i.ToString() ); count.Click += BatchCreate; createVirtualDesktop.DropDownItems.Add( count ); } _ctm.Items.Add( createVirtualDesktop ); /////////////////////////////////// // Show Virtual Desktop ContextMenu _ctm.Show( mi.Sender as Control, mi.Location ); } public static void CloseContextMenu() { _ctm?.Close(); } } public class MenuInfo { public VisibleWindow Vw { get; set; } public VirtualDesktopWindow Self { get; set; } public object Sender { get; set; } public Point Location { get; set; } public List Vdws { get; set; } } } ================================================ FILE: VirtualSpace/VirtualDesktop/Navigation.cs ================================================ // Copyright (C) 2022 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Windows.Forms; using VirtualSpace.Config; namespace VirtualSpace.VirtualDesktop { public static class Navigation { public static int CalculateTargetIndex( int vdCount, int fromIndex, Keys dir, Config.Entity.Navigation nav ) { var rowsCols = (int)Math.Ceiling( Math.Sqrt( vdCount ) ); var maxIndex = vdCount - 1; var da = Manager.CurrentProfile.UI.DesktopArrangement; var currentRowCol = RowColFromIndex( rowsCols, fromIndex, da ); var targetRowCol = TargetRowColByDirection( rowsCols, currentRowCol, dir, currentRowCol ); var targetIndex = IndexFromRowCol( rowsCols, targetRowCol, da ); while ( targetIndex > maxIndex ) // 暴力应对目标桌面不存在的情况 { targetRowCol = TargetRowColByDirection( rowsCols, targetRowCol, dir, currentRowCol ); targetIndex = IndexFromRowCol( rowsCols, targetRowCol, da ); } return IndexFromRowCol( rowsCols, targetRowCol, 0 ); ////////////////////////////////////////////////////////////////////////////////////////////////// /// 导航不受 DesktopArrangement 影响,或者说:导航永远按照 DesktopArrarngement 为 0 的情况下进行 /// 也即:桌面按照配置文件中的顺序,从左上角开始,行满换行的方式填充到矩阵中 /// /// 此函数假设导航的目标桌面一定存在(也就是无法应对桌面数量不是 n 的平方的情况),若不满足则由单独的代码处理 (int R, int C) TargetRowColByDirection( int n, (int R, int C) currentRC, Keys direction, (int R, int C) validRC ) { var r = currentRC.R; var c = currentRC.C; var targetRow = currentRC.R; var targetCol = currentRC.C; switch ( direction ) { case Keys.Left: if ( c == 0 ) { if ( nav.CirculationH ) { if ( nav.CirculationHType == Const.VirtualDesktop.NavHTypeNextRow ) { targetRow = r == 0 ? n - 1 : r - 1; } targetCol = n - 1; } else { return validRC; } } else { targetCol--; } break; case Keys.Right: if ( c == n - 1 ) { if ( nav.CirculationH ) { if ( nav.CirculationHType == Const.VirtualDesktop.NavHTypeNextRow ) { targetRow = r == n - 1 ? 0 : r + 1; } targetCol = 0; } else { return validRC; } } else { targetCol++; } break; case Keys.Up: if ( r == 0 ) { if ( nav.CirculationV ) { targetRow = n - 1; } else { return validRC; } } else { targetRow--; } break; case Keys.Down: if ( r == n - 1 ) { if ( nav.CirculationV ) { targetRow = 0; } else { return validRC; } } else { targetRow++; } break; } return ( targetRow, targetCol ); } } public static int IndexFromRowCol( int n, (int R, int C) currentRC, int? desktopArrangement ) { var r = currentRC.R; var c = currentRC.C; switch ( desktopArrangement ) { case 0: // TopLeft To BottomRight H return r * n + c; case 1: // TopRight To BottomLeft H return r * n + ( n - 1 - c ); case 2: // BottomLeft To TopRight H return ( n - 1 - r ) * n + c; case 3: // BottomRight To TopLeft H return ( n - 1 - r ) * n + ( n - 1 - c ); case 4: // TopLeft To BottomRight V return c * n + r; case 5: // TopRight To BottomLeft V return ( n - 1 - c ) * n + r; case 6: // BottomLeft To TopRight V return c * n + ( n - 1 - r ); case 7: // BottomRight To TopLeft V return ( n - 1 - c ) * n + ( n - 1 - r ); default: // TopLeft To BottomRight H return r * n + c; } } public static (int R, int C) RowColFromIndex( int n, int logicIndex, int? desktopArrangement ) { int row, col; switch ( desktopArrangement ) { case 0: // TopLeft To BottomRight H row = logicIndex / n; col = logicIndex % n; break; case 1: // TopRight To BottomLeft H row = logicIndex / n; col = n - 1 - logicIndex % n; break; case 2: // BottomLeft To TopRight H row = n - 1 - logicIndex / n; col = logicIndex % n; break; case 3: // BottomRight To TopLeft H row = n - 1 - logicIndex / n; col = n - 1 - logicIndex % n; break; case 4: // TopLeft To BottomRight V row = logicIndex % n; col = logicIndex / n; break; case 5: // TopRight To BottomLeft V row = logicIndex % n; col = n - 1 - logicIndex / n; break; case 6: // BottomLeft To TopRight V row = n - 1 - logicIndex % n; col = logicIndex / n; break; case 7: // BottomRight To TopLeft V row = n - 1 - logicIndex % n; col = n - 1 - logicIndex / n; break; default: // TopLeft To BottomRight H row = logicIndex / n; col = logicIndex % n; break; } return ( row, col ); } } } ================================================ FILE: VirtualSpace/VirtualDesktop/VirtualDesktopWindow.Designer.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ namespace VirtualSpace.VirtualDesktop { partial class VirtualDesktopWindow { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose( bool disposing ) { if ( disposing && ( components != null ) ) { components.Dispose(); } ReleaseThumbnails(); base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.SuspendLayout(); // // VirtualDesktopWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(978, 600); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "VirtualDesktopWindow"; this.ShowIcon = false; this.ShowInTaskbar = false; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.VirtualDesktopWindow_Closing); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.VirtualDesktopWindow_MouseDown); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.VirtualDesktopWindow_MouseMove); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.VirtualDesktopWindow_MouseUp); this.Paint += new System.Windows.Forms.PaintEventHandler(this.pbWallpaper_Paint); this.ResumeLayout(false); } #endregion } } ================================================ FILE: VirtualSpace/VirtualDesktop/VirtualDesktopWindow.Mouse.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using VirtualSpace.AppLogs; using VirtualSpace.Config; using VirtualSpace.Helpers; using VirtualSpace.Tools; using VirtualSpace.VirtualDesktop.Api; using ConfigManager = VirtualSpace.Config.Manager; namespace VirtualSpace.VirtualDesktop { public partial class VirtualDesktopWindow { private static int _hoverVdIndex; private static Point _startPoint; private static int _dragState; private static Rectangle _dragBounds = Rectangle.Empty; private static VisibleWindow? _selectedWindow; private static DragWindow? _dw; private bool _isTheOnlyOneInMainView; public void ResetOnlyOneStatus() { _isTheOnlyOneInMainView = false; } private void VirtualDesktopWindow_MouseDown( object sender, MouseEventArgs e ) { _virtualDesktops = VirtualDesktopManager.GetAllVirtualDesktops(); _startPoint = e.Location; var dragSize = SystemInformation.DragSize * ConfigManager.CurrentProfile.Mouse.DragSizeFactor; _dragBounds = new Rectangle( new Point( _startPoint.X - dragSize.Width / 2, _startPoint.Y - dragSize.Height / 2 ), dragSize ); _selectedWindow = _visibleWindows.FirstOrDefault( w => w.Rect.Contains( e.Location ) ); if ( _selectedWindow != null ) { Logger.Verbose( "SELECT.Win " + _selectedWindow.Title ); } } private static bool IsOutBounds( Point location ) { return _dragBounds != Rectangle.Empty && !_dragBounds.Contains( location ); } private void VirtualDesktopWindow_MouseMove( object sender, MouseEventArgs e ) { if ( _dragState == 0 && e.Button == MouseButtons.Left && IsOutBounds( e.Location ) ) { _dragState = 1; } if ( _dragState == 0 ) return; HoverOnDesktop( sender, e ); if ( _selectedWindow != null ) { if ( _dw == null ) { _dw = DragWindow.CreateAndShow( _selectedWindow.Rect.Width, _selectedWindow.Rect.Height ); var i = DwmApi.DwmRegisterThumbnail( _dw.Handle, _selectedWindow.Handle, out var thumb ); if ( i == 0 ) { var props = new DWM_THUMBNAIL_PROPERTIES { fVisible = true, dwFlags = DwmApi.DWM_TNP_VISIBLE | DwmApi.DWM_TNP_RECTDESTINATION | DwmApi.DWM_TNP_OPACITY, opacity = 255, rcDestination = new RECT( 0, 0, _dw.Width, _dw.Height ) }; _dw.Thumb = thumb; UpdateThumbnail( _dw.Thumb, props ); } var dtp = _selectedWindow.DTP; dtp.opacity = VirtualDesktopManager.Ui.ThumbDragSourceOpacity; DwmApi.DwmUpdateThumbnailProperties( _selectedWindow.Thumb, ref dtp ); } _dw.Left = Cursor.Position.X - _dw.Width / 2; _dw.Top = Cursor.Position.Y - _dw.Height / 2; } else { var vdw = sender as Form; vdw.Left = e.X + vdw.Left - _startPoint.X; vdw.Top = e.Y + vdw.Top - _startPoint.Y; } } private void VirtualDesktopWindow_MouseUp( object sender, MouseEventArgs e ) { if ( null == sender ) return; _hoverVdIndex = HoverOnDesktop( sender, e ); if ( _hoverVdIndex < 0 ) return; if ( _dragState > 0 ) { if ( _selectedWindow != null ) // if we drag a thumbnail in a virtual desktop { while ( true ) { _virtualDesktops[_hoverVdIndex].Opacity = 1; // reset hover virtual desktop opacity unconditionally if ( _hoverVdIndex == VdIndex || DesktopWrapper.IsWindowPinned( _selectedWindow.Handle ) || DesktopWrapper.IsApplicationPinned( _selectedWindow.Handle ) ) { ////////////////////////// // goes here means no need to move the dragged window var dtp = _selectedWindow.DTP; dtp.opacity = 255; DwmApi.DwmUpdateThumbnailProperties( _selectedWindow.Thumb, ref dtp ); break; } if ( User32.IsWindow( _selectedWindow.Handle ) ) { /////////////////////////// // goes here means the thumbnail window we dragged is drop in another virtual desktop // we need to move it. Logger.Verbose( $"DROP.Win {_selectedWindow.Title}({_selectedWindow.Handle.ToString( "X2" )}) IN Desktop[{_hoverVdIndex.ToString()}]" ); var sysIndex = DesktopWrapper.IndexFromGuid( _virtualDesktops[_hoverVdIndex].VdId ); DesktopWrapper.MoveWindowToDesktop( _selectedWindow.Handle, sysIndex ); var relevantVirtualDesktops = new List { _virtualDesktops[_hoverVdIndex], this }; VirtualDesktopManager.ShowVisibleWindowsForDesktops( relevantVirtualDesktops ); } break; } } else // if we drag a virtual desktop { if ( _hoverVdIndex == VdIndex ) { Location = _fixedPosition; } else { Swap( ConfigManager.CurrentProfile.DesktopOrder, VdIndex, _hoverVdIndex ); VirtualDesktopManager.SaveOrder(); Logger.Verbose( $"SWAP.Desktop Desktop[{VdIndex.ToString()}] WITH Desktop[{_hoverVdIndex.ToString()}]" ); VirtualDesktopManager.FixLayout(); VirtualDesktopManager.ShowAllVirtualDesktops(); User32.PostMessage( Handle, WinMsg.WM_HOTKEY, UserMessage.RefreshVdw, 0 ); User32.PostMessage( _virtualDesktops[_hoverVdIndex].Handle, WinMsg.WM_HOTKEY, UserMessage.RefreshVdw, 0 ); } } } else { ////////////////////////////////// // goes here means a Click if ( _selectedWindow != null && User32.IsWindow( _selectedWindow.Handle ) ) // click on a thumbnail { void ActiveWindow() { Logger.Verbose( $"ACTIVE.Win {_selectedWindow.Title}({_selectedWindow.Handle.ToString( "X2" )})" ); WindowTool.ActiveWindow( _selectedWindow.Handle, ConfigManager.CurrentProfile.DesktopOrder[_hoverVdIndex] ); } var action = Manager.Configs.GetMouseActionById( MouseAction.GetActionId( e.Button, ModifierKeys, MouseAction.MOUSE_NODE_WINDOW_PREFIX ) ); switch ( action ) { case MouseAction.Action.WindowActiveDesktopVisibleAndCloseView: ActiveWindow(); MainWindow.HideAll(); break; case MouseAction.Action.WindowActiveDesktopVisibleOnly: ActiveWindow(); break; case MouseAction.Action.WindowClose: CloseSelectedWindow( _selectedWindow ); break; case MouseAction.Action.ContextMenu: Menus.ThumbCtm( new MenuInfo { Vw = _selectedWindow, Sender = sender, Location = e.Location, Self = this } ); break; case MouseAction.Action.WindowHideFromView: Filters.WndHandleIgnoreListByManual.TryAdd( _selectedWindow.Handle, 0 ); VirtualDesktopManager.RefreshThumbs( _selectedWindow.Handle, this ); break; case MouseAction.Action.WindowShowForSelectedProcessOnly: try { _ = User32.GetWindowThreadProcessId( _selectedWindow.Handle, out var pId ); VirtualDesktopManager.ShowVisibleWindowsForDesktops( null, pId ); } catch ( Exception ex ) { Logger.Warning( "show windows from selected process: " + ex.Message ); } break; case MouseAction.Action.WindowShowForSelectedProcessInSelectedDesktop: try { _ = User32.GetWindowThreadProcessId( _selectedWindow.Handle, out var pId ); MakeTheOnlyOne( pId ); } catch ( Exception ex ) { Logger.Warning( "show windows from selected process: " + ex.Message ); } break; case MouseAction.Action.DoNothing: break; default: ActiveWindow(); MainWindow.HideAll(); break; } } else // click on a virtual desktop { var action = Manager.Configs.GetMouseActionById( MouseAction.GetActionId( e.Button, ModifierKeys, MouseAction.MOUSE_NODE_DESKTOP_PREFIX ) ); switch ( action ) { case MouseAction.Action.DesktopVisibleAndCloseView: MakeVisible(); MainWindow.HideAll(); break; case MouseAction.Action.DesktopVisibleOnly: MakeVisible(); break; case MouseAction.Action.ContextMenu: Menus.VdCtm( new MenuInfo { Sender = sender, Location = e.Location, Self = this, Vdws = _virtualDesktops } ); break; case MouseAction.Action.DesktopShowForSelectedDesktop: MakeTheOnlyOne(); break; case MouseAction.Action.DoNothing: break; default: MakeVisible(); MainWindow.HideAll(); break; } } } VirtualDesktopManager.UpdateVdwBackground(); if ( _dw != null ) { DwmApi.DwmUnregisterThumbnail( _dw.Thumb ); _dw.Close(); _dw = null; } _dragState = 0; _selectedWindow = null; _dragBounds = Rectangle.Empty; } private int HoverOnDesktop( object sender, MouseEventArgs e ) { if ( _virtualDesktops is null ) return -1; _hoverVdIndex = VdIndex; var cellIndex = MainWindow.InCell( new System.Windows.Point( Cursor.Position.X, Cursor.Position.Y ) ); MainWindow.UpdateHoverBorder( cellIndex ); foreach ( var vdw in _virtualDesktops ) { var controlRectangle = vdw.RectangleToScreen( vdw.ClientRectangle ); if ( controlRectangle.Contains( Cursor.Position ) ) { if ( vdw.VdIndex != VdIndex ) { _hoverVdIndex = vdw.VdIndex; if ( _selectedWindow != null ) { if ( _dragState == 1 ) { Logger.Verbose( $"DRAGGING.Win {_selectedWindow.Title} IN Desktop[{vdw.VdIndex.ToString()}]" ); _dragState++; } vdw.Opacity = VirtualDesktopManager.Ui.VDWDragTargetOpacity; } else { if ( _dragState == 1 ) { Logger.Verbose( $"DRAGGING.Desk Desktop[{VdIndex.ToString()}]) ON Desktop[{vdw.VdIndex.ToString()}])" ); _dragState++; } } } } else { vdw.Opacity = 1; } } return _hoverVdIndex; } private void MakeVisible() { Logger.Verbose( $"SWITCH TO DESKTOP Desktop[{_hoverVdIndex.ToString()}]" ); DesktopWrapper.MakeVisibleByGuid( VdId ); } private static void Swap( IList list, int indexA, int indexB ) { ( list[indexA], list[indexB] ) = ( list[indexB], list[indexA] ); } public async void CloseSelectedWindow( VisibleWindow vw ) { var isWindowPinned = DesktopWrapper.IsWindowPinned( vw.Handle ) || DesktopWrapper.IsApplicationPinned( vw.Handle ); void RefreshVDs( bool isPinned ) { if ( isPinned ) { VirtualDesktopManager.ShowVisibleWindowsForDesktops(); } else { VirtualDesktopManager.ShowVisibleWindowsForDesktops( new List {this} ); } } // _ = User32.ShowWindow( vw.Handle, 0 ); User32.PostMessage( vw.Handle, WinMsg.WM_SYSCOMMAND, WinMsg.SC_CLOSE, 0 ); await Task.Run( () => { var sw = Stopwatch.StartNew(); while ( sw.ElapsedMilliseconds < Const.WindowCloseTimeout ) { Thread.Sleep( 100 ); // if ( User32.IsWindow( vw.Handle ) ) continue; // 严格的判断 if ( User32.IsWindowVisible( vw.Handle ) ) continue; // 宽松的判断 RefreshVDs( isWindowPinned ); return; } RefreshVDs( isWindowPinned ); } ).ConfigureAwait( false ); } public void MakeTheOnlyOne( int pId = 0 ) { if ( _isTheOnlyOneInMainView ) { MainWindow.ResetMainGrid(); VirtualDesktopManager.HideAllVirtualDesktops(); VirtualDesktopManager.ShowAllVirtualDesktops(); VirtualDesktopManager.ShowVisibleWindowsForDesktops(); } else { MainWindow.ResetMainGridForSingleDesktop( VdIndex ); VirtualDesktopManager.HideAllVirtualDesktops(); _isTheOnlyOneInMainView = true; VirtualDesktopManager.ShowAllVirtualDesktops(); VirtualDesktopManager.ShowVisibleWindowsForDesktops( new List {this}, pId ); } } } } ================================================ FILE: VirtualSpace/VirtualDesktop/VirtualDesktopWindow.Thumbs.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Windows.Forms; using VirtualSpace.Helpers; using ConfigManager = VirtualSpace.Config.Manager; namespace VirtualSpace.VirtualDesktop { public partial class VirtualDesktopWindow { public void AddWindow( VisibleWindow wnd ) { _visibleWindows.Add( wnd ); } public void ClearVisibleWindows() { ReleaseThumbnails(); _visibleWindows.Clear(); } public void ShowThumbnails() { var wndCount = _visibleWindows.Count; if ( !string.IsNullOrEmpty( WindowFilter.Keyword ) ) { _visibleWindows.RemoveAll( wnd => !wnd.Title.ToLower().Contains( WindowFilter.Keyword.ToLower() ) ); wndCount = _visibleWindows.Count; } if ( wndCount < 1 ) return; _visibleWindows.Sort( ( x, y ) => x.Title.CompareTo( y.Title ) ); var rows = Math.Floor( Math.Sqrt( wndCount ) ); var cols = Math.Ceiling( wndCount / rows ); var marginH = VirtualDesktopManager.Ui.ThumbMargin.Left; var marginV = VirtualDesktopManager.Ui.ThumbMargin.Top; ////////////////////////////////////// // thumb container size var thumbWidth = ( Width - ( cols + 1 ) * marginH ) / cols; var thumbHeight = ( Height - ( rows + 1 ) * marginV ) / rows; ////////////////////////////////////// // show thumbnails for ( int index = 0, row = 0; row < rows; row++ ) { var topLeftY = Padding.Top + ( row + 1 ) * marginV + row * thumbHeight; for ( var col = 0; col < cols; col++ ) { if ( index >= wndCount ) break; var topLeftX = Padding.Left + ( col + 1 ) * marginH + col * thumbWidth; var i = -1; var thumb = IntPtr.Zero; if ( InvokeRequired ) { var idx = index; void Invoker() { i = DwmApi.DwmRegisterThumbnail( Handle, _visibleWindows[idx].Handle, out thumb ); } Invoke( (MethodInvoker)Invoker ); } else { i = DwmApi.DwmRegisterThumbnail( Handle, _visibleWindows[index].Handle, out thumb ); } if ( i == 0 ) { _visibleWindows[index].Thumb = thumb; var props = ScaleCenter( thumb, new RECT( (int)topLeftX, (int)topLeftY, (int)( topLeftX + thumbWidth ), (int)( topLeftY + thumbHeight ) ) ); _visibleWindows[index].SetValidArea( props ); UpdateThumbnail( thumb, props ); } index++; } } } private static DWM_THUMBNAIL_PROPERTIES ScaleCenter( IntPtr thumb, RECT rect ) { var props = new DWM_THUMBNAIL_PROPERTIES { fVisible = true, dwFlags = DwmApi.DWM_TNP_VISIBLE | DwmApi.DWM_TNP_RECTDESTINATION | DwmApi.DWM_TNP_OPACITY, opacity = 255, rcDestination = rect }; if ( thumb == IntPtr.Zero ) return props; _ = DwmApi.DwmQueryThumbnailSourceSize( thumb, out var srcSize ); var cellWidth = rect.Right - rect.Left; var cellHeight = rect.Bottom - rect.Top; var cellAspectRatio = cellWidth / (double)cellHeight; var srcAspectRatio = srcSize.cx / (double)srcSize.cy; if ( cellAspectRatio > srcAspectRatio ) { var scaleFactor = cellHeight / (double)srcSize.cy; var scaledX = (int)( srcSize.cx * scaleFactor ); var xOffset = ( cellWidth - scaledX ) / 2; props.rcDestination.Left += xOffset; props.rcDestination.Right -= xOffset; } else { var scaleFactor = cellWidth / (double)srcSize.cx; var scaledY = (int)( srcSize.cy * scaleFactor ); var yOffset = ( cellHeight - scaledY ) / 2; props.rcDestination.Top += yOffset; props.rcDestination.Bottom -= yOffset; } return props; } private static void UpdateThumbnail( IntPtr thumb, DWM_THUMBNAIL_PROPERTIES props ) { _ = DwmApi.DwmUpdateThumbnailProperties( thumb, ref props ); } private void ReleaseThumbnails() { foreach ( var window in _visibleWindows ) _ = DwmApi.DwmUnregisterThumbnail( window.Thumb ); } } } ================================================ FILE: VirtualSpace/VirtualDesktop/VirtualDesktopWindow.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows.Forms; using VirtualSpace.AppLogs; using VirtualSpace.Config; using VirtualSpace.Helpers; using VirtualSpace.VirtualDesktop.Api; using ConfigManager = VirtualSpace.Config.Manager; using Point = System.Drawing.Point; using Size = System.Drawing.Size; namespace VirtualSpace.VirtualDesktop { public partial class VirtualDesktopWindow : Form { private static List? _virtualDesktops; private readonly List _visibleWindows = new(); private string _desktopName; private Point _fixedPosition; private Size _initSize = Size.Empty; public Guid VdId; public int VdIndex { get; set; } private VirtualDesktopWindow() { InitializeComponent(); base.DoubleBuffered = ConfigManager.Configs.Cluster.EnableDoubleBufferedForVDW; } protected override CreateParams CreateParams { get { var cp = base.CreateParams; cp.ExStyle |= 0x00000080; // WS_EX_TOOLWINDOW cp.ExStyle |= 0x08000000; // WS_EX_NOACTIVATE cp.Style = unchecked(cp.Style | (int)0x80000000); // WS_POPUP return cp; } } protected override void WndProc( ref Message m ) { if ( m.Msg == WinMsg.WM_HOTKEY ) { switch ( m.WParam.ToInt32() ) { case UserMessage.ShowVdw: ShowByVdIndex(); return; case UserMessage.RefreshVdw: Refresh(); return; case UserMessage.ShowThumbsOfVdw: ShowThumbnails(); return; } } base.WndProc( ref m ); } protected override bool ShowWithoutActivation => true; public static VirtualDesktopWindow Create( int index, Guid guid, Size initSize, Color defaultBackColor, int vdwPadding ) { var vdw = new VirtualDesktopWindow { StartPosition = FormStartPosition.Manual, TabStop = false, TopLevel = true, TopMost = true, Name = "vdw_" + index, VdId = guid, VdIndex = index, Size = initSize, BackColor = defaultBackColor, Padding = new Padding( vdwPadding ), ResizeRedraw = true, Text = Const.Window.VD_CONTAINER_TITLE }; vdw.SetOwner( MainWindow.GetMainWindow() ); return vdw; } private void SetOwner( MainWindow owner ) { void DoSetOwner() { User32.SetWindowLongPtr( new HandleRef( this, Handle ), (int)GetWindowLongFields.GWL_HWNDPARENT, owner.Handle.ToInt32() ); } if ( owner.Dispatcher.CheckAccess() ) { DoSetOwner(); } else { owner.Dispatcher.Invoke( DoSetOwner ); } } public void UpdateWallpaper() { if ( InvokeRequired ) { Invoke( (MethodInvoker)Refresh ); } else { Refresh(); } } private void VirtualDesktopWindow_Closing( object? sender, FormClosingEventArgs e ) { e.Cancel = true; } public void RealClose() { FormClosing -= VirtualDesktopWindow_Closing; ClearVisibleWindows(); Close(); } private void ShowByVdIndex() { var ui = VirtualDesktopManager.Ui; var dpi = SysInfo.Dpi; var matrixIndex = VirtualDesktopManager.GetMatrixIndexByVdIndex( VdIndex ); var location = MainWindow.GetCellLocationByMatrixIndex( matrixIndex ); var point = new Point( (int)( ( location.X + ui.VDWBorderSize ) * dpi.ScaleX ), (int)( ( location.Y + ui.VDWBorderSize ) * dpi.ScaleY ) ); Location = point; _fixedPosition = point; var size = MainWindow.GetCellSizeByMatrixIndex( matrixIndex ); var vdwWidth = ( size.Width - 2 * ui.VDWBorderSize ) * dpi.ScaleX + 1; var vdwHeight = ( size.Height - 2 * ui.VDWBorderSize ) * dpi.ScaleY + 1; //////////////////////////////////////////////////////////////// // 虚拟桌面容器的宽/高下限,宽/高任意一个低于此值,虚拟桌面尺寸强制归零 if ( vdwWidth < Const.VirtualDesktop.VdwSizeFloor || vdwHeight < Const.VirtualDesktop.VdwSizeFloor ) { Size = Size.Empty; // 强制归零,从而避免接收到鼠标事件 } else { var vdName = DesktopWrapper.DesktopNameFromGuid( VdId ); if ( vdName != _desktopName ) { UpdateDesktopName( vdName ); } Size = new Size( (int)vdwWidth, (int)vdwHeight ); if ( !Visible ) Show(); } } private (bool isCached, string path, Color? color) CachedWallpaperInfo() { var wpPath = WinRegistry.GetWallPaperPathByGuid( VdId ); if ( wpPath is null ) { return new ValueTuple( false, "", WinRegistry.GetBackColor() ); } var wpInfo = Wallpaper.CachedWallPaperInfo( wpPath, ConfigManager.GetCachePath(), Width, Height ); return new ValueTuple( wpInfo.Exists, wpPath, null ); } private static void DrawImage( PaintEventArgs e, Wallpaper wp, int width = 0, int height = 0 ) { if ( width > 0 && height > 0 ) { e.Graphics.DrawImage( wp.Image, 0, 0, width, height ); } else { e.Graphics.DrawImage( wp.Image, 0, 0 ); } wp.Release(); } private void InitPaint( (bool isCached, string path, Color? color) wpInfo, PaintEventArgs e ) { Logger.Event( $"Init Desktop[{VdIndex}] background." ); _initSize.Width = Width; _initSize.Height = Height; if ( wpInfo.color != null ) { BackColor = (Color)wpInfo.color; return; } if ( wpInfo.isCached ) { DrawImage( e, WinRegistry.GetWallpaperByPath( wpInfo.path, Width, Height, ConfigManager.GetCachePath(), ConfigManager.Configs.Cluster.VdwWallpaperQuality ) ); } else { if ( VirtualDesktopManager.IsBatchCreate ) { DrawImage( e, WinRegistry.GetWallpaperByPath( wpInfo.path, Width, Height, ConfigManager.GetCachePath(), ConfigManager.Configs.Cluster.VdwWallpaperQuality ) ); } else { var hWnd = Handle; Task.Run( () => { WinRegistry.GetWallpaperByPath( wpInfo.path, Width, Height, ConfigManager.GetCachePath(), ConfigManager.Configs.Cluster.VdwWallpaperQuality ).Release(); User32.PostMessage( hWnd, WinMsg.WM_HOTKEY, UserMessage.RefreshVdw, 0 ); } ); } } } private void NormalPaint( (bool isCached, string path, Color? color) wpInfo, PaintEventArgs e ) { if ( wpInfo.color != null ) { BackColor = (Color)wpInfo.color; return; } if ( wpInfo.isCached ) { DrawImage( e, WinRegistry.GetWallpaperByPath( wpInfo.path, Width, Height, ConfigManager.GetCachePath(), ConfigManager.Configs.Cluster.VdwWallpaperQuality ) ); } else { Logger.Event( $"Create cache image({Width}*{Height}) for Desktop[{VdIndex}]" ); Task.Run( () => { // only once for path with current Width*Height WinRegistry.GetWallpaperByPath( wpInfo.path, Width, Height, ConfigManager.GetCachePath(), ConfigManager.Configs.Cluster.VdwWallpaperQuality ) .Release(); } ); //////////////////////////////////////////////////////////////////////////////////// // use init size, so we can create cache image async e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor; // faster DrawImage( e, WinRegistry.GetWallpaperByPath( wpInfo.path, _initSize.Width, _initSize.Height, ConfigManager.GetCachePath(), ConfigManager.Configs.Cluster.VdwWallpaperQuality ), Width, Height ); } } private void RefreshThumbs( object? o, EventArgs e ) { Logger.Event( $"Repaint thumbs in Desktop[{VdIndex}] due to size changed." ); ReleaseThumbnails(); ShowThumbnails(); } private void pbWallpaper_Paint( object sender, PaintEventArgs e ) { var wpInfo = CachedWallpaperInfo(); if ( _initSize == Size.Empty ) { Resize += RefreshThumbs; InitPaint( wpInfo, e ); } else { NormalPaint( wpInfo, e ); } var ui = ConfigManager.CurrentProfile.UI; var str = ""; if ( ui.ShowVdName ) { str += _desktopName; } if ( ui.ShowVdIndex ) { str += ui.ShowVdIndexType == 0 ? $"[{VdIndex}]" : $"[{VdIndex + 1}]"; } if ( str == "" ) return; using var font = new Font( "Segoe UI emoji", 10 ); e.Graphics.DrawString( str, font, Brushes.Beige, new Point( 2, Height - 30 ) ); } public void UpdateDesktopName( string name ) { _desktopName = name; Refresh(); } } } ================================================ FILE: VirtualSpace/VirtualDesktop/VirtualDesktopWindow.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: VirtualSpace/VirtualDesktop/VisibleWindow.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System; using System.Drawing; using VirtualSpace.Helpers; namespace VirtualSpace.VirtualDesktop { public class VisibleWindow { public VisibleWindow( string title, string classname, IntPtr handle ) { Title = title; Classname = classname; Handle = handle; } public string Title { get; set; } public string Classname { get; set; } public IntPtr Handle { get; set; } public Rectangle Rect { get; set; } public IntPtr Thumb { get; set; } internal DWM_THUMBNAIL_PROPERTIES DTP { get; set; } internal void SetValidArea( DWM_THUMBNAIL_PROPERTIES props ) { DTP = props; Rect = new Rectangle { X = props.rcDestination.Left, Y = props.rcDestination.Top, Width = props.rcDestination.Right - props.rcDestination.Left, Height = props.rcDestination.Bottom - props.rcDestination.Top }; } } } ================================================ FILE: VirtualSpace/VirtualSpace.csproj ================================================  WinExe net6.0-windows enable true VirtualSpace.Program True Resources\Logo_2.ico app.manifest AnyCPU;x64;x86 9 false false true True AutoVersion.tt 1701;1702;CA1416;CS8618 1701;1702;CA1416;CS8618 1701;1702;CA1416;CS8618 1701;1702;CA1416;CS8618 1701;1702;CA1416;CS8618 1701;1702;CA1416;CS8618 VirtualDesktop10 true VirtualDesktop11 true VirtualDesktop11_21H2 true VirtualDesktop11_23H2 true VirtualDesktop11_23H2_3085 true VirtualDesktop11_24H2 true en-US,zh-Hans ================================================ FILE: VirtualSpace/WindowFilter.xaml ================================================  ================================================ FILE: VirtualSpace/WindowFilter.xaml.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Runtime.InteropServices; using System.Timers; using System.Windows; using System.Windows.Interop; using VirtualSpace.Config; using VirtualSpace.Helpers; using VirtualSpace.VirtualDesktop; namespace VirtualSpace { public partial class WindowFilter : Window { private static WindowFilter? _instance; private static IntPtr _handle; private static string _lastKeyword = string.Empty; private static readonly Timer FilterTimer = new() { Enabled = true, Interval = Manager.Configs.Cluster.WindowFilterKeywordScanningInterval }; private WindowFilter() { InitializeComponent(); } public static WindowFilter GetInstance( IntPtr handle ) { if ( _instance == null ) { _instance = new WindowFilter { Height = Const.Window.WINDOW_FILTER_BAR_HEIGHT, Title = Const.Window.VS_WINDOW_FILTER_TITLE }; new WindowInteropHelper( _instance ).EnsureHandle(); } User32.SetWindowLongPtr( new HandleRef( _instance, _handle ), (int)GetWindowLongFields.GWL_HWNDPARENT, handle.ToInt32() ); FilterTimer.Elapsed += FilterTimerOnElapsed; return _instance; } private static void FilterTimerOnElapsed( object? sender, ElapsedEventArgs e ) { if ( _lastKeyword == Keyword ) return; _lastKeyword = Keyword; VirtualDesktopManager.ShowVisibleWindowsForDesktops(); } protected override void OnSourceInitialized( EventArgs e ) { base.OnSourceInitialized( e ); _handle = new WindowInteropHelper( this ).EnsureHandle(); } public void SetFocus() { User32.SetForegroundWindow( _handle ); tbFilter.Focus(); FilterTimer.Start(); } public void ClearAndHide( bool clearKeyword = true ) { FilterTimer.Stop(); if ( clearKeyword ) { _lastKeyword = string.Empty; tbFilter.Clear(); } if ( clearKeyword ) { Close(); _instance = null; } else { Hide(); } } public static string Keyword { get { if ( _instance == null ) return string.Empty; if ( _instance.tbFilter.CheckAccess() ) { return _instance.tbFilter.Text; } return _instance.Dispatcher.Invoke( () => _instance.tbFilter.Text ); } } } } ================================================ FILE: VirtualSpace/app.manifest ================================================  ================================================ FILE: VirtualSpace.sln ================================================  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31919.166 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualSpace", "VirtualSpace\VirtualSpace.csproj", "{DB52639D-5D7C-48D6-A4E1-0287C0323F6D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LinqExpressionBuilder", "LinqExpressionBuilder\LinqExpressionBuilder.csproj", "{39DADF49-9596-420D-8663-4F44F3A3179D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Configuration", "Configuration\Configuration.csproj", "{1BC48019-B0BC-434E-8677-B720DA769365}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logger", "Logger\Logger.csproj", "{FF6514E2-0F29-4694-AA57-DA539144DE56}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Helpers", "Helpers\Helpers.csproj", "{C585EA4E-FB09-47E9-B860-CE551701C25B}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bridge", "Bridge\Bridge.csproj", "{307A5E39-85D4-42C3-B267-B36706BB1F86}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ipc", "Ipc\Commons\Ipc.csproj", "{24AC7B65-7A18-4603-AB5A-B50A6903E5BF}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IpcServer", "Ipc\IpcServer\IpcServer.csproj", "{B7B5F165-21C3-456B-8F13-4C72FF6E6D32}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin", "Plugin\Commons\Plugin.csproj", "{36332EB5-80A3-4B90-998A-55D24AB17715}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppController", "WinForms\AppController\AppController.csproj", "{0C239946-4CA8-44B0-B0A3-7785931FAEB9}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PluginHost", "Plugin\PluginHost\PluginHost.csproj", "{8789C787-2125-413E-BB38-C9065C405D42}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualDesktop10", "VirtualDesktop\VirtualDesktop10\VirtualDesktop10.csproj", "{B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualDesktop11", "VirtualDesktop\VirtualDesktop11\VirtualDesktop11.csproj", "{E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualDesktop11_21H2", "VirtualDesktop\VirtualDesktop11_21H2\VirtualDesktop11_21H2.csproj", "{F63B2561-6C6C-4010-A63A-AAB03F8C3E30}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualDesktopWrapper", "VirtualDesktopWrapper\VirtualDesktopWrapper.csproj", "{1E662F33-8F91-48EB-A659-594E7039C65A}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ControlPanel", "WPF\ControlPanel\ControlPanel.csproj", "{FAC71622-8310-4139-944B-F1FBF6588843}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualDesktop11_23H2", "VirtualDesktop\VirtualDesktop11_23H2\VirtualDesktop11_23H2.csproj", "{8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualDesktop11_23H2_3085", "VirtualDesktop\VirtualDesktop11_23H2_3085\VirtualDesktop11_23H2_3085.csproj", "{698A0646-07E5-4A43-8D02-229BF3571086}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualDesktop11_24H2", "VirtualDesktop\VirtualDesktop11_24H2\VirtualDesktop11_24H2.csproj", "{D51F509E-9970-4454-B246-0970FF6C69CC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Debug|Any CPU.Build.0 = Debug|Any CPU {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Debug|x64.ActiveCfg = Debug|Any CPU {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Debug|x64.Build.0 = Debug|Any CPU {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Debug|x86.ActiveCfg = Debug|x86 {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Debug|x86.Build.0 = Debug|x86 {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Release|Any CPU.ActiveCfg = Release|Any CPU {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Release|Any CPU.Build.0 = Release|Any CPU {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Release|x64.ActiveCfg = Release|Any CPU {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Release|x64.Build.0 = Release|Any CPU {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Release|x86.ActiveCfg = Release|Any CPU {DB52639D-5D7C-48D6-A4E1-0287C0323F6D}.Release|x86.Build.0 = Release|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Debug|Any CPU.Build.0 = Debug|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Debug|x64.ActiveCfg = Debug|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Debug|x64.Build.0 = Debug|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Debug|x86.ActiveCfg = Debug|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Debug|x86.Build.0 = Debug|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Release|Any CPU.ActiveCfg = Release|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Release|Any CPU.Build.0 = Release|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Release|x64.ActiveCfg = Release|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Release|x64.Build.0 = Release|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Release|x86.ActiveCfg = Release|Any CPU {39DADF49-9596-420D-8663-4F44F3A3179D}.Release|x86.Build.0 = Release|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Debug|Any CPU.Build.0 = Debug|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Debug|x64.ActiveCfg = Debug|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Debug|x64.Build.0 = Debug|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Debug|x86.ActiveCfg = Debug|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Debug|x86.Build.0 = Debug|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Release|Any CPU.ActiveCfg = Release|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Release|Any CPU.Build.0 = Release|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Release|x64.ActiveCfg = Release|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Release|x64.Build.0 = Release|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Release|x86.ActiveCfg = Release|Any CPU {1BC48019-B0BC-434E-8677-B720DA769365}.Release|x86.Build.0 = Release|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Debug|Any CPU.Build.0 = Debug|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Debug|x64.ActiveCfg = Debug|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Debug|x64.Build.0 = Debug|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Debug|x86.ActiveCfg = Debug|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Debug|x86.Build.0 = Debug|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Release|Any CPU.ActiveCfg = Release|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Release|Any CPU.Build.0 = Release|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Release|x64.ActiveCfg = Release|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Release|x64.Build.0 = Release|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Release|x86.ActiveCfg = Release|Any CPU {FF6514E2-0F29-4694-AA57-DA539144DE56}.Release|x86.Build.0 = Release|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Debug|Any CPU.Build.0 = Debug|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Debug|x64.ActiveCfg = Debug|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Debug|x64.Build.0 = Debug|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Debug|x86.ActiveCfg = Debug|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Debug|x86.Build.0 = Debug|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Release|Any CPU.ActiveCfg = Release|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Release|Any CPU.Build.0 = Release|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Release|x64.ActiveCfg = Release|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Release|x64.Build.0 = Release|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Release|x86.ActiveCfg = Release|Any CPU {C585EA4E-FB09-47E9-B860-CE551701C25B}.Release|x86.Build.0 = Release|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Debug|Any CPU.Build.0 = Debug|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Debug|x64.ActiveCfg = Debug|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Debug|x64.Build.0 = Debug|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Debug|x86.ActiveCfg = Debug|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Debug|x86.Build.0 = Debug|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Release|Any CPU.ActiveCfg = Release|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Release|Any CPU.Build.0 = Release|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Release|x64.ActiveCfg = Release|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Release|x64.Build.0 = Release|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Release|x86.ActiveCfg = Release|Any CPU {307A5E39-85D4-42C3-B267-B36706BB1F86}.Release|x86.Build.0 = Release|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Debug|Any CPU.Build.0 = Debug|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Debug|x64.ActiveCfg = Debug|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Debug|x64.Build.0 = Debug|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Debug|x86.ActiveCfg = Debug|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Debug|x86.Build.0 = Debug|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Release|Any CPU.ActiveCfg = Release|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Release|Any CPU.Build.0 = Release|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Release|x64.ActiveCfg = Release|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Release|x64.Build.0 = Release|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Release|x86.ActiveCfg = Release|Any CPU {24AC7B65-7A18-4603-AB5A-B50A6903E5BF}.Release|x86.Build.0 = Release|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Debug|Any CPU.Build.0 = Debug|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Debug|x64.ActiveCfg = Debug|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Debug|x64.Build.0 = Debug|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Debug|x86.ActiveCfg = Debug|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Debug|x86.Build.0 = Debug|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Release|Any CPU.ActiveCfg = Release|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Release|Any CPU.Build.0 = Release|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Release|x64.ActiveCfg = Release|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Release|x64.Build.0 = Release|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Release|x86.ActiveCfg = Release|Any CPU {B7B5F165-21C3-456B-8F13-4C72FF6E6D32}.Release|x86.Build.0 = Release|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Debug|Any CPU.Build.0 = Debug|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Debug|x64.ActiveCfg = Debug|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Debug|x64.Build.0 = Debug|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Debug|x86.ActiveCfg = Debug|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Debug|x86.Build.0 = Debug|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Release|Any CPU.ActiveCfg = Release|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Release|Any CPU.Build.0 = Release|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Release|x64.ActiveCfg = Release|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Release|x64.Build.0 = Release|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Release|x86.ActiveCfg = Release|Any CPU {36332EB5-80A3-4B90-998A-55D24AB17715}.Release|x86.Build.0 = Release|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Debug|Any CPU.Build.0 = Debug|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Debug|x64.ActiveCfg = Debug|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Debug|x64.Build.0 = Debug|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Debug|x86.ActiveCfg = Debug|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Debug|x86.Build.0 = Debug|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Release|Any CPU.ActiveCfg = Release|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Release|Any CPU.Build.0 = Release|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Release|x64.ActiveCfg = Release|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Release|x64.Build.0 = Release|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Release|x86.ActiveCfg = Release|Any CPU {0C239946-4CA8-44B0-B0A3-7785931FAEB9}.Release|x86.Build.0 = Release|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Debug|Any CPU.Build.0 = Debug|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Debug|x64.ActiveCfg = Debug|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Debug|x64.Build.0 = Debug|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Debug|x86.ActiveCfg = Debug|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Debug|x86.Build.0 = Debug|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Release|Any CPU.ActiveCfg = Release|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Release|Any CPU.Build.0 = Release|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Release|x64.ActiveCfg = Release|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Release|x64.Build.0 = Release|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Release|x86.ActiveCfg = Release|Any CPU {8789C787-2125-413E-BB38-C9065C405D42}.Release|x86.Build.0 = Release|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Debug|Any CPU.Build.0 = Debug|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Debug|x64.ActiveCfg = Debug|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Debug|x64.Build.0 = Debug|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Debug|x86.ActiveCfg = Debug|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Debug|x86.Build.0 = Debug|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Release|Any CPU.ActiveCfg = Release|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Release|Any CPU.Build.0 = Release|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Release|x64.ActiveCfg = Release|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Release|x64.Build.0 = Release|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Release|x86.ActiveCfg = Release|Any CPU {B4CFADA1-1DC9-4E84-AE6C-64519D5FEB19}.Release|x86.Build.0 = Release|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Debug|Any CPU.Build.0 = Debug|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Debug|x64.ActiveCfg = Debug|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Debug|x64.Build.0 = Debug|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Debug|x86.ActiveCfg = Debug|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Debug|x86.Build.0 = Debug|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Release|Any CPU.ActiveCfg = Release|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Release|Any CPU.Build.0 = Release|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Release|x64.ActiveCfg = Release|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Release|x64.Build.0 = Release|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Release|x86.ActiveCfg = Release|Any CPU {E497EEBC-3B5C-4169-9DFA-37FEBBB7797A}.Release|x86.Build.0 = Release|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Debug|Any CPU.Build.0 = Debug|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Debug|x64.ActiveCfg = Debug|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Debug|x64.Build.0 = Debug|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Debug|x86.ActiveCfg = Debug|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Debug|x86.Build.0 = Debug|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Release|Any CPU.ActiveCfg = Release|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Release|Any CPU.Build.0 = Release|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Release|x64.ActiveCfg = Release|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Release|x64.Build.0 = Release|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Release|x86.ActiveCfg = Release|Any CPU {F63B2561-6C6C-4010-A63A-AAB03F8C3E30}.Release|x86.Build.0 = Release|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Debug|Any CPU.Build.0 = Debug|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Debug|x64.ActiveCfg = Debug|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Debug|x64.Build.0 = Debug|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Debug|x86.ActiveCfg = Debug|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Debug|x86.Build.0 = Debug|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Release|Any CPU.ActiveCfg = Release|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Release|Any CPU.Build.0 = Release|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Release|x64.ActiveCfg = Release|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Release|x64.Build.0 = Release|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Release|x86.ActiveCfg = Release|Any CPU {1E662F33-8F91-48EB-A659-594E7039C65A}.Release|x86.Build.0 = Release|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Debug|Any CPU.Build.0 = Debug|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Debug|x64.ActiveCfg = Debug|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Debug|x64.Build.0 = Debug|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Debug|x86.ActiveCfg = Debug|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Debug|x86.Build.0 = Debug|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Release|Any CPU.ActiveCfg = Release|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Release|Any CPU.Build.0 = Release|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Release|x64.ActiveCfg = Release|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Release|x64.Build.0 = Release|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Release|x86.ActiveCfg = Release|Any CPU {FAC71622-8310-4139-944B-F1FBF6588843}.Release|x86.Build.0 = Release|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Debug|Any CPU.Build.0 = Debug|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Debug|x64.ActiveCfg = Debug|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Debug|x64.Build.0 = Debug|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Debug|x86.ActiveCfg = Debug|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Debug|x86.Build.0 = Debug|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Release|Any CPU.ActiveCfg = Release|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Release|Any CPU.Build.0 = Release|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Release|x64.ActiveCfg = Release|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Release|x64.Build.0 = Release|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Release|x86.ActiveCfg = Release|Any CPU {8D57B4D2-AB2E-41D4-AE7D-D6A4A173A40F}.Release|x86.Build.0 = Release|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Debug|Any CPU.Build.0 = Debug|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Debug|x64.ActiveCfg = Debug|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Debug|x64.Build.0 = Debug|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Debug|x86.ActiveCfg = Debug|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Debug|x86.Build.0 = Debug|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Release|Any CPU.ActiveCfg = Release|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Release|Any CPU.Build.0 = Release|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Release|x64.ActiveCfg = Release|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Release|x64.Build.0 = Release|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Release|x86.ActiveCfg = Release|Any CPU {698A0646-07E5-4A43-8D02-229BF3571086}.Release|x86.Build.0 = Release|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Debug|Any CPU.Build.0 = Debug|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Debug|x64.ActiveCfg = Debug|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Debug|x64.Build.0 = Debug|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Debug|x86.ActiveCfg = Debug|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Debug|x86.Build.0 = Debug|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Release|Any CPU.ActiveCfg = Release|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Release|Any CPU.Build.0 = Release|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Release|x64.ActiveCfg = Release|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Release|x64.Build.0 = Release|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Release|x86.ActiveCfg = Release|Any CPU {D51F509E-9970-4454-B246-0970FF6C69CC}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {DBCC3BDC-8B47-46D6-A037-B71BC30D9B0A} EndGlobalSection EndGlobal ================================================ FILE: WPF/ControlPanel/App.xaml ================================================  ================================================ FILE: WPF/ControlPanel/App.xaml.cs ================================================ using System.Windows; namespace ControlPanel { /// /// Interaction logic for App.xaml /// public partial class App : Application { } } ================================================ FILE: WPF/ControlPanel/AssemblyInfo.cs ================================================ using System.Windows; [assembly: ThemeInfo( ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located //(used if a resource is not found in the page, // or application resource dictionaries) ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries) )] ================================================ FILE: WPF/ControlPanel/COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: WPF/ControlPanel/ControlPanel.csproj ================================================  WinExe net6.0-windows enable true false 11 all runtime; build; native; contentfiles; analyzers; buildtransitive True True Langs.resx MSBuild:Compile Wpf Designer true en-US,zh-Hans ================================================ FILE: WPF/ControlPanel/ControlPanel.xaml ================================================  ================================================ FILE: WPF/ControlPanel/Converters/CheckBoxConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows.Data; namespace ControlPanel.Converters; public class CheckBoxConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { return value != null && ( value.ToString()?.Equals( parameter ) ?? false ); } public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) { return value != null && value.Equals( true ) ? parameter : Binding.DoNothing; } } ================================================ FILE: WPF/ControlPanel/Converters/CheckBoxStateByIndexConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows.Data; namespace ControlPanel.Converters; public class CheckBoxStateByIndexConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { return value is >= 0; } public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) { throw new NotImplementedException(); } } ================================================ FILE: WPF/ControlPanel/Converters/DrawerStateMutexConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows; using System.Windows.Data; namespace ControlPanel.Converters; public class DrawerStateMutexConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { return (bool)value ? Visibility.Hidden : Visibility.Visible; } public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) { throw new NotImplementedException(); } } ================================================ FILE: WPF/ControlPanel/Converters/LocConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows.Data; namespace ControlPanel.Converters; public class LocConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { return parameter.ToString() + value; } public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) { throw new NotImplementedException(); } } ================================================ FILE: WPF/ControlPanel/Converters/MouseActionConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows.Data; using System.Windows.Forms; using VirtualSpace.Config; namespace ControlPanel.Converters; public class MouseActionConverter : IMultiValueConverter { public object Convert( object[] values, Type targetType, object parameter, CultureInfo culture ) { if ( values.Length == 0 ) return null; var prefix = values[0].ToString() == MouseAction.MOUSE_NODE_DESKTOP_PREFIX ? MouseAction.MOUSE_NODE_DESKTOP_PREFIX : MouseAction.MOUSE_NODE_WINDOW_PREFIX; var mks = Keys.None; if ( (bool)values[1] ) mks |= Keys.LWin; if ( (bool)values[2] ) mks |= Keys.Control; if ( (bool)values[3] ) mks |= Keys.Alt; if ( (bool)values[4] ) mks |= Keys.Shift; var mb = values[5]; var keyCode = ( (int)mks ).ToString( "X2" ); var maId = prefix + keyCode + MouseAction.KEY_SPLITTER + mb; if ( Manager.Configs.MouseActions.ContainsKey( maId ) ) { return Manager.Configs.MouseActions[maId].ToString(); } return MouseAction.Action.DoNothing.ToString(); } public object[] ConvertBack( object value, Type[] targetTypes, object parameter, CultureInfo culture ) { throw new NotImplementedException(); } } ================================================ FILE: WPF/ControlPanel/Converters/RuleFieldConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Linq; using System.Text.Json; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using ControlPanel.ViewModels; using VirtualSpace.Config.Events.Expression; namespace ControlPanel.Converters; public class RuleFieldConverter : IMultiValueConverter { public object Convert( object[] values, Type targetType, object parameter, CultureInfo culture ) { var type = parameter.ToString(); if ( type == "V" ) { return ForValue( values ); } if ( type == typeof( ComboBox ).FullName ) { return ForCombobox( values ); } if ( type == typeof( CheckBox ).FullName ) { return ForCheckBox( values ); } if ( type == typeof( TextBox ).FullName ) { return ForTextBox( values ); } return null; } private static int ForValue( object[] values ) { if ( values is null || values[0] is null || values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue ) return 0; try { var jsonDocument = (JsonDocument)values[0]; var expressionTemplate = Conditions.ParseExpressionTemplate( jsonDocument ); foreach ( var r in expressionTemplate.rules ) { if ( r.field == values[1].ToString() ) { var index = RulesViewModel.Screens.Select( ( vv, index ) => new {nv = vv, index} ) .Where( pair => ( (dynamic)pair.nv ).Value.ToString() == r.value.V ) .Select( pair => pair.index + 1 ) .FirstOrDefault() - 1; return index; } } } catch { return 0; } return 0; } private static int ForCombobox( object[] values ) { if ( values is null || values[0] is null || values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue ) return 0; try { var jsonDocument = (JsonDocument)values[0]; var expressionTemplate = Conditions.ParseExpressionTemplate( jsonDocument ); foreach ( var r in expressionTemplate.rules ) { if ( r.field == values[1].ToString() ) { var index = RulesViewModel.Operators.Select( ( v, index ) => new {value = v, index} ) .Where( pair => ( (dynamic)pair.value ).Value.ToString() == r.@operator ) .Select( pair => pair.index + 1 ) .FirstOrDefault() - 1; return index; } } } catch { return 0; } return 0; } private static bool ForCheckBox( object[] values ) { if ( values is null || values[0] is null || values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue ) return false; try { var jsonDocument = (JsonDocument)values[0]; var expressionTemplate = Conditions.ParseExpressionTemplate( jsonDocument ); foreach ( var r in expressionTemplate.rules ) { if ( r.field == values[1].ToString() ) { return true; } } } catch { return false; } return false; } private static string ForTextBox( object[] values ) { if ( values is null || values[0] is null || values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue ) return ""; try { var jsonDocument = (JsonDocument)values[0]; var expressionTemplate = Conditions.ParseExpressionTemplate( jsonDocument ); foreach ( var r in expressionTemplate.rules ) { if ( r.field == values[1].ToString() ) { return r.value.V; } } } catch { return ""; } return ""; } public object[] ConvertBack( object value, Type[] targetTypes, object parameter, CultureInfo culture ) { throw new NotImplementedException(); } } ================================================ FILE: WPF/ControlPanel/Converters/RuleFieldFromControlNameConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows.Data; namespace ControlPanel.Converters; public class RuleFieldFromControlNameConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { var name = value as string; return name.Split( "_" )[1]; } public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) { return int.Parse( value.ToString() ); } } ================================================ FILE: WPF/ControlPanel/Converters/RuleFormDefaultValueConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows.Data; namespace ControlPanel.Converters; public class RuleFormDefaultValueConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { var v = (int)value; return v < 0 ? 0 : v; } public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) { throw new NotImplementedException(); } } ================================================ FILE: WPF/ControlPanel/Converters/RuleHeaderByStateConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows.Data; namespace ControlPanel.Converters; public class RuleHeaderByStateConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { var guid = (Guid)value; return guid == Guid.Empty ? "Page.Rules.NewRule" : "Page.Rules.EditRule"; } public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) { throw new NotImplementedException(); } } ================================================ FILE: WPF/ControlPanel/Converters/ThemeConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows.Data; namespace ControlPanel.Converters; public class ThemeConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { return (int)value; } public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) { return int.Parse( value.ToString() ); } } ================================================ FILE: WPF/ControlPanel/Converters/UIButtonStyleByVdAConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows.Data; using System.Windows.Media; namespace ControlPanel.Converters; public class UIButtonStyleByVdAConverter : IMultiValueConverter { public object Convert( object[] values, Type targetType, object parameter, CultureInfo culture ) { if ( parameter.ToString() == "B" ) { var vda = (int)values[0]; var buttonIndex = int.Parse( values[1].ToString() ); return vda == buttonIndex ? new SolidColorBrush( Colors.Pink ) : new SolidColorBrush( Colors.LightGray ); } var count = (int)values[0]; return GetFlag( count ) || values[1].ToString() == "0"; } public object[] ConvertBack( object value, Type[] targetTypes, object parameter, CultureInfo culture ) { throw new NotImplementedException(); } private static bool GetFlag( int num ) { var result = Math.Sqrt( num ); return result % 1 == 0; } } ================================================ FILE: WPF/ControlPanel/Converters/WidthHeightConverter.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System; using System.Globalization; using System.Windows.Data; namespace ControlPanel.Converters; public class WidthHeightConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { return (double)value - double.Parse( parameter.ToString() ); } public object ConvertBack( object value, Type targetTypes, object parameter, CultureInfo culture ) { throw new NotImplementedException(); } } ================================================ FILE: WPF/ControlPanel/ExportResourceDictionary.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of ControlPanel. // // ControlPanel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // ControlPanel is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with ControlPanel. If not, see . using System.Windows.Markup; [assembly: XmlnsDefinition( "http://newlooper.com/virtualspace/share", "ControlPanel" )] namespace ControlPanel; public partial class ExportResourceDictionary { public static ExportResourceDictionary Instance { get; } = new ExportResourceDictionary(); public ExportResourceDictionary() { InitializeComponent(); } } ================================================ FILE: WPF/ControlPanel/ExportResourceDictionary.xaml ================================================  ================================================ FILE: WPF/ControlPanel/Factories/NavBarItem.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using MaterialDesignThemes.Wpf; using WPFLocalizeExtension.Extensions; namespace ControlPanel.Factories; public class NavBarItem : TabItem { public static readonly Dictionary NavBarItemsInfo = new() { {"General", ( PackIconKind.MonitorDashboard, "NavBar.General" )}, {"UI", ( PackIconKind.TableAccount, "NavBar.UI" )}, {"Control", ( PackIconKind.CursorPointer, "NavBar.Control" )}, {"Rules", ( PackIconKind.BookOpenPageVariant, "NavBar.Rules" )}, {"Plugins", ( PackIconKind.ToyBrickMarkerOutline, "NavBar.Plugins" )}, {"Logs", ( PackIconKind.BookSearchOutline, "NavBar.Logs" )}, {"About", ( PackIconKind.HelpBox, "NavBar.About" )}, }; private NavBarItem( string tag, PackIconKind kind, string locKey ) { var stackPanel = new StackPanel { Width = double.NaN, Height = double.NaN }; var packIcon = new PackIcon { Width = 24, Height = 24, HorizontalAlignment = HorizontalAlignment.Center, Kind = kind }; var tb = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center }; new LocExtension( locKey ).SetBinding( tb, TextBlock.TextProperty ); stackPanel.Children.Add( packIcon ); stackPanel.Children.Add( tb ); Header = stackPanel; Tag = tag; } public static void InitNavBar( TabControl tc ) { foreach ( var kv in NavBarItemsInfo ) tc.Items.Add( new NavBarItem( kv.Key, kv.Value.kind, kv.Value.locKey ) ); } } ================================================ FILE: WPF/ControlPanel/Factories/PageFactory.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System.Windows.Controls; using ControlPanel.Pages; using MaterialDesignThemes.Wpf; using Control = ControlPanel.Pages.Control; namespace ControlPanel.Factories; public static class PageFactory { public static UserControl GetPage( (PackIconKind kind, string locKey) info ) { return info.locKey switch { "NavBar.General" => General.Create( info.locKey, info.kind ), "NavBar.UI" => UI.Create( info.locKey, info.kind ), "NavBar.Rules" => Rules.Create( info.locKey, info.kind ), "NavBar.Control" => Control.Create( info.locKey, info.kind ), "NavBar.Plugins" => Plugins.Create( info.locKey, info.kind ), "NavBar.Logs" => Logs.Create( info.locKey, info.kind ), "NavBar.About" => Help.Instance, "NavBar.Settings" => Settings.Create(), _ => General.Create( info.locKey, info.kind ) }; } } ================================================ FILE: WPF/ControlPanel/FodyWeavers.xml ================================================  ================================================ FILE: WPF/ControlPanel/MainWindow.logs.cs ================================================ /* Copyright (C) 2021 Dylan Cheng (https://github.com/newlooper) This file is part of VirtualSpace. VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . */ using System.Threading; using System.Threading.Channels; using ControlPanel.Pages; using VirtualSpace.AppLogs; namespace ControlPanel; /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow { private static readonly Channel LogChannel = Logger.LogChannel; private readonly CancellationTokenSource _cancelTokenSourceForLog = new(); private async void PickLogAndWrite( CancellationToken stoppingToken ) { try { while ( await LogChannel.Reader.WaitToReadAsync( stoppingToken ) ) { if ( LogChannel.Reader.TryRead( out var message ) ) { Logs.Append( message.Message, message.Type ); } } } catch { // ignored } finally { _cancelTokenSourceForLog.Dispose(); } } } ================================================ FILE: WPF/ControlPanel/MainWindow.theme.cs ================================================ // Copyright (C) 2023 Dylan Cheng (https://github.com/newlooper) // // This file is part of VirtualSpace. // // VirtualSpace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // VirtualSpace is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with VirtualSpace. If not, see . using System.Windows.Media; using MaterialDesignColors; using MaterialDesignThemes.Wpf; using VirtualSpace.Config; using VirtualSpace.Helpers; namespace ControlPanel; public partial class MainWindow { private (Color pColor, Color sColor, IBaseTheme theme) GetThemeInfo() { var theme = Theme.Light; Color pColor; Color sColor; var pColorDark = SwatchHelper.Lookup[(MaterialDesignColor)PrimaryColor.Blue]; var sColorDark = SwatchHelper.Lookup[(MaterialDesignColor)SecondaryColor.LightBlue]; var pColorLight = SwatchHelper.Lookup[(MaterialDesignColor)PrimaryColor.Amber]; var sColorLight = SwatchHelper.Lookup[(MaterialDesignColor)SecondaryColor.Yellow]; switch ( Manager.CurrentProfile.UI.Theme ) { case 0: theme = SysInfo.GetAppsTheme() == SysInfo.WinAppsTheme.LIGHT ? Theme.Light : Theme.Dark; pColor = theme == Theme.Dark ? pColorDark : pColorLight; sColor = theme == Theme.Dark ? sColorDark : sColorLight; break; case 1: pColor = pColorLight; sColor = sColorLight; theme = Theme.Light; break; case 2: pColor = pColorDark; sColor = sColorDark; theme = Theme.Dark; break; } return ( pColor, sColor, theme ); } private void InitTheme() { UpdateTheme(); RegValueMonitor.OnRegValueChanged += ( o, args ) => { if ( Manager.CurrentProfile.UI.Theme != 0 ) return; var theme = Resources.GetTheme(); var (pColor, sColor, newTheme) = GetThemeInfo(); theme.SetPrimaryColor( pColor ); theme.SetSecondaryColor( sColor ); theme.SetBaseTheme( newTheme ); Dispatcher.Invoke( () => { Resources.SetTheme( theme ); } ); }; } public static void UpdateTheme() { var (primaryColor, secondaryColor, initTheme) = _instance.GetThemeInfo(); _instance.Resources.SetTheme( Theme.Create( initTheme, primaryColor, secondaryColor ) ); } } ================================================ FILE: WPF/ControlPanel/MainWindow.xaml ================================================