Make GTK UI resources more consistent

The GTK UI resources have to be different resources between major versions.

When kept in one directory with slightly different filenames they were
  difficult to distinguish and resource definition was difficult to update.

The resources for both gtk versions were stored in both builds resulting in
  unneccessary increased binary size.

The new stratagy lists the UI files once in a single gresources file and only
  includes what is required. If a UI file is added it must be provided in both
  gtk2 and 3 or a build failure will occour rather than a runtime error.
This commit is contained in:
Vincent Sanders 2020-09-04 08:26:04 +01:00
parent 50f5e3f1a6
commit b0b271274c
30 changed files with 28 additions and 33 deletions

View File

@ -103,6 +103,7 @@ GLIB_COMPILE_RESOURCES := glib-compile-resources
CFLAGS += -DWITH_GRESOURCE
NETSURF_GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/netsurf.gresource.xml
UI_GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/ui.gresource.xml
MESSAGES_GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/messages.gresource.xml
# generate the netsurf gresource source files
@ -112,6 +113,13 @@ $(OBJROOT)/netsurf_gresource.c: $(NETSURF_GRESOURCE_XML) $(shell $(GLIB_COMPILE_
S_RESOURCE += $(OBJROOT)/netsurf_gresource.c
# generate the ui gresource source files
$(OBJROOT)/ui_gresource.c: $(UI_GRESOURCE_XML) $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir $(NSGTK_RESOURCES_DIR)/gtk$(NETSURF_GTK_MAJOR) --generate-dependencies $(UI_GRESOURCE_XML))
$(VQ)echo "GRESORCE: $<"
$(Q)$(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir $(NSGTK_RESOURCES_DIR)/gtk$(NETSURF_GTK_MAJOR) --target=$@ $<
S_RESOURCE += $(OBJROOT)/ui_gresource.c
# generate the messages gresource source file
$(OBJROOT)/messages_gresource.c: $(MESSAGES_GRESOURCE_XML) $(addsuffix /Messages,$(addprefix $(MESSAGES_TARGET)/,$(MESSAGES_LANGUAGES)))
$(VQ)echo "GRESORCE: $<"
@ -182,7 +190,7 @@ GTK_RESOURCES_LIST := \
GTK_RESOURCES_LIST := \
$(addprefix $(NSGTK_RESOURCES_DIR)/, $(GTK_RESOURCES_LIST)) \
$(wildcard $(NSGTK_RESOURCES_DIR)/*.gtk$(NETSURF_GTK_MAJOR).ui)
$(wildcard $(NSGTK_RESOURCES_DIR)/gtk$(NETSURF_GTK_MAJOR)/*.ui)
# translations with more than just Messages files
GTK_TRANSLATIONS_HTML := de en fr it ja nl zh_CN

View File

@ -1,32 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/netsurf">
<file>cookies.gtk2.ui</file>
<file>cookies.gtk3.ui</file>
<file>downloads.gtk2.ui</file>
<file>downloads.gtk3.ui</file>
<file>globalhistory.gtk2.ui</file>
<file>globalhistory.gtk3.ui</file>
<file>hotlist.gtk2.ui</file>
<file>hotlist.gtk3.ui</file>
<file>localhistory.gtk2.ui</file>
<file>localhistory.gtk3.ui</file>
<file>netsurf.gtk2.ui</file>
<file>netsurf.gtk3.ui</file>
<file>options.gtk2.ui</file>
<file>options.gtk3.ui</file>
<file>pageinfo.gtk2.ui</file>
<file>pageinfo.gtk3.ui</file>
<file>password.gtk2.ui</file>
<file>password.gtk3.ui</file>
<file>tabcontents.gtk2.ui</file>
<file>tabcontents.gtk3.ui</file>
<file>toolbar.gtk2.ui</file>
<file>toolbar.gtk3.ui</file>
<file>viewdata.gtk2.ui</file>
<file>viewdata.gtk3.ui</file>
<file>warning.gtk3.ui</file>
<file>warning.gtk2.ui</file>
<file preprocess="to-pixdata">favicon.png</file>
<file preprocess="to-pixdata">netsurf.xpm</file>
<file preprocess="to-pixdata">menu_cursor.png</file>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/netsurf">
<file>cookies.ui</file>
<file>downloads.ui</file>
<file>globalhistory.ui</file>
<file>hotlist.ui</file>
<file>localhistory.ui</file>
<file>netsurf.ui</file>
<file>options.ui</file>
<file>pageinfo.ui</file>
<file>password.ui</file>
<file>tabcontents.ui</file>
<file>toolbar.ui</file>
<file>viewdata.ui</file>
<file>warning.ui</file>
</gresource>
</gresources>

View File

@ -345,11 +345,6 @@ init_pixbuf_resource(char **respath, struct nsgtk_resource_s *resource)
*/
static nserror init_ui_resource(char **respath, struct nsgtk_resource_s *ui_res)
{
#if GTK_CHECK_VERSION(3,0,0)
int gtkv = 3;
#else
int gtkv = 2;
#endif
int resnamelen;
char *resname;
struct nsgtk_resource_s resource;
@ -361,7 +356,7 @@ static nserror init_ui_resource(char **respath, struct nsgtk_resource_s *ui_res)
if (resname == NULL) {
return NSERROR_NOMEM;
}
snprintf(resname, resnamelen, "%s.gtk%d.ui", ui_res->name, gtkv);
snprintf(resname, resnamelen, "%s.ui", ui_res->name);
resource.name = resname;
resource.len = ui_res->len;
resource.path = NULL;