mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
merge master
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
@@ -15,7 +16,7 @@
|
||||
<ProjectGuid>{48804216-2A0E-4168-A6D8-9CD068D14227}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>fancyzones</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
||||
<ProjectName>fancyzones</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
@@ -37,6 +38,7 @@
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets')" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
@@ -62,7 +64,6 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;FANCYZONES_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<AdditionalIncludeDirectories>..\;..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;..\..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@@ -84,7 +85,6 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;FANCYZONES_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<AdditionalIncludeDirectories>..\;..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;..\..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
@@ -132,5 +132,7 @@
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -10,24 +10,25 @@
|
||||
#include <lib/trace.h>
|
||||
#include <lib/Settings.h>
|
||||
#include <lib/FancyZones.h>
|
||||
#include <lib/FancyZonesWinHookEventIDs.h>
|
||||
|
||||
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
Trace::RegisterProvider();
|
||||
break;
|
||||
case DLL_PROCESS_ATTACH:
|
||||
Trace::RegisterProvider();
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
Trace::UnregisterProvider();
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
Trace::UnregisterProvider();
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -45,13 +46,12 @@ public:
|
||||
// nullptr as the last element of the array. Nullptr can also be retured for empty list.
|
||||
virtual PCWSTR* get_events() override
|
||||
{
|
||||
static PCWSTR events[] = { ll_keyboard, win_hook_event, nullptr };
|
||||
return events;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Return JSON with the configuration options.
|
||||
// These are the settings shown on the settings page along with their current values.
|
||||
virtual bool get_config(_Out_ PWSTR buffer, _Out_ int *buffer_size) override
|
||||
virtual bool get_config(_Out_ PWSTR buffer, _Out_ int* buffer_size) override
|
||||
{
|
||||
return m_settings->GetConfig(buffer, buffer_size);
|
||||
}
|
||||
@@ -75,8 +75,37 @@ public:
|
||||
{
|
||||
if (!m_app)
|
||||
{
|
||||
InitializeWinhookEventIds();
|
||||
Trace::FancyZones::EnableFancyZones(true);
|
||||
m_app = MakeFancyZones(reinterpret_cast<HINSTANCE>(&__ImageBase), m_settings);
|
||||
|
||||
s_llKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), NULL);
|
||||
if (!s_llKeyboardHook)
|
||||
{
|
||||
MessageBoxW(NULL, L"Cannot install keyboard listener.", L"PowerToys - FancyZones", MB_OK | MB_ICONERROR);
|
||||
}
|
||||
|
||||
std::array<DWORD, 6> events_to_subscribe = {
|
||||
EVENT_SYSTEM_MOVESIZESTART,
|
||||
EVENT_SYSTEM_MOVESIZEEND,
|
||||
EVENT_OBJECT_NAMECHANGE,
|
||||
EVENT_OBJECT_UNCLOAKED,
|
||||
EVENT_OBJECT_SHOW,
|
||||
EVENT_OBJECT_CREATE
|
||||
};
|
||||
for (const auto event : events_to_subscribe)
|
||||
{
|
||||
auto hook = SetWinEventHook(event, event, nullptr, WinHookProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
|
||||
if (hook)
|
||||
{
|
||||
m_staticWinEventHooks.emplace_back(hook);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBoxW(NULL, L"Cannot install Windows event listener.", L"PowerToys - FancyZones", MB_OK | MB_ICONERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_app)
|
||||
{
|
||||
m_app->Run();
|
||||
@@ -96,27 +125,14 @@ public:
|
||||
return (m_app != nullptr);
|
||||
}
|
||||
|
||||
// Handle incoming event, data is event-specific
|
||||
// PowertoyModuleIface method, unused
|
||||
virtual intptr_t signal_event(const wchar_t* name, intptr_t data) override
|
||||
{
|
||||
if (m_app)
|
||||
{
|
||||
if (wcscmp(name, ll_keyboard) == 0)
|
||||
{
|
||||
// Return 1 if the keypress is to be suppressed (not forwarded to Windows), otherwise return 0.
|
||||
return HandleKeyboardHookEvent(reinterpret_cast<LowlevelKeyboardEvent*>(data));
|
||||
}
|
||||
else if (wcscmp(name, win_hook_event) == 0)
|
||||
{
|
||||
// Return value is ignored
|
||||
HandleWinHookEvent(reinterpret_cast<WinHookEvent*>(data));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void register_system_menu_helper(PowertoySystemMenuIface* helper) override { }
|
||||
virtual void signal_system_menu_action(const wchar_t* name) override { }
|
||||
virtual void register_system_menu_helper(PowertoySystemMenuIface* helper) override {}
|
||||
virtual void signal_system_menu_action(const wchar_t* name) override {}
|
||||
|
||||
// Destroy the powertoy and free memory
|
||||
virtual void destroy() override
|
||||
@@ -130,67 +146,129 @@ public:
|
||||
app_name = GET_RESOURCE_STRING(IDS_FANCYZONES);
|
||||
m_settings = MakeFancyZonesSettings(reinterpret_cast<HINSTANCE>(&__ImageBase), FancyZonesModule::get_name());
|
||||
JSONHelpers::FancyZonesDataInstance().LoadFancyZonesData();
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
private:
|
||||
void Disable(bool const traceEvent)
|
||||
{
|
||||
if (m_app) {
|
||||
if (traceEvent)
|
||||
if (m_app)
|
||||
{
|
||||
if (traceEvent)
|
||||
{
|
||||
Trace::FancyZones::EnableFancyZones(false);
|
||||
}
|
||||
m_app->Destroy();
|
||||
m_app = nullptr;
|
||||
m_settings->ResetCallback();
|
||||
|
||||
if (s_llKeyboardHook)
|
||||
{
|
||||
if (UnhookWindowsHookEx(s_llKeyboardHook))
|
||||
{
|
||||
s_llKeyboardHook = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
m_staticWinEventHooks.erase(std::remove_if(begin(m_staticWinEventHooks),
|
||||
end(m_staticWinEventHooks),
|
||||
[](const HWINEVENTHOOK hook) {
|
||||
return UnhookWinEvent(hook);
|
||||
}),
|
||||
end(m_staticWinEventHooks));
|
||||
if (m_objectLocationWinEventHook)
|
||||
{
|
||||
if (UnhookWinEvent(m_objectLocationWinEventHook))
|
||||
{
|
||||
m_objectLocationWinEventHook = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
intptr_t HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) noexcept;
|
||||
void HandleWinHookEvent(WinHookEvent* data) noexcept;
|
||||
void MoveSizeStart(HWND window, POINT const& ptScreen) noexcept;
|
||||
void MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept;
|
||||
void MoveSizeUpdate(POINT const& ptScreen) noexcept;
|
||||
|
||||
winrt::com_ptr<IFancyZones> m_app;
|
||||
winrt::com_ptr<IFancyZonesSettings> m_settings;
|
||||
std::wstring app_name;
|
||||
|
||||
static inline FancyZonesModule* s_instance;
|
||||
static inline HHOOK s_llKeyboardHook;
|
||||
|
||||
std::vector<HWINEVENTHOOK> m_staticWinEventHooks;
|
||||
HWINEVENTHOOK m_objectLocationWinEventHook;
|
||||
|
||||
static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
LowlevelKeyboardEvent event;
|
||||
if (nCode == HC_ACTION && wParam == WM_KEYDOWN)
|
||||
{
|
||||
event.lParam = reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam);
|
||||
event.wParam = wParam;
|
||||
if (s_instance)
|
||||
{
|
||||
return s_instance->HandleKeyboardHookEvent(&event);
|
||||
}
|
||||
}
|
||||
return CallNextHookEx(NULL, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
static void CALLBACK WinHookProc(HWINEVENTHOOK winEventHook,
|
||||
DWORD event,
|
||||
HWND window,
|
||||
LONG object,
|
||||
LONG child,
|
||||
DWORD eventThread,
|
||||
DWORD eventTime)
|
||||
{
|
||||
WinHookEvent data{ event, window, object, child, eventThread, eventTime };
|
||||
if (s_instance)
|
||||
{
|
||||
s_instance->HandleWinHookEvent(&data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
intptr_t FancyZonesModule::HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) noexcept
|
||||
{
|
||||
if (data->wParam == WM_KEYDOWN)
|
||||
{
|
||||
return m_app.as<IFancyZonesCallback>()->OnKeyDown(data->lParam) ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
return m_app.as<IFancyZonesCallback>()->OnKeyDown(data->lParam);
|
||||
}
|
||||
|
||||
void FancyZonesModule::HandleWinHookEvent(WinHookEvent* data) noexcept
|
||||
{
|
||||
POINT ptScreen;
|
||||
GetPhysicalCursorPos(&ptScreen);
|
||||
|
||||
auto fzCallback = m_app.as<IFancyZonesCallback>();
|
||||
switch (data->event)
|
||||
{
|
||||
case EVENT_SYSTEM_MOVESIZESTART:
|
||||
{
|
||||
MoveSizeStart(data->hwnd, ptScreen);
|
||||
fzCallback->HandleWinHookEvent(data);
|
||||
if (!m_objectLocationWinEventHook)
|
||||
{
|
||||
m_objectLocationWinEventHook = SetWinEventHook(EVENT_OBJECT_LOCATIONCHANGE,
|
||||
EVENT_OBJECT_LOCATIONCHANGE,
|
||||
nullptr,
|
||||
WinHookProc,
|
||||
0,
|
||||
0,
|
||||
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EVENT_SYSTEM_MOVESIZEEND:
|
||||
{
|
||||
MoveSizeEnd(data->hwnd, ptScreen);
|
||||
if (UnhookWinEvent(m_objectLocationWinEventHook))
|
||||
{
|
||||
m_objectLocationWinEventHook = nullptr;
|
||||
}
|
||||
fzCallback->HandleWinHookEvent(data);
|
||||
}
|
||||
break;
|
||||
|
||||
case EVENT_OBJECT_LOCATIONCHANGE:
|
||||
{
|
||||
if (m_app.as<IFancyZonesCallback>()->InMoveSize())
|
||||
{
|
||||
MoveSizeUpdate(ptScreen);
|
||||
}
|
||||
fzCallback->HandleWinHookEvent(data);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -210,10 +288,7 @@ void FancyZonesModule::HandleWinHookEvent(WinHookEvent* data) noexcept
|
||||
case EVENT_OBJECT_SHOW:
|
||||
case EVENT_OBJECT_CREATE:
|
||||
{
|
||||
if (data->idObject == OBJID_WINDOW)
|
||||
{
|
||||
m_app.as<IFancyZonesCallback>()->WindowCreated(data->hwnd);
|
||||
}
|
||||
fzCallback->HandleWinHookEvent(data);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -222,30 +297,7 @@ void FancyZonesModule::HandleWinHookEvent(WinHookEvent* data) noexcept
|
||||
}
|
||||
}
|
||||
|
||||
void FancyZonesModule::MoveSizeStart(HWND window, POINT const& ptScreen) noexcept
|
||||
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
|
||||
{
|
||||
if (auto monitor = MonitorFromPoint(ptScreen, MONITOR_DEFAULTTONULL))
|
||||
{
|
||||
m_app.as<IFancyZonesCallback>()->MoveSizeStart(window, monitor, ptScreen);
|
||||
}
|
||||
return new FancyZonesModule();
|
||||
}
|
||||
|
||||
void FancyZonesModule::MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept
|
||||
{
|
||||
m_app.as<IFancyZonesCallback>()->MoveSizeEnd(window, ptScreen);
|
||||
}
|
||||
|
||||
void FancyZonesModule::MoveSizeUpdate(POINT const& ptScreen) noexcept
|
||||
{
|
||||
if (auto monitor = MonitorFromPoint(ptScreen, MONITOR_DEFAULTTONULL))
|
||||
{
|
||||
m_app.as<IFancyZonesCallback>()->MoveSizeUpdate(monitor, ptScreen);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
|
||||
{
|
||||
return new FancyZonesModule();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Windows.CppWinRT" version="2.0.200316.3" targetFramework="native" />
|
||||
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.191107.2" targetFramework="native" />
|
||||
</packages>
|
||||
@@ -3,6 +3,8 @@
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#include <Unknwn.h>
|
||||
#include <winrt/base.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <TraceLoggingActivity.h>
|
||||
#include <wil\common.h>
|
||||
|
||||
Reference in New Issue
Block a user