Skip to content

Commit

Permalink
[windows] ignore mouse events
Browse files Browse the repository at this point in the history
  • Loading branch information
leaanthony committed Oct 23, 2023
1 parent e661052 commit 3422c40
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
26 changes: 26 additions & 0 deletions v3/examples/window/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"math/rand"
"os"
"runtime"
"strconv"
"time"
Expand Down Expand Up @@ -100,6 +101,21 @@ func main() {
}).Show()
windowCounter++
})
myMenu.Add("New WebviewWindow (ignores mouse events").
SetAccelerator("CmdOrCtrl+F").
OnClick(func(ctx *application.Context) {
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
HTML: "<div style='width: 100%; height: 95%; border: 3px solid red; background-color: \"0000\";'></div>",
X: rand.Intn(1000),
Y: rand.Intn(800),
IgnoreMouseEvents: true,
BackgroundType: application.BackgroundTypeTransparent,
Mac: application.MacWindow{
InvisibleTitleBarHeight: 50,
},
}).Show()
windowCounter++
})
if runtime.GOOS == "darwin" {
myMenu.Add("New WebviewWindow (MacTitleBarHiddenInset)").
OnClick(func(ctx *application.Context) {
Expand Down Expand Up @@ -384,6 +400,16 @@ func main() {
_ = w.Print()
})
})
printMenu.Add("Capture PNG").OnClick(func(ctx *application.Context) {
currentWindow(func(w *application.WebviewWindow) {
img, err := w.CapturePNG()
if err != nil {
application.ErrorDialog().SetTitle("Error").SetMessage(err.Error()).Show()
return
}
os.WriteFile("capture.png", img, 0644)
})
})

app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
BackgroundColour: application.NewRGB(33, 37, 41),
Expand Down
3 changes: 3 additions & 0 deletions v3/pkg/application/options_webview_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ type WebviewWindowOptions struct {

// KeyBindings is a map of key bindings to functions
KeyBindings map[string]func(window *WebviewWindow)

// IgnoreMouseEvents will ignore mouse events in the window
IgnoreMouseEvents bool
}

var WebviewWindowDefaults = &WebviewWindowOptions{
Expand Down
3 changes: 3 additions & 0 deletions v3/pkg/application/webview_window_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ func (w *windowsWebviewWindow) run() {
exStyle = w32.WS_EX_CONTROLPARENT
if options.BackgroundType != BackgroundTypeSolid {
exStyle |= w32.WS_EX_NOREDIRECTIONBITMAP
if w.parent.options.IgnoreMouseEvents {
exStyle |= w32.WS_EX_TRANSPARENT | w32.WS_EX_LAYERED
}
}
if options.AlwaysOnTop {
exStyle |= w32.WS_EX_TOPMOST
Expand Down

0 comments on commit 3422c40

Please sign in to comment.