title: How to handle mouseover events in GTK+3?
body: <p>I was wondering how to handle mouse over events without having one of the mouse buttons pressed.</p>
  
  <p>I wrote the following code (based on Cairo Zetcode tutorial), that draws and updates a line while the mouse button is pressed and the cursor is moving around:</p>
  
  <pre><code>#include &lt;cairo.h&gt;
  #include &lt;gtk/gtk.h&gt;
  
  
  static void do_drawing(cairo_t *);
  
  struct {
      double coordx[2];
      double coordy[2];
  }glob;
  
  static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr, gpointer user_data)
  {
      do_drawing(cr);  
      return FALSE;
  }
  
  static void do_drawing(cairo_t *cr)
  {
      cairo_set_source_rgb(cr, 0, 0, 0);
      cairo_set_line_width(cr, 0.8);
  
      cairo_move_to(cr, glob.coordx[0], glob.coordy[0]);
      cairo_line_to(cr, glob.coordx[1], glob.coordy[1]);
  
      cairo_stroke(cr);    
  }
  
  static gboolean clicked(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
  {
      if (event-&gt;button == 1) {
          glob.coordx[0] = event-&gt;x;
          glob.coordy[0] = event-&gt;y;
      }
  
      if (event-&gt;button == 3) {
          glob.coordx[0] = event-&gt;x;
          glob.coordy[0] = event-&gt;y;
      }
  
      return TRUE;
  }
  
  static gboolean motion_notify_event( GtkWidget *widget, GdkEventMotion *event ) {
  
      glob.coordx[1] = event-&gt;x;
      glob.coordy[1] = event-&gt;y;
      gtk_widget_queue_draw(widget);
  
      return TRUE;
  }
  
  int main(int argc, char *argv[])
  {
    GtkWidget *window;
    GtkWidget *darea;
  
    gtk_init(&amp;argc, &amp;argv);
  
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  
    darea = gtk_drawing_area_new();
    gtk_container_add(GTK_CONTAINER(window), darea);
  
    gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);
  
    g_signal_connect(G_OBJECT(darea), "draw", G_CALLBACK(on_draw_event), NULL); 
  
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);  
  
    g_signal_connect(window, "button-press-event", G_CALLBACK(clicked), NULL);
  
    g_signal_connect (window, "motion_notify_event",G_CALLBACK(motion_notify_event), NULL);
  
  
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 300); 
    gtk_window_set_title(GTK_WINDOW(window), "Lines");
  
    gtk_widget_show_all(window);
  
    gtk_main();
  
    return 0;
  }
  </code></pre>
  
  <p>How do I get GTK to update the drawing of the line just by moving the mouse, i.e. without having to press the mouse button?</p>
  
  <p>THanks!</p>