Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Qt scrollbar grippers 1.0 #836

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions mods/fix-qt-scrollbar-grippers.wh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// ==WindhawkMod==
// @id fix-qt-scrollbar-grippers
// @name Fix Qt scrollbar grippers
// @description Fixes scrollbar grippers in Qt 6.1+
// @version 1.0
// @author kawapure
// @github https://github.com/kawapure
// @twitter https://twitter.com/kawaipure

Check warning on line 8 in mods/fix-qt-scrollbar-grippers.wh.cpp

View workflow job for this annotation

GitHub Actions / Test changed files

@twitter requires manual verification
// @homepage https://kawapure.github.io
// @include ida64.exe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it meant to only target IDA?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDA was the application that I tested against, but it should work for any Qt 6.1+ application using native theme scrollbar controls. I thought that it would be obvious to any end user to specify custom targets. Should this be clarified in the README?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better clarify it, something like:

## How to enable the mod for a program
In Windhawk, go to the "Advanced" tab and scroll down to
"Custom process inclusion list". In that box, put the filename of the `.exe`.
The mod will immediately apply to those programs after you click "Save".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied that clarification.

// @compilerOptions -lcomdlg32 -luxtheme
// ==/WindhawkMod==

// ==WindhawkModReadme==
/*
# Fix Qt scrollbar grippers

![Preview](https://raw.githubusercontent.com/kawapure/images/main/fix-qt-scrollbar-grippers.png)

Qt applications compiled after 2021 (against Qt 6.1+) lack the scrollbar grippers (the lines in the middle),
visible on custom visual styles, because the responsible drawing code was removed. Here is a lazy hack around
that.

These were removed in Qt [because the developers thought that these changes wouldn't affect Windows 10](https://github.com/qt/qtbase/commit/5f5c342924a0d9a2856b2f2d6db373e25723f2b0).
They were wrong.
*/
// ==/WindhawkModReadme==

#include <windhawk_api.h>
#include <windhawk_utils.h>
#include <uxtheme.h>
#include <vsstyle.h>

using DrawThemeBackgroundEx_t = decltype(&DrawThemeBackgroundEx);
DrawThemeBackgroundEx_t DrawThemeBackgroundEx_orig;
HRESULT WINAPI DrawThemeBackgroundEx_hook(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCRECT pRect, const DTBGOPTS *pOptions)
{
HRESULT result = DrawThemeBackgroundEx_orig(hTheme, hdc, iPartId, iStateId, pRect, pOptions);

if (iPartId == SBP_THUMBBTNHORZ || iPartId == SBP_THUMBBTNVERT)
{
if (iPartId == SBP_THUMBBTNHORZ)
Wh_Log(L"dtb: is SBP_THUMBBTNHORZ");
else if (iPartId == SBP_THUMBBTNVERT)
Wh_Log(L"dtb: is SBP_THUMBBTNVERT");

int gripperPart = iPartId == SBP_THUMBBTNHORZ
? SBP_GRIPPERHORZ
: SBP_GRIPPERVERT;

SIZE gripperSize = { 0 };
GetThemePartSize(hTheme, hdc, gripperPart, iStateId, nullptr, TS_TRUE, &gripperSize);

if (
(iPartId == SBP_THUMBBTNVERT && (pRect->bottom - pRect->top) > gripperSize.cy) ||
(iPartId == SBP_THUMBBTNHORZ && (pRect->right - pRect->left) > gripperSize.cx)
)
{
Wh_Log(L"drawing gripper");

DrawThemeBackground(hTheme, hdc, gripperPart, iStateId, pRect, nullptr);
}
}

return result;
}

// The mod is being initialized, load settings, hook functions, and do other
// initialization stuff if required.
BOOL Wh_ModInit()
{
Wh_Log(L"Init");

Wh_SetFunctionHook(
(void *)DrawThemeBackgroundEx,
(void *)DrawThemeBackgroundEx_hook,
(void **)&DrawThemeBackgroundEx_orig
);

return TRUE;
}

// The mod is being unloaded, free all allocated resources.
void Wh_ModUninit()
{
Wh_Log(L"Uninit");
}
Loading