Add auto-type {CLEARFIELD} on XCB

This commit is contained in:
thez3ro 2017-03-25 22:23:43 +01:00 committed by Weslly
parent 28678f4e06
commit 7620395f92
2 changed files with 29 additions and 2 deletions

View File

@ -723,6 +723,12 @@ bool AutoTypePlatformX11::keysymModifiers(KeySym keysym, int keycode, unsigned i
* are set ON, many events will be sent.
*/
void AutoTypePlatformX11::SendKeyPressedEvent(KeySym keysym)
{
SendKey(keysym,true);
SendKey(keysym,false);
}
void AutoTypePlatformX11::SendKey(KeySym keysym, bool isKeyDown)
{
Window cur_focus;
int revert_to;
@ -802,8 +808,11 @@ void AutoTypePlatformX11::SendKeyPressedEvent(KeySym keysym)
/* press and release key */
event.keycode = keycode;
SendEvent(&event, KeyPress);
SendEvent(&event, KeyRelease);
if (isKeyDown) {
SendEvent(&event, KeyPress);
} else {
SendEvent(&event, KeyRelease);
}
/* release the modifiers */
SendModifier(&event, press_mask, KeyRelease);
@ -840,6 +849,22 @@ void AutoTypeExecutorX11::execKey(AutoTypeKey* action)
m_platform->SendKeyPressedEvent(m_platform->keyToKeySym(action->key));
}
void AutoTypeExecutorX11::execClearField(AutoTypeClearField* action = nullptr)
{
Q_UNUSED(action);
m_platform->SendKey(XK_Control_L, true);
m_platform->SendKeyPressedEvent(XK_a);
m_platform->SendKey(XK_Control_L, false);
m_platform->SendKeyPressedEvent(XK_Delete);
timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 25 * 1000 * 1000;
nanosleep(&ts, nullptr);
}
int AutoTypePlatformX11::initialTimeout()
{
return 500;

View File

@ -58,6 +58,7 @@ public:
KeySym keyToKeySym(Qt::Key key);
void SendKeyPressedEvent(KeySym keysym);
void SendKey(KeySym keysym, bool isKeyDown);
signals:
void globalShortcutTriggered();
@ -126,6 +127,7 @@ public:
void execChar(AutoTypeChar* action) override;
void execKey(AutoTypeKey* action) override;
void execClearField(AutoTypeClearField* action) override;
private:
AutoTypePlatformX11* const m_platform;