mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[runtime] Improve —wails-draggable by starting a drag immediately but only for the first click in a series (#2302)
This removes the sometime lagging experience when starting to drag on Windows. But it's still possible to use double-click events for adding e.g. a WindowToggleMaximise.
This commit is contained in:
@@ -404,7 +404,9 @@ func (f *Frontend) processMessage(message string) {
|
||||
}
|
||||
|
||||
if message == "runtime:ready" {
|
||||
cmd := fmt.Sprintf("window.wails.setCSSDragProperties('%s', '%s');", f.frontendOptions.CSSDragProperty, f.frontendOptions.CSSDragValue)
|
||||
cmd := fmt.Sprintf(
|
||||
"window.wails.setCSSDragProperties('%s', '%s');\n"+
|
||||
"window.wails.flags.deferDragToMouseMove = true;", f.frontendOptions.CSSDragProperty, f.frontendOptions.CSSDragValue)
|
||||
f.ExecJS(cmd)
|
||||
|
||||
if f.frontendOptions.Frameless && f.frontendOptions.DisableResize == false {
|
||||
|
||||
@@ -645,7 +645,6 @@ 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")
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ type Window struct {
|
||||
|
||||
OnSuspend func()
|
||||
OnResume func()
|
||||
dragging bool
|
||||
|
||||
chromium *edge.Chromium
|
||||
}
|
||||
@@ -187,13 +186,6 @@ 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:
|
||||
|
||||
@@ -66,6 +66,7 @@ window.wails = {
|
||||
defaultCursor: null,
|
||||
borderThickness: 6,
|
||||
shouldDrag: false,
|
||||
deferDragToMouseMove: false,
|
||||
cssDragProperty: "--wails-draggable",
|
||||
cssDragValue: "drag",
|
||||
}
|
||||
@@ -84,16 +85,27 @@ if (ENV === 1) {
|
||||
delete window.wailsbindings;
|
||||
}
|
||||
|
||||
window.addEventListener('mouseup', () => {
|
||||
window.wails.flags.shouldDrag = false;
|
||||
});
|
||||
|
||||
let dragTest = function (e) {
|
||||
var val = window.getComputedStyle(e.target).getPropertyValue(window.wails.flags.cssDragProperty);
|
||||
if (val) {
|
||||
val = val.trim();
|
||||
}
|
||||
return val === window.wails.flags.cssDragValue;
|
||||
|
||||
if (val !== window.wails.flags.cssDragValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (e.buttons !== 1) {
|
||||
// Do not start dragging if not the primary button has been clicked.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (e.detail !== 1) {
|
||||
// Do not start dragging if more than once has been clicked, e.g. when double clicking
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
window.wails.setCSSDragProperties = function (property, value) {
|
||||
@@ -117,9 +129,20 @@ window.addEventListener('mousedown', (e) => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
window.wails.flags.shouldDrag = true;
|
||||
if (window.wails.flags.deferDragToMouseMove) {
|
||||
window.wails.flags.shouldDrag = true;
|
||||
} else {
|
||||
e.preventDefault()
|
||||
window.WailsInvoke("drag");
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
window.wails.flags.shouldDrag = false;
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('mouseup', () => {
|
||||
window.wails.flags.shouldDrag = false;
|
||||
});
|
||||
|
||||
function setResize(cursor) {
|
||||
@@ -128,14 +151,14 @@ function setResize(cursor) {
|
||||
}
|
||||
|
||||
window.addEventListener('mousemove', function (e) {
|
||||
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
||||
if(window.wails.flags.shouldDrag && mousePressed <= 0) {
|
||||
window.wails.flags.shouldDrag = false;
|
||||
}
|
||||
|
||||
if (window.wails.flags.shouldDrag) {
|
||||
window.WailsInvoke("drag");
|
||||
return;
|
||||
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
||||
if(mousePressed <= 0) {
|
||||
window.wails.flags.shouldDrag = false;
|
||||
} else {
|
||||
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
Reference in New Issue
Block a user