-
Notifications
You must be signed in to change notification settings - Fork 1
/
window_darwin.go
114 lines (83 loc) · 2.68 KB
/
window_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
package title_bar
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Cocoa
#import <Cocoa/Cocoa.h>
struct RGBA {
float red;
float green;
float blue;
float alpha;
};
int
SetTitleBarColor(float redValue, float greenValue, float blueValue, float alphaValue) {
NSWindow *window = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
NSColor *myColor = [NSColor colorWithCalibratedRed:redValue green:greenValue blue:blueValue alpha:alphaValue];
window.backgroundColor = myColor;
return 0;
}
struct RGBA
GetTitleBarColor(void) {
NSWindow *window = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
NSColor *bg = [window valueForKey:@"backgroundColor"];
struct RGBA rgba;
rgba.red = [bg redComponent];
rgba.green = [bg greenComponent];
rgba.blue = [bg blueComponent];
rgba.alpha = [bg alphaComponent];
return rgba;
}
bool
GetTitleTransparency() {
id window = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
return [window valueForKey:@"titlebarAppearsTransparent"];
}
int
SetTitleTransparency(bool titleTransparency) {
NSWindow *window = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
window.titlebarAppearsTransparent = titleTransparency;
return 0;
}
int
SetTitleBarWidget(bool hide, bool close, bool minimize, bool resize) {
NSWindow *window = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
if (hide) {
window.styleMask = NSWindowStyleMaskBorderless;
} else {
window.styleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskFullScreen;
if (close) {
window.styleMask |= NSWindowStyleMaskClosable;
} else {
window.styleMask &= ~NSWindowStyleMaskClosable;
}
if (minimize) {
window.styleMask |= NSWindowStyleMaskMiniaturizable;
} else {
window.styleMask &= ~NSWindowStyleMaskMiniaturizable;
}
if (resize) {
window.styleMask |= NSWindowStyleMaskResizable;
} else {
window.styleMask &= ~NSWindowStyleMaskResizable;
}
}
return 0;
}
*/
import "C"
func setTitleBarColor(color color) {
C.SetTitleBarColor(C.float(float64(color.red)/255), C.float(float64(color.green)/255), C.float(float64(color.blue)/255), C.float(float64(color.alpha)/255))
}
func getTitleBarColor() color {
temp := C.GetTitleBarColor()
return color{red: int32(temp.red * 255), green: int32(temp.green * 255), blue: int32(temp.blue * 255), alpha: int32(temp.alpha * 255)}
}
func setTitleBarTransparency(transparency bool) {
C.SetTitleTransparency(C.bool(transparency))
}
func getTitleBarTransparency() bool {
return bool(C.GetTitleTransparency())
}
func setTitleBarWidget(hide bool, close bool, minimize bool, resize bool) {
C.SetTitleBarWidget(C.bool(hide), C.bool(close), C.bool(minimize), C.bool(resize))
}