mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
FZ: warn w/ a toast if an elevated window cannot be dragged and offer learning more
This commit is contained in:
committed by
Andrey Nekrasov
parent
c2e219b446
commit
60fa6071b9
@@ -12,9 +12,13 @@
|
||||
|
||||
#include <functional>
|
||||
#include <common/common.h>
|
||||
#include <lib\util.h>
|
||||
#include <common/window_helpers.h>
|
||||
#include <common/notifications.h>
|
||||
#include <lib/util.h>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <common/notifications/fancyzones_notifications.h>
|
||||
|
||||
enum class DisplayChangeType
|
||||
{
|
||||
WorkArea,
|
||||
@@ -24,6 +28,8 @@ enum class DisplayChangeType
|
||||
Initialization
|
||||
};
|
||||
|
||||
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
@@ -176,7 +182,7 @@ private:
|
||||
bool IsInterestingWindow(HWND window) noexcept;
|
||||
void UpdateZoneWindows() noexcept;
|
||||
void MoveWindowsOnDisplayChange() noexcept;
|
||||
void UpdateDragState(require_write_lock) noexcept;
|
||||
void UpdateDragState(HWND window, require_write_lock) noexcept;
|
||||
void CycleActiveZoneSet(DWORD vkCode) noexcept;
|
||||
bool OnSnapHotkey(DWORD vkCode) noexcept;
|
||||
void MoveSizeStartInternal(HWND window, HMONITOR monitor, POINT const& ptScreen, require_write_lock) noexcept;
|
||||
@@ -807,7 +813,7 @@ void FancyZones::MoveWindowsOnDisplayChange() noexcept
|
||||
EnumWindows(callback, reinterpret_cast<LPARAM>(this));
|
||||
}
|
||||
|
||||
void FancyZones::UpdateDragState(require_write_lock) noexcept
|
||||
void FancyZones::UpdateDragState(HWND window, require_write_lock) noexcept
|
||||
{
|
||||
const bool shift = GetAsyncKeyState(VK_SHIFT) & 0x8000;
|
||||
const bool mouseL = GetAsyncKeyState(VK_LBUTTON) & 0x8000;
|
||||
@@ -836,6 +842,23 @@ void FancyZones::UpdateDragState(require_write_lock) noexcept
|
||||
{
|
||||
m_dragEnabled = !(shift | mouse);
|
||||
}
|
||||
|
||||
const bool windowElevated = IsProcessOfWindowElevated(window);
|
||||
static const bool meElevated = is_process_elevated();
|
||||
static bool warning_shown = false;
|
||||
if (windowElevated && !meElevated)
|
||||
{
|
||||
m_dragEnabled = false;
|
||||
if (!warning_shown && !is_cant_drag_elevated_warning_disabled())
|
||||
{
|
||||
std::vector<notifications::action_t> actions = {
|
||||
notifications::link_button{ GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED_LEARN_MORE), L"https://aka.ms/powertoysDetectedElevatedHelp" },
|
||||
notifications::link_button{ GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED_DIALOG_DONT_SHOW_AGAIN), L"powertoys://cant_drag_elevated_disable/" }
|
||||
};
|
||||
notifications::show_toast_with_activations(GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED), {}, std::move(actions));
|
||||
warning_shown = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FancyZones::CycleActiveZoneSet(DWORD vkCode) noexcept
|
||||
@@ -936,7 +959,7 @@ void FancyZones::MoveSizeStartInternal(HWND window, HMONITOR monitor, POINT cons
|
||||
m_windowMoveSize = window;
|
||||
|
||||
// This updates m_dragEnabled depending on if the shift key is being held down.
|
||||
UpdateDragState(writeLock);
|
||||
UpdateDragState(window, writeLock);
|
||||
|
||||
if (m_dragEnabled)
|
||||
{
|
||||
@@ -1019,7 +1042,7 @@ void FancyZones::MoveSizeUpdateInternal(HMONITOR monitor, POINT const& ptScreen,
|
||||
if (m_inMoveSize)
|
||||
{
|
||||
// This updates m_dragEnabled depending on if the shift key is being held down.
|
||||
UpdateDragState(writeLock);
|
||||
UpdateDragState(m_windowMoveSize, writeLock);
|
||||
|
||||
if (m_zoneWindowMoveSize)
|
||||
{
|
||||
@@ -1226,4 +1249,4 @@ winrt::com_ptr<IFancyZones> MakeFancyZones(HINSTANCE hinstance, const winrt::com
|
||||
}
|
||||
|
||||
return winrt::make_self<FancyZones>(hinstance, settings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ BEGIN
|
||||
IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION "To exclude an application from snapping to zones add its name here (one per line). Excluded apps will react to the Windows Snap regardless of all other settings."
|
||||
IDS_SETTINGS_HIGHLIGHT_OPACITY "Zone opacity (%)"
|
||||
IDS_FANCYZONES L"FancyZones"
|
||||
IDS_CANT_DRAG_ELEVATED L"We've detected an application running with administrator privileges. This blocks some functionality in PowerToys. Visit our wiki page to learn more."
|
||||
IDS_CANT_DRAG_ELEVATED_LEARN_MORE L"Learn more"
|
||||
IDS_CANT_DRAG_ELEVATED_DIALOG_DONT_SHOW_AGAIN L"Don't show again"
|
||||
|
||||
END
|
||||
|
||||
1 VERSIONINFO
|
||||
|
||||
@@ -19,3 +19,6 @@
|
||||
#define IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION 119
|
||||
#define IDS_SETTINGS_HIGHLIGHT_OPACITY 120
|
||||
#define IDS_FANCYZONES 121
|
||||
#define IDS_CANT_DRAG_ELEVATED 122
|
||||
#define IDS_CANT_DRAG_ELEVATED_LEARN_MORE 123
|
||||
#define IDS_CANT_DRAG_ELEVATED_DIALOG_DONT_SHOW_AGAIN 124
|
||||
|
||||
Reference in New Issue
Block a user