mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-17 09:29:30 +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) {
|
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;
|
shouldDrag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,10 +67,7 @@ function onMouseMove(e) {
|
|||||||
shouldDrag = false;
|
shouldDrag = false;
|
||||||
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
||||||
if (mousePressed > 0) {
|
if (mousePressed > 0) {
|
||||||
window.wails.previousCursor = document.body.style.cursor;
|
|
||||||
document.body.style.cursor = 'grab';
|
|
||||||
invoke("drag");
|
invoke("drag");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ The electron alternative for Go
|
|||||||
// defined in the Taskfile
|
// defined in the Taskfile
|
||||||
export let invoke = function(input) {
|
export let invoke = function(input) {
|
||||||
if(WINDOWS) {
|
if(WINDOWS) {
|
||||||
chrome.external.invoke(input);
|
chrome.webview.postMessage(input);
|
||||||
} else {
|
} else {
|
||||||
webkit.messageHandlers.external.postMessage(input);
|
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 {dialogCallback, dialogErrorCallback, Error, Info, OpenFile, Question, SaveFile, Warning,} from "./dialogs";
|
||||||
import {enableContextMenus} from "./contextmenu";
|
import {enableContextMenus} from "./contextmenu";
|
||||||
import {reloadWML} from "./wml";
|
import {reloadWML} from "./wml";
|
||||||
import {setupDrag} from "./drag";
|
import {setupDrag, endDrag} from "./drag";
|
||||||
|
|
||||||
window.wails = {
|
window.wails = {
|
||||||
...newRuntime(null),
|
...newRuntime(null),
|
||||||
@ -33,6 +33,7 @@ window._wails = {
|
|||||||
dispatchWailsEvent,
|
dispatchWailsEvent,
|
||||||
callCallback,
|
callCallback,
|
||||||
callErrorCallback,
|
callErrorCallback,
|
||||||
|
endDrag,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function newRuntime(windowName) {
|
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
|
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) {
|
func invokeSyncWithResultAndError[T any](fn func() (T, error)) (res T, err error) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
@ -62,6 +62,7 @@ type (
|
|||||||
setFrameless(bool)
|
setFrameless(bool)
|
||||||
openContextMenu(menu *Menu, data *ContextMenuData)
|
openContextMenu(menu *Menu, data *ContextMenuData)
|
||||||
nativeWindowHandle() uintptr
|
nativeWindowHandle() uintptr
|
||||||
|
startDrag() error
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -437,12 +438,17 @@ func (w *WebviewWindow) SetBackgroundColour(colour RGBA) *WebviewWindow {
|
|||||||
func (w *WebviewWindow) handleMessage(message string) {
|
func (w *WebviewWindow) handleMessage(message string) {
|
||||||
w.info(message)
|
w.info(message)
|
||||||
// Check for special messages
|
// Check for special messages
|
||||||
if message == "test" {
|
if message == "drag" {
|
||||||
invokeSync(func() {
|
if !w.IsFullscreen() {
|
||||||
w.SetTitle("Hello World")
|
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),
|
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
|
// Render HTML
|
||||||
C.windowRenderHTML(w.nsWindow, cHTML)
|
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
|
// Handle script messages from the external bridge
|
||||||
- (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
|
- (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
|
||||||
NSString *m = message.body;
|
NSString *m = message.body;
|
||||||
|
|
||||||
|
// TODO: Standardise drag by sending the drag event back to Go
|
||||||
if ( [m isEqualToString:@"drag"] ) {
|
if ( [m isEqualToString:@"drag"] ) {
|
||||||
/*
|
/*
|
||||||
if( [self IsFullScreen] ) {
|
if( [self IsFullScreen] ) {
|
||||||
|
@ -45,6 +45,15 @@ type windowsWebviewWindow struct {
|
|||||||
resizeDebouncer func(func())
|
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 {
|
func (w *windowsWebviewWindow) nativeWindowHandle() uintptr {
|
||||||
return w.hwnd
|
return w.hwnd
|
||||||
}
|
}
|
||||||
@ -660,6 +669,8 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp
|
|||||||
windowsApp.unregisterWindow(w)
|
windowsApp.unregisterWindow(w)
|
||||||
case w32.WM_NCLBUTTONDOWN:
|
case w32.WM_NCLBUTTONDOWN:
|
||||||
w32.SetFocus(w.hwnd)
|
w32.SetFocus(w.hwnd)
|
||||||
|
case w32.WM_NCLBUTTONUP:
|
||||||
|
|
||||||
case w32.WM_MOVE, w32.WM_MOVING:
|
case w32.WM_MOVE, w32.WM_MOVING:
|
||||||
_ = w.chromium.NotifyParentWindowPositionChanged()
|
_ = w.chromium.NotifyParentWindowPositionChanged()
|
||||||
case w32.WM_SIZE:
|
case w32.WM_SIZE:
|
||||||
|
Loading…
Reference in New Issue
Block a user