-
Notifications
You must be signed in to change notification settings - Fork 78
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
How to make window transparent? #73
Comments
Not sure what you're asking. Do you mean semi-transparent? Or do you mean no chrome (title bar, frame, etc.)? If the latter, try SetChromeless(true). |
This isn't something we have on our roadmap. I'll re-open it in case someone wants to implement it. |
This could be useful to make overlays with Chromeless set to true. |
@albertwoo Perhaps an workaround for getting this effect (note that you can't have only the background transparent, just the window as a whole): User32.cs: using System;
using System.Runtime.InteropServices;
namespace HelloPhotino.Vue.Native;
public static class User32
{
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
public const int GWL_EX_STYLE = -20;
public const int LWA_ALPHA = 0x2;
public const int WS_EX_LAYERED = 0x80000;
/// <summary>
/// Makes the entire window of the specified process transparent.
/// </summary>
/// <param name="transparency">Desired transparency, value between 0 (invisible) to 100 (opaque).</param>
public static void SetTransparency(IntPtr windowHandle, int transparency)
{
if (windowHandle == IntPtr.Zero) throw new Exception("Process handle zero");
// Get original window properties
var props = GetWindowLong(windowHandle, GWL_EX_STYLE);
// Add "WS_EX_LAYERED"-flag (required for transparency).
SetWindowLong(windowHandle, GWL_EX_STYLE, props | WS_EX_LAYERED);
// Set transparency
var isSet = SetLayeredWindowAttributes(windowHandle, 0, (byte)Math.Ceiling(255f / 100f * transparency), LWA_ALPHA);
if (!isSet) throw new Exception("Could not set window opacity");
}
} Then somewhere before window.WindowCreated += (s, a) =>
{
User32.SetTransparency(window.WindowHandle, 50);
}; I've been using this technique for windows-terminal-quake, works quite well. |
@flyingpie thank you for your contribution! We will look closer into how to implement this on Linux and macOS. We want to release this functionality for all platforms together to prevent inconsistencies between the different OSs. Your interop code would go into the Photino.Native package and then expose it in the |
any news on this? |
Implementation for transparent window background on Windows: For Linux the follow functions can be used, but we need to configure |
Hi @Andersen27, thank you for your contribution! We pulled your changes from your fork and it will be part our next release. Would you be able to implement this change for Linux as well and create a PR for us? |
@philippjbauer I'll try it soon. I will create draft PR for it. |
For Linux i'm doing something like this: |
@Andersen27 Could you update the repo with the Linux changes? Also, is this on X11, Wayland, or both? |
@flyingpie P.S: I'm not C++ developer, so I could made some stupid mistake. |
@Andersen27 It seems that the issue is with actually calling the function. I've left a couple comments in the native repos. One thing is that I'm not sure what the proper place for that would be, but here's an example where I put the init bit under Maybe @philippjbauer can help? :) |
No description provided.
The text was updated successfully, but these errors were encountered: