2020-02-10 21:59:51 +08:00
|
|
|
#include "pch.h"
|
|
|
|
|
|
|
|
#include <common/common.h>
|
|
|
|
|
|
|
|
#include "ZoneWindow.h"
|
|
|
|
#include "trace.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#include <ShellScalingApi.h>
|
|
|
|
#include <mutex>
|
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
#include <gdiplus.h>
|
|
|
|
|
2020-02-10 21:59:51 +08:00
|
|
|
namespace ZoneWindowUtils
|
|
|
|
{
|
|
|
|
const std::wstring& GetActiveZoneSetTmpPath()
|
|
|
|
{
|
|
|
|
static std::wstring activeZoneSetTmpFileName;
|
|
|
|
static std::once_flag flag;
|
|
|
|
|
|
|
|
std::call_once(flag, []() {
|
|
|
|
wchar_t fileName[L_tmpnam_s];
|
|
|
|
|
|
|
|
if (_wtmpnam_s(fileName, L_tmpnam_s) != 0)
|
|
|
|
abort();
|
|
|
|
|
|
|
|
activeZoneSetTmpFileName = std::wstring{ fileName };
|
|
|
|
});
|
|
|
|
|
|
|
|
return activeZoneSetTmpFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::wstring& GetAppliedZoneSetTmpPath()
|
|
|
|
{
|
|
|
|
static std::wstring appliedZoneSetTmpFileName;
|
|
|
|
static std::once_flag flag;
|
|
|
|
|
|
|
|
std::call_once(flag, []() {
|
|
|
|
wchar_t fileName[L_tmpnam_s];
|
|
|
|
|
|
|
|
if (_wtmpnam_s(fileName, L_tmpnam_s) != 0)
|
|
|
|
abort();
|
|
|
|
|
|
|
|
appliedZoneSetTmpFileName = std::wstring{ fileName };
|
|
|
|
});
|
|
|
|
|
|
|
|
return appliedZoneSetTmpFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::wstring& GetCustomZoneSetsTmpPath()
|
|
|
|
{
|
|
|
|
static std::wstring customZoneSetsTmpFileName;
|
|
|
|
static std::once_flag flag;
|
|
|
|
|
|
|
|
std::call_once(flag, []() {
|
|
|
|
wchar_t fileName[L_tmpnam_s];
|
|
|
|
|
|
|
|
if (_wtmpnam_s(fileName, L_tmpnam_s) != 0)
|
|
|
|
abort();
|
|
|
|
|
|
|
|
customZoneSetsTmpFileName = std::wstring{ fileName };
|
|
|
|
});
|
|
|
|
|
|
|
|
return customZoneSetsTmpFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring GenerateUniqueId(HMONITOR monitor, PCWSTR deviceId, PCWSTR virtualDesktopId)
|
|
|
|
{
|
|
|
|
wchar_t uniqueId[256]{}; // Parsed deviceId + resolution + virtualDesktopId
|
|
|
|
|
|
|
|
MONITORINFOEXW mi;
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
if (virtualDesktopId && GetMonitorInfo(monitor, &mi))
|
|
|
|
{
|
|
|
|
wchar_t parsedId[256]{};
|
|
|
|
ParseDeviceId(deviceId, parsedId, 256);
|
|
|
|
|
|
|
|
Rect const monitorRect(mi.rcMonitor);
|
|
|
|
StringCchPrintf(uniqueId, ARRAYSIZE(uniqueId), L"%s_%d_%d_%s", parsedId, monitorRect.width(), monitorRect.height(), virtualDesktopId);
|
|
|
|
}
|
|
|
|
return std::wstring{ uniqueId };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace ZoneWindowDrawUtils
|
|
|
|
{
|
|
|
|
struct ColorSetting
|
|
|
|
{
|
|
|
|
BYTE fillAlpha{};
|
|
|
|
COLORREF fill{};
|
|
|
|
BYTE borderAlpha{};
|
|
|
|
COLORREF border{};
|
|
|
|
int thickness{};
|
|
|
|
};
|
|
|
|
|
|
|
|
void DrawBackdrop(wil::unique_hdc& hdc, RECT const& clientRect) noexcept
|
|
|
|
{
|
|
|
|
FillRectARGB(hdc, &clientRect, 0, RGB(0, 0, 0), false);
|
|
|
|
}
|
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
void DrawIndex(wil::unique_hdc& hdc, Rect rect, size_t index)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-03-25 22:38:44 +08:00
|
|
|
Gdiplus::Graphics g(hdc.get());
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
Gdiplus::FontFamily fontFamily(L"Segoe ui");
|
|
|
|
Gdiplus::Font font(&fontFamily, 80, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
|
|
|
|
Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255, 0, 0, 0));
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
std::wstring text = std::to_wstring(index);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
g.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
|
|
|
|
Gdiplus::StringFormat stringFormat = new Gdiplus::StringFormat();
|
|
|
|
stringFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
|
|
|
|
stringFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
Gdiplus::RectF gdiRect(static_cast<Gdiplus::REAL>(rect.left()),
|
|
|
|
static_cast<Gdiplus::REAL>(rect.top()),
|
|
|
|
static_cast<Gdiplus::REAL>(rect.width()),
|
|
|
|
static_cast<Gdiplus::REAL>(rect.height()));
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
g.DrawString(text.c_str(), -1, &font, gdiRect, &stringFormat, &solidBrush);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawZone(wil::unique_hdc& hdc, ColorSetting const& colorSetting, winrt::com_ptr<IZone> zone, const std::vector<winrt::com_ptr<IZone>>& zones, bool flashMode) noexcept
|
|
|
|
{
|
|
|
|
RECT zoneRect = zone->GetZoneRect();
|
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
Gdiplus::Graphics g(hdc.get());
|
|
|
|
Gdiplus::Color fillColor(colorSetting.fillAlpha, GetRValue(colorSetting.fill), GetGValue(colorSetting.fill), GetBValue(colorSetting.fill));
|
|
|
|
Gdiplus::Color borderColor(colorSetting.borderAlpha, GetRValue(colorSetting.border), GetGValue(colorSetting.border), GetBValue(colorSetting.border));
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-04-08 21:59:17 +08:00
|
|
|
Gdiplus::Rect rectangle(zoneRect.left, zoneRect.top, zoneRect.right - zoneRect.left - 1, zoneRect.bottom - zoneRect.top - 1);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
Gdiplus::Pen pen(borderColor, static_cast<Gdiplus::REAL>(colorSetting.thickness));
|
|
|
|
g.FillRectangle(new Gdiplus::SolidBrush(fillColor), rectangle);
|
|
|
|
g.DrawRectangle(&pen, rectangle);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
if (!flashMode)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-03-25 22:38:44 +08:00
|
|
|
DrawIndex(hdc, zoneRect, zone->Id());
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
void DrawActiveZoneSet(wil::unique_hdc& hdc,
|
|
|
|
COLORREF zoneColor,
|
|
|
|
COLORREF zoneBorderColor,
|
|
|
|
COLORREF highlightColor,
|
|
|
|
int zoneOpacity,
|
|
|
|
const std::vector<winrt::com_ptr<IZone>>& zones,
|
2020-04-10 22:09:08 +08:00
|
|
|
const std::vector<int>& highlightZones,
|
2020-03-25 22:38:44 +08:00
|
|
|
bool flashMode,
|
|
|
|
bool drawHints) noexcept
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-03-25 22:38:44 +08:00
|
|
|
// { fillAlpha, fill, borderAlpha, border, thickness }
|
|
|
|
ColorSetting const colorHints{ OpacitySettingToAlpha(zoneOpacity), RGB(81, 92, 107), 255, RGB(104, 118, 138), -2 };
|
|
|
|
ColorSetting colorViewer{ OpacitySettingToAlpha(zoneOpacity), 0, 255, RGB(40, 50, 60), -2 };
|
|
|
|
ColorSetting colorHighlight{ OpacitySettingToAlpha(zoneOpacity), 0, 255, 0, -2 };
|
|
|
|
ColorSetting const colorFlash{ OpacitySettingToAlpha(zoneOpacity), RGB(81, 92, 107), 200, RGB(104, 118, 138), -2 };
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-04-10 22:09:08 +08:00
|
|
|
std::vector<bool> isHighlighted(zones.size(), false);
|
|
|
|
for (int x : highlightZones)
|
|
|
|
{
|
|
|
|
isHighlighted[x] = true;
|
|
|
|
}
|
|
|
|
|
2020-02-10 21:59:51 +08:00
|
|
|
for (auto iter = zones.begin(); iter != zones.end(); iter++)
|
|
|
|
{
|
2020-04-10 22:09:08 +08:00
|
|
|
int zoneId = static_cast<int>(iter - zones.begin());
|
2020-02-10 21:59:51 +08:00
|
|
|
winrt::com_ptr<IZone> zone = iter->try_as<IZone>();
|
|
|
|
if (!zone)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-10 22:09:08 +08:00
|
|
|
if (!isHighlighted[zoneId])
|
2019-11-30 21:38:27 +08:00
|
|
|
{
|
2020-02-10 21:59:51 +08:00
|
|
|
if (flashMode)
|
|
|
|
{
|
|
|
|
DrawZone(hdc, colorFlash, zone, zones, flashMode);
|
|
|
|
}
|
|
|
|
else if (drawHints)
|
|
|
|
{
|
|
|
|
DrawZone(hdc, colorHints, zone, zones, flashMode);
|
|
|
|
}
|
|
|
|
{
|
2020-03-25 22:38:44 +08:00
|
|
|
colorViewer.fill = zoneColor;
|
|
|
|
colorViewer.border = zoneBorderColor;
|
2020-02-10 21:59:51 +08:00
|
|
|
DrawZone(hdc, colorViewer, zone, zones, flashMode);
|
|
|
|
}
|
|
|
|
}
|
2020-04-10 22:09:08 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
colorHighlight.fill = highlightColor;
|
|
|
|
colorHighlight.border = zoneBorderColor;
|
|
|
|
DrawZone(hdc, colorHighlight, zone, zones, flashMode);
|
|
|
|
}
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ZoneWindow : public winrt::implements<ZoneWindow, IZoneWindow>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ZoneWindow(HINSTANCE hinstance);
|
2020-03-25 22:38:44 +08:00
|
|
|
~ZoneWindow();
|
|
|
|
|
2020-04-10 22:29:18 +08:00
|
|
|
bool Init(IZoneWindowHost* host, HINSTANCE hinstance, HMONITOR monitor, const std::wstring& uniqueId, bool flashZones, bool newWorkArea);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
IFACEMETHODIMP MoveSizeEnter(HWND window, bool dragEnabled) noexcept;
|
|
|
|
IFACEMETHODIMP MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled) noexcept;
|
|
|
|
IFACEMETHODIMP MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept;
|
2020-03-25 22:38:44 +08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
RestoreOrginalTransparency() noexcept;
|
2020-02-17 23:28:49 +08:00
|
|
|
IFACEMETHODIMP_(bool)
|
2020-04-28 16:57:09 +08:00
|
|
|
IsDragEnabled() noexcept { return m_dragEnabled; }
|
2020-02-17 23:28:49 +08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
MoveWindowIntoZoneByIndex(HWND window, int index) noexcept;
|
2020-04-10 22:09:08 +08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
MoveWindowIntoZoneByIndexSet(HWND window, const std::vector<int>& indexSet) noexcept;
|
2020-03-25 01:50:26 +08:00
|
|
|
IFACEMETHODIMP_(bool)
|
|
|
|
MoveWindowIntoZoneByDirection(HWND window, DWORD vkCode, bool cycle) noexcept;
|
2020-02-17 23:28:49 +08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
CycleActiveZoneSet(DWORD vkCode) noexcept;
|
|
|
|
IFACEMETHODIMP_(std::wstring)
|
2020-04-28 16:57:09 +08:00
|
|
|
UniqueId() noexcept { return { m_uniqueId }; }
|
2020-02-17 23:28:49 +08:00
|
|
|
IFACEMETHODIMP_(std::wstring)
|
2020-04-28 16:57:09 +08:00
|
|
|
WorkAreaKey() noexcept { return { m_workArea }; }
|
2020-02-17 23:28:49 +08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
SaveWindowProcessToZoneIndex(HWND window) noexcept;
|
|
|
|
IFACEMETHODIMP_(IZoneSet*)
|
2020-04-28 16:57:09 +08:00
|
|
|
ActiveZoneSet() noexcept { return m_activeZoneSet.get(); }
|
2020-03-13 22:56:23 +08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
ShowZoneWindow() noexcept;
|
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
HideZoneWindow() noexcept;
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void LoadSettings() noexcept;
|
2020-04-10 22:29:18 +08:00
|
|
|
void InitializeZoneSets(bool newWorkArea) noexcept;
|
2020-02-10 21:59:51 +08:00
|
|
|
void CalculateZoneSet() noexcept;
|
|
|
|
void UpdateActiveZoneSet(_In_opt_ IZoneSet* zoneSet) noexcept;
|
|
|
|
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
|
|
|
void OnPaint(wil::unique_hdc& hdc) noexcept;
|
|
|
|
void OnKeyUp(WPARAM wparam) noexcept;
|
2020-04-10 22:09:08 +08:00
|
|
|
std::vector<int> ZonesFromPoint(POINT pt) noexcept;
|
2020-02-10 21:59:51 +08:00
|
|
|
void CycleActiveZoneSetInternal(DWORD wparam, Trace::ZoneWindow::InputMode mode) noexcept;
|
|
|
|
void FlashZones() noexcept;
|
|
|
|
|
|
|
|
winrt::com_ptr<IZoneWindowHost> m_host;
|
|
|
|
HMONITOR m_monitor{};
|
|
|
|
std::wstring m_uniqueId; // Parsed deviceId + resolution + virtualDesktopId
|
|
|
|
wchar_t m_workArea[256]{};
|
2020-03-10 02:22:53 +08:00
|
|
|
wil::unique_hwnd m_window{}; // Hidden tool window used to represent current monitor desktop work area.
|
2020-02-10 21:59:51 +08:00
|
|
|
HWND m_windowMoveSize{};
|
|
|
|
bool m_drawHints{};
|
|
|
|
bool m_flashMode{};
|
|
|
|
bool m_dragEnabled{};
|
|
|
|
winrt::com_ptr<IZoneSet> m_activeZoneSet;
|
|
|
|
std::vector<winrt::com_ptr<IZoneSet>> m_zoneSets;
|
2020-04-10 22:09:08 +08:00
|
|
|
std::vector<int> m_highlightZone;
|
2020-02-10 21:59:51 +08:00
|
|
|
WPARAM m_keyLast{};
|
|
|
|
size_t m_keyCycle{};
|
|
|
|
static const UINT m_showAnimationDuration = 200; // ms
|
|
|
|
static const UINT m_flashDuration = 700; // ms
|
2020-03-25 22:38:44 +08:00
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
HWND draggedWindow = nullptr;
|
|
|
|
long draggedWindowExstyle = 0;
|
|
|
|
COLORREF draggedWindowCrKey = RGB(0, 0, 0);
|
|
|
|
DWORD draggedWindowDwFlags = 0;
|
|
|
|
BYTE draggedWindowInitialAlpha = 0;
|
2020-04-04 02:17:12 +08:00
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
ULONG_PTR gdiplusToken;
|
2020-02-10 21:59:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
ZoneWindow::ZoneWindow(HINSTANCE hinstance)
|
|
|
|
{
|
|
|
|
WNDCLASSEXW wcex{};
|
|
|
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
|
|
|
wcex.lpfnWndProc = s_WndProc;
|
|
|
|
wcex.hInstance = hinstance;
|
|
|
|
wcex.lpszClassName = L"SuperFancyZones_ZoneWindow";
|
|
|
|
wcex.hCursor = LoadCursorW(nullptr, IDC_ARROW);
|
|
|
|
RegisterClassExW(&wcex);
|
2020-03-25 22:38:44 +08:00
|
|
|
|
|
|
|
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
|
2020-04-28 16:57:09 +08:00
|
|
|
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
|
2020-03-25 22:38:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ZoneWindow::~ZoneWindow()
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
Gdiplus::GdiplusShutdown(gdiplusToken);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-04-10 22:29:18 +08:00
|
|
|
bool ZoneWindow::Init(IZoneWindowHost* host, HINSTANCE hinstance, HMONITOR monitor, const std::wstring& uniqueId, bool flashZones, bool newWorkArea)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
m_host.copy_from(host);
|
|
|
|
|
|
|
|
MONITORINFO mi{};
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
if (!GetMonitorInfoW(monitor, &mi))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_monitor = monitor;
|
|
|
|
const UINT dpi = GetDpiForMonitor(m_monitor);
|
|
|
|
const Rect monitorRect(mi.rcMonitor);
|
|
|
|
const Rect workAreaRect(mi.rcWork, dpi);
|
|
|
|
StringCchPrintf(m_workArea, ARRAYSIZE(m_workArea), L"%d_%d", monitorRect.width(), monitorRect.height());
|
|
|
|
|
|
|
|
m_uniqueId = uniqueId;
|
|
|
|
LoadSettings();
|
2020-04-10 22:29:18 +08:00
|
|
|
InitializeZoneSets(newWorkArea);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
m_window = wil::unique_hwnd{
|
|
|
|
CreateWindowExW(WS_EX_TOOLWINDOW, L"SuperFancyZones_ZoneWindow", L"", WS_POPUP, workAreaRect.left(), workAreaRect.top(), workAreaRect.width(), workAreaRect.height(), nullptr, nullptr, hinstance, this)
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!m_window)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MakeWindowTransparent(m_window.get());
|
|
|
|
if (flashZones)
|
|
|
|
{
|
|
|
|
// Don't flash if the foreground window is in full screen mode
|
|
|
|
RECT windowRect;
|
|
|
|
if (!(GetWindowRect(GetForegroundWindow(), &windowRect) &&
|
|
|
|
windowRect.left == mi.rcMonitor.left &&
|
|
|
|
windowRect.top == mi.rcMonitor.top &&
|
|
|
|
windowRect.right == mi.rcMonitor.right &&
|
|
|
|
windowRect.bottom == mi.rcMonitor.bottom))
|
|
|
|
{
|
|
|
|
FlashZones();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP ZoneWindow::MoveSizeEnter(HWND window, bool dragEnabled) noexcept
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_windowMoveSize)
|
2020-04-04 02:17:12 +08:00
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_host->isMakeDraggedWindowTransparentActive())
|
2020-03-25 22:38:44 +08:00
|
|
|
{
|
2020-04-04 02:17:12 +08:00
|
|
|
draggedWindowExstyle = GetWindowLong(window, GWL_EXSTYLE);
|
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
draggedWindow = window;
|
|
|
|
SetWindowLong(window,
|
|
|
|
GWL_EXSTYLE,
|
2020-04-04 02:17:12 +08:00
|
|
|
draggedWindowExstyle | WS_EX_LAYERED);
|
2020-03-25 22:38:44 +08:00
|
|
|
|
2020-04-04 02:17:12 +08:00
|
|
|
GetLayeredWindowAttributes(window, &draggedWindowCrKey, &draggedWindowInitialAlpha, &draggedWindowDwFlags);
|
2020-03-25 22:38:44 +08:00
|
|
|
|
|
|
|
SetLayeredWindowAttributes(window, 0, (255 * 50) / 100, LWA_ALPHA);
|
|
|
|
}
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
m_dragEnabled = dragEnabled;
|
|
|
|
m_windowMoveSize = window;
|
|
|
|
m_drawHints = true;
|
|
|
|
m_highlightZone = {};
|
2020-02-10 21:59:51 +08:00
|
|
|
ShowZoneWindow();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP ZoneWindow::MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled) noexcept
|
|
|
|
{
|
|
|
|
bool redraw = false;
|
|
|
|
POINT ptClient = ptScreen;
|
2020-04-28 16:57:09 +08:00
|
|
|
MapWindowPoints(nullptr, m_window.get(), &ptClient, 1);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
m_dragEnabled = dragEnabled;
|
|
|
|
|
|
|
|
if (dragEnabled)
|
|
|
|
{
|
2020-04-10 22:09:08 +08:00
|
|
|
auto highlightZone = ZonesFromPoint(ptClient);
|
2020-02-10 21:59:51 +08:00
|
|
|
redraw = (highlightZone != m_highlightZone);
|
|
|
|
m_highlightZone = std::move(highlightZone);
|
|
|
|
}
|
2020-04-10 22:09:08 +08:00
|
|
|
else if (m_highlightZone.size())
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-10 22:09:08 +08:00
|
|
|
m_highlightZone = {};
|
2020-02-10 21:59:51 +08:00
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (redraw)
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
InvalidateRect(m_window.get(), nullptr, true);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP ZoneWindow::MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept
|
|
|
|
{
|
2020-03-25 22:38:44 +08:00
|
|
|
RestoreOrginalTransparency();
|
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_windowMoveSize != window)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_activeZoneSet)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
POINT ptClient = ptScreen;
|
2020-04-28 16:57:09 +08:00
|
|
|
MapWindowPoints(nullptr, m_window.get(), &ptClient, 1);
|
|
|
|
m_activeZoneSet->MoveWindowIntoZoneByPoint(window, m_window.get(), ptClient);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
SaveWindowProcessToZoneIndex(window);
|
|
|
|
}
|
2020-04-28 16:57:09 +08:00
|
|
|
Trace::ZoneWindow::MoveSizeEnd(m_activeZoneSet);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
HideZoneWindow();
|
|
|
|
m_windowMoveSize = nullptr;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-25 22:38:44 +08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
ZoneWindow::RestoreOrginalTransparency() noexcept
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_host->isMakeDraggedWindowTransparentActive() && draggedWindow != nullptr)
|
2020-03-25 22:38:44 +08:00
|
|
|
{
|
2020-04-04 02:17:12 +08:00
|
|
|
SetLayeredWindowAttributes(draggedWindow, draggedWindowCrKey, draggedWindowInitialAlpha, draggedWindowDwFlags);
|
|
|
|
SetWindowLong(draggedWindow, GWL_EXSTYLE, draggedWindowExstyle);
|
2020-03-25 22:38:44 +08:00
|
|
|
draggedWindow = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 21:59:51 +08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
ZoneWindow::MoveWindowIntoZoneByIndex(HWND window, int index) noexcept
|
2020-04-10 22:09:08 +08:00
|
|
|
{
|
|
|
|
MoveWindowIntoZoneByIndexSet(window, { index });
|
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
ZoneWindow::MoveWindowIntoZoneByIndexSet(HWND window, const std::vector<int>& indexSet) noexcept
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_activeZoneSet)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
m_activeZoneSet->MoveWindowIntoZoneByIndexSet(window, m_window.get(), indexSet, false);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-25 01:50:26 +08:00
|
|
|
IFACEMETHODIMP_(bool)
|
|
|
|
ZoneWindow::MoveWindowIntoZoneByDirection(HWND window, DWORD vkCode, bool cycle) noexcept
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_activeZoneSet)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_activeZoneSet->MoveWindowIntoZoneByDirection(window, m_window.get(), vkCode, cycle))
|
2020-03-25 01:50:26 +08:00
|
|
|
{
|
|
|
|
SaveWindowProcessToZoneIndex(window);
|
|
|
|
return true;
|
|
|
|
}
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
2020-03-25 01:50:26 +08:00
|
|
|
return false;
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
ZoneWindow::CycleActiveZoneSet(DWORD wparam) noexcept
|
|
|
|
{
|
|
|
|
CycleActiveZoneSetInternal(wparam, Trace::ZoneWindow::InputMode::Keyboard);
|
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_windowMoveSize)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
InvalidateRect(m_window.get(), nullptr, true);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlashZones();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
ZoneWindow::SaveWindowProcessToZoneIndex(HWND window) noexcept
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_activeZoneSet)
|
2019-11-19 07:29:42 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
DWORD zoneIndex = static_cast<DWORD>(m_activeZoneSet->GetZoneIndexFromWindow(window));
|
2019-11-19 07:29:42 +08:00
|
|
|
if (zoneIndex != -1)
|
|
|
|
{
|
2020-02-10 21:59:51 +08:00
|
|
|
OLECHAR* guidString;
|
2020-04-28 16:57:09 +08:00
|
|
|
if (StringFromCLSID(m_activeZoneSet->Id(), &guidString) == S_OK)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
JSONHelpers::FancyZonesDataInstance().SetAppLastZone(window, m_uniqueId, guidString, zoneIndex);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CoTaskMemFree(guidString);
|
2019-11-19 07:29:42 +08:00
|
|
|
}
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
2019-12-06 22:09:27 +08:00
|
|
|
}
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-03-13 22:56:23 +08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
ZoneWindow::ShowZoneWindow() noexcept
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-05-01 22:14:35 +08:00
|
|
|
auto window = m_window.get();
|
|
|
|
if (!window)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-05-01 22:14:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-05-01 22:14:35 +08:00
|
|
|
m_flashMode = false;
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-05-01 22:14:35 +08:00
|
|
|
UINT flags = SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE;
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-05-01 22:14:35 +08:00
|
|
|
HWND windowInsertAfter = m_windowMoveSize;
|
|
|
|
if (windowInsertAfter == nullptr)
|
|
|
|
{
|
|
|
|
windowInsertAfter = HWND_TOPMOST;
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
2020-05-01 22:14:35 +08:00
|
|
|
|
|
|
|
SetWindowPos(window, windowInsertAfter, 0, 0, 0, 0, flags);
|
|
|
|
|
|
|
|
std::thread{ [=]() {
|
|
|
|
AnimateWindow(window, m_showAnimationDuration, AW_BLEND);
|
|
|
|
InvalidateRect(window, nullptr, true);
|
|
|
|
} }.detach();
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-03-13 22:56:23 +08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
ZoneWindow::HideZoneWindow() noexcept
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_window)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
ShowWindow(m_window.get(), SW_HIDE);
|
2020-02-10 21:59:51 +08:00
|
|
|
m_keyLast = 0;
|
|
|
|
m_windowMoveSize = nullptr;
|
|
|
|
m_drawHints = false;
|
2020-04-10 22:09:08 +08:00
|
|
|
m_highlightZone = {};
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-13 22:56:23 +08:00
|
|
|
#pragma region private
|
|
|
|
|
2020-02-10 21:59:51 +08:00
|
|
|
void ZoneWindow::LoadSettings() noexcept
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
JSONHelpers::FancyZonesDataInstance().AddDevice(m_uniqueId);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-04-10 22:29:18 +08:00
|
|
|
void ZoneWindow::InitializeZoneSets(bool newWorkArea) noexcept
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
auto parent = m_host->GetParentZoneWindow(m_monitor);
|
2020-04-10 22:29:18 +08:00
|
|
|
if (newWorkArea && parent)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
// Update device info with device info from parent virtual desktop (if empty).
|
2020-04-28 16:57:09 +08:00
|
|
|
JSONHelpers::FancyZonesDataInstance().CloneDeviceInfo(parent->UniqueId(), m_uniqueId);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
CalculateZoneSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoneWindow::CalculateZoneSet() noexcept
|
|
|
|
{
|
|
|
|
const auto& fancyZonesData = JSONHelpers::FancyZonesDataInstance();
|
2020-04-28 16:57:09 +08:00
|
|
|
const auto deviceInfoData = fancyZonesData.FindDeviceInfo(m_uniqueId);
|
2020-02-10 21:59:51 +08:00
|
|
|
const auto& activeDeviceId = fancyZonesData.GetActiveDeviceId();
|
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
if (!activeDeviceId.empty() && activeDeviceId != m_uniqueId)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-17 23:28:49 +08:00
|
|
|
if (!deviceInfoData.has_value())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& activeZoneSet = deviceInfoData->activeZoneSet;
|
|
|
|
|
2020-02-10 21:59:51 +08:00
|
|
|
if (activeZoneSet.uuid.empty() || activeZoneSet.type == JSONHelpers::ZoneSetLayoutType::Blank)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GUID zoneSetId;
|
|
|
|
if (SUCCEEDED_LOG(CLSIDFromString(activeZoneSet.uuid.c_str(), &zoneSetId)))
|
|
|
|
{
|
|
|
|
auto zoneSet = MakeZoneSet(ZoneSetConfig(
|
|
|
|
zoneSetId,
|
|
|
|
activeZoneSet.type,
|
2020-04-28 16:57:09 +08:00
|
|
|
m_monitor,
|
|
|
|
m_workArea));
|
2020-02-10 21:59:51 +08:00
|
|
|
MONITORINFO monitorInfo{};
|
|
|
|
monitorInfo.cbSize = sizeof(monitorInfo);
|
2020-04-28 16:57:09 +08:00
|
|
|
if (GetMonitorInfoW(m_monitor, &monitorInfo))
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-02-17 23:28:49 +08:00
|
|
|
bool showSpacing = deviceInfoData->showSpacing;
|
|
|
|
int spacing = showSpacing ? deviceInfoData->spacing : 0;
|
|
|
|
int zoneCount = deviceInfoData->zoneCount;
|
2020-02-10 21:59:51 +08:00
|
|
|
zoneSet->CalculateZones(monitorInfo, zoneCount, spacing);
|
|
|
|
UpdateActiveZoneSet(zoneSet.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoneWindow::UpdateActiveZoneSet(_In_opt_ IZoneSet* zoneSet) noexcept
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
m_activeZoneSet.copy_from(zoneSet);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_activeZoneSet)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
wil::unique_cotaskmem_string zoneSetId;
|
2020-04-28 16:57:09 +08:00
|
|
|
if (SUCCEEDED_LOG(StringFromCLSID(m_activeZoneSet->Id(), &zoneSetId)))
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
JSONHelpers::ZoneSetData data{
|
|
|
|
.uuid = zoneSetId.get(),
|
2020-04-28 16:57:09 +08:00
|
|
|
.type = m_activeZoneSet->LayoutType()
|
2020-02-10 21:59:51 +08:00
|
|
|
};
|
2020-04-28 16:57:09 +08:00
|
|
|
JSONHelpers::FancyZonesDataInstance().SetActiveZoneSet(m_uniqueId, data);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT ZoneWindow::WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept
|
|
|
|
{
|
|
|
|
switch (message)
|
|
|
|
{
|
2020-03-25 22:38:44 +08:00
|
|
|
case WM_NCDESTROY:
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
::DefWindowProc(m_window.get(), message, wparam, lparam);
|
|
|
|
SetWindowLongPtr(m_window.get(), GWLP_USERDATA, 0);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_ERASEBKGND:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case WM_PRINTCLIENT:
|
2020-03-25 22:38:44 +08:00
|
|
|
case WM_PAINT:
|
|
|
|
{
|
2020-02-10 21:59:51 +08:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
wil::unique_hdc hdc{ reinterpret_cast<HDC>(wparam) };
|
|
|
|
if (!hdc)
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
hdc.reset(BeginPaint(m_window.get(), &ps));
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
OnPaint(hdc);
|
|
|
|
|
|
|
|
if (wparam == 0)
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
EndPaint(m_window.get(), &ps);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
hdc.release();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
return DefWindowProc(m_window.get(), message, wparam, lparam);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoneWindow::OnPaint(wil::unique_hdc& hdc) noexcept
|
|
|
|
{
|
|
|
|
RECT clientRect;
|
2020-04-28 16:57:09 +08:00
|
|
|
GetClientRect(m_window.get(), &clientRect);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
wil::unique_hdc hdcMem;
|
|
|
|
HPAINTBUFFER bufferedPaint = BeginBufferedPaint(hdc.get(), &clientRect, BPBF_TOPDOWNDIB, nullptr, &hdcMem);
|
|
|
|
if (bufferedPaint)
|
|
|
|
{
|
|
|
|
ZoneWindowDrawUtils::DrawBackdrop(hdcMem, clientRect);
|
2020-03-25 22:38:44 +08:00
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_activeZoneSet && m_host)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-03-25 22:38:44 +08:00
|
|
|
ZoneWindowDrawUtils::DrawActiveZoneSet(hdcMem,
|
2020-04-28 16:57:09 +08:00
|
|
|
m_host->GetZoneColor(),
|
|
|
|
m_host->GetZoneBorderColor(),
|
|
|
|
m_host->GetZoneHighlightColor(),
|
|
|
|
m_host->GetZoneHighlightOpacity(),
|
|
|
|
m_activeZoneSet->GetZones(),
|
|
|
|
m_highlightZone,
|
|
|
|
m_flashMode,
|
|
|
|
m_drawHints);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EndBufferedPaint(bufferedPaint, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoneWindow::OnKeyUp(WPARAM wparam) noexcept
|
|
|
|
{
|
|
|
|
bool fRedraw = false;
|
|
|
|
Trace::ZoneWindow::KeyUp(wparam);
|
|
|
|
|
|
|
|
if ((wparam >= '0') && (wparam <= '9'))
|
|
|
|
{
|
|
|
|
CycleActiveZoneSetInternal(static_cast<DWORD>(wparam), Trace::ZoneWindow::InputMode::Keyboard);
|
2020-04-28 16:57:09 +08:00
|
|
|
InvalidateRect(m_window.get(), nullptr, true);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 22:09:08 +08:00
|
|
|
std::vector<int> ZoneWindow::ZonesFromPoint(POINT pt) noexcept
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_activeZoneSet)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
return m_activeZoneSet->ZonesFromPoint(pt);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
2020-04-10 22:09:08 +08:00
|
|
|
return {};
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ZoneWindow::CycleActiveZoneSetInternal(DWORD wparam, Trace::ZoneWindow::InputMode mode) noexcept
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
Trace::ZoneWindow::CycleActiveZoneSet(m_activeZoneSet, mode);
|
|
|
|
if (m_keyLast != wparam)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
m_keyCycle = 0;
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
m_keyLast = wparam;
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
bool loopAround = true;
|
|
|
|
size_t const val = static_cast<size_t>(wparam - L'0');
|
|
|
|
size_t i = 0;
|
2020-04-28 16:57:09 +08:00
|
|
|
for (auto zoneSet : m_zoneSets)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
if (zoneSet->GetZones().size() == val)
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
if (i < m_keyCycle)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-06 22:09:27 +08:00
|
|
|
UpdateActiveZoneSet(zoneSet.get());
|
2020-02-10 21:59:51 +08:00
|
|
|
loopAround = false;
|
|
|
|
break;
|
2019-12-06 22:09:27 +08:00
|
|
|
}
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
if ((m_keyCycle > 0) && loopAround)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
// Cycling through a non-empty group and hit the end
|
2020-04-28 16:57:09 +08:00
|
|
|
m_keyCycle = 0;
|
2020-02-10 21:59:51 +08:00
|
|
|
OnKeyUp(wparam);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
m_keyCycle++;
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
if (m_host)
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-04-28 16:57:09 +08:00
|
|
|
m_host->MoveWindowsOnActiveZoneSetChange();
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
2020-04-10 22:09:08 +08:00
|
|
|
m_highlightZone = {};
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ZoneWindow::FlashZones() noexcept
|
|
|
|
{
|
2020-03-27 18:24:27 +08:00
|
|
|
// "Turning FLASHING_ZONE option off"
|
2020-04-04 02:17:12 +08:00
|
|
|
if (true)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-03-27 18:24:27 +08:00
|
|
|
|
2020-02-10 21:59:51 +08:00
|
|
|
m_flashMode = true;
|
|
|
|
|
2020-04-28 16:57:09 +08:00
|
|
|
ShowWindow(m_window.get(), SW_SHOWNA);
|
|
|
|
std::thread([window = m_window.get()]() {
|
2020-02-10 21:59:51 +08:00
|
|
|
AnimateWindow(window, m_flashDuration, AW_HIDE | AW_BLEND);
|
|
|
|
}).detach();
|
|
|
|
}
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
LRESULT CALLBACK ZoneWindow::s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept
|
|
|
|
{
|
|
|
|
auto thisRef = reinterpret_cast<ZoneWindow*>(GetWindowLongPtr(window, GWLP_USERDATA));
|
|
|
|
if ((thisRef == nullptr) && (message == WM_CREATE))
|
|
|
|
{
|
|
|
|
auto createStruct = reinterpret_cast<LPCREATESTRUCT>(lparam);
|
|
|
|
thisRef = reinterpret_cast<ZoneWindow*>(createStruct->lpCreateParams);
|
|
|
|
SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(thisRef));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (thisRef != nullptr) ? thisRef->WndProc(message, wparam, lparam) :
|
|
|
|
DefWindowProc(window, message, wparam, lparam);
|
|
|
|
}
|
|
|
|
|
2020-04-10 22:29:18 +08:00
|
|
|
winrt::com_ptr<IZoneWindow> MakeZoneWindow(IZoneWindowHost* host, HINSTANCE hinstance, HMONITOR monitor, const std::wstring& uniqueId, bool flashZones, bool newWorkArea) noexcept
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
auto self = winrt::make_self<ZoneWindow>(hinstance);
|
2020-04-10 22:29:18 +08:00
|
|
|
if (self->Init(host, hinstance, monitor, uniqueId, flashZones, newWorkArea))
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|