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
3c8eb40487
.
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>
This commit is contained in:
parent
6c38a82aa8
commit
100ed0c01d
@ -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;
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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];
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user