Skip to content

Commit 58afdce

Browse files
make pin moving compatible with Wayland on Qt6 (flameshot-org#4000)
* make pin moving compatible with Wayland on Qt6 * found more to clean up
1 parent 5d91ce3 commit 58afdce

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

src/tools/pin/pinwidget.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <QGraphicsDropShadowEffect>
44
#include <QGraphicsOpacityEffect>
55
#include <QPinchGesture>
6+
#include <QWindow>
67

78
#include "pinwidget.h"
89
#include "qguiappcurrentscreen.h"
@@ -34,12 +35,11 @@ PinWidget::PinWidget(const QPixmap& pixmap,
3435
, m_shadowEffect(new QGraphicsDropShadowEffect(this))
3536
{
3637
setWindowIcon(QIcon(GlobalValues::iconPath()));
37-
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
38+
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint |
39+
Qt::Dialog);
3840
setFocusPolicy(Qt::StrongFocus);
39-
// set the bottom widget background transparent
4041
setAttribute(Qt::WA_TranslucentBackground);
4142
setAttribute(Qt::WA_DeleteOnClose);
42-
setWindowTitle("flameshot-pin");
4343
ConfigHandler conf;
4444
m_baseColor = conf.uiColor();
4545
m_hoverColor = conf.contrastUiColor();
@@ -69,10 +69,6 @@ PinWidget::PinWidget(const QPixmap& pixmap,
6969
static_cast<int>(static_cast<double>(MARGIN) * devicePixelRatio);
7070
QRect adjusted_pos = geometry + QMargins(margin, margin, margin, margin);
7171
setGeometry(adjusted_pos);
72-
#if defined(Q_OS_LINUX)
73-
setWindowFlags(Qt::X11BypassWindowManagerHint);
74-
#endif
75-
7672
#if defined(Q_OS_MACOS) || defined(Q_OS_LINUX)
7773
if (currentScreen != nullptr) {
7874
QPoint topLeft = currentScreen->geometry().topLeft();
@@ -152,19 +148,13 @@ void PinWidget::mouseDoubleClickEvent(QMouseEvent*)
152148

153149
void PinWidget::mousePressEvent(QMouseEvent* e)
154150
{
155-
m_dragStart = e->globalPosition();
156-
m_offsetX = e->position().x() / width();
157-
m_offsetY = e->position().y() / height();
151+
if (QWindow* window = windowHandle(); window != nullptr) {
152+
window->startSystemMove();
153+
return;
154+
}
158155
}
159156

160-
void PinWidget::mouseMoveEvent(QMouseEvent* e)
161-
{
162-
const QPointF delta = e->globalPosition() - m_dragStart;
163-
const int offsetW = width() * m_offsetX;
164-
const int offsetH = height() * m_offsetY;
165-
move(m_dragStart.x() + delta.x() - offsetW,
166-
m_dragStart.y() + delta.y() - offsetH);
167-
}
157+
void PinWidget::mouseMoveEvent(QMouseEvent* e) {}
168158

169159
void PinWidget::keyPressEvent(QKeyEvent* event)
170160
{

src/tools/pin/pinwidget.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ class PinWidget : public QWidget
4545
QPixmap m_pixmap;
4646
QVBoxLayout* m_layout;
4747
QLabel* m_label;
48-
QPointF m_dragStart;
49-
qreal m_offsetX{}, m_offsetY{};
5048
QGraphicsDropShadowEffect* m_shadowEffect;
5149
QColor m_baseColor, m_hoverColor;
5250

0 commit comments

Comments
 (0)