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_MACOS |
33 | #include <gdk/macos/gdkmacos.h> |
34 | #endif |
35 | |
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 | |
43 | static guint do_nothing (void) { return 0; } |
44 | static gboolean return_false (void) { return FALSE; } |
45 | |
46 | static void |
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->prefers_app_menu = (gpointer) return_false; |
63 | } |
64 | |
65 | void |
66 | gtk_application_impl_startup (GtkApplicationImpl *impl, |
67 | gboolean register_session) |
68 | { |
69 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->startup (impl, register_session); |
70 | } |
71 | |
72 | void |
73 | gtk_application_impl_shutdown (GtkApplicationImpl *impl) |
74 | { |
75 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->shutdown (impl); |
76 | } |
77 | |
78 | void |
79 | gtk_application_impl_before_emit (GtkApplicationImpl *impl, |
80 | GVariant *platform_data) |
81 | { |
82 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->before_emit (impl, platform_data); |
83 | } |
84 | |
85 | void |
86 | gtk_application_impl_window_added (GtkApplicationImpl *impl, |
87 | GtkWindow *window) |
88 | { |
89 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->window_added (impl, window); |
90 | } |
91 | |
92 | void |
93 | gtk_application_impl_window_removed (GtkApplicationImpl *impl, |
94 | GtkWindow *window) |
95 | { |
96 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->window_removed (impl, window); |
97 | } |
98 | |
99 | void |
100 | gtk_application_impl_active_window_changed (GtkApplicationImpl *impl, |
101 | GtkWindow *window) |
102 | { |
103 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->active_window_changed (impl, window); |
104 | } |
105 | |
106 | void |
107 | gtk_application_impl_handle_window_realize (GtkApplicationImpl *impl, |
108 | GtkWindow *window) |
109 | { |
110 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->handle_window_realize (impl, window); |
111 | } |
112 | |
113 | void |
114 | gtk_application_impl_handle_window_map (GtkApplicationImpl *impl, |
115 | GtkWindow *window) |
116 | { |
117 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->handle_window_map (impl, window); |
118 | } |
119 | |
120 | void |
121 | (GtkApplicationImpl *impl, |
122 | GMenuModel *) |
123 | { |
124 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->set_app_menu (impl, app_menu); |
125 | } |
126 | |
127 | void |
128 | (GtkApplicationImpl *impl, |
129 | GMenuModel *) |
130 | { |
131 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->set_menubar (impl, menubar); |
132 | } |
133 | |
134 | guint |
135 | gtk_application_impl_inhibit (GtkApplicationImpl *impl, |
136 | GtkWindow *window, |
137 | GtkApplicationInhibitFlags flags, |
138 | const char *reason) |
139 | { |
140 | return GTK_APPLICATION_IMPL_GET_CLASS (impl)->inhibit (impl, window, flags, reason); |
141 | } |
142 | |
143 | void |
144 | gtk_application_impl_uninhibit (GtkApplicationImpl *impl, |
145 | guint cookie) |
146 | { |
147 | GTK_APPLICATION_IMPL_GET_CLASS (impl)->uninhibit (impl, cookie); |
148 | } |
149 | |
150 | gboolean |
151 | (GtkApplicationImpl *impl) |
152 | { |
153 | return GTK_APPLICATION_IMPL_GET_CLASS (impl)->prefers_app_menu (impl); |
154 | } |
155 | |
156 | GtkApplicationImpl * |
157 | gtk_application_impl_new (GtkApplication *application, |
158 | GdkDisplay *display) |
159 | { |
160 | GtkApplicationImpl *impl; |
161 | GType impl_type; |
162 | |
163 | impl_type = gtk_application_impl_get_type (); |
164 | |
165 | #ifdef GDK_WINDOWING_X11 |
166 | if (GDK_IS_X11_DISPLAY (display)) |
167 | impl_type = gtk_application_impl_x11_get_type (); |
168 | #endif |
169 | |
170 | #ifdef GDK_WINDOWING_WAYLAND |
171 | if (GDK_IS_WAYLAND_DISPLAY (display)) |
172 | impl_type = gtk_application_impl_wayland_get_type (); |
173 | #endif |
174 | |
175 | #ifdef GDK_WINDOWING_MACOS |
176 | if (GDK_IS_MACOS_DISPLAY (display)) |
177 | impl_type = gtk_application_impl_quartz_get_type (); |
178 | #endif |
179 | |
180 | impl = g_object_new (object_type: impl_type, NULL); |
181 | impl->application = application; |
182 | impl->display = display; |
183 | |
184 | return impl; |
185 | } |
186 | |