mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[OOBE] Out of box experience window (#9973)
This commit is contained in:
@@ -41,6 +41,7 @@ void D2DWindow::show(UINT x, UINT y, UINT width, UINT height)
|
||||
on_show();
|
||||
SetWindowPos(hwnd, HWND_TOPMOST, x, y, width, height, 0);
|
||||
ShowWindow(hwnd, SW_SHOWNORMAL);
|
||||
SetForegroundWindow(hwnd);
|
||||
UpdateWindow(hwnd);
|
||||
}
|
||||
|
||||
|
||||
29
src/modules/shortcut_guide/native_event_waiter.cpp
Normal file
29
src/modules/shortcut_guide/native_event_waiter.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "pch.h"
|
||||
#include "native_event_waiter.h"
|
||||
|
||||
void NativeEventWaiter::run()
|
||||
{
|
||||
while (!aborting)
|
||||
{
|
||||
auto result = WaitForSingleObject(event_handle, timeout);
|
||||
if (!aborting && result == WAIT_OBJECT_0)
|
||||
{
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NativeEventWaiter::NativeEventWaiter(const std::wstring& event_name, std::function<void()> action)
|
||||
{
|
||||
event_handle = CreateEventW(NULL, FALSE, FALSE, event_name.c_str());
|
||||
this->action = action;
|
||||
running_thread = std::thread([&]() { run(); });
|
||||
}
|
||||
|
||||
NativeEventWaiter::~NativeEventWaiter()
|
||||
{
|
||||
aborting = true;
|
||||
SetEvent(event_handle);
|
||||
running_thread.join();
|
||||
CloseHandle(event_handle);
|
||||
}
|
||||
20
src/modules/shortcut_guide/native_event_waiter.h
Normal file
20
src/modules/shortcut_guide/native_event_waiter.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
#include "common/interop/shared_constants.h"
|
||||
|
||||
class NativeEventWaiter
|
||||
{
|
||||
static const int timeout = 1000;
|
||||
|
||||
HANDLE event_handle;
|
||||
std::function<void()> action;
|
||||
std::atomic<bool> aborting;
|
||||
|
||||
void run();
|
||||
std::thread running_thread;
|
||||
|
||||
public:
|
||||
|
||||
NativeEventWaiter(const std::wstring& event_name, std::function<void()> action);
|
||||
~NativeEventWaiter();
|
||||
};
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <common/SettingsAPI/settings_objects.h>
|
||||
#include <common/debug_control.h>
|
||||
#include <common/interop/shared_constants.h>
|
||||
#include <sstream>
|
||||
#include <modules/shortcut_guide/ShortcutGuideConstants.h>
|
||||
|
||||
@@ -94,6 +95,8 @@ namespace
|
||||
((style & WS_THICKFRAME) == WS_THICKFRAME);
|
||||
return result;
|
||||
}
|
||||
|
||||
const LPARAM eventActivateWindow = 1;
|
||||
}
|
||||
|
||||
OverlayWindow::OverlayWindow()
|
||||
@@ -212,6 +215,13 @@ void OverlayWindow::enable()
|
||||
instance->target_state->toggle_force_shown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (msg == WM_APP && lparam == eventActivateWindow)
|
||||
{
|
||||
instance->target_state->toggle_force_shown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (msg != WM_HOTKEY)
|
||||
{
|
||||
return 0;
|
||||
@@ -260,6 +270,12 @@ void OverlayWindow::enable()
|
||||
}
|
||||
}
|
||||
RegisterHotKey(winkey_popup->get_window_handle(), alternative_switch_hotkey_id, alternative_switch_modifier_mask, alternative_switch_vk_code);
|
||||
|
||||
auto show_action = [&]() {
|
||||
PostMessageW(winkey_popup->get_window_handle(), WM_APP, 0, eventActivateWindow);
|
||||
};
|
||||
|
||||
event_waiter = std::make_unique<NativeEventWaiter>(CommonSharedConstants::SHOW_SHORTCUT_GUIDE_SHARED_EVENT, show_action);
|
||||
}
|
||||
_enabled = true;
|
||||
}
|
||||
@@ -276,6 +292,7 @@ void OverlayWindow::disable(bool trace_event)
|
||||
Trace::EnableShortcutGuide(false);
|
||||
}
|
||||
UnregisterHotKey(winkey_popup->get_window_handle(), alternative_switch_hotkey_id);
|
||||
event_waiter.reset();
|
||||
winkey_popup->hide();
|
||||
target_state->exit();
|
||||
target_state.reset();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <interface/powertoy_module_interface.h>
|
||||
#include "overlay_window.h"
|
||||
#include "native_event_waiter.h"
|
||||
|
||||
#include "Generated Files/resource.h"
|
||||
|
||||
@@ -44,6 +45,7 @@ private:
|
||||
std::unique_ptr<D2DOverlayWindow> winkey_popup;
|
||||
bool _enabled = false;
|
||||
HHOOK hook_handle;
|
||||
std::unique_ptr<NativeEventWaiter> event_waiter;
|
||||
|
||||
void init_settings();
|
||||
void disable(bool trace_event);
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
<ClInclude Include="d2d_svg.h" />
|
||||
<ClInclude Include="d2d_text.h" />
|
||||
<ClInclude Include="d2d_window.h" />
|
||||
<ClInclude Include="native_event_waiter.h" />
|
||||
<ClInclude Include="overlay_window.h" />
|
||||
<ClInclude Include="keyboard_state.h" />
|
||||
<ClInclude Include="Generated Files/resource.h" />
|
||||
@@ -83,6 +84,7 @@
|
||||
<ClCompile Include="d2d_svg.cpp" />
|
||||
<ClCompile Include="d2d_text.cpp" />
|
||||
<ClCompile Include="d2d_window.cpp" />
|
||||
<ClCompile Include="native_event_waiter.cpp" />
|
||||
<ClCompile Include="overlay_window.cpp" />
|
||||
<ClCompile Include="dllmain.cpp" />
|
||||
<ClCompile Include="keyboard_state.cpp" />
|
||||
|
||||
@@ -36,6 +36,9 @@
|
||||
<ClCompile Include="tasklist_positions.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="native_event_waiter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
@@ -73,6 +76,9 @@
|
||||
<ClInclude Include="start_visible.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="native_event_waiter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Header Files">
|
||||
|
||||
Reference in New Issue
Block a user