diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-09-04 17:40:13 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-09-28 17:48:37 +0200 |
commit | e310c00709ed4fe0788aeff5142e3581d8b4d319 (patch) | |
tree | b85827742e4a93a57150b5d8d254ea85a6265379 /vcl/osx | |
parent | dea1b649765262b2e8beac88b0977d5dead98953 (diff) |
Unify SalUserEvent handling
Merges the various SalUserEvent structs and their handling into
a single class. This includes a common SalFrame* hash map, as all
backends use such a map to verify alive SalFrames.
It also reverts the "FIXME: lousy workaround" for i#90083, which
was part of commit d6f7c94e5c27ba02ff5c3229760c9808cc9b5bea.
At least on my current OSX box application based window switching
"just works" "out of the box", even without the code.
Change-Id: I188b567e44fd79c162b2d9cabbd771d1f66c7dc4
Reviewed-on: https://gerrit.libreoffice.org/42845
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/osx')
-rw-r--r-- | vcl/osx/salframe.cxx | 8 | ||||
-rw-r--r-- | vcl/osx/salinst.cxx | 93 | ||||
-rw-r--r-- | vcl/osx/vclnsapp.mm | 117 |
3 files changed, 49 insertions, 169 deletions
diff --git a/vcl/osx/salframe.cxx b/vcl/osx/salframe.cxx index e54073cdf4f1..dcdfe6d9c936 100644 --- a/vcl/osx/salframe.cxx +++ b/vcl/osx/salframe.cxx @@ -87,8 +87,7 @@ AquaSalFrame::AquaSalFrame( SalFrame* pParent, SalFrameStyleFlags salFrameStyle initWindowAndView(); SalData* pSalData = GetSalData(); - pSalData->maFrames.push_front( this ); - pSalData->maFrameCheck.insert( this ); + pSalData->mpFirstInstance->insertFrame( this ); } AquaSalFrame::~AquaSalFrame() @@ -106,8 +105,7 @@ AquaSalFrame::~AquaSalFrame() [SalFrameView unsetMouseFrame: this]; SalData* pSalData = GetSalData(); - pSalData->maFrames.remove( this ); - pSalData->maFrameCheck.erase( this ); + pSalData->mpFirstInstance->eraseFrame( this ); pSalData->maPresentationFrames.remove( this ); SAL_WARN_IF( this == s_pCaptureFrame, "vcl", "capture frame destroyed" ); @@ -296,7 +294,7 @@ void AquaSalFrame::ReleaseGraphics( SalGraphics *pGraphics ) bool AquaSalFrame::PostEvent(ImplSVEvent* pData) { - GetSalData()->mpFirstInstance->PostUserEvent( this, SalEvent::UserEvent, pData ); + GetSalData()->mpFirstInstance->PostEvent( this, pData, SalEvent::UserEvent ); return TRUE; } diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx index 855dac645e41..89e3ae6d4e82 100644 --- a/vcl/osx/salinst.cxx +++ b/vcl/osx/salinst.cxx @@ -79,7 +79,8 @@ static bool bLeftMain = false; class AquaDelayedSettingsChanged : public Idle { bool mbInvalidate; - public: + +public: AquaDelayedSettingsChanged( bool bInvalidate ) : mbInvalidate( bInvalidate ) { @@ -87,20 +88,20 @@ class AquaDelayedSettingsChanged : public Idle virtual void Invoke() override { - SalData* pSalData = GetSalData(); - if( ! pSalData->maFrames.empty() ) - pSalData->maFrames.front()->CallCallback( SalEvent::SettingsChanged, nullptr ); + AquaSalInstance *pInst = GetSalData()->mpFirstInstance; + SalFrame *pAnyFrame = pInst->anyFrame(); + if( pAnyFrame ) + pAnyFrame->CallCallback( SalEvent::SettingsChanged, nullptr ); if( mbInvalidate ) { - for( std::list< AquaSalFrame* >::iterator it = pSalData->maFrames.begin(); - it != pSalData->maFrames.end(); ++it ) + for( auto pSalFrame : pInst->getFrames() ) { - if( (*it)->mbShown ) - (*it)->SendPaintEvent(); + AquaSalFrame* pFrame = static_cast<AquaSalFrame*>( const_cast<SalFrame*>( pSalFrame ) ); + if( pFrame->mbShown ) + pFrame->SendPaintEvent(); } } - Stop(); delete this; } }; @@ -390,17 +391,19 @@ AquaSalInstance::~AquaSalInstance() delete mpSalYieldMutex; } -void AquaSalInstance::PostUserEvent( AquaSalFrame* pFrame, SalEvent nType, void* pData ) +void AquaSalInstance::TriggerUserEventProcessing() { - { - osl::MutexGuard g( maUserEventListMutex ); - maUserEvents.push_back( SalUserEvent( pFrame, pData, nType ) ); - } dispatch_async(dispatch_get_main_queue(),^{ ImplNSAppPostEvent( AquaSalInstance::YieldWakeupEvent, NO ); }); } +void AquaSalInstance::ProcessEvent( SalUserEvent aEvent ) +{ + aEvent.m_pFrame->CallCallback( aEvent.m_nEvent, aEvent.m_pData ); + maWaitingYieldCond.set(); +} + comphelper::SolarMutex* AquaSalInstance::GetYieldMutex() { return mpSalYieldMutex; @@ -453,15 +456,17 @@ void AquaSalInstance::handleAppDefinedEvent( NSEvent* pEvent ) case AppleRemoteControlEvent: // Defined in <apple_remote/RemoteMainController.h> { MediaCommand nCommand; - SalData* pSalData = GetSalData(); + AquaSalInstance *pInst = GetSalData()->mpFirstInstance; bool bIsFullScreenMode = false; - std::list<AquaSalFrame*>::iterator it = pSalData->maFrames.begin(); - while( it != pSalData->maFrames.end() ) + for( auto pSalFrame : pInst->getFrames() ) { - if ( (*it) && (*it)->mbFullScreen ) + const AquaSalFrame* pFrame = static_cast<const AquaSalFrame*>( pSalFrame ); + if ( pFrame->mbFullScreen ) + { bIsFullScreenMode = true; - ++it; + break; + } } switch ([pEvent data1]) @@ -497,9 +502,8 @@ void AquaSalInstance::handleAppDefinedEvent( NSEvent* pEvent ) default: break; } - AquaSalFrame* pFrame = pSalData->maFrames.front(); + AquaSalFrame* pFrame = static_cast<AquaSalFrame*>( pInst->anyFrame() ); vcl::Window* pWindow = pFrame ? pFrame->GetWindow() : nullptr; - if( pWindow ) { const Point aPoint; @@ -532,6 +536,7 @@ bool AquaSalInstance::RunInMainYield( bool bHandleAllCurrentEvents ) return false; } + static bool isWakeupEvent( NSEvent *pEvent ) { SAL_WNODEPRECATED_DECLARATIONS_PUSH @@ -542,8 +547,6 @@ SAL_WNODEPRECATED_DECLARATIONS_POP bool AquaSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents) { - bool bHadEvent = false; - // ensure that the per thread autorelease pool is top level and // will therefore not be destroyed by cocoa implicitly SalData::ensureThreadAutoreleasePool(); @@ -552,36 +555,10 @@ bool AquaSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents) // an own pool for each yield level ReleasePoolHolder aReleasePool; - // Release all locks so that we don't deadlock when we pull pending - // events from the event queue - bool bDispatchUser = true; - while( bDispatchUser ) - { - // get one user event - SalUserEvent aEvent( nullptr, nullptr, SalEvent::NONE ); - { - osl::MutexGuard g( maUserEventListMutex ); - if( ! maUserEvents.empty() ) - { - aEvent = maUserEvents.front(); - maUserEvents.pop_front(); - bHadEvent = true; - } - else - bDispatchUser = false; - } - - // dispatch it - if( aEvent.mpFrame && AquaSalFrame::isAlive( aEvent.mpFrame ) ) - { - aEvent.mpFrame->CallCallback( aEvent.mnType, aEvent.mpData ); - maWaitingYieldCond.set(); - } - - // return if only one event is asked for - if( !bHandleAllCurrentEvents && bDispatchUser ) - return true; - } + // first, process current user events + bool bHadEvent = DispatchUserEvents( bHandleAllCurrentEvents ); + if ( !bHandleAllCurrentEvents && bHadEvent ) + return true; // handle cocoa event queue // cocoa events may be only handled in the thread the NSApp was created @@ -639,13 +616,13 @@ SAL_WNODEPRECATED_DECLARATIONS_POP } // collect update rectangles - const std::list< AquaSalFrame* > rFrames( GetSalData()->maFrames ); - for( std::list< AquaSalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it ) + for( auto pSalFrame : GetSalData()->mpFirstInstance->getFrames() ) { - if( (*it)->mbShown && ! (*it)->maInvalidRect.IsEmpty() ) + AquaSalFrame* pFrame = static_cast<AquaSalFrame*>( const_cast<SalFrame*>( pSalFrame ) ); + if( pFrame->mbShown && ! pFrame->maInvalidRect.IsEmpty() ) { - (*it)->Flush( (*it)->maInvalidRect ); - (*it)->maInvalidRect.SetEmpty(); + pFrame->Flush( pFrame->maInvalidRect ); + pFrame->maInvalidRect.SetEmpty(); } } diff --git a/vcl/osx/vclnsapp.mm b/vcl/osx/vclnsapp.mm index 651fa2a014cc..dafcdb97aca5 100644 --- a/vcl/osx/vclnsapp.mm +++ b/vcl/osx/vclnsapp.mm @@ -136,24 +136,6 @@ SAL_WNODEPRECATED_DECLARATIONS_PUSH } } - // #i90083# handle frame switching - // FIXME: lousy workaround - if( (nModMask & (NSControlKeyMask|NSAlternateKeyMask)) == 0 ) - { - if( [[pEvent characters] isEqualToString: @"<"] || - [[pEvent characters] isEqualToString: @"~"] ) - { - [self cycleFrameForward: pFrame]; - return; - } - else if( [[pEvent characters] isEqualToString: @">"] || - [[pEvent characters] isEqualToString: @"`"] ) - { - [self cycleFrameBackward: pFrame]; - return; - } - } - // get information whether the event was handled; keyDown returns nothing GetSalData()->maKeyEventAnswer[ pEvent ] = false; bool bHandled = false; @@ -245,84 +227,6 @@ SAL_WNODEPRECATED_DECLARATIONS_POP [super sendEvent: pEvent]; } --(void)cycleFrameForward: (AquaSalFrame*)pCurFrame -{ - // find current frame in list - std::list< AquaSalFrame* >& rFrames( GetSalData()->maFrames ); - std::list< AquaSalFrame* >::iterator it = rFrames.begin(); - for( ; it != rFrames.end() && *it != pCurFrame; ++it ) - ; - if( it != rFrames.end() ) - { - // now find the next frame (or end) - do - { - ++it; - if( it != rFrames.end() ) - { - if( (*it)->mpDockMenuEntry != nullptr && - (*it)->mbShown ) - { - [(*it)->getNSWindow() makeKeyAndOrderFront: NSApp]; - return; - } - } - } while( it != rFrames.end() ); - // cycle around, find the next up to pCurFrame - it = rFrames.begin(); - while( *it != pCurFrame ) - { - if( (*it)->mpDockMenuEntry != nullptr && - (*it)->mbShown ) - { - [(*it)->getNSWindow() makeKeyAndOrderFront: NSApp]; - return; - } - ++it; - } - } -} - --(void)cycleFrameBackward: (AquaSalFrame*)pCurFrame -{ - // do the same as cycleFrameForward only with a reverse iterator - - // find current frame in list - std::list< AquaSalFrame* >& rFrames( GetSalData()->maFrames ); - std::list< AquaSalFrame* >::reverse_iterator it = rFrames.rbegin(); - for( ; it != rFrames.rend() && *it != pCurFrame; ++it ) - ; - if( it != rFrames.rend() ) - { - // now find the next frame (or end) - do - { - ++it; - if( it != rFrames.rend() ) - { - if( (*it)->mpDockMenuEntry != nullptr && - (*it)->mbShown ) - { - [(*it)->getNSWindow() makeKeyAndOrderFront: NSApp]; - return; - } - } - } while( it != rFrames.rend() ); - // cycle around, find the next up to pCurFrame - it = rFrames.rbegin(); - while( *it != pCurFrame ) - { - if( (*it)->mpDockMenuEntry != nullptr && - (*it)->mbShown ) - { - [(*it)->getNSWindow() makeKeyAndOrderFront: NSApp]; - return; - } - ++it; - } - } -} - -(NSMenu*)applicationDockMenu:(NSApplication *)sender { (void)sender; @@ -413,12 +317,13 @@ SAL_WNODEPRECATED_DECLARATIONS_POP { SolarMutexGuard aGuard; - SalData* pSalData = GetSalData(); - if( ! pSalData->maFrames.empty() ) + AquaSalInstance *pInst = GetSalData()->mpFirstInstance; + SalFrame *pAnyFrame = pInst->anyFrame(); + if( pAnyFrame ) { // the following QueryExit will likely present a message box, activate application [NSApp activateIgnoringOtherApps: YES]; - aReply = pSalData->maFrames.front()->CallCallback( SalEvent::Shutdown, nullptr ) ? NSTerminateCancel : NSTerminateNow; + aReply = pAnyFrame->CallCallback( SalEvent::Shutdown, nullptr ) ? NSTerminateCancel : NSTerminateNow; } if( aReply == NSTerminateNow ) @@ -439,9 +344,10 @@ SAL_WNODEPRECATED_DECLARATIONS_POP (void)pNotification; SolarMutexGuard aGuard; - const SalData* pSalData = GetSalData(); - if( !pSalData->maFrames.empty() ) - pSalData->maFrames.front()->CallCallback( SalEvent::SettingsChanged, nullptr ); + AquaSalInstance *pInst = GetSalData()->mpFirstInstance; + SalFrame *pAnyFrame = pInst->anyFrame(); + if( pAnyFrame ) + pAnyFrame->CallCallback( SalEvent::SettingsChanged, nullptr ); } -(void)screenParametersChanged: (NSNotification*) pNotification @@ -449,11 +355,10 @@ SAL_WNODEPRECATED_DECLARATIONS_POP (void)pNotification; SolarMutexGuard aGuard; - SalData* pSalData = GetSalData(); - std::list< AquaSalFrame* >::iterator it; - for( it = pSalData->maFrames.begin(); it != pSalData->maFrames.end(); ++it ) + for( auto pSalFrame : GetSalData()->mpFirstInstance->getFrames() ) { - (*it)->screenParametersChanged(); + AquaSalFrame *pFrame = static_cast<AquaSalFrame*>( const_cast<SalFrame*>( pSalFrame ) ); + pFrame->screenParametersChanged(); } } |