5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 11:29:29 +08:00

Add WebviewWindow.IsFocused()

This commit is contained in:
Lea Anthony 2023-09-13 08:57:09 +10:00
parent d808654d99
commit bb3a0cc54f
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
5 changed files with 32 additions and 1 deletions

View File

@ -551,6 +551,11 @@ func windowIsFullscreen(window pointer) bool {
return state&C.GDK_WINDOW_STATE_FULLSCREEN > 0
}
func windowIsFocused(window pointer) bool {
// returns true if window is focused
return C.gtk_window_has_toplevel_focus((*C.GtkWindow)(window)) == 1
}
func windowIsMaximized(window pointer) bool {
gdkwindow := C.gtk_widget_get_window((*C.GtkWidget)(window))
state := C.gdk_window_get_state(gdkwindow)

View File

@ -53,6 +53,7 @@ type (
isFullscreen() bool
isNormal() bool
isVisible() bool
isFocused() bool
setFullscreenButtonEnabled(enabled bool)
focus()
show()
@ -482,6 +483,14 @@ func (w *WebviewWindow) Size() (int, int) {
return width, height
}
// IsFocused returns true if the window is currently focused
func (w *WebviewWindow) IsFocused() bool {
if w.impl == nil {
return false
}
return invokeSyncWithResult(w.impl.isFullscreen)
}
// IsFullscreen returns true if the window is fullscreen
func (w *WebviewWindow) IsFullscreen() bool {
if w.impl == nil {

View File

@ -345,6 +345,10 @@ bool windowIsMinimised(void* nsWindow) {
return [(WebviewWindow*)nsWindow isMiniaturized];
}
bool windowIsFocused(void* nsWindow) {
return [(WebviewWindow*)nsWindow isKeyWindow];
}
// Set Window fullscreen
void windowFullscreen(void* nsWindow) {
if( windowIsFullscreen(nsWindow) ) {
@ -716,6 +720,10 @@ type macosWebviewWindow struct {
parent *WebviewWindow
}
func (w *macosWebviewWindow) isFocused() bool {
return bool(C.windowIsFocused(w.nsWindow))
}
func (w *macosWebviewWindow) setAbsolutePosition(x int, y int) {
C.windowSetAbsolutePosition(w.nsWindow, C.int(x), C.int(y))
}
@ -944,7 +952,7 @@ func (w *macosWebviewWindow) setTitle(title string) {
}
}
func (w *macosWebviewWindow) flash(enabled bool) {
func (w *macosWebviewWindow) flash(_ bool) {
// Not supported on macOS
}

View File

@ -231,6 +231,10 @@ func (w *linuxWebviewWindow) isMaximised() bool {
return windowIsMaximized(w.window)
}
func (w *linuxWebviewWindow) isFocused() bool {
return windowIsFocused(w.window)
}
func (w *linuxWebviewWindow) isFullscreen() bool {
return windowIsFullscreen(w.window)
}

View File

@ -549,6 +549,11 @@ func (w *windowsWebviewWindow) isMaximised() bool {
return style&w32.WS_MAXIMIZE != 0
}
func (w *windowsWebviewWindow) isFocused() bool {
// Returns true if the window is currently focused
return w32.GetForegroundWindow() == w.hwnd
}
func (w *windowsWebviewWindow) isFullscreen() bool {
// TODO: Actually calculate this based on size of window against screen size
// => stffabi: This flag is essential since it indicates that we are in fullscreen mode even before the native properties