mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
[FancyZones] Obtain device id (#8451)
This commit is contained in:
@@ -644,42 +644,56 @@ void FancyZones::ToggleEditor() noexcept
|
|||||||
std::vector<std::pair<HMONITOR, MONITORINFOEX>> allMonitors;
|
std::vector<std::pair<HMONITOR, MONITORINFOEX>> allMonitors;
|
||||||
allMonitors = FancyZonesUtils::GetAllMonitorInfo<&MONITORINFOEX::rcWork>();
|
allMonitors = FancyZonesUtils::GetAllMonitorInfo<&MONITORINFOEX::rcWork>();
|
||||||
|
|
||||||
|
// device id map
|
||||||
|
std::unordered_map<std::wstring, DWORD> displayDeviceIdxMap;
|
||||||
|
|
||||||
bool showDpiWarning = false;
|
bool showDpiWarning = false;
|
||||||
int prevDpiX = -1, prevDpiY = -1;
|
int prevDpiX = -1, prevDpiY = -1;
|
||||||
std::wstring monitorsData;
|
std::wstring monitorsDataStr;
|
||||||
for (auto& monitor : allMonitors)
|
for (auto& monitorData : allMonitors)
|
||||||
{
|
{
|
||||||
auto monitorId = FancyZonesUtils::GenerateMonitorId(monitor.second, monitor.first, m_currentDesktopId);
|
HMONITOR monitor = monitorData.first;
|
||||||
if (monitor.first == targetMonitor)
|
auto monitorInfo = monitorData.second;
|
||||||
|
|
||||||
|
std::wstring monitorId;
|
||||||
|
std::wstring deviceId = FancyZonesUtils::GetDisplayDeviceId(monitorInfo.szDevice, displayDeviceIdxMap);
|
||||||
|
wil::unique_cotaskmem_string virtualDesktopId;
|
||||||
|
if (SUCCEEDED(StringFromCLSID(m_currentDesktopId, &virtualDesktopId)))
|
||||||
{
|
{
|
||||||
params += *monitorId + divider; /* Monitor id where the Editor should be opened */
|
monitorId = FancyZonesUtils::GenerateUniqueId(monitor, deviceId, virtualDesktopId.get());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitorId.has_value())
|
if (monitor == targetMonitor)
|
||||||
{
|
{
|
||||||
monitorsData += std::move(*monitorId) + divider; /* Monitor id */
|
params += monitorId + divider; /* Monitor id where the Editor should be opened */
|
||||||
|
}
|
||||||
|
|
||||||
UINT dpiX = 0;
|
monitorsDataStr += std::move(monitorId) + divider; /* Monitor id */
|
||||||
UINT dpiY = 0;
|
|
||||||
if (GetDpiForMonitor(monitor.first, MDT_EFFECTIVE_DPI, &dpiX, &dpiY) == S_OK)
|
UINT dpiX = 0;
|
||||||
|
UINT dpiY = 0;
|
||||||
|
if (GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY) == S_OK)
|
||||||
|
{
|
||||||
|
monitorsDataStr += std::to_wstring(dpiX) + divider; /* DPI */
|
||||||
|
if (spanZonesAcrossMonitors && prevDpiX != -1 && (prevDpiX != dpiX || prevDpiY != dpiY))
|
||||||
{
|
{
|
||||||
monitorsData += std::to_wstring(dpiX) + divider; /* DPI */
|
showDpiWarning = true;
|
||||||
if (spanZonesAcrossMonitors && prevDpiX != -1 && (prevDpiX != dpiX || prevDpiY != dpiY))
|
|
||||||
{
|
|
||||||
showDpiWarning = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
prevDpiX = dpiX;
|
|
||||||
prevDpiY = dpiY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
monitorsData += std::to_wstring(monitor.second.rcMonitor.left) + divider;
|
prevDpiX = dpiX;
|
||||||
monitorsData += std::to_wstring(monitor.second.rcMonitor.top) + divider;
|
prevDpiY = dpiY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
monitorsDataStr += std::to_wstring(monitorInfo.rcMonitor.left) + divider;
|
||||||
|
monitorsDataStr += std::to_wstring(monitorInfo.rcMonitor.top) + divider;
|
||||||
}
|
}
|
||||||
|
|
||||||
params += std::to_wstring(allMonitors.size()) + divider; /* Monitors count */
|
params += std::to_wstring(allMonitors.size()) + divider; /* Monitors count */
|
||||||
params += monitorsData;
|
params += monitorsDataStr;
|
||||||
|
|
||||||
if (showDpiWarning)
|
if (showDpiWarning)
|
||||||
{
|
{
|
||||||
@@ -957,30 +971,8 @@ void FancyZones::UpdateZoneWindows() noexcept
|
|||||||
auto& displayDeviceIdxMap = *(params->displayDeviceIdx);
|
auto& displayDeviceIdxMap = *(params->displayDeviceIdx);
|
||||||
FancyZones* fancyZones = params->fancyZones;
|
FancyZones* fancyZones = params->fancyZones;
|
||||||
|
|
||||||
DISPLAY_DEVICE displayDevice{ .cb = sizeof(displayDevice) };
|
std::wstring deviceId = FancyZonesUtils::GetDisplayDeviceId(mi.szDevice, displayDeviceIdxMap);
|
||||||
std::wstring deviceId;
|
fancyZones->AddZoneWindow(monitor, deviceId);
|
||||||
while (EnumDisplayDevicesW(mi.szDevice, displayDeviceIdxMap[mi.szDevice], &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
|
|
||||||
{
|
|
||||||
++displayDeviceIdxMap[mi.szDevice];
|
|
||||||
// Only take active monitors (presented as being "on" by the respective GDI view) and monitors that don't
|
|
||||||
// represent a pseudo device used to mirror application drawing.
|
|
||||||
if (WI_IsFlagSet(displayDevice.StateFlags, DISPLAY_DEVICE_ACTIVE) &&
|
|
||||||
WI_IsFlagClear(displayDevice.StateFlags, DISPLAY_DEVICE_MIRRORING_DRIVER))
|
|
||||||
{
|
|
||||||
deviceId = displayDevice.DeviceID;
|
|
||||||
fancyZones->AddZoneWindow(monitor, deviceId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceId.empty())
|
|
||||||
{
|
|
||||||
deviceId = GetSystemMetrics(SM_REMOTESESSION) ?
|
|
||||||
L"\\\\?\\DISPLAY#REMOTEDISPLAY#" :
|
|
||||||
L"\\\\?\\DISPLAY#LOCALDISPLAY#";
|
|
||||||
|
|
||||||
fancyZones->AddZoneWindow(monitor, deviceId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -155,6 +155,34 @@ namespace FancyZonesUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef BOOL(WINAPI* GetDpiForMonitorInternalFunc)(HMONITOR, UINT, UINT*, UINT*);
|
typedef BOOL(WINAPI* GetDpiForMonitorInternalFunc)(HMONITOR, UINT, UINT*, UINT*);
|
||||||
|
std::wstring GetDisplayDeviceId(const std::wstring& device, std::unordered_map<std::wstring, DWORD>& displayDeviceIdxMap)
|
||||||
|
{
|
||||||
|
DISPLAY_DEVICE displayDevice{ .cb = sizeof(displayDevice) };
|
||||||
|
std::wstring deviceId;
|
||||||
|
while (EnumDisplayDevicesW(device.c_str(), displayDeviceIdxMap[device], &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
|
||||||
|
{
|
||||||
|
++displayDeviceIdxMap[device];
|
||||||
|
|
||||||
|
// Only take active monitors (presented as being "on" by the respective GDI view) and monitors that don't
|
||||||
|
// represent a pseudo device used to mirror application drawing.
|
||||||
|
if (WI_IsFlagSet(displayDevice.StateFlags, DISPLAY_DEVICE_ACTIVE) &&
|
||||||
|
WI_IsFlagClear(displayDevice.StateFlags, DISPLAY_DEVICE_MIRRORING_DRIVER))
|
||||||
|
{
|
||||||
|
deviceId = displayDevice.DeviceID;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceId.empty())
|
||||||
|
{
|
||||||
|
deviceId = GetSystemMetrics(SM_REMOTESESSION) ?
|
||||||
|
L"\\\\?\\DISPLAY#REMOTEDISPLAY#" :
|
||||||
|
L"\\\\?\\DISPLAY#LOCALDISPLAY#";
|
||||||
|
}
|
||||||
|
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
UINT GetDpiForMonitor(HMONITOR monitor) noexcept
|
UINT GetDpiForMonitor(HMONITOR monitor) noexcept
|
||||||
{
|
{
|
||||||
UINT dpi{};
|
UINT dpi{};
|
||||||
@@ -582,36 +610,6 @@ namespace FancyZonesUtils
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::wstring> GenerateMonitorId(MONITORINFOEX mi, HMONITOR monitor, const GUID& virtualDesktopId)
|
|
||||||
{
|
|
||||||
DISPLAY_DEVICE displayDevice = { sizeof(displayDevice) };
|
|
||||||
PCWSTR deviceId = nullptr;
|
|
||||||
|
|
||||||
bool validMonitor = true;
|
|
||||||
if (EnumDisplayDevices(mi.szDevice, 0, &displayDevice, 1))
|
|
||||||
{
|
|
||||||
if (displayDevice.DeviceID[0] != L'\0')
|
|
||||||
{
|
|
||||||
deviceId = displayDevice.DeviceID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!deviceId)
|
|
||||||
{
|
|
||||||
deviceId = GetSystemMetrics(SM_REMOTESESSION) ?
|
|
||||||
L"\\\\?\\DISPLAY#REMOTEDISPLAY#" :
|
|
||||||
L"\\\\?\\DISPLAY#LOCALDISPLAY#";
|
|
||||||
}
|
|
||||||
|
|
||||||
wil::unique_cotaskmem_string vdId;
|
|
||||||
if (SUCCEEDED(StringFromCLSID(virtualDesktopId, &vdId)))
|
|
||||||
{
|
|
||||||
return GenerateUniqueId(monitor, deviceId, vdId.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t ChooseNextZoneByPosition(DWORD vkCode, RECT windowRect, const std::vector<RECT>& zoneRects) noexcept
|
size_t ChooseNextZoneByPosition(DWORD vkCode, RECT windowRect, const std::vector<RECT>& zoneRects) noexcept
|
||||||
{
|
{
|
||||||
using complex = std::complex<double>;
|
using complex = std::complex<double>;
|
||||||
|
|||||||
@@ -184,6 +184,8 @@ namespace FancyZonesUtils
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::wstring GetDisplayDeviceId(const std::wstring& device, std::unordered_map<std::wstring, DWORD>& displayDeviceIdxMap);
|
||||||
|
|
||||||
UINT GetDpiForMonitor(HMONITOR monitor) noexcept;
|
UINT GetDpiForMonitor(HMONITOR monitor) noexcept;
|
||||||
void OrderMonitors(std::vector<std::pair<HMONITOR, RECT>>& monitorInfo);
|
void OrderMonitors(std::vector<std::pair<HMONITOR, RECT>>& monitorInfo);
|
||||||
void SizeWindowToRect(HWND window, RECT rect) noexcept;
|
void SizeWindowToRect(HWND window, RECT rect) noexcept;
|
||||||
@@ -202,7 +204,6 @@ namespace FancyZonesUtils
|
|||||||
|
|
||||||
std::wstring GenerateUniqueId(HMONITOR monitor, const std::wstring& devideId, const std::wstring& virtualDesktopId);
|
std::wstring GenerateUniqueId(HMONITOR monitor, const std::wstring& devideId, const std::wstring& virtualDesktopId);
|
||||||
std::wstring GenerateUniqueIdAllMonitorsArea(const std::wstring& virtualDesktopId);
|
std::wstring GenerateUniqueIdAllMonitorsArea(const std::wstring& virtualDesktopId);
|
||||||
std::optional<std::wstring> GenerateMonitorId(MONITORINFOEX mi, HMONITOR monitor, const GUID& virtualDesktopId);
|
|
||||||
|
|
||||||
std::wstring TrimDeviceId(const std::wstring& deviceId);
|
std::wstring TrimDeviceId(const std::wstring& deviceId);
|
||||||
std::optional<FancyZonesDataTypes::DeviceIdData> ParseDeviceId(const std::wstring& deviceId);
|
std::optional<FancyZonesDataTypes::DeviceIdData> ParseDeviceId(const std::wstring& deviceId);
|
||||||
|
|||||||
Reference in New Issue
Block a user