From c113930a66efb7a2a8a1bab62e110dafb5b21209 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 21 Sep 2021 22:17:53 +0300 Subject: Added build options for popup/macOS menus --- CMakeLists.txt | 10 +++++++++- src/defs.h | 4 +++- src/ui/util.c | 6 +++++- src/ui/window.c | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b229442..d98cc700 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,15 +45,17 @@ option (ENABLE_HARFBUZZ_MINIMAL "Build the HarfBuzz library with minimal depende option (ENABLE_IDLE_SLEEP "While idle, sleep in the main thread instead of waiting for events" ON) option (ENABLE_IPC "Use IPC to communicate between running instances" ON) option (ENABLE_KERNING "Enable kerning in font renderer (slower)" ON) +option (ENABLE_MAC_MENUS "Use native context menus (macOS)" ON) option (ENABLE_MOBILE_PHONE "Use the phone mobile UI design instead of desktop UI" OFF) option (ENABLE_MOBILE_TABLET "Use the tablet mobile UI design instead of desktop UI" OFF) option (ENABLE_MPG123 "Use mpg123 for decoding MPEG audio" ON) +option (ENABLE_POPUP_MENUS "Use popup windows for context menus (if OFF, menus are confined inside main window)" ON) option (ENABLE_RELATIVE_EMBED "Resources should always be found via relative path" OFF) option (ENABLE_RESIZE_DRAW "Force window to redraw during resizing" ${DEFAULT_RESIZE_DRAW}) option (ENABLE_RESOURCE_EMBED "Embed resources inside the executable" OFF) option (ENABLE_WEBP "Use libwebp to decode .webp images (via pkg-config)" ON) option (ENABLE_WINDOWPOS_FIX "Set position after showing window (workaround for SDL bug)" OFF) -option (ENABLE_X11_SWRENDER "Use software rendering under X11" OFF) +option (ENABLE_X11_SWRENDER "Use software rendering (X11)" OFF) include (BuildType.cmake) include (res/Embed.cmake) @@ -328,10 +330,16 @@ endif () if (ENABLE_KERNING) target_compile_definitions (app PUBLIC LAGRANGE_ENABLE_KERNING=1) endif () +if (ENABLE_MAC_MENUS) + target_compile_definitions (app PUBLIC LAGRANGE_ENABLE_MAC_MENUS=1) +endif () if (ENABLE_MPG123 AND MPG123_FOUND) target_compile_definitions (app PUBLIC LAGRANGE_ENABLE_MPG123=1) target_link_libraries (app PUBLIC PkgConfig::MPG123) endif () +if (ENABLE_POPUP_MENUS) + target_compile_definitions (app PUBLIC LAGRANGE_ENABLE_POPUP_MENUS=1) +endif () if (ENABLE_RESIZE_DRAW) target_compile_definitions (app PUBLIC LAGRANGE_ENABLE_RESIZE_DRAW=1) endif () diff --git a/src/defs.h b/src/defs.h index 8b47790a..01bf2b3d 100644 --- a/src/defs.h +++ b/src/defs.h @@ -166,7 +166,9 @@ iLocalDef int acceptKeyMod_ReturnKeyBehavior(int behavior) { #if defined (iPlatformAppleDesktop) # define iHaveNativeMenus /* main menu */ -# define iHaveNativeContextMenus +# if defined (LAGRANGE_ENABLE_MAC_MENUS) +# define iHaveNativeContextMenus +# endif #endif /* UI labels that depend on the platform */ diff --git a/src/ui/util.c b/src/ui/util.c index c75d7698..2b6ff929 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -975,7 +975,11 @@ void unselectAllNativeMenuItems_Widget(iWidget *menu) { } iLocalDef iBool isUsingMenuPopupWindows_(void) { +#if defined (LAGRANGE_ENABLE_POPUP_MENUS) return deviceType_App() == desktop_AppDeviceType; +#else + return iFalse; +#endif } void releaseNativeMenu_Widget(iWidget *d) { @@ -1019,7 +1023,7 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) { removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */ const float pixelRatio = get_Window()->pixelRatio; iInt2 menuPos = add_I2(get_MainWindow()->place.normalRect.pos, - divf_I2(windowCoord, pixelRatio)); + divf_I2(sub_I2(windowCoord, divi_I2(gap2_UI, 2)), pixelRatio)); arrange_Widget(d); /* Check display bounds. */ { const iInt2 menuSize = divf_I2(d->rect.size, pixelRatio); diff --git a/src/ui/window.c b/src/ui/window.c index 3f8faaea..8197afd4 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -913,7 +913,7 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) { } default: { SDL_Event event = *ev; - if (event.type == SDL_USEREVENT && isCommand_UserEvent(ev, "window.unfreeze")) { + if (event.type == SDL_USEREVENT && isCommand_UserEvent(ev, "window.unfreeze") && mw) { mw->isDrawFrozen = iFalse; if (SDL_GetWindowFlags(d->win) & SDL_WINDOW_HIDDEN) { SDL_ShowWindow(d->win); -- cgit v1.2.3