Skip to content

Commit

Permalink
Allow set window class name via options for Windows (#3828)
Browse files Browse the repository at this point in the history
* Allow set window class name via options

* update changelog
  • Loading branch information
APshenkin authored Oct 20, 2024
1 parent 14cc9ec commit 1b6ed1b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
9 changes: 7 additions & 2 deletions v2/internal/frontend/desktop/windows/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *ope

var dwStyle = w32.WS_OVERLAPPEDWINDOW

winc.RegClassOnlyOnce("wailsWindow")
handle := winc.CreateWindow("wailsWindow", parent, uint(exStyle), uint(dwStyle))
windowClassName := "wailsWindow"
if windowsOptions != nil && windowsOptions.WindowClassName != "" {
windowClassName = windowsOptions.WindowClassName
}

winc.RegClassOnlyOnce(windowClassName)
handle := winc.CreateWindow(windowClassName, parent, uint(exStyle), uint(dwStyle))
result.SetHandle(handle)
winc.RegMsgHandler(result)
result.SetParent(parent)
Expand Down
3 changes: 3 additions & 0 deletions v2/pkg/options/windows/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ type Options struct {

// Configure whether swipe gestures should be enabled
EnableSwipeGestures bool

// Class name for the window. If empty, 'wailsWindow' will be used.
WindowClassName string
}

func DefaultMessages() *Messages {
Expand Down
13 changes: 11 additions & 2 deletions website/docs/reference/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func main() {
// OnResume is called when Windows resumes from low power mode
OnResume: func(),
// Disable GPU hardware acceleration for the webview
WebviewGpuDisabled: false,
WebviewGpuDisabled: false,
// Class name for the window. If empty, 'wailsWindow' will be used.
WindowClassName: "MyWindow",
},
Mac: &mac.Options{
TitleBar: &mac.TitleBar{
Expand Down Expand Up @@ -322,7 +324,7 @@ If not defined, the result is the following in cases where the Handler would hav

:::info

This does not work with vite v5.0.0+ and wails v2 due to changes in vite.
This does not work with vite v5.0.0+ and wails v2 due to changes in vite.
Changes are planned in v3 to support similar functionality under vite v5.0.0+.
If you need this feature, stay with vite v4.0.0+.
See [issue 3240](https://github.com/wailsapp/wails/issues/3240) for details
Expand Down Expand Up @@ -804,6 +806,13 @@ Setting this to `true` will enable swipe gestures for the webview.
Name: EnableSwipeGestures<br/>
Type: `bool`

#### WindowClassName

Class name for the window. If empty, 'wailsWindow' will be used.

Name: WindowClassName<br/>
Type: `string`

### Mac

This defines [Mac specific options](#mac).
Expand Down
3 changes: 3 additions & 0 deletions website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Security` in case of vulnerabilities.

## [Unreleased]
### Added
- Added option to set window class name on Windows. Added in [PR](https://github.com/wailsapp/wails/pull/3828) by @APshenkin

### Fixed
- Fixed cross compilation failed with CGO [PR](https://github.com/wailsapp/wails/pull/3795) by [@fcying](https://github.com/fcying)

Expand Down

0 comments on commit 1b6ed1b

Please sign in to comment.