-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions_mac.mm
125 lines (97 loc) · 3.77 KB
/
functions_mac.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#import <CoreServices/CoreServices.h>
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <objc/objc-runtime.h>
#include "functions.h"
@interface PROPanel : NSWindow
@end
@implementation PROPanel
- (NSWindowStyleMask)styleMask {
return NSWindowStyleMaskTexturedBackground | NSWindowStyleMaskResizable | NSWindowStyleMaskFullSizeContentView | NSWindowStyleMaskNonactivatingPanel;
}
- (NSWindowCollectionBehavior)collectionBehavior {
return NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorFullScreenAuxiliary;
}
- (BOOL)isFloatingPanel {
return YES;
}
- (NSWindowLevel)level {
return NSFloatingWindowLevel;
}
- (BOOL)canBecomeKeyWindow {
return YES;
}
- (BOOL)canBecomeMainWindow {
return YES;
}
- (BOOL)needsPanelToBecomeKey {
return YES;
}
- (BOOL)acceptsFirstResponder {
return YES;
}
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath context:(nullable void *)context {
// macOS Big Sur attempts to remove an observer for the NSTitlebarView that doesn't exist.
// This is due to us changing the class from NSWindow -> NSPanel at runtime, it's possible
// there is assumed setup that doesn't happen. Details of the exception this is avoiding are
// here: https://github.com/goabstract/electron-panel-window/issues/6
if ([keyPath isEqualToString:@"_titlebarBackdropGroupName"]) {
// NSLog(@"removeObserver ignored");
return;
}
if (context) {
[super removeObserver:observer forKeyPath:keyPath context:context];
} else {
[super removeObserver:observer forKeyPath:keyPath];
}
}
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath {
[self removeObserver:observer forKeyPath:keyPath context:NULL];
}
@end
Class electronWindowClass;
NAN_METHOD(MakePanel) {
v8::Local<v8::Object> handleBuffer = info[0].As<v8::Object>();
v8::Isolate* isolate = info.GetIsolate();
v8::HandleScope scope(isolate);
char* buffer = node::Buffer::Data(handleBuffer);
NSView* mainContentView = *reinterpret_cast<NSView**>(buffer);
if (!mainContentView)
return info.GetReturnValue().Set(false);
electronWindowClass = [mainContentView.window class];
// NSLog(@"class of main window before = %@", object_getClass(mainContentView.window));
NSWindow *nswindow = [mainContentView window];
nswindow.titlebarAppearsTransparent = true;
nswindow.titleVisibility = (NSWindowTitleVisibility)1;
// NSLog(@"stylemask = %ld", mainContentView.window.styleMask);
// Convert the NSWindow class to PROPanel
object_setClass(mainContentView.window, [PROPanel class]);
// NSLog(@"class of main window after = %@", object_getClass(mainContentView.window));
// NSLog(@"stylemask after = %ld", mainContentView.window.styleMask);
return info.GetReturnValue().Set(true);
}
NAN_METHOD(MakeKeyWindow) {
v8::Local<v8::Object> handleBuffer = info[0].As<v8::Object>();
v8::Isolate* isolate = info.GetIsolate();
v8::HandleScope scope(isolate);
char* buffer = node::Buffer::Data(handleBuffer);
NSView* mainContentView = *reinterpret_cast<NSView**>(buffer);
if (!mainContentView)
return info.GetReturnValue().Set(false);
[mainContentView.window makeKeyWindow];
[mainContentView.window makeMainWindow];
return info.GetReturnValue().Set(true);
}
NAN_METHOD(MakeWindow) {
v8::Local<v8::Object> handleBuffer = info[0].As<v8::Object>();
v8::Isolate* isolate = info.GetIsolate();
v8::HandleScope scope(isolate);
char* buffer = node::Buffer::Data(handleBuffer);
NSView* mainContentView = *reinterpret_cast<NSView**>(buffer);
if (!mainContentView)
return info.GetReturnValue().Set(false);
NSWindow* newWindow = mainContentView.window;
// Convert the NSPanel class to whatever it was before
object_setClass(newWindow, electronWindowClass);
return info.GetReturnValue().Set(true);
}