1
0
mirror of synced 2025-01-11 05:42:15 +01:00

impr: Prevent window from being moved while hovering over items on macOS

This commit is contained in:
WerWolv 2025-01-01 16:45:11 +01:00
parent 6a3b10111f
commit 9f9c5abf35
3 changed files with 20 additions and 4 deletions

View File

@ -17,6 +17,7 @@
void enumerateFontsMacos(); void enumerateFontsMacos();
void macosHandleTitlebarDoubleClickGesture(GLFWwindow *window); void macosHandleTitlebarDoubleClickGesture(GLFWwindow *window);
void macosSetWindowMovable(GLFWwindow *window, bool movable);
bool macosIsWindowBeingResizedByUser(GLFWwindow *window); bool macosIsWindowBeingResizedByUser(GLFWwindow *window);
void macosMarkContentEdited(GLFWwindow *window, bool edited = true); void macosMarkContentEdited(GLFWwindow *window, bool edited = true);
} }

View File

@ -112,6 +112,12 @@
} }
} }
void macosSetWindowMovable(GLFWwindow *window, bool movable) {
NSWindow* cocoaWindow = glfwGetCocoaWindow(window);
[cocoaWindow setMovable:movable];
}
bool macosIsWindowBeingResizedByUser(GLFWwindow *window) { bool macosIsWindowBeingResizedByUser(GLFWwindow *window) {
NSWindow* cocoaWindow = glfwGetCocoaWindow(window); NSWindow* cocoaWindow = glfwGetCocoaWindow(window);

View File

@ -416,10 +416,19 @@ namespace hex::plugin::builtin {
const auto menuUnderlaySize = ImVec2(windowSize.x, ImGui::GetCurrentWindowRead()->MenuBarHeight); const auto menuUnderlaySize = ImVec2(windowSize.x, ImGui::GetCurrentWindowRead()->MenuBarHeight);
ImGui::SetCursorPos(ImVec2()); ImGui::SetCursorPos(ImVec2());
// Drawing this button late allows widgets rendered before it to grab click events, forming an "input underlay" // Prevent window from being moved unless title bar is hovered
if (ImGui::InvisibleButton("##mainMenuUnderlay", menuUnderlaySize, ImGuiButtonFlags_PressedOnDoubleClick)) {
macosHandleTitlebarDoubleClickGesture(window); if (!ImGui::IsAnyItemHovered()) {
const auto cursorPos = ImGui::GetCursorScreenPos();
if (ImGui::IsMouseHoveringRect(cursorPos, cursorPos + menuUnderlaySize) && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
macosHandleTitlebarDoubleClickGesture(window);
}
macosSetWindowMovable(window, true);
} else {
macosSetWindowMovable(window, false);
} }
} }
#endif #endif