diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0ab8cb718f59c011f531ff70cc9ee2c11949ebef..a1297e9dd78f17a0ccc2caa12145fbee39be4102 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -235,6 +235,13 @@ set(inkscape_SRC inkview-window.cpp ) +if(APPLE) + list(APPEND inkscape_SRC + ink-osx.h + ink-osx.mm + ) +endif() + # ----------------------------------------------------------------------------- # Generate version file # ----------------------------------------------------------------------------- diff --git a/src/ink-osx.h b/src/ink-osx.h new file mode 100644 index 0000000000000000000000000000000000000000..31c6688592a1062b5b8b1992e85c6046d51ad55b --- /dev/null +++ b/src/ink-osx.h @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + * macOS specific code + */ + +namespace Inkscape { +void removeMacosSpecificMenuItems(); +} + +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/ink-osx.mm b/src/ink-osx.mm new file mode 100644 index 0000000000000000000000000000000000000000..dc1610f12b05e444d97cfe53e39273c9a9e9dc75 --- /dev/null +++ b/src/ink-osx.mm @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + * macOS specific code + */ + +#include "ink-osx.h" + +#import + +namespace Inkscape { +/** + * Same as "defaults write org.inkscape.Inkscape $key $value" but only if the key is unset. + */ +static void setNSUserDefaultIfUnset(NSString *key, BOOL value) +{ + auto userdefaults = [NSUserDefaults standardUserDefaults]; + if ([userdefaults objectForKey:key] == nil) { + [userdefaults setBool:value forKey:key]; + } +} + +/** + * Remove unwanted automatically added menu items on macOS. + * + * Based on https://github.com/opencor/opencor/blob/c90e38140d/src/misc/macos.mm + */ +void removeMacosSpecificMenuItems() +{ +#ifdef AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER + // Remove the "Show Tab Bar" menu item from the "View" menu + [NSWindow setAllowsAutomaticWindowTabbing:NO]; +#endif + + // Remove the "Enter Full Screen" menu item from the "View" menu + setNSUserDefaultIfUnset(@"NSFullScreenMenuItemEverywhere", NO); + + // Remove the "Start Dictation..." menu item from the "Edit" menu + setNSUserDefaultIfUnset(@"NSDisabledDictationMenuItem", YES); + + // Remove the "Emoji & Symbols" menu items from the "Edit" menu + setNSUserDefaultIfUnset(@"NSDisabledCharacterPaletteMenuItem", YES); +} +} + +// vim: filetype=objcpp:expandtab:shiftwidth=4:softtabstop=4 : diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 7f918084dca998972e7d8dc80ab74e33cb938352..a4e882f046b34a6ea4d9b5e4f8419dd1610e6be8 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -80,6 +80,7 @@ #ifdef GDK_WINDOWING_QUARTZ #include +#include "ink-osx.h" #endif using Inkscape::DocumentUndo; @@ -950,6 +951,8 @@ sp_desktop_widget_realize (GtkWidget *widget) auto osxapp = gtkosx_application_get(); auto menushell = static_cast(dtw->menubar()); if (osxapp && menushell && window) { + Inkscape::removeMacosSpecificMenuItems(); + menushell->set_parent(*window); gtkosx_application_set_menu_bar(osxapp, menushell->gobj()); // using quartz accelerators gives menu shortcuts priority over everything else,