vcl/Library_vclplug_gen.mk | 1 vcl/inc/displayconnectiondispatch.hxx | 32 ------ vcl/inc/salinst.hxx | 10 -- vcl/inc/unx/X11DisplayConnectionDispatch.hxx | 58 ++++++++++++ vcl/inc/unx/salinst.h | 18 +++ vcl/source/app/salinst.cxx | 5 - vcl/source/helper/displayconnectiondispatch.cxx | 67 -------------- vcl/unx/generic/app/X11DisplayConnectionDispatch.cxx | 89 +++++++++++++++++++ vcl/unx/generic/app/saldisp.cxx | 4 vcl/unx/generic/app/salinst.cxx | 13 +- vcl/unx/generic/dtrans/X11_selection.hxx | 6 - 11 files changed, 180 insertions(+), 123 deletions(-)
New commits: commit 09537873130b7d475001aee3403fbcc437c6b39b Author: Michael Weghorn <[email protected]> AuthorDate: Mon Mar 2 05:47:20 2026 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Mon Mar 2 17:21:31 2026 +0100 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 <[email protected]> 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 <[email protected]> diff --git a/vcl/Library_vclplug_gen.mk b/vcl/Library_vclplug_gen.mk index 43b825c5eae2..bdaf12ff62b2 100644 --- a/vcl/Library_vclplug_gen.mk +++ b/vcl/Library_vclplug_gen.mk @@ -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 \ diff --git a/vcl/inc/displayconnectiondispatch.hxx b/vcl/inc/displayconnectiondispatch.hxx index 739291e03cd9..222ddd361aca 100644 --- a/vcl/inc/displayconnectiondispatch.hxx +++ b/vcl/inc/displayconnectiondispatch.hxx @@ -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: */ diff --git a/vcl/inc/salinst.hxx b/vcl/inc/salinst.hxx index 2ab9d7fef481..f35a59fba576 100644 --- a/vcl/inc/salinst.hxx +++ b/vcl/inc/salinst.hxx @@ -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); diff --git a/vcl/inc/unx/X11DisplayConnectionDispatch.hxx b/vcl/inc/unx/X11DisplayConnectionDispatch.hxx new file mode 100644 index 000000000000..69f4ed21d005 --- /dev/null +++ b/vcl/inc/unx/X11DisplayConnectionDispatch.hxx @@ -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: */ diff --git a/vcl/inc/unx/salinst.h b/vcl/inc/unx/salinst.h index 9fd33bd5b64d..8767541e2f87 100644 --- a/vcl/inc/unx/salinst.h +++ b/vcl/inc/unx/salinst.h @@ -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: */ diff --git a/vcl/source/app/salinst.cxx b/vcl/source/app/salinst.cxx index 6fb6230ee2c3..3d01a829533f 100644 --- a/vcl/source/app/salinst.cxx +++ b/vcl/source/app/salinst.cxx @@ -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 diff --git a/vcl/source/helper/displayconnectiondispatch.cxx b/vcl/source/helper/displayconnectiondispatch.cxx index 0b08259c6a5d..ce80ad368fe1 100644 --- a/vcl/source/helper/displayconnectiondispatch.cxx +++ b/vcl/source/helper/displayconnectiondispatch.cxx @@ -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: */ diff --git a/vcl/unx/generic/app/X11DisplayConnectionDispatch.cxx b/vcl/unx/generic/app/X11DisplayConnectionDispatch.cxx new file mode 100644 index 000000000000..ec72999dc093 --- /dev/null +++ b/vcl/unx/generic/app/X11DisplayConnectionDispatch.cxx @@ -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: */ diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx index 849ffdf70e4a..dae9965e5b30 100644 --- a/vcl/unx/generic/app/saldisp.cxx +++ b/vcl/unx/generic/app/saldisp.cxx @@ -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 ) { diff --git a/vcl/unx/generic/app/salinst.cxx b/vcl/unx/generic/app/salinst.cxx index d21a9295c619..0ae0730e3d08 100644 --- a/vcl/unx/generic/app/salinst.cxx +++ b/vcl/unx/generic/app/salinst.cxx @@ -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: */ diff --git a/vcl/unx/generic/dtrans/X11_selection.hxx b/vcl/unx/generic/dtrans/X11_selection.hxx index 60efc786aad6..5d355e161851 100644 --- a/vcl/unx/generic/dtrans/X11_selection.hxx +++ b/vcl/unx/generic/dtrans/X11_selection.hxx @@ -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
