2022-02-11 12:38:45 +01:00
|
|
|
// Copyright 2022 The Ebiten Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package directx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"golang.org/x/sys/windows"
|
|
|
|
)
|
|
|
|
|
2022-08-27 08:15:16 +02:00
|
|
|
const is64bit = unsafe.Sizeof(uintptr(0)) == 8
|
|
|
|
|
2022-10-01 18:52:21 +02:00
|
|
|
type handleError windows.Handle
|
|
|
|
|
|
|
|
func (h handleError) Error() string {
|
|
|
|
return fmt.Sprintf("HANDLE(%d)", h)
|
|
|
|
}
|
|
|
|
|
2022-05-29 16:47:45 +02:00
|
|
|
type (
|
|
|
|
_BOOL int32
|
|
|
|
)
|
|
|
|
|
2022-02-11 12:38:45 +01:00
|
|
|
func boolToUintptr(v bool) uintptr {
|
|
|
|
if v {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-03-25 03:55:58 +01:00
|
|
|
type _PAPPSTATE_CHANGE_ROUTINE func(quiesced bool, context unsafe.Pointer) uintptr
|
2022-02-11 12:38:45 +01:00
|
|
|
|
|
|
|
var (
|
2023-03-25 03:55:58 +01:00
|
|
|
// https://github.com/MicrosoftDocs/sdk-api/blob/docs/sdk-api-src/content/appnotify/nf-appnotify-registerappstatechangenotification.md
|
|
|
|
appnotify = windows.NewLazySystemDLL("API-MS-Win-Core-psm-appnotify-l1-1-0.dll")
|
2022-05-22 15:04:09 +02:00
|
|
|
|
2023-03-25 03:55:58 +01:00
|
|
|
procRegisterAppStateChangeNotification = appnotify.NewProc("RegisterAppStateChangeNotification")
|
2022-02-11 12:38:45 +01:00
|
|
|
)
|
|
|
|
|
2022-12-21 18:56:36 +01:00
|
|
|
func _RegisterAppStateChangeNotification(routine _PAPPSTATE_CHANGE_ROUTINE, context unsafe.Pointer) (unsafe.Pointer, error) {
|
|
|
|
cb := windows.NewCallback(routine)
|
|
|
|
var registration unsafe.Pointer
|
|
|
|
r, _, _ := procRegisterAppStateChangeNotification.Call(cb, uintptr(context), uintptr(unsafe.Pointer(®istration)))
|
|
|
|
if windows.Errno(r) != windows.ERROR_SUCCESS {
|
|
|
|
return nil, fmt.Errorf("directx: RegisterAppStateChangeNotification failed: %w", windows.Errno(r))
|
|
|
|
}
|
|
|
|
return registration, nil
|
|
|
|
}
|