mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
Introduce ZoneWindowDrawing files and move stuff to better place (#6142)
This commit is contained in:
@@ -17,19 +17,6 @@ namespace localized_strings
|
||||
const wchar_t LAST_ERROR_TITLE_STRING[] = L"Error";
|
||||
}
|
||||
|
||||
std::optional<RECT> get_button_pos(HWND hwnd)
|
||||
{
|
||||
RECT button;
|
||||
if (DwmGetWindowAttribute(hwnd, DWMWA_CAPTION_BUTTON_BOUNDS, &button, sizeof(RECT)) == S_OK)
|
||||
{
|
||||
return button;
|
||||
}
|
||||
else
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<RECT> get_window_pos(HWND hwnd)
|
||||
{
|
||||
RECT window;
|
||||
@@ -43,19 +30,6 @@ std::optional<RECT> get_window_pos(HWND hwnd)
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<POINT> get_mouse_pos()
|
||||
{
|
||||
POINT point;
|
||||
if (GetCursorPos(&point) == 0)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
else
|
||||
{
|
||||
return point;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_system_window(HWND hwnd, const char* class_name)
|
||||
{
|
||||
// We compare the HWND against HWND of the desktop and shell windows,
|
||||
@@ -79,74 +53,6 @@ bool is_system_window(HWND hwnd, const char* class_name)
|
||||
return false;
|
||||
}
|
||||
|
||||
int width(const RECT& rect)
|
||||
{
|
||||
return rect.right - rect.left;
|
||||
}
|
||||
|
||||
int height(const RECT& rect)
|
||||
{
|
||||
return rect.bottom - rect.top;
|
||||
}
|
||||
|
||||
bool operator<(const RECT& lhs, const RECT& rhs)
|
||||
{
|
||||
auto lhs_tuple = std::make_tuple(lhs.left, lhs.right, lhs.top, lhs.bottom);
|
||||
auto rhs_tuple = std::make_tuple(rhs.left, rhs.right, rhs.top, rhs.bottom);
|
||||
return lhs_tuple < rhs_tuple;
|
||||
}
|
||||
|
||||
RECT keep_rect_inside_rect(const RECT& small_rect, const RECT& big_rect)
|
||||
{
|
||||
RECT result = small_rect;
|
||||
if ((result.right - result.left) > (big_rect.right - big_rect.left))
|
||||
{
|
||||
// small_rect is too big horizontally. resize it.
|
||||
result.right = big_rect.right;
|
||||
result.left = big_rect.left;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.right > big_rect.right)
|
||||
{
|
||||
// move the rect left.
|
||||
result.left -= result.right - big_rect.right;
|
||||
result.right -= result.right - big_rect.right;
|
||||
}
|
||||
|
||||
if (result.left < big_rect.left)
|
||||
{
|
||||
// move the rect right.
|
||||
result.right += big_rect.left - result.left;
|
||||
result.left += big_rect.left - result.left;
|
||||
}
|
||||
}
|
||||
|
||||
if ((result.bottom - result.top) > (big_rect.bottom - big_rect.top))
|
||||
{
|
||||
// small_rect is too big vertically. resize it.
|
||||
result.bottom = big_rect.bottom;
|
||||
result.top = big_rect.top;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.bottom > big_rect.bottom)
|
||||
{
|
||||
// move the rect up.
|
||||
result.top -= result.bottom - big_rect.bottom;
|
||||
result.bottom -= result.bottom - big_rect.bottom;
|
||||
}
|
||||
|
||||
if (result.top < big_rect.top)
|
||||
{
|
||||
// move the rect down.
|
||||
result.bottom += big_rect.top - result.top;
|
||||
result.top += big_rect.top - result.top;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int run_message_loop(const bool until_idle, const std::optional<uint32_t> timeout_seconds)
|
||||
{
|
||||
MSG msg;
|
||||
|
||||
@@ -6,23 +6,12 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
// Returns RECT with positions of the minimize/maximize buttons of the given window.
|
||||
// Does not always work, since some apps draw custom toolbars.
|
||||
std::optional<RECT> get_button_pos(HWND hwnd);
|
||||
// Gets position of given window.
|
||||
std::optional<RECT> get_window_pos(HWND hwnd);
|
||||
// Gets mouse position.
|
||||
std::optional<POINT> get_mouse_pos();
|
||||
|
||||
// Check if window is part of the shell or the taskbar.
|
||||
bool is_system_window(HWND hwnd, const char* class_name);
|
||||
|
||||
// Calculate sizes
|
||||
int width(const RECT& rect);
|
||||
int height(const RECT& rect);
|
||||
// Compare rects
|
||||
bool operator<(const RECT& lhs, const RECT& rhs);
|
||||
// Moves and/or resizes small_rect to fit inside big_rect.
|
||||
RECT keep_rect_inside_rect(const RECT& small_rect, const RECT& big_rect);
|
||||
// Initializes and runs windows message loop
|
||||
int run_message_loop(const bool until_idle = false, const std::optional<uint32_t> timeout_seconds = {});
|
||||
|
||||
@@ -107,5 +96,3 @@ struct overloaded : Ts...
|
||||
};
|
||||
template<class... Ts>
|
||||
overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
#define POWER_LAUNCHER_PID_SHARED_FILE L"Local\\3cbfbad4-199b-4e2c-9825-942d5d3d3c74"
|
||||
|
||||
@@ -4,6 +4,16 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
bool operator<(const RECT& lhs, const RECT& rhs)
|
||||
{
|
||||
auto lhs_tuple = std::make_tuple(lhs.left, lhs.right, lhs.top, lhs.bottom);
|
||||
auto rhs_tuple = std::make_tuple(rhs.left, rhs.right, rhs.top, rhs.bottom);
|
||||
return lhs_tuple < rhs_tuple;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const ScreenSize& lhs, const ScreenSize& rhs)
|
||||
{
|
||||
auto lhs_tuple = std::make_tuple(lhs.rect.left, lhs.rect.right, lhs.rect.top, lhs.rect.bottom);
|
||||
|
||||
Reference in New Issue
Block a user