Update x11Time when a global shortcut is pressed

KGlobalAccel sets the timestamp as a property and we need to set our
x11Time to it otherwise following keyboard grabs might fail.

Requires 61e2a156678eef033b2629f7c72530dc78d7c3ac in kglobalaccel.
This commit is contained in:
Martin Gräßlin 2015-02-19 10:38:49 +01:00
parent d95ab94f0a
commit 857219546f
7 changed files with 46 additions and 9 deletions

View file

@ -83,6 +83,11 @@ void InputRedirection::registerAxisShortcut(Qt::KeyboardModifiers modifiers, Poi
Q_UNUSED(action)
}
void InputRedirection::registerShortcutForGlobalAccelTimestamp(QAction *action)
{
Q_UNUSED(action)
}
void updateXTime()
{
}

View file

@ -44,6 +44,11 @@ void InputRedirection::registerAxisShortcut(Qt::KeyboardModifiers modifiers, Poi
Q_UNUSED(action)
}
void InputRedirection::registerShortcutForGlobalAccelTimestamp(QAction *action)
{
Q_UNUSED(action)
}
}
Q_DECLARE_METATYPE(Qt::Orientation)

View file

@ -551,6 +551,7 @@ Qt::KeyboardModifiers InputRedirection::keyboardModifiers() const
void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action)
{
m_shortcuts->registerShortcut(action, shortcut);
registerShortcutForGlobalAccelTimestamp(action);
}
void InputRedirection::registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action)
@ -563,6 +564,18 @@ void InputRedirection::registerAxisShortcut(Qt::KeyboardModifiers modifiers, Poi
m_shortcuts->registerAxisShortcut(action, modifiers, axis);
}
void InputRedirection::registerShortcutForGlobalAccelTimestamp(QAction *action)
{
connect(action, &QAction::triggered, kwinApp(), [action] {
QVariant timestamp = action->property("org.kde.kglobalaccel.activationTimestamp");
bool ok = false;
const quint32 t = timestamp.toULongLong(&ok);
if (ok) {
kwinApp()->setX11Time(t);
}
});
}
static bool screenContainsPos(const QPointF &pos)
{
for (int i = 0; i < screens()->count(); ++i) {

20
input.h
View file

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef KWIN_INPUT_H
#define KWIN_INPUT_H
#include <kwinglobals.h>
#include <QAction>
#include <QHash>
#include <QObject>
#include <QPoint>
@ -27,7 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QWeakPointer>
#include <config-kwin.h>
class QAction;
class QKeySequence;
struct xkb_context;
@ -85,6 +85,16 @@ public:
Qt::KeyboardModifiers keyboardModifiers() const;
void registerShortcut(const QKeySequence &shortcut, QAction *action);
/**
* @overload
*
* Like registerShortcut, but also connects QAction::triggered to the @p slot on @p receiver.
* It's recommended to use this method as it ensures that the X11 timestamp is updated prior
* to the @p slot being invoked. If not using this overload it's required to ensure that
* registerShortcut is called before connecting to QAction's triggered signal.
**/
template <typename T>
void registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, void (T::*slot)());
void registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action);
void registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action);
@ -158,6 +168,7 @@ private:
void setupLibInput();
void updatePointerPosition(const QPointF &pos);
void updatePointerAfterScreenChange();
void registerShortcutForGlobalAccelTimestamp(QAction *action);
QPointF m_globalPointer;
QHash<uint32_t, PointerButtonState> m_pointerButtons;
#if HAVE_XKB
@ -222,6 +233,13 @@ InputRedirection::PointerButtonState InputRedirection::pointerButtonState(uint32
}
}
template <typename T>
inline
void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, void (T::*slot)()) {
registerShortcut(shortcut, action);
connect(action, &QAction::triggered, receiver, slot);
}
#if HAVE_XKB
inline
Qt::KeyboardModifiers Xkb::modifiers() const

View file

@ -500,8 +500,7 @@ void TabBox::key(const char *actionName, Slot slot, const QKeySequence &shortcut
a->setObjectName(QString::fromUtf8(actionName));
a->setText(i18n(actionName));
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << shortcut);
connect(a, &QAction::triggered, TabBox::self(), slot);
input()->registerShortcut(shortcut, a);
input()->registerShortcut(shortcut, a, TabBox::self(), slot);
auto cuts = KGlobalAccel::self()->shortcut(a);
globalShortcutChanged(a, cuts.isEmpty() ? QKeySequence() : cuts.first());
}

View file

@ -937,8 +937,7 @@ void Workspace::initShortcut(const QString &actionName, const QString &descripti
}
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << shortcut);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << shortcut);
connect(a, &QAction::triggered, this, slot);
input()->registerShortcut(shortcut, a);
input()->registerShortcut(shortcut, a, this, slot);
}
/*!

View file

@ -458,9 +458,8 @@ void VirtualDesktopManager::addAction(const QString &name, const KLocalizedStrin
a->setObjectName(name.arg(value));
a->setText(label.subs(value).toString());
a->setData(value);
connect(a, &QAction::triggered, this, slot);
KGlobalAccel::setGlobalShortcut(a, key);
input()->registerShortcut(key, a);
input()->registerShortcut(key, a, this, slot);
}
void VirtualDesktopManager::addAction(const QString &name, const QString &label, void (VirtualDesktopManager::*slot)())
@ -468,9 +467,8 @@ void VirtualDesktopManager::addAction(const QString &name, const QString &label,
QAction *a = new QAction(this);
a->setObjectName(name);
a->setText(label);
connect(a, &QAction::triggered, this, slot);
KGlobalAccel::setGlobalShortcut(a, QKeySequence());
input()->registerShortcut(QKeySequence(), a);
input()->registerShortcut(QKeySequence(), a, this, slot);
}
void VirtualDesktopManager::slotSwitchTo()