mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
[windows]Better popup menu positioning
This commit is contained in:
parent
1dff481199
commit
b2c43c034f
2 changed files with 22 additions and 1 deletions
|
|
@ -110,6 +110,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- `ServiceStartup` hooks are now invoked when `App.Run` is called, not in `application.New` by [@fbbdev](https://github.com/fbbdev) in [#4066](https://github.com/wailsapp/wails/pull/4066)
|
||||
- `ServiceStartup` errors are now returned from `App.Run` instead of terminating the process by [@fbbdev](https://github.com/fbbdev) in [#4066](https://github.com/wailsapp/wails/pull/4066)
|
||||
- Binding and dialog calls from JS now reject with error objects instead of strings by [@fbbdev](https://github.com/fbbdev) in [#4066](https://github.com/wailsapp/wails/pull/4066)
|
||||
- Improved systray menu positioning on Windows by [@leaanthony](https://github.com/leaanthony)
|
||||
|
||||
## v3.0.0-alpha.9 - 2025-01-13
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package application
|
|||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v3/pkg/w32"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -191,7 +192,26 @@ func (p *Win32Menu) ShowAt(x int, y int) {
|
|||
p.onMenuOpen()
|
||||
}
|
||||
|
||||
if !w32.TrackPopupMenuEx(p.menu, w32.TPM_LEFTALIGN, int32(x), int32(y-5), p.parent, nil) {
|
||||
// Get screen dimensions to determine menu positioning
|
||||
monitor := w32.MonitorFromWindow(p.parent, w32.MONITOR_DEFAULTTONEAREST)
|
||||
var monitorInfo w32.MONITORINFO
|
||||
monitorInfo.CbSize = uint32(unsafe.Sizeof(monitorInfo))
|
||||
if !w32.GetMonitorInfo(monitor, &monitorInfo) {
|
||||
globalApplication.fatal("GetMonitorInfo failed")
|
||||
}
|
||||
|
||||
// Set flags to always position the menu above the cursor
|
||||
menuFlags := uint32(w32.TPM_LEFTALIGN | w32.TPM_BOTTOMALIGN)
|
||||
|
||||
// Check if we're close to the right edge of the screen
|
||||
// If so, right-align the menu with some padding
|
||||
if x > int(monitorInfo.RcWork.Right)-200 { // Assuming 200px as a reasonable menu width
|
||||
menuFlags = uint32(w32.TPM_RIGHTALIGN | w32.TPM_BOTTOMALIGN)
|
||||
// Add a small padding (10px) from the right edge
|
||||
x = int(monitorInfo.RcWork.Right) - 10
|
||||
}
|
||||
|
||||
if !w32.TrackPopupMenuEx(p.menu, menuFlags, int32(x), int32(y), p.parent, nil) {
|
||||
globalApplication.fatal("TrackPopupMenu failed")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue