From dc7e4aa96e5fd6b3efd073d6b1d86606b0545bca Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 17 Feb 2017 14:06:31 +0100 Subject: [PATCH] Install some headers for use in plugins --- Makefile.am | 13 +++++++++++++ include/helper-theme.h | 29 +++++++++++++++++++++++++++++ include/helper.h | 28 ++++++++-------------------- include/view.h | 2 +- include/x11-helper.h | 1 + source/dialogs/drun.c | 34 ++-------------------------------- source/dialogs/run.c | 36 +----------------------------------- source/dialogs/ssh.c | 1 + source/helper.c | 30 +++++++++++++++++++++++++++++- source/theme.c | 1 + source/view.c | 3 ++- source/widgets/textbox.c | 1 + 12 files changed, 89 insertions(+), 90 deletions(-) create mode 100644 include/helper-theme.h diff --git a/Makefile.am b/Makefile.am index 508244b0..92c997fa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,6 +20,12 @@ BUILT_SOURCES=\ lexer/theme-parser.c\ lexer/theme-lexer.c +rofiincludedir=${includedir}/rofi +rofiinclude_HEADERS=\ + include/mode.h\ + include/mode-private.h\ + include/settings.h\ + include/helper.h ## # Rofi the program @@ -69,6 +75,7 @@ SOURCES=\ include/view.h\ include/view-internal.h\ include/helper.h\ + include/helper-theme.h\ include/timings.h\ include/history.h\ include/theme.h\ @@ -260,6 +267,7 @@ helper_pidfile_SOURCES=\ include/mode-private.h\ source/helper.c\ include/helper.h\ + include/helper-theme.h\ include/xrmoptions.h\ source/xrmoptions.c\ source/x11-helper.c\ @@ -275,6 +283,7 @@ helper_tokenize_SOURCES=\ include/mode-private.h\ source/helper.c\ include/helper.h\ + include/helper-theme.h\ include/xrmoptions.h\ source/xrmoptions.c\ source/x11-helper.c\ @@ -335,6 +344,7 @@ textbox_test_SOURCES=\ include/widgets/textbox.h\ include/xrmoptions.h\ include/helper.h\ + include/helper-theme.h\ test/textbox-test.c helper_test_SOURCES=\ @@ -344,6 +354,7 @@ helper_test_SOURCES=\ include/mode-private.h\ source/helper.c\ include/helper.h\ + include/helper-theme.h\ include/xrmoptions.h\ source/xrmoptions.c\ source/x11-helper.c\ @@ -374,6 +385,7 @@ helper_expand_SOURCES=\ include/mode-private.h\ source/helper.c\ include/helper.h\ + include/helper-theme.h\ include/xrmoptions.h\ source/xrmoptions.c\ source/x11-helper.c\ @@ -393,6 +405,7 @@ helper_config_cmdline_parser_SOURCES=\ include/mode-private.h\ source/helper.c\ include/helper.h\ + include/helper-theme.h\ include/xrmoptions.h\ source/xrmoptions.c\ source/x11-helper.c\ diff --git a/include/helper-theme.h b/include/helper-theme.h new file mode 100644 index 00000000..d685a3fa --- /dev/null +++ b/include/helper-theme.h @@ -0,0 +1,29 @@ +#ifndef ROFI_HELPER_THEME_H +#define ROFI_HELPER_THEME_H +#include +#include "theme.h" +/** + * @defgroup HELPERS Helpers + * @{ + */ +/** + * @param th The ThemeHighlight + * @param tokens Array of regexes used for matching + * @param input The input string to find the matches on + * @param retv The Attribute list to update with matches + * + * Creates a set of pango attributes highlighting the matches found in the input string. + * + * @returns the updated retv list. + */ +PangoAttrList *helper_token_match_get_pango_attr ( ThemeHighlight th, GRegex **tokens, const char *input, PangoAttrList *retv ); + +/** + * @param pfd Pango font description to validate. + * @param font The name of the font to check. + * + * @returns true if font is valid. + */ +gboolean helper_validate_font ( PangoFontDescription *pfd, const char *font ); +/* @} */ +#endif // ROFI_HELPER_THEME_H diff --git a/include/helper.h b/include/helper.h index cd46eed8..cccc1a24 100644 --- a/include/helper.h +++ b/include/helper.h @@ -1,9 +1,5 @@ #ifndef ROFI_HELPER_H #define ROFI_HELPER_H -#include "rofi.h" - -#include -#include /** * @defgroup HELPERS Helpers */ @@ -197,18 +193,6 @@ char * rofi_force_utf8 ( gchar *data, ssize_t length ); */ char * rofi_latin_to_utf8_strdup ( const char *input, gssize length ); -/** - * @param th The ThemeHighlight - * @param tokens Array of regexes used for matching - * @param input The input string to find the matches on - * @param retv The Attribute list to update with matches - * - * Creates a set of pango attributes highlighting the matches found in the input string. - * - * @returns the updated retv list. - */ -PangoAttrList *token_match_get_pango_attr ( ThemeHighlight th, GRegex **tokens, const char *input, PangoAttrList *retv ); - /** * @param pattern The user input to match against. * @param plen Pattern length. @@ -235,11 +219,15 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st */ int utf8_strncmp ( const char *a, const char* b, size_t n ); + /** - * @param pfd Pango font description to validate. - * @param font The name of the font to check. + * @param wd The work directory (optional) + * @param cmd The cmd to execute + * @param run_in_term Indicate if command should be run in a terminal * - * @returns true if font is valid. + * Execute command. + * + * @returns FALSE On failure, TRUE on success */ -gboolean helper_validate_font ( PangoFontDescription *pfd, const char *font ); +int helper_execute_command ( const char *wd, const char *cmd, int run_in_term ); #endif // ROFI_HELPER_H diff --git a/include/view.h b/include/view.h index 1c9cec6d..817aeedb 100644 --- a/include/view.h +++ b/include/view.h @@ -1,6 +1,6 @@ #ifndef ROFI_VIEW_H #define ROFI_VIEW_H - +#include "mode.h" #include "xkb.h" /** diff --git a/include/x11-helper.h b/include/x11-helper.h index fadfcf5c..a40fde88 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "xkb.h" diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index 4415c3d3..03c842c2 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -50,36 +50,6 @@ #define DRUN_CACHE_FILE "rofi2.druncache" #define LOG_DOMAIN "Dialogs.DRun" -static inline int execsh ( const char *wd, const char *cmd, int run_in_term ) -{ - int retv = TRUE; - char **args = NULL; - int argc = 0; - if ( !cmd || !cmd[0] ) { - return 0; - } - if ( run_in_term ) { - helper_parse_setup ( config.run_shell_command, &args, &argc, "{cmd}", cmd, NULL ); - } - else { - helper_parse_setup ( config.run_command, &args, &argc, "{cmd}", cmd, NULL ); - } - GError *error = NULL; - g_spawn_async ( wd, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error ); - if ( error != NULL ) { - char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, error->message ); - rofi_view_error_dialog ( msg, FALSE ); - g_free ( msg ); - // print error. - g_error_free ( error ); - retv = FALSE; - } - - // Free the args list. - g_strfreev ( args ); - return retv; -} - /** * Store extra information about the entry. * Currently the executable and if it should run in terminal. @@ -201,7 +171,7 @@ static void exec_cmd_entry ( DRunModeEntry *e ) // Returns false if not found, if key not found, we don't want run in terminal. gboolean terminal = g_key_file_get_boolean ( e->key_file, "Desktop Entry", "Terminal", NULL ); - if ( execsh ( exec_path, fp, terminal ) ) { + if ( helper_execute_command ( exec_path, fp, terminal ) ) { char *path = g_build_filename ( cache_dir, DRUN_CACHE_FILE, NULL ); char *key = g_strdup_printf ( "%s:::%s", e->root, e->path ); history_set ( path, key ); @@ -462,7 +432,7 @@ static ModeMode drun_mode_result ( Mode *sw, int mretv, char **input, unsigned i exec_cmd_entry ( &( rmpd->entry_list[selected_line] ) ); } else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { - execsh ( NULL, *input, run_in_term ); + helper_execute_command ( NULL, *input, run_in_term ); } else if ( ( mretv & MENU_ENTRY_DELETE ) && selected_line < rmpd->cmd_list_length ) { if ( selected_line < rmpd->history_length ) { diff --git a/source/dialogs/run.c b/source/dialogs/run.c index bf55b77b..e9ba44c6 100644 --- a/source/dialogs/run.c +++ b/source/dialogs/run.c @@ -70,40 +70,6 @@ typedef struct unsigned int cmd_list_length; } RunModePrivateData; -/** - * @param cmd The cmd to execute - * @param run_in_term Indicate if command should be run in a terminal - * - * Execute command. - * - * @returns FALSE On failure, TRUE on success - */ -static inline int execsh ( const char *cmd, int run_in_term ) -{ - int retv = TRUE; - char **args = NULL; - int argc = 0; - if ( run_in_term ) { - helper_parse_setup ( config.run_shell_command, &args, &argc, "{cmd}", cmd, NULL ); - } - else { - helper_parse_setup ( config.run_command, &args, &argc, "{cmd}", cmd, NULL ); - } - GError *error = NULL; - g_spawn_async ( NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error ); - if ( error != NULL ) { - char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, error->message ); - rofi_view_error_dialog ( msg, FALSE ); - g_free ( msg ); - // print error. - g_error_free ( error ); - retv = FALSE; - } - - // Free the args list. - g_strfreev ( args ); - return retv; -} /** * @param cmd The cmd to execute @@ -126,7 +92,7 @@ static void exec_cmd ( const char *cmd, int run_in_term ) } char *path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL ); - if ( execsh ( lf_cmd, run_in_term ) ) { + if ( helper_execute_command ( NULL, lf_cmd, run_in_term ) ) { /** * This happens in non-critical time (After launching app) * It is allowed to be a bit slower. diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 9a0909a0..d2ffbed9 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -30,6 +30,7 @@ * @{ */ #include +#include #include #include diff --git a/source/helper.c b/source/helper.c index b6871c19..2bc2afa4 100644 --- a/source/helper.c +++ b/source/helper.c @@ -45,6 +45,7 @@ #include #include #include "helper.h" +#include "helper-theme.h" #include "settings.h" #include "x11-helper.h" #include "rofi.h" @@ -394,7 +395,7 @@ int find_arg_char ( const char * const key, char *val ) return FALSE; } -PangoAttrList *token_match_get_pango_attr ( ThemeHighlight th, GRegex **tokens, const char *input, PangoAttrList *retv ) +PangoAttrList *helper_token_match_get_pango_attr ( ThemeHighlight th, GRegex **tokens, const char *input, PangoAttrList *retv ) { // Do a tokenized match. if ( tokens ) { @@ -928,3 +929,30 @@ int utf8_strncmp ( const char* a, const char* b, size_t n ) g_free ( nb ); return r; } + +int helper_execute_command ( const char *wd, const char *cmd, int run_in_term ) +{ + int retv = TRUE; + char **args = NULL; + int argc = 0; + if ( run_in_term ) { + helper_parse_setup ( config.run_shell_command, &args, &argc, "{cmd}", cmd, NULL ); + } + else { + helper_parse_setup ( config.run_command, &args, &argc, "{cmd}", cmd, NULL ); + } + GError *error = NULL; + g_spawn_async ( wd, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error ); + if ( error != NULL ) { + char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, error->message ); + rofi_view_error_dialog ( msg, FALSE ); + g_free ( msg ); + // print error. + g_error_free ( error ); + retv = FALSE; + } + + // Free the args list. + g_strfreev ( args ); + return retv; +} diff --git a/source/theme.c b/source/theme.c index 47e7c4a0..7c49a9ae 100644 --- a/source/theme.c +++ b/source/theme.c @@ -8,6 +8,7 @@ #include "settings.h" #include "widgets/textbox.h" #include "view.h" +#include "rofi.h" /** Logging domain for theme */ #define LOG_DOMAIN "Theme" diff --git a/source/view.c b/source/view.c index d00a8b47..6067224d 100644 --- a/source/view.c +++ b/source/view.c @@ -53,6 +53,7 @@ #include "xcb-internal.h" #include "xkb-internal.h" #include "helper.h" +#include "helper-theme.h" #include "x11-helper.h" #include "xrmoptions.h" #include "dialogs/dialogs.h" @@ -878,7 +879,7 @@ static void update_callback ( textbox *t, unsigned int index, void *udata, TextB } ThemeHighlight th = { HL_BOLD | HL_UNDERLINE, { 0.0, 0.0, 0.0, 0.0 } }; th = rofi_theme_get_highlight ( WIDGET ( t ), "highlight", th ); - token_match_get_pango_attr ( th, state->tokens, textbox_get_visible_text ( t ), list ); + helper_token_match_get_pango_attr ( th, state->tokens, textbox_get_visible_text ( t ), list ); textbox_set_pango_attributes ( t, list ); pango_attr_list_unref ( list ); } diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 5342a0f2..60c15313 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -32,6 +32,7 @@ #include "widgets/textbox.h" #include "keyb.h" #include "helper.h" +#include "helper-theme.h" #include "x11-helper.h" #include "mode.h" #include "view.h"