[haiku-bugs] [Haiku] #10461: SetEventMask(B_KEYBOARD_EVENTS) leads to duplicate Alt-B, Alt-V ..etc

  • From: "ttcoder" <trac@xxxxxxxxxxxx>
  • Date: Thu, 23 Jan 2014 12:40:15 -0000

#10461: SetEventMask(B_KEYBOARD_EVENTS) leads to duplicate Alt-B, Alt-V ..etc
--------------------------------+------------------------------
 Reporter:  ttcoder             |        Owner:  axeld
     Type:  bug                 |       Status:  new
 Priority:  normal              |    Milestone:  R1
Component:  Kits/Interface Kit  |      Version:  R1/Development
 Keywords:                      |   Blocked By:
 Blocking:                      |  Has a Patch:  0
 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:
         http://cgit.haiku-
 os.org/haiku/tree/src/kits/interface/Window.cpp#n3804
 and thus the target view's hooks (KeyDown(), MessageReceived()) are never
 called, we never enter the `if()` here:
         http://cgit.haiku-
 os.org/haiku/tree/src/kits/interface/Window.cpp#n1196

 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.

--
Ticket URL: <https://dev.haiku-os.org/ticket/10461>
Haiku <https://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: