summaryrefslogtreecommitdiffstats
path: root/source/xrmoptions.c
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-08-04 20:22:59 +0200
committerDave Davenport <qball@gmpclient.org>2016-08-04 20:24:01 +0200
commiteb0bfc60c4c316ad43e7c566e4ab75360f7f0c32 (patch)
tree86d64e56bc8991137efbad24812b2abbb5e3d264 /source/xrmoptions.c
parentce822a3bbf9f5cae61739b1eb34636c50e0f8920 (diff)
Indicate what set an option, comment default options in dump-xresources.
Diffstat (limited to 'source/xrmoptions.c')
-rw-r--r--source/xrmoptions.c196
1 files changed, 118 insertions, 78 deletions
diff --git a/source/xrmoptions.c b/source/xrmoptions.c
index f8eb4c72..288ad324 100644
--- a/source/xrmoptions.c
+++ b/source/xrmoptions.c
@@ -44,6 +44,20 @@
#include "settings.h"
#include "helper.h"
+const char * const ConfigSourceStr[] = {
+ "Default",
+ "XResources",
+ "File",
+ "Commandline",
+};
+enum ConfigSource
+{
+ CONFIG_DEFAULT = 0,
+ CONFIG_XRESOURCES = 1,
+ CONFIG_FILE = 2,
+ CONFIG_CMDLINE = 3
+};
+
typedef struct
{
int type;
@@ -55,9 +69,10 @@ typedef struct
char ** str;
void *pointer;
char * charc;
- } value;
- char *mem;
- const char *comment;
+ } value;
+ char *mem;
+ const char *comment;
+ enum ConfigSource source;
} XrmOption;
/**
* Map X resource and commandline options to internal options
@@ -65,116 +80,116 @@ typedef struct
*/
static XrmOption xrmOptions[] = {
{ xrm_String, "switchers", { .str = &config.modi }, NULL,
- "" },
+ "", CONFIG_DEFAULT },
{ xrm_String, "modi", { .str = &config.modi }, NULL,
- "Enabled modi" },
+ "Enabled modi", CONFIG_DEFAULT },
{ xrm_Number, "opacity", { .num = &config.window_opacity }, NULL,
- "Window opacity" },
+ "Window opacity", CONFIG_DEFAULT },
{ xrm_SNumber, "width", { .snum = &config.menu_width }, NULL,
- "Window width" },
+ "Window width", CONFIG_DEFAULT },
{ xrm_Number, "lines", { .num = &config.menu_lines }, NULL,
- "Number of lines" },
+ "Number of lines", CONFIG_DEFAULT },
{ xrm_Number, "columns", { .num = &config.menu_columns }, NULL,
- "Number of columns" },
+ "Number of columns", CONFIG_DEFAULT },
{ xrm_String, "font", { .str = &config.menu_font }, NULL,
- "Font to use" },
+ "Font to use", CONFIG_DEFAULT },
{ xrm_String, "color-normal", { .str = &config.color_normal }, NULL,
- "Color scheme for normal row" },
+ "Color scheme for normal row", CONFIG_DEFAULT },
{ xrm_String, "color-urgent", { .str = &config.color_urgent }, NULL,
- "Color scheme for urgent row" },
+ "Color scheme for urgent row", CONFIG_DEFAULT },
{ xrm_String, "color-active", { .str = &config.color_active }, NULL,
- "Color scheme for active row" },
+ "Color scheme for active row", CONFIG_DEFAULT },
{ xrm_String, "color-window", { .str = &config.color_window }, NULL,
- "Color scheme window" },
+ "Color scheme window", CONFIG_DEFAULT },
{ xrm_Number, "borderwidth", { .num = &config.menu_bw }, NULL,
- "" },
+ "", CONFIG_DEFAULT },
{ xrm_Number, "bw", { .num = &config.menu_bw }, NULL,
- "Border width" },
+ "Border width", CONFIG_DEFAULT },
{ xrm_Number, "location", { .num = &config.location }, NULL,
- "Location on screen" },
+ "Location on screen", CONFIG_DEFAULT },
{ xrm_Number, "padding", { .num = &config.padding }, NULL,
- "Padding" },
+ "Padding", CONFIG_DEFAULT },
{ xrm_SNumber, "yoffset", { .snum = &config.y_offset }, NULL,
- "Y-offset relative to location" },
+ "Y-offset relative to location", CONFIG_DEFAULT },
{ xrm_SNumber, "xoffset", { .snum = &config.x_offset }, NULL,
- "X-offset relative to location" },
+ "X-offset relative to location", CONFIG_DEFAULT },
{ xrm_Boolean, "fixed-num-lines", { .num = &config.fixed_num_lines }, NULL,
- "Always show number of lines" },
+ "Always show number of lines", CONFIG_DEFAULT },
{ xrm_String, "terminal", { .str = &config.terminal_emulator }, NULL,
- "Terminal to use" },
+ "Terminal to use", CONFIG_DEFAULT },
{ xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL,
- "Ssh client to use" },
+ "Ssh client to use", CONFIG_DEFAULT },
{ xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL,
- "Ssh command to execute" },
+ "Ssh command to execute", CONFIG_DEFAULT },
{ xrm_String, "run-command", { .str = &config.run_command }, NULL,
- "Run command to execute" },
+ "Run command to execute", CONFIG_DEFAULT },
{ xrm_String, "run-list-command", { .str = &config.run_list_command }, NULL,
- "Command to get extra run targets" },
+ "Command to get extra run targets", CONFIG_DEFAULT },
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL,
- "Run command to execute that runs in shell" },
+ "Run command to execute that runs in shell", CONFIG_DEFAULT },
{ xrm_String, "window-command", { .str = &config.window_command }, NULL,
- "Command executed on accep-entry-custom for window modus" },
+ "Command executed on accep-entry-custom for window modus", CONFIG_DEFAULT },
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL,
- "Disable history in run/ssh" },
+ "Disable history in run/ssh", CONFIG_DEFAULT },
{ xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort }, NULL,
- "Use levenshtein sorting" },
+ "Use levenshtein sorting", CONFIG_DEFAULT },
{ xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL,
- "Set case-sensitivity" },
+ "Set case-sensitivity", CONFIG_DEFAULT },
{ xrm_Boolean, "cycle", { .num = &config.cycle }, NULL,
- "Cycle through the results list" },
+ "Cycle through the results list", CONFIG_DEFAULT },
{ xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL,
- "Enable sidebar-mode" },
+ "Enable sidebar-mode", CONFIG_DEFAULT },
{ xrm_SNumber, "eh", { .snum = &config.element_height }, NULL,
- "Row height (in chars)" },
+ "Row height (in chars)", CONFIG_DEFAULT },
{ xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL,
- "Enable auto select mode" },
+ "Enable auto select mode", CONFIG_DEFAULT },
{ xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL,
- "Parse hosts file for ssh mode" },
+ "Parse hosts file for ssh mode", CONFIG_DEFAULT },
{ xrm_Boolean, "parse-known-hosts", { .num = &config.parse_known_hosts }, NULL,
- "Parse known_hosts file for ssh mode" },
+ "Parse known_hosts file for ssh mode", CONFIG_DEFAULT },
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL,
- "Set the modi to combine in combi mode" },
+ "Set the modi to combine in combi mode", CONFIG_DEFAULT },
{ xrm_Boolean, "glob", { .num = &config.glob }, NULL,
- "Use glob matching" },
+ "Use glob matching", CONFIG_DEFAULT },
{ xrm_Boolean, "regex", { .num = &config.regex }, NULL,
- "Use regex matching" },
+ "Use regex matching", CONFIG_DEFAULT },
{ xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL,
- "Tokenize input string" },
+ "Tokenize input string", CONFIG_DEFAULT },
{ xrm_Number, "monitor", { .snum = &config.monitor }, NULL,
- "" },
+ "", CONFIG_DEFAULT },
/* Alias for dmenu compatibility. */
{ xrm_SNumber, "m", { .snum = &config.monitor }, NULL,
- "Monitor id to show on" },
+ "Monitor id to show on", CONFIG_DEFAULT },
{ xrm_Number, "line-margin", { .num = &config.line_margin }, NULL,
- "Margin between rows" },
+ "Margin between rows", CONFIG_DEFAULT },
{ xrm_String, "filter", { .str = &config.filter }, NULL,
- "Pre-set filter" },
+ "Pre-set filter", CONFIG_DEFAULT },
{ xrm_String, "separator-style", { .str = &config.separator_style }, NULL,
- "Separator style (none, dash, solid)" },
+ "Separator style (none, dash, solid)", CONFIG_DEFAULT },
{ xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL,
- "Hide scroll-bar" },
+ "Hide scroll-bar", CONFIG_DEFAULT },
{ xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL,
- "Fullscreen" },
+ "Fullscreen", CONFIG_DEFAULT },
{ xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL,
- "Fake transparency" },
+ "Fake transparency", CONFIG_DEFAULT },
{ xrm_SNumber, "dpi", { .snum = &config.dpi }, NULL,
- "DPI" },
+ "DPI", CONFIG_DEFAULT },
{ xrm_Number, "threads", { .num = &config.threads }, NULL,
- "Threads to use for string matching" },
+ "Threads to use for string matching", CONFIG_DEFAULT },
{ xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL,
- "Scrollbar width" },
+ "Scrollbar width", CONFIG_DEFAULT },
{ xrm_Number, "scroll-method", { .num = &config.scroll_method }, NULL,
- "Scrolling method. (0: Page, 1: Centered)" },
+ "Scrolling method. (0: Page, 1: Centered)", CONFIG_DEFAULT },
{ xrm_String, "fake-background", { .str = &config.fake_background }, NULL,
- "Background to use for fake transparency. (background or screenshot)" },
+ "Background to use for fake transparency. (background or screenshot)", CONFIG_DEFAULT },
{ xrm_String, "window-format", { .str = &config.window_format }, NULL,
- "Window Format. w (desktop name), t (title), n (name), r (role), c (class)" },
+ "Window Format. w (desktop name), t (title), n (name), r (role), c (class)", CONFIG_DEFAULT },
};
// Dynamic options.
@@ -189,6 +204,7 @@ void config_parser_add_option ( XrmOptionType type, const char *key, void **valu
extra_options[num_extra_options].name = key;
extra_options[num_extra_options].value.pointer = value;
extra_options[num_extra_options].comment = comment;
+ extra_options[num_extra_options].source = CONFIG_DEFAULT;
if ( type == xrm_String ) {
extra_options[num_extra_options].mem = ( (char *) ( *value ) );
}
@@ -199,7 +215,7 @@ void config_parser_add_option ( XrmOptionType type, const char *key, void **valu
num_extra_options++;
}
-static void config_parser_set ( XrmOption *option, char *xrmValue )
+static void config_parser_set ( XrmOption *option, char *xrmValue, enum ConfigSource source )
{
if ( option->type == xrm_String ) {
if ( ( option )->mem != NULL ) {
@@ -229,9 +245,10 @@ static void config_parser_set ( XrmOption *option, char *xrmValue )
else if ( option->type == xrm_Char ) {
*( option->value.charc ) = helper_parse_char ( xrmValue );
}
+ option->source = source;
}
-static void __config_parse_xresource_options ( xcb_xrm_database_t *xDB )
+static void __config_parse_xresource_options ( xcb_xrm_database_t *xDB, enum ConfigSource source )
{
const char * namePrefix = "rofi";
@@ -240,7 +257,7 @@ static void __config_parse_xresource_options ( xcb_xrm_database_t *xDB )
char *xrmValue = NULL;
if ( xcb_xrm_resource_get_string ( xDB, name, NULL, &xrmValue ) == 0 ) {
- config_parser_set ( &( xrmOptions[i] ), xrmValue );
+ config_parser_set ( &( xrmOptions[i] ), xrmValue, source );
}
if ( xrmValue ) {
free ( xrmValue );
@@ -253,7 +270,7 @@ void config_parse_xresource_options ( xcb_stuff *xcb )
{
xcb_xrm_database_t *xDB = xcb_xrm_database_from_default ( xcb->connection );
if ( xDB ) {
- __config_parse_xresource_options ( xDB );
+ __config_parse_xresource_options ( xDB, CONFIG_XRESOURCES );
xcb_xrm_database_free ( xDB );
}
}
@@ -267,7 +284,7 @@ void config_parse_xresource_options_file ( const char *filename )
if ( xDB == NULL ) {
return;
}
- __config_parse_xresource_options ( xDB );
+ __config_parse_xresource_options ( xDB, CONFIG_FILE );
xcb_xrm_database_free ( xDB );
}
@@ -281,10 +298,14 @@ static void config_parse_cmd_option ( XrmOption *option )
switch ( option->type )
{
case xrm_Number:
- find_arg_uint ( key, option->value.num );
+ if ( find_arg_uint ( key, option->value.num ) == TRUE ) {
+ option->source = CONFIG_CMDLINE;
+ }
break;
case xrm_SNumber:
- find_arg_int ( key, option->value.snum );
+ if ( find_arg_int ( key, option->value.snum ) == TRUE ) {
+ option->source = CONFIG_CMDLINE;
+ }
break;
case xrm_String:
if ( find_arg_str ( key, option->value.str ) == TRUE ) {
@@ -292,22 +313,27 @@ static void config_parse_cmd_option ( XrmOption *option )
g_free ( option->mem );
option->mem = NULL;
}
+ option->source = CONFIG_CMDLINE;
}
break;
case xrm_Boolean:
if ( find_arg ( key ) >= 0 ) {
*( option->value.num ) = TRUE;
+ option->source = CONFIG_CMDLINE;
}
else {
g_free ( key );
key = g_strdup_printf ( "-no-%s", option->name );
if ( find_arg ( key ) >= 0 ) {
*( option->value.num ) = FALSE;
+ option->source = CONFIG_CMDLINE;
}
}
break;
case xrm_Char:
- find_arg_char ( key, option->value.charc );
+ if ( find_arg_char ( key, option->value.charc ) == TRUE ) {
+ option->source = CONFIG_CMDLINE;
+ }
break;
default:
break;
@@ -331,7 +357,7 @@ void config_parse_cmd_options_dynamic ( void )
}
}
-static void __config_parse_xresource_options_dynamic ( xcb_xrm_database_t *xDB )
+static void __config_parse_xresource_options_dynamic ( xcb_xrm_database_t *xDB, enum ConfigSource source )
{
const char * namePrefix = "rofi";
@@ -341,7 +367,7 @@ static void __config_parse_xresource_options_dynamic ( xcb_xrm_database_t *xDB )
name = g_strdup_printf ( "%s.%s", namePrefix, extra_options[i].name );
char *xrmValue = NULL;
if ( xcb_xrm_resource_get_string ( xDB, name, NULL, &xrmValue ) == 0 ) {
- config_parser_set ( &( extra_options[i] ), xrmValue );
+ config_parser_set ( &( extra_options[i] ), xrmValue, source );
}
if ( xrmValue ) {
free ( xrmValue );
@@ -356,7 +382,7 @@ void config_parse_xresource_options_dynamic ( xcb_stuff *xcb )
char *name = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), XCB_ATOM_RESOURCE_MANAGER );
if ( name ) {
xcb_xrm_database_t *xDB = xcb_xrm_database_from_string ( name );
- __config_parse_xresource_options_dynamic ( xDB );
+ __config_parse_xresource_options_dynamic ( xDB, CONFIG_XRESOURCES );
xcb_xrm_database_free ( xDB );
g_free ( name );
}
@@ -371,7 +397,7 @@ void config_parse_xresource_options_dynamic_file ( const char *filename )
if ( xDB == NULL ) {
return;
}
- __config_parse_xresource_options_dynamic ( xDB );
+ __config_parse_xresource_options_dynamic ( xDB, CONFIG_FILE );
xcb_xrm_database_free ( xDB );
}
@@ -396,7 +422,11 @@ void config_xresource_free ( void )
static void xresource_dump_entry ( const char *namePrefix, XrmOption *option )
{
- printf ( "! %s\n", option->comment );
+ printf ( "! \"%s\" ", option->comment );
+ printf ( "Set from: %s\n", ConfigSourceStr[option->source] );
+ if ( option->source == CONFIG_DEFAULT ) {
+ printf ( "! " );
+ }
printf ( "%s.%s: %*s", namePrefix, option->name,
(int) ( 30 - strlen ( option->name ) ), "" );
switch ( option->type )
@@ -452,11 +482,13 @@ static void print_option_string ( XrmOption *xo, int is_term )
int l = strlen ( xo->name );
if ( is_term ) {
printf ( "\t"color_bold "-%s"color_reset " [string]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
- printf ( "\t\t"color_italic "%s"color_reset "\n", ( *( xo->value.str ) == NULL ) ? "(unset)" : ( *( xo->value.str ) ) );
+ printf ( "\t"color_italic "%s"color_reset, ( *( xo->value.str ) == NULL ) ? "(unset)" : ( *( xo->value.str ) ) );
+ printf ( " "color_green "(%s)"color_reset "\n", ConfigSourceStr[xo->source] );
}
else {
printf ( "\t-%s [string]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
- printf ( "\t\t%s\n", ( *( xo->value.str ) == NULL ) ? "(unset)" : ( *( xo->value.str ) ) );
+ printf ( "\t\t%s", ( *( xo->value.str ) == NULL ) ? "(unset)" : ( *( xo->value.str ) ) );
+ printf ( " (%s)\n", ConfigSourceStr[xo->source] );
}
}
static void print_option_number ( XrmOption *xo, int is_term )
@@ -464,11 +496,13 @@ static void print_option_number ( XrmOption *xo, int is_term )
int l = strlen ( xo->name );
if ( is_term ) {
printf ( "\t"color_bold "-%s"color_reset " [number]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
- printf ( "\t\t"color_italic "%u"color_reset "\n", *( xo->value.num ) );
+ printf ( "\t"color_italic "%u"color_reset, *( xo->value.num ) );
+ printf ( " "color_green "(%s)"color_reset "\n", ConfigSourceStr[xo->source] );
}
else {
printf ( "\t-%s [number]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
- printf ( "\t\t%u\n", *( xo->value.num ) );
+ printf ( "\t\t%u", *( xo->value.num ) );
+ printf ( " (%s)\n", ConfigSourceStr[xo->source] );
}
}
static void print_option_snumber ( XrmOption *xo, int is_term )
@@ -476,11 +510,13 @@ static void print_option_snumber ( XrmOption *xo, int is_term )
int l = strlen ( xo->name );
if ( is_term ) {
printf ( "\t"color_bold "-%s"color_reset " [number]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
- printf ( "\t\t"color_italic "%d"color_reset "\n", *( xo->value.snum ) );
+ printf ( "\t"color_italic "%d"color_reset, *( xo->value.snum ) );
+ printf ( " "color_green "(%s)"color_reset "\n", ConfigSourceStr[xo->source] );
}
else {
printf ( "\t-%s [number]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
- printf ( "\t\t%d\n", *( xo->value.snum ) );
+ printf ( "\t\t%d", *( xo->value.snum ) );
+ printf ( " (%s)\n", ConfigSourceStr[xo->source] );
}
}
static void print_option_char ( XrmOption *xo, int is_term )
@@ -488,11 +524,13 @@ static void print_option_char ( XrmOption *xo, int is_term )
int l = strlen ( xo->name );
if ( is_term ) {
printf ( "\t"color_bold "-%s"color_reset " [character]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
- printf ( "\t\t"color_italic "%c"color_reset "\n", *( xo->value.charc ) );
+ printf ( "\t"color_italic "%c"color_reset, *( xo->value.charc ) );
+ printf ( " "color_green "(%s)"color_reset "\n", ConfigSourceStr[xo->source] );
}
else {
printf ( "\t-%s [character]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
- printf ( "\t\t%c\n", *( xo->value.charc ) );
+ printf ( "\t\t%c", *( xo->value.charc ) );
+ printf ( " (%s)\n", ConfigSourceStr[xo->source] );
}
}
static void print_option_boolean ( XrmOption *xo, int is_term )
@@ -500,11 +538,13 @@ static void print_option_boolean ( XrmOption *xo, int is_term )
int l = strlen ( xo->name );
if ( is_term ) {
printf ( "\t"color_bold "-[no-]%s"color_reset " %-*c%s\n", xo->name, 33 - l, ' ', xo->comment );
- printf ( "\t\t"color_italic "%s"color_reset "\n", ( *( xo->value.snum ) ) ? "True" : "False" );
+ printf ( "\t"color_italic "%s"color_reset, ( *( xo->value.snum ) ) ? "True" : "False" );
+ printf ( " "color_green "(%s)"color_reset "\n", ConfigSourceStr[xo->source] );
}
else {
printf ( "\t-[no-]%s %-*c%s\n", xo->name, 33 - l, ' ', xo->comment );
- printf ( "\t\t%s\n", ( *( xo->value.snum ) ) ? "True" : "False" );
+ printf ( "\t\t%s", ( *( xo->value.snum ) ) ? "True" : "False" );
+ printf ( " (%s)\n", ConfigSourceStr[xo->source] );
}
}