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:
parent
833b6bdbb8
commit
b6dee773c5
@ -391,6 +391,7 @@ func (f *Frontend) setupChromium() {
|
||||
}
|
||||
chromium.Embed(f.mainWindow.Handle())
|
||||
chromium.Resize()
|
||||
f.mainWindow.chromium = chromium
|
||||
settings, err := chromium.GetSettings()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -572,6 +573,7 @@ func (f *Frontend) Callback(message string) {
|
||||
}
|
||||
|
||||
func (f *Frontend) startDrag() error {
|
||||
f.mainWindow.dragging = true
|
||||
if !w32.ReleaseCapture() {
|
||||
return fmt.Errorf("unable to release mouse capture")
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/go-webview2/pkg/edge"
|
||||
"unsafe"
|
||||
|
||||
"github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/win32"
|
||||
@ -32,6 +33,9 @@ type Window struct {
|
||||
|
||||
OnSuspend func()
|
||||
OnResume func()
|
||||
dragging bool
|
||||
|
||||
chromium *edge.Chromium
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
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:
|
||||
switch wparam {
|
||||
case win32.PBT_APMSUSPEND:
|
||||
@ -176,7 +187,6 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
||||
w.OnResume()
|
||||
}
|
||||
}
|
||||
|
||||
case w32.WM_SETTINGCHANGE:
|
||||
settingChanged := w32.UTF16PtrToString((*uint16)(unsafe.Pointer(lparam)))
|
||||
if settingChanged == "ImmersiveColorSet" {
|
||||
|
@ -63,7 +63,7 @@ window.wails = {
|
||||
enableResize: false,
|
||||
defaultCursor: null,
|
||||
borderThickness: 6,
|
||||
dbClickInterval: 100,
|
||||
shouldDrag: false
|
||||
}
|
||||
};
|
||||
|
||||
@ -78,12 +78,9 @@ if (ENV === 0) {
|
||||
delete window.wailsbindings;
|
||||
}
|
||||
|
||||
var dragTimeOut;
|
||||
var dragLastTime = 0;
|
||||
|
||||
function drag() {
|
||||
window.WailsInvoke("drag");
|
||||
}
|
||||
window.addEventListener('mouseup', () => {
|
||||
window.wails.flags.shouldDrag = false;
|
||||
});
|
||||
|
||||
// Setup drag handler
|
||||
// Based on code from: https://github.com/patr0nus/DeskGap
|
||||
@ -108,13 +105,8 @@ window.addEventListener('mousedown', (e) => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (new Date().getTime() - dragLastTime < window.wails.flags.dbClickInterval) {
|
||||
clearTimeout(dragTimeOut);
|
||||
break;
|
||||
}
|
||||
dragTimeOut = setTimeout(drag, window.wails.flags.dbClickInterval);
|
||||
dragLastTime = new Date().getTime();
|
||||
e.preventDefault();
|
||||
|
||||
window.wails.flags.shouldDrag = true;
|
||||
break;
|
||||
}
|
||||
currentElement = currentElement.parentElement;
|
||||
@ -127,6 +119,10 @@ function setResize(cursor) {
|
||||
}
|
||||
|
||||
window.addEventListener('mousemove', function (e) {
|
||||
if (window.wails.flags.shouldDrag) {
|
||||
window.WailsInvoke("drag");
|
||||
return;
|
||||
}
|
||||
if (!window.wails.flags.enableResize) {
|
||||
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
Loading…
Reference in New Issue
Block a user