mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
[Workspaces] Saving app properties on launch and recapture (#36751)
* [Workspaces] Implementing set and get GUID to/from HWND to distinguish windows moved by the Workspaces tool * After launch and capture copy the CLI args from the "original" project * Fix getting GUID * spell check * modification to be able to handle different data sizes on different systems * code optimisation * Replacing string parameter by InvokePoint * renaming variable
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <WorkspacesLib/AppUtils.h>
|
||||
#include <WorkspacesLib/PwaHelper.h>
|
||||
#include <WindowProperties/WorkspacesWindowPropertyUtils.h>
|
||||
|
||||
#pragma comment(lib, "ntdll.lib")
|
||||
|
||||
@@ -38,7 +39,7 @@ namespace SnapshotUtils
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle, const std::function<WorkspacesData::WorkspacesProject::Monitor::MonitorRect(unsigned int)> getMonitorRect)
|
||||
std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(bool isGuidNeeded, const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle, const std::function<WorkspacesData::WorkspacesProject::Monitor::MonitorRect(unsigned int)> getMonitorRect)
|
||||
{
|
||||
Utils::PwaHelper pwaHelper{};
|
||||
std::vector<WorkspacesData::WorkspacesProject::Application> apps{};
|
||||
@@ -157,7 +158,10 @@ namespace SnapshotUtils
|
||||
rect.bottom = monitorRect.top + monitorRect.height;
|
||||
}
|
||||
|
||||
std::wstring guid = isGuidNeeded ? WorkspacesWindowProperties::GetGuidFromHwnd(window) : L"";
|
||||
|
||||
WorkspacesData::WorkspacesProject::Application app{
|
||||
.id = guid,
|
||||
.name = appData.name,
|
||||
.title = title,
|
||||
.path = appData.installPath,
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
|
||||
namespace SnapshotUtils
|
||||
{
|
||||
std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle, const std::function<WorkspacesData::WorkspacesProject::Monitor::MonitorRect(unsigned int)> getMonitorRect);
|
||||
std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(bool isGuidNeeded, const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle, const std::function<WorkspacesData::WorkspacesProject::Monitor::MonitorRect(unsigned int)> getMonitorRect);
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <common/utils/gpo.h>
|
||||
#include <common/utils/logger_helper.h>
|
||||
#include <common/utils/UnhandledExceptionHandler.h>
|
||||
#include <WorkspacesLib/utils.h>
|
||||
|
||||
const std::wstring moduleName = L"Workspaces\\WorkspacesSnapshotTool";
|
||||
const std::wstring internalPath = L"";
|
||||
@@ -46,13 +47,17 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdLine, int cm
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::wstring cmdLineStr{ GetCommandLineW() };
|
||||
auto cmdArgs = split(cmdLineStr, L" ");
|
||||
|
||||
// create new project
|
||||
time_t creationTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
WorkspacesData::WorkspacesProject project{ .id = CreateGuidString(), .creationTime = creationTime };
|
||||
Logger::trace(L"Creating workspace {}:{}", project.name, project.id);
|
||||
|
||||
project.monitors = MonitorUtils::IdentifyMonitors();
|
||||
project.apps = SnapshotUtils::GetApps([&](HWND window) -> unsigned int {
|
||||
bool isGuidNeeded = cmdArgs.invokePoint == InvokePoint::LaunchAndEdit;
|
||||
project.apps = SnapshotUtils::GetApps(isGuidNeeded, [&](HWND window) -> unsigned int {
|
||||
auto windowMonitor = MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY);
|
||||
unsigned int monitorNumber = 0;
|
||||
for (const auto& monitor : project.monitors)
|
||||
|
||||
Reference in New Issue
Block a user