kwhat/libuiohook

How to prevent event propagation?

WilixLead opened this issue · 10 comments

I can't find way to prevent event. Can libuiohook do it?
Will be cool prevent event after receiving (optionally)

kwhat commented

Hi, It is possible for Windows and OS X systems, however, it is not currently possible on Linux or Unix. To use this functionality, you need to set the reserved flag of the uiohook_event structure to 0x1 when you recieve the event on callback. This flag must be set synchronously on the same thread as the callback is received on. So far, only the mask 1 >> 0 is supported for the reserved field.

Thank you!
But. I use parts of code from examples and my code looks like this:

void dispatch_proc(uiohook_event * const event) {
  switch (event->type) {
    ....
    case EVENT_KEY_PRESSED:
    case EVENT_KEY_RELEASED:
    case EVENT_KEY_TYPED:
    case EVENT_MOUSE_PRESSED:
    case EVENT_MOUSE_RELEASED:
    case EVENT_MOUSE_CLICKED:
    case EVENT_MOUSE_MOVED:
    case EVENT_MOUSE_DRAGGED:
    case EVENT_MOUSE_WHEEL:
      event->reserved = 0x1;
      ......
    break;
  }
}

But events still emits to the system. What I'm doing wrong?

kwhat commented

That looks correct, which branch are you compiling? The master branch is probably broken and 1.1 is the current stable.

I use 1.1 branch. Some later I try remove current version of libuiohook and clone clean 1.1. But I think it is not help.
What should happen if I prevent key? When I type something and always set reserverd = 0x1, nothing will be typed (in notepad or terminal for example) ?

kwhat commented

Yes, if you set the reserved flag, it will prevent the event it was set for from propagating. So if it was a mouse move event, the mouse will not move. If it was a key down and key up, you will not be able to type.

kwhat commented

Please post the code you are using for the callback so I may better help you.

kwhat commented

I am not sure if it matters in your implementation, but the reserved flag must be set on the same thread context that it was called from. So you cannot copy the memory to a different thread.

Please look at this file https://github.com/WilixLead/iohook/blob/master/src/iohook.cc
For tests I just make this:

case EVENT_KEY_PRESSED:
    case EVENT_KEY_RELEASED:
    case EVENT_KEY_TYPED:
    case EVENT_MOUSE_PRESSED:
    case EVENT_MOUSE_RELEASED:
    case EVENT_MOUSE_CLICKED:
    case EVENT_MOUSE_MOVED:
    case EVENT_MOUSE_DRAGGED:
    case EVENT_MOUSE_WHEEL:
      event->reserved = 0x1; // <----- THIS
      uiohook_event event_copy;
      memcpy(&event_copy, event, sizeof(uiohook_event));

As I think, It should prevent all propagation. But really no :(
Where Im wrong?

Is it still the case that preventing event propagation is not possible on *nix?

If so are there any plans to add this functionality?

Thanks

kwhat commented

It's not possible on X11 due to some technical limitations and I doubt that will ever change. It maybe possible on Wayland, but that hasn't really seen widespread adoption thus far. Migrating this library to wayland is going to take substantial effort and I haven't really looked into it much at this point. If anyone really wants this functionality, start looking into wayland to see this maybe possible. I only have so many hours in a day and right now 2.2 getting finalized and a 3.0 refactor to fix several other long standing issues are a priority.