VisibilityTracker needs to inherit from sigc::tracker so that it can be used without...
[ardour.git] / libs / gtkmm2ext / visibility_tracker.cc
1 /*
2     Copyright (C) 2013 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <gtkmm/window.h>
21
22 #include "gtkmm2ext/visibility_tracker.h"
23
24 using namespace Gtkmm2ext;
25
26 VisibilityTracker::VisibilityTracker (Gtk::Window& win)
27         : _window (win)
28         , _visibility (GdkVisibilityState (0))
29 {
30         _window.add_events (Gdk::VISIBILITY_NOTIFY_MASK);
31         _window.signal_visibility_notify_event().connect (sigc::mem_fun (*this, &VisibilityTracker::handle_visibility_notify_event));
32 }
33
34 bool
35 VisibilityTracker::handle_visibility_notify_event (GdkEventVisibility* ev)
36 {
37         _visibility = ev->state;
38         return false;
39 }
40
41 void
42 VisibilityTracker::cycle_visibility ()
43 {
44         if (fully_visible ()) {
45                 _window.hide ();
46         } else {
47                 _window.present ();
48         }
49 }
50
51 bool
52 VisibilityTracker::fully_visible () const
53 {
54         return _window.is_mapped() && (_visibility == GDK_VISIBILITY_UNOBSCURED);
55 }
56
57 bool
58 VisibilityTracker::not_visible () const
59 {
60         return !_window.is_mapped() || (_visibility == GDK_VISIBILITY_FULLY_OBSCURED);
61 }
62
63 bool
64 VisibilityTracker::partially_visible () const
65 {
66         return _window.is_mapped() && ((_visibility == GDK_VISIBILITY_PARTIAL) || (_visibility == GDK_VISIBILITY_UNOBSCURED));
67 }