Install some headers for use in plugins

This commit is contained in:
Dave Davenport 2017-02-17 14:06:31 +01:00
parent f7b4bebb9b
commit dc7e4aa96e
12 changed files with 89 additions and 90 deletions

View file

@ -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\

29
include/helper-theme.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef ROFI_HELPER_THEME_H
#define ROFI_HELPER_THEME_H
#include <pango/pango.h>
#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

View file

@ -1,9 +1,5 @@
#ifndef ROFI_HELPER_H
#define ROFI_HELPER_H
#include "rofi.h"
#include <pango/pango.h>
#include <theme.h>
/**
* @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

View file

@ -1,6 +1,6 @@
#ifndef ROFI_VIEW_H
#define ROFI_VIEW_H
#include "mode.h"
#include "xkb.h"
/**

View file

@ -3,6 +3,7 @@
#include <glib.h>
#include <cairo.h>
#include <xcb/xcb.h>
#include <xkbcommon/xkbcommon.h>
#include "xkb.h"

View file

@ -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 ) {

View file

@ -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.

View file

@ -30,6 +30,7 @@
* @{
*/
#include <config.h>
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>

View file

@ -45,6 +45,7 @@
#include <pango/pango-fontmap.h>
#include <pango/pangocairo.h>
#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;
}

View file

@ -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"

View file

@ -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 );
}

View file

@ -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"