vcl: Move X11DisplayConnectionDispatch logic to gen vcl plugin
X11DisplayConnectionDispatch is only used inside of the gen/x11
vcl plugin.
After previous commit
Change-Id: I32faa336aaef3ca30b71228b35a7be2c772171ca
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Mon Mar 2 05:31:51 2026 +0100
vcl: Have an abstract DisplayConnectionDispatch base class
, the logic involving X11DisplayConnectionDispatch
can now be moved into the gen vcl plugin itself:
Move the DisplayEventHandler and X11DisplayConnectionDispatch classes
from Library_vcl to Library_vclplug_gen (and out of the vcl
namespace).
Move SalInstance::m_pEventInst and the 2 methods making
use of X11DisplayConnectionDispatch from the SalInstance
base class used for all platforms and vcl plugins to the
gen-specific X11SalInstance, because it's only relevant there.
Add GetX11SalInstance() that allows getting the more
specific subclass and use it where it's needed now
to access the methods moved to this subclass.
This also prepares for further simplification
in upcoming commits.
Change-Id: I41a826234b7737b97f91d3980c262419ae6034aa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200760
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
@@ -75,6 +75,7 @@ $(eval $(call gb_Library_add_libs,vclplug_gen,\
|
||||
))
|
||||
|
||||
$(eval $(call gb_Library_add_exception_objects,vclplug_gen,\
|
||||
vcl/unx/generic/app/X11DisplayConnectionDispatch \
|
||||
vcl/unx/generic/app/i18n_cb \
|
||||
vcl/unx/generic/app/i18n_ic \
|
||||
vcl/unx/generic/app/i18n_im \
|
||||
|
||||
@@ -19,23 +19,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sal/config.h>
|
||||
#include <cppuhelper/implbase.hxx>
|
||||
#include <com/sun/star/uno/Reference.hxx>
|
||||
#include <rtl/ref.hxx>
|
||||
#include <cppuhelper/weak.hxx>
|
||||
#include <vcl/dllapi.h>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace vcl {
|
||||
|
||||
class DisplayEventHandler : public cppu::WeakImplHelper<>
|
||||
{
|
||||
public:
|
||||
virtual bool handleEvent(const void* pEvent) = 0;
|
||||
virtual void shutdown() noexcept = 0;
|
||||
};
|
||||
|
||||
class VCL_DLLPUBLIC DisplayConnectionDispatch : public cppu::OWeakObject
|
||||
{
|
||||
public:
|
||||
@@ -44,24 +32,6 @@ public:
|
||||
|
||||
virtual void terminate() = 0;
|
||||
};
|
||||
|
||||
class VCL_DLLPUBLIC X11DisplayConnectionDispatch final : public DisplayConnectionDispatch
|
||||
{
|
||||
std::mutex m_aMutex;
|
||||
std::vector<rtl::Reference<DisplayEventHandler>> m_aHandlers;
|
||||
public:
|
||||
X11DisplayConnectionDispatch();
|
||||
~X11DisplayConnectionDispatch() override;
|
||||
|
||||
void start();
|
||||
void terminate() override;
|
||||
|
||||
bool dispatchEvent(const void* pEvent);
|
||||
|
||||
void addEventHandler(const rtl::Reference<DisplayEventHandler>& handler);
|
||||
void removeEventHandler(const rtl::Reference<DisplayEventHandler>& handler);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -83,7 +83,6 @@ typedef struct _cairo_font_options cairo_font_options_t;
|
||||
class VCL_DLLPUBLIC SalInstance
|
||||
{
|
||||
private:
|
||||
rtl::Reference<vcl::X11DisplayConnectionDispatch> m_pEventInst;
|
||||
const std::unique_ptr<comphelper::SolarMutex> m_pYieldMutex;
|
||||
css::uno::Reference<css::datatransfer::clipboard::XClipboard> m_clipboard;
|
||||
o3tl::sorted_vector<OUString> m_usedUI;
|
||||
@@ -193,15 +192,6 @@ public:
|
||||
CreateColorChooserDialog(weld::Window* pParent, vcl::ColorPickerMode eMode);
|
||||
virtual weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
|
||||
|
||||
// methods for X11DisplayConnectionDispatch
|
||||
|
||||
void SetEventCallback(rtl::Reference<vcl::X11DisplayConnectionDispatch> const& pInstance)
|
||||
{
|
||||
m_pEventInst = pInstance;
|
||||
}
|
||||
|
||||
bool CallEventCallback(const void* pEvent);
|
||||
|
||||
// dtrans implementation
|
||||
virtual css::uno::Reference<css::datatransfer::clipboard::XClipboard>
|
||||
CreateClipboard(ClipboardSelectionType eSelection);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
||||
/*
|
||||
* 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 .
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sal/config.h>
|
||||
|
||||
#include <displayconnectiondispatch.hxx>
|
||||
|
||||
#include <cppuhelper/implbase.hxx>
|
||||
#include <com/sun/star/uno/Reference.hxx>
|
||||
#include <rtl/ref.hxx>
|
||||
#include <vcl/dllapi.h>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
class DisplayEventHandler : public cppu::WeakImplHelper<>
|
||||
{
|
||||
public:
|
||||
virtual bool handleEvent(const void* pEvent) = 0;
|
||||
virtual void shutdown() noexcept = 0;
|
||||
};
|
||||
|
||||
class X11DisplayConnectionDispatch final : public vcl::DisplayConnectionDispatch
|
||||
{
|
||||
std::mutex m_aMutex;
|
||||
std::vector<rtl::Reference<DisplayEventHandler>> m_aHandlers;
|
||||
|
||||
public:
|
||||
X11DisplayConnectionDispatch();
|
||||
~X11DisplayConnectionDispatch() override;
|
||||
|
||||
void start();
|
||||
void terminate() override;
|
||||
|
||||
bool dispatchEvent(const void* pEvent);
|
||||
|
||||
void addEventHandler(const rtl::Reference<DisplayEventHandler>& handler);
|
||||
void removeEventHandler(const rtl::Reference<DisplayEventHandler>& handler);
|
||||
};
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
+17
-1
@@ -19,6 +19,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "X11DisplayConnectionDispatch.hxx"
|
||||
|
||||
#include <salinst.hxx>
|
||||
#include <unx/geninst.h>
|
||||
|
||||
@@ -32,6 +34,7 @@ class SalX11Display;
|
||||
class X11SalInstance final : public SalGenericInstance
|
||||
{
|
||||
private:
|
||||
rtl::Reference<X11DisplayConnectionDispatch> m_pEventInst;
|
||||
std::unordered_map< Atom, css::uno::Reference< css::datatransfer::clipboard::XClipboard > > m_aInstances;
|
||||
|
||||
SalXLib *mpXLib;
|
||||
@@ -88,7 +91,20 @@ public:
|
||||
virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) override;
|
||||
|
||||
/** Get the DisplayConnection. It allows to send display events to the application. */
|
||||
static rtl::Reference<vcl::X11DisplayConnectionDispatch> GetDisplayConnection();
|
||||
static rtl::Reference<X11DisplayConnectionDispatch> GetDisplayConnection();
|
||||
|
||||
// methods for X11DisplayConnectionDispatch
|
||||
void SetEventCallback(rtl::Reference<X11DisplayConnectionDispatch> const& pInstance)
|
||||
{
|
||||
m_pEventInst = pInstance;
|
||||
}
|
||||
|
||||
bool CallEventCallback(const void* pEvent);
|
||||
};
|
||||
|
||||
inline X11SalInstance* GetX11SalInstance()
|
||||
{
|
||||
return static_cast<X11SalInstance*>(GetSalInstance());
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -62,11 +62,6 @@ std::unique_ptr<SalMenu> SalInstance::CreateMenu(bool, Menu*)
|
||||
|
||||
std::unique_ptr<SalMenuItem> SalInstance::CreateMenuItem(const SalItemParams&) { return nullptr; }
|
||||
|
||||
bool SalInstance::CallEventCallback(const void* pEvent)
|
||||
{
|
||||
return m_pEventInst.is() && m_pEventInst->dispatchEvent(pEvent);
|
||||
}
|
||||
|
||||
bool SalInstance::DoExecute(int&)
|
||||
{
|
||||
// can't run on system event loop without implementing DoExecute and DoQuit
|
||||
|
||||
@@ -17,16 +17,9 @@
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
#include <vcl/svapp.hxx>
|
||||
#include <tools/debug.hxx>
|
||||
|
||||
#include <displayconnectiondispatch.hxx>
|
||||
#include <svdata.hxx>
|
||||
#include <salinst.hxx>
|
||||
|
||||
using namespace vcl;
|
||||
using namespace com::sun::star::uno;
|
||||
using namespace com::sun::star::awt;
|
||||
|
||||
DisplayConnectionDispatch::DisplayConnectionDispatch()
|
||||
{
|
||||
@@ -34,64 +27,4 @@ DisplayConnectionDispatch::DisplayConnectionDispatch()
|
||||
|
||||
DisplayConnectionDispatch::~DisplayConnectionDispatch() {}
|
||||
|
||||
X11DisplayConnectionDispatch::X11DisplayConnectionDispatch() {}
|
||||
|
||||
X11DisplayConnectionDispatch::~X11DisplayConnectionDispatch() {}
|
||||
|
||||
void X11DisplayConnectionDispatch::start()
|
||||
{
|
||||
DBG_TESTSOLARMUTEX();
|
||||
ImplSVData* pSVData = ImplGetSVData();
|
||||
pSVData->mpDefInst->SetEventCallback( this );
|
||||
}
|
||||
|
||||
void X11DisplayConnectionDispatch::terminate()
|
||||
{
|
||||
DBG_TESTSOLARMUTEX();
|
||||
ImplSVData* pSVData = ImplGetSVData();
|
||||
|
||||
if( pSVData )
|
||||
{
|
||||
pSVData->mpDefInst->SetEventCallback( nullptr );
|
||||
}
|
||||
|
||||
SolarMutexReleaser aRel;
|
||||
|
||||
std::scoped_lock aGuard( m_aMutex );
|
||||
std::vector<rtl::Reference<DisplayEventHandler>> aLocalList(m_aHandlers);
|
||||
for (auto const& elem : aLocalList)
|
||||
elem->shutdown();
|
||||
}
|
||||
|
||||
void X11DisplayConnectionDispatch::addEventHandler(
|
||||
const rtl::Reference<DisplayEventHandler>& handler)
|
||||
{
|
||||
std::scoped_lock aGuard( m_aMutex );
|
||||
|
||||
m_aHandlers.push_back( handler );
|
||||
}
|
||||
|
||||
void X11DisplayConnectionDispatch::removeEventHandler(
|
||||
const rtl::Reference<DisplayEventHandler>& handler)
|
||||
{
|
||||
std::scoped_lock aGuard( m_aMutex );
|
||||
|
||||
std::erase(m_aHandlers, handler);
|
||||
}
|
||||
|
||||
bool X11DisplayConnectionDispatch::dispatchEvent(const void* pEvent)
|
||||
{
|
||||
SolarMutexReleaser aRel;
|
||||
|
||||
std::vector<rtl::Reference<DisplayEventHandler>> handlers;
|
||||
{
|
||||
std::scoped_lock aGuard( m_aMutex );
|
||||
handlers = m_aHandlers;
|
||||
}
|
||||
for (auto const& handle : handlers)
|
||||
if (handle->handleEvent(pEvent))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
||||
/*
|
||||
* 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 .
|
||||
*/
|
||||
|
||||
#include <salinst.hxx>
|
||||
#include <svdata.hxx>
|
||||
#include <unx/X11DisplayConnectionDispatch.hxx>
|
||||
#include <unx/salinst.h>
|
||||
|
||||
#include <tools/debug.hxx>
|
||||
#include <vcl/svapp.hxx>
|
||||
|
||||
using namespace vcl;
|
||||
|
||||
X11DisplayConnectionDispatch::X11DisplayConnectionDispatch() {}
|
||||
|
||||
X11DisplayConnectionDispatch::~X11DisplayConnectionDispatch() {}
|
||||
|
||||
void X11DisplayConnectionDispatch::start()
|
||||
{
|
||||
DBG_TESTSOLARMUTEX();
|
||||
GetX11SalInstance()->SetEventCallback(this);
|
||||
}
|
||||
|
||||
void X11DisplayConnectionDispatch::terminate()
|
||||
{
|
||||
DBG_TESTSOLARMUTEX();
|
||||
ImplSVData* pSVData = ImplGetSVData();
|
||||
|
||||
if (pSVData)
|
||||
{
|
||||
GetX11SalInstance()->SetEventCallback(nullptr);
|
||||
}
|
||||
|
||||
SolarMutexReleaser aRel;
|
||||
|
||||
std::scoped_lock aGuard(m_aMutex);
|
||||
std::vector<rtl::Reference<DisplayEventHandler>> aLocalList(m_aHandlers);
|
||||
for (auto const& elem : aLocalList)
|
||||
elem->shutdown();
|
||||
}
|
||||
|
||||
void X11DisplayConnectionDispatch::addEventHandler(
|
||||
const rtl::Reference<DisplayEventHandler>& handler)
|
||||
{
|
||||
std::scoped_lock aGuard(m_aMutex);
|
||||
|
||||
m_aHandlers.push_back(handler);
|
||||
}
|
||||
|
||||
void X11DisplayConnectionDispatch::removeEventHandler(
|
||||
const rtl::Reference<DisplayEventHandler>& handler)
|
||||
{
|
||||
std::scoped_lock aGuard(m_aMutex);
|
||||
|
||||
std::erase(m_aHandlers, handler);
|
||||
}
|
||||
|
||||
bool X11DisplayConnectionDispatch::dispatchEvent(const void* pEvent)
|
||||
{
|
||||
SolarMutexReleaser aRel;
|
||||
|
||||
std::vector<rtl::Reference<DisplayEventHandler>> handlers;
|
||||
{
|
||||
std::scoped_lock aGuard(m_aMutex);
|
||||
handlers = m_aHandlers;
|
||||
}
|
||||
for (auto const& handle : handlers)
|
||||
if (handle->handleEvent(pEvent))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
@@ -52,6 +52,7 @@
|
||||
#include <unx/i18n_xkb.hxx>
|
||||
#include <unx/saldisp.hxx>
|
||||
#include <unx/saldata.hxx>
|
||||
#include <unx/salinst.h>
|
||||
#include <salinst.hxx>
|
||||
#include <unx/salframe.h>
|
||||
#include <vcl/keycodes.hxx>
|
||||
@@ -1880,8 +1881,7 @@ void SalX11Display::Dispatch(XEvent* pEvent)
|
||||
return;
|
||||
}
|
||||
|
||||
SalInstance* pInstance = GetSalInstance();
|
||||
pInstance->CallEventCallback(pEvent);
|
||||
GetX11SalInstance()->CallEventCallback(pEvent);
|
||||
|
||||
switch( pEvent->type )
|
||||
{
|
||||
|
||||
@@ -228,20 +228,25 @@ std::shared_ptr<SalBitmap> X11SalInstance::CreateSalBitmap()
|
||||
return std::make_shared<SvpSalBitmap>();
|
||||
}
|
||||
|
||||
rtl::Reference<vcl::X11DisplayConnectionDispatch> X11SalInstance::GetDisplayConnection()
|
||||
rtl::Reference<X11DisplayConnectionDispatch> X11SalInstance::GetDisplayConnection()
|
||||
{
|
||||
ImplSVData* pSVData = ImplGetSVData();
|
||||
|
||||
if (!pSVData->mxDisplayConnection.is())
|
||||
{
|
||||
rtl::Reference<vcl::X11DisplayConnectionDispatch> pDisplayConnection(
|
||||
new vcl::X11DisplayConnectionDispatch);
|
||||
rtl::Reference<X11DisplayConnectionDispatch> pDisplayConnection(
|
||||
new X11DisplayConnectionDispatch);
|
||||
pSVData->mxDisplayConnection = pDisplayConnection;
|
||||
pDisplayConnection->start();
|
||||
return pDisplayConnection;
|
||||
}
|
||||
|
||||
return dynamic_cast<vcl::X11DisplayConnectionDispatch*>(pSVData->mxDisplayConnection.get());
|
||||
return dynamic_cast<X11DisplayConnectionDispatch*>(pSVData->mxDisplayConnection.get());
|
||||
}
|
||||
|
||||
bool X11SalInstance::CallEventCallback(const void* pEvent)
|
||||
{
|
||||
return m_pEventInst.is() && m_pEventInst->dispatchEvent(pEvent);
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <displayconnectiondispatch.hxx>
|
||||
#include <DropTarget.hxx>
|
||||
#include <unx/X11DisplayConnectionDispatch.hxx>
|
||||
|
||||
#include <cppuhelper/compbase.hxx>
|
||||
#include <cppuhelper/implbase.hxx>
|
||||
@@ -115,7 +115,7 @@ namespace x11 {
|
||||
|
||||
};
|
||||
|
||||
class SelectionManager : public cppu::ImplInheritanceHelper<vcl::DisplayEventHandler,
|
||||
class SelectionManager : public cppu::ImplInheritanceHelper<DisplayEventHandler,
|
||||
css::datatransfer::dnd::XDragSource,
|
||||
css::frame::XTerminateListener>,
|
||||
public SelectionAdaptor
|
||||
@@ -214,7 +214,7 @@ namespace x11 {
|
||||
::osl::Condition m_aDragRunning;
|
||||
::Window m_aWindow;
|
||||
css::uno::Reference< css::frame::XDesktop2 > m_xDesktop;
|
||||
rtl::Reference<vcl::X11DisplayConnectionDispatch> m_xDisplayConnection;
|
||||
rtl::Reference<X11DisplayConnectionDispatch> m_xDisplayConnection;
|
||||
Time m_nSelectionTimestamp;
|
||||
|
||||
// members used for Xdnd
|
||||
|
||||
Reference in New Issue
Block a user