From 00bc906130b5c394d2a6fc7a76deb44883f9e25f Mon Sep 17 00:00:00 2001 From: Thomas Holder Date: Wed, 8 Jan 2020 22:03:25 +0100 Subject: [PATCH 1/2] macOS: remove macOS specific menu items --- src/CMakeLists.txt | 7 ++++++ src/ink-osx.h | 10 ++++++++ src/ink-osx.mm | 43 ++++++++++++++++++++++++++++++++++ src/widgets/desktop-widget.cpp | 3 +++ 4 files changed, 63 insertions(+) create mode 100644 src/ink-osx.h create mode 100644 src/ink-osx.mm diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0ab8cb718f5..a1297e9dd78 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 00000000000..31c6688592a --- /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 00000000000..290b80a55a4 --- /dev/null +++ b/src/ink-osx.mm @@ -0,0 +1,43 @@ +// 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() +{ + // Remove the "Show Tab Bar" menu item from the "View" menu + [NSWindow setAllowsAutomaticWindowTabbing:NO]; + + // 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 7f918084dca..a4e882f046b 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, -- GitLab From 566b2dcc0139fd2a2a5ad7705be4ef3b0afa2ac7 Mon Sep 17 00:00:00 2001 From: Thomas Holder Date: Fri, 10 Jan 2020 21:15:29 +0100 Subject: [PATCH 2/2] AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER --- src/ink-osx.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ink-osx.mm b/src/ink-osx.mm index 290b80a55a4..dc1610f12b0 100644 --- a/src/ink-osx.mm +++ b/src/ink-osx.mm @@ -26,8 +26,10 @@ static void setNSUserDefaultIfUnset(NSString *key, BOOL value) */ 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); -- GitLab