Commit a5aa3e9262e858debf7e08a1c1bf22e68c15fa5b
1 parent
5a112412
Exists in
master
and in
2 other branches
Migrating from GtkApplication to GtkOSXApplication.
Showing
5 changed files
with
179 additions
and
50 deletions
Show diff stats
configure.ac
... | ... | @@ -234,7 +234,19 @@ dnl --------------------------------------------------------------------------- |
234 | 234 | |
235 | 235 | GLIB_GSETTINGS |
236 | 236 | |
237 | -PKG_CHECK_MODULES( [GTK], [gtk+-3.0 glib-2.0 gmodule-2.0], AC_DEFINE(HAVE_GTK), AC_MSG_ERROR([GTK not present.])) | |
237 | +case "$host" in | |
238 | + *-mingw32|*-pc-msys) | |
239 | + PKG_CHECK_MODULES( [GTK], [gtk+-3.0 glib-2.0 gmodule-2.0], AC_DEFINE(HAVE_GTK), AC_MSG_ERROR([GTK not present.])) | |
240 | + ;; | |
241 | + | |
242 | + *-apple-darwin*) | |
243 | + PKG_CHECK_MODULES( [GTK], [gtk+-3.0 glib-2.0 gmodule-2.0 gtk-mac-integration-gtk3], AC_DEFINE(HAVE_GTK), AC_MSG_ERROR([GTK not present.])) | |
244 | + ;; | |
245 | + | |
246 | + *) | |
247 | + PKG_CHECK_MODULES( [GTK], [gtk+-3.0 glib-2.0 gmodule-2.0], AC_DEFINE(HAVE_GTK), AC_MSG_ERROR([GTK not present.])) | |
248 | + | |
249 | +esac | |
238 | 250 | |
239 | 251 | AC_SUBST(GTK_LIBS) |
240 | 252 | AC_SUBST(GTK_CFLAGS) | ... | ... |
src/objects/application/application.c
... | ... | @@ -34,26 +34,15 @@ enum { |
34 | 34 | |
35 | 35 | static GParamSpec * props[NUM_PROPERTIES]; |
36 | 36 | |
37 | -struct _pw3270ApplicationClass { | |
38 | - GtkApplicationClass parent_class; | |
39 | -}; | |
40 | - | |
41 | -struct _pw3270Application { | |
42 | - GtkApplication parent; | |
43 | - | |
44 | - GSettings * settings; | |
45 | - GList * keypads; | |
46 | - gchar * logfile; | |
47 | - GSList * plugins; ///< @brief Handlers of the loaded plugins. | |
48 | - PW3270_UI_STYLE ui_style; | |
49 | - | |
50 | -}; | |
51 | - | |
52 | 37 | static void startup(GApplication * application); |
53 | 38 | static void activate(GApplication * application); |
54 | 39 | static void finalize(GObject *object); |
55 | 40 | |
56 | -G_DEFINE_TYPE(pw3270Application, pw3270Application, GTK_TYPE_APPLICATION); | |
41 | +#ifdef __APPLE__ | |
42 | + G_DEFINE_TYPE(pw3270Application, pw3270Application, GTKOSX_TYPE_APPLICATION); | |
43 | +#else | |
44 | + G_DEFINE_TYPE(pw3270Application, pw3270Application, GTK_TYPE_APPLICATION); | |
45 | +#endif // __APPLE__ | |
57 | 46 | |
58 | 47 | static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) { |
59 | 48 | |
... | ... | @@ -270,41 +259,62 @@ static void pw3270Application_init(pw3270Application *app) { |
270 | 259 | |
271 | 260 | g_application_add_main_option_entries(G_APPLICATION(app), cmd_options); |
272 | 261 | |
273 | -#ifdef _WIN32 | |
262 | + app->settings = pw3270_application_settings_new(); | |
263 | + | |
264 | +#if defined(_WIN32) | |
265 | + // | |
266 | + // Setup windows UI | |
267 | + // | |
274 | 268 | app->ui_style = PW3270_UI_STYLE_CLASSICAL; |
269 | + { | |
270 | + // https://stackoverflow.com/questions/37035936/how-to-get-native-windows-decorations-on-gtk3-on-windows-7-and-msys2 | |
271 | + int gtk_csd = g_settings_get_int(app->settings,"gtk-csd"); | |
272 | + if(gtk_csd != -1) { | |
273 | + g_autofree gchar * env = g_strdup_printf("GTK_CSD=%d",gtk_csd); | |
274 | + putenv(env); | |
275 | + } | |
276 | + } | |
277 | + | |
278 | + if(app->settings) { | |
279 | + g_object_ref_sink(G_OBJECT(app->settings)); | |
280 | + g_settings_bind(app->settings, "ui-style", app, "ui-style", G_SETTINGS_BIND_DEFAULT); | |
281 | + } | |
282 | + | |
283 | + { | |
284 | + lib3270_autoptr(char) plugin_path = lib3270_build_data_filename("plugins",NULL); | |
285 | + pw3270_load_plugins_from_path(app, plugin_path); | |
286 | + } | |
287 | + | |
288 | +#elif defined(__APPLE__) | |
289 | + // | |
290 | + // Setup Apple UI | |
291 | + // | |
292 | + { | |
293 | + lib3270_autoptr(char) plugin_path = lib3270_build_data_filename("plugins",NULL); | |
294 | + pw3270_load_plugins_from_path(app, plugin_path); | |
295 | + } | |
296 | + | |
275 | 297 | #else |
298 | + // | |
299 | + // Setup linux UI | |
300 | + // | |
276 | 301 | app->ui_style = PW3270_UI_STYLE_AUTOMATIC; |
277 | -#endif // _WIN32 | |
278 | - | |
279 | - // Get settings | |
280 | 302 | app->settings = pw3270_application_settings_new(); |
281 | - | |
282 | - // Bind properties | |
283 | 303 | if(app->settings) { |
284 | - | |
285 | 304 | g_object_ref_sink(G_OBJECT(app->settings)); |
305 | + g_settings_bind(app->settings, "ui-style", app, "ui-style", G_SETTINGS_BIND_DEFAULT); | |
306 | + } | |
307 | + | |
308 | + pw3270_load_plugins_from_path(app, G_STRINGIFY(LIBDIR) G_DIR_SEPARATOR_S G_STRINGIFY(PRODUCT_NAME) "-plugins"); | |
286 | 309 | |
287 | -#ifdef _WIN32 | |
288 | - { | |
289 | - // https://stackoverflow.com/questions/37035936/how-to-get-native-windows-decorations-on-gtk3-on-windows-7-and-msys2 | |
290 | - int gtk_csd = g_settings_get_int(app->settings,"gtk-csd"); | |
291 | - if(gtk_csd != -1) { | |
292 | - g_autofree gchar * env = g_strdup_printf("GTK_CSD=%d",gtk_csd); | |
293 | - putenv(env); | |
294 | - } | |
295 | - } | |
296 | 310 | #endif // _WIN32 |
297 | 311 | |
298 | - g_settings_bind(app->settings, "ui-style", app, "ui-style", G_SETTINGS_BIND_DEFAULT); | |
299 | - } | |
312 | + /* | |
313 | + | |
314 | + FIX-ME: Move to other place. | |
300 | 315 | |
301 | 316 | // Get plugins. |
302 | 317 | { |
303 | -#ifdef _WIN32 | |
304 | - lib3270_autoptr(char) path = lib3270_build_data_filename("plugins",NULL); | |
305 | -#else | |
306 | - const gchar * path = G_STRINGIFY(LIBDIR) G_DIR_SEPARATOR_S G_STRINGIFY(PRODUCT_NAME) "-plugins"; | |
307 | -#endif // _WIN32 | |
308 | 318 | |
309 | 319 | if(g_file_test(path,G_FILE_TEST_IS_DIR)) { |
310 | 320 | |
... | ... | @@ -353,17 +363,19 @@ static void pw3270Application_init(pw3270Application *app) { |
353 | 363 | |
354 | 364 | } |
355 | 365 | |
356 | - // Initialize plugins | |
357 | - { | |
358 | - GSList * item; | |
359 | - void (*call)(GtkApplication *application); | |
360 | 366 | |
361 | - for(item = app->plugins; item; item = g_slist_next(item)) { | |
362 | - if(g_module_symbol((GModule *) item->data, "pw3270_plugin_set_application", (gpointer *) &call)) { | |
363 | - call(GTK_APPLICATION(app)); | |
364 | - } | |
365 | - } | |
367 | + } | |
368 | + */ | |
369 | + | |
370 | + // Initialize plugins | |
371 | + { | |
372 | + GSList * item; | |
373 | + void (*call)(GtkApplication *application); | |
366 | 374 | |
375 | + for(item = app->plugins; item; item = g_slist_next(item)) { | |
376 | + if(g_module_symbol((GModule *) item->data, "pw3270_plugin_set_application", (gpointer *) &call)) { | |
377 | + call(GTK_APPLICATION(app)); | |
378 | + } | |
367 | 379 | } |
368 | 380 | |
369 | 381 | } |
... | ... | @@ -537,6 +549,7 @@ void activate(GApplication *application) { |
537 | 549 | |
538 | 550 | void pw3270_application_set_ui_style(GApplication *app, PW3270_UI_STYLE type) { |
539 | 551 | |
552 | +#ifndef __APPLE__ | |
540 | 553 | g_return_if_fail(PW3270_IS_APPLICATION(app)); |
541 | 554 | |
542 | 555 | pw3270Application * application = PW3270_APPLICATION(app); |
... | ... | @@ -547,12 +560,18 @@ void pw3270_application_set_ui_style(GApplication *app, PW3270_UI_STYLE type) { |
547 | 560 | application->ui_style = type; |
548 | 561 | g_object_notify_by_pspec(G_OBJECT(app), props[PROP_UI_STYLE]); |
549 | 562 | |
563 | +#endif // !__APPLE | |
564 | + | |
550 | 565 | } |
551 | 566 | |
552 | 567 | PW3270_UI_STYLE pw3270_application_get_ui_style(GApplication *app) { |
553 | 568 | |
569 | +#ifdef __APPLE__ | |
570 | + return PW3270_UI_STYLE_GNOME; | |
571 | +#else | |
554 | 572 | g_return_val_if_fail(PW3270_IS_APPLICATION(app),PW3270_UI_STYLE_CLASSICAL); |
555 | 573 | return PW3270_APPLICATION(app)->ui_style; |
574 | +#endif // __APPLE__ | |
556 | 575 | |
557 | 576 | } |
558 | 577 | ... | ... |
... | ... | @@ -0,0 +1,70 @@ |
1 | +/* SPDX-License-Identifier: LGPL-3.0-or-later */ | |
2 | + | |
3 | +/* | |
4 | + * Copyright (C) 2008 Banco do Brasil S.A. | |
5 | + * | |
6 | + * This program is free software: you can redistribute it and/or modify | |
7 | + * it under the terms of the GNU Lesser General Public License as published | |
8 | + * by the Free Software Foundation, either version 3 of the License, or | |
9 | + * (at your option) any later version. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License | |
17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
18 | + */ | |
19 | + | |
20 | +#include "private.h" | |
21 | + | |
22 | +void pw3270_load_plugins_from_path(pw3270Application *app, const char *path) { | |
23 | + | |
24 | + if(g_file_test(path,G_FILE_TEST_IS_DIR)) { | |
25 | + | |
26 | + g_message("Loading plugins from %s",path); | |
27 | + | |
28 | + GError * err = NULL; | |
29 | + GDir * dir = g_dir_open(path,0,&err); | |
30 | + | |
31 | + if(dir) { | |
32 | + | |
33 | + const gchar *name; | |
34 | + while((name = g_dir_read_name(dir)) != NULL) { | |
35 | + | |
36 | + g_autofree gchar *filename = g_build_filename(path,name,NULL); | |
37 | + | |
38 | + if(g_str_has_suffix(filename,G_MODULE_SUFFIX)) { | |
39 | + | |
40 | + g_message("Loading %s",filename); | |
41 | + | |
42 | + GModule *handle = g_module_open(filename,G_MODULE_BIND_LOCAL); | |
43 | + | |
44 | + if(handle) { | |
45 | + | |
46 | + app->plugins = g_slist_append(app->plugins,handle); | |
47 | + | |
48 | + } else { | |
49 | + | |
50 | + g_warning("Can't load %s: %s",filename,g_module_error()); | |
51 | + | |
52 | + } | |
53 | + | |
54 | + } | |
55 | + | |
56 | + } | |
57 | + | |
58 | + g_dir_close(dir); | |
59 | + } | |
60 | + | |
61 | + if(err) { | |
62 | + | |
63 | + g_warning("Can't load plugins from %s: %s",path,err->message); | |
64 | + g_error_free(err); | |
65 | + | |
66 | + } | |
67 | + | |
68 | + } | |
69 | + | |
70 | +} | ... | ... |
src/objects/application/private.h
... | ... | @@ -46,10 +46,36 @@ |
46 | 46 | #include <lib3270.h> |
47 | 47 | #include <lib3270/log.h> |
48 | 48 | |
49 | +#ifdef __APPLE__ | |
50 | + #include <gtkosxapplication.h> | |
51 | +#endif // __APPLE__ | |
52 | + | |
53 | +typedef struct _pw3270Application { | |
54 | +#ifdef __APPLE__ | |
55 | + GtkosxApplication parent; | |
56 | +#else | |
57 | + GtkApplication parent; | |
58 | + PW3270_UI_STYLE ui_style; | |
59 | +#endif // __APPLE__ | |
60 | + | |
61 | + GSettings * settings; | |
62 | + GList * keypads; | |
63 | + gchar * logfile; | |
64 | + GSList * plugins; ///< @brief Handlers of the loaded plugins. | |
65 | + | |
66 | +} pw3270Application; | |
67 | + | |
68 | +struct _pw3270ApplicationClass { | |
69 | + GtkApplicationClass parent_class; | |
70 | +}; | |
71 | + | |
72 | + | |
49 | 73 | G_GNUC_INTERNAL void pw3270_application_open(GApplication * application, GFile **files, gint n_files, const gchar *hint); |
50 | 74 | |
51 | 75 | G_GNUC_INTERNAL GtkWidget * pw3270_terminal_new(const gchar *session_file); |
52 | 76 | |
77 | +G_GNUC_INTERNAL void pw3270_load_plugins_from_path(pw3270Application *app, const char *path); | |
78 | + | |
53 | 79 | // Actions |
54 | 80 | G_GNUC_INTERNAL GAction * pw3270_about_action_new(); |
55 | 81 | G_GNUC_INTERNAL GAction * pw3270_preferences_action_new(); | ... | ... |
src/objects/window/window.c
... | ... | @@ -531,7 +531,9 @@ static void pw3270ApplicationWindow_init(pw3270ApplicationWindow *widget) { |
531 | 531 | // |
532 | 532 | // Bind properties |
533 | 533 | // |
534 | -#ifndef __APPLE__ | |
534 | +#ifdef __APPLE__ | |
535 | + gtk_application_window_set_show_menubar(GTK_APPLICATION_WINDOW(widget),TRUE); | |
536 | +#else | |
535 | 537 | g_action_map_add_action( |
536 | 538 | G_ACTION_MAP(widget), |
537 | 539 | G_ACTION(g_property_action_new("menubar", widget, "show-menubar")) | ... | ... |