mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 14:29:50 +08:00
Support vibrancy and transparency for webview
Options Colour -> RGBA
This commit is contained in:
parent
84730d2f4d
commit
3f3094f0aa
@ -139,8 +139,8 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string) error
|
|||||||
// C.DisableFrame(a.app)
|
// C.DisableFrame(a.app)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if a.config.Colour != 0 {
|
if a.config.RGBA != 0 {
|
||||||
r, g, b, alpha := intToColour(a.config.Colour)
|
r, g, b, alpha := intToColour(a.config.RGBA)
|
||||||
C.SetColour(a.app, r, g, b, alpha)
|
C.SetColour(a.app, r, g, b, alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +119,8 @@ struct Application {
|
|||||||
int green;
|
int green;
|
||||||
int blue;
|
int blue;
|
||||||
int alpha;
|
int alpha;
|
||||||
|
int webviewIsTranparent;
|
||||||
|
const char *vibrancy;
|
||||||
|
|
||||||
// Features
|
// Features
|
||||||
int frame;
|
int frame;
|
||||||
@ -148,7 +150,6 @@ struct Application {
|
|||||||
|
|
||||||
void TitlebarAppearsTransparent(struct Application* app) {
|
void TitlebarAppearsTransparent(struct Application* app) {
|
||||||
app->titlebarAppearsTransparent = 1;
|
app->titlebarAppearsTransparent = 1;
|
||||||
Debug("[x] setTitlebarAppearsTransparent %d", app->titlebarAppearsTransparent? YES:NO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HideTitle(struct Application *app) {
|
void HideTitle(struct Application *app) {
|
||||||
@ -167,6 +168,19 @@ void UseToolbar(struct Application *app) {
|
|||||||
app->useToolBar = 1;
|
app->useToolBar = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebviewIsTransparent will make the webview transparent
|
||||||
|
// revealing the Cocoa window underneath
|
||||||
|
void WebviewIsTransparent(struct Application *app) {
|
||||||
|
app->webviewIsTranparent = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetVibrancy will set the window's vibrancy to the
|
||||||
|
// given value
|
||||||
|
void SetVibrancy(struct Application *app, const char *vibrancy) {
|
||||||
|
app->vibrancy = vibrancy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void applyWindowColour(struct Application *app) {
|
void applyWindowColour(struct Application *app) {
|
||||||
// Apply the colour only if the window has been created
|
// Apply the colour only if the window has been created
|
||||||
if( app->mainWindow != NULL ) {
|
if( app->mainWindow != NULL ) {
|
||||||
@ -271,8 +285,10 @@ void* NewApplication(const char *title, int width, int height, int resizable, in
|
|||||||
result->fullSizeContent = 0;
|
result->fullSizeContent = 0;
|
||||||
result->useToolBar = 0;
|
result->useToolBar = 0;
|
||||||
result->hideToolbarSeparator = 0;
|
result->hideToolbarSeparator = 0;
|
||||||
|
result->vibrancy = "NSAppearanceNameAqua";
|
||||||
|
|
||||||
result->titlebarAppearsTransparent = 0;
|
result->titlebarAppearsTransparent = 0;
|
||||||
|
result->webviewIsTranparent = 0;
|
||||||
|
|
||||||
result->sendMessageToBackend = (ffenestriCallback) messageFromWindowCallback;
|
result->sendMessageToBackend = (ffenestriCallback) messageFromWindowCallback;
|
||||||
|
|
||||||
@ -413,7 +429,6 @@ void SetSize(struct Application *app, int width, int height) {
|
|||||||
frame.origin.y = (frame.origin.y + frame.size.height) - (float)height;
|
frame.origin.y = (frame.origin.y + frame.size.height) - (float)height;
|
||||||
frame.size.width = (float)width;
|
frame.size.width = (float)width;
|
||||||
frame.size.height = (float)height;
|
frame.size.height = (float)height;
|
||||||
dumpFrame("after", frame);
|
|
||||||
|
|
||||||
msg(app->mainWindow, s("setFrame:display:animate:"), frame, 1, 0);
|
msg(app->mainWindow, s("setFrame:display:animate:"), frame, 1, 0);
|
||||||
)
|
)
|
||||||
@ -837,6 +852,16 @@ void Run(void *applicationPointer, int argc, char **argv) {
|
|||||||
1,
|
1,
|
||||||
1));
|
1));
|
||||||
|
|
||||||
|
if( app->webviewIsTranparent == 1 ) {
|
||||||
|
msg(wkwebview, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 1), str("drawsTransparentBackground"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set Vibrancy
|
||||||
|
msg(mainWindow, s("setAppearance:"),
|
||||||
|
msg(c("NSAppearance"), s("appearanceNamed:"), str(app->vibrancy))
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// Finally call run
|
// Finally call run
|
||||||
Debug("Run called");
|
Debug("Run called");
|
||||||
msg(application, s("run"));
|
msg(application, s("run"));
|
||||||
|
@ -11,6 +11,8 @@ extern void FullSizeContent(void *);
|
|||||||
extern void UseToolbar(void *);
|
extern void UseToolbar(void *);
|
||||||
extern void HideToolbarSeparator(void *);
|
extern void HideToolbarSeparator(void *);
|
||||||
extern void DisableFrame(void *);
|
extern void DisableFrame(void *);
|
||||||
|
extern void SetVibrancy(void *, const char *);
|
||||||
|
extern void WebviewIsTransparent(void *);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
@ -51,4 +53,14 @@ func (a *Application) processPlatformSettings() {
|
|||||||
if titlebar.TitlebarAppearsTransparent && titlebar.HideTitle {
|
if titlebar.TitlebarAppearsTransparent && titlebar.HideTitle {
|
||||||
C.DisableFrame(a.app)
|
C.DisableFrame(a.app)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process window vibrancy
|
||||||
|
if mac.Vibrancy != "" {
|
||||||
|
C.SetVibrancy(a.app, a.string2CString(string(mac.Vibrancy)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the webview should be transparent
|
||||||
|
if mac.WebviewIsTransparent {
|
||||||
|
C.WebviewIsTransparent(a.app)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,10 @@ var Default = &App{
|
|||||||
Width: 1024,
|
Width: 1024,
|
||||||
Height: 768,
|
Height: 768,
|
||||||
DevTools: true,
|
DevTools: true,
|
||||||
Colour: 0xFFFFFFFF,
|
RGBA: 0xFFFFFFFF,
|
||||||
Mac: &mac.Options{
|
Mac: &mac.Options{
|
||||||
TitleBar: mac.TitleBarDefault(),
|
TitleBar: mac.TitleBarDefault(),
|
||||||
|
Vibrancy: mac.NSAppearanceNameAqua,
|
||||||
|
WebviewIsTransparent: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,7 @@ package mac
|
|||||||
|
|
||||||
// Options ae options speific to Mac
|
// Options ae options speific to Mac
|
||||||
type Options struct {
|
type Options struct {
|
||||||
TitleBar *TitleBar
|
TitleBar *TitleBar
|
||||||
|
Vibrancy VibrancyType
|
||||||
|
WebviewIsTransparent bool
|
||||||
}
|
}
|
||||||
|
21
v2/pkg/options/mac/vibrancy.go
Normal file
21
v2/pkg/options/mac/vibrancy.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package mac
|
||||||
|
|
||||||
|
// VibrancyType is a type of vibrancy for Cocoa windows
|
||||||
|
type VibrancyType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// NSAppearanceNameAqua - The standard light system appearance.
|
||||||
|
NSAppearanceNameAqua VibrancyType = "NSAppearanceNameAqua"
|
||||||
|
// NSAppearanceNameDarkAqua - The standard dark system appearance.
|
||||||
|
NSAppearanceNameDarkAqua VibrancyType = "NSAppearanceNameDarkAqua"
|
||||||
|
// NSAppearanceNameVibrantLight - The light vibrant appearance
|
||||||
|
NSAppearanceNameVibrantLight VibrancyType = "NSAppearanceNameVibrantLight"
|
||||||
|
// NSAppearanceNameAccessibilityHighContrastAqua - A high-contrast version of the standard light system appearance.
|
||||||
|
NSAppearanceNameAccessibilityHighContrastAqua VibrancyType = "NSAppearanceNameAccessibilityHighContrastAqua"
|
||||||
|
// NSAppearanceNameAccessibilityHighContrastDarkAqua - A high-contrast version of the standard dark system appearance.
|
||||||
|
NSAppearanceNameAccessibilityHighContrastDarkAqua VibrancyType = "NSAppearanceNameAccessibilityHighContrastDarkAqua"
|
||||||
|
// NSAppearanceNameAccessibilityHighContrastVibrantLight - A high-contrast version of the light vibrant appearance.
|
||||||
|
NSAppearanceNameAccessibilityHighContrastVibrantLight VibrancyType = "NSAppearanceNameAccessibilityHighContrastVibrantLight"
|
||||||
|
// NSAppearanceNameAccessibilityHighContrastVibrantDark - A high-contrast version of the dark vibrant appearance.
|
||||||
|
NSAppearanceNameAccessibilityHighContrastVibrantDark VibrancyType = "NSAppearanceNameAccessibilityHighContrastVibrantDark"
|
||||||
|
)
|
@ -20,7 +20,7 @@ type App struct {
|
|||||||
MaxHeight int
|
MaxHeight int
|
||||||
StartHidden bool
|
StartHidden bool
|
||||||
DevTools bool
|
DevTools bool
|
||||||
Colour int
|
RGBA int
|
||||||
Mac *mac.Options
|
Mac *mac.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ body {
|
|||||||
font-family: 'Roboto';
|
font-family: 'Roboto';
|
||||||
min-height: 75rem;
|
min-height: 75rem;
|
||||||
padding-top: 4.5rem;
|
padding-top: 4.5rem;
|
||||||
|
background-color: #0000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-check-label {
|
.form-check-label {
|
||||||
|
@ -22,11 +22,12 @@ func main() {
|
|||||||
Height: 620,
|
Height: 620,
|
||||||
DisableResize: false,
|
DisableResize: false,
|
||||||
Fullscreen: false,
|
Fullscreen: false,
|
||||||
Colour: 0xFF000088,
|
RGBA: 0xFF0000FF,
|
||||||
Mac: &mac.Options{
|
Mac: &mac.Options{
|
||||||
// TitleBar: mac.TitleBarHidden(),
|
// TitleBar: mac.TitleBarHidden(),
|
||||||
// TitleBar: mac.TitleBarHiddenInset(),
|
// TitleBar: mac.TitleBarHiddenInset(),
|
||||||
TitleBar: mac.TitleBarDefault(),
|
TitleBar: mac.TitleBarDefault(),
|
||||||
|
Vibrancy: mac.NSAppearanceNameDarkAqua,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user