mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-17 01:19:29 +08:00
[v3 windows] Support frameless drag
This commit is contained in:
parent
dc4daaebac
commit
49e62aebe3
@ -51,7 +51,14 @@ function onMouseDown(e) {
|
||||
}
|
||||
|
||||
function onMouseUp(e) {
|
||||
document.body.style.cursor = window.wails.previousCursor || 'auto';
|
||||
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
||||
if (mousePressed > 0) {
|
||||
endDrag();
|
||||
}
|
||||
}
|
||||
|
||||
export function endDrag() {
|
||||
document.body.style.cursor = 'default';
|
||||
shouldDrag = false;
|
||||
}
|
||||
|
||||
@ -60,10 +67,7 @@ function onMouseMove(e) {
|
||||
shouldDrag = false;
|
||||
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
||||
if (mousePressed > 0) {
|
||||
window.wails.previousCursor = document.body.style.cursor;
|
||||
document.body.style.cursor = 'grab';
|
||||
invoke("drag");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ The electron alternative for Go
|
||||
// defined in the Taskfile
|
||||
export let invoke = function(input) {
|
||||
if(WINDOWS) {
|
||||
chrome.external.invoke(input);
|
||||
chrome.webview.postMessage(input);
|
||||
} else {
|
||||
webkit.messageHandlers.external.postMessage(input);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import {dispatchWailsEvent, Emit, Off, OffAll, On, Once, OnMultiple} from "./eve
|
||||
import {dialogCallback, dialogErrorCallback, Error, Info, OpenFile, Question, SaveFile, Warning,} from "./dialogs";
|
||||
import {enableContextMenus} from "./contextmenu";
|
||||
import {reloadWML} from "./wml";
|
||||
import {setupDrag} from "./drag";
|
||||
import {setupDrag, endDrag} from "./drag";
|
||||
|
||||
window.wails = {
|
||||
...newRuntime(null),
|
||||
@ -33,6 +33,7 @@ window._wails = {
|
||||
dispatchWailsEvent,
|
||||
callCallback,
|
||||
callErrorCallback,
|
||||
endDrag,
|
||||
};
|
||||
|
||||
export function newRuntime(windowName) {
|
||||
|
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
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
@ -666,6 +666,17 @@ func invokeSyncWithResult[T any](fn func() T) (res T) {
|
||||
return res
|
||||
}
|
||||
|
||||
func invokeSyncWithError(fn func() error) (err error) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
err = fn()
|
||||
wg.Done()
|
||||
})
|
||||
wg.Wait()
|
||||
return
|
||||
}
|
||||
|
||||
func invokeSyncWithResultAndError[T any](fn func() (T, error)) (res T, err error) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
|
@ -62,6 +62,7 @@ type (
|
||||
setFrameless(bool)
|
||||
openContextMenu(menu *Menu, data *ContextMenuData)
|
||||
nativeWindowHandle() uintptr
|
||||
startDrag() error
|
||||
}
|
||||
)
|
||||
|
||||
@ -437,12 +438,17 @@ func (w *WebviewWindow) SetBackgroundColour(colour RGBA) *WebviewWindow {
|
||||
func (w *WebviewWindow) handleMessage(message string) {
|
||||
w.info(message)
|
||||
// Check for special messages
|
||||
if message == "test" {
|
||||
invokeSync(func() {
|
||||
w.SetTitle("Hello World")
|
||||
})
|
||||
if message == "drag" {
|
||||
if !w.IsFullscreen() {
|
||||
invokeSync(func() {
|
||||
err := w.startDrag()
|
||||
if err != nil {
|
||||
w.error("Failed to start drag: %s", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
w.info("ProcessMessage from front end:", message)
|
||||
w.info("ProcessMessage from front end: %s", message)
|
||||
|
||||
}
|
||||
|
||||
@ -842,3 +848,10 @@ func (w *WebviewWindow) emit(eventType events.WindowEventType) {
|
||||
EventID: uint(eventType),
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) startDrag() error {
|
||||
if w.impl == nil {
|
||||
return nil
|
||||
}
|
||||
return invokeSyncWithError(w.impl.startDrag)
|
||||
}
|
||||
|
@ -1222,3 +1222,8 @@ func (w *macosWebviewWindow) setHTML(html string) {
|
||||
// Render HTML
|
||||
C.windowRenderHTML(w.nsWindow, cHTML)
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) startDrag() error {
|
||||
// Unused - handled by the native code
|
||||
return nil
|
||||
}
|
||||
|
@ -64,6 +64,8 @@ extern bool hasListeners(unsigned int);
|
||||
// Handle script messages from the external bridge
|
||||
- (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
|
||||
NSString *m = message.body;
|
||||
|
||||
// TODO: Standardise drag by sending the drag event back to Go
|
||||
if ( [m isEqualToString:@"drag"] ) {
|
||||
/*
|
||||
if( [self IsFullScreen] ) {
|
||||
|
@ -45,6 +45,15 @@ type windowsWebviewWindow struct {
|
||||
resizeDebouncer func(func())
|
||||
}
|
||||
|
||||
func (w *windowsWebviewWindow) startDrag() error {
|
||||
if !w32.ReleaseCapture() {
|
||||
return fmt.Errorf("unable to release mouse capture")
|
||||
}
|
||||
// Use PostMessage because we don't want to block the caller until dragging has been finished.
|
||||
w32.PostMessage(w.hwnd, w32.WM_NCLBUTTONDOWN, w32.HTCAPTION, 0)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *windowsWebviewWindow) nativeWindowHandle() uintptr {
|
||||
return w.hwnd
|
||||
}
|
||||
@ -660,6 +669,8 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp
|
||||
windowsApp.unregisterWindow(w)
|
||||
case w32.WM_NCLBUTTONDOWN:
|
||||
w32.SetFocus(w.hwnd)
|
||||
case w32.WM_NCLBUTTONUP:
|
||||
|
||||
case w32.WM_MOVE, w32.WM_MOVING:
|
||||
_ = w.chromium.NotifyParentWindowPositionChanged()
|
||||
case w32.WM_SIZE:
|
||||
|
Loading…
Reference in New Issue
Block a user