impr: Prevent window from being moved while hovering over items on macOS
This commit is contained in:
parent
6a3b10111f
commit
9f9c5abf35
@ -17,6 +17,7 @@
|
||||
void enumerateFontsMacos();
|
||||
|
||||
void macosHandleTitlebarDoubleClickGesture(GLFWwindow *window);
|
||||
void macosSetWindowMovable(GLFWwindow *window, bool movable);
|
||||
bool macosIsWindowBeingResizedByUser(GLFWwindow *window);
|
||||
void macosMarkContentEdited(GLFWwindow *window, bool edited = true);
|
||||
}
|
||||
|
@ -112,6 +112,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
void macosSetWindowMovable(GLFWwindow *window, bool movable) {
|
||||
NSWindow* cocoaWindow = glfwGetCocoaWindow(window);
|
||||
|
||||
[cocoaWindow setMovable:movable];
|
||||
}
|
||||
|
||||
bool macosIsWindowBeingResizedByUser(GLFWwindow *window) {
|
||||
NSWindow* cocoaWindow = glfwGetCocoaWindow(window);
|
||||
|
||||
|
@ -416,10 +416,19 @@ namespace hex::plugin::builtin {
|
||||
const auto menuUnderlaySize = ImVec2(windowSize.x, ImGui::GetCurrentWindowRead()->MenuBarHeight);
|
||||
|
||||
ImGui::SetCursorPos(ImVec2());
|
||||
|
||||
// Drawing this button late allows widgets rendered before it to grab click events, forming an "input underlay"
|
||||
if (ImGui::InvisibleButton("##mainMenuUnderlay", menuUnderlaySize, ImGuiButtonFlags_PressedOnDoubleClick)) {
|
||||
macosHandleTitlebarDoubleClickGesture(window);
|
||||
|
||||
// Prevent window from being moved unless title bar is hovered
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user