wangwenx190 / framelesshelper

Project moved to: https://github.com/stdware/qwindowkit Cross-platform window customization framework for Qt Widgets and Qt Quick. Supports Windows, Linux and macOS.
MIT License
849 stars 202 forks source link

[Windows] [>= Win10 1803] Dragging & Resizing is laggy when the Acrylic effect is enabled #27

Closed wangwenx190 closed 2 years ago

wangwenx190 commented 4 years ago

It's a bug of Windows itself. Not fixable from my side.

wangwenx190 commented 4 years ago

we can ship a specific dll in the meantime

I think it's dangerous. Better to wait for the official fix.

JulienMaille commented 4 years ago

we can ship a specific dll in the meantime

I think it's dangerous. Better to wait for the official fix.

Can you share the links where you've seen other people stating latest insider build has the fix?

selastingeorge commented 4 years ago

I have seen here, people are telling that the acrylic blur is not lag in under builds. https://github.com/Eugeny/terminus/issues/949

I think the only current way or the better way is to use the xaml islands

On Sat, 14 Nov, 2020, 7:16 pm Julien, notifications@github.com wrote:

we can ship a specific dll in the meantime

I think it's dangerous. Better to wait for the official fix.

Can you share the links where you've seen other people stating latest insider build has the fix?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wangwenx190/framelesshelper/issues/27#issuecomment-727209560, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKGWVOAQUPXZD465DJ77GDSP2C4XANCNFSM4STC7GBQ .

JulienMaille commented 4 years ago

@wangwenx190 bad news: resizing is still laggy!

wangwenx190 commented 4 years ago

@wangwenx190 bad news: resizing is still laggy!

Previously we can work-around the laggy dragging by disabling the transparent effect, but the resizing is still laggy. So I'm not surprised.

wangwenx190 commented 4 years ago

I think the only current way or the better way is to use the xaml islands

@SelastinGeorge Yes, it is. The best way to use the Acrylic brush in Win32 applications is to use the xaml islands, and that's what Microsoft recommended. There's no laggy dragging and resizing issue when using xaml islands. But for this repo, we are using Qt, and it's rather hard to integrate Qt with xaml islands.

selastingeorge commented 4 years ago

@wangwenx190 did u get flickering while resizing the window on window 10 19042. when i alter the WM_NCCALCSIZE. it flickers one or two times. so i come up with a new way by altering the hbrush of the window class. its perfect and does not flicker at all. In the 1903 build the dwmExtendFrame... creates a 8px margin around window while maximizing. you can fix this issue also by altering the hbrush of window in createwindowex

selastingeorge commented 4 years ago

i'm doing this in wpf. i was not able to alter the window class in wpf but i altered it by using the setWindowCompositionAttribute(). its undocumented but altering some values bring better options like if we set AccentState to 6 we get a completely transparent window. and a very good news is that from 19042 the acrylic blur is not flickering from this sample:

https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/AcrylicEffect

wangwenx190 commented 4 years ago

@wangwenx190 did u get flickering while resizing the window on window 10 19042. when i alter the WM_NCCALCSIZE. it flickers one or two times. so i come up with a new way by altering the hbrush of the window class. its perfect and does not flicker at all. In the 1903 build the dwmExtendFrame... creates a 8px margin around window while maximizing. you can fix this issue also by altering the hbrush of window in createwindowex

Thanks for telling me this. Your solution may work well for normal windows, however, things are a lot different in Qt. Qt has taken over the responsibility of painting windows. Adjust the brush may not help.

wangwenx190 commented 4 years ago

i'm doing this in wpf. i was not able to alter the window class in wpf but i altered it by using the setWindowCompositionAttribute(). its undocumented but altering some values bring better options like if we set AccentState to 6 we get a completely transparent window. and a very good news is that from 19042 the acrylic blur is not flickering from this sample:

https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/AcrylicEffect

That’s a good news indeed! Thanks for telling me this!

selastingeorge commented 4 years ago

@wangwenx190 did u get flickering while resizing the window on window 10 19042. when i alter the WM_NCCALCSIZE. it flickers one or two times. so i come up with a new way by altering the hbrush of the window class. its perfect and does not flicker at all. In the 1903 build the dwmExtendFrame... creates a 8px margin around window while maximizing. you can fix this issue also by altering the hbrush of window in createwindowex

Thanks for telling me this. Your solution may work well for normal windows, however, things are a lot different in Qt. Qt has taken over the responsibility of painting windows. Adjust the brush may not help.

Have you tried using WS_EX_NOREDIRECTIONBITMAP in window style. In win32 it removes the content which is drawn using WM_PAINT, but since wpf uses directx we get a fully transparent window with system borders and shadow (it's the perfect window) and is used by UWP Apps. (i inspected using spy++). May be Qt can also do the same thing.

wangwenx190 commented 4 years ago

@wangwenx190 did u get flickering while resizing the window on window 10 19042. when i alter the WM_NCCALCSIZE. it flickers one or two times. so i come up with a new way by altering the hbrush of the window class. its perfect and does not flicker at all. In the 1903 build the dwmExtendFrame... creates a 8px margin around window while maximizing. you can fix this issue also by altering the hbrush of window in createwindowex

Thanks for telling me this. Your solution may work well for normal windows, however, things are a lot different in Qt. Qt has taken over the responsibility of painting windows. Adjust the brush may not help.

Have you tried using WS_EX_NOREDIRECTIONBITMAP in window style. In win32 it removes the content which is drawn using WM_PAINT, but since wpf uses directx we get a fully transparent window with system borders and shadow (it's the perfect window) and is used by UWP Apps. (i inspected using spy++). May be Qt can also do the same thing.

Yes I've tried that style once, but it doesn't work for Qt. I still got a normal window, nothing changed. But it does work as expected in pure Win32 projects. I tested it in a normal Win32 window and it become totally transparent indeed. I guess Qt doesn't paint in WM_PAINT.

selastingeorge commented 4 years ago

Go the awkward way. In set window composition attribute insted of ACRYLIC_BLUR_BEHIND use the value as 6(create a new enum value with value as 6). It is same as redirection bitmap....

On Sat, 28 Nov, 2020, 5:05 pm Yuhang Zhao, notifications@github.com wrote:

@wangwenx190 https://github.com/wangwenx190 did u get flickering while resizing the window on window 10 19042. when i alter the WM_NCCALCSIZE. it flickers one or two times. so i come up with a new way by altering the hbrush of the window class. its perfect and does not flicker at all. In the 1903 build the dwmExtendFrame... creates a 8px margin around window while maximizing. you can fix this issue also by altering the hbrush of window in createwindowex

Thanks for telling me this. Your solution may work well for normal windows, however, things are a lot different in Qt. Qt has taken over the responsibility of painting windows. Adjust the brush may not help.

Have you tried using WS_EX_NOREDIRECTIONBITMAP in window style. In win32 it removes the content which is drawn using WM_PAINT, but since wpf uses directx we get a fully transparent window with system borders and shadow (it's the perfect window) and is used by UWP Apps. (i inspected using spy++). May be Qt can also do the same thing.

Yes I've tried that style once, but it doesn't work for Qt. I still got a normal window, nothing changed. But it does work as expected in pure Win32 projects. I tested it in a normal Win32 window and it become totally transparent indeed. I guess Qt doesn't paint in WM_PAINT.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wangwenx190/framelesshelper/issues/27#issuecomment-735220118, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKGWVIZ2CPHB65WUYROI7TSSDN73ANCNFSM4STC7GBQ .

selastingeorge commented 4 years ago

like this : private enum AccentState { ACCENT_DISABLED = 0, ACCENT_ENABLE_GRADIENT = 1, ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, ACCENT_ENABLE_BLURBEHIND = 3, ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, ACCENT_INVALID_STATE = 5, ACCENT_DISABLE_REDIRECTIONBITMAP=6 }

selastingeorge commented 4 years ago

The WS_EX_NOREDIRECTIONBITMAP can only be used with CreateWindowEx(). it won't work while using the SetWindowLong()

JulienMaille commented 3 years ago

Quick update, with latest insider build, moving is still ok while resizing is laggy. The lag when resizing is growing the longer you keep dragging. It really feels like repaint are buffered and processed slower than they are generated. Is there anything that could be done to repaint at a slower rate?

selastingeorge commented 3 years ago

I don't think there is a way until Microsoft release the source for the compositor which is used in windows 10.

On Sun, 13 Dec, 2020, 6:06 pm Julien, notifications@github.com wrote:

Quick update, with latest insider build, moving is still ok while resizing is laggy. The lag when resizing is growing the longer you keep dragging. It really feels like repaint are buffered and processed slower than they are generated. Is there anything that could be done to repaint at a slower rate?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wangwenx190/framelesshelper/issues/27#issuecomment-744001617, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKGWVJWNUPXSTQYNNPB7N3SUSYNXANCNFSM4STC7GBQ .

wangwenx190 commented 3 years ago

I'm not sure whether there's an appropriate workaround or not.

wangwenx190 commented 3 years ago

I prefer waiting for Microsoft to fix the bug officially, although it may be a very long time (and it already is). There are no good workarounds currently in my point of view.

JulienMaille commented 3 years ago

anything interesting in this PR? https://github.com/qt/qtbase/pull/44/files

wangwenx190 commented 3 years ago

anything interesting in this PR? https://github.com/qt/qtbase/pull/44/files

Not quite sure.

JulienMaille commented 3 years ago

Monthly update: got insider build 21292.1000 and resizing is still laggy

selastingeorge commented 3 years ago

They are not going to fix this issue any sooner, because there is already a work around using xaml islands. Like microsoft terminal does

On Thu, 14 Jan, 2021, 2:17 am Julien, notifications@github.com wrote:

Monthly update: got insider build 21292.1000 and resizing is still laggy

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wangwenx190/framelesshelper/issues/27#issuecomment-759729825, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKGWVOXB37VDCPA5KZFRO3SZYBHZANCNFSM4STC7GBQ .

wangwenx190 commented 3 years ago

Monthly update: got insider build 21292.1000 and resizing is still laggy

@JulienMaille Thanks for your information!

They are not going to fix this issue any sooner, because there is already a work around using xaml islands. Like microsoft terminal does

@SelastinGeorge Maybe you are right, but at least the moving is not laggy any more.

selastingeorge commented 3 years ago

You're welcome! ,I am working on new acrylic blur effect which is not laggy check this out: https://youtu.be/V-G8s-ol6p4

On Fri, 15 Jan, 2021, 7:34 am Yuhang Zhao, notifications@github.com wrote:

Monthly update: got insider build 21292.1000 and resizing is still laggy

@JulienMaille https://github.com/JulienMaille Thanks for your information!

They are not going to fix this issue any sooner, because there is already a work around using xaml islands. Like microsoft terminal does

@SelastinGeorge https://github.com/SelastinGeorge Maybe you are right, but at least the moving is not laggy any more.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wangwenx190/framelesshelper/issues/27#issuecomment-760595463, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKGWVPDL3QIZXSNFZWFSFTSZ6PEDANCNFSM4STC7GBQ .

wangwenx190 commented 3 years ago

I am working on new acrylic blur effect which is not laggy check this out: https://youtu.be/V-G8s-ol6p4

@SelastinGeorge It looks quite impressive! How do you achieve that? Is it pure C++ or based on WPF/.NET?

selastingeorge commented 3 years ago

yes its completely working on c++ but i can port it to WPF, it uses direct composition and uses desktop wallpaper as blur input(instead of Host backdrop), later I am going to get the host backdrop using desktop duplication with WDA_EXCLUDEFROMCAPTURE.

Still it's not perfect it in the video above the window is moved along with cursor but if I try dragging the window the blur will start to flicker like this https://youtu.be/bAKCRQdNLjc and that's weird. it is something related to some mathematical calculation I don't know where is the mistake. i have spend a lot of time in it and still no result. now I'm still working on it.

wangwenx190 commented 3 years ago

yes its completely working on c++ but i can port it to WPF, it uses direct composition and uses desktop wallpaper as blur input(instead of Host backdrop), later I am going to get the host backdrop using desktop duplication with WDA_EXCLUDEFROMCAPTURE.

Still it's not perfect it in the video above the window is moved along with cursor but if I try dragging the window the blur will start to flicker like this https://youtu.be/bAKCRQdNLjc and that's weird. it is something related to some mathematical calculation I don't know where is the mistake. i have spend a lot of time in it and still no result. now I'm still working on it.

@SelastinGeorge Thanks for your impressive work! I'm looking forward to your final solution! May I ask will it be open source?

selastingeorge commented 3 years ago

yes of course it will be opensource. I know how hard is to find something like this in internet. I will share the complete source code once it is ready.

selastingeorge commented 3 years ago

but i need more time to fix these issues. till then everyone can use this https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/AcrylicEffect

this one is not laggy anymore.its working fine in my system, i dont have a c++ version of it but i would like to build it

wangwenx190 commented 3 years ago

but i need more time to fix these issues. till then everyone can use this https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/AcrylicEffect

this one is not laggy anymore.its working fine in my system, i dont have a c++ version of it but i would like to build it

I'm afriad of it's using some WPF specific technique to avoid laggy. I would like to help you but sadly I'm not able to convert it to C++.

selastingeorge commented 3 years ago

No it is not using anything from wpf, it's completely built using winrt c++ but they haven't published the code for c++ version.

Winrt is like a new version of direct composition that I used in the demo I showed you.

It's difficult to work with winrt, almost all time the code intellisense of vs2019 is disabled and no suggestions are available.so it shows errors but when compiling it build successfully.

On Fri, 15 Jan, 2021, 10:02 am Yuhang Zhao, notifications@github.com wrote:

but i need more time to fix these issues. till then everyone can use this https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/AcrylicEffect

this one is not laggy anymore.its working fine in my system, i dont have a c++ version of it but i would like to build it

I'm afriad of it's using some WPF specific technique to avoid laggy. I would like to help you but sadly I'm not able to convert it to C++.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wangwenx190/framelesshelper/issues/27#issuecomment-760638388, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKGWVLIJCRYAT2RR5FE2LTSZ7AMXANCNFSM4STC7GBQ .

wangwenx190 commented 3 years ago

Monthly update: got insider build 21292.1000 and resizing is still laggy

@JulienMaille I think we should not count on this undocumented function anymore. Even if Microsoft fixed it some day in the future, it will require a very recent version of Windows 10, which I think is not acceptable. And it's undocumented API after all, it may become unstable or even totally unusable in the future. I think the best solution is to simulate the Acrylic effect ourself. Let's wait for @SelastinGeorge 's great work.

selastingeorge commented 3 years ago

Well i ran into another problem, i was able to build the acrylic effect with best quality and no flicker. Here is the video : https://youtu.be/_SV-s4Q4O1s (in video it flickers because i was capturing using obs and i have less ram, but it doesn't flicker if obs is off)

but the problem is will not be able to draw anything into the window. whatever i draw in window will be overlapped by the blur resulting this :

sample

i know why does this happen but there is no way i could solve this. Actually the acrylic i built is rendered by direct composition and direct composition always draws only at the top of the window.

And i reached another dead end.......

selastingeorge commented 3 years ago

Here is the executable : https://firebasestorage.googleapis.com/v0/b/quizbox-f1bb1.appspot.com/o/Debug.zip?alt=media&token=c34323a4-82d0-4064-b74a-d467bef16a6c

wangwenx190 commented 3 years ago

Here is the executable : https://firebasestorage.googleapis.com/v0/b/quizbox-f1bb1.appspot.com/o/Debug.zip?alt=media&token=c34323a4-82d0-4064-b74a-d467bef16a6c

It's really impressive! But I don't understand why you can't draw anything on that window. Isn't it an official demo provided by Microsoft? If it has such a severe issue, it would have been fixed by MS already.

selastingeorge commented 3 years ago

I have edited their samples and tried out but no luck. The direct composition always draw on top of the window like the dwm thumbnail does.

In uwp they have been drawing everything in window using direct composition so there is no issue. In the case of wpf no luck.

On Thu, 21 Jan, 2021, 7:05 pm Yuhang Zhao, notifications@github.com wrote:

Here is the executable : https://firebasestorage.googleapis.com/v0/b/quizbox-f1bb1.appspot.com/o/Debug.zip?alt=media&token=c34323a4-82d0-4064-b74a-d467bef16a6c

It's really impressive! But I don't understand why you can't draw anything on that window. Isn't it an official demo provided by Microsoft? If it has such a severe issue, it would have been fixed by MS already.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wangwenx190/framelesshelper/issues/27#issuecomment-764646390, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKGWVPZQAWRL7VHTBX5POLS3AUTHANCNFSM4STC7GBQ .

wangwenx190 commented 3 years ago

I have edited their samples and tried out but no luck. The direct composition always draw on top of the window like the dwm thumbnail does. In uwp they have been drawing everything in window using direct composition so there is no issue. In the case of wpf no luck.

Oh, that's too bad!

wangwenx190 commented 3 years ago

@JulienMaille @SelastinGeorge I have bought QtitanRibbon's source code from Developer Machines, and they are achieveing this by acquiring the wallpaper and blurring it, the appearance is not very bad but I think the performance will not be good, and honestly, the appearance is not very good as well. And it has some issues when running on Windows 7. According to the license I can't show you the source code, but it's not much code, they are using Qt Graphic Effect to do this.

selastingeorge commented 3 years ago

In normal win32 I have done this using direct composition and dwmflush() function. It was working well but the problem was windows airspace issue when I use it in another places such as wpf , I won't be able to draw anything on top of the window. Every content is drawn under the window

On Tue, 23 Feb, 2021, 6:26 pm Yuhang Zhao, notifications@github.com wrote:

@JulienMaille https://github.com/JulienMaille @SelastinGeorge https://github.com/SelastinGeorge I have bought QtitanRibbon https://www.devmachines.com/qtitanribbon-overview.html's source code from Developer Machines, and they are achieveing this by acquiring the wallpaper and blurring it, the appearance is not very bad but I think the performance will not be good, and honestly, the appearance is not very good as well. And it has some issues when running on Windows 7. According to the license I can't show you the source code, but it's not much code, they are using Qt Graphic Effect to do this.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wangwenx190/framelesshelper/issues/27#issuecomment-784181929, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKGWVMLJADGI3EKH5CAPX3TAOQYHANCNFSM4STC7GBQ .

wangwenx190 commented 3 years ago

In normal win32 I have done this using direct composition and dwmflush() function. It was working well but the problem was windows airspace issue when I use it in another places such as wpf , I won't be able to draw anything on top of the window. Every content is drawn under the window

Yes I know, you have told me about this.

JulienMaille commented 3 years ago

@JulienMaille @SelastinGeorge I have bought QtitanRibbon's source code from Developer Machines

That's what I call dedication! Too bad it wasn't worth it. Are you still working on an official Qt patch of this repository?

wangwenx190 commented 3 years ago

Too bad it wasn't worth it.

It was not too bad actually. Although their home made acrylic effect is not perfect, I still learned a lot from their source code.

Are you still working on an official Qt patch of this repository?

Yes but the situation now is a bit awkward. In the very beginning, I was trying to introduce a totally new feature called "WindowChrome", I was just adding new stuff to Qt, not modifying any of its original code. It mostly works on Windows because I'm not professional on Linux and macOS. But after some discussions with Qt engineers, I decided to simplify the patch. The reason why we have to write so many code on Windows is we can't use the "Qt::FramelessWindowHint" flag provided by Qt. I tried that flag on Linux KDE and it works fine, the frame shadow is still there, and the animations of windows when they are maximizing or minimizing are preserved as well. So I guess it's a Windows-only issue. The patch now only modified QPA's source code to let Qt::FramelessWindowHint works like other platforms. The code is quite simple, but some unit tests failed so it can't be merged. However I'm not familiar with Qt's unit tests, so the process stuck there.

The patch for Qt: https://codereview.qt-project.org/c/qt/qtbase/+/325649

wangwenx190 commented 3 years ago

@JulienMaille I'm currently working on a private repository to emulate the acrylic effect base on QtitanRibbon's solution. Once it's done, I'll let you know. It's not a simple copy-and-paste so I think there will not be license issues. It's heavily modified to meet my own needs.

PS. It's not perfect indeed, but at least it works, and works on Windows 7 ~ 10. But to get the best appearance, you should use it on Windows 10.

JulienMaille commented 3 years ago

Thanks, yes I'd be happy to see how you can emulate it!

wangwenx190 commented 3 years ago

Thanks, yes I'd be happy to see how you can emulate it!

Good news: making good progress. Bad news: maybe lack support for Linux.

wangwenx190 commented 3 years ago

@JulienMaille @SelastinGeorge The Acrylic Effect has been added to the master branch. You can test it now. Feel free to open new issues if you find anything not correct. It currently only supports Windows 7~10. Support for Linux and macOS may be added later.

selastingeorge commented 3 years ago

@JulienMaille @SelastinGeorge The Acrylic Effect has been added to the master branch. You can test it now. Feel free to open new issues if you find anything not correct. It currently only supports Windows 7~10. Support for Linux and macOS may be added later.

can you please post a link to the exe file of that example. i haven't installed QT

wangwenx190 commented 3 years ago

can you please post a link to the exe file of that example. i haven't installed QT

@SelastinGeorge No problem. But how can I send it to you? I have no access to any Google-related services.

selastingeorge commented 3 years ago

just upload it to any links such as onedrive,dropbox,mediafire any one of them or anyplace where i could download the file