Commit 53ed39aa authored by David Edmundson's avatar David Edmundson
Browse files

Micro-optimise screenpool event filter by caching xcb extension offset

Summary: BUG: 390499

Test Plan:
See callgrind in bug report
Added debug in the relevant section, unplugged a monitor. Saw my output

Reviewers: #plasma, broulik

Subscribers: jtamate, mart, broulik, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D10538
parent fdd24e9f
......@@ -73,6 +73,7 @@ target_link_libraries(plasmashell
KF5::XmlGui
KF5::Package
KF5::WaylandClient
KF5::WindowSystem
)
target_include_directories(plasmashell PRIVATE "${CMAKE_BINARY_DIR}")
target_compile_definitions(plasmashell PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}")
......
......@@ -9,6 +9,7 @@ MACRO(PLASMASHELL_UNIT_TESTS)
Qt5::Test
Qt5::Gui
KF5::Service
KF5::WindowSystem
)
if(HAVE_X11)
target_link_libraries(${_testname} ${X11_LIBRARIES} ${XCB_LIBRARIES} )
......
......@@ -22,6 +22,7 @@
#include <QGuiApplication>
#include <QScreen>
#include <KWindowSystem>
#if HAVE_X11
#include <QX11Info>
......@@ -34,12 +35,19 @@ ScreenPool::ScreenPool(KSharedConfig::Ptr config, QObject *parent)
: QObject(parent),
m_configGroup(KConfigGroup(config, QStringLiteral("ScreenConnectors")))
{
qApp->installNativeEventFilter(this);
m_configSaveTimer.setSingleShot(true);
connect(&m_configSaveTimer, &QTimer::timeout, this, [this](){
m_configGroup.sync();
});
#if HAVE_X11
if (KWindowSystem::isPlatformX11()) {
qApp->installNativeEventFilter(this);
const xcb_query_extension_reply_t* reply = xcb_get_extension_data(QX11Info::connection(), &xcb_randr_id);
m_xrandrExtensionOffset = reply->first_event;
}
#endif
}
void ScreenPool::load()
......@@ -185,9 +193,8 @@ bool ScreenPool::nativeEventFilter(const QByteArray& eventType, void* message, l
const auto responseType = XCB_EVENT_RESPONSE_TYPE(ev);
const xcb_query_extension_reply_t* reply = xcb_get_extension_data(QX11Info::connection(), &xcb_randr_id);
if (responseType == reply->first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY) {
if (responseType == m_xrandrExtensionOffset + XCB_RANDR_SCREEN_CHANGE_NOTIFY) {
if (qGuiApp->primaryScreen()->name() != primaryConnector()) {
//new screen?
if (id(qGuiApp->primaryScreen()->name()) < 0) {
......
......@@ -65,6 +65,7 @@ private:
QHash<QString, int> m_idForConnector;
QTimer m_configSaveTimer;
int m_xrandrExtensionOffset;
};
#endif // SCREENPOOL_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment