GtkWidget::add_events

void add_events(GdkEventMask events);

Lets the widget receive more events by adding the event masks to the list of to-be-notified-of event types.

With that, you can let e.g. a GtkButton receive "motion-notify-event"s which it doesn't do by default.

Example 150. Tracking mouse movement on a button with add_events

<?php
/**
* We let the button receive an event that normally
* is not recognized by using GtkWidget::add_events()
*/
$btn = new GtkButton('move the mouse');
$btn->add_events(Gdk::POINTER_MOTION_MASK);
$btn->connect('motion-notify-event', 'onMouseOver');

function onMouseOver($btn, $event) {
    $btn->set_label($event->x . ', ' . $event->y);
}

$wnd = new GtkWindow();
$wnd->set_default_size(200, 100);
$wnd->add($btn);
$wnd->show_all();
$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));
Gtk::main();
?>

See also: get_events() , set_events()