Skip to content

[v3] Fix SetBackgroundColour on Windows - #4492

Merged
leaanthony merged 3 commits into
wailsapp:v3-alphafrom
PPTGamer:v3-alpha
Aug 12, 2025
Merged

leaanthony merged 3 commits into
wailsapp:v3-alphafrom
PPTGamer:v3-alpha

Conversation

@PPTGamer

@PPTGamer PPTGamer commented Aug 10, 2025 •

Copy link
Copy Markdown
Contributor

Description

The SetBackgroundColour() function does not work as expected on Windows.

In v3/pkg/application/webview_window_windows.go, setting the background color is accomplished in setupChromium() and run() by accomplishing two things:

  1. Calling w32.SetBackgroundColour.
  2. Calling chromium.SetBackgroundColour.

However, only the first of these is currently accomplished by windowsWebviewWindow.SetBackgroundColour, which means that runtime calls to SetBackgroundColour do not change the chromium window color.

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.


This was tested by inserting a window.SetBackgroundColour(application.NewRGB(255, 255, 0)) call in the timer goroutine in the default project generated by wails3 init

Test Configuration

 Wails (v3.0.0-dev)  Wails Doctor 

# System 

┌─────────────────────────────────────────────────────────────────────────────────────────────┐
| Name              | Windows 10 Pro                                                          |
| Version           | 2009 (Build: 26100)                                                     |
| ID                | 24H2                                                                    |
| Branding          | Windows 11 Pro                                                          |
| Platform          | windows                                                                 |
| Architecture      | amd64                                                                   |
| Go WebView2Loader | true                                                                    |
| WebView2 Version  | 138.0.3351.121                                                          |
| CPU               | 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz                           |
| GPU 1             | NVIDIA GeForce RTX 3070 Ti (NVIDIA) - Driver: 32.0.15.7700              |
| GPU 2             | Intel(R) UHD Graphics 750 (Intel Corporation) - Driver: 27.20.100.9127  |
| Memory            | 16GB                                                                    |
└─────────────────────────────────────────────────────────────────────────────────────────────┘

# Build Environment 

┌─────────────────────────────────────────────────────────┐
| Wails CLI    | v3.0.0-dev                               |
| Go Version   | go1.24.3                                 |
| Revision     | fdff7e7b21a2c4c12be4d5bb43480542d8670531 |
| Modified     | true                                     |
| -buildmode   | exe                                      |
| -compiler    | gc                                       |
| CGO_CFLAGS   |                                          |
| CGO_CPPFLAGS |                                          |
| CGO_CXXFLAGS |                                          |
| CGO_ENABLED  | 1                                        |
| CGO_LDFLAGS  |                                          |
| GOAMD64      | v1                                       |
| GOARCH       | amd64                                    |
| GOOS         | windows                                  |
| vcs          | git                                      |
| vcs.modified | true                                     |
| vcs.revision | fdff7e7b21a2c4c12be4d5bb43480542d8670531 |
| vcs.time     | 2025-08-10T02:50:53Z                     |
└─────────────────────────────────────────────────────────┘

# Dependencies 

┌────────────────────────────────────────────┐
| npm                        | 10.9.3        |
| NSIS                       | Not Installed |
| MakeAppx.exe (Windows SDK) | Not Installed |
| MSIX Packaging Tool        | Not Installed |
| SignTool.exe (Windows SDK) | Not Installed |
|                                            |
└───────── * - Optional Dependency ──────────┘

# Checking for issues 

 SUCCESS  No issues found

# Diagnosis 

 SUCCESS  Your system is ready for Wails development!

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes

    • Windows: Corrected window background rendering. Solid backgrounds now apply as specified, while transparent/translucent windows render with proper transparency. Fixes SetBackgroundColour behavior and ensures backdrop effects are applied only for translucent backgrounds.
  • Documentation

    • Updated changelog and release notes to reflect the Windows background color fix.
  • Chores

    • Bumped version to v3.0.0-alpha.23.

Update Chromium window color on calls to SetBackgroundColour.
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 10, 2025
@coderabbitai

coderabbitai Bot commented Aug 10, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Consolidates Windows background color logic into setBackgroundColour, updates run() to call it and conditionally apply backdrop for translucent windows. Updates changelog with an unreleased entry, bumps version to v3.0.0-alpha.23, and revises release notes to include a single Windows background fix under “Fixed.”

Changes

Cohort / File(s) Summary
Windows webview background handling
v3/pkg/application/webview_window_windows.go
Centralizes background setting in setBackgroundColour; sets native/Chromium colors for solid backgrounds; forces transparent Chromium background for transparent/translucent; run() now calls setBackgroundColour and only sets backdrop when BackgroundTypeTranslucent.
Changelog update
docs/src/content/docs/changelog.mdx
Adds Unreleased entry v3.0.0-alpha.23 with a Fixed note for Windows SetBackgroundColour.
Version bump
v3/internal/version/version.txt
Increments version from v3.0.0-alpha.22 to v3.0.0-alpha.23.
Release notes revision
v3/release-notes.txt, v3/release_notes.md
Removes prior Added/Changed items; adds single Fixed entry for Windows SetBackgroundColour.

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant WinWindow
  participant NativeWin
  participant Chromium

  App->>WinWindow: run()
  WinWindow->>WinWindow: setBackgroundColour(RGBA, BackgroundType)
  alt BackgroundTypeSolid
    WinWindow->>NativeWin: SetWindowBackground(RGBA)
    WinWindow->>Chromium: SetBackgroundColor(RGBA)
  else Transparent/Translucent
    WinWindow->>Chromium: SetBackgroundColor(0,0,0,0)
  end
  alt BackgroundTypeTranslucent
    WinWindow->>NativeWin: setBackdropType(parentOptions.backdrop)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

Suggested labels

Bug, v3, lgtm

Suggested reviewers

  • leaanthony

Poem

I brushed the panes with hues so bright,
Then learned to fade in moonlit light—
Solid walls or crystal thin,
My backdrop whispers from within.
Hop-hop! A fix on Windows’ view,
Transparent dreams now shining true. 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot Bot added Bug Something isn't working Windows labels Aug 10, 2025
@github-actions github-actions Bot added v3-alpha and removed Bug Something isn't working labels Aug 10, 2025
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Aug 10, 2025

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
v3/pkg/application/webview_window_windows.go (1)

2059-2065: Remove redundant global Chromium background call in setupChromium()

The instance method windowsWebviewWindow.setBackgroundColour already invokes w.chromium.SetBackgroundColour for both solid and transparent/translucent cases. The extra global call immediately afterward is therefore unnecessary and risks a brief override/flicker.

Locations to update:

  • v3/pkg/application/webview_window_windows.go @ lines 2058–2064

Proposed diff:

-	// Set background colour
-	w.setBackgroundColour(w.parent.options.BackgroundColour)
-	chromium.SetBackgroundColour(
-		w.parent.options.BackgroundColour.Red,
-		w.parent.options.BackgroundColour.Green,
-		w.parent.options.BackgroundColour.Blue,
-		w.parent.options.BackgroundColour.Alpha,
-	)
+	// Set background colour (uses single source of truth)
+	w.setBackgroundColour(w.parent.options.BackgroundColour)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fdff7e7 and ff54639.

📒 Files selected for processing (1)
  • v3/pkg/application/webview_window_windows.go (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: APshenkin
PR: wailsapp/wails#4480
File: v2/internal/frontend/desktop/darwin/message.h:17-19
Timestamp: 2025-08-08T09:13:16.884Z
Learning: In Wails v2 bindings origin verification, processBindingMessage intentionally has different signatures across platforms: Darwin includes an isMainFrame bool (WKWebKit provides it), Linux uses two params (message, source) as WebKitGTK doesn’t expose main-frame info there, and Windows handles origin checks in Go via WebView2 sender/args without a C bridge. This divergence is acceptable/expected per maintainer (APshenkin).
📚 Learning: 2024-09-20T23:34:29.841Z
Learnt from: nixpare
PR: wailsapp/wails#3763
File: v3/examples/keybindings/main.go:16-17
Timestamp: 2024-09-20T23:34:29.841Z
Learning: In the codebase, `application.Options.KeyBindings` uses the `application.Window` type, whereas `application.WebviewWindowOptions.KeyBindings` uses `*application.WebviewWindow`. This is intentional and acceptable.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
v3/pkg/application/webview_window_windows.go (1)

483-486: Consolidate background handling and only apply backdrop for Translucent

This aligns run() with the unified logic and avoids applying backdrop effects where they don’t belong. Looks good.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Aug 11, 2025
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
v3/release_notes.md (1)

2-2: Nit: format API name as code

Wrap the API name in backticks for consistency/readability.

-- Fix SetBackgroundColour on Windows by @PPTGamer in [PR](https://github.com/wailsapp/wails/pull/4492)
+- Fix `SetBackgroundColour` on Windows by @PPTGamer in [PR](https://github.com/wailsapp/wails/pull/4492)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ad2dfd and fa6fdea.

📒 Files selected for processing (4)
  • docs/src/content/docs/changelog.mdx (1 hunks)
  • v3/internal/version/version.txt (1 hunks)
  • v3/release-notes.txt (1 hunks)
  • v3/release_notes.md (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • docs/src/content/docs/changelog.mdx
  • v3/internal/version/version.txt
  • v3/release-notes.txt
🔇 Additional comments (1)
v3/release_notes.md (1)

1-2: LGTM — concise and scoped release note

Clear “Fixed” entry with PR link and attribution. Matches the PR scope.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 11, 2025
@leaanthony
leaanthony enabled auto-merge (squash) August 12, 2025 10:45
@leaanthony
leaanthony disabled auto-merge August 12, 2025 10:45
@leaanthony
leaanthony merged commit b7414a4 into wailsapp:v3-alpha Aug 12, 2025
@dosubot dosubot Bot mentioned this pull request Aug 30, 2025
Grantmartin2002 pushed a commit to Grantmartin2002/wails that referenced this pull request Apr 29, 2026
* Fix SetBackgroundColour on Windows

Update Chromium window color on calls to SetBackgroundColour.

* update changelog

* v3.0.0-alpha.23

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@taliesin-ai taliesin-ai added v3 and removed v3-alpha labels Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files. v3 Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants