rofi  1.5.1
helper.c File Reference
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <pwd.h>
#include <ctype.h>
#include <pango/pango.h>
#include <pango/pango-fontmap.h>
#include <pango/pangocairo.h>
#include <librsvg/rsvg.h>
#include "display.h"
#include "xcb.h"
#include "helper.h"
#include "helper-theme.h"
#include "settings.h"
#include "rofi.h"
#include "view.h"
Include dependency graph for helper.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "Helper"
 
#define MIN3(a, b, c)   ( ( a ) < ( b ) ? ( ( a ) < ( c ) ? ( a ) : ( c ) ) : ( ( b ) < ( c ) ? ( b ) : ( c ) ) )
 
#define FUZZY_SCORER_MAX_LENGTH   256
 
#define MIN_SCORE   ( INT_MIN / 2 )
 
#define LEADING_GAP_SCORE   -4
 
#define GAP_SCORE   -5
 
#define WORD_START_SCORE   50
 
#define NON_WORD_SCORE   40
 
#define CAMEL_SCORE   ( WORD_START_SCORE + GAP_SCORE - 1 )
 
#define CONSECUTIVE_SCORE   ( WORD_START_SCORE + GAP_SCORE )
 
#define PATTERN_NON_START_MULTIPLIER   1
 
#define PATTERN_START_MULTIPLIER   2
 

Enumerations

enum  CharClass { LOWER, UPPER, DIGIT, NON_WORD }
 

Functions

void cmd_set_arguments (int argc, char **argv)
 
static gboolean helper_eval_cb (const GMatchInfo *info, GString *res, gpointer data)
 
int helper_parse_setup (char *string, char ***output, int *length,...)
 
void helper_tokenize_free (rofi_int_matcher **tokens)
 
static gchar * glob_to_regex (const char *input)
 
static gchar * fuzzy_to_regex (const char *input)
 
static GRegex * R (const char *s, int case_sensitive)
 
static rofi_int_matchercreate_regex (const char *input, int case_sensitive)
 
rofi_int_matcher ** helper_tokenize (const char *input, int case_sensitive)
 
int find_arg (const char *const key)
 
int find_arg_str (const char *const key, char **val)
 
const char ** find_arg_strv (const char *const key)
 
int find_arg_int (const char *const key, int *val)
 
int find_arg_uint (const char *const key, unsigned int *val)
 
char helper_parse_char (const char *arg)
 
int find_arg_char (const char *const key, char *val)
 
PangoAttrList * helper_token_match_get_pango_attr (RofiHighlightColorStyle th, rofi_int_matcher **tokens, const char *input, PangoAttrList *retv)
 
int helper_token_match (rofi_int_matcher *const *tokens, const char *input)
 
int execute_generator (const char *cmd)
 
int create_pid_file (const char *pidfile)
 
void remove_pid_file (int fd)
 
gboolean helper_validate_font (PangoFontDescription *pfd, const char *font)
 
int config_sanity_check (void)
 
char * rofi_expand_path (const char *input)
 
unsigned int levenshtein (const char *needle, const glong needlelen, const char *haystack, const glong haystacklen)
 
char * rofi_latin_to_utf8_strdup (const char *input, gssize length)
 
gchar * rofi_escape_markup (gchar *text)
 
char * rofi_force_utf8 (const gchar *data, ssize_t length)
 
static enum CharClass rofi_scorer_get_character_class (gunichar c)
 
static int rofi_scorer_get_score_for (enum CharClass prev, enum CharClass curr)
 
int rofi_scorer_fuzzy_evaluate (const char *pattern, glong plen, const char *str, glong slen)
 
int utf8_strncmp (const char *a, const char *b, size_t n)
 
gboolean helper_execute (const char *wd, char **args, const char *error_precmd, const char *error_cmd, RofiHelperExecuteContext *context)
 
gboolean helper_execute_command (const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context)
 
char * helper_get_theme_path (const char *file)
 
cairo_surface_t * cairo_image_surface_create_from_svg (const gchar *file, int height)
 
static void parse_pair (char *input, rofi_range_pair *item)
 
void parse_ranges (char *input, rofi_range_pair **list, unsigned int *length)
 
void rofi_output_formatted_line (const char *format, const char *string, int selected_line, const char *filter)
 

Variables

const char *const monitor_position_entries []
 
static int stored_argc = 0
 
static char ** stored_argv = NULL
 

Macro Definition Documentation

◆ CAMEL_SCORE

#define CAMEL_SCORE   ( WORD_START_SCORE + GAP_SCORE - 1 )

CamelCase score

Definition at line 799 of file helper.c.

Referenced by rofi_scorer_get_score_for().

◆ CONSECUTIVE_SCORE

#define CONSECUTIVE_SCORE   ( WORD_START_SCORE + GAP_SCORE )

Consecutive score

Definition at line 801 of file helper.c.

Referenced by rofi_scorer_fuzzy_evaluate().

◆ FUZZY_SCORER_MAX_LENGTH

#define FUZZY_SCORER_MAX_LENGTH   256

Max length of input to score.

Definition at line 787 of file helper.c.

Referenced by rofi_scorer_fuzzy_evaluate().

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "Helper"

Definition at line 29 of file helper.c.

◆ GAP_SCORE

#define GAP_SCORE   -5

gap score

Definition at line 793 of file helper.c.

Referenced by rofi_scorer_fuzzy_evaluate().

◆ LEADING_GAP_SCORE

#define LEADING_GAP_SCORE   -4

Leading gap score

Definition at line 791 of file helper.c.

Referenced by rofi_scorer_fuzzy_evaluate().

◆ MIN3

#define MIN3 (   a,
  b,
 
)    ( ( a ) < ( b ) ? ( ( a ) < ( c ) ? ( a ) : ( c ) ) : ( ( b ) < ( c ) ? ( b ) : ( c ) ) )

Return the minimum value of a,b,c

Definition at line 700 of file helper.c.

Referenced by levenshtein().

◆ MIN_SCORE

#define MIN_SCORE   ( INT_MIN / 2 )

minimum score

Definition at line 789 of file helper.c.

Referenced by rofi_scorer_fuzzy_evaluate().

◆ NON_WORD_SCORE

#define NON_WORD_SCORE   40

non-word score

Definition at line 797 of file helper.c.

Referenced by rofi_scorer_get_score_for().

◆ PATTERN_NON_START_MULTIPLIER

#define PATTERN_NON_START_MULTIPLIER   1

non-start multiplier

Definition at line 803 of file helper.c.

Referenced by rofi_scorer_fuzzy_evaluate().

◆ PATTERN_START_MULTIPLIER

#define PATTERN_START_MULTIPLIER   2

start multiplier

Definition at line 805 of file helper.c.

Referenced by rofi_scorer_fuzzy_evaluate().

◆ WORD_START_SCORE

#define WORD_START_SCORE   50

start of word score

Definition at line 795 of file helper.c.

Referenced by rofi_scorer_get_score_for().

Enumeration Type Documentation

◆ CharClass

enum CharClass

Character classification.

Enumerator
LOWER 
UPPER 
DIGIT 
NON_WORD 

Definition at line 810 of file helper.c.

Function Documentation

◆ cairo_image_surface_create_from_svg()

cairo_surface_t* cairo_image_surface_create_from_svg ( const gchar *  file,
int  height 
)
Parameters
fileThe file path
heightThe wanted height Gets a surface from an svg path
Returns
a cairo surface from an svg path

Rendering fails

Definition at line 1085 of file helper.c.

References config, and Settings::dpi.

◆ create_regex()

static rofi_int_matcher* create_regex ( const char *  input,
int  case_sensitive 
)
static

Definition at line 218 of file helper.c.

References config, fuzzy_to_regex(), glob_to_regex(), rofi_int_matcher_t::invert, Settings::matching_method, MM_FUZZY, MM_GLOB, MM_REGEX, R(), and rofi_int_matcher_t::regex.

Referenced by helper_tokenize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fuzzy_to_regex()

static gchar* fuzzy_to_regex ( const char *  input)
static

Definition at line 181 of file helper.c.

Referenced by create_regex().

Here is the caller graph for this function:

◆ glob_to_regex()

static gchar* glob_to_regex ( const char *  input)
static

Definition at line 164 of file helper.c.

Referenced by create_regex().

Here is the caller graph for this function:

◆ helper_eval_cb()

static gboolean helper_eval_cb ( const GMatchInfo *  info,
GString *  res,
gpointer  data 
)
static
Parameters
infoTo Match information on.
resThe string being generated.
dataUser data

Replace the entries. This function gets called by g_regex_replace_eval.

Returns
TRUE to stop replacement, FALSE to continue

Definition at line 88 of file helper.c.

Referenced by helper_parse_setup().

Here is the caller graph for this function:

◆ helper_execute()

gboolean helper_execute ( const char *  wd,
char **  args,
const char *  error_precmd,
const char *  error_cmd,
RofiHelperExecuteContext context 
)
Parameters
wdThe working directory.
argsThe arguments of the command to exec.
error_precmdPrefix to error message command.
error_cmdError message command
contextThe startup notification context, if any

Executes the command

Returns
TRUE when successful, FALSE when failed.

Definition at line 975 of file helper.c.

References display_startup_notification(), and rofi_view_error_dialog().

Referenced by execshssh(), and helper_execute_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ helper_execute_command()

gboolean helper_execute_command ( const char *  wd,
const char *  cmd,
gboolean  run_in_term,
RofiHelperExecuteContext context 
)
Parameters
wdThe work directory (optional)
cmdThe cmd to execute
run_in_termIndicate if command should be run in a terminal
contextThe startup notification context, if any

Execute command. If needed members of

Parameters
contextare NULL, they will be filled.
Returns
FALSE On failure, TRUE on success

Definition at line 1000 of file helper.c.

References RofiHelperExecuteContext::binary, RofiHelperExecuteContext::command, config, RofiHelperExecuteContext::description, helper_execute(), helper_parse_setup(), RofiHelperExecuteContext::name, Settings::run_command, and Settings::run_shell_command.

Referenced by exec_cmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ helper_get_theme_path()

char* helper_get_theme_path ( const char *  file)
Parameters
fileFile name passed to option.
Returns
path to theme or copy of filename if not found.

Definition at line 1034 of file helper.c.

References rofi_expand_path().

Here is the call graph for this function:

◆ parse_pair()

static void parse_pair ( char *  input,
rofi_range_pair item 
)
static

Definition at line 1129 of file helper.c.

References rofi_range_pair::start, and rofi_range_pair::stop.

Referenced by parse_ranges().

Here is the caller graph for this function:

◆ parse_ranges()

void parse_ranges ( char *  input,
rofi_range_pair **  list,
unsigned int *  length 
)

Ranges.

Parameters
inputString to parse
listList of ranges
lengthLength of list.

ranges

Definition at line 1148 of file helper.c.

References parse_pair().

Referenced by dmenu_mode_init(), and parse_header_entry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ R()

static GRegex* R ( const char *  s,
int  case_sensitive 
)
inlinestatic

Definition at line 213 of file helper.c.

Referenced by create_regex().

Here is the caller graph for this function:

◆ rofi_output_formatted_line()

void rofi_output_formatted_line ( const char *  format,
const char *  string,
int  selected_line,
const char *  filter 
)
Parameters
formatThe format string used. See below for possible syntax.
stringThe selected entry.
selected_lineThe selected line index.
filterThe entered filter.

Function that outputs the selected line in the user-specified format. Currently the following formats are supported:

  • i: Print the index (0-(N-1))
  • d: Print the index (1-N)
  • s: Print input string.
  • q: Print quoted input string.
  • f: Print the entered filter.
  • F: Print the entered filter, quoted

This functions outputs the formatted string to stdout, appends a newline (
) character and calls flush on the file descriptor.

Definition at line 1182 of file helper.c.

Referenced by dmenu_print_results(), and dmenu_switcher_dialog().

Here is the caller graph for this function:

◆ rofi_scorer_get_character_class()

static enum CharClass rofi_scorer_get_character_class ( gunichar  c)
static
Parameters
cThe character to determine class of
Returns
the class of the character c.

Definition at line 827 of file helper.c.

References DIGIT, LOWER, NON_WORD, and UPPER.

Referenced by rofi_scorer_fuzzy_evaluate().

Here is the caller graph for this function:

◆ rofi_scorer_get_score_for()

static int rofi_scorer_get_score_for ( enum CharClass  prev,
enum CharClass  curr 
)
static
Parameters
prevThe previous character.
currThe current character

Scrore the transition.

Returns
score of the transition.

Definition at line 849 of file helper.c.

References CAMEL_SCORE, DIGIT, LOWER, NON_WORD, NON_WORD_SCORE, UPPER, and WORD_START_SCORE.

Referenced by rofi_scorer_fuzzy_evaluate().

Here is the caller graph for this function:

◆ utf8_strncmp()

int utf8_strncmp ( const char *  a,
const char *  b,
size_t  n 
)
Parameters
aUTF-8 string to compare
bUTF-8 string to compare
nMaximum number of characters to compare

Compares the G_NORMALIZE_ALL_COMPOSE forms of the two strings.

Returns
less than, equal to, or greater than zero if the first n characters (not bytes) of a are found, respectively, to be less than, to match, or be greater than the first n characters (not bytes) of b.

Definition at line 963 of file helper.c.

Referenced by combi_mode_result(), and combi_preprocess_input().

Here is the caller graph for this function:

Variable Documentation

◆ monitor_position_entries

const char* const monitor_position_entries[]
Initial value:
= {
"on focused monitor",
"on focused window",
"at mouse pointer",
"on monitor with focused window",
"on monitor that has mouse pointer"
}

Textual description of positioning rofi.

Definition at line 61 of file helper.c.

Referenced by config_sanity_check().

◆ stored_argc

int stored_argc = 0
static

copy of the argc for use in commandline argument parser.

Definition at line 69 of file helper.c.

Referenced by cmd_set_arguments(), find_arg(), find_arg_char(), find_arg_int(), find_arg_str(), find_arg_strv(), and find_arg_uint().

◆ stored_argv

char** stored_argv = NULL
static

copy of the argv pointer for use in the commandline argument parser

Definition at line 71 of file helper.c.

Referenced by cmd_set_arguments(), find_arg(), find_arg_char(), find_arg_int(), find_arg_str(), find_arg_strv(), and find_arg_uint().