2021-08-18 22:36:46 +02:00
|
|
|
#include "window.hpp"
|
|
|
|
|
2023-07-13 14:08:23 +02:00
|
|
|
#include "messaging.hpp"
|
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
#if defined(OS_WINDOWS)
|
|
|
|
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/utils.hpp>
|
2021-09-16 22:23:51 +02:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
#include <imgui.h>
|
2021-08-25 19:32:47 +02:00
|
|
|
#include <imgui_internal.h>
|
2021-08-18 22:36:46 +02:00
|
|
|
|
|
|
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
|
|
|
#include <GLFW/glfw3native.h>
|
2021-08-25 19:32:47 +02:00
|
|
|
#undef GLFW_EXPOSE_NATIVE_WIN32
|
|
|
|
|
2023-01-07 10:32:01 +01:00
|
|
|
#include <winbase.h>
|
2021-08-18 22:36:46 +02:00
|
|
|
#include <winuser.h>
|
|
|
|
#include <dwmapi.h>
|
|
|
|
#include <windowsx.h>
|
2023-01-14 14:21:16 +01:00
|
|
|
#include <shobjidl.h>
|
|
|
|
#include <wrl/client.h>
|
2023-10-21 20:40:24 +02:00
|
|
|
#include <fcntl.h>
|
2024-01-10 23:46:50 +01:00
|
|
|
#include <oleidl.h>
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2023-03-18 11:35:01 +01:00
|
|
|
#include <cstdio>
|
2022-08-12 15:11:27 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2023-05-23 11:34:30 +02:00
|
|
|
template<typename T>
|
|
|
|
using WinUniquePtr = std::unique_ptr<std::remove_pointer_t<T>, BOOL(*)(T)>;
|
|
|
|
|
2023-12-27 16:33:49 +01:00
|
|
|
static LONG_PTR s_oldWndProc;
|
|
|
|
static float s_titleBarHeight;
|
|
|
|
static Microsoft::WRL::ComPtr<ITaskbarList4> s_taskbarList;
|
2022-01-24 20:53:17 +01:00
|
|
|
|
2023-05-27 17:45:41 +02:00
|
|
|
void nativeErrorMessage(const std::string &message) {
|
|
|
|
log::fatal(message);
|
2023-11-10 20:47:08 +01:00
|
|
|
MessageBox(nullptr, message.c_str(), "Error", MB_ICONERROR | MB_OK);
|
2023-05-27 17:45:41 +02:00
|
|
|
}
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Custom Window procedure for receiving OS events
|
2022-09-15 09:47:47 +02:00
|
|
|
static LRESULT commonWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
switch (uMsg) {
|
2023-02-17 12:03:53 +01:00
|
|
|
case WM_COPYDATA: {
|
|
|
|
// Handle opening files in existing instance
|
|
|
|
|
2022-09-15 09:47:47 +02:00
|
|
|
auto message = reinterpret_cast<COPYDATASTRUCT *>(lParam);
|
|
|
|
if (message == nullptr) break;
|
|
|
|
|
2023-07-13 14:08:23 +02:00
|
|
|
ssize_t nullIndex = -1;
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
auto messageData = static_cast<const char*>(message->lpData);
|
2023-07-13 14:08:23 +02:00
|
|
|
size_t messageSize = message->cbData;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < messageSize; i++) {
|
|
|
|
if (messageData[i] == '\0') {
|
|
|
|
nullIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nullIndex == -1) {
|
|
|
|
log::warn("Received invalid forwarded event");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string eventName(messageData, nullIndex);
|
2022-09-15 09:47:47 +02:00
|
|
|
|
2023-07-13 14:08:23 +02:00
|
|
|
std::vector<u8> eventData(messageData + nullIndex + 1, messageData + messageSize);
|
|
|
|
|
|
|
|
hex::messaging::messageReceived(eventName, eventData);
|
2022-09-15 09:47:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-02-17 12:03:53 +01:00
|
|
|
case WM_SETTINGCHANGE: {
|
|
|
|
// Handle Windows theme changes
|
2022-09-15 09:47:47 +02:00
|
|
|
if (lParam == 0) break;
|
|
|
|
|
|
|
|
if (LPCTSTR(lParam) == std::string_view("ImmersiveColorSet")) {
|
2023-12-08 10:29:44 +01:00
|
|
|
EventOSThemeChanged::post();
|
2022-09-15 09:47:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2023-07-06 10:26:12 +02:00
|
|
|
case WM_SETCURSOR: {
|
|
|
|
if (LOWORD(lParam) != HTCLIENT) {
|
2023-12-27 16:33:49 +01:00
|
|
|
return CallWindowProc((WNDPROC)s_oldWndProc, hwnd, uMsg, wParam, lParam);
|
2023-07-06 10:26:12 +02:00
|
|
|
} else {
|
|
|
|
switch (ImGui::GetMouseCursor()) {
|
|
|
|
case ImGuiMouseCursor_Arrow:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_ARROW));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_Hand:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_HAND));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_ResizeEW:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_SIZEWE));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_ResizeNS:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_SIZENS));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_ResizeNWSE:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_SIZENWSE));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_ResizeNESW:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_SIZENESW));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_ResizeAll:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_SIZEALL));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_NotAllowed:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_NO));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_TextInput:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_IBEAM));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2022-09-15 09:47:47 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-12-27 16:33:49 +01:00
|
|
|
return CallWindowProc((WNDPROC)s_oldWndProc, hwnd, uMsg, wParam, lParam);
|
2022-09-15 09:47:47 +02:00
|
|
|
}
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Custom window procedure for borderless window
|
2022-09-15 09:47:47 +02:00
|
|
|
static LRESULT borderlessWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
2022-01-24 20:53:17 +01:00
|
|
|
switch (uMsg) {
|
2023-05-20 21:10:12 +02:00
|
|
|
case WM_MOUSELAST:
|
|
|
|
break;
|
2022-02-01 22:09:44 +01:00
|
|
|
case WM_NCACTIVATE:
|
|
|
|
case WM_NCPAINT:
|
2023-02-17 12:03:53 +01:00
|
|
|
// Handle Windows Aero Snap
|
2022-02-01 22:09:44 +01:00
|
|
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
2023-02-17 12:03:53 +01:00
|
|
|
case WM_NCCALCSIZE: {
|
|
|
|
// Handle window resizing
|
|
|
|
|
|
|
|
RECT &rect = *reinterpret_cast<RECT *>(lParam);
|
|
|
|
RECT client = rect;
|
|
|
|
|
2023-12-27 16:33:49 +01:00
|
|
|
CallWindowProc((WNDPROC)s_oldWndProc, hwnd, uMsg, wParam, lParam);
|
2023-02-17 12:03:53 +01:00
|
|
|
|
|
|
|
if (IsMaximized(hwnd)) {
|
|
|
|
WINDOWINFO windowInfo = { };
|
|
|
|
windowInfo.cbSize = sizeof(WINDOWINFO);
|
|
|
|
GetWindowInfo(hwnd, &windowInfo);
|
2023-05-11 12:00:56 +02:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
rect = RECT {
|
|
|
|
.left = static_cast<LONG>(client.left + windowInfo.cyWindowBorders),
|
|
|
|
.top = static_cast<LONG>(client.top + windowInfo.cyWindowBorders),
|
2023-05-11 20:49:07 +02:00
|
|
|
.right = static_cast<LONG>(client.right - windowInfo.cyWindowBorders),
|
|
|
|
.bottom = static_cast<LONG>(client.bottom - windowInfo.cyWindowBorders) + 1
|
2023-02-17 12:03:53 +01:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
rect = client;
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
2021-12-10 16:09:55 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case WM_NCHITTEST: {
|
|
|
|
// Handle window resizing and moving
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
const POINT border {
|
2023-05-11 18:43:19 +02:00
|
|
|
static_cast<LONG>((::GetSystemMetrics(SM_CXFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER)) * ImHexApi::System::getGlobalScale()),
|
|
|
|
static_cast<LONG>((::GetSystemMetrics(SM_CYFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER)) * ImHexApi::System::getGlobalScale())
|
2023-02-17 12:03:53 +01:00
|
|
|
};
|
2022-02-01 22:09:44 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
RECT window;
|
|
|
|
if (!::GetWindowRect(hwnd, &window)) {
|
|
|
|
return HTNOWHERE;
|
|
|
|
}
|
2022-02-01 22:09:44 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
constexpr static auto RegionClient = 0b0000;
|
|
|
|
constexpr static auto RegionLeft = 0b0001;
|
|
|
|
constexpr static auto RegionRight = 0b0010;
|
|
|
|
constexpr static auto RegionTop = 0b0100;
|
|
|
|
constexpr static auto RegionBottom = 0b1000;
|
2022-02-01 22:09:44 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
const auto result =
|
|
|
|
RegionLeft * (cursor.x < (window.left + border.x)) |
|
|
|
|
RegionRight * (cursor.x >= (window.right - border.x)) |
|
|
|
|
RegionTop * (cursor.y < (window.top + border.y)) |
|
|
|
|
RegionBottom * (cursor.y >= (window.bottom - border.y));
|
|
|
|
|
2023-05-20 21:10:12 +02:00
|
|
|
if (result != 0 && (ImGui::IsAnyItemHovered() || ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId))) {
|
2023-04-06 14:58:05 +02:00
|
|
|
break;
|
2023-05-20 21:10:12 +02:00
|
|
|
}
|
2023-04-06 14:58:05 +02:00
|
|
|
|
2023-11-13 00:06:04 +01:00
|
|
|
std::string_view hoveredWindowName = GImGui->HoveredWindow == nullptr ? "" : GImGui->HoveredWindow->Name;
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
switch (result) {
|
|
|
|
case RegionLeft:
|
|
|
|
return HTLEFT;
|
|
|
|
case RegionRight:
|
|
|
|
return HTRIGHT;
|
|
|
|
case RegionTop:
|
|
|
|
return HTTOP;
|
|
|
|
case RegionBottom:
|
|
|
|
return HTBOTTOM;
|
|
|
|
case RegionTop | RegionLeft:
|
|
|
|
return HTTOPLEFT;
|
|
|
|
case RegionTop | RegionRight:
|
|
|
|
return HTTOPRIGHT;
|
|
|
|
case RegionBottom | RegionLeft:
|
|
|
|
return HTBOTTOMLEFT;
|
|
|
|
case RegionBottom | RegionRight:
|
|
|
|
return HTBOTTOMRIGHT;
|
|
|
|
case RegionClient:
|
|
|
|
default:
|
2023-12-27 16:33:49 +01:00
|
|
|
if (cursor.y < (window.top + s_titleBarHeight * 2)) {
|
2023-11-16 09:32:24 +01:00
|
|
|
if (hoveredWindowName == "##MainMenuBar" || hoveredWindowName == "ImHexDockSpace") {
|
|
|
|
if (!ImGui::IsAnyItemHovered()) {
|
|
|
|
return HTCAPTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2023-02-17 12:03:53 +01:00
|
|
|
break;
|
|
|
|
}
|
2022-02-01 22:09:44 +01:00
|
|
|
default:
|
2022-01-24 20:53:17 +01:00
|
|
|
break;
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
2022-09-15 09:47:47 +02:00
|
|
|
return commonWindowProc(hwnd, uMsg, wParam, lParam);
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2021-08-22 20:24:42 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
2023-10-22 23:39:14 +02:00
|
|
|
[[maybe_unused]]
|
2023-10-21 20:40:24 +02:00
|
|
|
static void reopenConsoleHandle(u32 stdHandleNumber, i32 stdFileDescriptor, FILE *stdStream) {
|
|
|
|
// Get the Windows handle for the standard stream
|
|
|
|
HANDLE handle = ::GetStdHandle(stdHandleNumber);
|
|
|
|
|
|
|
|
// Redirect the standard stream to the relevant console stream
|
|
|
|
if (stdFileDescriptor == STDIN_FILENO)
|
|
|
|
freopen("CONIN$", "rt", stdStream);
|
|
|
|
else
|
|
|
|
freopen("CONOUT$", "wt", stdStream);
|
|
|
|
|
|
|
|
// Disable buffering
|
|
|
|
setvbuf(stdStream, nullptr, _IONBF, 0);
|
|
|
|
|
|
|
|
// Reopen the standard stream as a file descriptor
|
|
|
|
auto unboundFd = [stdFileDescriptor, handle]{
|
|
|
|
if (stdFileDescriptor == STDIN_FILENO)
|
|
|
|
return _open_osfhandle(intptr_t(handle), _O_RDONLY);
|
|
|
|
else
|
|
|
|
return _open_osfhandle(intptr_t(handle), _O_WRONLY);
|
|
|
|
}();
|
|
|
|
|
|
|
|
// Duplicate the file descriptor to the standard stream
|
|
|
|
dup2(unboundFd, stdFileDescriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void Window::initNative() {
|
2023-10-22 23:39:14 +02:00
|
|
|
if (ImHexApi::System::isDebugBuild()) {
|
|
|
|
// If the application is running in debug mode, ImHex runs under the CONSOLE subsystem,
|
|
|
|
// so we don't need to do anything besides enabling ANSI colors
|
|
|
|
log::impl::enableColorPrinting();
|
|
|
|
} else if (hex::getEnvironmentVariable("__IMHEX_FORWARD_CONSOLE__") == "1") {
|
|
|
|
// Check for the __IMHEX_FORWARD_CONSOLE__ environment variable that was set by the forwarder application
|
|
|
|
|
|
|
|
// If it's present, attach to its console window
|
2023-10-21 20:40:24 +02:00
|
|
|
::AttachConsole(ATTACH_PARENT_PROCESS);
|
|
|
|
|
2023-10-22 23:39:14 +02:00
|
|
|
// Reopen stdin, stdout and stderr to the console if not in debug mode
|
2023-10-21 20:40:24 +02:00
|
|
|
reopenConsoleHandle(STD_INPUT_HANDLE, STDIN_FILENO, stdin);
|
|
|
|
reopenConsoleHandle(STD_OUTPUT_HANDLE, STDOUT_FILENO, stdout);
|
|
|
|
|
|
|
|
// Explicitly don't forward stderr because some libraries like to write to it
|
|
|
|
// with no way to disable it (e.g., libmagic)
|
|
|
|
/*
|
|
|
|
reopenConsoleHandle(STD_ERROR_HANDLE, STDERR_FILENO, stderr);
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Enable ANSI colors in the console
|
|
|
|
log::impl::enableColorPrinting();
|
2023-07-13 14:08:23 +02:00
|
|
|
} else {
|
2023-10-21 20:40:24 +02:00
|
|
|
log::impl::redirectToFile();
|
2023-07-13 14:08:23 +02:00
|
|
|
}
|
|
|
|
|
2023-01-14 14:21:16 +01:00
|
|
|
ImHexApi::System::impl::setBorderlessWindowMode(true);
|
2023-01-07 10:32:01 +01:00
|
|
|
|
|
|
|
// Add plugin library folders to dll search path
|
|
|
|
for (const auto &path : hex::fs::getDefaultPaths(fs::ImHexPath::Libraries)) {
|
|
|
|
if (std::fs::exists(path))
|
|
|
|
AddDllDirectory(path.c_str());
|
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2021-08-22 20:24:42 +02:00
|
|
|
|
2024-01-10 23:46:50 +01:00
|
|
|
class DropManager : public IDropTarget {
|
|
|
|
public:
|
|
|
|
DropManager() = default;
|
|
|
|
virtual ~DropManager() = default;
|
|
|
|
|
|
|
|
ULONG AddRef() override { return 1; }
|
|
|
|
ULONG Release() override { return 0; }
|
|
|
|
|
|
|
|
HRESULT QueryInterface(REFIID riid, void **ppvObject) override {
|
|
|
|
if (riid == IID_IDropTarget) {
|
|
|
|
*ppvObject = this;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppvObject = nullptr;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE DragEnter(
|
|
|
|
IDataObject *,
|
|
|
|
DWORD,
|
|
|
|
POINTL,
|
|
|
|
DWORD *pdwEffect) override
|
|
|
|
{
|
|
|
|
EventFileDragged::post(true);
|
|
|
|
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE DragOver(
|
|
|
|
DWORD,
|
|
|
|
POINTL,
|
|
|
|
DWORD *pdwEffect) override
|
|
|
|
{
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE DragLeave() override
|
|
|
|
{
|
|
|
|
EventFileDragged::post(false);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE Drop(
|
|
|
|
IDataObject *pDataObj,
|
|
|
|
DWORD,
|
|
|
|
POINTL,
|
|
|
|
DWORD *pdwEffect) override
|
|
|
|
{
|
|
|
|
FORMATETC fmte = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
|
|
|
|
STGMEDIUM stgm;
|
|
|
|
|
|
|
|
if (SUCCEEDED(pDataObj->GetData(&fmte, &stgm))) {
|
|
|
|
auto hdrop = HDROP(stgm.hGlobal);
|
|
|
|
auto fileCount = DragQueryFile(hdrop, 0xFFFFFFFF, nullptr, 0);
|
|
|
|
|
|
|
|
for (UINT i = 0; i < fileCount; i++) {
|
|
|
|
WCHAR szFile[MAX_PATH];
|
|
|
|
UINT cch = DragQueryFileW(hdrop, i, szFile, MAX_PATH);
|
|
|
|
if (cch > 0 && cch < MAX_PATH) {
|
|
|
|
EventFileDropped::post(szFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseStgMedium(&stgm);
|
|
|
|
}
|
|
|
|
|
|
|
|
EventFileDragged::post(false);
|
|
|
|
|
|
|
|
*pdwEffect &= DROPEFFECT_NONE;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void Window::setupNativeWindow() {
|
|
|
|
// Setup borderless window
|
2023-12-19 13:10:25 +01:00
|
|
|
auto hwnd = glfwGetWin32Window(m_window);
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2024-01-10 23:46:50 +01:00
|
|
|
OleInitialize(nullptr);
|
|
|
|
|
|
|
|
static DropManager dm;
|
|
|
|
RegisterDragDrop(hwnd, &dm);
|
|
|
|
|
2022-08-04 09:46:17 +02:00
|
|
|
bool borderlessWindowMode = ImHexApi::System::isBorderlessWindowModeEnabled();
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Set up the correct window procedure based on the borderless window mode state
|
2022-08-04 09:46:17 +02:00
|
|
|
if (borderlessWindowMode) {
|
2023-12-27 16:33:49 +01:00
|
|
|
s_oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)borderlessWindowProc);
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2022-02-15 22:36:36 +01:00
|
|
|
MARGINS borderless = { 1, 1, 1, 1 };
|
|
|
|
::DwmExtendFrameIntoClientArea(hwnd, &borderless);
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2022-02-15 22:36:36 +01:00
|
|
|
DWORD attribute = DWMNCRP_ENABLED;
|
|
|
|
::DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &attribute, sizeof(attribute));
|
2021-11-28 11:57:52 +01:00
|
|
|
|
2022-02-15 22:36:36 +01:00
|
|
|
::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE);
|
2022-09-15 09:47:47 +02:00
|
|
|
} else {
|
2023-12-27 16:33:49 +01:00
|
|
|
s_oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)commonWindowProc);
|
2022-02-15 22:36:36 +01:00
|
|
|
}
|
2022-08-12 15:11:27 +02:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Set up a taskbar progress handler
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) {
|
2023-12-27 16:33:49 +01:00
|
|
|
CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskbarList4, &s_taskbarList);
|
2023-01-14 14:21:16 +01:00
|
|
|
}
|
|
|
|
|
2023-12-08 10:29:44 +01:00
|
|
|
EventSetTaskBarIconState::subscribe([hwnd](u32 state, u32 type, u32 progress){
|
2023-02-17 12:03:53 +01:00
|
|
|
using enum ImHexApi::System::TaskProgressState;
|
|
|
|
switch (ImHexApi::System::TaskProgressState(state)) {
|
|
|
|
case Reset:
|
2023-12-27 16:33:49 +01:00
|
|
|
s_taskbarList->SetProgressState(hwnd, TBPF_NOPROGRESS);
|
|
|
|
s_taskbarList->SetProgressValue(hwnd, 0, 0);
|
2023-02-17 12:03:53 +01:00
|
|
|
break;
|
|
|
|
case Flash:
|
|
|
|
FlashWindow(hwnd, true);
|
|
|
|
break;
|
|
|
|
case Progress:
|
2023-12-27 16:33:49 +01:00
|
|
|
s_taskbarList->SetProgressState(hwnd, TBPF_INDETERMINATE);
|
|
|
|
s_taskbarList->SetProgressValue(hwnd, progress, 100);
|
2023-02-17 12:03:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
using enum ImHexApi::System::TaskProgressType;
|
|
|
|
switch (ImHexApi::System::TaskProgressType(type)) {
|
|
|
|
case Normal:
|
2023-12-27 16:33:49 +01:00
|
|
|
s_taskbarList->SetProgressState(hwnd, TBPF_NORMAL);
|
2023-02-17 12:03:53 +01:00
|
|
|
break;
|
|
|
|
case Warning:
|
2023-12-27 16:33:49 +01:00
|
|
|
s_taskbarList->SetProgressState(hwnd, TBPF_PAUSED);
|
2023-02-17 12:03:53 +01:00
|
|
|
break;
|
|
|
|
case Error:
|
2023-12-27 16:33:49 +01:00
|
|
|
s_taskbarList->SetProgressState(hwnd, TBPF_ERROR);
|
2023-02-17 12:03:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-05-22 12:00:35 +02:00
|
|
|
|
|
|
|
struct ACCENTPOLICY {
|
2023-05-23 13:20:35 +02:00
|
|
|
u32 accentState;
|
|
|
|
u32 accentFlags;
|
|
|
|
u32 gradientColor;
|
|
|
|
u32 animationId;
|
2023-05-22 12:00:35 +02:00
|
|
|
};
|
|
|
|
struct WINCOMPATTRDATA {
|
2023-05-23 13:20:35 +02:00
|
|
|
int attribute;
|
|
|
|
PVOID pData;
|
|
|
|
ULONG dataSize;
|
2023-05-22 12:00:35 +02:00
|
|
|
};
|
|
|
|
|
2023-12-08 10:29:44 +01:00
|
|
|
EventThemeChanged::subscribe([this]{
|
2023-12-19 13:10:25 +01:00
|
|
|
auto hwnd = glfwGetWin32Window(m_window);
|
2023-05-22 12:00:35 +02:00
|
|
|
|
2023-05-23 13:20:35 +02:00
|
|
|
static auto user32Dll = WinUniquePtr<HMODULE>(LoadLibraryA("user32.dll"), FreeLibrary);
|
2023-05-22 12:00:35 +02:00
|
|
|
if (user32Dll != nullptr) {
|
|
|
|
using SetWindowCompositionAttributeFunc = BOOL(WINAPI*)(HWND, WINCOMPATTRDATA*);
|
|
|
|
|
2023-05-23 11:34:30 +02:00
|
|
|
const auto SetWindowCompositionAttribute =
|
|
|
|
(SetWindowCompositionAttributeFunc)
|
|
|
|
(void*)
|
|
|
|
GetProcAddress(user32Dll.get(), "SetWindowCompositionAttribute");
|
|
|
|
|
2023-05-22 12:00:35 +02:00
|
|
|
if (SetWindowCompositionAttribute != nullptr) {
|
2023-11-16 22:24:06 +01:00
|
|
|
ACCENTPOLICY policy = { ImGuiExt::GetCustomStyle().WindowBlur > 0.5F ? 4U : 0U, 0, ImGuiExt::GetCustomColorU32(ImGuiCustomCol_BlurBackground), 0 };
|
2023-05-22 13:20:25 +02:00
|
|
|
WINCOMPATTRDATA data = { 19, &policy, sizeof(ACCENTPOLICY) };
|
2023-05-22 12:00:35 +02:00
|
|
|
SetWindowCompositionAttribute(hwnd, &data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void Window::beginNativeWindowFrame() {
|
2023-12-27 16:33:49 +01:00
|
|
|
s_titleBarHeight = ImGui::GetCurrentWindowRead()->MenuBarHeight();
|
2024-01-09 17:24:27 +01:00
|
|
|
|
|
|
|
// Remove WS_POPUP style from the window to make various window management tools work
|
|
|
|
auto hwnd = glfwGetWin32Window(m_window);
|
|
|
|
::SetWindowLong(hwnd, GWL_STYLE, (GetWindowLong(hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW) & ~WS_POPUP);
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void Window::endNativeWindowFrame() {
|
2022-08-04 09:46:17 +02:00
|
|
|
if (!ImHexApi::System::isBorderlessWindowModeEnabled())
|
|
|
|
return;
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
#endif
|