mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[v3] Add WindowUnFocus event
This commit is contained in:
+21
-1
@@ -58,4 +58,24 @@ The runtime is located in `v3/internal/runtime`. When the runtime is updated, th
|
||||
|
||||
```shell
|
||||
wails task runtime:build
|
||||
```
|
||||
```
|
||||
|
||||
### Events
|
||||
|
||||
Events are defined in `v3/pkg/events`. When adding a new event, the following steps need to be taken:
|
||||
|
||||
- Add the event to the `events.txt` file
|
||||
- Run `wails task events:generate`
|
||||
|
||||
There are a number of types of events: platform specific application and window events + common events. The common events are useful for cross-platform event handling, but you aren't limited to the "lowest common denominator". You can use the platform specific events if you need to.
|
||||
|
||||
When adding a common event, ensure that the platform specific events are mapped. An example of this is in `window_webview_darwin.go`:
|
||||
|
||||
```go
|
||||
// Translate ShouldClose to common WindowClosing event
|
||||
w.parent.On(events.Mac.WindowShouldClose, func(_ *WindowEventContext) {
|
||||
w.parent.emit(events.Common.WindowClosing)
|
||||
})
|
||||
```
|
||||
|
||||
NOTE: We may try to automate this in the future by adding the mapping to the event definition.
|
||||
@@ -1070,6 +1070,11 @@ func (w *macosWebviewWindow) run() {
|
||||
w.parent.emit(events.Common.WindowClosing)
|
||||
})
|
||||
|
||||
// Translate WindowDidUnfocus to common WindowUnFocus event
|
||||
w.parent.On(events.Mac.WindowDidUnfocus, func(_ *WindowEventContext) {
|
||||
w.parent.emit(events.Common.WindowUnFocus)
|
||||
})
|
||||
|
||||
if w.parent.options.HTML != "" {
|
||||
w.setHTML(w.parent.options.HTML)
|
||||
}
|
||||
|
||||
@@ -735,6 +735,10 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp
|
||||
case w32.WM_CLOSE:
|
||||
w.parent.emit(events.Common.WindowClosing)
|
||||
return 0
|
||||
case w32.WM_KILLFOCUS:
|
||||
w.parent.emit(events.Common.WindowUnFocus)
|
||||
case w32.WM_SETFOCUS:
|
||||
w.parent.emit(events.Common.WindowFocus)
|
||||
case w32.WM_NCLBUTTONDOWN:
|
||||
w32.SetFocus(w.hwnd)
|
||||
case w32.WM_MOVE, w32.WM_MOVING:
|
||||
|
||||
@@ -24,6 +24,7 @@ type commonEvents struct {
|
||||
WindowZoomOut WindowEventType
|
||||
WindowZoomReset WindowEventType
|
||||
WindowFocus WindowEventType
|
||||
WindowUnFocus WindowEventType
|
||||
WindowShow WindowEventType
|
||||
WindowHide WindowEventType
|
||||
WindowDPIChanged WindowEventType
|
||||
@@ -45,9 +46,10 @@ func newCommonEvents() commonEvents {
|
||||
WindowZoomOut: 1165,
|
||||
WindowZoomReset: 1166,
|
||||
WindowFocus: 1167,
|
||||
WindowShow: 1168,
|
||||
WindowHide: 1169,
|
||||
WindowDPIChanged: 1170,
|
||||
WindowUnFocus: 1168,
|
||||
WindowShow: 1169,
|
||||
WindowHide: 1170,
|
||||
WindowDPIChanged: 1171,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,6 +142,7 @@ common:WindowZoomIn
|
||||
common:WindowZoomOut
|
||||
common:WindowZoomReset
|
||||
common:WindowFocus
|
||||
common:WindowUnFocus
|
||||
common:WindowShow
|
||||
common:WindowHide
|
||||
common:WindowDPIChanged
|
||||
|
||||
Reference in New Issue
Block a user