// If the focused widget doesn't have the mouse,
// send the mouse input to the focused widget.
if (!focused) {
KInputTest::mouseButtonPressed(button, pressed);
}
}
}
// Update mouse button state.
const bool mousebuttonup = button.button() == Qt::LeftButton;
const int num = KInputTest::mouseButtonsToPress(button);
// If mouse button is down, send mouse input to the user (shift + mouse).
// If not, send mouse input to the focused widget (not visible).
if (num != -1) {
if (pressed && !mousebuttonup) {
KInputTest::mouseButtonReleased(button, pressed);
}
if (!pressed && mousebuttonup) {
KInputTest::mouseButtonPressed(button, pressed);
}
}
// If mouse button is not up (which is the default), stop polling.
// The alternative to polling in the context of using an app
// that has a button to poll, is to use polling events (like
// mouse button pressed above, but without a window manager)
// as a workaround to make sure that a KInputTest::mouseButtonPressed
// gets emitted with 'false' for a button press regardless of the
// button pressed.
if (num == -1) {
KInputTest::mouseButtonReleased(button, false);
return;
}
// Update mouse event.
Q_EMIT mouseButtonPressed(button, pressed);
}
// Update the state of the window manager and the desktop.
KWindowSystem::setState(winId(), KWindowSystem::WindowState(windowType));
const bool toplayer = KWindowSystem::isPlatformX11() || KWindowSystem::isPlatformWayland();
// Update the active desktop.
if (toplayer) {
KWindowSystem::setCurrentDesktop(KWindowSystem::desktop() + 1);
} else {
KWindowSystem::setCurrentDesktop(winId());
}
// Update the active window title.
if (toplayer) {
QString title = QString::number(KWindowSystem::activeWindow() + 1);
KWindowSystem::setUserTitle(winId(), title);
} else {
KWindowSystem::setUserTitle(winId(), title);
}
}