mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
merge master
This commit is contained in:
4
src/modules/shortcut_guide/packages.config
Normal file
4
src/modules/shortcut_guide/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Windows.CppWinRT" version="2.0.200316.3" targetFramework="native" />
|
||||
</packages>
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include <winrt/base.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <Windows.h>
|
||||
#include <dxgi1_3.h>
|
||||
#include <d3d11_2.h>
|
||||
|
||||
@@ -11,6 +11,24 @@ extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||
|
||||
OverlayWindow* instance = nullptr;
|
||||
|
||||
namespace
|
||||
{
|
||||
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
LowlevelKeyboardEvent event;
|
||||
if (nCode == HC_ACTION)
|
||||
{
|
||||
event.lParam = reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam);
|
||||
event.wParam = wParam;
|
||||
if (instance->signal_event(&event) != 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return CallNextHookEx(NULL, nCode, wParam, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
OverlayWindow::OverlayWindow()
|
||||
{
|
||||
app_name = GET_RESOURCE_STRING(IDS_SHORTCUT_GUIDE);
|
||||
@@ -24,8 +42,7 @@ const wchar_t* OverlayWindow::get_name()
|
||||
|
||||
const wchar_t** OverlayWindow::get_events()
|
||||
{
|
||||
static const wchar_t* events[2] = { ll_keyboard, 0 };
|
||||
return events;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool OverlayWindow::get_config(wchar_t* buffer, int* buffer_size)
|
||||
@@ -117,6 +134,11 @@ void OverlayWindow::enable()
|
||||
winkey_popup->set_theme(theme.value);
|
||||
target_state = std::make_unique<TargetState>(pressTime.value);
|
||||
winkey_popup->initialize();
|
||||
hook_handle = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), NULL);
|
||||
if (!hook_handle)
|
||||
{
|
||||
MessageBoxW(NULL, L"Cannot install keyboard listener.", L"PowerToys - Shortcut Guide", MB_OK | MB_ICONERROR);
|
||||
}
|
||||
}
|
||||
_enabled = true;
|
||||
}
|
||||
@@ -134,6 +156,14 @@ void OverlayWindow::disable(bool trace_event)
|
||||
target_state->exit();
|
||||
target_state.reset();
|
||||
winkey_popup.reset();
|
||||
if (hook_handle)
|
||||
{
|
||||
bool success = UnhookWindowsHookEx(hook_handle);
|
||||
if (success)
|
||||
{
|
||||
hook_handle = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,22 +179,31 @@ bool OverlayWindow::is_enabled()
|
||||
|
||||
intptr_t OverlayWindow::signal_event(const wchar_t* name, intptr_t data)
|
||||
{
|
||||
if (_enabled && wcscmp(name, ll_keyboard) == 0)
|
||||
{
|
||||
auto& event = *(reinterpret_cast<LowlevelKeyboardEvent*>(data));
|
||||
if (event.wParam == WM_KEYDOWN ||
|
||||
event.wParam == WM_SYSKEYDOWN ||
|
||||
event.wParam == WM_KEYUP ||
|
||||
event.wParam == WM_SYSKEYUP)
|
||||
{
|
||||
bool supress = target_state->signal_event(event.lParam->vkCode,
|
||||
event.wParam == WM_KEYDOWN || event.wParam == WM_SYSKEYDOWN);
|
||||
return supress ? 1 : 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
intptr_t OverlayWindow::signal_event(LowlevelKeyboardEvent* event)
|
||||
{
|
||||
if (!_enabled)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (event->wParam == WM_KEYDOWN ||
|
||||
event->wParam == WM_SYSKEYDOWN ||
|
||||
event->wParam == WM_KEYUP ||
|
||||
event->wParam == WM_SYSKEYUP)
|
||||
{
|
||||
bool suppress = target_state->signal_event(event->lParam->vkCode,
|
||||
event->wParam == WM_KEYDOWN || event->wParam == WM_SYSKEYDOWN);
|
||||
return suppress ? 1 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void OverlayWindow::on_held()
|
||||
{
|
||||
auto filter = get_shortcutguide_filtered_window();
|
||||
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
virtual void enable() override;
|
||||
virtual void disable() override;
|
||||
virtual bool is_enabled() override;
|
||||
|
||||
// PowerToys interface method, not used
|
||||
virtual intptr_t signal_event(const wchar_t* name, intptr_t data) override;
|
||||
|
||||
virtual void register_system_menu_helper(PowertoySystemMenuIface* helper) override {}
|
||||
@@ -32,6 +34,9 @@ public:
|
||||
void quick_hide();
|
||||
void was_hidden();
|
||||
|
||||
// Method called from LowLevelKeyboardProc
|
||||
intptr_t signal_event(LowlevelKeyboardEvent* event);
|
||||
|
||||
virtual void destroy() override;
|
||||
|
||||
private:
|
||||
@@ -39,6 +44,7 @@ private:
|
||||
std::unique_ptr<TargetState> target_state;
|
||||
std::unique_ptr<D2DOverlayWindow> winkey_popup;
|
||||
bool _enabled = false;
|
||||
HHOOK hook_handle;
|
||||
|
||||
void init_settings();
|
||||
void disable(bool trace_event);
|
||||
|
||||
@@ -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>{A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>overlaywindow</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
@@ -62,7 +63,6 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;OVERLAYWINDOW_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>..\..\common\inc;..\..\common\Telemetry;..\..\;..\;..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
@@ -83,7 +83,6 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;OVERLAYWINDOW_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>..\..\common\inc;..\..\common\Telemetry;..\..\;..\;..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
@@ -124,7 +123,18 @@
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="shortcut_guide.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<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>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<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.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>
|
||||
@@ -49,4 +49,7 @@
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="shortcut_guide.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user