Skip to content
Snippets Groups Projects
Commit 3494d7d8 authored by Pierre Lamot's avatar Pierre Lamot Committed by Jean-Baptiste Kempf
Browse files

qt: move CSD resize events handling to QML

InterfaceWindowHandler isn't receiving mouse events from the QWindow on X11, now
that we have CSDMouseStealer.qml which properly defines the resize areas, moving
the handling of resize areas from C++ to QML solves this issue and avoids having
the behavior handled in two places.
parent acf485b9
No related branches found
No related tags found
No related merge requests found
......@@ -118,58 +118,6 @@ InterfaceWindowHandler::~InterfaceWindowHandler()
}
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
bool InterfaceWindowHandler::CSDSetCursor(QMouseEvent* mouseEvent)
{
if (!m_mainInterface->useClientSideDecoration())
return false;
if ((m_window->visibility() & QWindow::Maximized) != 0)
return false;
Qt::CursorShape shape;
const int x = mouseEvent->x();
const int y = mouseEvent->y();
const int winHeight = m_window->height();
const int winWidth = m_window->width();
const int b = m_mainInterface->CSDBorderSize();
if (x < b && y < b) shape = Qt::SizeFDiagCursor;
else if (x >= winWidth - b && y >= winHeight - b) shape = Qt::SizeFDiagCursor;
else if (x >= winWidth - b && y < b) shape = Qt::SizeBDiagCursor;
else if (x < b && y >= winHeight - b) shape = Qt::SizeBDiagCursor;
else if (x < b || x >= winWidth - b) shape = Qt::SizeHorCursor;
else if (y < b || y >= winHeight - b) shape = Qt::SizeVerCursor;
else if (m_hasResizeCursor) {
m_window->unsetCursor();
m_hasResizeCursor = false;
return false;
} else {
return false;
}
m_hasResizeCursor = true;
m_window->setCursor(shape);
return false;
}
bool InterfaceWindowHandler::CSDHandleClick(QMouseEvent* mouseEvent)
{
if (!m_mainInterface->useClientSideDecoration())
return false;
const int b = m_mainInterface->CSDBorderSize();
if( mouseEvent->buttons() != Qt::LeftButton)
return false;
if ((m_window->visibility() & QWindow::Maximized) != 0)
return false;
Qt::Edges edge;
if (mouseEvent->x() < b) { edge |= Qt::LeftEdge; }
if (mouseEvent->x() > m_window->width() - b) { edge |= Qt::RightEdge; }
if (mouseEvent->y() < b) { edge |= Qt::TopEdge; }
if (mouseEvent->y() > m_window->height() - b) { edge |= Qt::BottomEdge; }
if (edge != 0) {
m_window->startSystemResize(edge);
return true;
}
return false;
}
void InterfaceWindowHandler::updateCSDWindowSettings()
{
m_window->hide(); // some window managers don't like to change frame window hint on visible window
......@@ -283,19 +231,6 @@ bool InterfaceWindowHandler::eventFilter(QObject*, QEvent* event)
return true;
}
}
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
//Handle CSD edge behaviors
case QEvent::MouseMove:
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
return CSDSetCursor(mouseEvent);
}
case QEvent::MouseButtonPress:
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
return CSDHandleClick(mouseEvent);
}
#endif
default:
break;
}
......
......@@ -56,8 +56,6 @@ signals:
private:
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
bool CSDSetCursor(QMouseEvent* mouseEvent);
bool CSDHandleClick(QMouseEvent* mouseEvent);
virtual void updateCSDWindowSettings();
#endif
......
......@@ -20,34 +20,82 @@ import QtQuick 2.15
import QtQuick.Window 2.15
Item {
parent: g_root
id: root
property int csdSize: mainInterface.csdBorderSize
//private
readonly property int _edgeVtHeight: g_root.height - root.csdSize * 2
readonly property int _edgeHzWidth: g_root.width - root.csdSize * 2
Repeater {
model: [
//Edges
{
x: 0,
edge: Qt.TopEdge,
x: root.csdSize,
y: 0,
width: g_root.width,
height: mainInterface.csdBorderSize
width: root._edgeHzWidth,
height: root.csdSize,
cursor: Qt.SizeVerCursor,
},
{
edge: Qt.LeftEdge,
x: 0,
y: 0,
width: mainInterface.csdBorderSize,
height: g_root.height
y: root.csdSize,
width: root.csdSize,
height: root._edgeVtHeight,
cursor: Qt.SizeHorCursor,
},
{
edge: Qt.RightEdge,
x: g_root.width - root.csdSize,
y: root.csdSize,
width: root.csdSize,
height: root._edgeVtHeight,
cursor: Qt.SizeHorCursor,
},
{
edge: Qt.BottomEdge,
x: root.csdSize,
y: g_root.height - root.csdSize,
width: root._edgeHzWidth,
height: root.csdSize,
cursor: Qt.SizeVerCursor,
},
//Corners
{
x: g_root.width - mainInterface.csdBorderSize,
edge: Qt.TopEdge | Qt.LeftEdge,
x: 0,
y: 0,
width: mainInterface.csdBorderSize,
height: g_root.height
width: root.csdSize,
height: root.csdSize,
cursor: Qt.SizeFDiagCursor,
},
{
edge: Qt.BottomEdge | Qt.LeftEdge,
x: 0,
y: g_root.height - mainInterface.csdBorderSize,
width: g_root.width,
height: mainInterface.csdBorderSize
}
y: g_root.height - root.csdSize,
width: root.csdSize,
height: root.csdSize,
cursor: Qt.SizeBDiagCursor,
},
{
edge: Qt.TopEdge | Qt.RightEdge,
x: g_root.width - root.csdSize,
y: 0,
width: root.csdSize,
height: root.csdSize,
cursor: Qt.SizeBDiagCursor,
},
{
edge: Qt.BottomEdge | Qt.RightEdge,
x: g_root.width - root.csdSize,
y: g_root.height - root.csdSize,
width: root.csdSize,
height: root.csdSize,
cursor: Qt.SizeFDiagCursor,
},
]
delegate: MouseArea {
......@@ -58,6 +106,10 @@ Item {
height: modelData.height
hoverEnabled: true
cursorShape: modelData.cursor
acceptedButtons: Qt.LeftButton
onPressed: topWindow.startSystemResize(modelData.edge)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment