[libhandy] Add hdy_init() back
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] Add hdy_init() back
- Date: Wed, 24 Jun 2020 15:02:58 +0000 (UTC)
commit 7f875ea7a3ef52eaa79dd0808db8e74dd977f3cc
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sat Jun 20 09:07:12 2020 +0200
Add hdy_init() back
The library constructor and the early main loop style initialization
were causing issues with some language bindings and some applications,
so introduce hdy_init() back instead.
hdy_init() now takes no parameters as they were useless.
debian/libhandy-1-0.symbols | 1 +
debian/tests/build-test | 1 +
doc/handy-docs.xml | 1 +
doc/hdy-migrating-0-0-to-1.xml | 13 +++--
doc/meson.build | 1 -
examples/handy-demo.c | 2 +
glade/glade-hdy-utils.c | 9 +++
glade/glade-hdy-utils.h | 2 +
glade/libhandy.xml | 1 +
src/gconstructorprivate.h | 120 ----------------------------------------
src/handy.h | 1 +
src/hdy-main-private.h | 2 +-
src/hdy-main.c | 42 +++++++-------
src/hdy-main.h | 18 ++++++
src/meson.build | 1 +
tests/test-action-row.c | 1 +
tests/test-application-window.c | 1 +
tests/test-avatar.c | 1 +
tests/test-carousel.c | 1 +
tests/test-combo-row.c | 1 +
tests/test-deck.c | 1 +
tests/test-expander-row.c | 1 +
tests/test-header-bar.c | 1 +
tests/test-header-group.c | 1 +
tests/test-keypad.c | 1 +
tests/test-leaflet.c | 1 +
tests/test-preferences-group.c | 1 +
tests/test-preferences-page.c | 1 +
tests/test-preferences-row.c | 1 +
tests/test-preferences-window.c | 1 +
tests/test-search-bar.c | 1 +
tests/test-squeezer.c | 1 +
tests/test-swipe-group.c | 1 +
tests/test-value-object.c | 1 +
tests/test-view-switcher-bar.c | 1 +
tests/test-view-switcher.c | 1 +
tests/test-window-handle.c | 1 +
tests/test-window.c | 1 +
38 files changed, 91 insertions(+), 147 deletions(-)
---
diff --git a/debian/libhandy-1-0.symbols b/debian/libhandy-1-0.symbols
index 1ece9630..924c48f6 100644
--- a/debian/libhandy-1-0.symbols
+++ b/debian/libhandy-1-0.symbols
@@ -170,6 +170,7 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
hdy_header_group_new@LIBHANDY_1_0 0.0.3
hdy_header_group_remove_header_bar@LIBHANDY_1_0 0.0.4~
hdy_header_group_set_focus@LIBHANDY_1_0 0.0.3
+ hdy_init@LIBHANDY_1_0 0.82.0
hdy_init_public_types@LIBHANDY_1_0 0.0.5
hdy_keypad_button_get_digit@LIBHANDY_1_0 0.0.12
hdy_keypad_button_get_symbols@LIBHANDY_1_0 0.0.12
diff --git a/debian/tests/build-test b/debian/tests/build-test
index 17f697ff..ad5779c6 100755
--- a/debian/tests/build-test
+++ b/debian/tests/build-test
@@ -19,6 +19,7 @@ main (int argc,
char **argv)
{
gtk_init(&argc, &argv);
+ hdy_init();
hdy_keypad_new(FALSE, TRUE);
}
EOF
diff --git a/doc/handy-docs.xml b/doc/handy-docs.xml
index b31f5af8..8c3b3c66 100644
--- a/doc/handy-docs.xml
+++ b/doc/handy-docs.xml
@@ -70,6 +70,7 @@
<chapter id="helpers">
<title>Helpers</title>
<xi:include href="xml/hdy-version.xml"/>
+ <xi:include href="xml/hdy-main.xml"/>
</chapter>
<chapter id="migrating">
diff --git a/doc/hdy-migrating-0-0-to-1.xml b/doc/hdy-migrating-0-0-to-1.xml
index fc233f78..cbe3e049 100644
--- a/doc/hdy-migrating-0-0-to-1.xml
+++ b/doc/hdy-migrating-0-0-to-1.xml
@@ -71,12 +71,15 @@
</para>
<refsect3>
- <title>hdy_init has been removed</title>
+ <title>hdy_init takes no parameters</title>
<para>
- hdy_init() has been removed.
- Instead, Handy 1 comes with a library constructor which will
- automatically initialize it when linked.
- You should just remove calls to hdy_init().
+ hdy_init() has been modified to take no parameters.
+ It must be called just after initializing GTK, if you are using
+ #GtkApplication it means it must be called when the
+ #GApplication::startup signal is emitted.
+ </para>
+ <para>
+ It initializes the localization, the types, the themes, and the icons.
</para>
</refsect3>
diff --git a/doc/meson.build b/doc/meson.build
index a235180a..b3b1ce01 100644
--- a/doc/meson.build
+++ b/doc/meson.build
@@ -4,7 +4,6 @@ subdir('xml')
private_headers = [
'config.h',
- 'gconstructorprivate.h',
'gtkprogresstrackerprivate.h',
'gtk-window-private.h',
'hdy-animation-private.h',
diff --git a/examples/handy-demo.c b/examples/handy-demo.c
index 86d794c1..93721b0a 100644
--- a/examples/handy-demo.c
+++ b/examples/handy-demo.c
@@ -23,6 +23,8 @@ startup (GtkApplication *app)
{
GtkCssProvider *css_provider = gtk_css_provider_new ();
+ hdy_init ();
+
gtk_css_provider_load_from_resource (css_provider, "/sm/puri/Handy/Demo/ui/style.css");
gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
GTK_STYLE_PROVIDER (css_provider),
diff --git a/glade/glade-hdy-utils.c b/glade/glade-hdy-utils.c
index 2fca1efb..81b8ae5e 100644
--- a/glade/glade-hdy-utils.c
+++ b/glade/glade-hdy-utils.c
@@ -11,6 +11,15 @@
#include <gladeui/glade.h>
+void
+glade_hdy_init (const gchar *name)
+{
+ g_assert (strcmp (name, "libhandy") == 0);
+
+ gtk_init (NULL, NULL);
+ hdy_init ();
+}
+
/* This function has been copied and modified from:
* glade-gtk-list-box.c - GladeWidgetAdaptor for GtkListBox widget
*
diff --git a/glade/glade-hdy-utils.h b/glade/glade-hdy-utils.h
index 9aeaf6d1..4ea665ec 100644
--- a/glade/glade-hdy-utils.h
+++ b/glade/glade-hdy-utils.h
@@ -22,6 +22,8 @@
#define glade_widget_action_get_def glade_widget_action_get_class
#endif
+void glade_hdy_init (const gchar *name);
+
void glade_hdy_sync_child_positions (GtkContainer *container);
gint glade_hdy_get_child_index (GtkContainer *container,
diff --git a/glade/libhandy.xml b/glade/libhandy.xml
index 29d2d5d3..7ec174f1 100644
--- a/glade/libhandy.xml
+++ b/glade/libhandy.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<glade-catalog name="libhandy" library="glade-handy-1" depends="gtk+" book="libhandy">
+ <init-function>glade_hdy_init</init-function>
<glade-widget-classes>
<glade-widget-class name="HdyActionRow" generic-name="actionrow" title="Action Row" since="0.0.6">
<properties>
diff --git a/src/handy.h b/src/handy.h
index 15f10f93..d63469e6 100644
--- a/src/handy.h
+++ b/src/handy.h
@@ -40,6 +40,7 @@ G_BEGIN_DECLS
#include "hdy-header-group.h"
#include "hdy-keypad.h"
#include "hdy-leaflet.h"
+#include "hdy-main.h"
#include "hdy-navigation-direction.h"
#include "hdy-preferences-group.h"
#include "hdy-preferences-page.h"
diff --git a/src/hdy-main-private.h b/src/hdy-main-private.h
index 35284f27..3ad6ad1d 100644
--- a/src/hdy-main-private.h
+++ b/src/hdy-main-private.h
@@ -9,7 +9,7 @@
#error "Only <handy.h> can be included directly."
#endif
-#include <glib.h>
+#include "hdy-main.h"
G_BEGIN_DECLS
diff --git a/src/hdy-main.c b/src/hdy-main.c
index 652683f5..45b3e475 100644
--- a/src/hdy-main.c
+++ b/src/hdy-main.c
@@ -8,25 +8,20 @@
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
-#include "gconstructorprivate.h"
+
+static gint hdy_initialized = FALSE;
/**
- * PRIVATE:hdy-main
+ * SECTION:hdy-main
* @short_description: Library initialization.
* @Title: hdy-main
- * @stability: Private
*
- * Before using the Handy library you should initialize it. This makes
- * sure translations for the Handy library are set up properly.
+ * Before using the Handy library you should initialize it by calling the
+ * hdy_init() function.
+ * This makes sure translations, types, themes, and icons for the Handy library
+ * are set up properly.
*/
-#if defined (G_HAS_CONSTRUCTORS)
-
-#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
-#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(hdy_constructor)
-#endif
-G_DEFINE_CONSTRUCTOR(hdy_constructor)
-
/* A stupidly high priority used to load the styles before anything else
* happens.
*
@@ -223,13 +218,22 @@ init_theme_cb (void)
}
/**
- * hdy_constructor:
+ * hdy_init:
*
- * Automatically initializes libhandy.
+ * Call this function just after initializing GTK, if you are using
+ * #GtkApplication it means it must be called when the #GApplication::startup
+ * signal is emitted. If libhandy has already been initialized, the function
+ * will simply return.
+ *
+ * This makes sure translations, types, themes, and icons for the Handy library
+ * are set up properly.
*/
-static void
-hdy_constructor (void)
+void
+hdy_init (void)
{
+ if (hdy_initialized)
+ return;
+
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
hdy_init_public_types ();
@@ -238,8 +242,6 @@ hdy_constructor (void)
* before any window shows up but after GTK is initialized.
*/
g_idle_add_full (HDY_PRIORITY_STYLE, (GSourceFunc) init_theme_cb, NULL, NULL);
-}
-#else
-# error Your platform/compiler is missing constructor support
-#endif
+ hdy_initialized = TRUE;
+}
diff --git a/src/hdy-main.h b/src/hdy-main.h
new file mode 100644
index 00000000..5b2f3846
--- /dev/null
+++ b/src/hdy-main.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2020 Purism SPC
+ *
+ * SPDX-License-Identifier: LGPL-2.1+
+ */
+#pragma once
+
+#if !defined(_HANDY_INSIDE) && !defined(HANDY_COMPILATION)
+#error "Only <handy.h> can be included directly."
+#endif
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+void hdy_init (void);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index 7a6a93c6..1ae28d41 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -80,6 +80,7 @@ src_headers = [
'hdy-header-group.h',
'hdy-keypad.h',
'hdy-leaflet.h',
+ 'hdy-main.h',
'hdy-navigation-direction.h',
'hdy-preferences-group.h',
'hdy-preferences-page.h',
diff --git a/tests/test-action-row.c b/tests/test-action-row.c
index ce0d9a72..38c63424 100644
--- a/tests/test-action-row.c
+++ b/tests/test-action-row.c
@@ -132,6 +132,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/ActionRow/add", test_hdy_action_row_add);
g_test_add_func("/Handy/ActionRow/add_prefix", test_hdy_action_row_add_prefix);
diff --git a/tests/test-application-window.c b/tests/test-application-window.c
index e31cd250..0ffb4fa4 100644
--- a/tests/test-application-window.c
+++ b/tests/test-application-window.c
@@ -23,6 +23,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/ApplicationWindow/new", test_hdy_application_window_new);
diff --git a/tests/test-avatar.c b/tests/test-avatar.c
index bce03f75..218ab7d2 100644
--- a/tests/test-avatar.c
+++ b/tests/test-avatar.c
@@ -186,6 +186,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func ("/Handy/Avatar/generate", test_hdy_avatar_generate);
g_test_add_func ("/Handy/Avatar/custom_image", test_hdy_avatar_custom_image);
diff --git a/tests/test-carousel.c b/tests/test-carousel.c
index 90ad7168..538ca6e1 100644
--- a/tests/test-carousel.c
+++ b/tests/test-carousel.c
@@ -315,6 +315,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/Carousel/add_remove", test_hdy_carousel_add_remove);
g_test_add_func("/Handy/Carousel/scroll_to", test_hdy_carousel_scroll_to);
diff --git a/tests/test-combo-row.c b/tests/test-combo-row.c
index e24f7ea4..a92b04da 100644
--- a/tests/test-combo-row.c
+++ b/tests/test-combo-row.c
@@ -59,6 +59,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/ComboRow/set_for_enum", test_hdy_combo_row_set_for_enum);
g_test_add_func("/Handy/ComboRow/use_subtitle", test_hdy_combo_row_use_subtitle);
diff --git a/tests/test-deck.c b/tests/test-deck.c
index 935268ce..dcb2307e 100644
--- a/tests/test-deck.c
+++ b/tests/test-deck.c
@@ -85,6 +85,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func ("/Handy/Deck/adjacent_child", test_hdy_deck_adjacent_child);
g_test_add_func ("/Handy/Deck/navigate", test_hdy_deck_navigate);
diff --git a/tests/test-expander-row.c b/tests/test-expander-row.c
index 71a6c986..cb945d37 100644
--- a/tests/test-expander-row.c
+++ b/tests/test-expander-row.c
@@ -155,6 +155,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/ExpanderRow/add", test_hdy_expander_row_add);
g_test_add_func("/Handy/ExpanderRow/title", test_hdy_expander_row_title);
diff --git a/tests/test-header-bar.c b/tests/test-header-bar.c
index 7798e411..d20dbaf6 100644
--- a/tests/test-header-bar.c
+++ b/tests/test-header-bar.c
@@ -199,6 +199,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/HeaderBar/pack", test_hdy_header_bar_pack);
g_test_add_func("/Handy/HeaderBar/title", test_hdy_header_bar_title);
diff --git a/tests/test-header-group.c b/tests/test-header-group.c
index 944fe966..07b7bb0a 100644
--- a/tests/test-header-group.c
+++ b/tests/test-header-group.c
@@ -69,6 +69,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/HeaderGroup/focus", test_hdy_header_group_focus);
g_test_add_func("/Handy/HeaderGroup/add_remove", test_hdy_header_group_add_remove);
diff --git a/tests/test-keypad.c b/tests/test-keypad.c
index e617c40b..58b4dee9 100644
--- a/tests/test-keypad.c
+++ b/tests/test-keypad.c
@@ -100,6 +100,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func ("/Handy/Keypad/show_symbols", test_hdy_keypad_show_symbols);
g_test_add_func ("/Handy/Keypad/set_actions", test_hdy_keypad_set_actions);
diff --git a/tests/test-leaflet.c b/tests/test-leaflet.c
index ac7faf5a..48f8c21f 100644
--- a/tests/test-leaflet.c
+++ b/tests/test-leaflet.c
@@ -101,6 +101,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func ("/Handy/Leaflet/adjacent_child", test_hdy_leaflet_adjacent_child);
g_test_add_func ("/Handy/Leaflet/navigate", test_hdy_leaflet_navigate);
diff --git a/tests/test-preferences-group.c b/tests/test-preferences-group.c
index 8ac47a8d..0cf987d8 100644
--- a/tests/test-preferences-group.c
+++ b/tests/test-preferences-group.c
@@ -72,6 +72,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/PreferencesGroup/add", test_hdy_preferences_group_add);
g_test_add_func("/Handy/PreferencesGroup/title", test_hdy_preferences_group_title);
diff --git a/tests/test-preferences-page.c b/tests/test-preferences-page.c
index 0c76c93b..52724dc4 100644
--- a/tests/test-preferences-page.c
+++ b/tests/test-preferences-page.c
@@ -71,6 +71,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/PreferencesPage/add", test_hdy_preferences_page_add);
g_test_add_func("/Handy/PreferencesPage/title", test_hdy_preferences_page_title);
diff --git a/tests/test-preferences-row.c b/tests/test-preferences-row.c
index 7b62581d..5815c404 100644
--- a/tests/test-preferences-row.c
+++ b/tests/test-preferences-row.c
@@ -49,6 +49,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/PreferencesRow/title", test_hdy_preferences_row_title);
g_test_add_func("/Handy/PreferencesRow/use_underline", test_hdy_preferences_row_use_undeline);
diff --git a/tests/test-preferences-window.c b/tests/test-preferences-window.c
index b5be41c8..f60e9437 100644
--- a/tests/test-preferences-window.c
+++ b/tests/test-preferences-window.c
@@ -35,6 +35,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/PreferencesWindow/add", test_hdy_preferences_window_add);
diff --git a/tests/test-search-bar.c b/tests/test-search-bar.c
index e1be3785..3bc85391 100644
--- a/tests/test-search-bar.c
+++ b/tests/test-search-bar.c
@@ -86,6 +86,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/SearchBar/add", test_hdy_search_bar_add);
g_test_add_func("/Handy/SearchBar/connect_entry", test_hdy_search_bar_connect_entry);
diff --git a/tests/test-squeezer.c b/tests/test-squeezer.c
index d0ec864a..bddb6fb2 100644
--- a/tests/test-squeezer.c
+++ b/tests/test-squeezer.c
@@ -148,6 +148,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/ViewSwitcher/homogeneous", test_hdy_squeezer_homogeneous);
g_test_add_func("/Handy/ViewSwitcher/transition_duration", test_hdy_squeezer_transition_duration);
diff --git a/tests/test-swipe-group.c b/tests/test-swipe-group.c
index 627be532..6e63deb4 100644
--- a/tests/test-swipe-group.c
+++ b/tests/test-swipe-group.c
@@ -39,6 +39,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/SwipeGroup/add_remove", test_hdy_swipe_group_add_remove);
return g_test_run();
diff --git a/tests/test-value-object.c b/tests/test-value-object.c
index 34115258..46cee42f 100644
--- a/tests/test-value-object.c
+++ b/tests/test-value-object.c
@@ -47,6 +47,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/ValueObject/init", test_hdy_value_object_init);
diff --git a/tests/test-view-switcher-bar.c b/tests/test-view-switcher-bar.c
index 7e1eb260..00cc1cb9 100644
--- a/tests/test-view-switcher-bar.c
+++ b/tests/test-view-switcher-bar.c
@@ -92,6 +92,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/ViewSwitcherBar/policy", test_hdy_view_switcher_bar_policy);
g_test_add_func("/Handy/ViewSwitcherBar/icon_size", test_hdy_view_switcher_bar_icon_size);
diff --git a/tests/test-view-switcher.c b/tests/test-view-switcher.c
index 892e6716..caa95ad0 100644
--- a/tests/test-view-switcher.c
+++ b/tests/test-view-switcher.c
@@ -92,6 +92,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/ViewSwitcher/policy", test_hdy_view_switcher_policy);
g_test_add_func("/Handy/ViewSwitcher/icon_size", test_hdy_view_switcher_icon_size);
diff --git a/tests/test-window-handle.c b/tests/test-window-handle.c
index 02a25826..2bdada7d 100644
--- a/tests/test-window-handle.c
+++ b/tests/test-window-handle.c
@@ -23,6 +23,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/WindowHandle/new", test_hdy_window_handle_new);
diff --git a/tests/test-window.c b/tests/test-window.c
index 19c46ead..e2105394 100644
--- a/tests/test-window.c
+++ b/tests/test-window.c
@@ -23,6 +23,7 @@ main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
+ hdy_init ();
g_test_add_func("/Handy/Window/new", test_hdy_window_new);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]