Consistent use of abort() /* NOTREACHED */
[ardour.git] / libs / gtkmm2ext / visibility_tracker.cc
1 /*
2  * Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 #include <iostream>
19 #include <gtkmm/window.h>
20
21 #include "gtkmm2ext/visibility_tracker.h"
22
23 using namespace Gtkmm2ext;
24
25 bool VisibilityTracker::_use_window_manager_visibility = true;
26
27 VisibilityTracker::VisibilityTracker (Gtk::Window& win)
28         : _window (win)
29         , _visibility (GDK_VISIBILITY_FULLY_OBSCURED)
30 {
31         _window.add_events (Gdk::VISIBILITY_NOTIFY_MASK);
32         _window.signal_visibility_notify_event().connect (sigc::mem_fun (*this, &VisibilityTracker::handle_visibility_notify_event));
33 }
34
35 void
36 VisibilityTracker::set_use_window_manager_visibility (bool yn)
37 {
38         _use_window_manager_visibility = yn;
39 }
40
41 bool
42 VisibilityTracker::handle_visibility_notify_event (GdkEventVisibility* ev)
43 {
44         _visibility = ev->state;
45         return false;
46 }
47
48 void
49 VisibilityTracker::cycle_visibility ()
50 {
51         if (fully_visible ()) {
52                 _window.hide ();
53         } else {
54                 _window.present ();
55         }
56 }
57
58 bool
59 VisibilityTracker::fully_visible () const
60 {
61         if (_use_window_manager_visibility) {
62                 return _window.is_mapped() && (_visibility == GDK_VISIBILITY_UNOBSCURED);
63         } else {
64                 return _window.is_mapped();
65         }
66 }
67
68 bool
69 VisibilityTracker::not_visible () const
70 {
71         if (_use_window_manager_visibility) {
72                 return !_window.is_mapped() || (_visibility == GDK_VISIBILITY_FULLY_OBSCURED);
73         } else {
74                 return !_window.is_mapped();
75         }
76 }
77
78 bool
79 VisibilityTracker::partially_visible () const
80 {
81         if (_use_window_manager_visibility) {
82                 return _window.is_mapped() && ((_visibility == GDK_VISIBILITY_PARTIAL) || (_visibility == GDK_VISIBILITY_UNOBSCURED));
83         } else {
84                 return _window.is_mapped();
85         }
86 }