shift-shell/containments/homescreens/folio/widgetcontainer.h
Florian RICHER (aka MrDev023) 43672a5ec5 homescreens/folio: Block propagation if edit mode is active to avoid widget to trigger event
Fixes https://invent.kde.org/plasma/plasma-mobile/-/issues/387 and https://invent.kde.org/plasma/plasma-mobile/-/issues/353

I can't only block the touch events because it blocks also MouseEvent.
> I think because it's used to convert it by QT into Mouse Event with source == MouseEventSynthesizedByQt or MouseEventSynthesizedBySystem.

So the solution, it's to check if mouse event is a synthetized event and if edit mode has been triggered to block or not the event propagation

Test:

- On VM with kwin_wayland command
- On mobile
2025-06-18 05:53:15 -04:00

48 lines
1.2 KiB
C++

// SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <QMouseEvent>
#include <QQuickItem>
#include <QTimer>
class WidgetContainer : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(bool editMode READ editMode WRITE setEditMode NOTIFY editModeChanged)
QML_NAMED_ELEMENT(WidgetContainer)
public:
WidgetContainer(QQuickItem *parent = nullptr);
bool editMode() const;
void setEditMode(bool editMode);
Q_SIGNALS:
void editModeChanged();
void pressReleased();
void startEditMode(QPointF pressPoint);
protected:
bool childMouseEventFilter(QQuickItem *item, QEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseUngrabEvent() override;
private Q_SLOTS:
void startPressAndHold();
void onActiveFocusChanged(bool activeFocus);
private:
bool validMouseEvent(QMouseEvent *event);
bool m_pressed{false};
bool m_editMode{false};
QTimer *m_pressAndHoldTimer{nullptr};
QPointF m_mouseDownPosition{};
};
QML_DECLARE_TYPE(WidgetContainer)