[Config] Load default config file in at startup

* load via resources doc/default_configuration.rasi
* print the configuration options on dump-config
This commit is contained in:
Dave Davenport 2021-07-10 00:25:20 +02:00
parent 0c3d24136d
commit 9f71c4f78d
8 changed files with 47 additions and 2 deletions

View file

@ -256,6 +256,7 @@ EXTRA_DIST+=\
script/get_git_rev.sh\ script/get_git_rev.sh\
$(theme_DATA)\ $(theme_DATA)\
doc/default_theme.rasi\ doc/default_theme.rasi\
doc/default_configuration.rasi\
Changelog Changelog
## ##
# Indent # Indent

View file

@ -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";
}
}

View file

@ -111,6 +111,7 @@ ThemeWidget *rofi_theme_find_or_create_name ( ThemeWidget *base, const char *nam
* Print out the widget to the commandline. * Print out the widget to the commandline.
*/ */
void rofi_theme_print ( ThemeWidget *widget ); void rofi_theme_print ( ThemeWidget *widget );
void rofi_theme_print_index ( ThemeWidget *widget, int index );
/** /**
* @param type The type of the property to create. * @param type The type of the property to create.

View file

@ -2,5 +2,6 @@
<gresources> <gresources>
<gresource prefix="/org/qtools/rofi"> <gresource prefix="/org/qtools/rofi">
<file alias="default_theme.rasi">doc/default_theme.rasi</file> <file alias="default_theme.rasi">doc/default_theme.rasi</file>
<file alias="default_configuration.rasi">doc/default_configuration.rasi</file>
</gresource> </gresource>
</gresources> </gresources>

View file

@ -856,6 +856,33 @@ int main ( int argc, char *argv[] )
} }
config_parser_add_option ( xrm_String, "pid", (void * *) &pidfile, "Pidfile location" ); 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 ) { if ( find_arg ( "-config" ) < 0 ) {
const char *cpath = g_get_user_config_dir (); const char *cpath = g_get_user_config_dir ();
if ( cpath ) { if ( cpath ) {

View file

@ -503,7 +503,7 @@ static void rofi_theme_print_property_index ( size_t pnl, int depth, Property *p
putchar ( '\n' ); putchar ( '\n' );
} }
static void rofi_theme_print_index ( ThemeWidget *widget, int index ) void rofi_theme_print_index ( ThemeWidget *widget, int index )
{ {
GHashTableIter iter; GHashTableIter iter;
gpointer key, value; gpointer key, value;

View file

@ -511,7 +511,7 @@ static void rofi_view_set_user_timeout ( G_GNUC_UNUSED gpointer data )
if ( wid ) { if ( wid ) {
/** Check string property */ /** Check string property */
Property *p = rofi_theme_find_property ( wid, P_INTEGER, "delay", TRUE); 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; int delay = p->value.i;
CacheState.user_timeout = g_timeout_add ( delay*1000 , rofi_view_user_timeout, NULL ); CacheState.user_timeout = g_timeout_add ( delay*1000 , rofi_view_user_timeout, NULL );
} }

View file

@ -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" ); fprintf ( out, "}\n" );
} }