Skip to content

Commit

Permalink
fix: adjust startup menu position for multi screen
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoruas committed Dec 11, 2024
1 parent 8db53b8 commit 1ccd545
Showing 1 changed file with 65 additions and 22 deletions.
87 changes: 65 additions & 22 deletions mods/taskbar-on-top.wh.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==WindhawkMod==
// @id taskbar-on-top
// @name Taskbar on top for Windows 11
// @id taskbar-on-top-fork

Check warning on line 2 in mods/taskbar-on-top.wh.cpp

View workflow job for this annotation

GitHub Actions / Test changed files

Expected id to be "taskbar-on-top"
// @name Taskbar on top for Windows 11 - Fork
// @description Moves the Windows 11 taskbar to the top of the screen
// @version 1.0.5
// @author m417z
Expand Down Expand Up @@ -1052,15 +1052,25 @@ BOOL WINAPI SetWindowPos_Hook(HWND hWnd,
};

HMONITOR monitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);

MONITORINFO monitorInfo = {sizeof(MONITORINFO)};
if (GetMonitorInfo(monitor, &monitorInfo)) {
// Corrigir o posicionamento horizontal
if (X < monitorInfo.rcWork.left) {
X = monitorInfo.rcWork.left;
} else if (X > monitorInfo.rcWork.right - cx) {
X = monitorInfo.rcWork.right - cx;
}

// Corrigir o posicionamento vertical
if (Y < monitorInfo.rcWork.top) {
Y = monitorInfo.rcWork.top;
}
}
if (GetTaskbarLocationForMonitor(monitor) == TaskbarLocation::bottom) {
return original();
}

MONITORINFO monitorInfo{
.cbSize = sizeof(MONITORINFO),
};
GetMonitorInfo(monitor, &monitorInfo);

if (g_inCTaskListThumbnailWnd_DisplayUI) {
Y = std::max(monitorInfo.rcWork.top, pt.y);
Y += MulDiv(12, GetDpiForWindow(hWnd), 96);
Expand All @@ -1084,15 +1094,25 @@ BOOL WINAPI SetWindowPos_Hook(HWND hWnd,
};

HMONITOR monitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);

MONITORINFO monitorInfo = {sizeof(MONITORINFO)};
if (GetMonitorInfo(monitor, &monitorInfo)) {
// Corrigir o posicionamento horizontal
if (X < monitorInfo.rcWork.left) {
X = monitorInfo.rcWork.left;
} else if (X > monitorInfo.rcWork.right - cx) {
X = monitorInfo.rcWork.right - cx;
}

// Corrigir o posicionamento vertical
if (Y < monitorInfo.rcWork.top) {
Y = monitorInfo.rcWork.top;
}
}
if (GetTaskbarLocationForMonitor(monitor) == TaskbarLocation::bottom) {
return original();
}

MONITORINFO monitorInfo{
.cbSize = sizeof(MONITORINFO),
};
GetMonitorInfo(monitor, &monitorInfo);

if (Y < monitorInfo.rcWork.top) {
Y = monitorInfo.rcWork.top;
} else if (Y > monitorInfo.rcWork.bottom - cy) {
Expand Down Expand Up @@ -1135,15 +1155,25 @@ BOOL WINAPI SetWindowPos_Hook(HWND hWnd,
GetCursorPos(&pt);

HMONITOR monitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);

MONITORINFO monitorInfo = {sizeof(MONITORINFO)};
if (GetMonitorInfo(monitor, &monitorInfo)) {
// Corrigir o posicionamento horizontal
if (X < monitorInfo.rcWork.left) {
X = monitorInfo.rcWork.left;
} else if (X > monitorInfo.rcWork.right - cx) {
X = monitorInfo.rcWork.right - cx;
}

// Corrigir o posicionamento vertical
if (Y < monitorInfo.rcWork.top) {
Y = monitorInfo.rcWork.top;
}
}
if (GetTaskbarLocationForMonitor(monitor) == TaskbarLocation::bottom) {
return original();
}

MONITORINFO monitorInfo{
.cbSize = sizeof(MONITORINFO),
};
GetMonitorInfo(monitor, &monitorInfo);

Y = monitorInfo.rcWork.top;
} else {
return original();
Expand Down Expand Up @@ -1245,7 +1275,19 @@ HRESULT WINAPI DwmSetWindowAttribute_Hook(HWND hwnd,
int cy = targetRect.bottom - targetRect.top;

if (target == Target::StartMenu) {
// Only change height.
// Obter o monitor do hwnd
HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);

MONITORINFO monitorInfo = {sizeof(MONITORINFO)};
if (!GetMonitorInfo(monitor, &monitorInfo)) {
return original(); // Fallback caso falhe.
}

// Centralizar no monitor ativo
int xNew = (monitorInfo.rcWork.left + monitorInfo.rcWork.right - cx) / 2;
int yNew = monitorInfo.rcWork.top;

// Ajustar apenas a altura para StartMenu
const int h1 = MulDiv(750, monitorDpiY, 96);
const int h2 = MulDiv(694, monitorDpiY, 96);
int cyNew = cy;
Expand All @@ -1255,11 +1297,12 @@ HRESULT WINAPI DwmSetWindowAttribute_Hook(HWND hwnd,
cyNew = h2;
}

if (cyNew == cy) {
return original();
}
// Aplicar as novas coordenadas
SetWindowPos_Original(hwnd, nullptr, xNew, yNew, cx, cyNew,
SWP_NOZORDER | SWP_NOACTIVATE);

return original(); // Retornar após ajustar.

cy = cyNew;
} else if (target == Target::SearchHost) {
// Only change y.
MONITORINFO monitorInfo{
Expand Down

0 comments on commit 1ccd545

Please sign in to comment.