-
Notifications
You must be signed in to change notification settings - Fork 710
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
Proposal: Borderless transparent window background support in apps using WinUI #1247
Comments
This is a very frequent scenario in Win32, We should consider this scenario at least for WinUI Desktop and WinUI XAML Islands. |
Adding a data point, our app (EarTrumpet) requires this functionality. |
Anything we can do to get this out of the freezer? https://github.com/microsoft/microsoft-ui-xaml/projects/4#card-25842420 I believe filling in functionality and API gaps should rank much higher. Frankly, I think it's critical to WinUI 3 XAML adoption. |
Those designs in the tweet look great. |
@riverar this is WinUI 2 backlog, and for WinUI 2 is freezer. When WinUI 3 backlog will be active, we will unfreeze it again. |
@marb2000 Thanks, it's very confusing how we all talk about WinUI 3 shipping soon yet the repository doesn't reflect WinUI 3 status very well. All we have are the community calls, tags, and word on the street right now. |
Can you please give a status update on this? |
We'd also like to see transparent borderless windows in WinUI We want to:
In this picture you can see our product, which is a Windows 10 device with 3 running applications, 2 in yellow and one in red rectangles. Right now it's achieved via hooking into native and undocumented places of ApplicationFrameHost.dll and Windows.UI.Xaml.dll, but we'd like to avoid that. |
This feature is needed for Windows Terminal. microsoft/terminal#603 Having transparent terminal is convenient and expected. |
I became really excited once I realized that WinUI could be used in Desktop applications, though I figured I would run into an obstacle that made it impossible. It didn't take long to find the show stopper; this seems to at least one of them and I am sure there are more. @Alikont would you mind sharing the unpublished workaround you are using? Since the day UWP came out in 2012 I have wanted to migrate a boatload of WPF to a more performant XAML flavor. If it requires unpublished trickory I will do whatever it takes. |
For WinUI Desktop AppsAs simple as this looks, it wasn't as simple to figure out with the information available to us 7/3/2020. I tested this against both 32/64 bit platforms running WinUI Preview 1 with .Net 5.0 preview 6 Disclaimers
|
Currently this is a blocker for my new client's project to use WinUI 3 |
@cnbluefire already sent here a solution for this problem and I have it working without any problems |
Fine, transparency works but click through not (or I don't know how to make it work) Tried with a different workaround project and found this: castorix/WinUI3_SwapChainPanel_Layered#5 |
I have a working click through with topmost too, I can send you the source code tomorrow |
And the last missing piece is working AcrylicBrush with HostBackground source applied to any control, not to whole window... |
That's the last thing which I can't get to work :( |
Thank you! I'm looking forward to this! |
@Pietro228 Could you send me some guidance where should I start? Thank you very much! |
You could use CombineRgn and SetWndowRgn (set for intransparent region) for clickthrough workaround. |
I just added SendInput in the sample, to simulate a click (+ testing IsAlwaysOnTop) |
Hi, sorry, I didn't have time yesterday :( For the transparency I used this project which @castorix sent here: Here's the code for unclickable window which works with @castorix 's project: [DllImport("user32.dll")]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)]
private static extern IntPtr IntSetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)]
private static extern Int32 IntSetWindowLong(IntPtr hWnd, int nIndex, Int32 dwNewLong);
private static int IntPtrToInt32(IntPtr intPtr)
{
return unchecked((int)intPtr.ToInt64());
}
[DllImport("kernel32.dll", EntryPoint = "SetLastError")]
public static extern void SetLastError(int dwErrorCode);
[Flags]
private enum ExtendedWindowStyles
{
// ...
WS_EX_TOOLWINDOW = 0x00000080,
WS_EX_TRANSPARENT = 32
// ...
}
private enum GetWindowLongFields
{
// ...
GWL_EXSTYLE = (-20),
// ...
}
private static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
{
int error = 0;
IntPtr result = IntPtr.Zero;
// Win32 SetWindowLong doesn't clear error on success
SetLastError(0);
if (IntPtr.Size == 4)
{
// use SetWindowLong
Int32 tempResult = IntSetWindowLong(hWnd, nIndex, IntPtrToInt32(dwNewLong));
error = Marshal.GetLastWin32Error();
result = new IntPtr(tempResult);
}
else
{
// use SetWindowLongPtr
result = IntSetWindowLongPtr(hWnd, nIndex, dwNewLong);
error = Marshal.GetLastWin32Error();
}
if ((result == IntPtr.Zero) && (error != 0))
{
throw new System.ComponentModel.Win32Exception(error);
}
return result;
}
// This changes clickability
public static void CaptureMouseClick(this Window window, bool condition)
{
try
{
var hwnd = WindowNative.GetWindowHandle(window);
if (condition)
{
int windowLong = (int)WindowInteropHelper.GetWindowLong(hwnd, (int)GetWindowLongFields.GWL_EXSTYLE);
WindowInteropHelper.SetWindowLong(hwnd, (int)GetWindowLongFields.GWL_EXSTYLE, (IntPtr)(windowLong & -33));
}
else
{
int windowLong = (int)WindowInteropHelper.GetWindowLong(hwnd, (int)GetWindowLongFields.GWL_EXSTYLE);
WindowInteropHelper.SetWindowLong(hwnd, (int)GetWindowLongFields.GWL_EXSTYLE, (IntPtr)(windowLong | (int)ExtendedWindowStyles.WS_EX_TRANSPARENT));
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
} |
Zaznam.2023-09-03.130725.mp4 |
@Pietro228 That's really promising! When should I use the Edit: I see you make a switch for this settings. |
@tibitoth Yes, I switch it in settings |
@Pietro228 @castorix I really appreciate your valuable help. One step is still missing for me. How can I create partially click through windows? It's really frustrating (not because of you) that we need to deal with such a low level APIs. With WPF it would be 4 line of code: <Window
...
Topmost="True"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"> |
@tibitoth Yeah in WPF it's easy, but I don't know how to do it partially because I don't really need this feature :/ |
In the test sample, I have put a Butterfly which has "Click Through" and the other not (with IsHitTestVisible in XAML) |
Have you checked that on a tablet device. The touch input is not stable work with HitTest |
WinUIEx just released an update that makes this super easy using a custom backdrop: https://github.com/dotMorten/WinUIEx/releases/tag/v2.3 |
So it's been four years, has it gone out of the "we know it cannot do what WPF can but why don't you just use WPF" phase? |
Read the previous comment |
I don't understand what you mean. I'm looking for an official support, that's the purpose of creating a ticket here in |
Anyone wants to try the solution from PowerToys? Seems working on my window as a WindowEx subclass. |
For me beneath the call refusing to discard the border.
Is there any restriction as it must be invoked before/after a particular invocation ? Like as me , I emply this specific order;
|
I've been playing around with other people's suggestions. castorix - Your Swapchain solution works out of the box, though enabling _presenter.IsAlwaysOnTop prevents drag selecting content in below windows. Clicks still get through though. Pietro228 I haven't managed to get your code to work, setting condition to true/false has no effect, clicks never pass through. That being said, I love the concept of it extending another window.. dotMorten - TransparentTintBackdrop works, though it doesn't let clicks pass through the window. tibitoth - I feel your pain, WPF was so simple, it's a shame both Winui3 and Avalonia make this so hard to do. |
@AlexanderBlackman Also Castorix's example doesn't truly pass the mouse events such as hover to the background. |
use a TransparentBackdrop for your window.SystemBackdrop then call this method, so you can now click (click on titlebar is not working):
|
Why can't Windows simply provide a copy of the desktop output if we request it, instead of - what seems very janky to me - using an overlapping transparent window? Is there some use that I'm not considering, that couldn't be satisfied by a copy of the output? |
Proposal: Transparent background support in apps using WinUI
Summary
Currently, WPF applications can have a transparent and borderless window while UWP applications cannot have that. Request is to support the creation of transparent borderless apps using WinUI.
Rationale
Scope
Important Notes
This feature could enable designs as shown in this video made by @niels9001 (source tweet).
This is currently not possible, because:
Open Questions
The text was updated successfully, but these errors were encountered: