Add -upgrade-config option.

* Print warning when old-style configuration is used.
* Add -upgrade-config option.
This commit is contained in:
Dave Davenport 2020-01-02 12:00:44 +01:00
parent 7650ed5d7a
commit b44b5e8d16
7 changed files with 1287 additions and 1266 deletions

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "ROFI\-THEME\-SELECTOR" "1" "January 2018" "" ""
.TH "ROFI\-THEME\-SELECTOR" "1" "December 2019" "" ""
.
.SH "NAME"
\fBrofi\-theme\-selector\fR \- Preview and apply themes for \fBrofi\fR

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "ROFI" "1" "August 2019" "" ""
.TH "ROFI" "1" "January 2020" "" ""
.
.SH "NAME"
\fBrofi\fR \- A window switcher, application launcher, ssh dialog and dmenu replacement
@ -60,7 +60,7 @@ Markup support can be enabled, see CONFIGURATION options\.
There are currently three methods of setting configuration options (evaluated in order below):
.
.IP "\(bu" 4
System configuration file (for example \fB/etc/rofi\.conf\fR)\.
System configuration file (for example \fB/etc/rofi\.rasi\fR or old format \fB/etc/rofi\.conf\fR)\.
.
.IP "\(bu" 4
Xresources: A method of storing key values in the Xserver\. See here \fIhttps://en\.wikipedia\.org/wiki/X_resources\fR for more information\.
@ -77,7 +77,7 @@ Command\-line options: Arguments passed to \fBrofi\fR\.
.IP "" 0
.
.P
\fBTIP\fR: To get a template config file run: \fBrofi \-dump\-xresources > rofi\-example\.config\fR\. \fBNOTE\fR: In version 1\.4\.0 we support configuration in a new format, a config for this can be generated by: \fBrofi \-dump\-config > config\.rasi\fR \fBNOTE\fR: If you want to use the new configuration format, the config file should be named \fBconfig\.rasi\fR\.
\fBTIP\fR: To get a template config file run: \fBrofi \-dump\-xresources > rofi\-example\.config\fR\. \fBNOTE\fR: In version 1\.4\.0 we support configuration in a new format, a config for this can be generated by: \fBrofi \-dump\-config > config\.rasi\fR \fBNOTE\fR: If you want to use the new configuration format, the config file should be named \fBconfig\.rasi\fR\. \fBNOTE\fR: You can upgrade to the new configuration file format using \fBrofi \-upgrade\-config\fR
.
.P
The Xresources file expects options starting with \fBrofi\.\fR followed by its name\. An example to set the number of lines:

View File

@ -53,7 +53,7 @@ Markup support can be enabled, see CONFIGURATION options.
There are currently three methods of setting configuration options (evaluated in order below):
* System configuration file (for example `/etc/rofi.conf`).
* System configuration file (for example `/etc/rofi.rasi` or old format `/etc/rofi.conf`).
* Xresources: A method of storing key values in the Xserver. See
[here](https://en.wikipedia.org/wiki/X_resources) for more information.
* Rasi theme file: The new *theme* format can be used to set configuration values.
@ -67,6 +67,7 @@ There are currently three methods of setting configuration options (evaluated in
**NOTE**: In version 1.4.0 we support configuration in a new format, a config for this can be generated by: `rofi
-dump-config > config.rasi`
**NOTE**: If you want to use the new configuration format, the config file should be named `config.rasi`.
**NOTE**: You can upgrade to the new configuration file format using `rofi -upgrade-config`
The Xresources file expects options starting with `rofi.` followed by its name. An example to set the number of lines:

View File

@ -167,10 +167,11 @@ char ** config_parser_return_display_help ( unsigned int *length );
gboolean config_parse_set_property ( const Property *p, char **error );
/**
* @param out The destination.
* @param changes Only print the changed options.
*
* @brief Dump configuration in rasi format.
*/
void config_parse_dump_config_rasi_format ( gboolean changes );
void config_parse_dump_config_rasi_format ( FILE *out, gboolean changes );
/* @}*/
#endif

View File

@ -119,6 +119,8 @@ static int dmenu_mode = FALSE;
/** Rofi's return code */
int return_code = EXIT_SUCCESS;
static gboolean old_config_format = FALSE;
void process_result ( RofiViewState *state );
void rofi_set_return_code ( int code )
@ -282,6 +284,7 @@ static void print_main_application_options ( int is_term )
print_help_msg ( "-no-plugins", "", "Disable loading of external plugins.", NULL, is_term );
print_help_msg ( "-plugin-path", "", "Directory used to search for rofi plugins.", NULL, is_term );
print_help_msg ( "-dump-config", "", "Dump the current configuration in rasi format and exit.", NULL, is_term );
print_help_msg ( "-upgrade-config", "", "Upgrade the old-style configuration fiel in the new rasi format and exit.", NULL, is_term );
print_help_msg ( "-dump-theme", "", "Dump the current theme in rasi format and exit.", NULL, is_term );
}
static void help ( G_GNUC_UNUSED int argc, char **argv )
@ -848,10 +851,19 @@ int main ( int argc, char *argv[] )
TICK_N ( "Setup abe" );
if ( find_arg ( "-no-config" ) < 0 ) {
// Load distro default settings
gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL );
gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.rasi", NULL );
g_debug ( "Testing: %s", etc);
if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
config_parse_xresource_options_file ( etc );
g_debug ( "Parsing: %s", etc);
rofi_theme_parse_file ( etc );
} else {
// Load distro default settings
gchar *xetc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL );
if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) {
config_parse_xresource_options_file ( xetc );
old_config_format = TRUE;
}
g_free ( xetc );
}
g_free ( etc );
// Load in config from X resources.
@ -866,6 +878,7 @@ int main ( int argc, char *argv[] )
g_free ( config_path_new );
config_path_new = NULL;
config_parse_xresource_options_file ( config_path );
old_config_format = TRUE;
}
}
find_arg_str ( "-theme", &( config.theme ) );
@ -882,6 +895,10 @@ int main ( int argc, char *argv[] )
config_parse_cmd_options ( );
TICK_N ( "Load cmd config " );
if ( old_config_format ) {
g_warning ( "The old Xresources based configuration format is deprecated.");
g_warning ( "Please upgrade: rofi -upgrade-config." );
}
parse_keys_abe ( bindings );
// Get the path to the cache dir.
@ -958,8 +975,47 @@ int main ( int argc, char *argv[] )
cleanup ();
return EXIT_SUCCESS;
}
if ( find_arg ( "-upgrade-config") >= 0 ) {
const char *cpath = g_get_user_config_dir ();
if ( cpath ) {
char *fcpath = g_build_filename ( cpath, "rofi", NULL );
if ( !g_file_test ( fcpath, G_FILE_TEST_IS_DIR ) && g_mkdir_with_parents ( fcpath, 0700) < 0 ) {
g_warning ( "Failed to create rofi configuration directory: %s", fcpath );
cleanup ();
g_free ( fcpath );
return EXIT_FAILURE;
}
g_free ( fcpath );
fcpath = g_build_filename ( cpath, "rofi", "config.rasi", NULL );
if ( g_file_test ( fcpath, G_FILE_TEST_IS_REGULAR ) ) {
g_warning ( "New configuration file already exists: %s", fcpath );
cleanup ();
g_free ( fcpath );
return EXIT_FAILURE;
}
FILE *fd = fopen(fcpath, "w" );
if ( fd == NULL ) {
g_warning ( "Failed to open new rofi configuration file: %s: %s", fcpath , strerror(errno));
cleanup ();
g_free ( fcpath );
return EXIT_FAILURE;
}
config_parse_dump_config_rasi_format ( fd, TRUE );
fprintf(stdout, "\n***** Generated configuration file in: %s *****\n", fcpath );
fflush ( fd );
fclose ( fd );
g_free( fcpath );
} else {
g_warning ( "Failed to get user configuration directory." );
cleanup ();
return EXIT_FAILURE;
}
cleanup ();
return EXIT_SUCCESS;
}
if ( find_arg ( "-dump-config" ) >= 0 ) {
config_parse_dump_config_rasi_format ( FALSE );
config_parse_dump_config_rasi_format ( stdout, FALSE );
cleanup ();
return EXIT_SUCCESS;
}

View File

@ -575,53 +575,53 @@ void config_parse_xresource_dump ( void )
}
}
static void config_parse_dump_config_option ( XrmOption *option )
static void config_parse_dump_config_option ( FILE *out, XrmOption *option )
{
if ( option->type == xrm_Char || option->source == CONFIG_DEFAULT ) {
printf ( "/*" );
fprintf ( out, "/*" );
}
printf ( "\t%s: ", option->name );
fprintf ( out, "\t%s: ", option->name );
switch ( option->type )
{
case xrm_Number:
printf ( "%u", *( option->value.num ) );
fprintf ( out, "%u", *( option->value.num ) );
break;
case xrm_SNumber:
printf ( "%i", *( option->value.snum ) );
fprintf ( out, "%i", *( option->value.snum ) );
break;
case xrm_String:
if ( ( *( option->value.str ) ) != NULL ) {
// TODO should this be escaped?
printf ( "\"%s\"", *( option->value.str ) );
fprintf ( out, "\"%s\"", *( option->value.str ) );
}
break;
case xrm_Boolean:
printf ( "%s", ( *( option->value.num ) == TRUE ) ? "true" : "false" );
fprintf ( out, "%s", ( *( option->value.num ) == TRUE ) ? "true" : "false" );
break;
case xrm_Char:
// TODO
if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) {
printf ( "'%c'", *( option->value.charc ) );
fprintf ( out, "'%c'", *( option->value.charc ) );
}
else {
printf ( "'\\x%02X'", *( option->value.charc ) );
fprintf ( out, "'\\x%02X'", *( option->value.charc ) );
}
printf ( " /* unsupported */" );
fprintf ( out, " /* unsupported */" );
break;
default:
break;
}
printf ( ";" );
fprintf ( out, ";" );
if ( option->type == xrm_Char || option->source == CONFIG_DEFAULT ) {
printf ( "*/" );
fprintf ( out, "*/" );
}
printf ( "\n" );
fprintf ( out, "\n" );
}
void config_parse_dump_config_rasi_format ( gboolean changes )
void config_parse_dump_config_rasi_format ( FILE *out, gboolean changes )
{
printf ( "configuration {\n" );
fprintf ( out, "configuration {\n" );
unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions );
for ( unsigned int i = 0; i < entries; ++i ) {
@ -632,16 +632,16 @@ void config_parse_dump_config_rasi_format ( gboolean changes )
}
}
if ( !changes || xrmOptions[i].source != CONFIG_DEFAULT ) {
config_parse_dump_config_option ( &( xrmOptions[i] ) );
config_parse_dump_config_option ( out, &( xrmOptions[i] ) );
}
}
for ( unsigned int i = 0; i < num_extra_options; i++ ) {
if ( !changes || extra_options[i].source != CONFIG_DEFAULT ) {
config_parse_dump_config_option ( &( extra_options[i] ) );
config_parse_dump_config_option ( out, &( extra_options[i] ) );
}
}
printf ( "}\n" );
fprintf ( out, "}\n" );
}
static void print_option_string ( XrmOption *xo, int is_term )