mirror of https://github.com/davatorium/rofi.git
Test config file before load, support ~/.config/rofi/theme and remove config_path global, fix loading dynamic options from /etc/rofi.conf
This commit is contained in:
parent
1b1f015880
commit
0c7d1a6b17
|
@ -7,7 +7,7 @@
|
||||||
* The 'object' that makes a mode in rofi.
|
* The 'object' that makes a mode in rofi.
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
typedef struct rofi_mode Mode;
|
typedef struct rofi_mode Mode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum used to sum the possible states of ROFI.
|
* Enum used to sum the possible states of ROFI.
|
||||||
|
|
|
@ -38,15 +38,15 @@ typedef struct
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
TB_AUTOHEIGHT = 1 << 0,
|
TB_AUTOHEIGHT = 1 << 0,
|
||||||
TB_AUTOWIDTH = 1 << 1,
|
TB_AUTOWIDTH = 1 << 1,
|
||||||
TB_LEFT = 1 << 16,
|
TB_LEFT = 1 << 16,
|
||||||
TB_RIGHT = 1 << 17,
|
TB_RIGHT = 1 << 17,
|
||||||
TB_CENTER = 1 << 18,
|
TB_CENTER = 1 << 18,
|
||||||
TB_EDITABLE = 1 << 19,
|
TB_EDITABLE = 1 << 19,
|
||||||
TB_MARKUP = 1 << 20,
|
TB_MARKUP = 1 << 20,
|
||||||
TB_WRAP = 1 << 21,
|
TB_WRAP = 1 << 21,
|
||||||
TB_PASSWORD = 1 << 22,
|
TB_PASSWORD = 1 << 22,
|
||||||
} TextboxFlags;
|
} TextboxFlags;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|
|
@ -78,7 +78,6 @@ struct xkb_stuff xkb = {
|
||||||
.state = NULL
|
.state = NULL
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
char *config_path = NULL;
|
|
||||||
// Array of modi.
|
// Array of modi.
|
||||||
Mode **modi = NULL;
|
Mode **modi = NULL;
|
||||||
unsigned int num_modi = 0;
|
unsigned int num_modi = 0;
|
||||||
|
@ -337,8 +336,6 @@ static void cleanup ()
|
||||||
// Cleanup the custom keybinding
|
// Cleanup the custom keybinding
|
||||||
cleanup_abe ();
|
cleanup_abe ();
|
||||||
|
|
||||||
g_free ( config_path );
|
|
||||||
|
|
||||||
TIMINGS_STOP ();
|
TIMINGS_STOP ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,24 +430,51 @@ static void setup_modi ( void )
|
||||||
*/
|
*/
|
||||||
static inline void load_configuration ( )
|
static inline void load_configuration ( )
|
||||||
{
|
{
|
||||||
|
const char *cpath = g_get_user_config_dir ();
|
||||||
|
char *config_path = NULL;
|
||||||
// Load distro default settings
|
// Load distro default settings
|
||||||
gchar *etc = g_build_filename ( G_DIR_SEPARATOR_S, "etc", "rofi.conf", NULL );
|
gchar *etc = g_build_filename ( G_DIR_SEPARATOR_S, "etc", "rofi.conf", NULL );
|
||||||
if ( g_file_test ( etc, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR ) ) {
|
if ( g_file_test ( etc, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR ) ) {
|
||||||
config_parse_xresource_options_file ( etc );
|
config_parse_xresource_options_file ( etc );
|
||||||
|
config_parse_xresource_options_dynamic_file ( etc );
|
||||||
}
|
}
|
||||||
g_free ( etc );
|
g_free ( etc );
|
||||||
|
|
||||||
// Load in config from X resources.
|
// Load in config from X resources.
|
||||||
config_parse_xresource_options ( xcb );
|
config_parse_xresource_options ( xcb );
|
||||||
config_parse_xresource_options_file ( config_path );
|
config_parse_xresource_options_dynamic ( xcb );
|
||||||
|
|
||||||
|
if ( find_arg ( "-config" ) < 0 ) {
|
||||||
|
if ( cpath ) {
|
||||||
|
config_path = g_build_filename ( cpath, "rofi", "config", NULL );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
char *c = NULL;
|
||||||
|
find_arg_str ( "-config", &c );
|
||||||
|
config_path = rofi_expand_path ( c );
|
||||||
|
}
|
||||||
|
if ( config_path != NULL ) {
|
||||||
|
if ( g_file_test ( config_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR ) ) {
|
||||||
|
// Load config from config file.
|
||||||
|
config_parse_xresource_options_file ( config_path );
|
||||||
|
config_parse_xresource_options_dynamic_file ( config_path );
|
||||||
|
}
|
||||||
|
g_free ( config_path );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load theme file
|
||||||
|
if ( cpath ) {
|
||||||
|
char *theme_path = g_build_filename ( cpath, "rofi", "theme", NULL );
|
||||||
|
if ( g_file_test ( theme_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR ) ) {
|
||||||
|
config_parse_xresource_options_file ( theme_path );
|
||||||
|
config_parse_xresource_options_dynamic_file ( theme_path );
|
||||||
|
}
|
||||||
|
g_free ( theme_path );
|
||||||
|
}
|
||||||
|
|
||||||
// Parse command line for settings.
|
// Parse command line for settings.
|
||||||
config_parse_cmd_options ( );
|
config_parse_cmd_options ( );
|
||||||
}
|
|
||||||
static inline void load_configuration_dynamic ( )
|
|
||||||
{
|
|
||||||
// Load in config from X resources.
|
|
||||||
config_parse_xresource_options_dynamic ( xcb );
|
|
||||||
config_parse_xresource_options_dynamic_file ( config_path );
|
|
||||||
config_parse_cmd_options_dynamic ( );
|
config_parse_cmd_options_dynamic ( );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,18 +667,6 @@ 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" );
|
||||||
|
|
||||||
if ( find_arg ( "-config" ) < 0 ) {
|
|
||||||
const char *cpath = g_get_user_config_dir ();
|
|
||||||
if ( cpath ) {
|
|
||||||
config_path = g_build_filename ( cpath, "rofi", "config", NULL );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
char *c = NULL;
|
|
||||||
find_arg_str ( "-config", &c );
|
|
||||||
config_path = rofi_expand_path ( c );
|
|
||||||
}
|
|
||||||
|
|
||||||
TICK ();
|
TICK ();
|
||||||
// Register cleanup function.
|
// Register cleanup function.
|
||||||
atexit ( cleanup );
|
atexit ( cleanup );
|
||||||
|
@ -806,9 +818,6 @@ int main ( int argc, char *argv[] )
|
||||||
setup_abe ();
|
setup_abe ();
|
||||||
TICK_N ( "Setup abe" );
|
TICK_N ( "Setup abe" );
|
||||||
|
|
||||||
if ( find_arg ( "-no-config" ) < 0 ) {
|
|
||||||
load_configuration ( );
|
|
||||||
}
|
|
||||||
if ( !dmenu_mode ) {
|
if ( !dmenu_mode ) {
|
||||||
// setup_modi
|
// setup_modi
|
||||||
setup_modi ();
|
setup_modi ();
|
||||||
|
@ -818,8 +827,7 @@ int main ( int argc, char *argv[] )
|
||||||
config_parser_add_option ( xrm_Char, "sep", (void * *) &( config.separator ), "Element separator" );
|
config_parser_add_option ( xrm_Char, "sep", (void * *) &( config.separator ), "Element separator" );
|
||||||
}
|
}
|
||||||
if ( find_arg ( "-no-config" ) < 0 ) {
|
if ( find_arg ( "-no-config" ) < 0 ) {
|
||||||
// Reload for dynamic part.
|
load_configuration ( );
|
||||||
load_configuration_dynamic ( );
|
|
||||||
}
|
}
|
||||||
// Dump.
|
// Dump.
|
||||||
// catch help request
|
// catch help request
|
||||||
|
|
Loading…
Reference in New Issue