summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-01-03 13:30:43 +0100
committerDave Davenport <qball@gmpclient.org>2016-01-03 13:30:43 +0100
commitbd3d472bec60babf29cc84d98a35dd7b3edd200a (patch)
tree562356b9702f48265e885d617c2940b766b3086e
parent4fbbce891bba56171b5b6fc5d6442427bad56a75 (diff)
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.
-rw-r--r--doc/rofi-manpage.markdown9
-rw-r--r--doc/rofi.115
-rw-r--r--include/xrmoptions.h2
-rw-r--r--source/rofi.c17
-rw-r--r--source/xrmoptions.c95
5 files changed, 104 insertions, 34 deletions
diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown
index 7f7a8b19..f3fef5b6 100644
--- a/doc/rofi-manpage.markdown
+++ b/doc/rofi-manpage.markdown
@@ -62,6 +62,7 @@
[ -regex ]
[ -tokenize ]
[ -threads *num* ]
+[ -config *filename* ]
## DESCRIPTION
@@ -99,12 +100,14 @@ The official website for `dmenu` can be found [here](http://tools.suckless.org/d
## 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.
* Xresources: A method of storing key values in the Xserver. See
[here](https://en.wikipedia.org/wiki/X_resources) for more information.
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**.
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*
+`-config` *filename*
+
+Load alternative configuration file.
+
### Theming
diff --git a/doc/rofi.1 b/doc/rofi.1
index ebd5fe66..397e2fd2 100644
--- a/doc/rofi.1
+++ b/doc/rofi.1
@@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "ROFI\-MANPAGE" "" "December 2015" "" ""
+.TH "ROFI\-MANPAGE" "" "January 2016" "" ""
.
.SH "NAME"
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
.
.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"
\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\.
.
.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
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\.
.
.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\.
.
.IP "" 0
@@ -316,6 +319,12 @@ Enable experimental fuzzy matching\.
.P
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"
All colors are either hex #rrggbb values or X11 color names\. \fB\-bg\fR
.
diff --git a/include/xrmoptions.h b/include/xrmoptions.h
index f1d9d3aa..ab621cae 100644
--- a/include/xrmoptions.h
+++ b/include/xrmoptions.h
@@ -19,6 +19,7 @@ typedef enum
* connected X server.
*/
void config_parse_xresource_options ( Display *display );
+void config_parse_xresource_options_file ( const char *filename );
/**
* Parse commandline options.
@@ -35,6 +36,7 @@ void config_parse_cmd_options_dynamic ( void );
* connected X server.
*/
void config_parse_xresource_options_dynamic ( Display *display );
+void config_parse_xresource_options_dynamic_file ( const char *filename );
/**
* Free any allocated memory.
diff --git a/source/rofi.c b/source/rofi.c
index dc67ba5c..8c058c64 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -80,6 +80,7 @@ SnDisplay *sndisplay = NULL;
SnLauncheeContext *sncontext = NULL;
Display *display = NULL;
char *display_str = NULL;
+char *config_path = NULL;
Window main_window = None;
Colormap map = None;
unsigned int normal_window_mode = FALSE;
@@ -2055,6 +2056,8 @@ static void cleanup ()
// Cleanup the custom keybinding
cleanup_abe ();
+ g_free ( config_path );
+
TIMINGS_STOP ();
}
@@ -2141,6 +2144,7 @@ static inline void load_configuration ( Display *display )
{
// Load in config from X resources.
config_parse_xresource_options ( display );
+ config_parse_xresource_options_file ( config_path );
// Parse command line for settings.
config_parse_cmd_options ( );
@@ -2149,6 +2153,7 @@ static inline void load_configuration_dynamic ( Display *display )
{
// Load in config from X resources.
config_parse_xresource_options_dynamic ( display );
+ config_parse_xresource_options_dynamic_file ( config_path );
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" );
+ 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 ();
// Register cleanup function.
atexit ( cleanup );
diff --git a/source/xrmoptions.c b/source/xrmoptions.c
index d1b4d029..d81053a2 100644
--- a/source/xrmoptions.c
+++ b/source/xrmoptions.c
@@ -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;
- // Map Xresource entries to rofi config options.
- XrmInitialize ();
- xRMS = XResourceManagerString ( display );
-
- if ( xRMS == NULL ) {
- return;
- }
- XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
-
- char * xrmType;
- XrmValue xrmValue;
- const char * namePrefix = "rofi";
- const char * classPrefix = "rofi";
+ char * xrmType;
+ XrmValue xrmValue;
+ const char * namePrefix = "rofi";
+ const char * classPrefix = "rofi";
for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) {
char *name, *class;
@@ -226,6 +216,33 @@ void config_parse_xresource_options ( Display *display )
g_free ( class );
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 );
}
@@ -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;
- // Map Xresource entries to rofi config options.
- XrmInitialize ();
- xRMS = XResourceManagerString ( display );
-
- if ( xRMS == NULL ) {
- return;
- }
- XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
-
- char * xrmType;
- XrmValue xrmValue;
- const char * namePrefix = "rofi";
- const char * classPrefix = "rofi";
+ char * xrmType;
+ XrmValue xrmValue;
+ const char * namePrefix = "rofi";
+ const char * classPrefix = "rofi";
for ( unsigned int i = 0; i < num_extra_options; ++i ) {
char *name, *class;
@@ -318,6 +325,34 @@ void config_parse_xresource_options_dynamic ( Display *display )
g_free ( class );
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 );
}