Commit c1aabb6e authored by Adrien Plazas's avatar Adrien Plazas

main: Init public GObject types in hdy_init()

This will avoid our users to manually ensure libhandy widget types are
loaded before using them in GtkBuilder templates.

Fixes Librem5/libhandy#20
parent 95ac5c85
......@@ -5,6 +5,7 @@ subdir('xml')
private_headers = [
'config.h',
'gtkprogresstrackerprivate.h',
'hdy-main-private.h',
]
images = [
......
#!/bin/sh
set -e
echo '/* This file was generated by gen-plublic-types.sh, do not edit it. */
'
for var in "$@"
do
echo "#include \"$var\""
done
echo '#include "hdy-main-private.h"
void
hdy_init_public_types (void)
{'
sed -ne 's/^#define \+\(HDY_TYPE_[A-Z0-9_]\+\) \+.*/ g_type_ensure (\1);/p' "$@" | sort
echo '}
'
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#pragma once
#include "hdy-main.h"
#if !defined(_HANDY_INSIDE) && !defined(HANDY_COMPILATION)
#error "Only <handy.h> can be included directly."
#endif
G_BEGIN_DECLS
/* Initializes the public GObject types, which is needed to ensure they are
* discoverable, for example so they can easily be used with GtkBuilder.
*
* The function is implemented in hdy-public-types.c which is generated at
* compile time by gen-public-types.sh
*/
void hdy_init_public_types (void);
G_END_DECLS
......@@ -4,7 +4,7 @@
* SPDX-License-Identifier: LGPL-2.1+
*/
#include "config.h"
#include "hdy-main.h"
#include "hdy-main-private.h"
#include <glib/gi18n.h>
static gint hdy_initialized = FALSE;
......@@ -41,6 +41,7 @@ hdy_init (int *argc, char ***argv)
textdomain (GETTEXT_PACKAGE);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
hdy_init_public_types ();
hdy_initialized = TRUE;
......
......@@ -61,6 +61,18 @@ src_headers = [
'hdy-title-bar.h',
]
sed = find_program('sed', required: true)
gen_public_types = find_program('gen-public-types.sh', required: true)
libhandy_init_public_types = custom_target('hdy-public-types.c',
output : 'hdy-public-types.c',
input : [src_headers, libhandy_generated_headers],
command : [gen_public_types, '@INPUT@'],
capture: true,
install : true,
install_dir : 'subdir',
)
src_sources = [
'gtkprogresstracker.c',
'hdy-arrows.c',
......@@ -87,6 +99,7 @@ libhandy_sources = [
libhandy_public_sources,
libhandy_private_sources,
libhandy_resources,
libhandy_init_public_types,
]
glib_min_version = '>= 2.44'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment