为什么XRecordDisableContext()不起作用? [英] Why XRecordDisableContext() is not working?
本文介绍了为什么XRecordDisableContext()不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
void Callback (XPointer, XRecordInterceptData *pRecord) { std::cout << "my logs
"; }
int main ()
{
if(auto* const pDisplay = XOpenDisplay(nullptr))
{
XRecordClientSpec clients = XRecordAllClients;
auto* pRange = ::XRecordAllocRange();
pRange->device_events = XRecordRange8{KeyPress, ButtonRelease};
auto context = ::XRecordCreateContext(pDisplay, 0, &clients, 1, &pRange, 1);
::XRecordEnableContextAsync(pDisplay, context, Callback, nullptr); // use with/without `...Async()`
::XRecordDisableContext(pDisplay, context);
::XRecordFreeContext(pDisplay, context);
::XFree(pRange);
::XFlush(pDisplay);
::XSync(pDisplay, true);
}
}
我注意到,即使在XRecordDisableContext()
之后,仍会继续调用Callback()
。
如何禁用录音,以便不再调用回调?
注意::
- 以this site为例。
- 不知道如何使用
XRecordEnableContext()
,所以使用XRecordEnableContextAsync()
。这是问题的根源吗?
推荐答案
一种方法是将Below语句移到Callback()
或某个等效的其他线程中。出于测试目的,我更改了代码,如下所示,在引发几个事件后,我从Callback()
禁用,它可以工作。
::Display* pDisplay;
XRecordRange* pRange;
XRecordContext context;
#define CHECK(EVENT) if(*pDatum == EVENT) qDebug() << #EVENT
void Handle (XPointer, XRecordInterceptData *pRecord)
{
std::cout << "my logs
";
static int i = 0;
if(++i < 10)
return;
::XRecordDisableContext(pDisplay, context);
::XRecordFreeContext(pDisplay, context);
::XFree(pRange);
::XFlush(pDisplay);
::XSync(pDisplay, true);
}
// other code same, except 3 variables are global and "Free"-up functions are not required
这篇关于为什么XRecordDisableContext()不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文