mirror of https://github.com/stenzek/duckstation
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
|
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
|
|
|
#include "platform_misc.h"
|
|
|
|
#include "common/error.h"
|
|
#include "common/file_system.h"
|
|
#include "common/log.h"
|
|
#include "common/small_string.h"
|
|
#include "common/string_util.h"
|
|
|
|
#include <algorithm>
|
|
#include <cinttypes>
|
|
#include <memory>
|
|
|
|
#include "common/windows_headers.h"
|
|
#include <Psapi.h>
|
|
#include <WinSock2.h>
|
|
#include <dwmapi.h>
|
|
|
|
LOG_CHANNEL(PlatformMisc);
|
|
|
|
static bool s_screensaver_suspended = false;
|
|
static bool s_winsock_initialized = false;
|
|
static std::once_flag s_winsock_initializer;
|
|
|
|
bool PlatformMisc::InitializeSocketSupport(Error* error)
|
|
{
|
|
std::call_once(
|
|
s_winsock_initializer,
|
|
[](Error* error) {
|
|
WSADATA wsa = {};
|
|
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
|
|
{
|
|
Error::SetSocket(error, "WSAStartup() failed: ", WSAGetLastError());
|
|
return false;
|
|
}
|
|
|
|
s_winsock_initialized = true;
|
|
std::atexit([]() { WSACleanup(); });
|
|
return true;
|
|
},
|
|
error);
|
|
|
|
return s_winsock_initialized;
|
|
}
|
|
|
|
bool PlatformMisc::SetWindowRoundedCornerState(void* window_handle, bool enabled, Error* error)
|
|
{
|
|
const DWM_WINDOW_CORNER_PREFERENCE value = enabled ? DWMWCP_DEFAULT : DWMWCP_DONOTROUND;
|
|
const HRESULT hr =
|
|
DwmSetWindowAttribute(static_cast<HWND>(window_handle), DWMWA_WINDOW_CORNER_PREFERENCE, &value, sizeof(value));
|
|
if (FAILED(hr))
|
|
Error::SetHResult(error, "DwmSetWindowAttribute(DWMWA_WINDOW_CORNER_PREFERENCE) failed: ", hr);
|
|
|
|
return SUCCEEDED(hr);
|
|
}
|