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
wilder-5.14
David Edmundson 8 years ago
parent fdd24e9f7a
commit 53ed39aaa4
  1. 1
      shell/CMakeLists.txt
  2. 1
      shell/autotests/CMakeLists.txt
  3. 13
      shell/screenpool.cpp
  4. 1
      shell/screenpool.h

@ -73,6 +73,7 @@ target_link_libraries(plasmashell
KF5::XmlGui KF5::XmlGui
KF5::Package KF5::Package
KF5::WaylandClient KF5::WaylandClient
KF5::WindowSystem
) )
target_include_directories(plasmashell PRIVATE "${CMAKE_BINARY_DIR}") target_include_directories(plasmashell PRIVATE "${CMAKE_BINARY_DIR}")
target_compile_definitions(plasmashell PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") target_compile_definitions(plasmashell PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}")

@ -9,6 +9,7 @@ MACRO(PLASMASHELL_UNIT_TESTS)
Qt5::Test Qt5::Test
Qt5::Gui Qt5::Gui
KF5::Service KF5::Service
KF5::WindowSystem
) )
if(HAVE_X11) if(HAVE_X11)
target_link_libraries(${_testname} ${X11_LIBRARIES} ${XCB_LIBRARIES} ) target_link_libraries(${_testname} ${X11_LIBRARIES} ${XCB_LIBRARIES} )

@ -22,6 +22,7 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QScreen> #include <QScreen>
#include <KWindowSystem>
#if HAVE_X11 #if HAVE_X11
#include <QX11Info> #include <QX11Info>
@ -34,12 +35,19 @@ ScreenPool::ScreenPool(KSharedConfig::Ptr config, QObject *parent)
: QObject(parent), : QObject(parent),
m_configGroup(KConfigGroup(config, QStringLiteral("ScreenConnectors"))) m_configGroup(KConfigGroup(config, QStringLiteral("ScreenConnectors")))
{ {
qApp->installNativeEventFilter(this);
m_configSaveTimer.setSingleShot(true); m_configSaveTimer.setSingleShot(true);
connect(&m_configSaveTimer, &QTimer::timeout, this, [this](){ connect(&m_configSaveTimer, &QTimer::timeout, this, [this](){
m_configGroup.sync(); 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() 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 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()) { if (qGuiApp->primaryScreen()->name() != primaryConnector()) {
//new screen? //new screen?
if (id(qGuiApp->primaryScreen()->name()) < 0) { if (id(qGuiApp->primaryScreen()->name()) < 0) {

@ -65,6 +65,7 @@ private:
QHash<QString, int> m_idForConnector; QHash<QString, int> m_idForConnector;
QTimer m_configSaveTimer; QTimer m_configSaveTimer;
int m_xrandrExtensionOffset;
}; };
#endif // SCREENPOOL_H #endif // SCREENPOOL_H

Loading…
Cancel
Save