-
Notifications
You must be signed in to change notification settings - Fork 3
/
qframelesswindow_darwin.go
120 lines (96 loc) · 3.57 KB
/
qframelesswindow_darwin.go
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
package qframelesswindow
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Cocoa
#import <Cocoa/Cocoa.h>
void applyBlurEffect(long *wid, long *contentid, bool isLight) {
NSView* view = (NSView*)wid;
NSWindow *window = [view window];
// NSVisualEffectViewをウィンドウのcontentViewに追加
NSVisualEffectView *visualEffectView = [[NSVisualEffectView alloc] initWithFrame:window.contentView.bounds];
visualEffectView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
visualEffectView.blendingMode = NSVisualEffectBlendingModeBehindWindow;
visualEffectView.state = NSVisualEffectStateActive;
if (isLight) {
visualEffectView.material = NSVisualEffectMaterialLight;
} else {
visualEffectView.material = NSVisualEffectMaterialUltraDark;
}
[window.contentView addSubview:visualEffectView positioned:NSWindowBelow relativeTo:nil];
NSView* qtView = (NSView*)contentid;
// QtのビューをvisualEffectViewの上に配置
[window.contentView addSubview:qtView positioned:NSWindowAbove relativeTo:visualEffectView];
}
void setNSWindowStyle(long *wid, bool isVisibleTitlebar, float red, float green, float blue, float alpha, bool isFullscreen) {
NSView* view = (NSView*)wid;
NSWindow *window = [view window];
// Style
window.styleMask |= NSWindowStyleMaskFullSizeContentView;
if (isVisibleTitlebar) {
window.styleMask |= NSWindowStyleMaskTitled;
}
window.styleMask |= NSWindowStyleMaskResizable;
window.styleMask |= NSWindowStyleMaskMiniaturizable;
window.styleMask |= NSWindowStyleMaskClosable;
[[window standardWindowButton:NSWindowCloseButton] setEnabled:YES];
[[window standardWindowButton:NSWindowCloseButton] setHidden:!isVisibleTitlebar];
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:!isVisibleTitlebar];
[[window standardWindowButton:NSWindowZoomButton] setHidden:!isVisibleTitlebar];
// Don't show title bar
window.titlebarAppearsTransparent = YES;
window.titleVisibility = isVisibleTitlebar ? NSWindowTitleVisible : NSWindowTitleHidden;
// Appearance
window.opaque = NO;
CGFloat cgred = red;
CGFloat cggreen = green;
CGFloat cgblue = blue;
CGFloat cgalpha = alpha;
window.backgroundColor = [NSColor colorWithCalibratedRed:cgred green:cggreen blue:cgblue alpha:cgalpha];
window.hasShadow = YES;
// Fullscreen
if (isFullscreen) {
window.styleMask |= NSWindowStyleMaskFullScreen;
}
}
*/
import "C"
import (
"unsafe"
"github.com/akiyosi/qt/core"
)
func (f *QFramelessWindow) SetStyleMask() {
f.SetNSWindowStyleMask(
!f.IsTitlebarHidden,
f.WindowColor.R, f.WindowColor.G, f.WindowColor.B,
float32(f.WindowColorAlpha),
f.WindowState() == core.Qt__WindowFullScreen,
)
}
func (f *QFramelessWindow) SetBlurEffectForMacOS(isLight bool) {
wid := f.WinId()
contentid := f.Content.WinId()
C.applyBlurEffect(
(*C.long)(unsafe.Pointer(wid)),
(*C.long)(unsafe.Pointer(contentid)),
C.bool(isLight),
)
}
func (f *QFramelessWindow) SetNSWindowStyleMask(isVisibleTitlebarButtons bool, R, G, B uint16, alpha float32, isWindowFullscreen bool) {
wid := f.WinId()
fR := float32(R) / float32(255)
fG := float32(G) / float32(255)
fB := float32(B) / float32(255)
C.setNSWindowStyle(
(*C.long)(unsafe.Pointer(wid)),
C.bool(isVisibleTitlebarButtons),
C.float(fR), C.float(fG), C.float(fB),
C.float(alpha),
C.bool(isWindowFullscreen),
)
}
func (f *QFramelessWindow) SetBlurEffectForWin(hwnd uintptr) {
}
func (f *QFramelessWindow) SetupNativeEvent() {
}
func (f *QFramelessWindow) SetupNativeEvent2() {
}