Skip to content
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

[v2] Can the background be transparent? #1296

Closed
ZeronoFreya opened this issue Mar 29, 2022 · 20 comments
Closed

[v2] Can the background be transparent? #1296

ZeronoFreya opened this issue Mar 29, 2022 · 20 comments
Labels
Enhancement New feature or request TODO The issue is ready to be developed

Comments

@ZeronoFreya
Copy link

ZeronoFreya commented Mar 29, 2022

v2@latest

I can only make the window semi-transparent, but can I make it fully transparent?

I don't know if you understand it, and if not, I can't explain more

System
------
OS:             Windows 10 Home China              // win11
Version:        2009 (Build: 22000)
ID:             21H2
Go Version:     go1.17.6
Platform:       windows
Architecture:   amd64

Dependency      Package Name    Status          Version
----------      ------------    ------          -------
WebView2        N/A             Installed       99.0.1150.55
npm             N/A             Installed       8.3.0
*upx            N/A             Available
*nsis           N/A             Available

I found a way, windows only
Use winapi to modify the window style

import (
"github.com/lxn/win"
)

// other code ...

func (a *App) startup(ctx context.Context) {
    hwnd := win.FindWindow(nil, syscall.StringToUTF16Ptr("Your App Title"))
    win.SetWindowLong(hwnd, win.GWL_EXSTYLE, win.GetWindowLong(hwnd, win.GWL_EXSTYLE)|win.WS_EX_LAYERED)
}

Disable WindowIsTranslucent

@ZeronoFreya ZeronoFreya added the Enhancement New feature or request label Mar 29, 2022
@leaanthony
Copy link
Member

leaanthony commented Mar 29, 2022

Hi! It looks like you are trying to open a ticket but haven't provided enough details.

  • If you are reporting a bug, please provide clear, reproducible steps
  • If you are using v1, use wails issue to report the issue
  • If you are using v2, please include the output of wails doctor

@misitebao
Copy link
Contributor

misitebao commented Mar 30, 2022

@leaanthony
I understand the meaning of this question. At present, the webview part of the Wails application can only be semi-transparent, not fully transparent. He hopes that the webview part can be fully transparent. This is convenient for developers to realize the special-shaped interface in combination with borderless.

@leaanthony
Copy link
Member

It can be fully transparent, but you're not providing any information that the ticket template requests, such as platform.

@misitebao
Copy link
Contributor

I have tested it many times on the windows platform, and it has always been impossible. I originally thought this was intentionally restricted.😂

@leaanthony
Copy link
Member

leaanthony commented Mar 30, 2022

It's possible on Windows just not exposed. It's also supported if you're running windows preview. The problem is, there's no indication on this ticket what OS the poster is talking about.

If you are using v2, please include the output of wails doctor

@ZeronoFreya
Copy link
Author

It's possible on Windows just not exposed. It's also supported if you're running windows preview. The problem is, there's no indication on this ticket what OS the poster is talking about.

If you are using v2, please include the output of wails doctor

It's my fault, I did forget to specify the platform
win11
Please see the question for details

@leaanthony
Copy link
Member

If you are using v2, please include the output of wails doctor

@ZeronoFreya
Copy link
Author

ZeronoFreya commented Apr 6, 2022

If you are using v2, please include the output of wails doctor

I really don't understand what you want, wails doctor I've appended at the end of the question, or do you want to know the version number?

Wails CLI v2.0.0-beta.34

System
------
OS:             Windows 10 Home China
Version:        2009 (Build: 22000)
ID:             21H2
Go Version:     go1.17.6
Platform:       windows
Architecture:   amd64

Dependency      Package Name    Status          Version
----------      ------------    ------          -------
WebView2        N/A             Installed       100.0.1185.29
npm             N/A             Installed       8.3.0
*upx            N/A             Available
*nsis           N/A             Available

@leaanthony leaanthony added this to the v2.5.0 milestone Apr 6, 2022
@NanoNik
Copy link
Contributor

NanoNik commented Jun 12, 2022

I've met the same issue when tried to make my window background transparent. The solution provided in the first post (adding WS_EX_LAYRED) will work only if user have DWM composition enabled, if it is not - window will be invisible.

So before adding WS_EX_LAYRED you should check for composition enabled using DwmIsCompositionEnabled.

My initial goal was to make window borders rounded (on Windows 10 and below), as a workaround for PC's without DWM composition I used SetWindowRgn.

@leaanthony
Copy link
Member

leaanthony commented Jun 14, 2022

@NanoNik Is this something you could consider making a PR for?

@leaanthony leaanthony modified the milestones: v2.5.0, v2.2.0 Jun 22, 2022
@NanoNik
Copy link
Contributor

NanoNik commented Jun 24, 2022

@leaanthony I'll see what I can do with it in a few days

@leaanthony leaanthony added the TODO The issue is ready to be developed label Jul 3, 2022
@leaanthony leaanthony moved this to 🆕 TODO in Wails Backlog Oct 16, 2022
@leaanthony
Copy link
Member

@NanoNik still interested in this?

@NanoNik
Copy link
Contributor

NanoNik commented Oct 23, 2022

@leaanthony Yes, I'm still intrested in this feature, actually I already use somewhat transparent window in production, but on some systems (especially running Windows 7) even with DWM enabled sometimes it's just doesn't work, so I'm not really sure how to fix or debug it. I was able to reproduce it in a VM only with DWM disabled.

@leaanthony leaanthony modified the milestones: v2.2, v2.3.0 Nov 22, 2022
@leaanthony leaanthony removed this from the v2.4.0 milestone Dec 29, 2022
@sohaha
Copy link

sohaha commented Mar 31, 2023

Is it still impossible to achieve transparent windows on Windows?

@claudioluciano
Copy link

any news on the transparent issue?
It's possible to the background be translucid at least ?

@leaanthony
Copy link
Member

This has been implemented for v3. If anyone wants to backport, please raise a PR 👍

@gunter423
Copy link

Hello, we've been able to set full transparency on Windows 10 and Windows 11 with the following code :

import (
"github.com/lxn/win"
)

// other code ...

func (a *App) startup(ctx context.Context) {
    hwnd := win.FindWindow(nil, syscall.StringToUTF16Ptr("Your App Title"))
    win.SetWindowLong(hwnd, win.GWL_EXSTYLE, win.GetWindowLong(hwnd, win.GWL_EXSTYLE)|win.WS_EX_LAYERED)
}

and set this in main.go :

err = wails.Run(&options.App{
...your_options,
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 0},
Windows: &windows.Options{
             WebviewIsTransparent: true,
             WindowIsTranslucent: false,
      }
})

@JadeVane
Copy link

JadeVane commented Aug 6, 2024

I am very happy to see that the effect I want to see is achieved on Windows, but now I want to ask a slightly off-topic question. Can parameters similar to WebviewIsTransparent be implemented on Linux?

The current situation is that only the WindowIsTranslucent parameter is available, so in Linux , either create a window with both background color and shadow, or remove both, which means that if I want to create a window with rounded corners, I can only remove the background color and shadow at the same time, so I need to implement the window shadow effect by myself, but in fact I did not find the parameters to set the window shadow in options.

So I would like to know Are there any plans now to implement the WebviewIsTransparent parameter on Linux as well?

Some necessary information below

# Wails
Version         | v2.9.1
Package Manager | apt   

# System
┌─────────────────────────────────────────────────────────────────────────────────┐
| OS           | Ubuntu                                                           |
| Version      | 22.04                                                            |
| ID           | ubuntu                                                           |
| Go Version   | go1.22.3                                                         |
| Platform     | linux                                                            |
| Architecture | amd64                                                            |
| CPU          | AMD Ryzen 5 PRO 4650U with Radeon Graphics                       |
| GPU          | Renoir (Advanced Micro Devices, Inc. [AMD/ATI]) - Driver: amdgpu |
| Memory       | 23GB                                                             |
└─────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌──────────────────────────────────────────────────────────────────────────┐
| Dependency | Package Name          | Status    | Version                 |
| *docker    | docker.io             | Installed | 24.0.7                  |
| gcc        | build-essential       | Installed | 12.9ubuntu3             |
| libgtk-3   | libgtk-3-dev          | Installed | 3.24.33-1ubuntu2.2      |
| libwebkit  | libwebkit2gtk-4.0-dev | Installed | 2.44.2-0ubuntu0.22.04.1 |
| npm        | npm                   | Installed | 10.5.0                  |
| *nsis      | nsis                  | Available | 3.08-2                  |
| pkg-config | pkg-config            | Installed | 0.29.2                  |
└──────────────────────── * - Optional Dependency ─────────────────────────┘

# Diagnosis
Optional package(s) installation details: 
  - nsis: sudo apt install nsis

@jrtp
Copy link

jrtp commented Aug 18, 2024

Does not work for me, the window is always showing the background color set in main.go without the 0 alpha on windows 11. Is there something else that must be taken care of?

Hello, we've been able to set full transparency on Windows 10 and Windows 11 with the following code :

import (
"github.com/lxn/win"
)

// other code ...

func (a *App) startup(ctx context.Context) {
    hwnd := win.FindWindow(nil, syscall.StringToUTF16Ptr("Your App Title"))
    win.SetWindowLong(hwnd, win.GWL_EXSTYLE, win.GetWindowLong(hwnd, win.GWL_EXSTYLE)|win.WS_EX_LAYERED)
}

and set this in main.go :

err = wails.Run(&options.App{
...your_options,
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 0},
Windows: &windows.Options{
             WebviewIsTransparent: true,
             WindowIsTranslucent: false,
      }
})

@AlexyL
Copy link

AlexyL commented Sep 23, 2024

@jrtp Did you replace "Your App Title" with your actual app title?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request TODO The issue is ready to be developed
Projects
Status: 🆕 TODO
Development

No branches or pull requests

10 participants