After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 132195 - EventBox not passing KEY events
EventBox not passing KEY events
Status: RESOLVED NOTABUG
Product: gtkmm
Classification: Bindings
Component: general
2.2
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2004-01-22 14:33 UTC by bevis
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: 2.1/2.2



Description bevis 2004-01-22 14:33:37 UTC
Set up an EventBox to grab key_press/release events, and they don't get
through.
The code below should print something for button & key events; it only
prints button events.
Possibly I've missed something.


#include <gtkmm.h>
#include <iostream>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow() : m_Label("Click here to quit, quit, quit, quit, quit")
  {
    set_title ("EventBox");
    set_border_width(10);
    add(m_EventBox);
    m_EventBox.add(m_Label);
    m_Label.set_size_request(110, 20);
    m_EventBox.set_events(Gdk::KEY_PRESS_MASK | Gdk::BUTTON_PRESS_MASK);
    m_EventBox.signal_button_press_event().connect(SigC::slot(*this,
&ExampleWindow::on_eventbox_button_press) );
    m_EventBox.signal_key_press_event().connect(SigC::slot(*this,
&ExampleWindow::on_eventbox_key_press) );

    show_all_children();
  }
  virtual ~ExampleWindow() {} ;

protected:
  virtual bool on_eventbox_key_press(GdkEventKey* event)
  {
    std::cout <<"KEY "<<event->keyval<<std::endl;
    return true;
  }
  virtual bool on_eventbox_button_press(GdkEventButton* event)
  {
    std::cout <<"BUTTON"<<std::endl;
    return true;
  }

  Gtk::EventBox m_EventBox;
  Gtk::Label m_Label;
};

int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);
  ExampleWindow window;
  Gtk::Main::run(window);
  return 0;
}
Comment 1 Murray Cumming 2004-01-22 16:29:19 UTC
Please ask on gtk-list@gnome.org about this. Maybe somebody has some idea.
Comment 2 Hagen.Moebius 2004-03-09 22:18:47 UTC
I don't know for sure but as far as I can remember keyboard events can
only be received by windows which may have the focus. This is true for
neither the EventBox nor the Label. You CAN receive mouse events
because there is an area to click on, but there is no window which can
have the focus.

If this raises the question where the keyboard input is going to end:
in the window. In the line:

m_EventBox.signal_key_press_event().connect(SigC::slot(*this,
&ExampleWindow::on_eventbox_key_press));

just remove the m_EventBox in front of it and the window will catch
the events (which is always true if nobody cares for a certain event).
Comment 3 Murray Cumming 2004-03-18 18:24:16 UTC
Please reopen if that does not solve the problem.
Comment 4 bevis 2004-03-19 10:25:19 UTC
Right, makes sense.  I had assumed that if the window had the focus,
then the event boxes within it would get the key events.