Add option to make the background transparent#2551
Conversation
|
How does this new setting interact with setting the background color, background image, or opacity? |
|
Here's a video demonstrating what it looks like. Works fine for the most part, though I just noticed doesn't seem to have an effect with images when the blur setting is off, will take a look and see what I can do to fix this. EDIT: Fixed with latest commit. |
5d83298 to
418f807
Compare
|
Do you need to check if the transparency setting changed here? LiveSplit/src/LiveSplit.View/View/TimerForm.cs Lines 1556 to 1559 in 4e6afea |
No, it seems to work without that, all that matters is that the background is a Bitmap, that conversion only needs to happen when the image is initially loaded. |
| if (TransparentBackgroundState != value) | ||
| { | ||
| TransparentBackgroundState = value; | ||
| var attributeData = new WindowCompositionAttributeData() | ||
| { | ||
| Attribute = WCA_ACCENT_POLICY, | ||
| Data = value ? AccentPolicyBlurPtr : AccentPolicyDisabledPtr, | ||
| SizeOfData = Marshal.SizeOf(typeof(AccentPolicy)) | ||
| }; | ||
| SetWindowCompositionAttribute(Handle, attributeData); | ||
| } |
There was a problem hiding this comment.
Use unsafe context and do the following:
if (value == _transparentBackground)
{
return;
}
AccentPolicy policy = new()
{
AccentState = value ? ACCENT_ENABLE_BLURBEHIND : ACCENT_DISABLED
};
WindowCompositionAttributeData data = new()
{
Attribute = WCA_ACCENT_POLICY,
Data = &policy,
SizeOfData = sizeof(AccentPolicy)
};
SetWindowCompositionAttribute(Handle, data);
_transparentBackground = value;| private const int ACCENT_ENABLE_BLURBEHIND = 3; | ||
| private const int WCA_ACCENT_POLICY = 19; | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] |
There was a problem hiding this comment.
Structs are sequential in layout by default. Remove this.
| internal struct WindowCompositionAttributeData | ||
| { | ||
| public int Attribute; | ||
| public IntPtr Data; |
| private AccentPolicy AccentPolicyBlur = new() | ||
| { | ||
| AccentState = ACCENT_ENABLE_BLURBEHIND, | ||
| }; | ||
| private static readonly IntPtr AccentPolicyBlurPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(AccentPolicy))); | ||
|
|
||
| private AccentPolicy AccentPolicyDisabled = new() | ||
| { | ||
| AccentState = ACCENT_DISABLED, | ||
| }; | ||
| private static readonly IntPtr AccentPolicyDisabledPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(AccentPolicy))); |
There was a problem hiding this comment.
Do not store these instances. It's not necessary. Please remove this and all code which accesses them.
| } | ||
| } | ||
| } | ||
| private bool TransparentBackgroundState = false; |
There was a problem hiding this comment.
| private bool TransparentBackgroundState = false; | |
| private bool _transparentBackground; |
There was a problem hiding this comment.
I wrote it like that to be consistent with MousePassThroughState later on in the file, which is used in a similar pattern. I can change the name, but the code will be less consistent that way.
There was a problem hiding this comment.
This file shouldn't really be cluttered up with Win32 definitions, those should go into separate files.
There was a problem hiding this comment.
Did this because there were already a lot of Win32 definitions in TimerForm. I'll move the definitions to LiveSplit.View/Model/Win32.cs unless you have a better suggestion.
| private static readonly IntPtr AccentPolicyDisabledPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(AccentPolicy))); | ||
|
|
||
| [DllImport("user32.dll")] | ||
| private static extern int SetWindowCompositionAttribute(IntPtr hWnd, in WindowCompositionAttributeData data); |
There was a problem hiding this comment.
| private static extern int SetWindowCompositionAttribute(IntPtr hWnd, in WindowCompositionAttributeData data); | |
| private static extern int SetWindowCompositionAttribute(nint hWnd, WindowCompositionAttributeData* data); | |
What if the conversion to Bitmap doesn't happen when you initially create the baked background image (because transparency is initially off), and then you enable the transparency setting? (Did you test every combination of settings changing?) |
Oops, forgot about that possibility, will add the check. |
|
@ImAciidz The gray noise you're talking about is barely visible on a game that covers entire screen |
|
It's worth noting that the feature doesn't work at all if transparency effects are disabled in the Windows accessibility settings. |
|
Added full transparency option: https://github.com/aesthet-ic/LiveSplit/releases Edit: Fixed full transparency for Windows 11 22H2+ |
Does your build still work? I found it via reddit post on google, but when I tried dropping the alpha to 0 on the background it did not become transparent. On Windows 11 23h, double checked Transparency Effects are enabled in both Personalization and Accessibility. |
Sorry about that, it should be fixed now. Re-download and enable the now-visible transparency checkboxes in addition to setting a solid color background with 0 alpha. Fixed layout settings UI: https://github.com/aesthet-ic/LiveSplit/releases |
Works great now, thanks. This is so helpful for running single monitor, wish it was built in and you didn't have to maintain a separate branch for it, but I'm glad you do. Much appreciated! |


This adds an option to make the background of LiveSplit transparent + blurred. This allows for the background to appear transparent without the opacity of the text being reduced alongside it. OBS can capture this (without blur) with the Windows 10 window capture method.