- /* We cannot set colours, fonts and cursors before the widget has
- been realized, so we do this directly after realization */
- g_signal_connect (connect_widget, "realize",
- G_CALLBACK (gtk_window_realized_callback), this);
+ // connect handler to prevent events from propagating up parent chain
+ g_signal_connect_after(m_widget,
+ "key_press_event", G_CALLBACK(key_and_mouse_event_after), this);
+ g_signal_connect_after(m_widget,
+ "key_release_event", G_CALLBACK(key_and_mouse_event_after), this);
+ g_signal_connect_after(m_widget,
+ "button_press_event", G_CALLBACK(key_and_mouse_event_after), this);
+ g_signal_connect_after(m_widget,
+ "button_release_event", G_CALLBACK(key_and_mouse_event_after), this);
+ g_signal_connect_after(m_widget,
+ "motion_notify_event", G_CALLBACK(key_and_mouse_event_after), this);
+
+ // We cannot set colours, fonts and cursors before the widget has been
+ // realized, so we do this directly after realization -- unless the widget
+ // was in fact realized already.
+ if ( gtk_widget_get_realized(connect_widget) )
+ {
+ gtk_window_realized_callback(connect_widget, this);
+ }
+ else
+ {
+ g_signal_connect (connect_widget, "realize",
+ G_CALLBACK (gtk_window_realized_callback), this);
+ }