add ability to specify row colors for region treeview
[ardour.git] / libs / gtkmm2ext / idle_adjustment.cc
1 #define _BSD_SOURCE
2 #include <gtkmm2ext/idle_adjustment.h>
3 #include <gtkmm/main.h>
4 #include <iostream>
5
6 using namespace Gtk;
7 using namespace sigc;
8 using namespace Gtkmm2ext;
9
10 IdleAdjustment::IdleAdjustment (Gtk::Adjustment& adj)
11 {
12         adj.signal_value_changed().connect (mem_fun (*this, &IdleAdjustment::underlying_adjustment_value_changed));
13         timeout_queued = 0;
14         gettimeofday (&last_vc, 0);
15 }
16
17 IdleAdjustment::~IdleAdjustment ()
18 {
19 }
20
21 void
22 IdleAdjustment::underlying_adjustment_value_changed ()
23 {
24         gettimeofday (&last_vc, 0);
25         
26         if (timeout_queued) {
27                 return;
28         }
29
30         Glib::signal_timeout().connect(mem_fun(*this, &IdleAdjustment::timeout_handler), 250);
31         timeout_queued = true;
32 }       
33
34 gint
35 IdleAdjustment::timeout_handler ()
36 {
37         struct timeval now;
38         struct timeval tdiff;
39
40         gettimeofday (&now, 0);
41
42         timersub (&now, &last_vc, &tdiff);
43
44         std::cerr << "timer elapsed, diff = " << tdiff.tv_sec << " + " << tdiff.tv_usec << std::endl;
45
46         if (tdiff.tv_sec > 0 || tdiff.tv_usec > 250000) {
47                 std::cerr << "send signal\n";
48                 value_changed ();
49                 timeout_queued = false;
50                 return FALSE;
51         } else {
52                 return TRUE;
53         }
54 }