From cc3d889fea0ebc10894caa622fbac6d41c891bba Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 31 Oct 2017 18:00:24 +0100 Subject: First testing to use GResource to load default theme. --- Makefile.am | 20 ++++++++++++++++++-- resources/resources.xml | 6 ++++++ source/rofi.c | 29 ++++++++++++++++++++--------- 3 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 resources/resources.xml diff --git a/Makefile.am b/Makefile.am index dbf77e99..8ee5f016 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,17 @@ pkgconfig_DATA = pkgconfig/rofi.pc BUILT_SOURCES=\ lexer/theme-parser.h\ lexer/theme-parser.c\ - lexer/theme-lexer.c + lexer/theme-lexer.c\ + resources/resources.c\ + resources/resources.h + +$(top_builddir)/resources/resources.c: $(top_srcdir)/resources/resources.xml + mkdir -p $(top_builddir)/resources/ + glib-compile-resources $< --generate-source --target=$@ --sourcedir=$(top_srcdir) + +$(top_builddir)/resources/resources.h: $(top_srcdir)/resources/resources.xml + mkdir -p $(top_builddir)/resources/ + glib-compile-resources $< --generate-header --target=$@ --sourcedir=$(top_srcdir) $(top_builddir)/lexer/theme-lexer.c: $(top_srcdir)/lexer/theme-lexer.l @@ -109,11 +119,14 @@ SOURCES=\ include/dialogs/script.h\ include/dialogs/window.h\ include/dialogs/dialogs.h\ - include/dialogs/help-keys.h + include/dialogs/help-keys.h\ + resources/resources.c\ + resources/resources.h rofi_SOURCES=\ lexer/theme-parser.y\ lexer/theme-lexer.l\ + resources/resources.xml\ $(SOURCES) rofi_CFLAGS=\ @@ -217,6 +230,7 @@ EXTRA_DIST+=\ doc/rofi.doxy.in\ script/get_git_rev.sh\ $(theme_DATA)\ + doc/default_theme.rasi\ Changelog ## # Indent @@ -564,6 +578,8 @@ doxy: doc/rofi.doxy $(rofi_SOURCES) clean-local: -rm $(top_builddir)/gitconfig.h + -rm $(top_builddir)/resources/resources.h + -rm $(top_builddir)/resources/resources.c $(top_builddir)/gitconfig.h: .FORCE $(top_srcdir)/script/get_git_rev.sh $(top_srcdir) $(top_builddir)/gitconfig.h diff --git a/resources/resources.xml b/resources/resources.xml new file mode 100644 index 00000000..d42ae460 --- /dev/null +++ b/resources/resources.xml @@ -0,0 +1,6 @@ + + + + doc/default_theme.rasi + + diff --git a/source/rofi.c b/source/rofi.c index 8199e302..85ad95d2 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -52,6 +52,8 @@ #endif #endif +#include "resources/resources.h" + #include "rofi.h" #include "display.h" @@ -887,18 +889,27 @@ int main ( int argc, char *argv[] ) } } if ( rofi_theme_is_empty ( ) ) { - if ( rofi_theme_parse_string ( default_theme ) ) { - g_warning ( "Failed to parse default theme. Giving up.." ); - if ( list_of_error_msgs ) { - for ( GList *iter = g_list_first ( list_of_error_msgs ); - iter != NULL; iter = g_list_next ( iter ) ) { - g_warning ( "Error: %s%s%s", + GBytes *theme_data = g_resource_lookup_data ( + resources_get_resource(), + "/org/qtools/rofi/default_theme.rasi", + G_RESOURCE_LOOKUP_FLAGS_NONE, + NULL ); + if ( theme_data ) { + const char *theme = g_bytes_get_data ( theme_data, NULL ); + if ( rofi_theme_parse_string ( (const char *)theme ) ) { + g_warning ( "Failed to parse default theme. Giving up.." ); + if ( list_of_error_msgs ) { + for ( GList *iter = g_list_first ( list_of_error_msgs ); + iter != NULL; iter = g_list_next ( iter ) ) { + g_warning ( "Error: %s%s%s", color_bold, ( (GString *) iter->data )->str, color_reset ); + } } + rofi_theme = NULL; + cleanup (); + return EXIT_FAILURE; } - rofi_theme = NULL; - cleanup (); - return EXIT_FAILURE; + g_bytes_unref ( theme_data ); } rofi_theme_convert_old (); } -- cgit v1.2.3