Skip to content

Commit

Permalink
impr: Restore native macOS title bar double click zoom gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
mentlerd committed May 19, 2024
1 parent d5eb6b5 commit d565ff9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/libimhex/include/hex/helpers/utils_macos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
void setupMacosWindowStyle(GLFWwindow *window, bool borderlessWindowMode);

void enumerateFontsMacos();

void toggleWindowZoomMacos(GLFWwindow *window);
}

#endif
#endif
10 changes: 10 additions & 0 deletions lib/libimhex/source/helpers/utils_macos.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ void enumerateFontsMacos(void) {
CFRelease(fontDescriptors);
}

void toggleWindowZoomMacos(GLFWwindow *window) {
NSWindow* cocoaWindow = glfwGetCocoaWindow(window);

// `[NSWindow performZoom:_ sender]` takes over pumping the main runloop for the duration of the resize,
// and would interfere with our renderer's frame logic. Shedule it for the next frame
CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes, ^{
[cocoaWindow performZoom:nil];
});
}

@interface HexDocument : NSDocument

@end
Expand Down
14 changes: 14 additions & 0 deletions plugins/builtin/source/content/window_decoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,20 @@ namespace hex::plugin::builtin {
drawMenu();
drawTitleBar();

#if defined(OS_MACOS)
if (ImHexApi::System::isBorderlessWindowModeEnabled()) {
const auto windowSize = ImHexApi::System::getMainWindowSize();
const auto menuUnderlaySize = ImVec2(windowSize.x, ImGui::GetCurrentWindowRead()->MenuBarHeight() * 1.5F);

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)) {
toggleWindowZoomMacos(window);
}
}
#endif

ImGui::EndMainMenuBar();
} else {
ImGui::PopStyleVar(2);
Expand Down

0 comments on commit d565ff9

Please sign in to comment.