iammilind
iammilind

Reputation: 70030

Why XRecordDisableContext() is not working?

void Callback (XPointer, XRecordInterceptData *pRecord) { std::cout << "my logs\n"; }

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);
  }
}

I am noticing that even after XRecordDisableContext(), the Callback() continues to be invoked.
How can we disable the recording, so that the callback isn't invoked anymore?

Note:

Upvotes: 2

Views: 205

Answers (1)

iammilind
iammilind

Reputation: 70030

One way is to move below statement into the Callback() or some equivalent other thread. For testing purpose, I changed the code as below where after few event raised, I disable from the Callback() and it works.

::Display* pDisplay;
XRecordRange* pRange;
XRecordContext context;

#define CHECK(EVENT) if(*pDatum == EVENT) qDebug() << #EVENT
void Handle (XPointer, XRecordInterceptData *pRecord)
{
  std::cout << "my logs\n";
  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

Upvotes: 1

Related Questions