Update classkeys to match new total LuaSignal count (windows only)
[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 #include <iostream>
20 #include <gtkmm/window.h>
21
22 #include "gtkmm2ext/visibility_tracker.h"
23
24 using namespace Gtkmm2ext;
25
26 bool VisibilityTracker::_use_window_manager_visibility = true;
27
28 VisibilityTracker::VisibilityTracker (Gtk::Window& win)
29         : _window (win)
30         , _visibility (GDK_VISIBILITY_FULLY_OBSCURED)
31 {
32         _window.add_events (Gdk::VISIBILITY_NOTIFY_MASK);
33         _window.signal_visibility_notify_event().connect (sigc::mem_fun (*this, &VisibilityTracker::handle_visibility_notify_event));
34 }
35
36 void
37 VisibilityTracker::set_use_window_manager_visibility (bool yn)
38 {
39         _use_window_manager_visibility = yn;
40 }
41
42 bool
43 VisibilityTracker::handle_visibility_notify_event (GdkEventVisibility* ev)
44 {
45         _visibility = ev->state;
46         return false;
47 }
48
49 void
50 VisibilityTracker::cycle_visibility ()
51 {
52         if (fully_visible ()) {
53                 _window.hide ();
54         } else {
55                 _window.present ();
56         }
57 }
58
59 bool
60 VisibilityTracker::fully_visible () const
61 {
62         if (_use_window_manager_visibility) {
63                 return _window.is_mapped() && (_visibility == GDK_VISIBILITY_UNOBSCURED);
64         } else {
65                 return _window.is_mapped();
66         }
67 }
68
69 bool
70 VisibilityTracker::not_visible () const
71 {
72         if (_use_window_manager_visibility) {
73                 return !_window.is_mapped() || (_visibility == GDK_VISIBILITY_FULLY_OBSCURED);
74         } else {
75                 return !_window.is_mapped();
76         }
77 }
78
79 bool
80 VisibilityTracker::partially_visible () const
81 {
82         if (_use_window_manager_visibility) {
83                 return _window.is_mapped() && ((_visibility == GDK_VISIBILITY_PARTIAL) || (_visibility == GDK_VISIBILITY_UNOBSCURED));
84         } else {
85                 return _window.is_mapped();
86         }
87 }