common: refactor common library pt2 (#8588)

- remove common lib
- split settings, remove common-md
- move ipc interop/kb_layout to interop
- rename core -> settings, settings -> old_settings
- os-detect header-only; interop -> PowerToysInterop
- split notifications, move single-use headers where they're used
- winstore lib
- rename com utils
- rename Updating and Telemetry projects
- rename core -> settings-ui and remove examples folder
- rename settings-ui folder + consisent common/version include
This commit is contained in:
Andrey Nekrasov
2020-12-15 15:16:09 +03:00
committed by GitHub
parent cddf48547d
commit 212ea2de30
588 changed files with 3304 additions and 3328 deletions

View File

@@ -0,0 +1,93 @@
#include "dpi_aware.h"
#include "monitors.h"
#include <ShellScalingApi.h>
#include <array>
#pragma comment(lib, "shcore.lib")
namespace DPIAware
{
HRESULT GetScreenDPIForWindow(HWND hwnd, UINT& dpi_x, UINT& dpi_y)
{
auto monitor_handle = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
dpi_x = 0;
dpi_y = 0;
if (monitor_handle != nullptr)
{
return GetDpiForMonitor(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y);
}
else
{
return E_FAIL;
}
}
HRESULT GetScreenDPIForPoint(POINT p, UINT& dpi_x, UINT& dpi_y)
{
auto monitor_handle = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST);
dpi_x = 0;
dpi_y = 0;
if (monitor_handle != nullptr)
{
return GetDpiForMonitor(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y);
}
else
{
return E_FAIL;
}
}
void Convert(HMONITOR monitor_handle, int& width, int& height)
{
if (monitor_handle == NULL)
{
const POINT ptZero = { 0, 0 };
monitor_handle = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
}
UINT dpi_x, dpi_y;
if (GetDpiForMonitor(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y) == S_OK)
{
width = width * static_cast<int>(dpi_x) / DEFAULT_DPI;
height = height * static_cast<int>(dpi_y) / DEFAULT_DPI;
}
}
void InverseConvert(HMONITOR monitor_handle, int& width, int& height)
{
if (monitor_handle == NULL)
{
const POINT ptZero = { 0, 0 };
monitor_handle = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
}
UINT dpi_x, dpi_y;
if (GetDpiForMonitor(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y) == S_OK)
{
width = width * DEFAULT_DPI / static_cast<int>(dpi_x);
height = height * DEFAULT_DPI / static_cast<int>(dpi_y);
}
}
void EnableDPIAwarenessForThisProcess()
{
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
}
AwarenessLevel GetAwarenessLevel(DPI_AWARENESS_CONTEXT system_returned_value)
{
const std::array levels{ DPI_AWARENESS_CONTEXT_UNAWARE,
DPI_AWARENESS_CONTEXT_SYSTEM_AWARE,
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE,
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2,
DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED };
for (size_t i = 0; i < size(levels); ++i)
{
if (AreDpiAwarenessContextsEqual(levels[i], system_returned_value))
{
return static_cast<AwarenessLevel>(i);
}
}
return AwarenessLevel::UNAWARE;
}
}