From 9f71c4f78db67d34c20b76211488ae2c971c829e Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 10 Jul 2021 00:25:20 +0200 Subject: [Config] Load default config file in at startup * load via resources doc/default_configuration.rasi * print the configuration options on dump-config --- Makefile.am | 1 + doc/default_configuration.rasi | 11 +++++++++++ include/theme.h | 1 + resources/resources.xml | 1 + source/rofi.c | 27 +++++++++++++++++++++++++++ source/theme.c | 2 +- source/view.c | 2 +- source/xrmoptions.c | 4 ++++ 8 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 doc/default_configuration.rasi diff --git a/Makefile.am b/Makefile.am index b4528d7a..a19556e0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -256,6 +256,7 @@ EXTRA_DIST+=\ script/get_git_rev.sh\ $(theme_DATA)\ doc/default_theme.rasi\ + doc/default_configuration.rasi\ Changelog ## # Indent diff --git a/doc/default_configuration.rasi b/doc/default_configuration.rasi new file mode 100644 index 00000000..d7ac8f77 --- /dev/null +++ b/doc/default_configuration.rasi @@ -0,0 +1,11 @@ +configuration { + + // Timeout from user input. + timeout { + // The delay after inactivity to execute action. + delay: 0; + // The action to execute once the delay expires. + action: "kb-cancel"; + } + +} diff --git a/include/theme.h b/include/theme.h index 94a7c1d7..bfd6c253 100644 --- a/include/theme.h +++ b/include/theme.h @@ -111,6 +111,7 @@ ThemeWidget *rofi_theme_find_or_create_name ( ThemeWidget *base, const char *nam * Print out the widget to the commandline. */ void rofi_theme_print ( ThemeWidget *widget ); +void rofi_theme_print_index ( ThemeWidget *widget, int index ); /** * @param type The type of the property to create. diff --git a/resources/resources.xml b/resources/resources.xml index d42ae460..f9c2f422 100644 --- a/resources/resources.xml +++ b/resources/resources.xml @@ -2,5 +2,6 @@ doc/default_theme.rasi + doc/default_configuration.rasi diff --git a/source/rofi.c b/source/rofi.c index a94d4611..531cd44f 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -856,6 +856,33 @@ int main ( int argc, char *argv[] ) } config_parser_add_option ( xrm_String, "pid", (void * *) &pidfile, "Pidfile location" ); + + /** default configuration */ + { + GBytes *theme_data = g_resource_lookup_data ( + resources_get_resource (), + "/org/qtools/rofi/default_configuration.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 configuration. 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_configuration = NULL; + cleanup (); + return EXIT_FAILURE; + } + g_bytes_unref ( theme_data ); + } + } + if ( find_arg ( "-config" ) < 0 ) { const char *cpath = g_get_user_config_dir (); if ( cpath ) { diff --git a/source/theme.c b/source/theme.c index 8afccb14..a6c998b8 100644 --- a/source/theme.c +++ b/source/theme.c @@ -503,7 +503,7 @@ static void rofi_theme_print_property_index ( size_t pnl, int depth, Property *p putchar ( '\n' ); } -static void rofi_theme_print_index ( ThemeWidget *widget, int index ) +void rofi_theme_print_index ( ThemeWidget *widget, int index ) { GHashTableIter iter; gpointer key, value; diff --git a/source/view.c b/source/view.c index 3259ed56..14f7c3d2 100644 --- a/source/view.c +++ b/source/view.c @@ -511,7 +511,7 @@ static void rofi_view_set_user_timeout ( G_GNUC_UNUSED gpointer data ) if ( wid ) { /** Check string property */ Property *p = rofi_theme_find_property ( wid, P_INTEGER, "delay", TRUE); - if ( p != NULL && p->type == P_INTEGER) { + if ( p != NULL && p->type == P_INTEGER && p->value.i > 0 ) { int delay = p->value.i; CacheState.user_timeout = g_timeout_add ( delay*1000 , rofi_view_user_timeout, NULL ); } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 91a98416..6a7fdf98 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -553,6 +553,10 @@ void config_parse_dump_config_rasi_format ( FILE *out, gboolean changes ) } } + for ( unsigned int index = 0; index < rofi_configuration->num_widgets; index ++ ) { + rofi_theme_print_index ( rofi_configuration->widgets[index], 2 ); + } + fprintf ( out, "}\n" ); } -- cgit v1.2.3