Remove QT_DEVICE_PIXEL_RATIO support from xcb

It will be reintroduced as a cross-platform feature.

Task-number: QTBUG-46615
Change-Id: Ia6d03275018b2a25ebed438fe51f15e491f1c3ff
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
Paul Olav Tvete 2015-06-18 16:58:01 +02:00
parent c5461ec751
commit c173a50719
9 changed files with 74 additions and 292 deletions

View File

@ -313,14 +313,7 @@ void QXcbBackingStore::beginPaint(const QRegion &region)
if (!m_image)
return;
int dpr = int(m_image->image()->devicePixelRatio());
const int windowDpr = int(window()->devicePixelRatio());
if (windowDpr != dpr) {
resize(window()->size(), QRegion());
dpr = int(m_image->image()->devicePixelRatio());
}
m_paintRegion = dpr == 1 ? region : QTransform::fromScale(dpr,dpr).map(region);
m_paintRegion = region;
m_image->preparePaint(m_paintRegion);
if (m_image->image()->hasAlphaChannel()) {
@ -369,18 +362,10 @@ void QXcbBackingStore::flush(QWindow *window, const QRegion &region, const QPoin
if (!m_image || m_image->size().isEmpty())
return;
const int dpr = int(window->devicePixelRatio());
#ifndef QT_NO_DEBUG
const int imageDpr = int(m_image->image()->devicePixelRatio());
if (dpr != imageDpr)
qWarning() << "QXcbBackingStore::flush() wrong devicePixelRatio for backingstore image" << dpr << imageDpr;
#endif
QSize imageSize = m_image->size() / dpr; //because we multiply with the DPR later
QSize imageSize = m_image->size();
QRegion clipped = region;
clipped &= QRect(0, 0, window->width(), window->height());
clipped &= QRect(QPoint(), window->size());
clipped &= QRect(0, 0, imageSize.width(), imageSize.height()).translated(-offset);
QRect bounds = clipped.boundingRect();
@ -398,8 +383,8 @@ void QXcbBackingStore::flush(QWindow *window, const QRegion &region, const QPoin
QVector<QRect> rects = clipped.rects();
for (int i = 0; i < rects.size(); ++i) {
QRect rect = QRect(rects.at(i).topLeft() * dpr, rects.at(i).size() * dpr);
m_image->put(platformWindow->xcb_window(), rect.topLeft(), rect.translated(offset * dpr));
QRect rect = QRect(rects.at(i).topLeft(), rects.at(i).size());
m_image->put(platformWindow->xcb_window(), rect.topLeft(), rect.translated(offset));
}
Q_XCB_NOOP(connection());
@ -430,9 +415,7 @@ void QXcbBackingStore::composeAndFlush(QWindow *window, const QRegion &region, c
void QXcbBackingStore::resize(const QSize &size, const QRegion &)
{
const int dpr = int(window()->devicePixelRatio());
const QSize xSize = size * dpr;
if (m_image && xSize == m_image->size() && dpr == m_image->image()->devicePixelRatio())
if (m_image && size == m_image->size())
return;
Q_XCB_NOOP(connection());
@ -445,13 +428,11 @@ void QXcbBackingStore::resize(const QSize &size, const QRegion &)
QXcbWindow* win = static_cast<QXcbWindow *>(pw);
delete m_image;
m_image = new QXcbShmImage(screen, xSize, win->depth(), win->imageFormat());
m_image->image()->setDevicePixelRatio(dpr);
m_image = new QXcbShmImage(screen, size, win->depth(), win->imageFormat());
// Slow path for bgr888 VNC: Create an additional image, paint into that and
// swap R and B while copying to m_image after each paint.
if (win->imageNeedsRgbSwap()) {
m_rgbImage = QImage(xSize, win->imageFormat());
m_rgbImage.setDevicePixelRatio(dpr);
m_rgbImage = QImage(size, win->imageFormat());
}
Q_XCB_NOOP(connection());
}
@ -463,14 +444,12 @@ bool QXcbBackingStore::scroll(const QRegion &area, int dx, int dy)
if (!m_image || m_image->image()->isNull())
return false;
const int dpr = int(m_image->image()->devicePixelRatio());
QRegion xArea = dpr == 1 ? area : QTransform::fromScale(dpr,dpr).map(area);
m_image->preparePaint(area);
QPoint delta(dx * dpr, dy * dpr);
const QVector<QRect> xRects = xArea.rects();
for (int i = 0; i < xRects.size(); ++i)
qt_scrollRectInImage(*m_image->image(), xRects.at(i), delta);
QPoint delta(dx, dy);
const QVector<QRect> rects = area.rects();
for (int i = 0; i < rects.size(); ++i)
qt_scrollRectInImage(*m_image->image(), rects.at(i), delta);
return true;
}

View File

@ -563,10 +563,8 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo
}
QWindowSystemInterface::TouchPoint &touchPoint = dev->touchPoints[xiDeviceEvent->detail];
QXcbScreen* screen = platformWindow->xcbScreen();
QPointF pos = screen->mapFromNative(QPointF(fixed1616ToReal(xiDeviceEvent->root_x),
fixed1616ToReal(xiDeviceEvent->root_y)));
qreal x = pos.x();
qreal y = pos.y();
qreal x = fixed1616ToReal(xiDeviceEvent->root_x);
qreal y = fixed1616ToReal(xiDeviceEvent->root_y);
qreal nx = -1.0, ny = -1.0, d = 0.0;
for (int i = 0; i < dev->xiDeviceInfo->num_classes; ++i) {
XIAnyClassInfo *classinfo = dev->xiDeviceInfo->classes[i];
@ -873,9 +871,8 @@ void QXcbConnection::xi2HandleScrollEvent(void *event, ScrollingDevice &scrollin
}
}
if (!angleDelta.isNull()) {
const int dpr = int(platformWindow->devicePixelRatio());
QPoint local(fixed1616ToReal(xiDeviceEvent->event_x)/dpr, fixed1616ToReal(xiDeviceEvent->event_y)/dpr);
QPoint global(fixed1616ToReal(xiDeviceEvent->root_x)/dpr, fixed1616ToReal(xiDeviceEvent->root_y)/dpr);
QPoint local(fixed1616ToReal(xiDeviceEvent->event_x), fixed1616ToReal(xiDeviceEvent->event_y));
QPoint global(fixed1616ToReal(xiDeviceEvent->root_x), fixed1616ToReal(xiDeviceEvent->root_y));
Qt::KeyboardModifiers modifiers = keyboard()->translateModifiers(xiDeviceEvent->mods.effective_mods);
if (modifiers & Qt::AltModifier) {
std::swap(angleDelta.rx(), angleDelta.ry());
@ -901,9 +898,8 @@ void QXcbConnection::xi2HandleScrollEvent(void *event, ScrollingDevice &scrollin
angleDelta.setX(-120);
}
if (!angleDelta.isNull()) {
const int dpr = int(platformWindow->devicePixelRatio());
QPoint local(fixed1616ToReal(xiDeviceEvent->event_x)/dpr, fixed1616ToReal(xiDeviceEvent->event_y)/dpr);
QPoint global(fixed1616ToReal(xiDeviceEvent->root_x)/dpr, fixed1616ToReal(xiDeviceEvent->root_y)/dpr);
QPoint local(fixed1616ToReal(xiDeviceEvent->event_x), fixed1616ToReal(xiDeviceEvent->event_y));
QPoint global(fixed1616ToReal(xiDeviceEvent->root_x), fixed1616ToReal(xiDeviceEvent->root_y));
Qt::KeyboardModifiers modifiers = keyboard()->translateModifiers(xiDeviceEvent->mods.effective_mods);
if (modifiers & Qt::AltModifier)
std::swap(angleDelta.rx(), angleDelta.ry());

View File

@ -635,15 +635,14 @@ QPoint QXcbCursor::pos() const
{
QPoint p;
queryPointer(connection(), 0, &p);
return m_screen->mapFromNative(p);
return p;
}
void QXcbCursor::setPos(const QPoint &pos)
{
const QPoint xPos = m_screen->mapToNative(pos);
xcb_window_t root = 0;
queryPointer(connection(), &root, 0);
xcb_warp_pointer(xcb_connection(), XCB_NONE, root, 0, 0, 0, 0, xPos.x(), xPos.y());
xcb_warp_pointer(xcb_connection(), XCB_NONE, root, 0, 0, 0, 0, pos.x(), pos.y());
xcb_flush(xcb_connection());
}

View File

@ -76,7 +76,6 @@ static inline xcb_window_t xcb_window(QWindow *w)
return static_cast<QXcbWindow *>(w->handle())->xcb_window();
}
static xcb_window_t xdndProxy(QXcbConnection *c, xcb_window_t w)
{
xcb_window_t proxy = XCB_NONE;
@ -303,7 +302,6 @@ void QXcbDrag::move(const QMouseEvent *me)
// We do not know which window that was at this point, so we just use the device pixel ratio
// of the QGuiApplication. This will break once we support screens with different DPR. Fixing
// this properly requires some redesign of the drag and drop architecture.
static const int dpr = int(qApp->devicePixelRatio());
QBasicDrag::move(me);
QPoint globalPos = me->globalPos();
@ -318,6 +316,7 @@ void QXcbDrag::move(const QMouseEvent *me)
break;
}
}
if (screen != current_screen) {
// ### need to recreate the shaped pixmap window?
// int screen = QCursor::x11Screen();
@ -340,7 +339,7 @@ void QXcbDrag::move(const QMouseEvent *me)
// qt_xdnd_current_screen = screen;
xcb_window_t rootwin = current_screen->root();
xcb_translate_coordinates_reply_t *translate =
::translateCoordinates(connection(), rootwin, rootwin, globalPos.x() * dpr, globalPos.y() * dpr);
::translateCoordinates(connection(), rootwin, rootwin, globalPos.x(), globalPos.y());
if (!translate)
return;
@ -463,7 +462,7 @@ void QXcbDrag::move(const QMouseEvent *me)
move.type = atom(QXcbAtom::XdndPosition);
move.data.data32[0] = connection()->clipboard()->owner();
move.data.data32[1] = 0; // flags
move.data.data32[2] = (globalPos.x() * dpr << 16) + globalPos.y() * dpr;
move.data.data32[2] = (globalPos.x() << 16) + globalPos.y();
move.data.data32[3] = connection()->time();
move.data.data32[4] = toXdndAction(defaultAction(currentDrag()->supportedActions(), QGuiApplication::keyboardModifiers()));
DEBUG() << "sending Xdnd position source=" << move.data.data32[0] << "target=" << move.window;
@ -710,9 +709,6 @@ void QXcbDrag::handle_xdnd_position(QWindow *w, const xcb_client_message_event_t
QPoint p((e->data.data32[2] & 0xffff0000) >> 16, e->data.data32[2] & 0x0000ffff);
Q_ASSERT(w);
QRect geometry = w->geometry();
const int dpr = int(w->handle()->devicePixelRatio());
p /= dpr;
p -= geometry.topLeft();
if (!w || (w->type() == Qt::Desktop))
@ -831,12 +827,10 @@ void QXcbDrag::handle_xdnd_status(const xcb_client_message_event_t *event)
updateCursor(Qt::IgnoreAction);
}
static const int dpr = int(qApp->devicePixelRatio());
if ((event->data.data32[1] & 2) == 0) {
QPoint p((event->data.data32[2] & 0xffff0000) >> 16, event->data.data32[2] & 0x0000ffff);
QSize s((event->data.data32[3] & 0xffff0000) >> 16, event->data.data32[3] & 0x0000ffff);
source_sameanswer = QRect(p / dpr, s / dpr);
source_sameanswer = QRect(p, s);
} else {
source_sameanswer = QRect();
}

View File

@ -55,6 +55,7 @@ QT_BEGIN_NAMESPACE
class QMouseEvent;
class QWindow;
class QPlatformWindow;
class QXcbConnection;
class QXcbWindow;
class QXcbDropData;

View File

@ -86,7 +86,6 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDe
, m_orientation(Qt::PrimaryOrientation)
, m_refreshRate(60)
, m_forcedDpi(-1)
, m_devicePixelRatio(1)
, m_hintStyle(QFontEngine::HintStyle(-1))
, m_noFontHinting(false)
, m_subpixelType(QFontEngine::SubpixelAntialiasingType(-1))
@ -107,9 +106,8 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDe
updateGeometry(output ? output->timestamp : 0);
}
const int dpr = int(devicePixelRatio());
if (m_geometry.isEmpty()) {
m_geometry = QRect(QPoint(), m_virtualSize/dpr);
m_geometry = QRect(QPoint(), m_virtualSize);
m_nativeGeometry = QRect(QPoint(), m_virtualSize);
}
if (m_availableGeometry.isEmpty())
@ -117,12 +115,6 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDe
readXResources();
// disable font hinting when we do UI scaling
static bool dpr_scaling_enabled = (qgetenv("QT_DEVICE_PIXEL_RATIO").toInt() > 1
|| qgetenv("QT_DEVICE_PIXEL_RATIO").toLower() == "auto");
if (dpr_scaling_enabled)
m_noFontHinting = true;
QScopedPointer<xcb_get_window_attributes_reply_t, QScopedPointerPodDeleter> rootAttribs(
xcb_get_window_attributes_reply(xcb_connection(),
xcb_get_window_attributes_unchecked(xcb_connection(), screen()->root), NULL));
@ -201,9 +193,8 @@ QWindow *QXcbScreen::topLevelAt(const QPoint &p) const
{
xcb_window_t root = screen()->root;
int dpr = int(devicePixelRatio());
int x = p.x() / dpr;
int y = p.y() / dpr;
int x = p.x();
int y = p.y();
xcb_window_t parent = root;
xcb_window_t child = root;
@ -237,43 +228,6 @@ QWindow *QXcbScreen::topLevelAt(const QPoint &p) const
return 0;
}
QPoint QXcbScreen::mapToNative(const QPoint &pos) const
{
const int dpr = int(devicePixelRatio());
return (pos - m_geometry.topLeft()) * dpr + m_nativeGeometry.topLeft();
}
QPoint QXcbScreen::mapFromNative(const QPoint &pos) const
{
const int dpr = int(devicePixelRatio());
return (pos - m_nativeGeometry.topLeft()) / dpr + m_geometry.topLeft();
}
QPointF QXcbScreen::mapToNative(const QPointF &pos) const
{
const int dpr = int(devicePixelRatio());
return (pos - m_geometry.topLeft()) * dpr + m_nativeGeometry.topLeft();
}
QPointF QXcbScreen::mapFromNative(const QPointF &pos) const
{
const int dpr = int(devicePixelRatio());
return (pos - m_nativeGeometry.topLeft()) / dpr + m_geometry.topLeft();
}
QRect QXcbScreen::mapToNative(const QRect &rect) const
{
const int dpr = int(devicePixelRatio());
return QRect(mapToNative(rect.topLeft()), rect.size() * dpr);
}
QRect QXcbScreen::mapFromNative(const QRect &rect) const
{
const int dpr = int(devicePixelRatio());
return QRect(mapFromNative(rect.topLeft()), rect.size() / dpr);
}
void QXcbScreen::windowShown(QXcbWindow *window)
{
// Freedesktop.org Startup Notification
@ -335,29 +289,17 @@ QDpi QXcbScreen::virtualDpi() const
Q_MM_PER_INCH * m_virtualSize.height() / m_virtualSizeMillimeters.height());
}
QDpi QXcbScreen::logicalDpi() const
{
static const int overrideDpi = qEnvironmentVariableIntValue("QT_FONT_DPI");
if (overrideDpi)
return QDpi(overrideDpi, overrideDpi);
int primaryDpr = int(connection()->screens().at(0)->devicePixelRatio());
if (m_forcedDpi > 0)
return QDpi(m_forcedDpi/primaryDpr, m_forcedDpi/primaryDpr);
QDpi vDpi = virtualDpi();
return QDpi(vDpi.first/primaryDpr, vDpi.second/primaryDpr);
}
qreal QXcbScreen::devicePixelRatio() const
{
static int override_dpr = qEnvironmentVariableIntValue("QT_DEVICE_PIXEL_RATIO");
static bool auto_dpr = qgetenv("QT_DEVICE_PIXEL_RATIO").toLower() == "auto";
if (override_dpr > 0)
return override_dpr;
if (auto_dpr)
return m_devicePixelRatio;
return 1.0;
if (m_forcedDpi > 0) {
return QDpi(m_forcedDpi, m_forcedDpi);
}
return virtualDpi();
}
QPlatformCursor *QXcbScreen::cursor() const
@ -515,12 +457,9 @@ void QXcbScreen::updateGeometry(const QRect &geom, uint8_t rotation)
}
free(workArea);
qreal dpi = xGeometry.width() / physicalSize().width() * qreal(25.4);
m_devicePixelRatio = qRound(dpi/96);
const int dpr = int(devicePixelRatio()); // we may override m_devicePixelRatio
m_geometry = QRect(xGeometry.topLeft(), xGeometry.size()/dpr);
m_geometry = QRect(xGeometry.topLeft(), xGeometry.size());
m_nativeGeometry = QRect(xGeometry.topLeft(), xGeometry.size());
m_availableGeometry = QRect(mapFromNative(xAvailableGeometry.topLeft()), xAvailableGeometry.size()/dpr);
m_availableGeometry = QRect(xAvailableGeometry.topLeft(), xAvailableGeometry.size());
QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), m_geometry, m_availableGeometry);
}

View File

@ -96,7 +96,6 @@ public:
QSizeF physicalVirtualSize() const { return m_virtualSizeMillimeters; }
QDpi virtualDpi() const;
QDpi logicalDpi() const Q_DECL_OVERRIDE;
qreal devicePixelRatio() const Q_DECL_OVERRIDE;
QPlatformCursor *cursor() const Q_DECL_OVERRIDE;
qreal refreshRate() const Q_DECL_OVERRIDE { return m_refreshRate; }
Qt::ScreenOrientation orientation() const Q_DECL_OVERRIDE { return m_orientation; }
@ -139,13 +138,6 @@ public:
QXcbXSettings *xSettings() const;
QPoint mapToNative(const QPoint &pos) const;
QPoint mapFromNative(const QPoint &pos) const;
QPointF mapToNative(const QPointF &pos) const;
QPointF mapFromNative(const QPointF &pos) const;
QRect mapToNative(const QRect &rect) const;
QRect mapFromNative(const QRect &rect) const;
private:
static bool xResource(const QByteArray &identifier,
const QByteArray &expectedIdentifier,
@ -176,7 +168,6 @@ private:
QXcbCursor *m_cursor;
int m_refreshRate;
int m_forcedDpi;
int m_devicePixelRatio;
QFontEngine::HintStyle m_hintStyle;
bool m_noFontHinting;
QFontEngine::SubpixelAntialiasingType m_subpixelType;

View File

@ -140,73 +140,11 @@ enum QX11EmbedMessageType {
const quint32 XEMBED_VERSION = 0;
static inline QRect mapLocalGeometryToNative(const QRect &qtRect, int dpr)
{
return QRect(qtRect.x() * dpr, qtRect.y() * dpr, qtRect.width() * dpr, qtRect.height() * dpr);
}
// When mapping expose events to Qt rects: round top/left towards the origin and
// bottom/right away from the origin, making sure that we cover the whole widget
static inline QPoint dpr_floor(const QPoint &p, int dpr)
{
return QPoint(p.x()/dpr, p.y()/dpr);
}
static inline QPoint dpr_ceil(const QPoint &p, int dpr)
{
return QPoint((p.x() + dpr - 1) / dpr, (p.y() + dpr - 1) / dpr);
}
static inline QSize dpr_ceil(const QSize &s, int dpr)
{
return QSize((s.width() + dpr - 1) / dpr, (s.height() + dpr - 1) / dpr);
}
static inline QRect mapExposeFromNative(const QRect &xRect, int dpr)
{
return QRect(dpr_floor(xRect.topLeft(), dpr), dpr_ceil(xRect.bottomRight(), dpr));
}
static inline QRect mapLocalGeometryFromNative(const QRect &xRect, int dpr)
{
return QRect(xRect.topLeft() / dpr, dpr_ceil(xRect.size(), dpr));
}
QXcbScreen *QXcbWindow::parentScreen()
{
return parent() ? static_cast<QXcbWindow*>(parent())->parentScreen() : m_xcbScreen;
}
QPoint QXcbWindow::mapToNative(const QPoint &pos, const QXcbScreen *screen) const
{
if (parent())
return pos * int(screen->devicePixelRatio());
else
return screen->mapToNative(pos);
}
QPoint QXcbWindow::mapFromNative(const QPoint &pos, const QXcbScreen *screen) const
{
if (parent())
return pos / int(screen->devicePixelRatio());
else
return screen->mapFromNative(pos);
}
QRect QXcbWindow::mapToNative(const QRect &rect, const QXcbScreen *screen) const
{
if (parent())
return mapLocalGeometryToNative(rect, int(screen->devicePixelRatio()));
else
return screen->mapToNative(rect);
}
QRect QXcbWindow::mapFromNative(const QRect &rect, const QXcbScreen *screen) const
{
if (parent())
return mapLocalGeometryFromNative(rect, int(screen->devicePixelRatio()));
else
return screen->mapFromNative(rect);
}
// Returns \c true if we should set WM_TRANSIENT_FOR on \a w
static inline bool isTransient(const QWindow *w)
{
@ -425,12 +363,10 @@ void QXcbWindow::create()
if (platformScreen != currentScreen)
QWindowSystemInterface::handleWindowScreenChanged(window(), platformScreen->QPlatformScreen::screen());
const int dpr = int(devicePixelRatio());
QSize minimumSize = window()->minimumSize();
if (rect.width() > 0 || rect.height() > 0) {
rect.setWidth(qBound(1, rect.width(), XCOORD_MAX/dpr));
rect.setHeight(qBound(1, rect.height(), XCOORD_MAX/dpr));
rect.setWidth(qBound(1, rect.width(), XCOORD_MAX));
rect.setHeight(qBound(1, rect.height(), XCOORD_MAX));
} else if (minimumSize.width() > 0 || minimumSize.height() > 0) {
rect.setSize(minimumSize);
} else {
@ -479,9 +415,7 @@ void QXcbWindow::create()
m_visualId = visualInfo->visualid;
const QRect xRect = mapToNative(rect, platformScreen);
m_window = XCreateWindow(DISPLAY_FROM_XCB(this), xcb_parent_id, xRect.x(), xRect.y(), xRect.width(), xRect.height(),
m_window = XCreateWindow(DISPLAY_FROM_XCB(this), xcb_parent_id, rect.x(), rect.y(), rect.width(), rect.height(),
0, visualInfo->depth, InputOutput, visualInfo->visual,
CWBackPixel|CWBorderPixel|CWColormap, &a);
@ -537,16 +471,14 @@ void QXcbWindow::create()
}
m_imageFormat = imageFormatForVisual(m_depth, visual->red_mask, visual->blue_mask, &m_imageRgbSwap);
const QRect xRect = mapToNative(rect, platformScreen);
Q_XCB_CALL(xcb_create_window(xcb_connection(),
m_depth,
m_window, // window id
xcb_parent_id, // parent window id
xRect.x(),
xRect.y(),
xRect.width(),
xRect.height(),
rect.x(),
rect.y(),
rect.width(),
rect.height(),
0, // border width
XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
m_visualId, // visual
@ -716,8 +648,7 @@ void QXcbWindow::setGeometry(const QRect &rect)
newScreen = currentScreen;
m_xcbScreen = newScreen;
const QRect xRect = mapToNative(rect, newScreen);
const QRect wmGeometry = windowToWmGeometry(xRect);
const QRect wmGeometry = windowToWmGeometry(rect);
if (newScreen != currentScreen)
QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->QPlatformScreen::screen());
@ -1615,8 +1546,7 @@ void QXcbWindow::propagateSizeHints()
xcb_size_hints_t hints;
memset(&hints, 0, sizeof(hints));
const int dpr = int(devicePixelRatio());
const QRect xRect = windowToWmGeometry(mapToNative(geometry(), xcbScreen()));
const QRect xRect = windowToWmGeometry(geometry());
QWindow *win = window();
@ -1626,10 +1556,10 @@ void QXcbWindow::propagateSizeHints()
xcb_size_hints_set_size(&hints, true, xRect.width(), xRect.height());
xcb_size_hints_set_win_gravity(&hints, m_gravity);
QSize minimumSize = win->minimumSize() * dpr;
QSize maximumSize = win->maximumSize() * dpr;
QSize baseSize = win->baseSize() * dpr;
QSize sizeIncrement = win->sizeIncrement() * dpr;
QSize minimumSize = window()->minimumSize();
QSize maximumSize = window()->maximumSize();
QSize baseSize = window()->baseSize();
QSize sizeIncrement = window()->sizeIncrement();
if (minimumSize.width() > 0 || minimumSize.height() > 0)
xcb_size_hints_set_min_size(&hints,
@ -1919,10 +1849,9 @@ QRect QXcbWindow::systemTrayWindowGlobalGeometry() const
class ExposeCompressor
{
public:
ExposeCompressor(xcb_window_t window, QRegion *region, int devicePixelRatio)
ExposeCompressor(xcb_window_t window, QRegion *region)
: m_window(window)
, m_region(region)
, m_dpr(devicePixelRatio)
, m_pending(true)
{
}
@ -1938,7 +1867,7 @@ public:
return false;
if (expose->count == 0)
m_pending = false;
*m_region |= mapExposeFromNative(QRect(expose->x, expose->y, expose->width, expose->height), m_dpr);
*m_region |= QRect(expose->x, expose->y, expose->width, expose->height);
return true;
}
@ -1950,7 +1879,6 @@ public:
private:
xcb_window_t m_window;
QRegion *m_region;
int m_dpr;
bool m_pending;
};
@ -1964,16 +1892,14 @@ bool QXcbWindow::handleGenericEvent(xcb_generic_event_t *event, long *result)
void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event)
{
const int dpr = int(devicePixelRatio());
QRect x_rect(event->x, event->y, event->width, event->height);
QRect rect = mapExposeFromNative(x_rect, dpr);
QRect rect(event->x, event->y, event->width, event->height);
if (m_exposeRegion.isEmpty())
m_exposeRegion = rect;
else
m_exposeRegion |= rect;
ExposeCompressor compressor(m_window, &m_exposeRegion, dpr);
ExposeCompressor compressor(m_window, &m_exposeRegion);
xcb_generic_event_t *filter = 0;
do {
filter = connection()->checkEvent(compressor);
@ -2051,26 +1977,6 @@ void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *even
}
}
// Temporary workaround for bug in QPlatformScreen::screenForGeometry
// we need the native geometries to detect our screen, but that's not
// available in cross-platform code. Will be fixed properly when highDPI
// support is refactored to expose the native coordinate system.
QXcbScreen *QXcbWindow::screenForNativeGeometry(const QRect &newGeometry) const
{
QXcbScreen *currentScreen = xcbScreen();
if (!currentScreen && QGuiApplication::primaryScreen())
currentScreen = static_cast<QXcbScreen*>(QGuiApplication::primaryScreen()->handle());
if (currentScreen && !parent() && !currentScreen->nativeGeometry().intersects(newGeometry)) {
Q_FOREACH (QPlatformScreen* screen, currentScreen->virtualSiblings()) {
QXcbScreen *xcbScreen = static_cast<QXcbScreen*>(screen);
if (xcbScreen->nativeGeometry().intersects(newGeometry))
return xcbScreen;
}
}
return currentScreen;
}
void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event)
{
bool fromSendEvent = (event->response_type & 0x80);
@ -2087,19 +1993,18 @@ void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *
}
}
const QRect nativeRect = QRect(pos, QSize(event->width, event->height));
QXcbScreen *newScreen = parent() ? parentScreen() : screenForNativeGeometry(nativeRect);
const QRect rect = QRect(pos, QSize(event->width, event->height));
QPlatformScreen *newScreen = parent() ? parent()->screen() : screenForGeometry(rect);
QXcbScreen *currentScreen = m_xcbScreen;
m_xcbScreen = newScreen;
m_xcbScreen = static_cast<QXcbScreen*>(newScreen);
if (!newScreen)
return;
const QRect rect = mapFromNative(nativeRect, newScreen);
QPlatformWindow::setGeometry(rect);
QWindowSystemInterface::handleGeometryChange(window(), rect);
if (newScreen != currentScreen)
QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->QPlatformScreen::screen());
QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->screen());
m_configureNotifyPending = false;
@ -2132,11 +2037,10 @@ QPoint QXcbWindow::mapToGlobal(const QPoint &pos) const
if (!m_embedded)
return pos;
const int dpr = int(devicePixelRatio());
QPoint ret;
xcb_translate_coordinates_cookie_t cookie =
xcb_translate_coordinates(xcb_connection(), xcb_window(), xcbScreen()->root(),
pos.x() * dpr, pos.y() * dpr);
pos.x(), pos.y());
xcb_translate_coordinates_reply_t *reply =
xcb_translate_coordinates_reply(xcb_connection(), cookie, NULL);
if (reply) {
@ -2145,7 +2049,7 @@ QPoint QXcbWindow::mapToGlobal(const QPoint &pos) const
free(reply);
}
return mapFromNative(ret, xcbScreen());
return ret;
}
QPoint QXcbWindow::mapFromGlobal(const QPoint &pos) const
@ -2153,17 +2057,15 @@ QPoint QXcbWindow::mapFromGlobal(const QPoint &pos) const
if (!m_embedded)
return pos;
const int dpr = int(devicePixelRatio());
QPoint ret;
QPoint xPos = mapToNative(pos, xcbScreen());
xcb_translate_coordinates_cookie_t cookie =
xcb_translate_coordinates(xcb_connection(), xcbScreen()->root(), xcb_window(),
xPos.x(), xPos.y());
pos.x(), pos.y());
xcb_translate_coordinates_reply_t *reply =
xcb_translate_coordinates_reply(xcb_connection(), cookie, NULL);
if (reply) {
ret.setX(reply->dst_x / dpr);
ret.setY(reply->dst_y / dpr);
ret.setX(reply->dst_x);
ret.setY(reply->dst_y);
free(reply);
}
@ -2179,7 +2081,7 @@ void QXcbWindow::handleMapNotifyEvent(const xcb_map_notify_event_t *event)
if (m_configureNotifyPending)
m_deferredExpose = true;
else
QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), geometry().size() * int(devicePixelRatio())));
QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), geometry().size()));
}
}
@ -2211,9 +2113,8 @@ void QXcbWindow::handleButtonPressEvent(int event_x, int event_y, int root_x, in
sendXEmbedMessage(container->xcb_window(), XEMBED_REQUEST_FOCUS);
}
}
const int dpr = int(devicePixelRatio());
QPoint local(event_x / dpr, event_y / dpr);
QPoint global = xcbScreen()->mapFromNative(QPoint(root_x, root_y));
QPoint local(event_x, event_y);
QPoint global(root_x, root_y);
if (isWheel) {
if (!connection()->isAtLeastXI21()) {
@ -2235,9 +2136,8 @@ void QXcbWindow::handleButtonPressEvent(int event_x, int event_y, int root_x, in
void QXcbWindow::handleButtonReleaseEvent(int event_x, int event_y, int root_x, int root_y,
int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp)
{
const int dpr = int(devicePixelRatio());
QPoint local(event_x / dpr, event_y / dpr);
QPoint global = xcbScreen()->mapFromNative(QPoint(root_x, root_y));
QPoint local(event_x, event_y);
QPoint global(root_x, root_y);
if (detail >= 4 && detail <= 7) {
// mouse wheel, handled in handleButtonPressEvent()
@ -2250,11 +2150,8 @@ void QXcbWindow::handleButtonReleaseEvent(int event_x, int event_y, int root_x,
void QXcbWindow::handleMotionNotifyEvent(int event_x, int event_y, int root_x, int root_y,
Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp)
{
if (!xcbScreen())
return;
const int dpr = int(devicePixelRatio());
QPoint local(event_x / dpr, event_y / dpr);
QPoint global = xcbScreen()->mapFromNative(QPoint(root_x, root_y));
QPoint local(event_x, event_y);
QPoint global(root_x, root_y);
handleMouseEvent(timestamp, local, global, modifiers);
}
@ -2382,11 +2279,10 @@ void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event)
if (ignoreEnterEvent(event))
return;
const int dpr = int(devicePixelRatio());
const QPoint local(event->event_x/dpr, event->event_y/dpr);
const QPoint local(event->event_x, event->event_y);
if (!xcbScreen())
return;
QPoint global = xcbScreen()->mapFromNative(QPoint(event->root_x, event->root_y));
QPoint global = QPoint(event->root_x, event->root_y);
QWindowSystemInterface::handleEnterEvent(window(), local, global);
}
@ -2402,11 +2298,10 @@ void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event)
QXcbWindow *enterWindow = enter ? connection()->platformWindowFromId(enter->event) : 0;
if (enterWindow) {
const int dpr = int(devicePixelRatio());
QPoint local(enter->event_x/dpr, enter->event_y/dpr);
QPoint local(enter->event_x, enter->event_y);
if (!xcbScreen())
return;
QPoint global = xcbScreen()->mapFromNative(QPoint(event->root_x, event->root_y));
QPoint global = QPoint(event->root_x, event->root_y);
QWindowSystemInterface::handleEnterLeaveEvent(enterWindow->window(), window(), local, global);
} else {
@ -2585,7 +2480,7 @@ bool QXcbWindow::startSystemResize(const QPoint &pos, Qt::Corner corner)
xev.type = moveResize;
xev.window = xcb_window();
xev.format = 32;
const QPoint globalPos = mapToNative(window()->mapToGlobal(pos), xcbScreen());
const QPoint globalPos = window()->mapToGlobal(pos);
xev.data.data32[0] = globalPos.x();
xev.data.data32[1] = globalPos.y();
const bool bottom = corner == Qt::BottomRightCorner || corner == Qt::BottomLeftCorner;
@ -2711,12 +2606,11 @@ void QXcbWindow::setMask(const QRegion &region)
xcb_shape_mask(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
XCB_SHAPE_SK_BOUNDING, xcb_window(), 0, 0, XCB_NONE);
} else {
const int dpr = devicePixelRatio();
QVector<xcb_rectangle_t> rects;
const QVector<QRect> regionRects = region.rects();
rects.reserve(regionRects.count());
foreach (const QRect &r, regionRects)
rects.push_back(qRectToXCBRectangle(mapLocalGeometryToNative(r, dpr)));
rects.push_back(qRectToXCBRectangle(r));
xcb_shape_rectangles(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
xcb_window(), 0, 0, rects.size(), &rects[0]);
@ -2754,11 +2648,6 @@ void QXcbWindow::postSyncWindowRequest()
}
}
qreal QXcbWindow::devicePixelRatio() const
{
return xcbScreen() ? xcbScreen()->devicePixelRatio() : 1.0;
}
QXcbScreen *QXcbWindow::xcbScreen() const
{
return static_cast<QXcbScreen *>(screen());

View File

@ -163,8 +163,6 @@ public:
void postSyncWindowRequest();
void clearSyncWindowRequest() { m_pendingSyncRequest = 0; }
qreal devicePixelRatio() const Q_DECL_OVERRIDE;
QXcbScreen *xcbScreen() const;
virtual void create();
@ -180,10 +178,6 @@ protected:
virtual void *createVisual() { return Q_NULLPTR; }
virtual bool supportsSyncProtocol() { return !window()->supportsOpenGL(); }
QPoint mapToNative(const QPoint &pos, const QXcbScreen *screen) const;
QPoint mapFromNative(const QPoint &pos, const QXcbScreen *screen) const;
QRect mapToNative(const QRect &rect, const QXcbScreen *screen) const;
QRect mapFromNative(const QRect &rect, const QXcbScreen *screen) const;
QXcbScreen *parentScreen();
void changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0);