Akascape / py-window-styles

Customize your python UI window with awesome pre-built windows 11 themes.
Creative Commons Zero v1.0 Universal
257 stars 15 forks source link

Stuttering Caused by Transparency Effects Option in Windows #10

Closed Rain623 closed 4 months ago

Rain623 commented 8 months ago

System: Windows 10 22H2 19045.3448 GPU: NVIDIA GeForce RTX 3060 Python:3.11.5 Enabling the "Transparency Effects" option in Personalization > Colors leads to severe lag when using transparent themes (acrylic, aero, transparent). When dragging windows, there is a significant delay, with windows gradually moving to the mouse's position. Even after releasing the mouse, the windows continue to move until they reach the final release point. Additionally, the GPU usage of the Desktop Window Manager (dwm.exe) ranges from approximately 5% to 30%. Disabling the "Transparency Effects" option doesn't result in a noticeable difference in GPU usage by the Desktop Window Manager (dwm.exe), but the lag issue disappears.

code:

import tkinter
import pywinstyles

root = tkinter.Tk()
pywinstyles.apply_style(root, "acrylic")

root.mainloop()
Akascape commented 8 months ago

@Rain623 I know this is a problem, but it works smoother after adding some widget and frames. Aero is much smoother than acrylic. For me the GPU uses decreases by 40% after adding elements in the window. (i.e 60%--> 20%)

Rain623 commented 8 months ago

@Akascape Even after adding some widget and frames, acrylic and transparency still experience lag, but Aero does not lag (in fact, Aero doesn't lag even without adding widget and frames).There is no significant change in GPU usage.

Akascape commented 8 months ago

@Rain623 there will be lag in blurred windows, can't do anything for now. Maybe disable the resizability of the window if you are worried too much.

littlewhitecloud commented 5 months ago

It is just a problem of the win32 api, actually, "SetWindowCompositionAttribute" is a undocumented function and it will cause many problem just like the laggy window. (Both windows 10 & 11)

littlewhitecloud commented 5 months ago

Also it won't be too much laggy on windows 11, acrylic and aero are the same effect. It only use %5 on windows 11 ( I am just using Arc A750 GPU) image And it seems that the titlebar can not show very well. image

Akascape commented 5 months ago

@littlewhitecloud So there is no solution for now.

many problem just like the laggy window

what other problems? Not serious I guess.

littlewhitecloud commented 5 months ago

They are hard too describe, maybe not serious.

littlewhitecloud commented 4 months ago

I just found a new way to fix it and it won't be lagyyyyyyyyy

Akascape commented 4 months ago

@littlewhitecloud Wow, please share the code.

littlewhitecloud commented 4 months ago

It is c++ and the code is here:

void ApplyAcrylic(HWND hwnd, bool extend = false)
{
    pfnSetWindowCompositionAttribute SetWindowCompositionAttribute = (pfnSetWindowCompositionAttribute)GetProcAddress(GetModuleHandle("user32.dll"), "SetWindowCompositionAttribute");

    ApplyDarkMode(hwnd);

    ACCENT_POLICY accentpolicy = {};

    accentpolicy.AccentState = 3;
    accentpolicy.GradientColor = gradientcolor;

    // Set the WindowCompositionArrtibuteData
    WINDOWCOMPOSITIONATTRIBDATA data;
    data.Attrib = 30;
    data.pvData = &accentpolicy;
    data.cbData = sizeof(accentpolicy);

    // Set the window's backdrop and extend to the frame
    SetWindowCompositionAttribute(hwnd, &data);
    if (extend)
        ExtendFrameIntoClientArea(hwnd);
}

There may be a bit different in the repo, that's okay. Clone this repo https://github.com/littlewhitecloud/win32style And copy this code:

from ctypes import c_char_p, windll
from win32style import *
from tkinter import Tk

w = Tk()
w.title("example")
w.geometry("1080x570")
w.iconbitmap("")
w.config(background="black")
hwnd = windll.user32.FindWindowW(c_char_p(None), "example")

ApplyAcrylic(hwnd, True)
w.mainloop()

Then it won't be laggy when you dragging or resizing the window. It also use no GPU and I don't know why.

littlewhitecloud commented 4 months ago

It does these:

littlewhitecloud commented 4 months ago

Does it fix the problem?

Akascape commented 4 months ago

@littlewhitecloud I will let you know, I am currently not working on this. But will fix it with your method.

littlewhitecloud commented 4 months ago

@littlewhitecloud I will let you know, I am currently not working on this. But will fix it with your method.

Let me do that. I'm already fixed it.

littlewhitecloud commented 4 months ago

I am not sure about that this patch will work on windows 10?