mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
[Peek]Close on activation shortcut if focused (#26480)
This commit is contained in:
@@ -62,6 +62,7 @@ private:
|
|||||||
bool m_alwaysRunNotElevated = true;
|
bool m_alwaysRunNotElevated = true;
|
||||||
|
|
||||||
HANDLE m_hProcess = 0;
|
HANDLE m_hProcess = 0;
|
||||||
|
DWORD m_processPid = 0;
|
||||||
|
|
||||||
HANDLE m_hInvokeEvent;
|
HANDLE m_hInvokeEvent;
|
||||||
|
|
||||||
@@ -233,7 +234,7 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_explorer_or_desktop_window_focused()
|
bool is_peek_or_explorer_or_desktop_window_focused()
|
||||||
{
|
{
|
||||||
HWND foregroundWindowHandle = GetForegroundWindow();
|
HWND foregroundWindowHandle = GetForegroundWindow();
|
||||||
if (foregroundWindowHandle == NULL)
|
if (foregroundWindowHandle == NULL)
|
||||||
@@ -241,6 +242,16 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DWORD pid{};
|
||||||
|
if (GetWindowThreadProcessId(foregroundWindowHandle, &pid)!=0)
|
||||||
|
{
|
||||||
|
// If the foreground window is the Peek window, send activation signal.
|
||||||
|
if (m_processPid != 0 && pid == m_processPid)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (is_desktop_window(foregroundWindowHandle))
|
if (is_desktop_window(foregroundWindowHandle))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -276,6 +287,7 @@ private:
|
|||||||
std::optional<ProcessInfo> processStartedInfo = RunNonElevatedFailsafe(runExecutablePath, executable_args, modulePath, PROCESS_QUERY_INFORMATION | SYNCHRONIZE | PROCESS_TERMINATE);
|
std::optional<ProcessInfo> processStartedInfo = RunNonElevatedFailsafe(runExecutablePath, executable_args, modulePath, PROCESS_QUERY_INFORMATION | SYNCHRONIZE | PROCESS_TERMINATE);
|
||||||
if (processStartedInfo.has_value())
|
if (processStartedInfo.has_value())
|
||||||
{
|
{
|
||||||
|
m_processPid = processStartedInfo.value().processID;
|
||||||
m_hProcess = processStartedInfo.value().processHandle.release();
|
m_hProcess = processStartedInfo.value().processHandle.release();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -303,6 +315,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_hProcess = sei.hProcess;
|
m_hProcess = sei.hProcess;
|
||||||
|
m_processPid = GetProcessId(m_hProcess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,6 +414,7 @@ public:
|
|||||||
}
|
}
|
||||||
CloseHandle(m_hProcess);
|
CloseHandle(m_hProcess);
|
||||||
m_hProcess = 0;
|
m_hProcess = 0;
|
||||||
|
m_processPid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_enabled = false;
|
m_enabled = false;
|
||||||
@@ -436,8 +450,8 @@ public:
|
|||||||
{
|
{
|
||||||
Logger::trace(L"Peek hotkey pressed");
|
Logger::trace(L"Peek hotkey pressed");
|
||||||
|
|
||||||
// Only activate and consume the shortcut if it is an explorer or desktop window is the foreground application.
|
// Only activate and consume the shortcut if a Peek, explorer or desktop window is the foreground application.
|
||||||
if (is_explorer_or_desktop_window_focused())
|
if (is_peek_or_explorer_or_desktop_window_focused())
|
||||||
{
|
{
|
||||||
// TODO: fix VK_SPACE DestroyWindow in viewer app
|
// TODO: fix VK_SPACE DestroyWindow in viewer app
|
||||||
if (!is_viewer_running())
|
if (!is_viewer_running())
|
||||||
|
|||||||
Reference in New Issue
Block a user