mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[mac] Fix fullscreen / start fullscreen
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
@property bool alwaysOnTop;
|
@property bool alwaysOnTop;
|
||||||
@property bool startHidden;
|
@property bool startHidden;
|
||||||
|
@property bool startFullscreen;
|
||||||
@property (retain) WailsWindow* mainWindow;
|
@property (retain) WailsWindow* mainWindow;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -26,6 +26,12 @@
|
|||||||
|
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
|
if ( self.startFullscreen ) {
|
||||||
|
NSWindowCollectionBehavior behaviour = [self.mainWindow collectionBehavior];
|
||||||
|
behaviour |= NSWindowCollectionBehaviorFullScreenPrimary;
|
||||||
|
[self.mainWindow setCollectionBehavior:behaviour];
|
||||||
|
[self.mainWindow toggleFullScreen:nil];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#define WindowStartsMinimised 2
|
#define WindowStartsMinimised 2
|
||||||
#define WindowStartsFullscreen 3
|
#define WindowStartsFullscreen 3
|
||||||
|
|
||||||
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug, int windowStartState, int startsHidden);
|
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight);
|
||||||
void Run(void*);
|
void Run(void*);
|
||||||
|
|
||||||
void SetTitle(void* ctx, const char *title);
|
void SetTitle(void* ctx, const char *title);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#import "WailsMenu.h"
|
#import "WailsMenu.h"
|
||||||
#import "WailsMenuItem.h"
|
#import "WailsMenuItem.h"
|
||||||
|
|
||||||
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug, int windowStartState, int startsHidden) {
|
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight) {
|
||||||
|
|
||||||
[NSApplication sharedApplication];
|
[NSApplication sharedApplication];
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ WailsContext* Create(const char* title, int width, int height, int frameless, in
|
|||||||
fullscreen = 1;
|
fullscreen = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
[result CreateWindow:width :height :frameless :resizable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent];
|
[result CreateWindow:width :height :frameless :resizable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent :minWidth :minHeight :maxWidth :maxHeight];
|
||||||
[result SetTitle:safeInit(title)];
|
[result SetTitle:safeInit(title)];
|
||||||
[result Center];
|
[result Center];
|
||||||
|
|
||||||
@@ -41,6 +41,10 @@ WailsContext* Create(const char* title, int width, int height, int frameless, in
|
|||||||
result.startHidden = true;
|
result.startHidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( fullscreen == 1 ) {
|
||||||
|
result.startFullscreen = true;
|
||||||
|
}
|
||||||
|
|
||||||
result.alwaysOnTop = alwaysOnTop;
|
result.alwaysOnTop = alwaysOnTop;
|
||||||
result.hideOnClose = hideWindowOnClose;
|
result.hideOnClose = hideWindowOnClose;
|
||||||
|
|
||||||
@@ -324,6 +328,7 @@ void Run(void *inctx) {
|
|||||||
delegate.mainWindow = ctx.mainWindow;
|
delegate.mainWindow = ctx.mainWindow;
|
||||||
delegate.alwaysOnTop = ctx.alwaysOnTop;
|
delegate.alwaysOnTop = ctx.alwaysOnTop;
|
||||||
delegate.startHidden = ctx.startHidden;
|
delegate.startHidden = ctx.startHidden;
|
||||||
|
delegate.startFullscreen = ctx.startFullscreen;
|
||||||
|
|
||||||
[ctx loadRequest:@"wails://wails/"];
|
[ctx loadRequest:@"wails://wails/"];
|
||||||
[app setMainMenu:ctx.applicationMenu];
|
[app setMainMenu:ctx.applicationMenu];
|
||||||
|
|||||||
@@ -19,7 +19,13 @@
|
|||||||
#define unicode(input) [NSString stringWithFormat:@"%C", input]
|
#define unicode(input) [NSString stringWithFormat:@"%C", input]
|
||||||
|
|
||||||
@interface WailsWindow : NSWindow
|
@interface WailsWindow : NSWindow
|
||||||
- (BOOL)canBecomeKeyWindow;
|
|
||||||
|
@property NSSize userMinSize;
|
||||||
|
@property NSSize userMaxSize;
|
||||||
|
|
||||||
|
- (BOOL) canBecomeKeyWindow;
|
||||||
|
- (void) applyWindowConstraints;
|
||||||
|
- (void) disableWindowConstraints;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface WailsContext : NSObject <WKURLSchemeHandler,WKScriptMessageHandler,WKNavigationDelegate>
|
@interface WailsContext : NSObject <WKURLSchemeHandler,WKScriptMessageHandler,WKNavigationDelegate>
|
||||||
@@ -31,9 +37,7 @@
|
|||||||
@property bool hideOnClose;
|
@property bool hideOnClose;
|
||||||
@property bool shuttingDown;
|
@property bool shuttingDown;
|
||||||
@property bool startHidden;
|
@property bool startHidden;
|
||||||
|
@property bool startFullscreen;
|
||||||
@property NSSize maxSize;
|
|
||||||
@property NSSize minSize;
|
|
||||||
|
|
||||||
@property (retain) NSEvent* mouseEvent;
|
@property (retain) NSEvent* mouseEvent;
|
||||||
|
|
||||||
@@ -50,7 +54,7 @@
|
|||||||
@property (retain) NSString* aboutTitle;
|
@property (retain) NSString* aboutTitle;
|
||||||
@property (retain) NSString* aboutDescription;
|
@property (retain) NSString* aboutDescription;
|
||||||
|
|
||||||
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent;
|
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight;
|
||||||
- (void) SetSize:(int)width :(int)height;
|
- (void) SetSize:(int)width :(int)height;
|
||||||
- (void) SetPosition:(int)x :(int) y;
|
- (void) SetPosition:(int)x :(int) y;
|
||||||
- (void) SetMinSize:(int)minWidth :(int)minHeight;
|
- (void) SetMinSize:(int)minWidth :(int)minHeight;
|
||||||
|
|||||||
@@ -21,6 +21,16 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) applyWindowConstraints {
|
||||||
|
[self setMinSize:self.userMinSize];
|
||||||
|
[self setMaxSize:self.userMaxSize];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) disableWindowConstraints {
|
||||||
|
[self setMinSize:NSMakeSize(0, 0)];
|
||||||
|
[self setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation WailsContext
|
@implementation WailsContext
|
||||||
@@ -33,7 +43,7 @@
|
|||||||
frame.origin.y += frame.size.height - height;
|
frame.origin.y += frame.size.height - height;
|
||||||
frame.size.width = width;
|
frame.size.width = width;
|
||||||
frame.size.height = height;
|
frame.size.height = height;
|
||||||
ON_MAIN_THREAD([self.mainWindow setFrame:frame display:TRUE animate:FALSE];);
|
[self.mainWindow setFrame:frame display:TRUE animate:FALSE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) SetPosition:(int)x :(int)y {
|
- (void) SetPosition:(int)x :(int)y {
|
||||||
@@ -45,8 +55,8 @@
|
|||||||
NSRect screenFrame = [screen frame];
|
NSRect screenFrame = [screen frame];
|
||||||
windowFrame.origin.x = screenFrame.origin.x + (float)x;
|
windowFrame.origin.x = screenFrame.origin.x + (float)x;
|
||||||
windowFrame.origin.y = (screenFrame.origin.y + screenFrame.size.height) - windowFrame.size.height - (float)y;
|
windowFrame.origin.y = (screenFrame.origin.y + screenFrame.size.height) - windowFrame.size.height - (float)y;
|
||||||
|
|
||||||
ON_MAIN_THREAD([self.mainWindow setFrame:windowFrame display:TRUE animate:FALSE]; );
|
[self.mainWindow setFrame:windowFrame display:TRUE animate:FALSE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) SetMinSize:(int)minWidth :(int)minHeight {
|
- (void) SetMinSize:(int)minWidth :(int)minHeight {
|
||||||
@@ -54,13 +64,9 @@
|
|||||||
if (self.shuttingDown) return;
|
if (self.shuttingDown) return;
|
||||||
|
|
||||||
NSSize size = { minWidth, minHeight };
|
NSSize size = { minWidth, minHeight };
|
||||||
|
self.mainWindow.userMinSize = size;
|
||||||
self.minSize = size;
|
[self.mainWindow setMinSize:size];
|
||||||
|
[self adjustWindowSize];
|
||||||
ON_MAIN_THREAD(
|
|
||||||
[self.mainWindow setMinSize:size];
|
|
||||||
[self adjustWindowSize];
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -73,12 +79,9 @@
|
|||||||
size.width = maxWidth > 0 ? maxWidth : FLT_MAX;
|
size.width = maxWidth > 0 ? maxWidth : FLT_MAX;
|
||||||
size.height = maxHeight > 0 ? maxHeight : FLT_MAX;
|
size.height = maxHeight > 0 ? maxHeight : FLT_MAX;
|
||||||
|
|
||||||
self.maxSize = size;
|
self.mainWindow.userMaxSize = size;
|
||||||
|
[self.mainWindow setMaxSize:size];
|
||||||
ON_MAIN_THREAD(
|
[self adjustWindowSize];
|
||||||
[self.mainWindow setMaxSize:size];
|
|
||||||
[self adjustWindowSize];
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -88,10 +91,10 @@
|
|||||||
|
|
||||||
NSRect currentFrame = [self.mainWindow frame];
|
NSRect currentFrame = [self.mainWindow frame];
|
||||||
|
|
||||||
if ( currentFrame.size.width > self.maxSize.width ) currentFrame.size.width = self.maxSize.width;
|
if ( currentFrame.size.width > self.mainWindow.userMaxSize.width ) currentFrame.size.width = self.mainWindow.userMaxSize.width;
|
||||||
if ( currentFrame.size.width < self.minSize.width ) currentFrame.size.width = self.minSize.width;
|
if ( currentFrame.size.width < self.mainWindow.userMinSize.width ) currentFrame.size.width = self.mainWindow.userMinSize.width;
|
||||||
if ( currentFrame.size.height > self.maxSize.height ) currentFrame.size.height = self.maxSize.height;
|
if ( currentFrame.size.height > self.mainWindow.userMaxSize.height ) currentFrame.size.height = self.mainWindow.userMaxSize.height;
|
||||||
if ( currentFrame.size.height < self.minSize.height ) currentFrame.size.height = self.minSize.height;
|
if ( currentFrame.size.height < self.mainWindow.userMinSize.height ) currentFrame.size.height = self.mainWindow.userMinSize.height;
|
||||||
|
|
||||||
[self.mainWindow setFrame:currentFrame display:YES animate:FALSE];
|
[self.mainWindow setFrame:currentFrame display:YES animate:FALSE];
|
||||||
|
|
||||||
@@ -116,11 +119,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void) SetTitle:(NSString*)title {
|
- (void) SetTitle:(NSString*)title {
|
||||||
ON_MAIN_THREAD([self.mainWindow setTitle:title];)
|
[self.mainWindow setTitle:title];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) Center {
|
- (void) Center {
|
||||||
ON_MAIN_THREAD( [self.mainWindow center]; );
|
[self.mainWindow center];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isFullscreen {
|
- (BOOL) isFullscreen {
|
||||||
@@ -131,37 +134,29 @@
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString*)appearance :(bool)windowIsTranslucent {
|
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString*)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight {
|
||||||
|
|
||||||
self.urlRequests = [NSMutableDictionary new];
|
self.urlRequests = [NSMutableDictionary new];
|
||||||
|
|
||||||
NSWindowStyleMask styleMask = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable;
|
NSWindowStyleMask styleMask = 0;
|
||||||
|
|
||||||
if (frameless) {
|
if( !frameless ) {
|
||||||
styleMask = NSWindowStyleMaskBorderless;
|
|
||||||
titlebarAppearsTransparent = true;
|
|
||||||
hideTitle = true;
|
|
||||||
} else {
|
|
||||||
if (!hideTitleBar) {
|
if (!hideTitleBar) {
|
||||||
styleMask |= NSWindowStyleMaskTitled;
|
styleMask |= NSWindowStyleMaskTitled;
|
||||||
}
|
}
|
||||||
|
styleMask |= NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable;
|
||||||
if (fullscreen) {
|
|
||||||
styleMask |= NSWindowStyleMaskFullScreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( fullSizeContent || frameless || titlebarAppearsTransparent ) {
|
|
||||||
styleMask |= NSWindowStyleMaskFullSizeContentView;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( fullSizeContent || frameless || titlebarAppearsTransparent ) {
|
||||||
|
styleMask |= NSWindowStyleMaskFullSizeContentView;
|
||||||
|
}
|
||||||
|
|
||||||
if (resizable) {
|
if (resizable) {
|
||||||
styleMask |= NSWindowStyleMaskResizable;
|
styleMask |= NSWindowStyleMaskResizable;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.mainWindow = [[[WailsWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
|
self.mainWindow = [[WailsWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
|
||||||
styleMask:styleMask backing:NSBackingStoreBuffered defer:NO]
|
styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
|
||||||
autorelease];
|
|
||||||
|
|
||||||
if (!frameless && useToolbar) {
|
if (!frameless && useToolbar) {
|
||||||
id toolbar = [[NSToolbar alloc] initWithIdentifier:@"wails.toolbar"];
|
id toolbar = [[NSToolbar alloc] initWithIdentifier:@"wails.toolbar"];
|
||||||
@@ -192,15 +187,25 @@
|
|||||||
[self.mainWindow setAppearance:nsAppearance];
|
[self.mainWindow setAppearance:nsAppearance];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up min/max
|
|
||||||
NSSize maxSize = { FLT_MAX, FLT_MAX };
|
NSSize minSize = { minWidth, minHeight };
|
||||||
self.maxSize = maxSize;
|
NSSize maxSize = { maxWidth, maxHeight };
|
||||||
NSSize minSize = { 0, 0 };
|
if (maxSize.width == 0) {
|
||||||
self.minSize = minSize;
|
maxSize.width = FLT_MAX;
|
||||||
[self adjustWindowSize];
|
}
|
||||||
|
if (maxSize.height == 0) {
|
||||||
|
maxSize.height = FLT_MAX;
|
||||||
|
}
|
||||||
|
self.mainWindow.userMaxSize = maxSize;
|
||||||
|
self.mainWindow.userMinSize = minSize;
|
||||||
|
|
||||||
|
if( !fullscreen ) {
|
||||||
|
[self.mainWindow applyWindowConstraints];
|
||||||
|
}
|
||||||
|
|
||||||
WindowDelegate *windowDelegate = [WindowDelegate new];
|
WindowDelegate *windowDelegate = [WindowDelegate new];
|
||||||
windowDelegate.hideOnClose = hideWindowOnClose;
|
windowDelegate.hideOnClose = hideWindowOnClose;
|
||||||
|
windowDelegate.ctx = self;
|
||||||
[self.mainWindow setDelegate:windowDelegate];
|
[self.mainWindow setDelegate:windowDelegate];
|
||||||
|
|
||||||
// Webview stuff here!
|
// Webview stuff here!
|
||||||
@@ -301,7 +306,7 @@
|
|||||||
|
|
||||||
id colour = [NSColor colorWithCalibratedRed:red green:green blue:blue alpha:alpha ];
|
id colour = [NSColor colorWithCalibratedRed:red green:green blue:blue alpha:alpha ];
|
||||||
|
|
||||||
ON_MAIN_THREAD([self.mainWindow setBackgroundColor:colour];);
|
[self.mainWindow setBackgroundColor:colour];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) HideMouse {
|
- (void) HideMouse {
|
||||||
@@ -325,52 +330,50 @@
|
|||||||
// Fullscreen sets the main window to be fullscreen
|
// Fullscreen sets the main window to be fullscreen
|
||||||
- (void) Fullscreen {
|
- (void) Fullscreen {
|
||||||
if( ! [self isFullScreen] ) {
|
if( ! [self isFullScreen] ) {
|
||||||
ON_MAIN_THREAD([self.mainWindow toggleFullScreen:nil];)
|
[self.mainWindow disableWindowConstraints];
|
||||||
|
[self.mainWindow toggleFullScreen:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnFullscreen resets the main window after a fullscreen
|
// UnFullscreen resets the main window after a fullscreen
|
||||||
- (void) UnFullscreen {
|
- (void) UnFullscreen {
|
||||||
if( [self isFullScreen] ) {
|
if( [self isFullScreen] ) {
|
||||||
ON_MAIN_THREAD([self.mainWindow toggleFullScreen:nil];)
|
[self.mainWindow applyWindowConstraints];
|
||||||
|
[self.mainWindow toggleFullScreen:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) Minimise {
|
- (void) Minimise {
|
||||||
ON_MAIN_THREAD([self.mainWindow miniaturize:nil];)
|
[self.mainWindow miniaturize:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) UnMinimise {
|
- (void) UnMinimise {
|
||||||
ON_MAIN_THREAD([self.mainWindow deminiaturize:nil];)
|
[self.mainWindow deminiaturize:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) Hide {
|
- (void) Hide {
|
||||||
ON_MAIN_THREAD([self.mainWindow orderOut:nil];)
|
[self.mainWindow orderOut:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) Show {
|
- (void) Show {
|
||||||
ON_MAIN_THREAD(
|
[self.mainWindow makeKeyAndOrderFront:nil];
|
||||||
[self.mainWindow makeKeyAndOrderFront:nil];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) Maximise {
|
- (void) Maximise {
|
||||||
if (![self.mainWindow isZoomed]) {
|
if (![self.mainWindow isZoomed]) {
|
||||||
ON_MAIN_THREAD([self.mainWindow zoom:nil];)
|
[self.mainWindow zoom:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) UnMaximise {
|
- (void) UnMaximise {
|
||||||
if ([self.mainWindow isZoomed]) {
|
if ([self.mainWindow isZoomed]) {
|
||||||
ON_MAIN_THREAD([self.mainWindow zoom:nil];)
|
[self.mainWindow zoom:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) ExecJS:(NSString*)script {
|
- (void) ExecJS:(NSString*)script {
|
||||||
ON_MAIN_THREAD(
|
[self.webview evaluateJavaScript:script completionHandler:nil];
|
||||||
[self.webview evaluateJavaScript:script completionHandler:nil];
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) processURLResponse:(NSString *)url :(NSString *)contentType :(NSData *)data {
|
- (void) processURLResponse:(NSString *)url :(NSString *)contentType :(NSData *)data {
|
||||||
@@ -406,15 +409,13 @@
|
|||||||
|
|
||||||
// Check for drag
|
// Check for drag
|
||||||
if ( [m isEqualToString:@"drag"] ) {
|
if ( [m isEqualToString:@"drag"] ) {
|
||||||
if( ! [self isFullScreen] ) {
|
if( [self isFullScreen] ) {
|
||||||
if( self.mouseEvent != nil ) {
|
|
||||||
[self HideMouse];
|
|
||||||
ON_MAIN_THREAD(
|
|
||||||
[self.mainWindow performWindowDragWithEvent:self.mouseEvent];
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if( self.mouseEvent != nil ) {
|
||||||
|
[self.mainWindow performWindowDragWithEvent:self.mouseEvent];
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *_m = [m UTF8String];
|
const char *_m = [m UTF8String];
|
||||||
@@ -455,28 +456,26 @@
|
|||||||
NSData *imageData = [NSData dataWithBytes:iconData length:iconDataLength];
|
NSData *imageData = [NSData dataWithBytes:iconData length:iconDataLength];
|
||||||
icon = [[NSImage alloc] initWithData:imageData];
|
icon = [[NSImage alloc] initWithData:imageData];
|
||||||
}
|
}
|
||||||
ON_MAIN_THREAD(
|
if( icon != nil) {
|
||||||
if( icon != nil) {
|
[alert setIcon:icon];
|
||||||
[alert setIcon:icon];
|
}
|
||||||
}
|
[alert.window setLevel:NSFloatingWindowLevel];
|
||||||
[alert.window setLevel:NSFloatingWindowLevel];
|
|
||||||
|
|
||||||
long response = [alert runModal];
|
long response = [alert runModal];
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if( response == NSAlertFirstButtonReturn ) {
|
if( response == NSAlertFirstButtonReturn ) {
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
else if( response == NSAlertSecondButtonReturn ) {
|
else if( response == NSAlertSecondButtonReturn ) {
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
else if( response == NSAlertThirdButtonReturn ) {
|
else if( response == NSAlertThirdButtonReturn ) {
|
||||||
result = 2;
|
result = 2;
|
||||||
} else {
|
} else {
|
||||||
result = 3;
|
result = 3;
|
||||||
}
|
}
|
||||||
processMessageDialogResponse(result);
|
processMessageDialogResponse(result);
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void) OpenFileDialog :(NSString*)title :(NSString*)defaultFilename :(NSString*)defaultDirectory :(bool)allowDirectories :(bool)allowFiles :(bool)canCreateDirectories :(bool)treatPackagesAsDirectories :(bool)resolveAliases :(bool)showHiddenFiles :(bool)allowMultipleSelection :(NSString*)filters {
|
-(void) OpenFileDialog :(NSString*)title :(NSString*)defaultFilename :(NSString*)defaultDirectory :(bool)allowDirectories :(bool)allowFiles :(bool)canCreateDirectories :(bool)treatPackagesAsDirectories :(bool)resolveAliases :(bool)showHiddenFiles :(bool)allowMultipleSelection :(NSString*)filters {
|
||||||
@@ -622,8 +621,7 @@
|
|||||||
[alert setIcon:self.aboutImage];
|
[alert setIcon:self.aboutImage];
|
||||||
}
|
}
|
||||||
|
|
||||||
ON_MAIN_THREAD([alert runModal];)
|
[alert runModal];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -8,10 +8,17 @@
|
|||||||
#ifndef WindowDelegate_h
|
#ifndef WindowDelegate_h
|
||||||
#define WindowDelegate_h
|
#define WindowDelegate_h
|
||||||
|
|
||||||
|
#import "WailsContext.h"
|
||||||
|
|
||||||
@interface WindowDelegate : NSObject <NSWindowDelegate>
|
@interface WindowDelegate : NSObject <NSWindowDelegate>
|
||||||
|
|
||||||
@property bool hideOnClose;
|
@property bool hideOnClose;
|
||||||
|
|
||||||
|
@property (assign) WailsContext* ctx;
|
||||||
|
|
||||||
|
- (void)windowDidExitFullScreen:(NSNotification *)notification;
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,4 +21,18 @@
|
|||||||
return !self.hideOnClose;
|
return !self.hideOnClose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)windowDidExitFullScreen:(NSNotification *)notification {
|
||||||
|
[self.ctx.mainWindow applyWindowConstraints];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)windowWillEnterFullScreen:(NSNotification *)notification {
|
||||||
|
[self.ctx.mainWindow disableWindowConstraints];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSApplicationPresentationOptions)window:(WailsWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions {
|
||||||
|
return NSApplicationPresentationAutoHideToolbar | NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationFullScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -51,11 +51,10 @@ type Frontend struct {
|
|||||||
assets *assetserver.DesktopAssetServer
|
assets *assetserver.DesktopAssetServer
|
||||||
|
|
||||||
// main window handle
|
// main window handle
|
||||||
mainWindow *Window
|
mainWindow *Window
|
||||||
minWidth, minHeight, maxWidth, maxHeight int
|
bindings *binding.Bindings
|
||||||
bindings *binding.Bindings
|
dispatcher frontend.Dispatcher
|
||||||
dispatcher frontend.Dispatcher
|
servingFromDisk bool
|
||||||
servingFromDisk bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend {
|
func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend {
|
||||||
@@ -163,15 +162,11 @@ func (f *Frontend) WindowSetTitle(title string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) WindowFullscreen() {
|
func (f *Frontend) WindowFullscreen() {
|
||||||
f.mainWindow.SetMaxSize(0, 0)
|
|
||||||
f.mainWindow.SetMinSize(0, 0)
|
|
||||||
f.mainWindow.Fullscreen()
|
f.mainWindow.Fullscreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) WindowUnFullscreen() {
|
func (f *Frontend) WindowUnFullscreen() {
|
||||||
f.mainWindow.UnFullscreen()
|
f.mainWindow.UnFullscreen()
|
||||||
f.mainWindow.SetMaxSize(f.maxWidth, f.maxHeight)
|
|
||||||
f.mainWindow.SetMinSize(f.minWidth, f.minHeight)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) WindowShow() {
|
func (f *Frontend) WindowShow() {
|
||||||
@@ -195,13 +190,9 @@ func (f *Frontend) WindowUnminimise() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) WindowSetMinSize(width int, height int) {
|
func (f *Frontend) WindowSetMinSize(width int, height int) {
|
||||||
f.minWidth = width
|
|
||||||
f.minHeight = height
|
|
||||||
f.mainWindow.SetMinSize(width, height)
|
f.mainWindow.SetMinSize(width, height)
|
||||||
}
|
}
|
||||||
func (f *Frontend) WindowSetMaxSize(width int, height int) {
|
func (f *Frontend) WindowSetMaxSize(width int, height int) {
|
||||||
f.maxWidth = width
|
|
||||||
f.maxHeight = height
|
|
||||||
f.mainWindow.SetMaxSize(width, height)
|
f.mainWindow.SetMaxSize(width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,6 +234,11 @@ func (f *Frontend) processMessage(message string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if strings.HasPrefix(message, "systemevent:") {
|
||||||
|
// f.processSystemEvent(message)
|
||||||
|
// return
|
||||||
|
//}
|
||||||
|
|
||||||
result, err := f.dispatcher.ProcessMessage(message, f)
|
result, err := f.dispatcher.ProcessMessage(message, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.logger.Error(err.Error())
|
f.logger.Error(err.Error())
|
||||||
@@ -292,6 +288,22 @@ func (f *Frontend) processRequest(r *request) {
|
|||||||
C.ProcessURLResponse(r.ctx, r.url, mimetype, data, C.int(len(_contents)))
|
C.ProcessURLResponse(r.ctx, r.url, mimetype, data, C.int(len(_contents)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//func (f *Frontend) processSystemEvent(message string) {
|
||||||
|
// sl := strings.Split(message, ":")
|
||||||
|
// if len(sl) != 2 {
|
||||||
|
// f.logger.Error("Invalid system message: %s", message)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// switch sl[1] {
|
||||||
|
// case "fullscreen":
|
||||||
|
// f.mainWindow.DisableSizeConstraints()
|
||||||
|
// case "unfullscreen":
|
||||||
|
// f.mainWindow.EnableSizeConstraints()
|
||||||
|
// default:
|
||||||
|
// f.logger.Error("Unknown system message: %s", message)
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
//export processMessage
|
//export processMessage
|
||||||
func processMessage(message *C.char) {
|
func processMessage(message *C.char) {
|
||||||
goMessage := C.GoString(message)
|
goMessage := C.GoString(message)
|
||||||
|
|||||||
@@ -200,9 +200,9 @@ unsigned int _Users_username_Pictures_SaltBae_png_len = 1863;
|
|||||||
|
|
||||||
int main(int argc, const char * argv[]) {
|
int main(int argc, const char * argv[]) {
|
||||||
// insert code here...
|
// insert code here...
|
||||||
int frameless = 1;
|
int frameless = 0;
|
||||||
int resizable = 0;
|
int resizable = 1;
|
||||||
int fullscreen = 0;
|
int fullscreen = 1;
|
||||||
int fullSizeContent = 1;
|
int fullSizeContent = 1;
|
||||||
int hideTitleBar = 0;
|
int hideTitleBar = 0;
|
||||||
int titlebarAppearsTransparent = 0;
|
int titlebarAppearsTransparent = 0;
|
||||||
@@ -215,7 +215,10 @@ int main(int argc, const char * argv[]) {
|
|||||||
const char* appearance = "NSAppearanceNameDarkAqua";
|
const char* appearance = "NSAppearanceNameDarkAqua";
|
||||||
int windowIsTranslucent = 1;
|
int windowIsTranslucent = 1;
|
||||||
int debug = 1;
|
int debug = 1;
|
||||||
WailsContext *result = Create("OI OI!",400,400, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, debug);
|
int windowStartState = 0;
|
||||||
|
int startsHidden = 0;
|
||||||
|
WailsContext *result = Create("OI OI!",400,400, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, debug, windowStartState,
|
||||||
|
startsHidden, 400, 400, 600, 600);
|
||||||
SetRGBA(result, 255, 0, 0, 255);
|
SetRGBA(result, 255, 0, 0, 255);
|
||||||
void *m = NewMenu("");
|
void *m = NewMenu("");
|
||||||
SetAbout(result, "Fake title", "I am a description", _Users_username_Pictures_SaltBae_png, _Users_username_Pictures_SaltBae_png_len);
|
SetAbout(result, "Fake title", "I am a description", _Users_username_Pictures_SaltBae_png, _Users_username_Pictures_SaltBae_png_len);
|
||||||
@@ -228,7 +231,7 @@ int main(int argc, const char * argv[]) {
|
|||||||
AppendSubmenu(m, submenu);
|
AppendSubmenu(m, submenu);
|
||||||
UpdateMenuItem(menuITem, 1);
|
UpdateMenuItem(menuITem, 1);
|
||||||
SetAsApplicationMenu(result, m);
|
SetAsApplicationMenu(result, m);
|
||||||
SetPosition(result, 100, 100);
|
// SetPosition(result, 100, 100);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window {
|
|||||||
|
|
||||||
width := C.int(frontendOptions.Width)
|
width := C.int(frontendOptions.Width)
|
||||||
height := C.int(frontendOptions.Height)
|
height := C.int(frontendOptions.Height)
|
||||||
|
minWidth := C.int(frontendOptions.MinWidth)
|
||||||
|
minHeight := C.int(frontendOptions.MinHeight)
|
||||||
|
maxWidth := C.int(frontendOptions.MaxWidth)
|
||||||
|
maxHeight := C.int(frontendOptions.MaxHeight)
|
||||||
windowStartState := C.int(int(frontendOptions.WindowStartState))
|
windowStartState := C.int(int(frontendOptions.WindowStartState))
|
||||||
|
|
||||||
title = c.String(frontendOptions.Title)
|
title = c.String(frontendOptions.Title)
|
||||||
@@ -80,7 +84,8 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window {
|
|||||||
}
|
}
|
||||||
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent,
|
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent,
|
||||||
hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent,
|
hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent,
|
||||||
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, debug, windowStartState, startsHidden)
|
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, debug, windowStartState, startsHidden,
|
||||||
|
minWidth, minHeight, maxWidth, maxHeight)
|
||||||
|
|
||||||
// Create menu
|
// Create menu
|
||||||
result := &Window{
|
result := &Window{
|
||||||
@@ -107,9 +112,6 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window {
|
|||||||
result.SetApplicationMenu(frontendOptions.Menu)
|
result.SetApplicationMenu(frontendOptions.Menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.SetMinSize(frontendOptions.MinWidth, frontendOptions.MinHeight)
|
|
||||||
result.SetMaxSize(frontendOptions.MaxWidth, frontendOptions.MaxHeight)
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,16 +168,10 @@ func (w *Window) UnMinimise() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) SetMinSize(width int, height int) {
|
func (w *Window) SetMinSize(width int, height int) {
|
||||||
if width == 0 && height == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
C.SetMinSize(w.context, C.int(width), C.int(height))
|
C.SetMinSize(w.context, C.int(width), C.int(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) SetMaxSize(width int, height int) {
|
func (w *Window) SetMaxSize(width int, height int) {
|
||||||
if width == 0 && height == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
C.SetMaxSize(w.context, C.int(width), C.int(height))
|
C.SetMaxSize(w.context, C.int(width), C.int(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user