diff --git a/gtk/Makefile.target b/gtk/Makefile.target index c31cca459..bbe5d5f54 100644 --- a/gtk/Makefile.target +++ b/gtk/Makefile.target @@ -95,6 +95,7 @@ S_RESOURCE := NETSURF_GRESOURCE_AVAILABLE := $(shell $(PKG_CONFIG) --atleast-version=2.32 gmodule-2.0 && echo yes) ifeq ($(NETSURF_GRESOURCE_AVAILABLE),yes) +#resource compiler tool GLIB_COMPILE_RESOURCES := glib-compile-resources CFLAGS += -DWITH_GRESOURCE @@ -107,11 +108,10 @@ GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/netsurf.gresource.xml $(OBJROOT)/netsurf_gresource.c: $(GRESOURCE_XML) $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir $(NSGTK_RESOURCES_DIR) --generate-dependencies $(GRESOURCE_XML)) $(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir $(NSGTK_RESOURCES_DIR) --target=$@ $< -endif +else +# No GResource available so build pixbufs as inlines instead -# ---------------------------------------------------------------------------- -# Builtin Pixbuf resources -# ---------------------------------------------------------------------------- +CFLAGS += -DWITH_BUILTIN_PIXBUF GTK_IMAGE_menu_cursor := gtk/res/menu_cursor.png @@ -130,13 +130,14 @@ $(2): $(1) endef +$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata))) + +endif + # ---------------------------------------------------------------------------- # Source file setup # ---------------------------------------------------------------------------- - -$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata))) - # S_GTK are sources purely for the GTK build S_GTK := font_pango.c bitmap.c gui.c schedule.c plotters.c \ treeview.c scaffolding.c gdk.c completion.c login.c throbber.c \ diff --git a/gtk/resources.c b/gtk/resources.c index 981131d33..e3e044e00 100644 --- a/gtk/resources.c +++ b/gtk/resources.c @@ -36,15 +36,18 @@ #include "gtk/compat.h" #include "gtk/resources.h" +#ifdef WITH_BUILTIN_PIXBUF #ifdef __GNUC__ extern const guint8 menu_cursor_pixdata[] __attribute__ ((__aligned__ (4))); #else extern const guint8 menu_cursor_pixdata[]; #endif +#endif enum nsgtk_resource_type_e { NSGTK_RESOURCE_FILE, - NSGTK_RESOURCE_BUILTIN, + NSGTK_RESOURCE_GLIB, + NSGTK_RESOURCE_INLINE, }; struct nsgtk_resource_s { @@ -74,6 +77,7 @@ static struct nsgtk_resource_s ui_resource[] = { static struct nsgtk_resource_s gen_resource[] = { { "favicon.png", 11, NSGTK_RESOURCE_FILE, NULL }, { "netsurf.xpm", 11, NSGTK_RESOURCE_FILE, NULL }, + { "menu_cursor.png", 15, NSGTK_RESOURCE_FILE, NULL }, { NULL, 0, NSGTK_RESOURCE_FILE, NULL }, }; @@ -82,10 +86,16 @@ GdkCursor *nsgtk_create_menu_cursor(void) { GdkCursor *cursor = NULL; GdkPixbuf *pixbuf; + nserror res; + const char *resname = "menu_cursor.png"; - pixbuf = gdk_pixbuf_new_from_inline(-1, menu_cursor_pixdata, FALSE, NULL); - cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, 0, 3); - g_object_unref (pixbuf); + + res = nsgdk_pixbuf_new_from_resname(resname, &pixbuf); + if (res == NSERROR_OK) { + cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), + pixbuf, 0, 3); + g_object_unref(pixbuf); + } return cursor; } @@ -110,7 +120,14 @@ init_resource(char **respath, struct nsgtk_resource_s *resource) { int resnamelen; char *resname; - +#ifdef WITH_BUILTIN_PIXBUF + if (strncmp(resource->name, "menu_cursor.png", resource->len) == 0) { + resource->path = (char *)&menu_cursor_pixdata[0]; + resource->type = NSGTK_RESOURCE_INLINE; + LOG("Found builtin for %s", resource->name); + return NSERROR_OK; + } +#endif #ifdef WITH_GRESOURCE gboolean present; @@ -128,7 +145,7 @@ init_resource(char **respath, struct nsgtk_resource_s *resource) if (present == TRUE) { /* found an entry in the resources */ resource->path = resname; - resource->type = NSGTK_RESOURCE_BUILTIN; + resource->type = NSGTK_RESOURCE_GLIB; LOG("Found gresource path %s", resource->path); return NSERROR_OK; } @@ -264,7 +281,7 @@ nserror nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_out) { struct nsgtk_resource_s *resource; - GdkPixbuf *new_pixbuf; + GdkPixbuf *new_pixbuf = NULL; GError* error = NULL; resource = find_resource_from_name(resname, &gen_resource[0]); @@ -272,10 +289,20 @@ nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_out) return NSERROR_NOT_FOUND; } - if (resource->type == NSGTK_RESOURCE_FILE) { + switch (resource->type) { + case NSGTK_RESOURCE_FILE: new_pixbuf = gdk_pixbuf_new_from_file(resource->path, &error); - } else { + break; + + case NSGTK_RESOURCE_GLIB: new_pixbuf = gdk_pixbuf_new_from_resource(resource->path, &error); + break; + + case NSGTK_RESOURCE_INLINE: +#ifdef WITH_BUILTIN_PIXBUF + new_pixbuf = gdk_pixbuf_new_from_inline(-1, (const guint8 *)resource->path, FALSE, NULL); +#endif + break; } if (new_pixbuf == NULL) { LOG("Unable to create pixbuf from file for %s with path %s \"%s\"",