1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Add optional config file that overrides local Xresources

Rofi will look at XDG_CONFIG_USER_DIR/rofi/config and load this after the Xresources db on DISPLAY.
This can be overridden using the -config commandline option.
The file should be in the same format as the Xresources file.
This commit is contained in:
Dave Davenport 2016-01-03 13:30:43 +01:00
parent 4fbbce891b
commit bd3d472bec
5 changed files with 104 additions and 34 deletions

View file

@ -62,6 +62,7 @@
[ -regex ] [ -regex ]
[ -tokenize ] [ -tokenize ]
[ -threads *num* ] [ -threads *num* ]
[ -config *filename* ]
## DESCRIPTION ## DESCRIPTION
@ -99,12 +100,14 @@ The official website for `dmenu` can be found [here](http://tools.suckless.org/d
## OPTIONS ## OPTIONS
There are currently three methods of setting configuration options: There are currently four methods of setting configuration options (evaluated in order below):
* Compile time: edit config.c. This method is strongly discouraged. * Compile time: edit config.c. This method is strongly discouraged.
* Xresources: A method of storing key values in the Xserver. See * Xresources: A method of storing key values in the Xserver. See
[here](https://en.wikipedia.org/wiki/X_resources) for more information. [here](https://en.wikipedia.org/wiki/X_resources) for more information.
This is the recommended way of configuring **rofi**. This is the recommended way of configuring **rofi**.
* Configuration File: This uses the same format as the Xresources file.
By default it looks in `XDG_USER_CONFIG_DIR`/rofi/config, but can be overriden on commandline.
* Command-line options: Arguments passed to **rofi**. * Command-line options: Arguments passed to **rofi**.
The Xresources file expects options starting with `rofi.` followed by it's name. An Example to set the number of lines: The Xresources file expects options starting with `rofi.` followed by it's name. An Example to set the number of lines:
@ -222,6 +225,10 @@ Enable experimental fuzzy matching.
Filter the list by setting text in input bar to *filter* Filter the list by setting text in input bar to *filter*
`-config` *filename*
Load alternative configuration file.
### Theming ### Theming

View file

@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "ROFI\-MANPAGE" "" "December 2015" "" "" .TH "ROFI\-MANPAGE" "" "January 2016" "" ""
. .
.SH "NAME" .SH "NAME"
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement \fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
. .
.SH "SYNOPSIS" .SH "SYNOPSIS"
\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-fg \fIcolor\fR ] [ \-fg\-urgent \fIcolor\fR ] [ \-fg\-active \fIcolor\fR ] [ \-bg\-urgent \fIcolor\fR ] [ \-bg\-active \fIcolor\fR ] [ \-bg \fIcolor\fR ] [ \-bgalt \fIcolor\fR ] [ \-hlfg \fIcolor\fR ] [ \-hlbg \fIcolor\fR ] [ \-key\-\fBmode\fR \fIcombo\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bc \fIcolor\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] [ \-input \fIinput\fR ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help ] [ \-dump\-xresources ] [ \-dump\-xresources\-theme ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-no\-parse\-known\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-quiet ] [ \-glob ] [ \-regex ] [ \-tokenize ] [ \-threads \fInum\fR ] \fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-fg \fIcolor\fR ] [ \-fg\-urgent \fIcolor\fR ] [ \-fg\-active \fIcolor\fR ] [ \-bg\-urgent \fIcolor\fR ] [ \-bg\-active \fIcolor\fR ] [ \-bg \fIcolor\fR ] [ \-bgalt \fIcolor\fR ] [ \-hlfg \fIcolor\fR ] [ \-hlbg \fIcolor\fR ] [ \-key\-\fBmode\fR \fIcombo\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bc \fIcolor\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] [ \-input \fIinput\fR ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help ] [ \-dump\-xresources ] [ \-dump\-xresources\-theme ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-no\-parse\-known\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-quiet ] [ \-glob ] [ \-regex ] [ \-tokenize ] [ \-threads \fInum\fR ] [ \-config \fIfilename\fR ]
. .
.SH "DESCRIPTION" .SH "DESCRIPTION"
\fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\. \fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\.
@ -51,7 +51,7 @@ Keybindings can also be specified in the \fBXresources\fR file\.
The official website for \fBdmenu\fR can be found here \fIhttp://tools\.suckless\.org/dmenu/\fR\. The official website for \fBdmenu\fR can be found here \fIhttp://tools\.suckless\.org/dmenu/\fR\.
. .
.SH "OPTIONS" .SH "OPTIONS"
There are currently three methods of setting configuration options: There are currently four methods of setting configuration options (evaluated in order below):
. .
.IP "\(bu" 4 .IP "\(bu" 4
Compile time: edit config\.c\. This method is strongly discouraged\. Compile time: edit config\.c\. This method is strongly discouraged\.
@ -60,6 +60,9 @@ Compile time: edit config\.c\. This method is strongly discouraged\.
Xresources: A method of storing key values in the Xserver\. See here \fIhttps://en\.wikipedia\.org/wiki/X_resources\fR for more information\. This is the recommended way of configuring \fBrofi\fR\. Xresources: A method of storing key values in the Xserver\. See here \fIhttps://en\.wikipedia\.org/wiki/X_resources\fR for more information\. This is the recommended way of configuring \fBrofi\fR\.
. .
.IP "\(bu" 4 .IP "\(bu" 4
Configuration File: This uses the same format as the Xresources file\. By default it looks in \fBXDG_USER_CONFIG_DIR\fR/rofi/config, but can be overriden on commandline\.
.
.IP "\(bu" 4
Command\-line options: Arguments passed to \fBrofi\fR\. Command\-line options: Arguments passed to \fBrofi\fR\.
. .
.IP "" 0 .IP "" 0
@ -316,6 +319,12 @@ Enable experimental fuzzy matching\.
.P .P
Filter the list by setting text in input bar to \fIfilter\fR Filter the list by setting text in input bar to \fIfilter\fR
. .
.P
\fB\-config\fR \fIfilename\fR
.
.P
Load alternative configuration file\.
.
.SS "Theming" .SS "Theming"
All colors are either hex #rrggbb values or X11 color names\. \fB\-bg\fR All colors are either hex #rrggbb values or X11 color names\. \fB\-bg\fR
. .

View file

@ -19,6 +19,7 @@ typedef enum
* connected X server. * connected X server.
*/ */
void config_parse_xresource_options ( Display *display ); void config_parse_xresource_options ( Display *display );
void config_parse_xresource_options_file ( const char *filename );
/** /**
* Parse commandline options. * Parse commandline options.
@ -35,6 +36,7 @@ void config_parse_cmd_options_dynamic ( void );
* connected X server. * connected X server.
*/ */
void config_parse_xresource_options_dynamic ( Display *display ); void config_parse_xresource_options_dynamic ( Display *display );
void config_parse_xresource_options_dynamic_file ( const char *filename );
/** /**
* Free any allocated memory. * Free any allocated memory.

View file

@ -80,6 +80,7 @@ SnDisplay *sndisplay = NULL;
SnLauncheeContext *sncontext = NULL; SnLauncheeContext *sncontext = NULL;
Display *display = NULL; Display *display = NULL;
char *display_str = NULL; char *display_str = NULL;
char *config_path = NULL;
Window main_window = None; Window main_window = None;
Colormap map = None; Colormap map = None;
unsigned int normal_window_mode = FALSE; unsigned int normal_window_mode = FALSE;
@ -2055,6 +2056,8 @@ static void cleanup ()
// Cleanup the custom keybinding // Cleanup the custom keybinding
cleanup_abe (); cleanup_abe ();
g_free ( config_path );
TIMINGS_STOP (); TIMINGS_STOP ();
} }
@ -2141,6 +2144,7 @@ static inline void load_configuration ( Display *display )
{ {
// Load in config from X resources. // Load in config from X resources.
config_parse_xresource_options ( display ); config_parse_xresource_options ( display );
config_parse_xresource_options_file ( config_path );
// Parse command line for settings. // Parse command line for settings.
config_parse_cmd_options ( ); config_parse_cmd_options ( );
@ -2149,6 +2153,7 @@ static inline void load_configuration_dynamic ( Display *display )
{ {
// Load in config from X resources. // Load in config from X resources.
config_parse_xresource_options_dynamic ( display ); config_parse_xresource_options_dynamic ( display );
config_parse_xresource_options_dynamic_file ( config_path );
config_parse_cmd_options_dynamic ( ); config_parse_cmd_options_dynamic ( );
} }
@ -2415,6 +2420,18 @@ 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 );

View file

@ -196,22 +196,12 @@ static void config_parser_set ( XrmOption *option, XrmValue *xrmValue )
} }
} }
void config_parse_xresource_options ( Display *display ) static void __config_parse_xresource_options ( XrmDatabase xDB )
{ {
char *xRMS; char * xrmType;
// Map Xresource entries to rofi config options. XrmValue xrmValue;
XrmInitialize (); const char * namePrefix = "rofi";
xRMS = XResourceManagerString ( display ); const char * classPrefix = "rofi";
if ( xRMS == NULL ) {
return;
}
XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
char * xrmType;
XrmValue xrmValue;
const char * namePrefix = "rofi";
const char * classPrefix = "rofi";
for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) { for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) {
char *name, *class; char *name, *class;
@ -226,6 +216,33 @@ void config_parse_xresource_options ( Display *display )
g_free ( class ); g_free ( class );
g_free ( name ); g_free ( name );
} }
}
void config_parse_xresource_options ( Display *display )
{
char *xRMS;
// Map Xresource entries to rofi config options.
XrmInitialize ();
xRMS = XResourceManagerString ( display );
if ( xRMS == NULL ) {
return;
}
XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
__config_parse_xresource_options ( xDB );
XrmDestroyDatabase ( xDB );
}
void config_parse_xresource_options_file ( const char *filename )
{
if ( !filename ) {
return;
}
// Map Xresource entries to rofi config options.
XrmInitialize ();
XrmDatabase xDB = XrmGetFileDatabase ( filename );
if ( xDB == NULL ) {
return;
}
__config_parse_xresource_options ( xDB );
XrmDestroyDatabase ( xDB ); XrmDestroyDatabase ( xDB );
} }
@ -289,22 +306,12 @@ void config_parse_cmd_options_dynamic ( void )
} }
} }
void config_parse_xresource_options_dynamic ( Display *display ) static void __config_parse_xresource_options_dynamic ( XrmDatabase xDB )
{ {
char *xRMS; char * xrmType;
// Map Xresource entries to rofi config options. XrmValue xrmValue;
XrmInitialize (); const char * namePrefix = "rofi";
xRMS = XResourceManagerString ( display ); const char * classPrefix = "rofi";
if ( xRMS == NULL ) {
return;
}
XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
char * xrmType;
XrmValue xrmValue;
const char * namePrefix = "rofi";
const char * classPrefix = "rofi";
for ( unsigned int i = 0; i < num_extra_options; ++i ) { for ( unsigned int i = 0; i < num_extra_options; ++i ) {
char *name, *class; char *name, *class;
@ -318,6 +325,34 @@ void config_parse_xresource_options_dynamic ( Display *display )
g_free ( class ); g_free ( class );
g_free ( name ); g_free ( name );
} }
}
void config_parse_xresource_options_dynamic ( Display *display )
{
char *xRMS;
// Map Xresource entries to rofi config options.
XrmInitialize ();
xRMS = XResourceManagerString ( display );
if ( xRMS == NULL ) {
return;
}
XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
__config_parse_xresource_options_dynamic ( xDB );
XrmDestroyDatabase ( xDB );
}
void config_parse_xresource_options_dynamic_file ( const char *filename )
{
if ( !filename ) {
return;
}
// Map Xresource entries to rofi config options.
XrmInitialize ();
XrmDatabase xDB = XrmGetFileDatabase ( filename );
if ( xDB == NULL ) {
return;
}
__config_parse_xresource_options_dynamic ( xDB );
XrmDestroyDatabase ( xDB ); XrmDestroyDatabase ( xDB );
} }