mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 11:17:53 +01:00
[Workspaces] Bring Editor to foreground on hotkey (#34414)
This commit is contained in:
@@ -75,7 +75,14 @@ public:
|
|||||||
|
|
||||||
virtual void OnHotkeyEx() override
|
virtual void OnHotkeyEx() override
|
||||||
{
|
{
|
||||||
launch_editor();
|
if (is_process_running())
|
||||||
|
{
|
||||||
|
bring_process_to_front();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
launch_editor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the configured status for the gpo policy for the module
|
// Return the configured status for the gpo policy for the module
|
||||||
@@ -323,6 +330,29 @@ private:
|
|||||||
m_hProcess = sei.hProcess;
|
m_hProcess = sei.hProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bring_process_to_front()
|
||||||
|
{
|
||||||
|
auto enum_windows = [](HWND hwnd, LPARAM param) -> BOOL {
|
||||||
|
HANDLE process_handle = reinterpret_cast<HANDLE>(param);
|
||||||
|
DWORD window_process_id = 0;
|
||||||
|
|
||||||
|
GetWindowThreadProcessId(hwnd, &window_process_id);
|
||||||
|
if (GetProcessId(process_handle) == window_process_id)
|
||||||
|
{
|
||||||
|
SetForegroundWindow(hwnd);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
};
|
||||||
|
|
||||||
|
EnumWindows(enum_windows, (LPARAM)m_hProcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_process_running() const
|
||||||
|
{
|
||||||
|
return WaitForSingleObject(m_hProcess, 0) == WAIT_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
std::wstring app_name;
|
std::wstring app_name;
|
||||||
//contains the non localized key of the powertoy
|
//contains the non localized key of the powertoy
|
||||||
std::wstring app_key;
|
std::wstring app_key;
|
||||||
|
|||||||
Reference in New Issue
Block a user