mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
app: [Windows] simplify GetWindowRect, delete old workaround
Go issue #34474 was fixed in 1.14 and backported to 1.13. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -342,12 +342,10 @@ var (
|
|||||||
|
|
||||||
func AdjustWindowRectEx(r *Rect, dwStyle uint32, bMenu int, dwExStyle uint32) {
|
func AdjustWindowRectEx(r *Rect, dwStyle uint32, bMenu int, dwExStyle uint32) {
|
||||||
_AdjustWindowRectEx.Call(uintptr(unsafe.Pointer(r)), uintptr(dwStyle), uintptr(bMenu), uintptr(dwExStyle))
|
_AdjustWindowRectEx.Call(uintptr(unsafe.Pointer(r)), uintptr(dwStyle), uintptr(bMenu), uintptr(dwExStyle))
|
||||||
issue34474KeepAlive(r)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CallMsgFilter(m *Msg, nCode uintptr) bool {
|
func CallMsgFilter(m *Msg, nCode uintptr) bool {
|
||||||
r, _, _ := _CallMsgFilter.Call(uintptr(unsafe.Pointer(m)), nCode)
|
r, _, _ := _CallMsgFilter.Call(uintptr(unsafe.Pointer(m)), nCode)
|
||||||
issue34474KeepAlive(m)
|
|
||||||
return r != 0
|
return r != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,7 +370,6 @@ func CreateWindowEx(dwExStyle uint32, lpClassName uint16, lpWindowName string, d
|
|||||||
uintptr(hMenu),
|
uintptr(hMenu),
|
||||||
uintptr(hInstance),
|
uintptr(hInstance),
|
||||||
uintptr(lpParam))
|
uintptr(lpParam))
|
||||||
issue34474KeepAlive(wname)
|
|
||||||
if hwnd == 0 {
|
if hwnd == 0 {
|
||||||
return 0, fmt.Errorf("CreateWindowEx failed: %v", err)
|
return 0, fmt.Errorf("CreateWindowEx failed: %v", err)
|
||||||
}
|
}
|
||||||
@@ -390,7 +387,6 @@ func DestroyWindow(hwnd syscall.Handle) {
|
|||||||
|
|
||||||
func DispatchMessage(m *Msg) {
|
func DispatchMessage(m *Msg) {
|
||||||
_DispatchMessage.Call(uintptr(unsafe.Pointer(m)))
|
_DispatchMessage.Call(uintptr(unsafe.Pointer(m)))
|
||||||
issue34474KeepAlive(m)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func EmptyClipboard() error {
|
func EmptyClipboard() error {
|
||||||
@@ -401,9 +397,10 @@ func EmptyClipboard() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetWindowRect(hwnd syscall.Handle, r *Rect) {
|
func GetWindowRect(hwnd syscall.Handle) Rect {
|
||||||
_GetWindowRect.Call(uintptr(hwnd), uintptr(unsafe.Pointer(r)))
|
var r Rect
|
||||||
issue34474KeepAlive(r)
|
_GetWindowRect.Call(uintptr(hwnd), uintptr(unsafe.Pointer(&r)))
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetClipboardData(format uint32) (syscall.Handle, error) {
|
func GetClipboardData(format uint32) (syscall.Handle, error) {
|
||||||
@@ -468,7 +465,6 @@ func GetMessage(m *Msg, hwnd syscall.Handle, wMsgFilterMin, wMsgFilterMax uint32
|
|||||||
uintptr(hwnd),
|
uintptr(hwnd),
|
||||||
uintptr(wMsgFilterMin),
|
uintptr(wMsgFilterMin),
|
||||||
uintptr(wMsgFilterMax))
|
uintptr(wMsgFilterMax))
|
||||||
issue34474KeepAlive(m)
|
|
||||||
return int32(r)
|
return int32(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,7 +641,6 @@ func OpenClipboard(hwnd syscall.Handle) error {
|
|||||||
|
|
||||||
func PeekMessage(m *Msg, hwnd syscall.Handle, wMsgFilterMin, wMsgFilterMax, wRemoveMsg uint32) bool {
|
func PeekMessage(m *Msg, hwnd syscall.Handle, wMsgFilterMin, wMsgFilterMax, wRemoveMsg uint32) bool {
|
||||||
r, _, _ := _PeekMessage.Call(uintptr(unsafe.Pointer(m)), uintptr(hwnd), uintptr(wMsgFilterMin), uintptr(wMsgFilterMax), uintptr(wRemoveMsg))
|
r, _, _ := _PeekMessage.Call(uintptr(unsafe.Pointer(m)), uintptr(hwnd), uintptr(wMsgFilterMin), uintptr(wMsgFilterMax), uintptr(wRemoveMsg))
|
||||||
issue34474KeepAlive(m)
|
|
||||||
return r != 0
|
return r != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -668,7 +663,6 @@ func ReleaseCapture() bool {
|
|||||||
|
|
||||||
func RegisterClassEx(cls *WndClassEx) (uint16, error) {
|
func RegisterClassEx(cls *WndClassEx) (uint16, error) {
|
||||||
a, _, err := _RegisterClassExW.Call(uintptr(unsafe.Pointer(cls)))
|
a, _, err := _RegisterClassExW.Call(uintptr(unsafe.Pointer(cls)))
|
||||||
issue34474KeepAlive(cls)
|
|
||||||
if a == 0 {
|
if a == 0 {
|
||||||
return 0, fmt.Errorf("RegisterClassExW failed: %v", err)
|
return 0, fmt.Errorf("RegisterClassExW failed: %v", err)
|
||||||
}
|
}
|
||||||
@@ -718,7 +712,6 @@ func SetTimer(hwnd syscall.Handle, nIDEvent uintptr, uElapse uint32, timerProc u
|
|||||||
|
|
||||||
func ScreenToClient(hwnd syscall.Handle, p *Point) {
|
func ScreenToClient(hwnd syscall.Handle, p *Point) {
|
||||||
_ScreenToClient.Call(uintptr(hwnd), uintptr(unsafe.Pointer(p)))
|
_ScreenToClient.Call(uintptr(hwnd), uintptr(unsafe.Pointer(p)))
|
||||||
issue34474KeepAlive(p)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowWindow(hwnd syscall.Handle, nCmdShow int32) {
|
func ShowWindow(hwnd syscall.Handle, nCmdShow int32) {
|
||||||
@@ -727,7 +720,6 @@ func ShowWindow(hwnd syscall.Handle, nCmdShow int32) {
|
|||||||
|
|
||||||
func TranslateMessage(m *Msg) {
|
func TranslateMessage(m *Msg) {
|
||||||
_TranslateMessage.Call(uintptr(unsafe.Pointer(m)))
|
_TranslateMessage.Call(uintptr(unsafe.Pointer(m)))
|
||||||
issue34474KeepAlive(m)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnregisterClass(cls uint16, hInst syscall.Handle) {
|
func UnregisterClass(cls uint16, hInst syscall.Handle) {
|
||||||
@@ -756,9 +748,3 @@ func (p *WindowPlacement) Set(Left, Top, Right, Bottom int) {
|
|||||||
p.rcNormalPosition.Right = int32(Right)
|
p.rcNormalPosition.Right = int32(Right)
|
||||||
p.rcNormalPosition.Bottom = int32(Bottom)
|
p.rcNormalPosition.Bottom = int32(Bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
// issue34474KeepAlive calls runtime.KeepAlive as a
|
|
||||||
// workaround for golang.org/issue/34474.
|
|
||||||
func issue34474KeepAlive(v interface{}) {
|
|
||||||
runtime.KeepAlive(v)
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-4
@@ -190,8 +190,7 @@ func createNativeWindow() (*window, error) {
|
|||||||
// If anything has changed it emits a ConfigEvent to notify the application.
|
// If anything has changed it emits a ConfigEvent to notify the application.
|
||||||
func (w *window) update() {
|
func (w *window) update() {
|
||||||
var triggerEvent bool
|
var triggerEvent bool
|
||||||
var r windows.Rect
|
r := windows.GetWindowRect(w.hwnd)
|
||||||
windows.GetWindowRect(w.hwnd, &r)
|
|
||||||
size := image.Point{
|
size := image.Point{
|
||||||
X: int(r.Right - r.Left - w.deltas.width),
|
X: int(r.Right - r.Left - w.deltas.width),
|
||||||
Y: int(r.Bottom - r.Top - w.deltas.height),
|
Y: int(r.Bottom - r.Top - w.deltas.height),
|
||||||
@@ -607,8 +606,7 @@ func (w *window) Configure(options []Option) {
|
|||||||
width := int32(w.config.Size.X)
|
width := int32(w.config.Size.X)
|
||||||
height := int32(w.config.Size.Y)
|
height := int32(w.config.Size.Y)
|
||||||
// Get the current window size and position.
|
// Get the current window size and position.
|
||||||
var wr windows.Rect
|
wr := windows.GetWindowRect(w.hwnd)
|
||||||
windows.GetWindowRect(w.hwnd, &wr)
|
|
||||||
// Set desired window size.
|
// Set desired window size.
|
||||||
wr.Right = wr.Left + width
|
wr.Right = wr.Left + width
|
||||||
wr.Bottom = wr.Top + height
|
wr.Bottom = wr.Top + height
|
||||||
|
|||||||
Reference in New Issue
Block a user