summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/xcb
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2014-09-24 18:14:22 +0400
committerAlexander Volkov <a.volkov@rusbitech.ru>2014-10-29 10:03:55 +0100
commit100ed0c01d7678a97e3b7b3a46320d84b3a7096d (patch)
tree6f48ed8cbc70e418cc9c709c7ad76aee228267a0 /src/plugins/platforms/xcb
parent6c38a82aa8165bbe3cbdc7f17e67999439842c29 (diff)
xcb: Fix getting the primary screen from QXcbConnection::screens()
Currently getting QXcbScreen* for primary screen is too messy and it wrongly uses QXcbConnection::primaryScreen() as an index in QXcbConnection::screens() although QXcbConnection::screens() returns the primary screen as the first item in the list since 3c8eb404877df9c967d81fa9df7d718c538fb407. So to clear the API rename primaryScreen() to primaryScreenNumber(), add QXcbConnection::primaryScreen() that returns correct QXcbScreen* and use it directly. Change-Id: Icb7391aa3e82b32ca48f2bda764dcf7ffd89cc47 Reviewed-by: Uli Schlachter <psychon@znc.in> Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
Diffstat (limited to 'src/plugins/platforms/xcb')
-rw-r--r--src/plugins/platforms/xcb/qxcbclipboard.cpp2
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection.cpp20
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection.h5
-rw-r--r--src/plugins/platforms/xcb/qxcbdrag.cpp2
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.cpp4
-rw-r--r--src/plugins/platforms/xcb/qxcbnativeinterface.cpp2
-rw-r--r--src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp7
-rw-r--r--src/plugins/platforms/xcb/qxcbwmsupport.cpp4
8 files changed, 26 insertions, 20 deletions
diff --git a/src/plugins/platforms/xcb/qxcbclipboard.cpp b/src/plugins/platforms/xcb/qxcbclipboard.cpp
index 45856f3e6c..8b3893ec2f 100644
--- a/src/plugins/platforms/xcb/qxcbclipboard.cpp
+++ b/src/plugins/platforms/xcb/qxcbclipboard.cpp
@@ -276,7 +276,7 @@ QXcbClipboard::QXcbClipboard(QXcbConnection *c)
m_timestamp[QClipboard::Clipboard] = XCB_CURRENT_TIME;
m_timestamp[QClipboard::Selection] = XCB_CURRENT_TIME;
- m_screen = connection()->screens().at(connection()->primaryScreen());
+ m_screen = connection()->primaryScreen();
int x = 0, y = 0, w = 3, h = 3;
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp
index 835c414d85..5510c3b1b4 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection.cpp
@@ -244,7 +244,7 @@ void QXcbConnection::updateScreens()
// the first or an exact match. An exact match isn't
// always available if primary->output is XCB_NONE
// or currently disconnected output.
- if (m_primaryScreen == xcbScreenNumber) {
+ if (m_primaryScreenNumber == xcbScreenNumber) {
if (!primaryScreen || (primary && outputs[i] == primary->output)) {
primaryScreen = screen;
siblings.prepend(siblings.takeLast());
@@ -306,7 +306,7 @@ void QXcbConnection::updateScreens()
QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGrabServer, const char *displayName)
: m_connection(0)
, m_canGrabServer(canGrabServer)
- , m_primaryScreen(0)
+ , m_primaryScreenNumber(0)
, m_displayName(displayName ? QByteArray(displayName) : qgetenv("DISPLAY"))
, m_nativeInterface(nativeInterface)
, xfixes_first_event(0)
@@ -331,7 +331,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra
#ifdef XCB_USE_XLIB
dpy = XOpenDisplay(m_displayName.constData());
if (dpy) {
- m_primaryScreen = DefaultScreen(dpy);
+ m_primaryScreenNumber = DefaultScreen(dpy);
m_connection = XGetXCBConnection(dpy);
XSetEventQueueOwner(dpy, XCBOwnsEventQueue);
XSetErrorHandler(nullErrorHandler);
@@ -339,7 +339,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra
m_xlib_display = dpy;
}
#else
- m_connection = xcb_connect(m_displayName.constData(), &m_primaryScreen);
+ m_connection = xcb_connect(m_displayName.constData(), &m_primaryScreenNumber);
#endif //XCB_USE_XLIB
if (!m_connection || xcb_connection_has_error(m_connection))
@@ -449,6 +449,16 @@ QXcbConnection::~QXcbConnection()
delete m_keyboard;
}
+QXcbScreen *QXcbConnection::primaryScreen() const
+{
+ if (!m_screens.isEmpty()) {
+ Q_ASSERT(m_screens.first()->screenNumber() == primaryScreenNumber());
+ return m_screens.first();
+ }
+
+ return Q_NULLPTR;
+}
+
void QXcbConnection::addWindowEventListener(xcb_window_t id, QXcbWindowEventListener *eventListener)
{
m_mapper.insert(id, eventListener);
@@ -1219,7 +1229,7 @@ xcb_timestamp_t QXcbConnection::getTimestamp()
xcb_window_t QXcbConnection::rootWindow()
{
- return screens().at(primaryScreen())->root();
+ return primaryScreen()->root();
}
void QXcbConnection::processXcbEvents()
diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h
index 4a16e116c6..51c7c91bf6 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.h
+++ b/src/plugins/platforms/xcb/qxcbconnection.h
@@ -369,7 +369,8 @@ public:
QXcbConnection *connection() const { return const_cast<QXcbConnection *>(this); }
const QList<QXcbScreen *> &screens() const { return m_screens; }
- int primaryScreen() const { return m_primaryScreen; }
+ int primaryScreenNumber() const { return m_primaryScreenNumber; }
+ QXcbScreen *primaryScreen() const;
inline xcb_atom_t atom(QXcbAtom::Atom atom) const { return m_allAtoms[atom]; }
QXcbAtom::Atom qatom(xcb_atom_t atom) const;
@@ -550,7 +551,7 @@ private:
bool m_canGrabServer;
QList<QXcbScreen *> m_screens;
- int m_primaryScreen;
+ int m_primaryScreenNumber;
xcb_atom_t m_allAtoms[QXcbAtom::NAtoms];
diff --git a/src/plugins/platforms/xcb/qxcbdrag.cpp b/src/plugins/platforms/xcb/qxcbdrag.cpp
index 53437f24ae..7037e102e2 100644
--- a/src/plugins/platforms/xcb/qxcbdrag.cpp
+++ b/src/plugins/platforms/xcb/qxcbdrag.cpp
@@ -311,7 +311,7 @@ void QXcbDrag::move(const QMouseEvent *me)
return;
const QList<QXcbScreen *> &screens = connection()->screens();
- QXcbScreen *screen = screens.at(connection()->primaryScreen());
+ QXcbScreen *screen = connection()->primaryScreen();
for (int i = 0; i < screens.size(); ++i) {
if (screens.at(i)->geometry().contains(globalPos)) {
screen = screens.at(i);
diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp
index d3533b8e44..52269bafea 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.cpp
+++ b/src/plugins/platforms/xcb/qxcbintegration.cpp
@@ -417,10 +417,8 @@ QVariant QXcbIntegration::styleHint(QPlatformIntegration::StyleHint hint) const
case QPlatformIntegration::StartDragDistance: {
// The default (in QPlatformTheme::defaultThemeHint) is 10 pixels, but
// on a high-resolution screen it makes sense to increase it.
- const QList<QXcbScreen *> &screens = defaultConnection()->screens();
qreal dpi = 100.0;
- if (screens.length() > 0) {
- const QXcbScreen *screen = screens.at(defaultConnection()->primaryScreen());
+ if (const QXcbScreen *screen = defaultConnection()->primaryScreen()) {
if (screen->logicalDpi().first > dpi)
dpi = screen->logicalDpi().first;
if (screen->logicalDpi().second > dpi)
diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
index 0d75a7f032..3058b29f2d 100644
--- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
+++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
@@ -367,7 +367,7 @@ void *QXcbNativeInterface::x11Screen()
QXcbIntegration *integration = static_cast<QXcbIntegration *>(QGuiApplicationPrivate::platformIntegration());
QXcbConnection *defaultConnection = integration->defaultConnection();
if (defaultConnection)
- return reinterpret_cast<void *>(defaultConnection->primaryScreen());
+ return reinterpret_cast<void *>(defaultConnection->primaryScreenNumber());
return 0;
}
diff --git a/src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp b/src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp
index 9ec4ea80ec..40a50f61ab 100644
--- a/src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp
+++ b/src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp
@@ -59,7 +59,7 @@ QXcbSystemTrayTracker *QXcbSystemTrayTracker::create(QXcbConnection *connection)
const xcb_atom_t trayAtom = connection->atom(QXcbAtom::_NET_SYSTEM_TRAY_OPCODE);
if (!trayAtom)
return 0;
- const QByteArray netSysTray = QByteArrayLiteral("_NET_SYSTEM_TRAY_S") + QByteArray::number(connection->primaryScreen());
+ const QByteArray netSysTray = QByteArrayLiteral("_NET_SYSTEM_TRAY_S") + QByteArray::number(connection->primaryScreenNumber());
const xcb_atom_t selection = connection->internAtom(netSysTray.constData());
if (!selection)
return 0;
@@ -145,11 +145,8 @@ QRect QXcbSystemTrayTracker::systemTrayWindowGlobalGeometry(xcb_window_t window)
inline void QXcbSystemTrayTracker::emitSystemTrayWindowChanged()
{
- const int screen = m_connection->primaryScreen();
- if (screen >= 0 && screen < m_connection->screens().size()) {
- const QPlatformScreen *ps = m_connection->screens().at(screen);
+ if (const QPlatformScreen *ps = m_connection->primaryScreen())
emit systemTrayWindowChanged(ps->screen());
- }
}
// Client messages with the "MANAGER" atom on the root window indicate creation of a new tray.
diff --git a/src/plugins/platforms/xcb/qxcbwmsupport.cpp b/src/plugins/platforms/xcb/qxcbwmsupport.cpp
index 0458be32f6..1be9ab3e05 100644
--- a/src/plugins/platforms/xcb/qxcbwmsupport.cpp
+++ b/src/plugins/platforms/xcb/qxcbwmsupport.cpp
@@ -56,7 +56,7 @@ void QXcbWMSupport::updateNetWMAtoms()
{
net_wm_atoms.clear();
- xcb_window_t root = connection()->screens().at(connection()->primaryScreen())->root();
+ xcb_window_t root = connection()->primaryScreen()->root();
int offset = 0;
int remaining = 0;
do {
@@ -90,7 +90,7 @@ void QXcbWMSupport::updateVirtualRoots()
if (!isSupportedByWM(atom(QXcbAtom::_NET_VIRTUAL_ROOTS)))
return;
- xcb_window_t root = connection()->screens().at(connection()->primaryScreen())->root();
+ xcb_window_t root = connection()->primaryScreen()->root();
int offset = 0;
int remaining = 0;
do {