Add support for WheelEvents on Decoration

Forwarded to the Decoration and reacts on emitted signal.
icc-effect-5.14.5
Martin Gräßlin 2014-07-25 08:05:47 +02:00
parent c8c0bace31
commit c1edbd584b
2 changed files with 43 additions and 10 deletions

View File

@ -523,6 +523,14 @@ void Client::createDecoration(const QRect& oldgeom)
dontMoveResize();
}
);
connect(m_decoration, &KDecoration2::Decoration::titleBarWheelEvent, this,
[this](const QPoint &angleDelta) {
if (angleDelta.y() == 0) {
return;
}
performMouseCommand(options->operationTitlebarMouseWheel(angleDelta.y()), Cursor::pos());
}
);
}
move(calculateGravitation(false));

View File

@ -1128,13 +1128,31 @@ bool Client::buttonPressEvent(xcb_window_t w, int button, int state, int x, int
return processDecorationButtonPress(button, state, x, y, x_root, y_root, true);
}
if (w == frameId() && m_decoration) {
qDebug() << "Button press on frame";
QMouseEvent event(QEvent::MouseButtonPress, QPointF(x, y), QPointF(x_root, y_root),
x11ToQtMouseButton(button), x11ToQtMouseButtons(state), x11ToQtKeyboardModifiers(state));
event.setAccepted(false);
QCoreApplication::sendEvent(m_decoration, &event);
if (!event.isAccepted()) {
processDecorationButtonPress(button, state, x, y, x_root, y_root);
if (button >= 4 && button <= 7) {
const Qt::KeyboardModifiers modifiers = x11ToQtKeyboardModifiers(state);
// Logic borrowed from qapplication_x11.cpp
const int delta = 120 * ((button == 4 || button == 6) ? 1 : -1);
const bool hor = (((button == 4 || button == 5) && (modifiers & Qt::AltModifier))
|| (button == 6 || button == 7));
const QPoint angle = hor ? QPoint(delta, 0) : QPoint(0, delta);
QWheelEvent event(QPointF(x, y),
QPointF(x_root, y_root),
QPoint(),
angle,
delta,
hor ? Qt::Horizontal : Qt::Vertical,
x11ToQtMouseButtons(state),
modifiers);
QCoreApplication::sendEvent(m_decoration, &event);
} else {
QMouseEvent event(QEvent::MouseButtonPress, QPointF(x, y), QPointF(x_root, y_root),
x11ToQtMouseButton(button), x11ToQtMouseButtons(state), x11ToQtKeyboardModifiers(state));
event.setAccepted(false);
QCoreApplication::sendEvent(m_decoration, &event);
if (!event.isAccepted()) {
processDecorationButtonPress(button, state, x, y, x_root, y_root);
}
}
return true;
}
@ -1189,9 +1207,16 @@ bool Client::processDecorationButtonPress(int button, int /*state*/, int x, int
bool Client::buttonReleaseEvent(xcb_window_t w, int button, int state, int x, int y, int x_root, int y_root)
{
if (w == frameId() && m_decoration) {
qDebug() << "Button release on frame";
QMouseEvent event(QEvent::MouseButtonRelease, QPointF(x, y), QPointF(x_root, y_root), x11ToQtMouseButton(button), x11ToQtMouseButtons(state), x11ToQtKeyboardModifiers(state));
QCoreApplication::sendEvent(m_decoration, &event);
// wheel handled on buttonPress
if (button < 4 || button > 7) {
QMouseEvent event(QEvent::MouseButtonRelease,
QPointF(x, y),
QPointF(x_root, y_root),
x11ToQtMouseButton(button),
x11ToQtMouseButtons(state),
x11ToQtKeyboardModifiers(state));
QCoreApplication::sendEvent(m_decoration, &event);
}
}
if (w == wrapperId()) {
xcb_allow_events(connection(), XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME); //xTime());