Commit f078d563 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

QuickEditor: Use XCB API to position the editor window

Qt scales coordinates relative to the upper-left corner of the screen
where the quick editor window is. This means that (0, 0) in the logical
pixels is not the same as (0, 0) in the native pixels.

Commit ccf8d522 tried to address that
issue by mapping (0, 0) from the native pixels to the logical pixels.

Unfortunately, it doesn't work reliably because setting geometry may
move a window to another screen and thus the computed window position
will be wrong.

It would be wonderful if QXcbWindowFunctions had a function that sets
the window geometry in native pixels that we could use here in Spectacle
to bypass HiDPI code path.

As a short term solution, this change makes Spectacle use XCB API
directly to position itself.
parent 0e260243
......@@ -25,6 +25,7 @@
#include <QScreen>
#include <QtCore/qmath.h>
#include <QPainterPath>
#include <QX11Info>
#include "QuickEditor.h"
#include "settings.h"
......@@ -54,24 +55,6 @@ const int QuickEditor::magZoom = 5;
const int QuickEditor::magPixels = 16;
const int QuickEditor::magOffset = 32;
static QPoint fromNative(const QPoint &point, const QScreen *screen)
{
const QPoint origin = screen->geometry().topLeft();
const qreal devicePixelRatio = screen->devicePixelRatio();
return (point - origin) / devicePixelRatio + origin;
}
static QSize fromNative(const QSize &size, const QScreen *screen)
{
return size / screen->devicePixelRatio();
}
static QRect fromNativePixels(const QRect &rect, const QScreen *screen)
{
return QRect(fromNative(rect.topLeft(), screen), fromNative(rect.size(), screen));
}
QuickEditor::QuickEditor(const QPixmap &thePixmap, KWayland::Client::PlasmaShell *plasmashell, QWidget *parent) :
QWidget(parent),
mMaskColor(QColor::fromRgbF(0, 0, 0, 0.15)),
......@@ -109,6 +92,7 @@ QuickEditor::QuickEditor(const QPixmap &thePixmap, KWayland::Client::PlasmaShell
setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::Popup | Qt::WindowStaysOnTopHint);
dprI = 1.0 / devicePixelRatioF();
setGeometry(0, 0, static_cast<int>(mPixmap.width() * dprI), static_cast<int>(mPixmap.height() * dprI));
if (KWindowSystem::isPlatformX11()) {
// Even though we want the quick editor window to be placed at (0, 0) in the native
......@@ -119,12 +103,19 @@ QuickEditor::QuickEditor(const QPixmap &thePixmap, KWayland::Client::PlasmaShell
// a conversion from the device-independent coordinates to the native pixels.
//
// Since (0, 0) in the device-independent pixels may not correspond to (0, 0) in the
// native pixels, we have to map (0, 0) from native pixels to dip and use that as
// the window position.
winId();
setGeometry(fromNativePixels(mPixmap.rect(), windowHandle()->screen()));
} else {
setGeometry(0, 0, static_cast<int>(mPixmap.width() * dprI), static_cast<int>(mPixmap.height() * dprI));
// native pixels, we use XCB API to place the quick editor window at (0, 0).
uint16_t mask = 0;
mask |= XCB_CONFIG_WINDOW_X;
mask |= XCB_CONFIG_WINDOW_Y;
const uint32_t values[] = {
/* x */ 0,
/* y */ 0,
};
xcb_configure_window(QX11Info::connection(), winId(), mask, values);
}
// TODO This is a hack until a better interface is available
......
Markdown is supported
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