From f9470056664f421f3ee8070d17ad7e03bf43474f Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 25 May 2012 18:08:09 -0400 Subject: [PATCH] TWK-885: Hide resize handle when in osx full-screen mode --- src/TomahawkApp.cpp | 2 +- src/TomahawkWindow.cpp | 38 ++++++++++++++++++++++++++------------ src/TomahawkWindow.h | 3 +++ src/mac/TomahawkApp_Mac.h | 5 ++++- src/mac/TomahawkApp_Mac.mm | 24 +++++++++++++++++++++++- 5 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/TomahawkApp.cpp b/src/TomahawkApp.cpp index 796b4392a..f98bce7b1 100644 --- a/src/TomahawkApp.cpp +++ b/src/TomahawkApp.cpp @@ -306,7 +306,7 @@ TomahawkApp::init() #ifdef Q_WS_MAC // Make sure to do this after main window is inited - Tomahawk::enableFullscreen(); + Tomahawk::enableFullscreen( m_mainwindow ); #endif } diff --git a/src/TomahawkWindow.cpp b/src/TomahawkWindow.cpp index bb325da05..10996b4a1 100644 --- a/src/TomahawkWindow.cpp +++ b/src/TomahawkWindow.cpp @@ -192,7 +192,7 @@ TomahawkWindow::applyPlatformTweaks() if ( !QString( qApp->style()->metaObject()->className() ).toLower().contains( "qtcurve" ) ) qApp->setStyle( new ProxyStyle() ); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC setUnifiedTitleAndToolBarOnMac( true ); delete ui->hline1; delete ui->hline2; @@ -272,7 +272,7 @@ TomahawkWindow::setupSideBar() sidebarWidget->layout()->setContentsMargins( 0, 0, 0, 0 ); sidebarWidget->layout()->setMargin( 0 ); -#ifndef Q_WS_MAC +#ifndef Q_OS_MAC sidebarWidget->layout()->setSpacing( 0 ); #endif @@ -287,11 +287,11 @@ TomahawkWindow::setupSideBar() void TomahawkWindow::setupUpdateCheck() { -#ifndef Q_WS_MAC +#ifndef Q_OS_MAC ui->menu_Help->insertSeparator( ui->actionAboutTomahawk ); #endif -#if defined( Q_WS_MAC ) && defined( HAVE_SPARKLE ) +#if defined( Q_OS_MAC ) && defined( HAVE_SPARKLE ) QAction* checkForUpdates = ui->menu_Help->addAction( tr( "Check For Updates..." ) ); checkForUpdates->setMenuRole( QAction::ApplicationSpecificRole ); connect( checkForUpdates, SIGNAL( triggered( bool ) ), SLOT( checkForUpdates() ) ); @@ -350,7 +350,7 @@ TomahawkWindow::setupSignals() connect( ui->actionNext, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( next() ) ); connect( ui->actionPrevious, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( previous() ) ); -#if defined( Q_WS_MAC ) +#if defined( Q_OS_MAC ) connect( ui->actionMinimize, SIGNAL( triggered() ), SLOT( minimize() ) ); connect( ui->actionZoom, SIGNAL( triggered() ), SLOT( maximize() ) ); #else @@ -399,7 +399,7 @@ TomahawkWindow::changeEvent( QEvent* e ) void TomahawkWindow::closeEvent( QCloseEvent* e ) { -#ifndef Q_WS_MAC +#ifndef Q_OS_MAC if ( e->spontaneous() && QSystemTrayIcon::isSystemTrayAvailable() ) { hide(); @@ -419,7 +419,7 @@ TomahawkWindow::showEvent( QShowEvent* e ) { QMainWindow::showEvent( e ); -#if defined( Q_WS_MAC ) +#if defined( Q_OS_MAC ) ui->actionMinimize->setDisabled( false ); ui->actionZoom->setDisabled( false ); #endif @@ -431,7 +431,7 @@ TomahawkWindow::hideEvent( QHideEvent* e ) { QMainWindow::hideEvent( e ); -#if defined( Q_WS_MAC ) +#if defined( Q_OS_MAC ) ui->actionMinimize->setDisabled( true ); ui->actionZoom->setDisabled( true ); #endif @@ -442,7 +442,7 @@ void TomahawkWindow::keyPressEvent( QKeyEvent* e ) { bool accept = true; -#if ! defined ( Q_WS_MAC ) +#if ! defined ( Q_OS_MAC ) #define KEY_PRESSED Q_FUNC_INFO << "Multimedia Key Pressed:" switch( e->key() ) { @@ -590,11 +590,25 @@ TomahawkWindow::showOfflineSources() } +void +TomahawkWindow::fullScreenEntered() +{ + statusBar()->setSizeGripEnabled( false ); +} + + +void +TomahawkWindow::fullScreenExited() +{ + statusBar()->setSizeGripEnabled( true ); +} + + void TomahawkWindow::loadSpiff() { LoadXSPFDialog* diag = new LoadXSPFDialog( this, Qt::Sheet ); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC connect( diag, SIGNAL( finished( int ) ), this, SLOT( loadXspfFinished( int ) ) ); diag->show(); #else @@ -719,7 +733,7 @@ void TomahawkWindow::createPlaylist() { PlaylistTypeSelectorDlg* playlistSelectorDlg = new PlaylistTypeSelectorDlg( TomahawkApp::instance()->mainWindow(), Qt::Sheet ); -#ifndef Q_WS_MAC +#ifndef Q_OS_MAC playlistSelectorDlg->setModal( true ); #endif connect( playlistSelectorDlg, SIGNAL( finished( int ) ), this, SLOT( playlistCreateDialogFinished( int ) ) ); @@ -863,7 +877,7 @@ TomahawkWindow::showAboutTomahawk() void TomahawkWindow::checkForUpdates() { -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC Tomahawk::checkForUpdates(); #endif } diff --git a/src/TomahawkWindow.h b/src/TomahawkWindow.h index d0f0cdaa1..a0bde3cda 100644 --- a/src/TomahawkWindow.h +++ b/src/TomahawkWindow.h @@ -88,6 +88,9 @@ public slots: void pluginMenuRemoved(QMenu*); void showOfflineSources(); + void fullScreenEntered(); + void fullScreenExited(); + private slots: void onAccountAdded( Tomahawk::Accounts::Account* account ); void onAccountConnected(); diff --git a/src/mac/TomahawkApp_Mac.h b/src/mac/TomahawkApp_Mac.h index e0957177f..e258c6719 100644 --- a/src/mac/TomahawkApp_Mac.h +++ b/src/mac/TomahawkApp_Mac.h @@ -23,6 +23,7 @@ // copyright David Sansome 2010 class QString; +class QObject; namespace Tomahawk { @@ -43,7 +44,9 @@ void setShortcutHandler(Tomahawk::MacShortcutHandler* engine); // used for opening files with tomahawk void setApplicationHandler(PlatformInterface* handler); void checkForUpdates(); -void enableFullscreen(); + +// Pass in a QObject with slots "fullScreenEntered() and fullScreenExited() in order to be notified +void enableFullscreen( QObject* notifier ); }; diff --git a/src/mac/TomahawkApp_Mac.mm b/src/mac/TomahawkApp_Mac.mm index 6187fab4e..402fb4c7f 100644 --- a/src/mac/TomahawkApp_Mac.mm +++ b/src/mac/TomahawkApp_Mac.mm @@ -43,6 +43,8 @@ #include #include +#include +#include @interface MacApplication :NSApplication { AppDelegate* delegate_; @@ -255,7 +257,7 @@ void Tomahawk::checkForUpdates() { #define SET_LION_FULLSCREEN (NSUInteger)(1 << 7) // Defined as NSWindowCollectionBehaviorFullScreenPrimary in lion's NSWindow.h #endif -void Tomahawk::enableFullscreen() +void Tomahawk::enableFullscreen( QObject* receiver ) { // We don't support anything below leopard, so if it's not [snow] leopard it must be lion // Can't check for lion as Qt 4.7 doesn't have the enum val, not checking for Unknown as it will be lion @@ -273,6 +275,26 @@ void Tomahawk::enableFullscreen() NSView *nsview = (NSView *)w->winId(); NSWindow *nswindow = [nsview window]; [nswindow setCollectionBehavior:SET_LION_FULLSCREEN]; + +#ifdef LION + if ( !receiver ) + continue; + + [[NSNotificationCenter defaultCenter] addObserverForName:NSWindowWillEnterFullScreenNotification + object:nswindow + queue:nil + usingBlock:^(NSNotification * note) { + NSLog(@"Became Full Screen!"); + QMetaObject::invokeMethod( receiver, "fullScreenEntered", Qt::DirectConnection ); + }]; + [[NSNotificationCenter defaultCenter] addObserverForName:NSWindowDidExitFullScreenNotification + object:nswindow + queue:nil + usingBlock:^(NSNotification * note) { + NSLog(@"Left Full Screen!"); + QMetaObject::invokeMethod( receiver, "fullScreenExited", Qt::DirectConnection ); + }]; +#endif } } }