SetEventMask(B_KEYBOARD_EVENTS) leads to duplicate Alt-B, Alt-V ..etc
|Reported by:||ttcoder||Owned by:||axeld|
|Has a Patch:||no||Platform:||All|
BView::SetEventMask(B_KEYBOARD_EVENTS) allows a view to "snoop" on the keyboard, i.e. makes the view receive keystrokes regardless of its being the window's current focus view or not.
This currently works not by re-routing the original message (like SetMouseEventMask() does), but instead by sending it normally and then also sending a duplicate copy to the view that called
SetEventMask(). That in itself is not a big problem to work-around, as each recipient (the window and the "snooping" view) is free to ignore what does not concern it by re-implementing the concerned hooks...
Except..... in the case of Command-xyz keyboard shortcuts, due to special treatment : they are not dispatched to both recipients -- instead they are both handled by the same recipient, the window. They never reach the view that called SetEventMask() (!) because
BWindow::DispatchMessage() processes them apart, consuming them with
return true here:
and thus the target view's hooks (KeyDown(), MessageReceived()) are never called, we never enter the
Thus hitting Command-B leads to be_app.AboutRequested() being called twice, hitting Command-V leads to the clipboard text being pasted twice and so on for other window shortcuts... And contrarily to other keyboard events, there is no clean possibility of fixing the misbehavior, except by hacking/overriding BWindow::DispatchMessage(), as I had to do in my app. Either that, or you have to forget about using SetEventMask(B_KEYBOARD_EVENTS). Somewhat annoying.