2023-08-01 16:56:58 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2022-05-27 13:38:45 +02:00
|
|
|
// SPDX-FileCopyrightText: 2002-2006 Marcus Geelnard
|
2023-08-03 18:11:13 +02:00
|
|
|
// SPDX-FileCopyrightText: 2006-2019 Camilla Löwy <elmindreda@glfw.org>
|
2022-05-27 13:38:45 +02:00
|
|
|
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
|
2022-04-19 17:49:43 +02:00
|
|
|
|
2023-10-03 16:07:53 +02:00
|
|
|
package glfw
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
import (
|
2022-07-04 05:55:34 +02:00
|
|
|
"errors"
|
2022-04-19 17:49:43 +02:00
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
"runtime"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"golang.org/x/sys/windows"
|
2022-05-29 12:13:31 +02:00
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
|
2023-03-30 19:07:35 +02:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/winver"
|
2022-04-19 17:49:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func (w *Window) getWindowStyle() uint32 {
|
|
|
|
var style uint32 = _WS_CLIPSIBLINGS | _WS_CLIPCHILDREN
|
|
|
|
|
|
|
|
if w.monitor != nil {
|
|
|
|
style |= _WS_POPUP
|
|
|
|
} else {
|
|
|
|
style |= _WS_SYSMENU | _WS_MINIMIZEBOX
|
|
|
|
if w.decorated {
|
|
|
|
style |= _WS_CAPTION
|
|
|
|
if w.resizable {
|
2022-09-01 15:48:36 +02:00
|
|
|
style |= _WS_THICKFRAME
|
|
|
|
if w.maxwidth == DontCare && w.maxheight == DontCare {
|
|
|
|
style |= _WS_MAXIMIZEBOX
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
style |= _WS_POPUP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return style
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) getWindowExStyle() uint32 {
|
|
|
|
var style uint32 = _WS_EX_APPWINDOW
|
|
|
|
|
|
|
|
if w.floating {
|
|
|
|
style |= _WS_EX_TOPMOST
|
|
|
|
}
|
|
|
|
|
|
|
|
return style
|
|
|
|
}
|
|
|
|
|
|
|
|
func chooseImage(images []*Image, width, height int) *Image {
|
|
|
|
var leastDiff uint = math.MaxUint32
|
|
|
|
var closest *Image
|
|
|
|
for _, image := range images {
|
|
|
|
currDiff := abs(image.Width*image.Height - width*height)
|
|
|
|
if currDiff < leastDiff {
|
|
|
|
closest = image
|
|
|
|
leastDiff = currDiff
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return closest
|
|
|
|
}
|
|
|
|
|
|
|
|
func createIcon(image *Image, xhot, yhot int, icon bool) (_HICON, error) {
|
|
|
|
var bi _BITMAPV5HEADER
|
|
|
|
bi.bV5Size = uint32(unsafe.Sizeof(bi))
|
|
|
|
bi.bV5Width = int32(image.Width)
|
|
|
|
bi.bV5Height = int32(-image.Height)
|
|
|
|
bi.bV5Planes = 1
|
|
|
|
bi.bV5BitCount = 32
|
|
|
|
bi.bV5Compression = _BI_BITFIELDS
|
|
|
|
bi.bV5RedMask = 0x00ff0000
|
|
|
|
bi.bV5GreenMask = 0x0000ff00
|
|
|
|
bi.bV5BlueMask = 0x000000ff
|
|
|
|
bi.bV5AlphaMask = 0xff000000
|
|
|
|
|
|
|
|
dc, err := _GetDC(0)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
defer _ReleaseDC(0, dc)
|
|
|
|
|
|
|
|
color, targetPtr, err := _CreateDIBSection(dc, &bi, _DIB_RGB_COLORS, 0, 0)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2022-09-09 18:52:46 +02:00
|
|
|
defer func() {
|
|
|
|
_ = _DeleteObject(_HGDIOBJ(color))
|
|
|
|
}()
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
mask, err := _CreateBitmap(int32(image.Width), int32(image.Height), 1, 1, nil)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2022-09-09 18:52:46 +02:00
|
|
|
defer func() {
|
|
|
|
_ = _DeleteObject(_HGDIOBJ(mask))
|
|
|
|
}()
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
source := image.Pixels
|
2022-10-29 18:29:54 +02:00
|
|
|
target := unsafe.Slice((*byte)(unsafe.Pointer(targetPtr)), len(source))
|
2022-04-19 17:49:43 +02:00
|
|
|
for i := 0; i < len(source)/4; i++ {
|
|
|
|
target[4*i] = source[4*i+2]
|
|
|
|
target[4*i+1] = source[4*i+1]
|
|
|
|
target[4*i+2] = source[4*i+0]
|
|
|
|
target[4*i+3] = source[4*i+3]
|
|
|
|
}
|
|
|
|
|
|
|
|
var iconInt32 int32
|
|
|
|
if icon {
|
|
|
|
iconInt32 = 1
|
|
|
|
}
|
|
|
|
ii := _ICONINFO{
|
|
|
|
fIcon: iconInt32,
|
|
|
|
xHotspot: uint32(xhot),
|
|
|
|
yHotspot: uint32(yhot),
|
|
|
|
hbmMask: mask,
|
|
|
|
hbmColor: color,
|
|
|
|
}
|
|
|
|
handle, err := _CreateIconIndirect(&ii)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getFullWindowSize(style uint32, exStyle uint32, contentWidth, contentHeight int, dpi uint32) (fullWidth, fullHeight int, err error) {
|
2022-05-29 12:13:31 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
2022-05-29 10:04:43 +02:00
|
|
|
return contentWidth, contentHeight, nil
|
|
|
|
}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
rect := _RECT{
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: int32(contentWidth),
|
|
|
|
bottom: int32(contentHeight),
|
|
|
|
}
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2022-04-19 17:49:43 +02:00
|
|
|
if err := _AdjustWindowRectExForDpi(&rect, style, false, exStyle, dpi); err != nil {
|
|
|
|
return 0, 0, err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := _AdjustWindowRectEx(&rect, style, false, exStyle); err != nil {
|
|
|
|
return 0, 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return int(rect.right - rect.left), int(rect.bottom - rect.top), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) applyAspectRatio(edge int, area *_RECT) error {
|
|
|
|
ratio := float32(w.numer) / float32(w.denom)
|
|
|
|
|
|
|
|
var dpi uint32 = _USER_DEFAULT_SCREEN_DPI
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
dpi = _GetDpiForWindow(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
xoff, yoff, err := getFullWindowSize(w.getWindowStyle(), w.getWindowExStyle(), 0, 0, dpi)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if edge == _WMSZ_LEFT || edge == _WMSZ_BOTTOMLEFT || edge == _WMSZ_RIGHT || edge == _WMSZ_BOTTOMRIGHT {
|
|
|
|
area.bottom = area.top + int32(yoff) + int32(float32(area.right-area.left-int32(xoff))/ratio)
|
|
|
|
} else if edge == _WMSZ_TOPLEFT || edge == _WMSZ_TOPRIGHT {
|
|
|
|
area.top = area.bottom - int32(yoff) - int32(float32(area.right-area.left-int32(xoff))/ratio)
|
|
|
|
} else if edge == _WMSZ_TOP || edge == _WMSZ_BOTTOM {
|
|
|
|
area.right = area.left + int32(xoff) + int32(float32(area.bottom-area.top-int32(yoff))*ratio)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) updateCursorImage() error {
|
|
|
|
if w.cursorMode == CursorNormal {
|
|
|
|
if w.cursor != nil {
|
2023-02-07 19:05:46 +01:00
|
|
|
_SetCursor(w.cursor.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
} else {
|
|
|
|
cursor, err := _LoadCursorW(0, _IDC_ARROW)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_SetCursor(cursor)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_SetCursor(0)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) clientToScreen(rect _RECT) (_RECT, error) {
|
|
|
|
point := _POINT{
|
|
|
|
x: rect.left,
|
|
|
|
y: rect.top,
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _ClientToScreen(w.platform.handle, &point); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return _RECT{}, err
|
|
|
|
}
|
|
|
|
rect.left = point.x
|
|
|
|
rect.top = point.y
|
|
|
|
|
|
|
|
point = _POINT{
|
|
|
|
x: rect.right,
|
|
|
|
y: rect.bottom,
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _ClientToScreen(w.platform.handle, &point); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return _RECT{}, err
|
|
|
|
}
|
|
|
|
rect.right = point.x
|
|
|
|
rect.bottom = point.y
|
|
|
|
return rect, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateClipRect(window *Window) error {
|
|
|
|
if window != nil {
|
2023-02-07 19:05:46 +01:00
|
|
|
clipRect, err := _GetClientRect(window.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
clipRect, err = window.clientToScreen(clipRect)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := _ClipCursor(&clipRect); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := _ClipCursor(nil); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) enableRawMouseMotion() error {
|
|
|
|
rid := []_RAWINPUTDEVICE{
|
|
|
|
{
|
|
|
|
usUsagePage: 0x01,
|
|
|
|
usUsage: 0x02,
|
|
|
|
dwFlags: 0,
|
2023-02-07 19:05:46 +01:00
|
|
|
hwndTarget: w.platform.handle,
|
2022-04-19 17:49:43 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
return _RegisterRawInputDevices(rid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) disableRawMouseMotion() error {
|
|
|
|
rid := []_RAWINPUTDEVICE{
|
|
|
|
{
|
|
|
|
usUsagePage: 0x01,
|
|
|
|
usUsage: 0x02,
|
|
|
|
dwFlags: _RIDEV_REMOVE,
|
|
|
|
hwndTarget: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return _RegisterRawInputDevices(rid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) disableCursor() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
_glfw.platformWindow.disabledCursorWindow = w
|
2022-04-19 17:49:43 +02:00
|
|
|
x, y, err := w.platformGetCursorPos()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
_glfw.platformWindow.restoreCursorPosX, _glfw.platformWindow.restoreCursorPosY = x, y
|
2022-04-19 17:49:43 +02:00
|
|
|
if err := w.updateCursorImage(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.centerCursorInContentArea(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := updateClipRect(w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if w.rawMouseMotion {
|
|
|
|
if err := w.enableRawMouseMotion(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) enableCursor() error {
|
|
|
|
if w.rawMouseMotion {
|
|
|
|
if err := w.disableRawMouseMotion(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
_glfw.platformWindow.disabledCursorWindow = nil
|
2022-04-19 17:49:43 +02:00
|
|
|
if err := updateClipRect(nil); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := w.platformSetCursorPos(_glfw.platformWindow.restoreCursorPosX, _glfw.platformWindow.restoreCursorPosY); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.updateCursorImage(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) cursorInContentArea() (bool, error) {
|
2022-05-31 17:35:37 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
pos, err := _GetCursorPos()
|
|
|
|
if err != nil {
|
2022-07-04 05:55:34 +02:00
|
|
|
if errors.Is(err, windows.ERROR_ACCESS_DENIED) {
|
|
|
|
return false, nil
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
return false, err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if _WindowFromPoint(pos) != w.platform.handle {
|
2022-04-19 17:49:43 +02:00
|
|
|
return false, nil
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
area, err := _GetClientRect(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
area, err = w.clientToScreen(area)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return _PtInRect(&area, pos), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) updateWindowStyles() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
s, err := _GetWindowLongW(w.platform.handle, _GWL_STYLE)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
style := uint32(s)
|
|
|
|
style &^= _WS_OVERLAPPEDWINDOW | _WS_POPUP
|
|
|
|
style |= w.getWindowStyle()
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
rect, err := _GetClientRect(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _AdjustWindowRectExForDpi(&rect, style, false, w.getWindowExStyle(), _GetDpiForWindow(w.platform.handle)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := _AdjustWindowRectEx(&rect, style, false, w.getWindowExStyle()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rect, err = w.clientToScreen(rect)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if _, err := _SetWindowLongW(w.platform.handle, _GWL_STYLE, int32(style)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPos(w.platform.handle, _HWND_TOP, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, _SWP_FRAMECHANGED|_SWP_NOACTIVATE|_SWP_NOZORDER); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) updateFramebufferTransparency() error {
|
2023-03-30 19:07:35 +02:00
|
|
|
if !winver.IsWindowsVistaOrGreater() {
|
2022-04-19 17:49:43 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
composition, err := _DwmIsCompositionEnabled()
|
|
|
|
if err != nil {
|
2022-06-03 06:59:16 +02:00
|
|
|
// Ignore an error from DWM functions as they might not be implemented e.g. on Proton (#2113).
|
|
|
|
return nil
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
if !composition {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var opaque bool
|
2023-03-30 19:07:35 +02:00
|
|
|
if !winver.IsWindows8OrGreater() {
|
2022-04-19 17:49:43 +02:00
|
|
|
_, opaque, err = _DwmGetColorizationColor()
|
|
|
|
if err != nil {
|
2022-06-03 06:59:16 +02:00
|
|
|
// Ignore an error from DWM functions as they might not be implemented e.g. on Proton (#2113).
|
|
|
|
return nil
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows8OrGreater() || !opaque {
|
2022-04-19 17:49:43 +02:00
|
|
|
region, err := _CreateRectRgn(0, 0, -1, -1)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-09 18:52:46 +02:00
|
|
|
defer func() {
|
|
|
|
_ = _DeleteObject(_HGDIOBJ(region))
|
|
|
|
}()
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
bb := _DWM_BLURBEHIND{
|
|
|
|
dwFlags: _DWM_BB_ENABLE | _DWM_BB_BLURREGION,
|
|
|
|
hRgnBlur: region,
|
|
|
|
fEnable: 1, // true
|
|
|
|
}
|
2022-06-03 06:59:16 +02:00
|
|
|
|
|
|
|
// Ignore an error from DWM functions as they might not be implemented e.g. on Proton (#2113).
|
2023-02-07 19:05:46 +01:00
|
|
|
_ = _DwmEnableBlurBehindWindow(w.platform.handle, &bb)
|
2022-04-19 17:49:43 +02:00
|
|
|
} else {
|
|
|
|
// HACK: Disable framebuffer transparency on Windows 7 when the
|
|
|
|
// colorization color is opaque, because otherwise the window
|
|
|
|
// contents is blended additively with the previous frame instead
|
|
|
|
// of replacing it
|
|
|
|
bb := _DWM_BLURBEHIND{
|
|
|
|
dwFlags: _DWM_BB_ENABLE,
|
|
|
|
}
|
2022-06-03 06:59:16 +02:00
|
|
|
|
|
|
|
// Ignore an error from DWM functions as they might not be implemented e.g. on Proton (#2113).
|
2023-02-07 19:05:46 +01:00
|
|
|
_ = _DwmEnableBlurBehindWindow(w.platform.handle, &bb)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getKeyMods() ModifierKey {
|
|
|
|
var mods ModifierKey
|
|
|
|
if uint16(_GetKeyState(_VK_SHIFT))&0x8000 != 0 {
|
|
|
|
mods |= ModShift
|
|
|
|
}
|
|
|
|
if uint16(_GetKeyState(_VK_CONTROL))&0x8000 != 0 {
|
|
|
|
mods |= ModControl
|
|
|
|
}
|
|
|
|
if uint16(_GetKeyState(_VK_MENU))&0x8000 != 0 {
|
|
|
|
mods |= ModAlt
|
|
|
|
}
|
|
|
|
if uint16(_GetKeyState(_VK_LWIN)|_GetKeyState(_VK_RWIN))&0x8000 != 0 {
|
|
|
|
mods |= ModSuper
|
|
|
|
}
|
|
|
|
if _GetKeyState(_VK_CAPITAL)&1 != 0 {
|
|
|
|
mods |= ModCapsLock
|
|
|
|
}
|
|
|
|
if _GetKeyState(_VK_NUMLOCK)&1 != 0 {
|
|
|
|
mods |= ModNumLock
|
|
|
|
}
|
|
|
|
return mods
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) fitToMonitor() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
mi, ok := _GetMonitorInfoW(w.monitor.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var hWndInsertAfter windows.HWND
|
|
|
|
if w.floating {
|
|
|
|
hWndInsertAfter = _HWND_TOPMOST
|
|
|
|
} else {
|
|
|
|
hWndInsertAfter = _HWND_NOTOPMOST
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPos(w.platform.handle, hWndInsertAfter,
|
2022-04-19 17:49:43 +02:00
|
|
|
mi.rcMonitor.left,
|
|
|
|
mi.rcMonitor.top,
|
|
|
|
mi.rcMonitor.right-mi.rcMonitor.left,
|
|
|
|
mi.rcMonitor.bottom-mi.rcMonitor.top,
|
|
|
|
_SWP_NOZORDER|_SWP_NOACTIVATE|_SWP_NOCOPYBITS); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) acquireMonitor() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
if _glfw.platformWindow.acquiredMonitorCount == 0 {
|
2022-04-19 17:49:43 +02:00
|
|
|
_SetThreadExecutionState(_ES_CONTINUOUS | _ES_DISPLAY_REQUIRED)
|
|
|
|
|
|
|
|
// HACK: When mouse trails are enabled the cursor becomes invisible when
|
|
|
|
// the OpenGL ICD switches to page flipping
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindowsXPOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SystemParametersInfoW(_SPI_GETMOUSETRAILS, 0, uintptr(unsafe.Pointer(&_glfw.platformWindow.mouseTrailSize)), 0); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := _SystemParametersInfoW(_SPI_SETMOUSETRAILS, 0, 0, 0); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if w.monitor.window == nil {
|
2023-02-07 19:05:46 +01:00
|
|
|
_glfw.platformWindow.acquiredMonitorCount++
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := w.monitor.setVideoModeWin32(&w.videoMode); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
w.monitor.inputMonitorWindow(w)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) releaseMonitor() error {
|
|
|
|
if w.monitor.window != w {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
_glfw.platformWindow.acquiredMonitorCount--
|
|
|
|
if _glfw.platformWindow.acquiredMonitorCount == 0 {
|
2022-04-19 17:49:43 +02:00
|
|
|
_SetThreadExecutionState(_ES_CONTINUOUS)
|
|
|
|
|
|
|
|
// HACK: Restore mouse trail length saved in acquireMonitor
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindowsXPOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SystemParametersInfoW(_SPI_SETMOUSETRAILS, _glfw.platformWindow.mouseTrailSize, 0, 0); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
w.monitor.inputMonitorWindow(nil)
|
|
|
|
w.monitor.restoreVideoModeWin32()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-20 16:09:10 +02:00
|
|
|
func (w *Window) maximizeWindowManually() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
mi, _ := _GetMonitorInfoW(_MonitorFromWindow(w.platform.handle, _MONITOR_DEFAULTTONEAREST))
|
2022-05-20 16:09:10 +02:00
|
|
|
|
|
|
|
rect := mi.rcWork
|
|
|
|
|
|
|
|
if w.maxwidth != DontCare && w.maxheight != DontCare {
|
|
|
|
if rect.right-rect.left > int32(w.maxwidth) {
|
|
|
|
rect.right = rect.left + int32(w.maxwidth)
|
|
|
|
}
|
|
|
|
if rect.bottom-rect.top > int32(w.maxheight) {
|
|
|
|
rect.bottom = rect.top + int32(w.maxheight)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
s, err := _GetWindowLongW(w.platform.handle, _GWL_STYLE)
|
2022-05-20 16:09:10 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
style := uint32(s)
|
|
|
|
style |= _WS_MAXIMIZE
|
2023-02-07 19:05:46 +01:00
|
|
|
if _, err := _SetWindowLongW(w.platform.handle, _GWL_STYLE, int32(style)); err != nil {
|
2022-05-20 16:09:10 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if w.decorated {
|
2023-02-07 19:05:46 +01:00
|
|
|
s, err := _GetWindowLongW(w.platform.handle, _GWL_EXSTYLE)
|
2022-05-20 16:09:10 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
exStyle := uint32(s)
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
dpi := _GetDpiForWindow(w.platform.handle)
|
2022-05-20 16:09:10 +02:00
|
|
|
if err := _AdjustWindowRectExForDpi(&rect, style, false, exStyle, dpi); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m, err := _GetSystemMetricsForDpi(_SM_CYCAPTION, dpi)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_OffsetRect(&rect, 0, m)
|
|
|
|
} else {
|
|
|
|
if err := _AdjustWindowRectEx(&rect, style, false, exStyle); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m, err := _GetSystemMetrics(_SM_CYCAPTION)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_OffsetRect(&rect, 0, m)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rect.bottom > mi.rcWork.bottom {
|
|
|
|
rect.bottom = mi.rcWork.bottom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPos(w.platform.handle, _HWND_TOP,
|
2022-05-20 16:09:10 +02:00
|
|
|
rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
|
|
|
|
_SWP_NOACTIVATE|_SWP_NOZORDER|_SWP_FRAMECHANGED); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
func windowProc(hWnd windows.HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) uintptr /*_LRESULT*/ {
|
2022-05-24 19:10:32 +02:00
|
|
|
window := handleToWindow[hWnd]
|
2022-04-19 17:49:43 +02:00
|
|
|
if window == nil {
|
|
|
|
// This is the message handling for the hidden helper window
|
|
|
|
// and for a regular window during its initial creation
|
|
|
|
switch uMsg {
|
|
|
|
case _WM_NCCREATE:
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2022-04-19 17:49:43 +02:00
|
|
|
cs := (*_CREATESTRUCTW)(unsafe.Pointer(lParam))
|
|
|
|
wndconfig := (*wndconfig)(cs.lpCreateParams)
|
|
|
|
|
|
|
|
// On per-monitor DPI aware V1 systems, only enable
|
|
|
|
// non-client scaling for windows that scale the client area
|
|
|
|
// We need WM_GETDPISCALEDSIZE from V2 to keep the client
|
|
|
|
// area static when the non-client area is scaled
|
|
|
|
if wndconfig != nil && wndconfig.scaleToMonitor {
|
|
|
|
if err := _EnableNonClientDpiScaling(hWnd); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case _WM_DISPLAYCHANGE:
|
|
|
|
if err := pollMonitorsWin32(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return uintptr(_DefWindowProcW(hWnd, uMsg, wParam, lParam))
|
|
|
|
}
|
|
|
|
|
|
|
|
switch uMsg {
|
|
|
|
case _WM_MOUSEACTIVATE:
|
|
|
|
// HACK: Postpone cursor disabling when the window was activated by
|
|
|
|
// clicking a caption button
|
|
|
|
if _HIWORD(uint32(lParam)) == _WM_LBUTTONDOWN {
|
|
|
|
if _LOWORD(uint32(lParam)) != _HTCLIENT {
|
2023-02-07 19:05:46 +01:00
|
|
|
window.platform.frameAction = true
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case _WM_CAPTURECHANGED:
|
|
|
|
// HACK: Disable the cursor once the caption button action has been
|
|
|
|
// completed or cancelled
|
2023-02-07 19:05:46 +01:00
|
|
|
if lParam == 0 && window.platform.frameAction {
|
2022-04-19 17:49:43 +02:00
|
|
|
if window.cursorMode == CursorDisabled {
|
|
|
|
if err := window.disableCursor(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
window.platform.frameAction = false
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case _WM_SETFOCUS:
|
|
|
|
window.inputWindowFocus(true)
|
|
|
|
|
|
|
|
// HACK: Do not disable cursor while the user is interacting with
|
|
|
|
// a caption button
|
2023-02-07 19:05:46 +01:00
|
|
|
if window.platform.frameAction {
|
2022-04-19 17:49:43 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if window.cursorMode == CursorDisabled {
|
|
|
|
if err := window.disableCursor(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_KILLFOCUS:
|
|
|
|
if window.cursorMode == CursorDisabled {
|
|
|
|
if err := window.enableCursor(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if window.monitor != nil && window.autoIconify {
|
|
|
|
window.platformIconifyWindow()
|
|
|
|
}
|
|
|
|
|
|
|
|
window.inputWindowFocus(false)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_SYSCOMMAND:
|
|
|
|
switch wParam & 0xfff0 {
|
|
|
|
case _SC_SCREENSAVE, _SC_MONITORPOWER:
|
|
|
|
if window.monitor != nil {
|
|
|
|
// We are running in full screen mode, so disallow
|
|
|
|
// screen saver and screen blanking
|
|
|
|
return 0
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
// User trying to access application menu using ALT?
|
|
|
|
case _SC_KEYMENU:
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
case _WM_CLOSE:
|
|
|
|
window.inputWindowCloseRequest()
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_INPUTLANGCHANGE:
|
2022-08-13 06:33:52 +02:00
|
|
|
updateKeyNamesWin32()
|
|
|
|
return 0
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
case _WM_CHAR, _WM_SYSCHAR:
|
|
|
|
if wParam >= 0xd800 && wParam <= 0xdbff {
|
2023-02-07 19:05:46 +01:00
|
|
|
window.platform.highSurrogate = uint16(wParam)
|
2022-04-19 17:49:43 +02:00
|
|
|
} else {
|
|
|
|
var codepoint rune
|
|
|
|
|
|
|
|
if wParam >= 0xdc00 && wParam <= 0xdfff {
|
2023-02-07 19:05:46 +01:00
|
|
|
if window.platform.highSurrogate != 0 {
|
|
|
|
codepoint += (rune(window.platform.highSurrogate) - 0xd800) << 10
|
2022-04-19 17:49:43 +02:00
|
|
|
codepoint += (rune(wParam) & 0xffff) - 0xdc00
|
|
|
|
codepoint += 0x10000
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
codepoint = rune(wParam) & 0xffff
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
window.platform.highSurrogate = 0
|
2022-04-19 17:49:43 +02:00
|
|
|
window.inputChar(codepoint, getKeyMods(), uMsg != _WM_SYSCHAR)
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_UNICHAR:
|
|
|
|
if wParam == _UNICODE_NOCHAR {
|
|
|
|
// WM_UNICHAR is not sent by Windows, but is sent by some
|
|
|
|
// third-party input method engine
|
|
|
|
// Returning TRUE here announces support for this message
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
window.inputChar(rune(wParam), getKeyMods(), true)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_KEYDOWN, _WM_SYSKEYDOWN, _WM_KEYUP, _WM_SYSKEYUP:
|
|
|
|
action := Press
|
|
|
|
if _HIWORD(uint32(lParam))&_KF_UP != 0 {
|
|
|
|
action = Release
|
|
|
|
}
|
|
|
|
mods := getKeyMods()
|
|
|
|
|
|
|
|
scancode := uint32((_HIWORD(uint32(lParam)) & (_KF_EXTENDED | 0xff)))
|
|
|
|
if scancode == 0 {
|
2022-05-29 12:13:31 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
2022-05-24 17:57:04 +02:00
|
|
|
break
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
// NOTE: Some synthetic key messages have a scancode of zero
|
|
|
|
// HACK: Map the virtual key back to a usable scancode
|
|
|
|
scancode = _MapVirtualKeyW(uint32(wParam), _MAPVK_VK_TO_VSC)
|
|
|
|
}
|
|
|
|
|
2022-08-07 07:32:00 +02:00
|
|
|
// HACK: Alt+PrtSc has a different scancode than just PrtSc
|
|
|
|
if scancode == 0x54 {
|
|
|
|
scancode = 0x137
|
|
|
|
}
|
|
|
|
|
|
|
|
// HACK: Ctrl+Pause has a different scancode than just Pause
|
|
|
|
if scancode == 0x146 {
|
|
|
|
scancode = 0x45
|
|
|
|
}
|
|
|
|
|
|
|
|
// HACK: CJK IME sets the extended bit for right Shift
|
|
|
|
if scancode == 0x136 {
|
|
|
|
scancode = 0x36
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
key := _glfw.platformWindow.keycodes[scancode]
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
// The Ctrl keys require special handling
|
|
|
|
if wParam == _VK_CONTROL {
|
|
|
|
if _HIWORD(uint32(lParam))&_KF_EXTENDED != 0 {
|
|
|
|
// Right side keys have the extended key bit set
|
|
|
|
key = KeyRightControl
|
|
|
|
} else {
|
|
|
|
// NOTE: Alt Gr sends Left Ctrl followed by Right Alt
|
|
|
|
// HACK: We only want one event for Alt Gr, so if we detect
|
|
|
|
// this sequence we discard this Left Ctrl message now
|
|
|
|
// and later report Right Alt normally
|
|
|
|
var next _MSG
|
|
|
|
time := _GetMessageTime()
|
|
|
|
if _PeekMessageW(&next, 0, 0, 0, _PM_NOREMOVE) {
|
|
|
|
if next.message == _WM_KEYDOWN ||
|
|
|
|
next.message == _WM_SYSKEYDOWN ||
|
|
|
|
next.message == _WM_KEYUP ||
|
|
|
|
next.message == _WM_SYSKEYUP {
|
|
|
|
if next.wParam == _VK_MENU && (_HIWORD(uint32(next.lParam))&_KF_EXTENDED) != 0 && next.time == uint32(time) {
|
|
|
|
// Next message is Right Alt down so discard this
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a regular Left Ctrl message
|
|
|
|
key = KeyLeftControl
|
|
|
|
}
|
|
|
|
} else if wParam == _VK_PROCESSKEY {
|
|
|
|
// IME notifies that keys have been filtered by setting the
|
|
|
|
// virtual key-code to VK_PROCESSKEY
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if action == Release && wParam == _VK_SHIFT {
|
|
|
|
// HACK: Release both Shift keys on Shift up event, as when both
|
|
|
|
// are pressed the first release does not emit any event
|
|
|
|
// NOTE: The other half of this is in _glfwPlatformPollEvents
|
|
|
|
window.inputKey(KeyLeftShift, int(scancode), action, mods)
|
|
|
|
window.inputKey(KeyRightShift, int(scancode), action, mods)
|
|
|
|
} else if wParam == _VK_SNAPSHOT {
|
|
|
|
// HACK: Key down is not reported for the Print Screen key
|
|
|
|
window.inputKey(key, int(scancode), Press, mods)
|
|
|
|
window.inputKey(key, int(scancode), Release, mods)
|
|
|
|
} else {
|
|
|
|
window.inputKey(key, int(scancode), action, mods)
|
|
|
|
}
|
|
|
|
|
|
|
|
case _WM_LBUTTONDOWN, _WM_RBUTTONDOWN, _WM_MBUTTONDOWN, _WM_XBUTTONDOWN, _WM_LBUTTONUP, _WM_RBUTTONUP, _WM_MBUTTONUP, _WM_XBUTTONUP:
|
|
|
|
var button MouseButton
|
|
|
|
if uMsg == _WM_LBUTTONDOWN || uMsg == _WM_LBUTTONUP {
|
|
|
|
button = MouseButtonLeft
|
|
|
|
} else if uMsg == _WM_RBUTTONDOWN || uMsg == _WM_RBUTTONUP {
|
|
|
|
button = MouseButtonRight
|
|
|
|
} else if uMsg == _WM_MBUTTONDOWN || uMsg == _WM_MBUTTONUP {
|
|
|
|
button = MouseButtonMiddle
|
|
|
|
} else if _GET_XBUTTON_WPARAM(wParam) == _XBUTTON1 {
|
|
|
|
button = MouseButton4
|
|
|
|
} else {
|
|
|
|
button = MouseButton5
|
|
|
|
}
|
|
|
|
|
|
|
|
var action Action
|
|
|
|
if uMsg == _WM_LBUTTONDOWN || uMsg == _WM_RBUTTONDOWN || uMsg == _WM_MBUTTONDOWN || uMsg == _WM_XBUTTONDOWN {
|
|
|
|
action = Press
|
|
|
|
} else {
|
|
|
|
action = Release
|
|
|
|
}
|
|
|
|
|
|
|
|
var i MouseButton
|
|
|
|
for i = 0; i <= MouseButtonLast; i++ {
|
|
|
|
if window.mouseButtons[i] == Press {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if i > MouseButtonLast {
|
|
|
|
_SetCapture(hWnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
window.inputMouseClick(button, action, getKeyMods())
|
|
|
|
|
|
|
|
for i = 0; i <= MouseButtonLast; i++ {
|
|
|
|
if window.mouseButtons[i] == Press {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if i > MouseButtonLast {
|
|
|
|
if err := _ReleaseCapture(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if uMsg == _WM_XBUTTONDOWN || uMsg == _WM_XBUTTONUP {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_MOUSEMOVE:
|
|
|
|
x := _GET_X_LPARAM(lParam)
|
|
|
|
y := _GET_Y_LPARAM(lParam)
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if !window.platform.cursorTracked {
|
2022-04-19 17:49:43 +02:00
|
|
|
var tme _TRACKMOUSEEVENT
|
|
|
|
tme.cbSize = uint32(unsafe.Sizeof(tme))
|
|
|
|
tme.dwFlags = _TME_LEAVE
|
2023-02-07 19:05:46 +01:00
|
|
|
tme.hwndTrack = window.platform.handle
|
2022-04-19 17:49:43 +02:00
|
|
|
if err := _TrackMouseEvent(&tme); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
window.platform.cursorTracked = true
|
2022-04-19 17:49:43 +02:00
|
|
|
window.inputCursorEnter(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
if window.cursorMode == CursorDisabled {
|
2023-02-07 19:05:46 +01:00
|
|
|
dx := x - window.platform.lastCursorPosX
|
|
|
|
dy := y - window.platform.lastCursorPosY
|
2022-04-19 17:49:43 +02:00
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if _glfw.platformWindow.disabledCursorWindow != window {
|
2022-04-19 17:49:43 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
if window.rawMouseMotion {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
window.inputCursorPos(window.virtualCursorPosX+float64(dx), window.virtualCursorPosY+float64(dy))
|
|
|
|
} else {
|
|
|
|
window.inputCursorPos(float64(x), float64(y))
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
window.platform.lastCursorPosX = x
|
|
|
|
window.platform.lastCursorPosY = y
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_INPUT:
|
2023-02-07 19:05:46 +01:00
|
|
|
if _glfw.platformWindow.disabledCursorWindow != window {
|
2022-04-19 17:49:43 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
if !window.rawMouseMotion {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
ri := _HRAWINPUT(lParam)
|
|
|
|
var size uint32
|
|
|
|
if _, err := _GetRawInputData(ri, _RID_INPUT, nil, &size); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if size > uint32(len(_glfw.platformWindow.rawInput)) {
|
|
|
|
_glfw.platformWindow.rawInput = make([]byte, size)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
size = uint32(len(_glfw.platformWindow.rawInput))
|
|
|
|
if _, err := _GetRawInputData(ri, _RID_INPUT, unsafe.Pointer(&_glfw.platformWindow.rawInput[0]), &size); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
// TODO: break?
|
|
|
|
}
|
|
|
|
|
|
|
|
var dx, dy int
|
2023-02-07 19:05:46 +01:00
|
|
|
data := (*_RAWINPUT)(unsafe.Pointer(&_glfw.platformWindow.rawInput[0]))
|
2022-04-19 17:49:43 +02:00
|
|
|
if data.mouse.usFlags&_MOUSE_MOVE_ABSOLUTE != 0 {
|
2023-02-07 19:05:46 +01:00
|
|
|
dx = int(data.mouse.lLastX) - window.platform.lastCursorPosX
|
|
|
|
dy = int(data.mouse.lLastY) - window.platform.lastCursorPosY
|
2022-04-19 17:49:43 +02:00
|
|
|
} else {
|
|
|
|
dx = int(data.mouse.lLastX)
|
|
|
|
dy = int(data.mouse.lLastY)
|
|
|
|
}
|
|
|
|
|
|
|
|
window.inputCursorPos(window.virtualCursorPosX+float64(dx), window.virtualCursorPosY+float64(dy))
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
window.platform.lastCursorPosX += dx
|
|
|
|
window.platform.lastCursorPosY += dy
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
case _WM_MOUSELEAVE:
|
2023-02-07 19:05:46 +01:00
|
|
|
window.platform.cursorTracked = false
|
2022-04-19 17:49:43 +02:00
|
|
|
window.inputCursorEnter(false)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_MOUSEWHEEL:
|
|
|
|
window.inputScroll(0, float64(int16(_HIWORD(uint32(wParam))))/_WHEEL_DELTA)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_MOUSEHWHEEL:
|
|
|
|
// This message is only sent on Windows Vista and later
|
|
|
|
// NOTE: The X-axis is inverted for consistency with macOS and X11
|
|
|
|
window.inputScroll(float64(-(int16(_HIWORD(uint32(wParam))))/_WHEEL_DELTA), 0)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_ENTERSIZEMOVE, _WM_ENTERMENULOOP:
|
2023-02-07 19:05:46 +01:00
|
|
|
if window.platform.frameAction {
|
2022-04-19 17:49:43 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// HACK: Enable the cursor while the user is moving or
|
|
|
|
// resizing the window or using the window menu
|
|
|
|
if window.cursorMode == CursorDisabled {
|
|
|
|
if err := window.enableCursor(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case _WM_EXITSIZEMOVE, _WM_EXITMENULOOP:
|
2023-02-07 19:05:46 +01:00
|
|
|
if window.platform.frameAction {
|
2022-04-19 17:49:43 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// HACK: Disable the cursor once the user is done moving or
|
|
|
|
// resizing the window or using the menu
|
|
|
|
if window.cursorMode == CursorDisabled {
|
|
|
|
if err := window.disableCursor(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case _WM_SIZE:
|
|
|
|
width := int(_LOWORD(uint32(lParam)))
|
|
|
|
height := int(_HIWORD(uint32(lParam)))
|
|
|
|
iconified := wParam == _SIZE_MINIMIZED
|
2023-02-07 19:05:46 +01:00
|
|
|
maximized := wParam == _SIZE_MAXIMIZED || (window.platform.maximized && wParam != _SIZE_RESTORED)
|
2022-04-19 17:49:43 +02:00
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if _glfw.platformWindow.disabledCursorWindow == window {
|
2022-04-19 17:49:43 +02:00
|
|
|
if err := updateClipRect(window); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if window.platform.iconified != iconified {
|
2022-04-19 17:49:43 +02:00
|
|
|
window.inputWindowIconify(iconified)
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if window.platform.maximized != maximized {
|
2022-04-19 17:49:43 +02:00
|
|
|
window.inputWindowMaximize(maximized)
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if width != window.platform.width || height != window.platform.height {
|
|
|
|
window.platform.width = width
|
|
|
|
window.platform.height = height
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
window.inputFramebufferSize(width, height)
|
|
|
|
window.inputWindowSize(width, height)
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if window.monitor != nil && window.platform.iconified != iconified {
|
2022-04-19 17:49:43 +02:00
|
|
|
if iconified {
|
|
|
|
if err := window.releaseMonitor(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := window.acquireMonitor(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if err := window.fitToMonitor(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
window.platform.iconified = iconified
|
|
|
|
window.platform.maximized = maximized
|
2022-04-19 17:49:43 +02:00
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_MOVE:
|
2023-02-07 19:05:46 +01:00
|
|
|
if _glfw.platformWindow.disabledCursorWindow == window {
|
2022-04-19 17:49:43 +02:00
|
|
|
if err := updateClipRect(window); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as
|
|
|
|
// those macros do not handle negative window positions correctly
|
|
|
|
window.inputWindowPos(_GET_X_LPARAM(lParam), _GET_Y_LPARAM(lParam))
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_SIZING:
|
|
|
|
if window.numer == DontCare || window.denom == DontCare {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := window.applyAspectRatio(int(wParam), (*_RECT)(unsafe.Pointer(lParam))); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
|
|
|
|
case _WM_GETMINMAXINFO:
|
|
|
|
var dpi uint32 = _USER_DEFAULT_SCREEN_DPI
|
|
|
|
mmi := (*_MINMAXINFO)(unsafe.Pointer(lParam))
|
|
|
|
|
|
|
|
if window.monitor != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
dpi = _GetDpiForWindow(window.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
xoff, yoff, err := getFullWindowSize(window.getWindowStyle(), window.getWindowExStyle(), 0, 0, dpi)
|
|
|
|
if err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if window.minwidth != DontCare && window.minheight != DontCare {
|
|
|
|
mmi.ptMinTrackSize.x = int32(window.minwidth + xoff)
|
|
|
|
mmi.ptMinTrackSize.y = int32(window.minheight + yoff)
|
|
|
|
}
|
|
|
|
|
|
|
|
if window.maxwidth != DontCare && window.maxheight != DontCare {
|
|
|
|
mmi.ptMaxTrackSize.x = int32(window.maxwidth + xoff)
|
|
|
|
mmi.ptMaxTrackSize.y = int32(window.maxheight + yoff)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !window.decorated {
|
2023-02-07 19:05:46 +01:00
|
|
|
mh := _MonitorFromWindow(window.platform.handle, _MONITOR_DEFAULTTONEAREST)
|
2022-04-19 17:49:43 +02:00
|
|
|
mi, _ := _GetMonitorInfoW(mh)
|
|
|
|
|
|
|
|
mmi.ptMaxPosition.x = mi.rcWork.left - mi.rcMonitor.left
|
|
|
|
mmi.ptMaxPosition.y = mi.rcWork.top - mi.rcMonitor.top
|
|
|
|
mmi.ptMaxSize.x = mi.rcWork.right - mi.rcWork.left
|
|
|
|
mmi.ptMaxSize.y = mi.rcWork.bottom - mi.rcWork.top
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_PAINT:
|
|
|
|
window.inputWindowDamage()
|
|
|
|
|
|
|
|
case _WM_ERASEBKGND:
|
|
|
|
return 1
|
|
|
|
|
|
|
|
case _WM_NCACTIVATE, _WM_NCPAINT:
|
|
|
|
// Prevent title bar from being drawn after restoring a minimized
|
|
|
|
// undecorated window
|
|
|
|
if !window.decorated {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
case _WM_DWMCOMPOSITIONCHANGED, _WM_DWMCOLORIZATIONCOLORCHANGED:
|
2023-02-07 19:05:46 +01:00
|
|
|
if window.platform.transparent {
|
2022-04-19 17:49:43 +02:00
|
|
|
if err := window.updateFramebufferTransparency(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case _WM_GETDPISCALEDSIZE:
|
2023-02-07 19:05:46 +01:00
|
|
|
if window.platform.scaleToMonitor {
|
2022-04-19 17:49:43 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust the window size to keep the content area size constant
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10CreatorsUpdateOrGreater() {
|
2022-04-19 17:49:43 +02:00
|
|
|
var source, target _RECT
|
|
|
|
size := (*_SIZE)(unsafe.Pointer(lParam))
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _AdjustWindowRectExForDpi(&source, window.getWindowStyle(), false, window.getWindowExStyle(), _GetDpiForWindow(window.platform.handle)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if err := _AdjustWindowRectExForDpi(&target, window.getWindowStyle(), false, window.getWindowExStyle(), uint32(_LOWORD(uint32(wParam)))); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
size.cx += (target.right - target.left) - (source.right - source.left)
|
|
|
|
size.cy += (target.bottom - target.top) - (source.bottom - source.top)
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
case _WM_DPICHANGED:
|
|
|
|
xscale := float32(_HIWORD(uint32(wParam))) / float32(_USER_DEFAULT_SCREEN_DPI)
|
|
|
|
yscale := float32(_LOWORD(uint32(wParam))) / float32(_USER_DEFAULT_SCREEN_DPI)
|
|
|
|
|
|
|
|
// Resize windowed mode windows that either permit rescaling or that
|
|
|
|
// need it to compensate for non-client area scaling
|
2023-03-30 19:07:35 +02:00
|
|
|
if window.monitor == nil && (window.platform.scaleToMonitor || winver.IsWindows10CreatorsUpdateOrGreater()) {
|
2022-04-19 17:49:43 +02:00
|
|
|
suggested := (*_RECT)(unsafe.Pointer(lParam))
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPos(window.platform.handle, _HWND_TOP,
|
2022-04-19 17:49:43 +02:00
|
|
|
suggested.left,
|
|
|
|
suggested.top,
|
|
|
|
suggested.right-suggested.left,
|
|
|
|
suggested.bottom-suggested.top,
|
|
|
|
_SWP_NOACTIVATE|_SWP_NOZORDER); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.inputWindowContentScale(xscale, yscale)
|
|
|
|
|
|
|
|
case _WM_SETCURSOR:
|
|
|
|
if _LOWORD(uint32(lParam)) == _HTCLIENT {
|
|
|
|
if err := window.updateCursorImage(); err != nil {
|
|
|
|
_glfw.errors = append(_glfw.errors, err)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
case _WM_DROPFILES:
|
|
|
|
drop := _HDROP(wParam)
|
|
|
|
|
|
|
|
count := _DragQueryFileW(drop, 0xffffffff, nil)
|
|
|
|
paths := make([]string, count)
|
|
|
|
|
|
|
|
// Move the mouse to the position of the drop
|
|
|
|
pt, _ := _DragQueryPoint(drop)
|
|
|
|
window.inputCursorPos(float64(pt.x), float64(pt.y))
|
|
|
|
|
|
|
|
for i := range paths {
|
|
|
|
length := _DragQueryFileW(drop, uint32(i), nil)
|
|
|
|
buffer := make([]uint16, length+1)
|
|
|
|
_DragQueryFileW(drop, uint32(i), buffer)
|
|
|
|
paths[i] = windows.UTF16ToString(buffer)
|
|
|
|
}
|
|
|
|
|
|
|
|
window.inputDrop(paths)
|
|
|
|
|
|
|
|
_DragFinish(drop)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return uintptr(_DefWindowProcW(hWnd, uMsg, wParam, lParam))
|
|
|
|
}
|
|
|
|
|
|
|
|
var windowProcPtr = windows.NewCallbackCDecl(windowProc)
|
|
|
|
|
2022-05-24 19:10:32 +02:00
|
|
|
var handleToWindow = map[windows.HWND]*Window{}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) error {
|
|
|
|
style := w.getWindowStyle()
|
|
|
|
exStyle := w.getWindowExStyle()
|
|
|
|
|
|
|
|
var xpos, ypos, fullWidth, fullHeight int32
|
|
|
|
if w.monitor != nil {
|
2023-02-07 19:05:46 +01:00
|
|
|
mi, ok := _GetMonitorInfoW(w.monitor.platform.handle)
|
2022-08-07 07:32:00 +02:00
|
|
|
if !ok {
|
2023-10-03 16:07:53 +02:00
|
|
|
return fmt.Errorf("glfw: GetMonitorInfoW failed")
|
2022-08-07 07:32:00 +02:00
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
// NOTE: This window placement is temporary and approximate, as the
|
|
|
|
// correct position and size cannot be known until the monitor
|
|
|
|
// video mode has been picked in _glfwSetVideoModeWin32
|
2022-08-07 07:32:00 +02:00
|
|
|
xpos = mi.rcMonitor.left
|
|
|
|
ypos = mi.rcMonitor.top
|
|
|
|
fullWidth = mi.rcMonitor.right - mi.rcMonitor.left
|
|
|
|
fullHeight = mi.rcMonitor.bottom - mi.rcMonitor.top
|
2022-04-19 17:49:43 +02:00
|
|
|
} else {
|
|
|
|
xpos = _CW_USEDEFAULT
|
|
|
|
ypos = _CW_USEDEFAULT
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
w.platform.maximized = wndconfig.maximized
|
2022-04-19 17:49:43 +02:00
|
|
|
if wndconfig.maximized {
|
|
|
|
style |= _WS_MAXIMIZE
|
|
|
|
}
|
|
|
|
|
|
|
|
w, h, err := getFullWindowSize(style, exStyle, wndconfig.width, wndconfig.height, _USER_DEFAULT_SCREEN_DPI)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fullWidth, fullHeight = int32(w), int32(h)
|
|
|
|
}
|
|
|
|
|
|
|
|
h, err := _CreateWindowExW(exStyle, _GLFW_WNDCLASSNAME, wndconfig.title, style, xpos, ypos, fullWidth, fullHeight,
|
|
|
|
0, // No parent window
|
|
|
|
0, // No window menu
|
2023-02-07 19:05:46 +01:00
|
|
|
_glfw.platformWindow.instance, unsafe.Pointer(wndconfig))
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
w.platform.handle = h
|
2022-04-19 17:49:43 +02:00
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
handleToWindow[w.platform.handle] = w
|
2022-04-19 17:49:43 +02:00
|
|
|
|
2023-03-30 19:07:35 +02:00
|
|
|
if !microsoftgdk.IsXbox() && winver.IsWindows7OrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _ChangeWindowMessageFilterEx(w.platform.handle, _WM_DROPFILES, _MSGFLT_ALLOW, nil); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _ChangeWindowMessageFilterEx(w.platform.handle, _WM_COPYDATA, _MSGFLT_ALLOW, nil); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _ChangeWindowMessageFilterEx(w.platform.handle, _WM_COPYGLOBALDATA, _MSGFLT_ALLOW, nil); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
w.platform.scaleToMonitor = wndconfig.scaleToMonitor
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
// Adjust window rect to account for DPI scaling of the window frame and
|
|
|
|
// (if enabled) DPI scaling of the content area
|
|
|
|
// This cannot be done until we know what monitor the window was placed on
|
2022-05-29 12:13:31 +02:00
|
|
|
if !microsoftgdk.IsXbox() && w.monitor == nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
rect := _RECT{
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: int32(wndconfig.width),
|
|
|
|
bottom: int32(wndconfig.height),
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
mh := _MonitorFromWindow(w.platform.handle, _MONITOR_DEFAULTTONEAREST)
|
2022-05-20 16:09:10 +02:00
|
|
|
|
|
|
|
// Adjust window rect to account for DPI scaling of the window frame and
|
|
|
|
// (if enabled) DPI scaling of the content area
|
|
|
|
// This cannot be done until we know what monitor the window was placed on
|
|
|
|
// Only update the restored window rect as the window may be maximized
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
if wndconfig.scaleToMonitor {
|
2022-05-20 16:09:10 +02:00
|
|
|
xscale, yscale, err := getMonitorContentScaleWin32(mh)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if xscale > 0 && yscale > 0 {
|
|
|
|
rect.right = int32(float32(rect.right) * xscale)
|
|
|
|
rect.bottom = int32(float32(rect.bottom) * yscale)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rect, err = w.clientToScreen(rect)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _AdjustWindowRectExForDpi(&rect, style, false, exStyle, _GetDpiForWindow(w.platform.handle)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := _AdjustWindowRectEx(&rect, style, false, exStyle); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only update the restored window rect as the window may be maximized
|
2023-02-07 19:05:46 +01:00
|
|
|
wp, err := _GetWindowPlacement(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-05-20 16:09:10 +02:00
|
|
|
_OffsetRect(&rect, wp.rcNormalPosition.left-rect.left, wp.rcNormalPosition.top-rect.top)
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
wp.rcNormalPosition = rect
|
|
|
|
wp.showCmd = _SW_HIDE
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPlacement(w.platform.handle, &wp); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
2022-05-20 16:09:10 +02:00
|
|
|
|
|
|
|
// Adjust rect of maximized undecorated window, because by default Windows will
|
|
|
|
// make such a window cover the whole monitor instead of its workarea
|
|
|
|
|
|
|
|
if wndconfig.maximized && !wndconfig.decorated {
|
|
|
|
mi, _ := _GetMonitorInfoW(mh)
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPos(w.platform.handle, _HWND_TOP,
|
2022-05-20 16:09:10 +02:00
|
|
|
mi.rcWork.left, mi.rcWork.top, mi.rcWork.right-mi.rcWork.left, mi.rcWork.bottom-mi.rcWork.top,
|
|
|
|
_SWP_NOACTIVATE|_SWP_NOZORDER); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2022-05-29 12:13:31 +02:00
|
|
|
if !microsoftgdk.IsXbox() {
|
2023-02-07 19:05:46 +01:00
|
|
|
_DragAcceptFiles(w.platform.handle, true)
|
2022-05-29 10:04:43 +02:00
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
if fbconfig.transparent {
|
|
|
|
if err := w.updateFramebufferTransparency(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
w.platform.transparent = true
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
width, height, err := w.platformGetWindowSize()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
w.platform.width, w.platform.height = width, height
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerWindowClassWin32() error {
|
|
|
|
var wc _WNDCLASSEXW
|
|
|
|
wc.cbSize = uint32(unsafe.Sizeof(wc))
|
|
|
|
wc.style = _CS_HREDRAW | _CS_VREDRAW | _CS_OWNDC
|
|
|
|
wc.lpfnWndProc = _WNDPROC(windowProcPtr)
|
2023-02-07 19:05:46 +01:00
|
|
|
wc.hInstance = _glfw.platformWindow.instance
|
2022-04-19 17:49:43 +02:00
|
|
|
cursor, err := _LoadCursorW(0, _IDC_ARROW)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
wc.hCursor = cursor
|
|
|
|
className, err := windows.UTF16FromString(_GLFW_WNDCLASSNAME)
|
|
|
|
if err != nil {
|
2023-10-03 16:07:53 +02:00
|
|
|
panic("glfw: _GLFW_WNDCLASSNAME must not inclucde a NUL character")
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
wc.lpszClassName = &className[0]
|
|
|
|
defer runtime.KeepAlive(className)
|
|
|
|
|
|
|
|
// In the original GLFW implementation, an embedded resource GLFW_ICON is used if possible.
|
|
|
|
// See https://www.glfw.org/docs/3.3/group__window.html
|
|
|
|
|
2022-05-29 12:13:31 +02:00
|
|
|
if !microsoftgdk.IsXbox() {
|
2022-05-24 19:00:55 +02:00
|
|
|
icon, err := _LoadImageW(0, _IDI_APPLICATION, _IMAGE_ICON, 0, 0, _LR_DEFAULTSIZE|_LR_SHARED)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
wc.hIcon = _HICON(icon)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := _RegisterClassExW(&wc); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func unregisterWindowClassWin32() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _UnregisterClassW(_GLFW_WNDCLASSNAME, _glfw.platformWindow.instance); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformCreateWindow(wndconfig *wndconfig, ctxconfig *ctxconfig, fbconfig *fbconfig) error {
|
|
|
|
if err := w.createNativeWindow(wndconfig, fbconfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctxconfig.client != NoAPI {
|
|
|
|
if ctxconfig.source == NativeContextAPI {
|
|
|
|
if err := initWGL(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.createContextWGL(ctxconfig, fbconfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2022-08-07 07:32:00 +02:00
|
|
|
if err := w.refreshContextAttribs(ctxconfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2023-09-18 07:52:25 +02:00
|
|
|
if wndconfig.mousePassthrough {
|
|
|
|
if err := w.platformSetWindowMousePassthrough(true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
if w.monitor != nil {
|
|
|
|
w.platformShowWindow()
|
|
|
|
if err := w.platformFocusWindow(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.acquireMonitor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.fitToMonitor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-08-07 07:32:00 +02:00
|
|
|
if wndconfig.centerCursor {
|
|
|
|
if err := w.centerCursorInContentArea(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if wndconfig.visible {
|
|
|
|
w.platformShowWindow()
|
|
|
|
if wndconfig.focused {
|
|
|
|
if err := w.platformFocusWindow(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformDestroyWindow() error {
|
|
|
|
if w.monitor != nil {
|
|
|
|
if err := w.releaseMonitor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if w.context.destroy != nil {
|
2022-09-09 18:52:46 +02:00
|
|
|
if err := w.context.destroy(w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if _glfw.platformWindow.disabledCursorWindow == w {
|
|
|
|
_glfw.platformWindow.disabledCursorWindow = nil
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if w.platform.handle != 0 {
|
2022-07-30 11:30:46 +02:00
|
|
|
if !microsoftgdk.IsXbox() {
|
2023-03-31 16:52:52 +02:00
|
|
|
// An error 'invalid window handle' can occur without any specific reasons (#2551).
|
|
|
|
// As there is nothing to do, just ignore this error.
|
|
|
|
if err := _DestroyWindow(w.platform.handle); err != nil && !errors.Is(err, windows.ERROR_INVALID_WINDOW_HANDLE) {
|
2022-07-30 11:30:46 +02:00
|
|
|
return err
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
delete(handleToWindow, w.platform.handle)
|
|
|
|
w.platform.handle = 0
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if w.platform.bigIcon != 0 {
|
|
|
|
if err := _DestroyIcon(w.platform.bigIcon); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if w.platform.smallIcon != 0 {
|
|
|
|
if err := _DestroyIcon(w.platform.smallIcon); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowTitle(title string) error {
|
2022-05-31 17:35:37 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return nil
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
return _SetWindowTextW(w.platform.handle, title)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowIcon(images []*Image) error {
|
|
|
|
var bigIcon, smallIcon _HICON
|
|
|
|
|
|
|
|
if len(images) > 0 {
|
|
|
|
cxIcon, err := _GetSystemMetrics(_SM_CXICON)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cyIcon, err := _GetSystemMetrics(_SM_CYICON)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cxsmIcon, err := _GetSystemMetrics(_SM_CXSMICON)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cysmIcon, err := _GetSystemMetrics(_SM_CYSMICON)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
bigImage := chooseImage(images, int(cxIcon), int(cyIcon))
|
|
|
|
smallImage := chooseImage(images, int(cxsmIcon), int(cysmIcon))
|
|
|
|
|
|
|
|
bigIcon, err = createIcon(bigImage, 0, 0, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
smallIcon, err = createIcon(smallImage, 0, 0, false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2023-02-07 19:05:46 +01:00
|
|
|
i, err := _GetClassLongPtrW(w.platform.handle, _GCLP_HICON)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
bigIcon = _HICON(i)
|
2023-02-07 19:05:46 +01:00
|
|
|
i, err = _GetClassLongPtrW(w.platform.handle, _GCLP_HICONSM)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
smallIcon = _HICON(i)
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
_SendMessageW(w.platform.handle, _WM_SETICON, _ICON_BIG, _LPARAM(bigIcon))
|
|
|
|
_SendMessageW(w.platform.handle, _WM_SETICON, _ICON_SMALL, _LPARAM(smallIcon))
|
2022-04-19 17:49:43 +02:00
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if w.platform.bigIcon != 0 {
|
|
|
|
if err := _DestroyIcon(w.platform.bigIcon); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if w.platform.smallIcon != 0 {
|
|
|
|
if err := _DestroyIcon(w.platform.smallIcon); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(images) > 0 {
|
2023-02-07 19:05:46 +01:00
|
|
|
w.platform.bigIcon = bigIcon
|
|
|
|
w.platform.smallIcon = smallIcon
|
2023-09-29 19:46:11 +02:00
|
|
|
} else {
|
|
|
|
w.platform.bigIcon = 0
|
|
|
|
w.platform.smallIcon = 0
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformGetWindowPos() (xpos, ypos int, err error) {
|
2022-06-01 05:07:48 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return 0, 0, nil
|
|
|
|
}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
var pos _POINT
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _ClientToScreen(w.platform.handle, &pos); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return 0, 0, err
|
|
|
|
}
|
|
|
|
return int(pos.x), int(pos.y), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowPos(xpos, ypos int) error {
|
2022-06-01 05:07:48 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
rect := _RECT{
|
|
|
|
left: int32(xpos),
|
|
|
|
top: int32(ypos),
|
|
|
|
right: int32(xpos),
|
|
|
|
bottom: int32(ypos),
|
|
|
|
}
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _AdjustWindowRectExForDpi(&rect, w.getWindowStyle(), false, w.getWindowExStyle(), _GetDpiForWindow(w.platform.handle)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := _AdjustWindowRectEx(&rect, w.getWindowStyle(), false, w.getWindowExStyle()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPos(w.platform.handle, 0, rect.left, rect.top, 0, 0, _SWP_NOACTIVATE|_SWP_NOZORDER|_SWP_NOSIZE); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformGetWindowSize() (width, height int, err error) {
|
2023-02-07 19:05:46 +01:00
|
|
|
area, err := _GetClientRect(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, 0, err
|
|
|
|
}
|
|
|
|
return int(area.right), int(area.bottom), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowSize(width, height int) error {
|
|
|
|
if w.monitor != nil {
|
|
|
|
if w.monitor.window == w {
|
|
|
|
if err := w.acquireMonitor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.fitToMonitor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rect := _RECT{
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: int32(width),
|
|
|
|
bottom: int32(height),
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _AdjustWindowRectExForDpi(&rect, w.getWindowStyle(), false, w.getWindowExStyle(), _GetDpiForWindow(w.platform.handle)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := _AdjustWindowRectEx(&rect, w.getWindowStyle(), false, w.getWindowExStyle()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPos(w.platform.handle, _HWND_TOP,
|
2022-04-19 17:49:43 +02:00
|
|
|
0, 0, rect.right-rect.left, rect.bottom-rect.top,
|
|
|
|
_SWP_NOACTIVATE|_SWP_NOOWNERZORDER|_SWP_NOMOVE|_SWP_NOZORDER); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowSizeLimits(minwidth, minheight, maxwidth, maxheight int) error {
|
|
|
|
if (minwidth == DontCare || minheight == DontCare) && (maxwidth == DontCare || maxheight == DontCare) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
area, err := _GetWindowRect(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _MoveWindow(w.platform.handle, area.left, area.top, area.right-area.left, area.bottom-area.top, true); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
2023-05-13 19:54:11 +02:00
|
|
|
|
|
|
|
if err := w.updateWindowStyles(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowAspectRatio(numer, denom int) error {
|
|
|
|
if numer == DontCare || denom == DontCare {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
area, err := _GetWindowRect(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.applyAspectRatio(_WMSZ_BOTTOMRIGHT, &area); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _MoveWindow(w.platform.handle, area.left, area.top, area.right-area.left, area.bottom-area.top, true); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformGetFramebufferSize() (width, height int, err error) {
|
|
|
|
return w.platformGetWindowSize()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformGetWindowFrameSize() (left, top, right, bottom int, err error) {
|
|
|
|
width, height, err := w.platformGetWindowSize()
|
|
|
|
if err != nil {
|
|
|
|
return 0, 0, 0, 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rect := _RECT{
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: int32(width),
|
|
|
|
bottom: int32(height),
|
|
|
|
}
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _AdjustWindowRectExForDpi(&rect, w.getWindowStyle(), false, w.getWindowExStyle(), _GetDpiForWindow(w.platform.handle)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return 0, 0, 0, 0, err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := _AdjustWindowRectEx(&rect, w.getWindowStyle(), false, w.getWindowExStyle()); err != nil {
|
|
|
|
return 0, 0, 0, 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -int(rect.left), -int(rect.top), int(rect.right) - width, int(rect.bottom) - height, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformGetWindowContentScale() (xscale, yscale float32, err error) {
|
2023-02-07 19:05:46 +01:00
|
|
|
handle := _MonitorFromWindow(w.platform.handle, _MONITOR_DEFAULTTONEAREST)
|
2022-04-19 17:49:43 +02:00
|
|
|
return getMonitorContentScaleWin32(handle)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformIconifyWindow() {
|
2023-02-07 19:05:46 +01:00
|
|
|
_ShowWindow(w.platform.handle, _SW_MINIMIZE)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformRestoreWindow() {
|
2023-02-07 19:05:46 +01:00
|
|
|
_ShowWindow(w.platform.handle, _SW_RESTORE)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2022-05-20 16:09:10 +02:00
|
|
|
func (w *Window) platformMaximizeWindow() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
if _IsWindowVisible(w.platform.handle) {
|
|
|
|
_ShowWindow(w.platform.handle, _SW_MAXIMIZE)
|
2022-05-20 16:09:10 +02:00
|
|
|
} else {
|
|
|
|
if err := w.maximizeWindowManually(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformShowWindow() {
|
2023-02-07 19:05:46 +01:00
|
|
|
_ShowWindow(w.platform.handle, _SW_SHOWNA)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformHideWindow() {
|
2023-02-07 19:05:46 +01:00
|
|
|
_ShowWindow(w.platform.handle, _SW_HIDE)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformRequestWindowAttention() {
|
2023-02-07 19:05:46 +01:00
|
|
|
_FlashWindow(w.platform.handle, true)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformFocusWindow() error {
|
2022-06-01 05:07:48 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _BringWindowToTop(w.platform.handle); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
_SetForegroundWindow(w.platform.handle)
|
|
|
|
if _, err := _SetFocus(w.platform.handle); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int) error {
|
|
|
|
if w.monitor == monitor {
|
|
|
|
if monitor != nil {
|
|
|
|
if monitor.window == w {
|
|
|
|
if err := w.acquireMonitor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.fitToMonitor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rect := _RECT{
|
|
|
|
left: int32(xpos),
|
|
|
|
top: int32(ypos),
|
|
|
|
right: int32(xpos + width),
|
|
|
|
bottom: int32(ypos + height),
|
|
|
|
}
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _AdjustWindowRectExForDpi(&rect, w.getWindowStyle(), false, w.getWindowExStyle(), _GetDpiForWindow(w.platform.handle)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := _AdjustWindowRectEx(&rect, w.getWindowStyle(), false, w.getWindowExStyle()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPos(w.platform.handle, _HWND_TOP,
|
2022-04-19 17:49:43 +02:00
|
|
|
rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
|
|
|
|
_SWP_NOCOPYBITS|_SWP_NOACTIVATE|_SWP_NOZORDER); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if w.monitor != nil {
|
|
|
|
if err := w.releaseMonitor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
w.inputWindowMonitor(monitor)
|
|
|
|
|
|
|
|
if w.monitor != nil {
|
|
|
|
var flags uint32 = _SWP_SHOWWINDOW | _SWP_NOACTIVATE | _SWP_NOCOPYBITS
|
|
|
|
if w.decorated {
|
2023-02-07 19:05:46 +01:00
|
|
|
s, err := _GetWindowLongW(w.platform.handle, _GWL_STYLE)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
style := uint32(s)
|
|
|
|
style &^= _WS_OVERLAPPEDWINDOW
|
|
|
|
style |= w.getWindowStyle()
|
2023-02-07 19:05:46 +01:00
|
|
|
if _, err := _SetWindowLongW(w.platform.handle, _GWL_STYLE, int32(style)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
flags |= _SWP_FRAMECHANGED
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := w.acquireMonitor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
mi, _ := _GetMonitorInfoW(w.monitor.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
var hWnd windows.HWND = _HWND_NOTOPMOST
|
|
|
|
if w.floating {
|
|
|
|
hWnd = _HWND_TOPMOST
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPos(w.platform.handle, hWnd,
|
2022-04-19 17:49:43 +02:00
|
|
|
mi.rcMonitor.left,
|
|
|
|
mi.rcMonitor.top,
|
|
|
|
mi.rcMonitor.right-mi.rcMonitor.left,
|
|
|
|
mi.rcMonitor.bottom-mi.rcMonitor.top,
|
|
|
|
flags); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var flags uint32 = _SWP_NOACTIVATE | _SWP_NOCOPYBITS
|
|
|
|
if w.decorated {
|
2023-02-07 19:05:46 +01:00
|
|
|
s, err := _GetWindowLongW(w.platform.handle, _GWL_STYLE)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
style := uint32(s)
|
|
|
|
style &^= _WS_POPUP
|
|
|
|
style |= w.getWindowStyle()
|
2023-02-07 19:05:46 +01:00
|
|
|
if _, err := _SetWindowLongW(w.platform.handle, _GWL_STYLE, int32(style)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
flags |= _SWP_FRAMECHANGED
|
|
|
|
}
|
|
|
|
|
|
|
|
rect := _RECT{
|
|
|
|
left: int32(xpos),
|
|
|
|
top: int32(ypos),
|
|
|
|
right: int32(xpos + width),
|
|
|
|
bottom: int32(ypos + height),
|
|
|
|
}
|
2023-03-30 19:07:35 +02:00
|
|
|
if winver.IsWindows10AnniversaryUpdateOrGreater() {
|
2022-04-19 17:49:43 +02:00
|
|
|
if err := _AdjustWindowRectExForDpi(&rect, w.getWindowStyle(),
|
|
|
|
false, w.getWindowExStyle(),
|
2023-02-07 19:05:46 +01:00
|
|
|
_GetDpiForWindow(w.platform.handle)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := _AdjustWindowRectEx(&rect, w.getWindowStyle(),
|
|
|
|
false, w.getWindowExStyle()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var after windows.HWND
|
|
|
|
if w.floating {
|
|
|
|
after = _HWND_TOPMOST
|
|
|
|
} else {
|
|
|
|
after = _HWND_NOTOPMOST
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetWindowPos(w.platform.handle, after,
|
2022-04-19 17:49:43 +02:00
|
|
|
rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
|
|
|
|
flags); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformWindowFocused() bool {
|
2022-05-31 17:35:37 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return true
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
return w.platform.handle == _GetActiveWindow()
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformWindowIconified() bool {
|
2022-06-01 05:07:48 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return false
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
return _IsIconic(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformWindowVisible() bool {
|
2022-06-01 05:07:48 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return true
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
return _IsWindowVisible(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformWindowMaximized() bool {
|
2022-06-01 05:07:48 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return false
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
return _IsZoomed(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformWindowHovered() (bool, error) {
|
2022-06-01 05:07:48 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return true, nil
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
return w.cursorInContentArea()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformFramebufferTransparent() bool {
|
2022-06-01 05:07:48 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if !w.platform.transparent {
|
2022-04-19 17:49:43 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:07:35 +02:00
|
|
|
if !winver.IsWindowsVistaOrGreater() {
|
2022-04-19 17:49:43 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
composition, err := _DwmIsCompositionEnabled()
|
|
|
|
if err != nil || !composition {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:07:35 +02:00
|
|
|
if !winver.IsWindows8OrGreater() {
|
2022-04-19 17:49:43 +02:00
|
|
|
// HACK: Disable framebuffer transparency on Windows 7 when the
|
|
|
|
// colorization color is opaque, because otherwise the window
|
|
|
|
// contents is blended additively with the previous frame instead
|
|
|
|
// of replacing it
|
|
|
|
_, opaque, err := _DwmGetColorizationColor()
|
|
|
|
if err != nil || opaque {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowResizable(enabled bool) error {
|
|
|
|
return w.updateWindowStyles()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowDecorated(enabled bool) error {
|
|
|
|
return w.updateWindowStyles()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowFloating(enabled bool) error {
|
|
|
|
var after windows.HWND = _HWND_NOTOPMOST
|
|
|
|
if enabled {
|
|
|
|
after = _HWND_TOPMOST
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
return _SetWindowPos(w.platform.handle, after, 0, 0, 0, 0, _SWP_NOACTIVATE|_SWP_NOMOVE|_SWP_NOSIZE)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2023-09-18 07:52:25 +02:00
|
|
|
func (w *Window) platformSetWindowMousePassthrough(enabled bool) error {
|
|
|
|
exStyle, err := _GetWindowLongW(w.platform.handle, _GWL_EXSTYLE)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var key _COLORREF
|
|
|
|
var alpha byte
|
|
|
|
var flags uint32
|
|
|
|
if exStyle&_WS_EX_LAYERED != 0 {
|
|
|
|
var err error
|
|
|
|
key, alpha, flags, err = _GetLayeredWindowAttributes(w.platform.handle)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if enabled {
|
|
|
|
exStyle |= _WS_EX_TRANSPARENT | _WS_EX_LAYERED
|
|
|
|
} else {
|
|
|
|
exStyle &^= _WS_EX_TRANSPARENT
|
|
|
|
// NOTE: Window opacity also needs the layered window style so do not
|
|
|
|
// remove it if the window is alpha blended
|
|
|
|
if exStyle&_WS_EX_LAYERED != 0 {
|
|
|
|
if flags&_LWA_ALPHA == 0 {
|
|
|
|
exStyle &^= _WS_EX_LAYERED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := _SetWindowLongW(w.platform.handle, _GWL_EXSTYLE, exStyle); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if enabled {
|
|
|
|
if err := _SetLayeredWindowAttributes(w.platform.handle, key, alpha, flags); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
func (w *Window) platformGetWindowOpacity() (float32, error) {
|
2023-02-07 19:05:46 +01:00
|
|
|
style, err := _GetWindowLongW(w.platform.handle, _GWL_EXSTYLE)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if style&_WS_EX_LAYERED != 0 {
|
2023-02-07 19:05:46 +01:00
|
|
|
_, alpha, flags, err := _GetLayeredWindowAttributes(w.platform.handle)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if flags&_LWA_ALPHA != 0 {
|
|
|
|
return float32(alpha) / 255, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetWindowOpacity(opacity float32) error {
|
|
|
|
if opacity < 1 {
|
|
|
|
alpha := byte(255 * opacity)
|
2023-02-07 19:05:46 +01:00
|
|
|
style, err := _GetWindowLongW(w.platform.handle, _GWL_EXSTYLE)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
style |= _WS_EX_LAYERED
|
2023-02-07 19:05:46 +01:00
|
|
|
if _, err := _SetWindowLongW(w.platform.handle, _GWL_EXSTYLE, style); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _SetLayeredWindowAttributes(w.platform.handle, 0, alpha, _LWA_ALPHA); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2023-02-07 19:05:46 +01:00
|
|
|
style, err := _GetWindowLongW(w.platform.handle, _GWL_EXSTYLE)
|
2022-04-19 17:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
style &^= _WS_EX_LAYERED
|
2023-02-07 19:05:46 +01:00
|
|
|
if _, err := _SetWindowLongW(w.platform.handle, _GWL_EXSTYLE, style); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetRawMouseMotion(enabled bool) error {
|
2023-02-07 19:05:46 +01:00
|
|
|
if _glfw.platformWindow.disabledCursorWindow != w {
|
2022-04-19 17:49:43 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if enabled {
|
|
|
|
if err := w.enableRawMouseMotion(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := w.disableRawMouseMotion(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func platformRawMouseMotionSupported() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func platformPollEvents() error {
|
|
|
|
if len(_glfw.errors) > 0 {
|
|
|
|
return _glfw.errors[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
var msg _MSG
|
|
|
|
for _PeekMessageW(&msg, 0, 0, 0, _PM_REMOVE) {
|
|
|
|
if msg.message == _WM_QUIT {
|
|
|
|
// NOTE: While GLFW does not itself post WM_QUIT, other processes
|
|
|
|
// may post it to this one, for example Task Manager
|
|
|
|
// HACK: Treat WM_QUIT as a close on all windows
|
|
|
|
for _, window := range _glfw.windows {
|
|
|
|
window.inputWindowCloseRequest()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_TranslateMessage(&msg)
|
|
|
|
_DispatchMessageW(&msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:35:37 +02:00
|
|
|
var handle windows.HWND
|
|
|
|
if microsoftgdk.IsXbox() {
|
|
|
|
// Assume that there is always exactly one active window.
|
2023-02-07 19:05:46 +01:00
|
|
|
handle = _glfw.windows[0].platform.handle
|
2022-05-31 17:35:37 +02:00
|
|
|
} else {
|
|
|
|
handle = _GetActiveWindow()
|
|
|
|
}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
// HACK: Release modifier keys that the system did not emit KEYUP for
|
|
|
|
// NOTE: Shift keys on Windows tend to "stick" when both are pressed as
|
|
|
|
// no key up message is generated by the first key release
|
|
|
|
// NOTE: Windows key is not reported as released by the Win+V hotkey
|
|
|
|
// Other Win hotkeys are handled implicitly by _glfwInputWindowFocus
|
|
|
|
// because they change the input focus
|
|
|
|
// NOTE: The other half of this is in the WM_*KEY* handler in windowProc
|
2022-05-31 17:35:37 +02:00
|
|
|
if handle != 0 {
|
2022-05-24 19:10:32 +02:00
|
|
|
if window := handleToWindow[handle]; window != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
keys := [...]struct {
|
|
|
|
VK int
|
|
|
|
Key Key
|
|
|
|
}{
|
|
|
|
{_VK_LSHIFT, KeyLeftShift},
|
|
|
|
{_VK_RSHIFT, KeyRightShift},
|
|
|
|
{_VK_LWIN, KeyLeftSuper},
|
|
|
|
{_VK_RWIN, KeyRightSuper},
|
|
|
|
}
|
|
|
|
for i := range keys {
|
|
|
|
vk := keys[i].VK
|
|
|
|
key := keys[i].Key
|
2023-02-07 19:05:46 +01:00
|
|
|
scancode := _glfw.platformWindow.scancodes[key]
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
if uint32(_GetKeyState(int32(vk)))&0x8000 != 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if window.keys[key] != Press {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
window.inputKey(key, int(scancode), Release, getKeyMods())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if window := _glfw.platformWindow.disabledCursorWindow; window != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
width, height, err := window.platformGetWindowSize()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Re-center the cursor only if it has moved since the last call,
|
|
|
|
// to avoid breaking glfwWaitEvents with WM_MOUSEMOVE
|
2023-02-07 19:05:46 +01:00
|
|
|
if window.platform.lastCursorPosX != width/2 || window.platform.lastCursorPosY != height/2 {
|
2022-04-19 17:49:43 +02:00
|
|
|
if err := window.platformSetCursorPos(float64(width/2), float64(height/2)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func platformWaitEvents() error {
|
|
|
|
if err := _WaitMessage(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := platformPollEvents(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func platformWaitEventsTimeout(timeout float64) error {
|
|
|
|
if _, err := _MsgWaitForMultipleObjects(0, nil, false, uint32(timeout*1e3), _QS_ALLEVENTS); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := platformPollEvents(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func platformPostEmptyEvent() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
return _PostMessageW(_glfw.platformWindow.helperWindowHandle, _WM_NULL, 0, 0)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformGetCursorPos() (xpos, ypos float64, err error) {
|
|
|
|
pos, err := _GetCursorPos()
|
|
|
|
if err != nil {
|
2022-07-04 05:55:34 +02:00
|
|
|
if errors.Is(err, windows.ERROR_ACCESS_DENIED) {
|
|
|
|
return 0, 0, nil
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
return 0, 0, err
|
|
|
|
}
|
2022-06-01 05:07:48 +02:00
|
|
|
if !microsoftgdk.IsXbox() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _ScreenToClient(w.platform.handle, &pos); err != nil {
|
2022-06-01 05:07:48 +02:00
|
|
|
return 0, 0, err
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
return float64(pos.x), float64(pos.y), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetCursorPos(xpos, ypos float64) error {
|
|
|
|
pos := _POINT{
|
|
|
|
x: int32(xpos),
|
|
|
|
y: int32(ypos),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the new position so it can be recognized later
|
2023-02-07 19:05:46 +01:00
|
|
|
w.platform.lastCursorPosX = int(pos.x)
|
|
|
|
w.platform.lastCursorPosY = int(pos.y)
|
2022-04-19 17:49:43 +02:00
|
|
|
|
2022-06-01 05:07:48 +02:00
|
|
|
if !microsoftgdk.IsXbox() {
|
2023-02-07 19:05:46 +01:00
|
|
|
if err := _ClientToScreen(w.platform.handle, &pos); err != nil {
|
2022-06-01 05:07:48 +02:00
|
|
|
return err
|
|
|
|
}
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
if err := _SetCursorPos(pos.x, pos.y); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetCursorMode(mode int) error {
|
|
|
|
if mode == CursorDisabled {
|
|
|
|
if w.platformWindowFocused() {
|
|
|
|
if err := w.disableCursor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
if _glfw.platformWindow.disabledCursorWindow == w {
|
2022-04-19 17:49:43 +02:00
|
|
|
if err := w.enableCursor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
in, err := w.cursorInContentArea()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if in {
|
|
|
|
if err := w.updateCursorImage(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-13 06:33:52 +02:00
|
|
|
func platformGetScancodeName(scancode int) (string, error) {
|
2023-02-07 19:05:46 +01:00
|
|
|
if scancode < 0 || scancode > (_KF_EXTENDED|0xff) || _glfw.platformWindow.keycodes[scancode] == KeyUnknown {
|
2022-08-13 06:33:52 +02:00
|
|
|
return "", fmt.Errorf("glwfwin: invalid scancode %d: %w", scancode, InvalidValue)
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
return _glfw.platformWindow.keynames[_glfw.platformWindow.keycodes[scancode]], nil
|
2022-08-13 06:33:52 +02:00
|
|
|
}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
func platformGetKeyScancode(key Key) int {
|
2023-02-07 19:05:46 +01:00
|
|
|
return _glfw.platformWindow.scancodes[key]
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Cursor) platformCreateStandardCursor(shape StandardCursor) error {
|
2022-05-29 12:13:31 +02:00
|
|
|
if microsoftgdk.IsXbox() {
|
2022-05-24 19:00:55 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-19 17:49:43 +02:00
|
|
|
var id int
|
|
|
|
switch shape {
|
|
|
|
case ArrowCursor:
|
|
|
|
id = _OCR_NORMAL
|
|
|
|
case IBeamCursor:
|
|
|
|
id = _OCR_IBEAM
|
|
|
|
case CrosshairCursor:
|
|
|
|
id = _OCR_CROSS
|
|
|
|
case HandCursor:
|
|
|
|
id = _OCR_HAND
|
|
|
|
case HResizeCursor:
|
|
|
|
id = _OCR_SIZEWE
|
|
|
|
case VResizeCursor:
|
|
|
|
id = _OCR_SIZENS
|
2023-01-15 18:26:41 +01:00
|
|
|
case ResizeNWSECursor: // v3.4
|
|
|
|
id = _OCR_SIZENWSE
|
|
|
|
case ResizeNESWCursor: // v3.4
|
|
|
|
id = _OCR_SIZENESW
|
|
|
|
case ResizeAllCursor: // v3.4
|
|
|
|
id = _OCR_SIZEALL
|
|
|
|
case NotAllowedCursor: // v3.4
|
|
|
|
id = _OCR_NO
|
2022-04-19 17:49:43 +02:00
|
|
|
default:
|
2023-10-03 16:07:53 +02:00
|
|
|
return fmt.Errorf("glfw: invalid shape: %d", shape)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
h, err := _LoadImageW(0, uintptr(id), _IMAGE_CURSOR, 0, 0, _LR_DEFAULTSIZE|_LR_SHARED)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
c.platform.handle = _HCURSOR(h)
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Cursor) platformDestroyCursor() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
if c.platform.handle != 0 {
|
|
|
|
if err := _DestroyIcon(_HICON(c.platform.handle)); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) platformSetCursor(cursor *Cursor) error {
|
|
|
|
in, err := w.cursorInContentArea()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if in {
|
|
|
|
if err := w.updateCursorImage(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func platformSetClipboardString(str string) error {
|
2023-10-03 16:07:53 +02:00
|
|
|
panic("glfw: platformSetClipboardString is not implemented")
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func platformGetClipboardString() (string, error) {
|
2023-10-03 16:07:53 +02:00
|
|
|
panic("glfw: platformGetClipboardString is not implemented")
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) GetWin32Window() (windows.HWND, error) {
|
|
|
|
if !_glfw.initialized {
|
|
|
|
return 0, NotInitialized
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
return w.platform.handle, nil
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|