1 /*
2  * Copyright © 2013 Canonical Limited
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the licence, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Author: Ryan Lortie <desrt@desrt.ca>
18  */
19 
20 #include "config.h"
21 
22 #include "gtkapplicationprivate.h"
23 
24 #ifdef GDK_WINDOWING_X11
25 #include <gdk/x11/gdkx.h>
26 #endif
27 
28 #ifdef GDK_WINDOWING_WAYLAND
29 #include <gdk/wayland/gdkwayland.h>
30 #endif
31 
32 #ifdef GDK_WINDOWING_QUARTZ
33 #include <gdk/quartz/gdkquartz.h>
34 #endif
35 
G_DEFINE_TYPE(GtkApplicationImpl,gtk_application_impl,G_TYPE_OBJECT)36 G_DEFINE_TYPE (GtkApplicationImpl, gtk_application_impl, G_TYPE_OBJECT)
37 
38 static void
39 gtk_application_impl_init (GtkApplicationImpl *impl)
40 {
41 }
42 
do_nothing(void)43 static guint do_nothing (void) { return 0; }
return_false(void)44 static gboolean return_false (void) { return FALSE; }
45 
46 static void
gtk_application_impl_class_init(GtkApplicationImplClass * class)47 gtk_application_impl_class_init (GtkApplicationImplClass *class)
48 {
49   /* NB: can only 'do_nothing' for functions with integer or void return */
50   class->startup = (gpointer) do_nothing;
51   class->shutdown = (gpointer) do_nothing;
52   class->before_emit = (gpointer) do_nothing;
53   class->window_added = (gpointer) do_nothing;
54   class->window_removed = (gpointer) do_nothing;
55   class->active_window_changed = (gpointer) do_nothing;
56   class->handle_window_realize = (gpointer) do_nothing;
57   class->handle_window_map = (gpointer) do_nothing;
58   class->set_app_menu = (gpointer) do_nothing;
59   class->set_menubar = (gpointer) do_nothing;
60   class->inhibit = (gpointer) do_nothing;
61   class->uninhibit = (gpointer) do_nothing;
62   class->is_inhibited = (gpointer) do_nothing;
63   class->prefers_app_menu = (gpointer) return_false;
64 }
65 
66 void
gtk_application_impl_startup(GtkApplicationImpl * impl,gboolean register_session)67 gtk_application_impl_startup (GtkApplicationImpl *impl,
68                               gboolean            register_session)
69 {
70   GTK_APPLICATION_IMPL_GET_CLASS (impl)->startup (impl, register_session);
71 }
72 
73 void
gtk_application_impl_shutdown(GtkApplicationImpl * impl)74 gtk_application_impl_shutdown (GtkApplicationImpl *impl)
75 {
76   GTK_APPLICATION_IMPL_GET_CLASS (impl)->shutdown (impl);
77 }
78 
79 void
gtk_application_impl_before_emit(GtkApplicationImpl * impl,GVariant * platform_data)80 gtk_application_impl_before_emit (GtkApplicationImpl *impl,
81                                   GVariant           *platform_data)
82 {
83   GTK_APPLICATION_IMPL_GET_CLASS (impl)->before_emit (impl, platform_data);
84 }
85 
86 void
gtk_application_impl_window_added(GtkApplicationImpl * impl,GtkWindow * window)87 gtk_application_impl_window_added (GtkApplicationImpl *impl,
88                                    GtkWindow          *window)
89 {
90   GTK_APPLICATION_IMPL_GET_CLASS (impl)->window_added (impl, window);
91 }
92 
93 void
gtk_application_impl_window_removed(GtkApplicationImpl * impl,GtkWindow * window)94 gtk_application_impl_window_removed (GtkApplicationImpl *impl,
95                                      GtkWindow          *window)
96 {
97   GTK_APPLICATION_IMPL_GET_CLASS (impl)->window_removed (impl, window);
98 }
99 
100 void
gtk_application_impl_active_window_changed(GtkApplicationImpl * impl,GtkWindow * window)101 gtk_application_impl_active_window_changed (GtkApplicationImpl *impl,
102                                             GtkWindow          *window)
103 {
104   GTK_APPLICATION_IMPL_GET_CLASS (impl)->active_window_changed (impl, window);
105 }
106 
107 void
gtk_application_impl_handle_window_realize(GtkApplicationImpl * impl,GtkWindow * window)108 gtk_application_impl_handle_window_realize (GtkApplicationImpl *impl,
109                                             GtkWindow          *window)
110 {
111   GTK_APPLICATION_IMPL_GET_CLASS (impl)->handle_window_realize (impl, window);
112 }
113 
114 void
gtk_application_impl_handle_window_map(GtkApplicationImpl * impl,GtkWindow * window)115 gtk_application_impl_handle_window_map (GtkApplicationImpl *impl,
116                                         GtkWindow          *window)
117 {
118   GTK_APPLICATION_IMPL_GET_CLASS (impl)->handle_window_map (impl, window);
119 }
120 
121 void
gtk_application_impl_set_app_menu(GtkApplicationImpl * impl,GMenuModel * app_menu)122 gtk_application_impl_set_app_menu (GtkApplicationImpl *impl,
123                                    GMenuModel         *app_menu)
124 {
125   GTK_APPLICATION_IMPL_GET_CLASS (impl)->set_app_menu (impl, app_menu);
126 }
127 
128 void
gtk_application_impl_set_menubar(GtkApplicationImpl * impl,GMenuModel * menubar)129 gtk_application_impl_set_menubar (GtkApplicationImpl *impl,
130                                   GMenuModel         *menubar)
131 {
132   GTK_APPLICATION_IMPL_GET_CLASS (impl)->set_menubar (impl, menubar);
133 }
134 
135 guint
gtk_application_impl_inhibit(GtkApplicationImpl * impl,GtkWindow * window,GtkApplicationInhibitFlags flags,const gchar * reason)136 gtk_application_impl_inhibit (GtkApplicationImpl         *impl,
137                               GtkWindow                  *window,
138                               GtkApplicationInhibitFlags  flags,
139                               const gchar                *reason)
140 {
141   return GTK_APPLICATION_IMPL_GET_CLASS (impl)->inhibit (impl, window, flags, reason);
142 }
143 
144 void
gtk_application_impl_uninhibit(GtkApplicationImpl * impl,guint cookie)145 gtk_application_impl_uninhibit (GtkApplicationImpl *impl,
146                                 guint               cookie)
147 {
148   GTK_APPLICATION_IMPL_GET_CLASS (impl)->uninhibit (impl, cookie);
149 }
150 
151 gboolean
gtk_application_impl_is_inhibited(GtkApplicationImpl * impl,GtkApplicationInhibitFlags flags)152 gtk_application_impl_is_inhibited (GtkApplicationImpl         *impl,
153                                    GtkApplicationInhibitFlags  flags)
154 {
155   return GTK_APPLICATION_IMPL_GET_CLASS (impl)->is_inhibited (impl, flags);
156 }
157 
158 gboolean
gtk_application_impl_prefers_app_menu(GtkApplicationImpl * impl)159 gtk_application_impl_prefers_app_menu (GtkApplicationImpl *impl)
160 {
161   return GTK_APPLICATION_IMPL_GET_CLASS (impl)->prefers_app_menu (impl);
162 }
163 
164 GtkApplicationImpl *
gtk_application_impl_new(GtkApplication * application,GdkDisplay * display)165 gtk_application_impl_new (GtkApplication *application,
166                           GdkDisplay     *display)
167 {
168   GtkApplicationImpl *impl;
169   GType impl_type;
170 
171   impl_type = gtk_application_impl_get_type ();
172 
173 #ifdef GDK_WINDOWING_X11
174   if (GDK_IS_X11_DISPLAY (display))
175     impl_type = gtk_application_impl_x11_get_type ();
176 #endif
177 
178 #ifdef GDK_WINDOWING_WAYLAND
179   if (GDK_IS_WAYLAND_DISPLAY (display))
180     impl_type = gtk_application_impl_wayland_get_type ();
181 #endif
182 
183 #ifdef GDK_WINDOWING_QUARTZ
184   if (GDK_IS_QUARTZ_DISPLAY (display))
185     impl_type = gtk_application_impl_quartz_get_type ();
186 #endif
187 
188   impl = g_object_new (impl_type, NULL);
189   impl->application = application;
190   impl->display = display;
191 
192   return impl;
193 }
194