5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 00:09:56 +08:00

Attempted fix for both drag and doubleclick (#1704)

* Attempted fix for both drag and doubleclick

* Shameful hack for windows doubleclick events

* Handle end of drag

* Remove dbClickInterval
This commit is contained in:
Lea Anthony 2022-08-08 17:27:23 +10:00 committed by GitHub
parent 833b6bdbb8
commit b6dee773c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 34 deletions

View File

@ -391,6 +391,7 @@ func (f *Frontend) setupChromium() {
} }
chromium.Embed(f.mainWindow.Handle()) chromium.Embed(f.mainWindow.Handle())
chromium.Resize() chromium.Resize()
f.mainWindow.chromium = chromium
settings, err := chromium.GetSettings() settings, err := chromium.GetSettings()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -572,6 +573,7 @@ func (f *Frontend) Callback(message string) {
} }
func (f *Frontend) startDrag() error { func (f *Frontend) startDrag() error {
f.mainWindow.dragging = true
if !w32.ReleaseCapture() { if !w32.ReleaseCapture() {
return fmt.Errorf("unable to release mouse capture") return fmt.Errorf("unable to release mouse capture")
} }

View File

@ -3,6 +3,7 @@
package windows package windows
import ( import (
"github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/go-webview2/pkg/edge"
"unsafe" "unsafe"
"github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/win32" "github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/win32"
@ -32,6 +33,9 @@ type Window struct {
OnSuspend func() OnSuspend func()
OnResume func() OnResume func()
dragging bool
chromium *edge.Chromium
} }
func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *operatingsystem.WindowsVersionInfo) *Window { func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *operatingsystem.WindowsVersionInfo) *Window {
@ -165,6 +169,13 @@ func (w *Window) IsVisible() bool {
func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr { func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
switch msg { switch msg {
case w32.WM_EXITSIZEMOVE:
if w.dragging {
w.dragging = false
w.Invoke(func() {
w.chromium.Eval("wails.flags.shouldDrag = false;")
})
}
case win32.WM_POWERBROADCAST: case win32.WM_POWERBROADCAST:
switch wparam { switch wparam {
case win32.PBT_APMSUSPEND: case win32.PBT_APMSUSPEND:
@ -176,7 +187,6 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
w.OnResume() w.OnResume()
} }
} }
case w32.WM_SETTINGCHANGE: case w32.WM_SETTINGCHANGE:
settingChanged := w32.UTF16PtrToString((*uint16)(unsafe.Pointer(lparam))) settingChanged := w32.UTF16PtrToString((*uint16)(unsafe.Pointer(lparam)))
if settingChanged == "ImmersiveColorSet" { if settingChanged == "ImmersiveColorSet" {

View File

@ -63,7 +63,7 @@ window.wails = {
enableResize: false, enableResize: false,
defaultCursor: null, defaultCursor: null,
borderThickness: 6, borderThickness: 6,
dbClickInterval: 100, shouldDrag: false
} }
}; };
@ -78,12 +78,9 @@ if (ENV === 0) {
delete window.wailsbindings; delete window.wailsbindings;
} }
var dragTimeOut; window.addEventListener('mouseup', () => {
var dragLastTime = 0; window.wails.flags.shouldDrag = false;
});
function drag() {
window.WailsInvoke("drag");
}
// Setup drag handler // Setup drag handler
// Based on code from: https://github.com/patr0nus/DeskGap // Based on code from: https://github.com/patr0nus/DeskGap
@ -108,13 +105,8 @@ window.addEventListener('mousedown', (e) => {
break; break;
} }
} }
if (new Date().getTime() - dragLastTime < window.wails.flags.dbClickInterval) {
clearTimeout(dragTimeOut); window.wails.flags.shouldDrag = true;
break;
}
dragTimeOut = setTimeout(drag, window.wails.flags.dbClickInterval);
dragLastTime = new Date().getTime();
e.preventDefault();
break; break;
} }
currentElement = currentElement.parentElement; currentElement = currentElement.parentElement;
@ -127,6 +119,10 @@ function setResize(cursor) {
} }
window.addEventListener('mousemove', function (e) { window.addEventListener('mousemove', function (e) {
if (window.wails.flags.shouldDrag) {
window.WailsInvoke("drag");
return;
}
if (!window.wails.flags.enableResize) { if (!window.wails.flags.enableResize) {
return; return;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long