ramensoftware / windhawk-mods

The official collection of Windhawk mods
319 stars 57 forks source link

Bring Back The Borders! | Buggy behavior #902

Open SandTechStuff opened 3 months ago

SandTechStuff commented 3 months ago

@teknixstuff

Bring Back The Borders! does not seem to be working as intended. The following screenshots are using DWMBlurGlass to apply accent color to titlebars and window borders without having to use another msstyles file. I have observed the same behavior using custom msstyles, however. Let me know if you have any questions, or if the nature of Windows 11 makes this a pain to fix.

without Without BBTB!

with With BBTB! Notice the lack of borders and black outline around windows.

restartDwm With BBTB!, after restarting DWM. There is an outline of borders, but they are not filled in.

withEdits An edited version of BBTB! that removed everything related to GetBorderRect. The borders are filled in now! They still disappear every once in a while, though. I do not have experience with Windhawk mods so I do not know the intended function of the GetBorderRect hooks, and if they are safe to remove.

stylesAndGlass That edited version of BBTB! along with custom msstyles and DWMBlurGlass. The borders render properly but the black outline is still there and the corners are not transparent.

Mod logs if needed: BBTBlogs.txt

Windows 11 23H2 22631.4037

teknixstuff commented 3 months ago

The third image is expected behaviour with the default W11 theme, as it does not have borders included afaik. The behaviour in the fourth image seems very weird to me, but I'll look into that. The fifth image is expected behaviour with the normal (unedited) version as well. Could you please send me the edited version? I'd like to test it and see if it works more reliably than my current version.

teknixstuff commented 3 months ago

Regarding the corners and black outlines, that is unfortunately quite hard to fix, but when I have time I will see what I can do.

SandTechStuff commented 3 months ago

The third image is expected behaviour with the default W11 theme, as it does not have borders included afaik.

This happens with custom msstyles too. Image below is unedited BBTB! The borders are rendered but not filled in. This is what was shown in the third image, but as you noticed Win11 does not have border resources so they are transparent.

stylesAndStockBBTB

The fifth image is expected behaviour with the normal (unedited) version as well.

Not in my case, the borders are not filled in (as shown in the image above). Also, with the unedited version, if you click off the window the borders disappear completely. This leaves just the custom titlebar.

clickOff

Could you please send me the edited version?

Sure, here you go.

// ==WindhawkMod==
// @id              w11-dwm-fix-fork
// @name            Bring Back the Borders! - Fork
// @description     Testing BBTB
// @version         1.1.0
// @author          teknixstuff
// @github          https://github.com/teknixstuff
// @twitter         https://twitter.com/teknixstuff
// @homepage        https://teknixstuff.github.io/
// @include         dwm.exe
// @architecture    x86-64
// ==/WindhawkMod==

// Source code is published under The MIT License.
// Email teknixstuff@gmail.com for any help or info

// ==WindhawkModReadme==
/*
# Bring back the borders!

A simple mod to restore borders and corners in Windows 11.

Based on the
[Disable rounded corners in Windows 11](https://windhawk.net/mods/disable-rounded-corners)
project by m417z.

Based on the
[Win11DisableRoundedCorners](https://github.com/valinet/Win11DisableRoundedCorners)
project by Valentin Radu.

## ⚠ Important usage note ⚠

In order to use this mod, you must allow Windhawk to inject into the **dwm.exe**
system process. To do so, add it to the process inclusion list in the advanced
settings. If you do not do this, it will silently fail to inject.

![Advanced settings screenshot](https://i.imgur.com/LRhREtJ.png)
*/
// ==/WindhawkModReadme==

#include <windhawk_utils.h>

bool HighContrastNow = true;

int (*WINAPI GetEffectiveCornerStyle_Original)();
int WINAPI GetEffectiveCornerStyle_Hook() {
    return 0;
}

bool (*WINAPI IsHighContrastMode_Original)();
bool WINAPI IsHighContrastMode_Hook() {
    return HighContrastNow;
}

bool (*WINAPI SystemParametersInfoW_Original)(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni);
bool WINAPI SystemParametersInfoW_Hook(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni) {
    bool retval = SystemParametersInfoW_Original(uiAction, uiParam, pvParam, fWinIni);
    if (uiAction == SPI_GETHIGHCONTRAST) {
        HIGHCONTRASTW* contrast;
        contrast = (HIGHCONTRASTW*)pvParam;
        contrast->dwFlags |= HCF_HIGHCONTRASTON;
    }
    return retval;
}

BOOL Wh_ModInit() {
    Wh_Log(L">");

    HMODULE udwm = GetModuleHandle(L"udwm.dll");
    if (!udwm) {
        Wh_Log(L"udwm.dll isn't loaded");
        return FALSE;
    }
    HMODULE user32 = GetModuleHandle(L"user32.dll");
    if (!user32) {
        Wh_Log(L"user32.dll isn't loaded");
        return FALSE;
    }

    WindhawkUtils::SYMBOL_HOOK symbolHooksUser32[] = {
        {
            {LR"(int __cdecl RealSystemParametersInfoW(unsigned int,unsigned int,void *,unsigned int))"},
            (void**)&SystemParametersInfoW_Original,
            (void*)SystemParametersInfoW_Hook,
        },
    };

    HookSymbols(user32, symbolHooksUser32, ARRAYSIZE(symbolHooksUser32));

    WindhawkUtils::SYMBOL_HOOK symbolHooks[] = {
        {
            {LR"(private: enum CORNER_STYLE __cdecl CTopLevelWindow::GetEffectiveCornerStyle(void))"},
            (void**)&GetEffectiveCornerStyle_Original,
            (void*)GetEffectiveCornerStyle_Hook,
        },
        {
            {LR"(public: static bool __cdecl CDesktopManager::IsHighContrastMode(void))"},
            (void**)&IsHighContrastMode_Original,
            (void*)IsHighContrastMode_Hook,
        },
    };

    return HookSymbols(udwm, symbolHooks, ARRAYSIZE(symbolHooks));
}

void Wh_ModUninit() {
    Wh_Log(L">");
}
SandTechStuff commented 2 months ago

Any updates on this Tech Stuff?