Skip to content

Commit

Permalink
Fix disallowed classes
Browse files Browse the repository at this point in the history
  • Loading branch information
alvesvaren committed Nov 8, 2024
1 parent 345cc6f commit b0f5cd4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
65 changes: 35 additions & 30 deletions resizer2/resizer2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ static void snapToMonitor(HWND window, HMONITOR screen) {
ShowWindow(window, SW_MAXIMIZE);
}

static bool isWindowAllowed(HWND win) {
LPTSTR className = new TCHAR[256];
GetClassName(win, className, 256);

std::string str{ static_cast<std::string>(CT2A(className)) };

if (disallowedClasses.count(str) > 0) {
return false;
}

return true;
}

template <ResizerCursor cursor>
void SetGlobalCursor() {
HCURSOR hCursor = NULL;
Expand Down Expand Up @@ -313,29 +326,35 @@ void adjustWindowOpacity(int change) {
POINT pt;
GetCursorPos(&pt);
HWND hwnd = getTopLevelParent(WindowFromPoint(pt));
if (hwnd != NULL) {
BYTE currentOpacity = MAX_OPACITY;
LONG_PTR exStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
if (exStyle & WS_EX_LAYERED) {
BYTE alpha;
DWORD flags;
GetLayeredWindowAttributes(hwnd, NULL, &alpha, &flags);
currentOpacity = alpha;
}
int newOpacity = max(MIN_OPACITY, min(MAX_OPACITY, currentOpacity + change));
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle | WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd, 0, (BYTE)newOpacity, LWA_ALPHA);

if ((hwnd == NULL) || !isWindowAllowed(hwnd)) {
return;
}

BYTE currentOpacity = MAX_OPACITY;
LONG_PTR exStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
if (exStyle & WS_EX_LAYERED) {
BYTE alpha;
DWORD flags;
GetLayeredWindowAttributes(hwnd, NULL, &alpha, &flags);
currentOpacity = alpha;
}
int newOpacity = max(MIN_OPACITY, min(MAX_OPACITY, currentOpacity + change));
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle | WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd, 0, (BYTE)newOpacity, LWA_ALPHA);
}

void minimizeWindow() {
POINT pt;
GetCursorPos(&pt);
HWND hwnd = WindowFromPoint(pt);
hwnd = getTopLevelParent(hwnd);
if (hwnd != NULL) {
ShowWindow(hwnd, SW_MINIMIZE);

if (hwnd == NULL || !isWindowAllowed(hwnd)) {
return;
}

ShowWindow(hwnd, SW_MINIMIZE);
}

template<ContextType type>
Expand All @@ -350,23 +369,9 @@ void startWindowOperation() {
}

GetCursorPos(&ctx.startMousePos);
ctx.targetWindow = WindowFromPoint(ctx.startMousePos);

if (ctx.targetWindow == NULL) {
ctx.inProgress = false;
CloseHandle(ctx.hEvent);
ctx.hEvent = NULL;
return;
}

ctx.targetWindow = getTopLevelParent(ctx.targetWindow);

LPTSTR className = new TCHAR[256];
GetClassName(ctx.targetWindow, className, 256);
ctx.targetWindow = getTopLevelParent(WindowFromPoint(ctx.startMousePos));

std::string str{ static_cast<std::string>(CT2A(className)) };

if (disallowedClasses.count(str) > 0) {
if (ctx.targetWindow == NULL || !isWindowAllowed(ctx.targetWindow)) {
ctx.inProgress = false;
CloseHandle(ctx.hEvent);
ctx.hEvent = NULL;
Expand Down
1 change: 1 addition & 0 deletions resizer2/resizer2.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const int DUMMY_KEY = VK_F13; // Any key that doesn't do anything when pressed t
const std::unordered_set<std::string> disallowedClasses{
"Shell_TrayWnd",
"Progman",
"WorkerW",
};

enum ContextType {
Expand Down

0 comments on commit b0f5cd4

Please sign in to comment.