From 6bdcec81055df8ceea9e75c7b4fb7816fb2c1d56 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 28 Sep 2020 22:08:53 +1000 Subject: [PATCH] WIP: Basics of window drag --- v2/internal/ffenestri/ffenestri_darwin.c | 40 +++++++++++++++--------- v2/test/frameless/main.go | 3 +- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 7f78973a8..14d8a783e 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -97,6 +97,7 @@ struct Application { id wkwebview; id manager; id config; + id mouseEvent; // Window Data const char *title; @@ -213,7 +214,9 @@ void messageHandler(id self, SEL cmd, id contentController, id message) { Show(app); msg(app->config, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 0), str("suppressesIncrementalRendering")); }); - + } else if( strcmp(name, "windowDrag") == 0 ) { + Debug("DRAGGING!!!!!"); + msg(app->mainWindow, s("performWindowDragWithEvent:"), app->mouseEvent); } else { const char *m = (const char *)msg(msg(message, s("body")), s("UTF8String")); app->sendMessageToBackend(m); @@ -571,6 +574,18 @@ void DisableFrame(struct Application *app) app->frame = 0; } +void setMinMaxSize(struct Application *app) +{ + if (app->maxHeight > 0 && app->maxWidth > 0) + { + msg(app->mainWindow, s("setMaxSize:"), CGSizeMake(app->maxWidth, app->maxHeight)); + } + if (app->minHeight > 0 && app->minWidth > 0) + { + msg(app->mainWindow, s("setMinSize:"), CGSizeMake(app->minWidth, app->minHeight)); + } +} + void SetMinWindowSize(struct Application *app, int minWidth, int minHeight) { app->minWidth = minWidth; @@ -628,18 +643,6 @@ void disableBoolConfig(id config, const char *setting) { msg(msg(config, s("preferences")), s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 0), str(setting)); } -void setMinMaxSize(struct Application *app) -{ - if (app->maxHeight > 0 && app->maxWidth > 0) - { - msg(app->mainWindow, s("setMaxSize:"), CGSizeMake(app->maxWidth, app->maxHeight)); - } - if (app->minHeight > 0 && app->minWidth > 0) - { - msg(app->mainWindow, s("setMinSize:"), CGSizeMake(app->minWidth, app->minHeight)); - } -} - void Run(void *applicationPointer, int argc, char **argv) { struct Application *app = (struct Application*) applicationPointer; @@ -730,6 +733,15 @@ void Run(void *applicationPointer, int argc, char **argv) { if( app->frame == 0) { msg(mainWindow, s("setTitlebarAppearsTransparent:"), YES); msg(mainWindow, s("setTitleVisibility:"), NSWindowTitleHidden); + + // Setup drag message handler + msg(manager, s("addScriptMessageHandler:name:"), delegate, str("windowDrag")); + // Add mouse event hooks + // msg(mainWindow, s("mouseDown:"), ^(id event) { + // Debug("Got mouse down event!!!!"); + // app->mouseEvent = event; + // }); + } else { Debug("setTitlebarAppearsTransparent %d", app->titlebarAppearsTransparent ? YES :NO); msg(mainWindow, s("setTitlebarAppearsTransparent:"), app->titlebarAppearsTransparent ? YES : NO); @@ -813,6 +825,4 @@ void Run(void *applicationPointer, int argc, char **argv) { free((void*)internalCode); } - - #endif diff --git a/v2/test/frameless/main.go b/v2/test/frameless/main.go index f20af3749..e8e897b1a 100644 --- a/v2/test/frameless/main.go +++ b/v2/test/frameless/main.go @@ -2,12 +2,13 @@ package main import ( wails "github.com/wailsapp/wails/v2" + "github.com/wailsapp/wails/v2/pkg/options" ) func main() { // Create application with options - app := wails.CreateAppWithOptions(&wails.Options{ + app := wails.CreateAppWithOptions(&options.App{ Title: "Frameless Demo", Width: 1024, Height: 768,