summaryrefslogtreecommitdiff
path: root/vcl/inc
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2017-09-04 17:40:13 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2017-09-28 17:48:37 +0200
commite310c00709ed4fe0788aeff5142e3581d8b4d319 (patch)
treeb85827742e4a93a57150b5d8d254ea85a6265379 /vcl/inc
parentdea1b649765262b2e8beac88b0977d5dead98953 (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/inc')
-rw-r--r--vcl/inc/headless/svpinst.hxx47
-rw-r--r--vcl/inc/osx/saldata.hxx11
-rw-r--r--vcl/inc/osx/salframe.h10
-rw-r--r--vcl/inc/osx/salinst.h20
-rw-r--r--vcl/inc/osx/vclnsapp.h2
-rw-r--r--vcl/inc/salusereventlist.hxx126
-rw-r--r--vcl/inc/unx/gendisp.hxx32
-rw-r--r--vcl/inc/unx/gtk/gtkdata.hxx8
-rw-r--r--vcl/inc/unx/saldisp.hxx8
9 files changed, 174 insertions, 90 deletions
diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx
index 0883981c4406..80566be18248 100644
--- a/vcl/inc/headless/svpinst.hxx
+++ b/vcl/inc/headless/svpinst.hxx
@@ -25,6 +25,7 @@
#include <salinst.hxx>
#include <salwtype.hxx>
#include <saltimer.hxx>
+#include <salusereventlist.hxx>
#include <unx/geninst.h>
#include <unx/genprn.h>
@@ -57,35 +58,18 @@ class GenPspGraphics;
SalInstance* svp_create_SalInstance();
-class VCL_DLLPUBLIC SvpSalInstance : public SalGenericInstance
+class VCL_DLLPUBLIC SvpSalInstance : public SalGenericInstance, public SalUserEventList
{
timeval m_aTimeout;
sal_uLong m_nTimeoutMS;
int m_pTimeoutFDS[2];
- // internal event queue
- struct SalUserEvent
- {
- const SalFrame* m_pFrame;
- ImplSVEvent* m_pData;
- SalEvent m_nEvent;
-
- SalUserEvent( const SalFrame* pFrame, ImplSVEvent* pData, SalEvent nEvent )
- : m_pFrame( pFrame ),
- m_pData( pData ),
- m_nEvent( nEvent )
- {}
- };
-
- osl::Mutex m_aEventGuard;
- std::list< SalUserEvent > m_aUserEvents;
-
- std::list< SalFrame* > m_aFrames;
-
- bool isFrameAlive( const SalFrame* pFrame ) const;
-
void DoReleaseYield( int nTimeoutMS );
+ virtual void TriggerUserEventProcessing() override;
+ virtual void ProcessEvent( SalUserEvent aEvent ) override;
+ void Wakeup();
+
public:
static SvpSalInstance* s_pDefaultInstance;
@@ -95,20 +79,15 @@ public:
void CloseWakeupPipe(bool log);
void CreateWakeupPipe(bool log);
- void PostEvent(const SalFrame* pFrame, ImplSVEvent* pData, SalEvent nEvent);
-
#ifdef ANDROID
bool PostedEventsInQueue();
#endif
void StartTimer( sal_uLong nMS );
void StopTimer();
- void Wakeup();
- void registerFrame( SalFrame* pFrame ) { m_aFrames.push_back( pFrame ); }
- void deregisterFrame( SalFrame* pFrame );
- const std::list< SalFrame* >&
- getFrames() const { return m_aFrames; }
+ inline void registerFrame( SalFrame* pFrame );
+ inline void deregisterFrame( SalFrame* pFrame );
bool CheckTimeout( bool bExecuteTimers = true );
@@ -171,6 +150,16 @@ public:
virtual GenPspGraphics *CreatePrintGraphics() override;
};
+inline void SvpSalInstance::registerFrame( SalFrame* pFrame )
+{
+ insertFrame( pFrame );
+}
+
+inline void SvpSalInstance::deregisterFrame( SalFrame* pFrame )
+{
+ eraseFrame( pFrame );
+}
+
#endif // INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/osx/saldata.hxx b/vcl/inc/osx/saldata.hxx
index fbc28e05391d..5ec684b83973 100644
--- a/vcl/inc/osx/saldata.hxx
+++ b/vcl/inc/osx/saldata.hxx
@@ -45,6 +45,7 @@
#include "apple_remote/RemoteMainController.h"
+class AquaSalFrame;
class AquaSalInstance;
class SalObject;
class SalFrame;
@@ -53,14 +54,6 @@ class SalPrinter;
class SystemFontList;
#define SAL_CLIPRECT_COUNT 16
-
-class AquaSalFrame;
-struct FrameHash : public std::hash<sal_IntPtr>
-{
- size_t operator()(const AquaSalFrame* frame) const
- { return std::hash<sal_IntPtr>::operator()( reinterpret_cast<const sal_IntPtr>(frame) ); }
-};
-
#define INVALID_CURSOR_PTR reinterpret_cast<NSCursor*>(0xdeadbeef)
// Singleton, instantiated from Application::Application() in
@@ -71,8 +64,6 @@ class SalData
public:
SALTIMERPROC mpTimerProc; // timer callback proc
AquaSalInstance *mpFirstInstance; // pointer of first instance
- std::list<AquaSalFrame*> maFrames; // list of all frames
- std::unordered_set<const AquaSalFrame*,FrameHash> maFrameCheck;// for fast check of frame existence
std::list<AquaSalFrame*> maPresentationFrames; // list of frames in presentation mode
SalObject *mpFirstObject; // pointer of first object window
SalVirtualDevice *mpFirstVD; // first VirDev
diff --git a/vcl/inc/osx/salframe.h b/vcl/inc/osx/salframe.h
index e99a3175876d..f8cef1834106 100644
--- a/vcl/inc/osx/salframe.h
+++ b/vcl/inc/osx/salframe.h
@@ -26,6 +26,7 @@
#include <vcl/sysdata.hxx>
+#include "osx/salinst.h"
#include "osx/salmenu.h"
#include "osx/saldata.hxx"
#include "osx/osxvcltypes.h"
@@ -163,8 +164,7 @@ public:
// trigger painting of the window
void SendPaintEvent( const tools::Rectangle* pRect = nullptr );
- static bool isAlive( const AquaSalFrame* pFrame )
- { return GetSalData()->maFrameCheck.find( pFrame ) != GetSalData()->maFrameCheck.end(); }
+ static inline bool isAlive( const AquaSalFrame* pFrame );
static AquaSalFrame* GetCaptureFrame() { return s_pCaptureFrame; }
@@ -204,6 +204,12 @@ private: // data
AquaSalFrame& operator=(const AquaSalFrame&) = delete;
};
+inline bool AquaSalFrame::isAlive( const AquaSalFrame* pFrame )
+{
+ AquaSalInstance *pInst = GetSalData()->mpFirstInstance;
+ return pInst && pInst->isFrameAlive( pFrame );
+}
+
#endif // INCLUDED_VCL_INC_OSX_SALFRAME_H
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/osx/salinst.h b/vcl/inc/osx/salinst.h
index 0e30dfafb693..272cfc722d64 100644
--- a/vcl/inc/osx/salinst.h
+++ b/vcl/inc/osx/salinst.h
@@ -34,6 +34,8 @@
#include "osx/runinmain.hxx"
+#include "salusereventlist.hxx"
+
class AquaSalFrame;
class SalFrame;
class SalObject;
@@ -59,27 +61,18 @@ public:
virtual bool IsCurrentThread() const override;
};
-class AquaSalInstance : public SalInstance
+class AquaSalInstance : public SalInstance, public SalUserEventList
{
- struct SalUserEvent
- {
- AquaSalFrame* mpFrame;
- void* mpData;
- SalEvent mnType;
-
- SalUserEvent( AquaSalFrame* pFrame, void* pData, SalEvent nType ) :
- mpFrame( pFrame ), mpData( pData ), mnType( nType )
- {}
- };
-
bool RunInMainYield( bool bHandleAllCurrentEvents );
+ virtual void TriggerUserEventProcessing() override;
+ virtual void ProcessEvent( SalUserEvent aEvent ) override;
+
public:
SalYieldMutex* mpSalYieldMutex; // Sal-Yield-Mutex
OUString maDefaultPrinter;
oslThreadIdentifier maMainThread;
int mnActivePrintJobs;
- std::list< SalUserEvent > maUserEvents;
osl::Mutex maUserEventListMutex;
osl::Condition maWaitingYieldCond;
bool mbIsLiveResize;
@@ -145,7 +138,6 @@ public:
public:
friend class AquaSalFrame;
- void PostUserEvent( AquaSalFrame* pFrame, SalEvent nType, void* pData );
void delayedSettingsChanged( bool bInvalidate );
// Is this the NSAppThread?
diff --git a/vcl/inc/osx/vclnsapp.h b/vcl/inc/osx/vclnsapp.h
index c899ffce59d1..39bd3170abaf 100644
--- a/vcl/inc/osx/vclnsapp.h
+++ b/vcl/inc/osx/vclnsapp.h
@@ -61,8 +61,6 @@ class AquaSalFrame;
#endif
-(BOOL)applicationShouldHandleReopen: (NSApplication*)pApp hasVisibleWindows: (BOOL)bWinVisible;
-(void)setDockIconClickHandler: (NSObject*)pHandler;
--(void)cycleFrameForward: (AquaSalFrame*)pCurFrame;
--(void)cycleFrameBackward: (AquaSalFrame*)pCurFrame;
@end
#endif // INCLUDED_VCL_INC_OSX_VCLNSAPP_H
diff --git a/vcl/inc/salusereventlist.hxx b/vcl/inc/salusereventlist.hxx
new file mode 100644
index 000000000000..1f689fb5cbf7
--- /dev/null
+++ b/vcl/inc/salusereventlist.hxx
@@ -0,0 +1,126 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_VCL_INC_SALUSEREVENTLIST_HXX
+#define INCLUDED_VCL_INC_SALUSEREVENTLIST_HXX
+
+#include <sal/config.h>
+#include <vcl/dllapi.h>
+#include <osl/mutex.hxx>
+
+#include <assert.h>
+
+#include <list>
+#include <unordered_set>
+
+class SalFrame;
+enum class SalEvent;
+
+struct SalFrameHash : public std::hash<sal_IntPtr>
+{
+ size_t operator()(const SalFrame* frame) const
+ { return std::hash<sal_IntPtr>::operator()( reinterpret_cast<const sal_IntPtr>(frame) ); }
+};
+
+typedef std::unordered_set< SalFrame*, SalFrameHash > SalFrameSet;
+
+class VCL_PLUGIN_PUBLIC SalUserEventList
+{
+public:
+ struct SalUserEvent
+ {
+ SalFrame* m_pFrame;
+ void* m_pData;
+ SalEvent m_nEvent;
+
+ SalUserEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
+ : m_pFrame( pFrame ),
+ m_pData( pData ),
+ m_nEvent( nEvent )
+ {}
+
+ bool operator==(const SalUserEvent &aEvent) const
+ {
+ return m_pFrame == aEvent.m_pFrame
+ && m_pData == aEvent.m_pData
+ && m_nEvent== aEvent.m_nEvent;
+ }
+ };
+
+protected:
+ mutable osl::Mutex m_aUserEventsMutex;
+ std::list< SalUserEvent > m_aUserEvents;
+ std::list< SalUserEvent > m_aProcessingUserEvents;
+ SalFrameSet m_aFrames;
+
+ virtual void ProcessEvent( SalUserEvent aEvent ) = 0;
+ virtual void TriggerUserEventProcessing() = 0;
+ virtual void TriggerAllUserEventsProcessed() {};
+
+public:
+ SalUserEventList();
+ virtual ~SalUserEventList();
+
+ inline const SalFrameSet& getFrames() const;
+ inline SalFrame* anyFrame() const;
+ void insertFrame( SalFrame* pFrame );
+ void eraseFrame( SalFrame* pFrame );
+ inline bool isFrameAlive( const SalFrame* pFrame ) const;
+
+ void PostEvent( SalFrame* pFrame, void* pData, SalEvent nEvent );
+ bool RemoveEvent( SalFrame* pFrame, void* pData, SalEvent nEvent );
+ inline bool HasUserEvents() const;
+
+ bool DispatchUserEvents( bool bHandleAllCurrentEvents );
+};
+
+inline SalFrame* SalUserEventList::anyFrame() const
+{
+ if ( m_aFrames.empty() )
+ return nullptr;
+ return *m_aFrames.begin();
+}
+
+inline bool SalUserEventList::isFrameAlive( const SalFrame* pFrame ) const
+{
+ auto it = m_aFrames.find( const_cast<SalFrame*>( pFrame ) );
+ return it != m_aFrames.end();
+}
+
+inline bool SalUserEventList::HasUserEvents() const
+{
+ osl::MutexGuard aGuard( m_aUserEventsMutex );
+ return !(m_aUserEvents.empty() && m_aProcessingUserEvents.empty());
+}
+
+inline void SalUserEventList::PostEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
+{
+ osl::MutexGuard aGuard( m_aUserEventsMutex );
+ m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
+ TriggerUserEventProcessing();
+}
+
+inline const SalFrameSet& SalUserEventList::getFrames() const
+{
+ return m_aFrames;
+}
+
+#endif // INCLUDED_VCL_INC_SALUSEREVENTLIST_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/unx/gendisp.hxx b/vcl/inc/unx/gendisp.hxx
index 64564237a232..5c8f5113c300 100644
--- a/vcl/inc/unx/gendisp.hxx
+++ b/vcl/inc/unx/gendisp.hxx
@@ -27,45 +27,27 @@
#include <vcl/dllapi.h>
#include <list>
#include <vector>
+#include <salusereventlist.hxx>
class SalFrame;
-class VCL_DLLPUBLIC SalGenericDisplay
+class VCL_DLLPUBLIC SalGenericDisplay : public SalUserEventList
{
- mutable osl::Mutex m_aEventGuard;
- struct SalUserEvent
- {
- SalFrame* m_pFrame;
- void* m_pData;
- SalEvent m_nEvent;
-
- SalUserEvent( SalFrame* pFrame, void* pData,
- SalEvent nEvent )
- : m_pFrame( pFrame ),
- m_pData( pData ),
- m_nEvent( nEvent )
- {}
- };
- std::list< SalUserEvent > m_aUserEvents;
protected:
SalFrame* m_pCapture;
- std::list<SalFrame*> m_aFrames;
+
+ virtual void ProcessEvent( SalUserEvent aEvent ) override;
+
public:
SalGenericDisplay();
- virtual ~SalGenericDisplay();
-
- osl::Mutex& getEventGuardMutex() { return m_aEventGuard; }
+ virtual ~SalGenericDisplay() override;
void registerFrame( SalFrame* pFrame );
virtual void deregisterFrame( SalFrame* pFrame );
void emitDisplayChanged();
- // Event handling
- virtual void PostUserEvent() = 0;
-
void SendInternalEvent( SalFrame* pFrame, void* pData, SalEvent nEvent = SalEvent::UserEvent );
- void CancelInternalEvent( SalFrame const * pFrame, void const * pData, SalEvent nEvent );
+ void CancelInternalEvent( SalFrame* pFrame, void* pData, SalEvent nEvent );
bool DispatchInternalEvent();
- bool HasUserEvents() const;
bool MouseCaptured( const SalFrame *pFrameData ) const
{ return m_pCapture == pFrameData; }
diff --git a/vcl/inc/unx/gtk/gtkdata.hxx b/vcl/inc/unx/gtk/gtkdata.hxx
index 4f4d520fc141..01b5c46b8dca 100644
--- a/vcl/inc/unx/gtk/gtkdata.hxx
+++ b/vcl/inc/unx/gtk/gtkdata.hxx
@@ -117,9 +117,9 @@ public:
static void initNWF();
static void deInitNWF();
- static gboolean userEventFn( gpointer data );
+ void TriggerUserEventProcessing();
+ void TriggerAllUserEventsProcessed();
- void PostUserEvent();
bool Yield( bool bWait, bool bHandleAllCurrentEvents );
inline GdkDisplay *GetGdkDisplay();
@@ -146,6 +146,7 @@ class GtkSalDisplay : public SalDisplay
GdkCursor* getFromXBM( const unsigned char *pBitmap, const unsigned char *pMask,
int nWidth, int nHeight, int nXHot, int nYHot );
+
public:
GtkSalDisplay( GdkDisplay* pDisplay );
virtual ~GtkSalDisplay() override;
@@ -180,7 +181,8 @@ public:
void screenSizeChanged( GdkScreen const * );
void monitorsChanged( GdkScreen const * );
- virtual void PostUserEvent() override;
+ virtual void TriggerUserEventProcessing() override;
+ virtual void TriggerAllUserEventsProcessed() override;
#if !GTK_CHECK_VERSION(3,0,0)
virtual bool Dispatch( XEvent *pEvent ) override;
diff --git a/vcl/inc/unx/saldisp.hxx b/vcl/inc/unx/saldisp.hxx
index 0ec4e10e7d65..8f96e03630b0 100644
--- a/vcl/inc/unx/saldisp.hxx
+++ b/vcl/inc/unx/saldisp.hxx
@@ -168,7 +168,7 @@ public:
virtual bool Yield( bool bWait, bool bHandleAllCurrentEvents );
virtual void Wakeup();
- virtual void PostUserEvent();
+ void TriggerUserEventProcessing();
virtual void Insert( int fd, void* data,
YieldFunc pending,
@@ -371,12 +371,10 @@ public:
{ return getDataForScreen( nXScreen ).m_aRoot; }
unsigned int GetXScreenCount() const { return m_aScreens.size(); }
- const std::list< SalFrame* >& getFrames() const { return m_aFrames; }
+ const SalFrameSet& getFrames() const { return m_aFrames; }
bool IsNumLockFromXS() const { return bNumLockFromXS_; }
std::list< SalObject* >& getSalObjects() { return m_aSalObjects; }
-
- virtual void PostUserEvent() override = 0;
};
inline Display *SalColormap::GetXDisplay() const
@@ -390,7 +388,7 @@ public:
virtual bool Dispatch( XEvent *pEvent ) override;
virtual void Yield();
- virtual void PostUserEvent() override;
+ virtual void TriggerUserEventProcessing() override;
bool IsEvent();
void SetupInput();