Skip to content

app: enable transparent CSD windows on Wayland#170

Open
Rana718 wants to merge 1 commit into
gioui:mainfrom
Rana718:main
Open

app: enable transparent CSD windows on Wayland#170
Rana718 wants to merge 1 commit into
gioui:mainfrom
Rana718:main

Conversation

@Rana718

@Rana718 Rana718 commented Jul 5, 2026

Copy link
Copy Markdown

This patch enables window transparency and compositor-drawn rounded corners
for undecorated (CSD) windows on Wayland.

Changes:

  • Clear framebuffer with transparent black instead of opaque white
  • Skip setting opaque region for CSD windows so compositors can apply
    rounded corners and transparency
  • Call updateOpaqueRegion in setWindowConstraints to apply after options change

Without this, undecorated Gio windows on GNOME/KDE cannot have transparent
backgrounds or compositor-rounded corners because the surface is always
marked fully opaque.

Tested on GNOME 50 (Wayland). Apps can now use Decorated(false) with a
semi-transparent background and get proper rounded corners from the compositor,
matching the behavior of GTK/Qt CSD apps.

Comment thread app/os_wayland.go
Comment on lines +1728 to +1733
if !w.config.Decorated {
// Don't mark CSD windows as opaque so the compositor can apply
// rounded corners and transparency effects.
C.wl_surface_set_opaque_region(w.surf, nil)
return
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why Decorated should controls opqueness. On the one hand, it seems to me a Decorated = true window may be transparent as well. On the other hand, what about Decorated = false windows that are opaque? Will your change incur a cost because the system compositor is forced to blend window content instead of merely copying it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Decorated and transparency are orthogonal concepts — a decorated window might want a transparent background, and an undecorated one might be intentionally opaque (for performance).

A cleaner solution: add a Transparent bool field to Config with a corresponding Transparent(bool) Option, and use that instead of Decorated to control the opaque region. This way apps explicitly opt in, paying the compositor blending cost only when needed, while the default stays opaque (fast path).

Happy to revise the patch with this approach if that direction is acceptable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Transparent(bool) sounds good to me.

Comment thread app/window.go
Comment on lines +210 to +212
// Use transparent clear color to support window transparency and
// compositor-drawn rounded corners on Wayland/macOS.
w.gpu.Clear(color.NRGBA{A: 0x00, R: 0x00, G: 0x00, B: 0x00})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Echoing my comment above, how do you know this is the correct change across all platforms?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right — making the clear color transparent globally is incorrect and could break other platforms.

With the proposed Transparent option approach, the clear color would only be transparent when w.config.Transparent is true, keeping the existing opaque white behavior everywhere else. The window.go change would become:

if w.config.Transparent {
    w.gpu.Clear(color.NRGBA{A: 0x00})
} else {
    w.gpu.Clear(color.NRGBA{A: 0xff, R: 0xff, G: 0xff, B: 0xff})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants