5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 21:10:54 +08:00

[windows-x] Support window drag

This commit is contained in:
Lea Anthony 2021-08-15 20:17:58 +10:00
parent 3ac1dcc8d9
commit de255729e6

View File

@ -3,8 +3,10 @@ package windows
import (
"context"
"encoding/json"
"fmt"
"github.com/jchv/go-webview2/pkg/edge"
"github.com/tadvi/winc"
"github.com/tadvi/winc/w32"
"github.com/wailsapp/wails/v2/internal/binding"
"github.com/wailsapp/wails/v2/internal/frontend"
"github.com/wailsapp/wails/v2/internal/frontend/assetserver"
@ -215,6 +217,13 @@ func (f *Frontend) processRequest(req *edge.ICoreWebView2WebResourceRequest, arg
func (f *Frontend) processMessage(message string) {
println("msg:", message)
if message == "drag" {
err := f.startDrag()
if err != nil {
f.logger.Error(err.Error())
}
return
}
err := f.dispatcher.ProcessMessage(message)
if err != nil {
f.logger.Error(err.Error())
@ -227,6 +236,14 @@ func (f *Frontend) Callback(message string) {
})
}
func (f *Frontend) startDrag() error {
if !w32.ReleaseCapture() {
return fmt.Errorf("unable to release mouse capture")
}
w32.SendMessage(f.mainWindow.Handle(), w32.WM_NCLBUTTONDOWN, w32.HTCAPTION, 0)
return nil
}
func NewFrontend(appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend {
result := &Frontend{