Skip to content

Commit

Permalink
GUI - remove duplicate fullscreen menu entry on macOS
Browse files Browse the repository at this point in the history
macOS automagically adds an "Enter Fullscreen" entry to the menu. We already provide one of these for all platforms, so disable the macOS specific one. This requires some ObjectiveC funkiness...
  • Loading branch information
samaaron committed Nov 10, 2020
1 parent d262e30 commit 51bc5fa
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/gui/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ SET(RESOURCES
# Enable tracy profiler on debug and rel with debug builds
if(WIN32)
SET (SOURCES ${SOURCES} ${APP_ROOT}/external/tracy/TracyClient.cpp)
elseif(APPLE)
SET (SOURCES ${SOURCES} ${APP_ROOT}/platform/macos.mm)
SET (SOURCES ${SOURCES} ${APP_ROOT}/platform/macos.h)
endif()

set(ALL_SOURCES ${OSC_SOURCES} ${QT_SOURCES} ${SOURCES} ${EDITOR_SOURCES})
Expand All @@ -145,6 +148,7 @@ if (APPLE)
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
RESOURCE "images/app.icns"
LINK_FLAGS "-framework AppKit"
OUTPUT_NAME ${MACOS_APP_NAME}
)
file(
Expand Down
6 changes: 6 additions & 0 deletions app/gui/qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include <QtPlatformHeaders\QWindowsWindowFunctions>
#endif

#ifdef Q_OS_MAC
#include "platform/macos.h"
#endif

int main(int argc, char *argv[])
{

Expand Down Expand Up @@ -116,6 +120,8 @@ int main(int argc, char *argv[])
#elif __APPLE__
// macOS code goes here

SonicPi::removeMacosSpecificMenuItems();

QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

QMainWindow* splashWindow = new QMainWindow(0, Qt::FramelessWindowHint);
Expand Down
20 changes: 20 additions & 0 deletions app/gui/qt/platform/macos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//--
// This file is part of Sonic Pi: http://sonic-pi.net
// Full project source: https://github.com/sonic-pi-net/sonic-pi
// License: https://github.com/sonic-pi-net/sonic-pi/blob/main/LICENSE.md
//
// Copyright 2020 by Sam Aaron (http://sam.aaron.name).
// All rights reserved.
//
// Permission is granted for use, copying, modification, and
// distribution of modified versions of this work as long as this
// notice is included.
//++

#pragma once

namespace SonicPi {

void removeMacosSpecificMenuItems();

}
36 changes: 36 additions & 0 deletions app/gui/qt/platform/macos.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//--
// This file is part of Sonic Pi: http://sonic-pi.net
// Full project source: https://github.com/sonic-pi-net/sonic-pi
// License: https://github.com/sonic-pi-net/sonic-pi/blob/main/LICENSE.md
//
// Copyright 2020 by Sam Aaron (http://sam.aaron.name).
// All rights reserved.
//
// Permission is granted for use, copying, modification, and
// distribution of modified versions of this work as long as this
// notice is included.
//++

#include "macos.h"
#import <AppKit/NSWindow.h>

namespace SonicPi {

void removeMacosSpecificMenuItems()
{

#ifdef AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER
// Remove (don't allow) the "Show Tab Bar" menu item from the "View" menu,
// if supported

if ([NSWindow respondsToSelector:@selector(allowsAutomaticWindowTabbing)])
NSWindow.allowsAutomaticWindowTabbing = NO;
#endif

// Remove (don't have) the "Enter Full Screen" menu item from the "View"
// menu

[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSFullScreenMenuItemEverywhere"];
}

}

0 comments on commit 51bc5fa

Please sign in to comment.