Fix window dragging - use ReleaseCapture + SendMessage for native drag
- webkit-app-region doesn't work in WebView2, use Win API instead - Bind windowDrag() that calls ReleaseCapture + SendMessage(WM_NCLBUTTONDOWN) - Title bar onmousedown triggers native window drag behavior - stopPropagation on window control buttons to prevent drag on click - Window can now be dragged by clicking anywhere on the title bar Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
9
main.go
9
main.go
@@ -30,6 +30,8 @@ var (
|
||||
procSetWindowPos = user32.NewProc("SetWindowPos")
|
||||
procPostMessage = user32.NewProc("PostMessageW")
|
||||
procShowWindow = user32.NewProc("ShowWindow")
|
||||
procReleaseCapture = user32.NewProc("ReleaseCapture")
|
||||
procSendMessage = user32.NewProc("SendMessageW")
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -48,6 +50,8 @@ const (
|
||||
swpNoZOrder = 0x0004
|
||||
|
||||
wmSysCommand = 0x0112
|
||||
wmNcLButtonDown = 0x00A1
|
||||
htCaption = 2
|
||||
scMinimize = 0xF020
|
||||
scMaximize = 0xF030
|
||||
scRestore = 0xF120
|
||||
@@ -125,6 +129,11 @@ func main() {
|
||||
removeWindowFrame(hwnd)
|
||||
|
||||
// Bind window control functions for custom title bar buttons
|
||||
// Drag: simulate title bar click to enable native window dragging
|
||||
w.Bind("windowDrag", func() {
|
||||
procReleaseCapture.Call()
|
||||
procSendMessage.Call(hwnd, wmNcLButtonDown, htCaption, 0)
|
||||
})
|
||||
w.Bind("windowMinimize", func() {
|
||||
procPostMessage.Call(hwnd, wmSysCommand, scMinimize, 0)
|
||||
})
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
<body>
|
||||
<div class="app">
|
||||
<!-- Custom Title Bar (frameless window) -->
|
||||
<div class="titlebar" id="titlebar">
|
||||
<div class="titlebar-left">
|
||||
<div class="titlebar" id="titlebar" onmousedown="windowDrag()">
|
||||
<div class="titlebar-left" onmousedown="event.stopPropagation()">
|
||||
<img src="icon-app.png" class="app-logo-img" alt="">
|
||||
<div class="app-title">
|
||||
<span class="app-name">DRIVER BOOSTER</span>
|
||||
@@ -24,13 +24,13 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="titlebar-controls">
|
||||
<button class="win-btn win-minimize" onclick="windowMinimize()" title="Minimize">
|
||||
<button class="win-btn win-minimize" onmousedown="event.stopPropagation()" onclick="windowMinimize()" title="Minimize">
|
||||
<svg width="10" height="1" viewBox="0 0 10 1"><rect width="10" height="1" fill="currentColor"/></svg>
|
||||
</button>
|
||||
<button class="win-btn win-maximize" onclick="windowMaximize()" title="Maximize">
|
||||
<button class="win-btn win-maximize" onmousedown="event.stopPropagation()" onclick="windowMaximize()" title="Maximize">
|
||||
<svg width="10" height="10" viewBox="0 0 10 10"><rect x="0.5" y="0.5" width="9" height="9" fill="none" stroke="currentColor" stroke-width="1"/></svg>
|
||||
</button>
|
||||
<button class="win-btn win-close" onclick="windowClose()" title="Close">
|
||||
<button class="win-btn win-close" onmousedown="event.stopPropagation()" onclick="windowClose()" title="Close">
|
||||
<svg width="10" height="10" viewBox="0 0 10 10"><line x1="0" y1="0" x2="10" y2="10" stroke="currentColor" stroke-width="1.2"/><line x1="10" y1="0" x2="0" y2="10" stroke="currentColor" stroke-width="1.2"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user