rofi  1.7.0
drun.c File Reference
#include <config.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "dialogs/drun.h"
#include "dialogs/filebrowser.h"
#include "helper.h"
#include "history.h"
#include "mode-private.h"
#include "rofi.h"
#include "settings.h"
#include "timings.h"
#include "widgets/textbox.h"
#include "xcb.h"
#include "rofi-icon-fetcher.h"
Include dependency graph for drun.c:

Go to the source code of this file.

Data Structures

struct  DRunModeEntry
 
struct  DRunEntryField
 
struct  _DRunModePrivateData
 
struct  RegexEvalArg
 

Macros

#define G_LOG_DOMAIN   "Dialogs.DRun"
 
#define DRUN_CACHE_FILE   "rofi3.druncache"
 
#define DRUN_DESKTOP_CACHE_FILE   "rofi-drun-desktop.cache"
 
#define CACHE_VERSION   2
 

Typedefs

typedef struct _DRunModePrivateData DRunModePrivateData
 

Enumerations

enum  DRunDesktopEntryType {
  DRUN_DESKTOP_ENTRY_TYPE_UNDETERMINED = 0 , DRUN_DESKTOP_ENTRY_TYPE_APPLICATION , DRUN_DESKTOP_ENTRY_TYPE_LINK , DRUN_DESKTOP_ENTRY_TYPE_SERVICE ,
  DRUN_DESKTOP_ENTRY_TYPE_DIRECTORY
}
 
enum  DRunMatchingFields {
  DRUN_MATCH_FIELD_NAME , DRUN_MATCH_FIELD_GENERIC , DRUN_MATCH_FIELD_EXEC , DRUN_MATCH_FIELD_CATEGORIES ,
  DRUN_MATCH_FIELD_KEYWORDS , DRUN_MATCH_FIELD_COMMENT , DRUN_MATCH_NUM_FIELDS
}
 

Functions

static gboolean drun_helper_eval_cb (const GMatchInfo *info, GString *res, gpointer data)
 
static void launch_link_entry (DRunModeEntry *e)
 
static void exec_cmd_entry (DRunModeEntry *e, const char *path)
 
static gboolean rofi_strv_contains (const char *const *categories, const char *const *field)
 
static void read_desktop_file (DRunModePrivateData *pd, const char *root, const char *path, const gchar *basename, const char *action)
 
static void walk_dir (DRunModePrivateData *pd, const char *root, const char *dirname)
 
static void delete_entry_history (const DRunModeEntry *entry)
 
static void get_apps_history (DRunModePrivateData *pd)
 
static gint drun_int_sort_list (gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer user_data)
 
static void drun_write_str (FILE *fd, const char *str)
 
static void drun_write_integer (FILE *fd, int32_t val)
 
static void drun_read_integer (FILE *fd, int32_t *type)
 
static void drun_read_string (FILE *fd, char **str)
 
static void drun_write_strv (FILE *fd, char **str)
 
static void drun_read_stringv (FILE *fd, char ***str)
 
static void write_cache (DRunModePrivateData *pd, const char *cache_file)
 
static gboolean drun_read_cache (DRunModePrivateData *pd, const char *cache_file)
 
static void get_apps (DRunModePrivateData *pd)
 
static void drun_mode_parse_entry_fields ()
 
static void drun_mode_parse_display_format ()
 
static int drun_mode_init (Mode *sw)
 
static void drun_entry_clear (DRunModeEntry *e)
 
static ModeMode drun_mode_result (Mode *sw, int mretv, char **input, unsigned int selected_line)
 
static void drun_mode_destroy (Mode *sw)
 
static char * _get_display_value (const Mode *sw, unsigned int selected_line, int *state, G_GNUC_UNUSED GList **list, int get_entry)
 
static cairo_surface_t * fallback_icon (DRunModePrivateData *pd, int height)
 
static cairo_surface_t * _get_icon (const Mode *sw, unsigned int selected_line, int height)
 
static char * drun_get_completion (const Mode *sw, unsigned int index)
 
static int drun_token_match (const Mode *data, rofi_int_matcher **tokens, unsigned int index)
 
static unsigned int drun_mode_get_num_entries (const Mode *sw)
 
static char * drun_get_message (const Mode *sw)
 

Variables

char * DRUN_GROUP_NAME = "Desktop Entry"
 
static DRunEntryField matching_entry_fields [DRUN_MATCH_NUM_FIELDS]
 
Mode drun_mode
 

Macro Definition Documentation

◆ CACHE_VERSION

#define CACHE_VERSION   2

Version of the DRUN cache file format.

Definition at line 831 of file drun.c.

◆ DRUN_CACHE_FILE

#define DRUN_CACHE_FILE   "rofi3.druncache"

The filename of the history cache file.

Definition at line 61 of file drun.c.

◆ DRUN_DESKTOP_CACHE_FILE

#define DRUN_DESKTOP_CACHE_FILE   "rofi-drun-desktop.cache"

The filename of the drun quick-load cache file.

Definition at line 64 of file drun.c.

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "Dialogs.DRun"

The log domain of this dialog.

Definition at line 29 of file drun.c.

Typedef Documentation

◆ DRunModePrivateData

The Internal data structure for the drun mode.

Definition at line 67 of file drun.c.

Enumeration Type Documentation

◆ DRunDesktopEntryType

Used to determine the type of desktop file.

Enumerator
DRUN_DESKTOP_ENTRY_TYPE_UNDETERMINED 

Unknown.

DRUN_DESKTOP_ENTRY_TYPE_APPLICATION 

Application

DRUN_DESKTOP_ENTRY_TYPE_LINK 

Link

DRUN_DESKTOP_ENTRY_TYPE_SERVICE 

KDE Service File

DRUN_DESKTOP_ENTRY_TYPE_DIRECTORY 

Directory

Definition at line 77 of file drun.c.

◆ DRunMatchingFields

The fields that can be displayed and used for matching

Enumerator
DRUN_MATCH_FIELD_NAME 

Name

DRUN_MATCH_FIELD_GENERIC 

Generic Name

DRUN_MATCH_FIELD_EXEC 

Exec

DRUN_MATCH_FIELD_CATEGORIES 

List of categories

DRUN_MATCH_FIELD_KEYWORDS 

List of keywords

DRUN_MATCH_FIELD_COMMENT 

Comment

DRUN_MATCH_NUM_FIELDS 

Number of DRunMatchingFields entries.

Definition at line 144 of file drun.c.

Function Documentation

◆ _get_display_value()

static char* _get_display_value ( const Mode sw,
unsigned int  selected_line,
int *  state,
G_GNUC_UNUSED GList **  list,
int  get_entry 
)
static

◆ _get_icon()

static cairo_surface_t* _get_icon ( const Mode sw,
unsigned int  selected_line,
int  height 
)
static

◆ delete_entry_history()

static void delete_entry_history ( const DRunModeEntry entry)
static
Parameters
entryThe command entry to remove from history

Remove command from history.

Definition at line 777 of file drun.c.

References cache_dir, DRunModeEntry::desktop_id, DRUN_CACHE_FILE, and history_remove().

Referenced by drun_mode_result().

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

◆ drun_entry_clear()

◆ drun_get_completion()

static char* drun_get_completion ( const Mode sw,
unsigned int  index 
)
static

Definition at line 1366 of file drun.c.

References _DRunModePrivateData::entry_list, DRunModeEntry::generic_name, mode_get_private_data(), and DRunModeEntry::name.

Here is the call graph for this function:

◆ drun_get_message()

◆ drun_helper_eval_cb()

static gboolean drun_helper_eval_cb ( const GMatchInfo *  info,
GString *  res,
gpointer  data 
)
static

Definition at line 228 of file drun.c.

References RegexEvalArg::e, DRunModeEntry::icon, DRunModeEntry::icon_name, DRunModeEntry::name, and DRunModeEntry::path.

Referenced by exec_cmd_entry().

Here is the caller graph for this function:

◆ drun_int_sort_list()

static gint drun_int_sort_list ( gconstpointer  a,
gconstpointer  b,
G_GNUC_UNUSED gpointer  user_data 
)
static

Definition at line 806 of file drun.c.

References DRunModeEntry::name, and DRunModeEntry::sort_index.

Referenced by get_apps().

Here is the caller graph for this function:

◆ drun_mode_destroy()

◆ drun_mode_get_num_entries()

static unsigned int drun_mode_get_num_entries ( const Mode sw)
static

◆ drun_mode_init()

◆ drun_mode_parse_display_format()

static void drun_mode_parse_display_format ( )
static

Definition at line 1091 of file drun.c.

References config, Settings::drun_display_format, DRUN_MATCH_NUM_FIELDS, DRunEntryField::enabled_match, and matching_entry_fields.

Referenced by drun_mode_init().

Here is the caller graph for this function:

◆ drun_mode_parse_entry_fields()

static void drun_mode_parse_entry_fields ( )
static

◆ drun_mode_result()

◆ drun_read_cache()

◆ drun_read_integer()

static void drun_read_integer ( FILE *  fd,
int32_t *  type 
)
static

Definition at line 844 of file drun.c.

Referenced by drun_read_cache().

Here is the caller graph for this function:

◆ drun_read_string()

static void drun_read_string ( FILE *  fd,
char **  str 
)
static

Definition at line 850 of file drun.c.

Referenced by drun_read_cache(), and drun_read_stringv().

Here is the caller graph for this function:

◆ drun_read_stringv()

static void drun_read_stringv ( FILE *  fd,
char ***  str 
)
static

Definition at line 874 of file drun.c.

References drun_read_string().

Referenced by drun_read_cache().

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

◆ drun_token_match()

◆ drun_write_integer()

static void drun_write_integer ( FILE *  fd,
int32_t  val 
)
static

Definition at line 841 of file drun.c.

Referenced by write_cache().

Here is the caller graph for this function:

◆ drun_write_str()

static void drun_write_str ( FILE *  fd,
const char *  str 
)
static

Definition at line 832 of file drun.c.

Referenced by drun_write_strv(), and write_cache().

Here is the caller graph for this function:

◆ drun_write_strv()

static void drun_write_strv ( FILE *  fd,
char **  str 
)
static

Definition at line 867 of file drun.c.

References drun_write_str().

Referenced by write_cache().

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

◆ exec_cmd_entry()

◆ fallback_icon()

static cairo_surface_t* fallback_icon ( DRunModePrivateData pd,
int  height 
)
static

Definition at line 1330 of file drun.c.

References Settings::application_fallback_icon, config, _DRunModePrivateData::fallback_icon_fetch_uid, rofi_icon_fetcher_get(), and rofi_icon_fetcher_query().

Referenced by _get_icon().

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

◆ get_apps()

static void get_apps ( DRunModePrivateData pd)
static

◆ get_apps_history()

static void get_apps_history ( DRunModePrivateData pd)
static

Definition at line 783 of file drun.c.

References cache_dir, _DRunModePrivateData::cmd_list_length, DRunModeEntry::desktop_id, DRUN_CACHE_FILE, _DRunModePrivateData::entry_list, history_get_list(), DRunModeEntry::sort_index, and TICK_N.

Referenced by get_apps().

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

◆ launch_link_entry()

static void launch_link_entry ( DRunModeEntry e)
static

◆ read_desktop_file()

◆ rofi_strv_contains()

static gboolean rofi_strv_contains ( const char *const *  categories,
const char *const *  field 
)
static

Definition at line 408 of file drun.c.

Referenced by read_desktop_file().

Here is the caller graph for this function:

◆ walk_dir()

static void walk_dir ( DRunModePrivateData pd,
const char *  root,
const char *  dirname 
)
static

Internal spider used to get list of executables.

Definition at line 714 of file drun.c.

References DRUN_GROUP_NAME, and read_desktop_file().

Referenced by get_apps().

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

◆ write_cache()

Variable Documentation

◆ DRUN_GROUP_NAME

char* DRUN_GROUP_NAME = "Desktop Entry"

The group name used in desktop files

Definition at line 67 of file drun.c.

Referenced by drun_entry_clear(), read_desktop_file(), and walk_dir().

◆ drun_mode

Mode drun_mode
Initial value:
= {.name = "drun",
.cfg_name_key = "display-drun",
._init = drun_mode_init,
._get_num_entries = drun_mode_get_num_entries,
._result = drun_mode_result,
._destroy = drun_mode_destroy,
._token_match = drun_token_match,
._get_message = drun_get_message,
._get_completion = drun_get_completion,
._get_display_value = _get_display_value,
._get_icon = _get_icon,
._preprocess_input = NULL,
.private_data = NULL,
.free = NULL}
static ModeMode drun_mode_result(Mode *sw, int mretv, char **input, unsigned int selected_line)
Definition: drun.c:1153
static char * _get_display_value(const Mode *sw, unsigned int selected_line, int *state, G_GNUC_UNUSED GList **list, int get_entry)
Definition: drun.c:1270
static cairo_surface_t * _get_icon(const Mode *sw, unsigned int selected_line, int height)
Definition: drun.c:1341
static char * drun_get_completion(const Mode *sw, unsigned int index)
Definition: drun.c:1366
static char * drun_get_message(const Mode *sw)
Definition: drun.c:1451
static int drun_token_match(const Mode *data, rofi_int_matcher **tokens, unsigned int index)
Definition: drun.c:1376
static unsigned int drun_mode_get_num_entries(const Mode *sw)
Definition: drun.c:1443
static int drun_mode_init(Mode *sw)
Definition: drun.c:1105
static void drun_mode_destroy(Mode *sw)
Definition: drun.c:1250

The DRun Mode interface.

Definition at line 1471 of file drun.c.

Referenced by get_apps(), and rofi_collect_modi().

◆ matching_entry_fields

DRunEntryField matching_entry_fields[DRUN_MATCH_NUM_FIELDS]
static

Stores what fields should be matched on user input. based on user setting.

Definition at line 163 of file drun.c.

Referenced by drun_mode_parse_display_format(), drun_mode_parse_entry_fields(), drun_token_match(), and read_desktop_file().