Window Flash for Linux

Set Min/Max window buttons
This commit is contained in:
Lea Anthony 2024-02-09 21:31:41 +11:00 committed by Travis McLane
commit b6c5d90c9d
6 changed files with 68 additions and 11 deletions

View file

@ -445,11 +445,13 @@ func main() {
})
})
if runtime.GOOS == "windows" {
stateMenu.Add("Flash Start").OnClick(func(ctx *application.Context) {
if runtime.GOOS != "darwin" {
stateMenu.Add("Flash for 5s").OnClick(func(ctx *application.Context) {
currentWindow(func(w *application.WebviewWindow) {
time.Sleep(2 * time.Second)
w.Flash(true)
time.Sleep(5 * time.Second)
w.Flash(false)
})
})
}

View file

@ -1039,6 +1039,11 @@ func (w *linuxWebviewWindow) startDrag() error {
return nil
}
func (w *linuxWebviewWindow) flash(enabled bool) {
// Flash the window to get the user's attention
C.gtk_window_set_urgency_hint(w.gtkWindow(), gtkBool(enabled))
}
func enableDevTools(webview pointer) {
settings := C.webkit_web_view_get_settings((*C.WebKitWebView)(webview))
enabled := C.webkit_settings_get_enable_developer_extras(settings)

View file

@ -64,6 +64,8 @@ type (
isVisible() bool
isFocused() bool
setFullscreenButtonEnabled(enabled bool)
setMinimiseButtonEnabled(enabled bool)
setMaximiseButtonEnabled(enabled bool)
focus()
show()
hide()
@ -532,6 +534,26 @@ func (w *WebviewWindow) SetFullscreenButtonEnabled(enabled bool) Window {
return w
}
func (w *WebviewWindow) SetMinimiseButtonEnabled(enabled bool) Window {
w.options.FullscreenButtonEnabled = enabled
if w.impl != nil {
InvokeSync(func() {
w.impl.setMinimiseButtonEnabled(enabled)
})
}
return w
}
func (w *WebviewWindow) SetMaximiseButtonEnabled(enabled bool) Window {
w.options.FullscreenButtonEnabled = enabled
if w.impl != nil {
InvokeSync(func() {
w.impl.setMaximiseButtonEnabled(enabled)
})
}
return w
}
// Flash flashes the window's taskbar button/icon.
// Useful to indicate that attention is required. Windows only.
func (w *WebviewWindow) Flash(enabled bool) {

View file

@ -1132,13 +1132,13 @@ func (w *macosWebviewWindow) run() {
}
if macOptions.DisableMinimiseButton {
C.enableMinimiseButton(w.nsWindow, C.bool(false))
w.setMinimiseButtonEnabled(w.nsWindow, false)
}
if macOptions.DisableMaximiseButton {
C.enableMaximiseButton(w.nsWindow, C.bool(false))
w.setMaximiseButtonEnabled(w.nsWindow, false)
}
if macOptions.DisableCloseButton {
C.enableCloseButton(w.nsWindow, C.bool(false))
w.enableCloseButton(w.nsWindow, false)
}
if options.IgnoreMouseEvents {
@ -1269,3 +1269,15 @@ func (w *macosWebviewWindow) startDrag() error {
C.startDrag(w.nsWindow)
return nil
}
func (w *macosWebviewWindow) setMinimiseButtonEnabled(enabled bool) {
C.enableMinimiseButton(w.nsWindow, C.bool(enabled))
}
func (w *macosWebviewWindow) setMaximiseButtonEnabled(enabled bool) {
C.enableMaximiseButton(w.nsWindow, C.bool(enabled))
}
func (w *macosWebviewWindow) setCloseButtonEnabled(enabled bool) {
C.enableCloseButton(w.nsWindow, C.bool(enabled))
}

View file

@ -36,6 +36,14 @@ type linuxWebviewWindow struct {
gtkmenu pointer
}
func (w *linuxWebviewWindow) setMinimiseButtonEnabled(enabled bool) {
// Not available in Linux
}
func (w *linuxWebviewWindow) setMaximiseButtonEnabled(enabled bool) {
// Not available in Linux
}
var (
registered bool = false // avoid 'already registered message' about 'wails://'
)
@ -105,10 +113,6 @@ func (w *linuxWebviewWindow) unminimise() {
w.present()
}
func (w *linuxWebviewWindow) flash(enabled bool) {
// Not supported on linux
}
func (w *linuxWebviewWindow) on(eventID uint) {
// TODO: Test register/unregister listener for linux events
//C.registerListener(C.uint(eventID))

View file

@ -238,8 +238,12 @@ func (w *windowsWebviewWindow) run() {
w.setSize(options.Width, options.Height)
// Min/max buttons
w.setStyle(!options.Windows.DisableMinimiseButton, w32.WS_MINIMIZEBOX)
w.setStyle(!options.Windows.DisableMaximiseButton, w32.WS_MAXIMIZEBOX)
if !options.Windows.DisableMinimiseButton {
w.setMinimiseButtonEnabled(false)
}
if !options.Windows.DisableMaximiseButton {
w.setMaximiseButtonEnabled(false)
}
// Register the window with the application
getNativeApplication().registerWindow(w)
@ -1626,6 +1630,14 @@ func (w *windowsWebviewWindow) processMessageWithAdditionalObjects(message strin
}
}
func (w *windowsWebviewWindow) setMaximiseButtonEnabled(enabled bool) {
w.setStyle(enabled, w32.WS_MINIMIZEBOX)
}
func (w *windowsWebviewWindow) setMinimiseButtonEnabled(enabled bool) {
w.setStyle(enabled, w32.WS_MAXIMIZEBOX)
}
func ScaleWithDPI(pixels int, dpi uint) int {
return (pixels * int(dpi)) / 96
}