From c549c4f72d1c45049279b76272bba354e88d51a4 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Wed, 5 Nov 2014 10:52:10 +0100 Subject: [PATCH] Reload configuration in daemon mode on SIGHUP --- doc/rofi-manpage.markdown | 6 +++++ doc/rofi.1 | 9 +++++++ source/rofi.c | 57 +++++++++++++++++++++++++++++++++------ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index aea63610..d0378ed6 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -337,6 +337,12 @@ This way it can be used as a drop-in replacement for dmenu. just copy or symlink ln -s /usr/bin/dmenu /usr/bin/rofi +## Signals + +`HUP` + + If in daemon mode, reload the configuration from Xresources. (arguments still override). + ## Keybindings Rofi supports the following keybindings: diff --git a/doc/rofi.1 b/doc/rofi.1 index 3e343ec8..93edca79 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -422,6 +422,15 @@ This way it can be used as a drop\-in replacement for dmenu. just copy or symlin ln \-s /usr/bin/dmenu /usr/bin/rofi .fi .RE +.SH Signals +.PP +\fB\fCHUP\fR +.PP +.RS +.nf +If in daemon mode, reload the configuration from Xresources. (arguments still override). +.fi +.RE .SH Keybindings .PP Rofi supports the following keybindings: diff --git a/source/rofi.c b/source/rofi.c index 5682daa8..e6e25e7e 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -2397,9 +2397,52 @@ static void setup_switchers ( void ) g_free ( switcher_str ); } +/** + * Keep a copy of arc, argv around, so we can use the same parsing method + */ +int stored_argc; +char **stored_argv; + +/** + * @param display Pointer to the X connection to use. + * Load configuration. + * Following priority: (current), X, commandline arguments + */ +static inline void load_configuration ( Display *display ) +{ + // Load in config from X resources. + parse_xresource_options ( display ); + + // Parse command line for settings. + parse_cmd_options ( stored_argc, stored_argv ); + + // Sanity check + config_sanity_check (); +} + +/** + * Handle sighub request. + * Currently we just reload the configuration. + */ +static void hup_action_handler ( int num ) +{ + /** + * Open new connection to X. It seems the XResources do not get updated + * on the old connection. + */ + Display *display = XOpenDisplay ( display_str ); + if ( display ) { + load_configuration ( display ); + XCloseDisplay ( display ); + } +} + int main ( int argc, char *argv[] ) { + stored_argc = argc; + stored_argv = argv; + // Get the path to the cache dir. cache_dir = g_get_user_cache_dir (); @@ -2415,14 +2458,7 @@ int main ( int argc, char *argv[] ) return EXIT_FAILURE; } - // Load in config from X resources. - parse_xresource_options ( display ); - - // Parse command line for settings. - parse_cmd_options ( argc, argv ); - - // Sanity check - config_sanity_check (); + load_configuration ( display ); // setup_switchers setup_switchers (); @@ -2539,6 +2575,11 @@ int main ( int argc, char *argv[] ) grab_key ( display, sshdialog_modmask, sshdialog_keysym ); } + // Setup handler for sighub (reload config) + const struct sigaction hup_action = { hup_action_handler, }; + sigaction ( SIGHUP, &hup_action, NULL ); + + // Main loop for (;; ) { XEvent ev;