diff --git a/v2/pkg/options/linux/linux.go b/v2/pkg/options/linux/linux.go index 797450c2..1287f1da 100644 --- a/v2/pkg/options/linux/linux.go +++ b/v2/pkg/options/linux/linux.go @@ -4,10 +4,10 @@ package linux type WebviewGpuPolicy int const ( - // WebviewGpuPolicyAlways Hardware acceleration is always enabled. - WebviewGpuPolicyAlways WebviewGpuPolicy = iota // WebviewGpuPolicyOnDemand Hardware acceleration is enabled/disabled as request by web contents. - WebviewGpuPolicyOnDemand + WebviewGpuPolicyOnDemand WebviewGpuPolicy = iota + // WebviewGpuPolicyAlways Hardware acceleration is always enabled. + WebviewGpuPolicyAlways // WebviewGpuPolicyNever Hardware acceleration is always disabled. WebviewGpuPolicyNever ) diff --git a/v3/pkg/application/linux_cgo.go b/v3/pkg/application/linux_cgo.go index 379af254..73e32247 100644 --- a/v3/pkg/application/linux_cgo.go +++ b/v3/pkg/application/linux_cgo.go @@ -793,7 +793,7 @@ func windowMinimize(window pointer) { C.gtk_window_iconify((*C.GtkWindow)(window)) } -func windowNew(application pointer, menu pointer, windowId uint, gpuPolicy int) (window, webview, vbox pointer) { +func windowNew(application pointer, menu pointer, windowId uint, gpuPolicy WebviewGpuPolicy) (window, webview, vbox pointer) { window = pointer(C.gtk_application_window_new((*C.GtkApplication)(application))) C.g_object_ref_sink(C.gpointer(window)) webview = windowNewWebview(windowId, gpuPolicy) @@ -810,45 +810,39 @@ func windowNew(application pointer, menu pointer, windowId uint, gpuPolicy int) return } -func windowNewWebview(parentId uint, gpuPolicy int) pointer { +func windowNewWebview(parentId uint, gpuPolicy WebviewGpuPolicy) pointer { + c := NewCalloc() + defer c.Free() manager := C.webkit_user_content_manager_new() - external := C.CString("external") - C.webkit_user_content_manager_register_script_message_handler(manager, external) - C.free(unsafe.Pointer(external)) - webview := C.webkit_web_view_new_with_user_content_manager(manager) + C.webkit_user_content_manager_register_script_message_handler(manager, c.String("external")) + webView := C.webkit_web_view_new_with_user_content_manager(manager) id := C.uint(parentId) if !registered { - wails := C.CString("wails") C.webkit_web_context_register_uri_scheme( C.webkit_web_context_get_default(), - wails, + c.String("wails"), C.WebKitURISchemeRequestCallback(C.onProcessRequest), C.gpointer(&id), nil) registered = true - C.free(unsafe.Pointer(wails)) } - settings := C.webkit_web_view_get_settings((*C.WebKitWebView)(unsafe.Pointer(webview))) - wails_io := C.CString("wails.io") - empty := C.CString("") - defer C.free(unsafe.Pointer(wails_io)) - defer C.free(unsafe.Pointer(empty)) - C.webkit_settings_set_user_agent_with_application_details(settings, wails_io, empty) + settings := C.webkit_web_view_get_settings((*C.WebKitWebView)(unsafe.Pointer(webView))) + C.webkit_settings_set_user_agent_with_application_details(settings, c.String("wails.io"), c.String("")) switch gpuPolicy { - case 0: + case WebviewGpuPolicyAlways: C.webkit_settings_set_hardware_acceleration_policy(settings, C.WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS) break - case 1: + case WebviewGpuPolicyOnDemand: C.webkit_settings_set_hardware_acceleration_policy(settings, C.WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND) break - case 2: + case WebviewGpuPolicyNever: C.webkit_settings_set_hardware_acceleration_policy(settings, C.WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER) break default: C.webkit_settings_set_hardware_acceleration_policy(settings, C.WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND) } - return pointer(webview) + return pointer(webView) } func windowPresent(window pointer) { diff --git a/v3/pkg/application/options_linux.go b/v3/pkg/application/options_linux.go index bf3d0c30..3a471902 100644 --- a/v3/pkg/application/options_linux.go +++ b/v3/pkg/application/options_linux.go @@ -1,6 +1,43 @@ package application -// LinuxWindow contains macOS specific options +// WebviewGpuPolicy values used for determining the webview's hardware acceleration policy. +type WebviewGpuPolicy int + +const ( + // WebviewGpuPolicyAlways Hardware acceleration is always enabled. + WebviewGpuPolicyAlways WebviewGpuPolicy = iota + // WebviewGpuPolicyOnDemand Hardware acceleration is enabled/disabled as request by web contents. + WebviewGpuPolicyOnDemand + // WebviewGpuPolicyNever Hardware acceleration is always disabled. + WebviewGpuPolicyNever +) + +// LinuxWindow specific to Linux windows type LinuxWindow struct { - ShowApplicationMenu bool + // Icon Sets up the icon representing the window. This icon is used when the window is minimized + // (also known as iconified). + Icon []byte + + // WindowIsTranslucent sets the window's background to transparent when enabled. + WindowIsTranslucent bool + + // WebviewGpuPolicy used for determining the hardware acceleration policy for the webview. + // - WebviewGpuPolicyAlways + // - WebviewGpuPolicyOnDemand + // - WebviewGpuPolicyNever + // + // Due to https://github.com/wailsapp/wails/issues/2977, if options.Linux is nil + // in the call to wails.Run(), WebviewGpuPolicy is set by default to WebviewGpuPolicyNever. + // Client code may override this behavior by passing a non-nil Options and set + // WebviewGpuPolicy as needed. + WebviewGpuPolicy WebviewGpuPolicy + + // ProgramName is used to set the program's name for the window manager via GTK's g_set_prgname(). + //This name should not be localized. [see the docs] + // + //When a .desktop file is created this value helps with window grouping and desktop icons when the .desktop file's Name + //property differs form the executable's filename. + // + //[see the docs]: https://docs.gtk.org/glib/func.set_prgname.html + ProgramName string } diff --git a/v3/pkg/application/options_webview_window.go b/v3/pkg/application/options_webview_window.go index d2bccba4..7164066e 100644 --- a/v3/pkg/application/options_webview_window.go +++ b/v3/pkg/application/options_webview_window.go @@ -100,6 +100,9 @@ type WebviewWindowOptions struct { // Windows options Windows WindowsWindow + // Linux options + Linux LinuxWindow + // ShouldClose is called when the window is about to close. // Return true to allow the window to close, or false to prevent it from closing. ShouldClose func(window *WebviewWindow) bool diff --git a/v3/pkg/application/webview_window_linux.go b/v3/pkg/application/webview_window_linux.go index 5314ea6b..3df64706 100644 --- a/v3/pkg/application/webview_window_linux.go +++ b/v3/pkg/application/webview_window_linux.go @@ -2,6 +2,7 @@ package application +import "C" import ( "fmt" "github.com/wailsapp/wails/v3/internal/assetserver" @@ -354,7 +355,7 @@ func (w *linuxWebviewWindow) run() { app := getNativeApplication() menu := app.getApplicationMenu() - w.window, w.webview, w.vbox = windowNew(app.application, menu, w.parent.id, 1) + w.window, w.webview, w.vbox = windowNew(app.application, menu, w.parent.id, w.parent.options.Linux.WebviewGpuPolicy) app.registerWindow(w.window, w.parent.id) // record our mapping w.connectSignals() if w.parent.options.EnableDragAndDrop {