rofi 2.0.0
rofi.c File Reference
#include "config.h"
#include <errno.h>
#include <gmodule.h>
#include <locale.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sysexits.h>
#include <time.h>
#include <unistd.h>
#include <glib-unix.h>
#include "resources.h"
#include "display.h"
#include "rofi.h"
#include "settings.h"
#include "helper.h"
#include "mode.h"
#include "modes/modes.h"
#include "widgets/textbox.h"
#include "xrmoptions.h"
#include "view-internal.h"
#include "view.h"
#include "rofi-icon-fetcher.h"
#include "theme.h"
#include "timings.h"
Include dependency graph for rofi.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "Rofi"

Functions

static void rofi_collectmodes_destroy (void)
void rofi_add_error_message (GString *str)
void rofi_clear_error_messages (void)
void rofi_add_warning_message (GString *str)
void rofi_clear_warning_messages (void)
void process_result (RofiViewState *state)
void rofi_set_return_code (int code)
unsigned int rofi_get_num_enabled_modes (void)
const Moderofi_get_mode (unsigned int index)
static int mode_lookup (const char *name)
static const Modemode_available_lookup (const char *name)
static void teardown (int pfd)
static void run_mode_index (ModeMode mode)
static void print_list_of_modes (int is_term)
static void print_main_application_options (int is_term)
static void print_backend_info ()
static void help (G_GNUC_UNUSED int argc, char **argv, const gboolean compact)
static void help_print_disabled_mode (const char *mode)
static void help_print_mode_not_found (const char *mode)
static void help_print_no_arguments (void)
static void cleanup (void)
Moderofi_collect_modes_search (const char *name)
static gboolean rofi_collectmodes_add (Mode *mode)
static void rofi_collectmodes_dir (const char *base_dir)
static void rofi_collect_modes (void)
static void rofi_collectmodes_setup (void)
static int add_mode (const char *token)
static gboolean setup_modes (void)
void rofi_quit_main_loop (void)
static gboolean main_loop_signal_handler_int (G_GNUC_UNUSED gpointer data)
static void show_error_dialog (void)
static gboolean startup (G_GNUC_UNUSED gpointer data)
static gboolean take_screenshot_quit (G_GNUC_UNUSED void *data)
static gboolean record (G_GNUC_UNUSED void *data)
static void rofi_custom_log_function (const char *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level, const gchar *message, gpointer user_data)
int main (int argc, char *argv[])
int rofi_theme_rasi_validate (const char *filename)
const Moderofi_get_completer (void)

Variables

char * pidfile = NULL
const char * cache_dir = NULL
char * cache_dir_alloc = NULL
GList * list_of_error_msgs = NULL
GList * list_of_warning_msgs = NULL
G_MODULE_EXPORT char * config_path = NULL
Mode ** modes = NULL
Mode ** available_modes = NULL
unsigned int num_available_modes = 0
unsigned int num_modes = 0
unsigned int curr_mode = 0
NkBindings * bindings = NULL
gboolean display_setup_success = FALSE
GMainLoop * main_loop = NULL
int rofi_is_in_dmenu_mode = FALSE
int return_code = EXIT_SUCCESS

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "Rofi"

Log domain

Definition at line 30 of file rofi.c.

Function Documentation

◆ add_mode()

int add_mode ( const char * token)
static

Parse the mode string, into internal array of type Mode.

String is split on separator ',' First the three build-in modes are checked: window, run, ssh if that fails, a script-mode is created.

Definition at line 748 of file rofi.c.

References mode_set_config(), modes, num_modes, rofi_collect_modes_search(), rofi_collectmodes_add(), script_mode_is_valid(), and script_mode_parse_setup().

Referenced by setup_modes(), and startup().

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

◆ cleanup()

void cleanup ( void )
static

◆ help()

void help ( G_GNUC_UNUSED int argc,
char ** argv,
const gboolean compact )
static

◆ help_print_disabled_mode()

void help_print_disabled_mode ( const char * mode)
static

Definition at line 492 of file rofi.c.

References color_green, color_red, color_reset, and config.

Referenced by startup().

Here is the caller graph for this function:

◆ help_print_mode_not_found()

void help_print_mode_not_found ( const char * mode)
static

Definition at line 505 of file rofi.c.

References available_modes, mode_get_name(), modes, num_available_modes, num_modes, and rofi_add_error_message().

Referenced by setup_modes(), and startup().

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

◆ help_print_no_arguments()

void help_print_no_arguments ( void )
static

Definition at line 522 of file rofi.c.

References available_modes, ERROR_MSG_MARKUP, mode_get_name(), modes, num_available_modes, num_modes, rofi_set_return_code(), and rofi_view_error_dialog().

Referenced by startup().

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

◆ main()

int main ( int argc,
char * argv[] )
Parameters
argcnumber of input arguments.
argvarray of the input arguments.

Main application entry point.

Returns
return code of rofi.

default configuration

New format.

New format.

dirty hack for dmenu compatibility

Make small commandline changes to the current theme.

Definition at line 942 of file rofi.c.

References abe_list_all_bindings(), bindings, cache_dir, cache_dir_alloc, cleanup(), cmd_set_arguments(), color_bold, color_reset, config, config_parse_cmd_options(), config_parse_dump_config_rasi_format(), config_parser_add_option(), config_path, create_pid_file(), display_init(), display_late_setup(), display_scale(), display_setup(), display_setup_success, DISPLAY_WAYLAND, DISPLAY_XCB, find_arg(), find_arg_str(), find_arg_strv(), find_arg_uint(), help(), helper_get_theme_path(), list_of_error_msgs, main_loop, main_loop_signal_handler_int(), parse_keys_abe(), pidfile, proxy, record(), return_code, rofi_collect_modes(), rofi_collectmodes_setup(), rofi_configuration, rofi_custom_log_function(), rofi_expand_path(), rofi_icon_fetcher_init(), rofi_is_in_dmenu_mode, rofi_theme, rofi_theme_free(), rofi_theme_parse_file(), rofi_theme_parse_process_conditionals(), rofi_theme_parse_process_links(), rofi_theme_parse_string(), rofi_theme_print(), rofi_theme_rasi_validate(), rofi_theme_reset(), rofi_theme_set_disp_scale_func(), rofi_view_workers_initialize(), setup_abe(), setup_modes(), startup(), take_screenshot_quit(), teardown(), textbox_setup(), TICK, TICK_N, TIMINGS_START, wayland_proxy, xcb_proxy, and xrm_String.

Here is the call graph for this function:

◆ main_loop_signal_handler_int()

gboolean main_loop_signal_handler_int ( G_GNUC_UNUSED gpointer data)
static

Definition at line 793 of file rofi.c.

References main_loop.

Referenced by main().

Here is the caller graph for this function:

◆ mode_available_lookup()

const Mode * mode_available_lookup ( const char * name)
static
Parameters
nameName of the mode to lookup.

Find the index of the mode with name.

Returns
index of the mode in modes, -1 if not found.

Definition at line 179 of file rofi.c.

References available_modes, mode_get_name(), and num_available_modes.

Referenced by rofi_get_completer().

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

◆ mode_lookup()

int mode_lookup ( const char * name)
static
Parameters
nameName of the mode to lookup.

Find the index of the mode with name.

Returns
index of the mode in modes, -1 if not found.

Definition at line 164 of file rofi.c.

References mode_get_name(), modes, and num_modes.

Referenced by startup().

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

◆ print_backend_info()

void print_backend_info ( )
static

Definition at line 359 of file rofi.c.

References color_bold, color_reset, config, DISPLAY_WAYLAND, and DISPLAY_XCB.

Referenced by help().

Here is the caller graph for this function:

◆ print_list_of_modes()

void print_list_of_modes ( int is_term)
static

Help function.

Definition at line 299 of file rofi.c.

References available_modes, color_green, color_red, color_reset, mode_get_name(), modes, num_available_modes, and num_modes.

Referenced by help().

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

◆ print_main_application_options()

void print_main_application_options ( int is_term)
static

Definition at line 313 of file rofi.c.

References print_help_msg().

Referenced by help().

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

◆ process_result()

void process_result ( RofiViewState * state)
Parameters
stateThe Menu Handle

Check if a finalize function is set, and if sets executes it.

Load in the new mode.

Definition at line 238 of file rofi.c.

References curr_mode, MODE_EXIT, mode_result(), modes, NEXT_DIALOG, num_modes, PREVIOUS_DIALOG, RELOAD_DIALOG, RESET_DIALOG, rofi_view_clear_input(), rofi_view_free(), rofi_view_get_return_value(), rofi_view_get_selected_line(), rofi_view_get_user_input(), rofi_view_remove_active(), rofi_view_switch_mode(), RofiViewState::sw, RofiViewState::text, textbox_cursor_end(), and textbox_text().

Referenced by rofi_view_error_dialog(), and run_mode_index().

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

◆ record()

gboolean record ( G_GNUC_UNUSED void * data)
static

Definition at line 923 of file rofi.c.

References rofi_capture_screenshot().

Referenced by main().

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

◆ rofi_collect_modes()

void rofi_collect_modes ( void )
static

Find all available modes.

Definition at line 676 of file rofi.c.

References combi_mode, config, DISPLAY_WAYLAND, DISPLAY_XCB, file_browser_mode, find_arg(), find_arg_str(), help_keys_mode, recursive_browser_mode, rofi_collectmodes_add(), rofi_collectmodes_dir(), run_mode, script_mode_gather_user_scripts(), and ssh_mode.

Referenced by main().

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

◆ rofi_collectmodes_add()

gboolean rofi_collectmodes_add ( Mode * mode)
static
Parameters
modeAdd mode to list.
Returns
TRUE when success.

Definition at line 619 of file rofi.c.

References available_modes, mode_get_name(), num_available_modes, and rofi_collect_modes_search().

Referenced by add_mode(), rofi_collect_modes(), and rofi_collectmodes_dir().

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

◆ rofi_collectmodes_destroy()

void rofi_collectmodes_destroy ( void )
static

Definition at line 725 of file rofi.c.

References available_modes, mode_free(), mode_plugin_get_module(), and num_available_modes.

Referenced by cleanup().

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

◆ rofi_collectmodes_dir()

void rofi_collectmodes_dir ( const char * base_dir)
static

Definition at line 632 of file rofi.c.

References ABI_VERSION, mode_get_abi_version(), mode_plugin_set_module(), and rofi_collectmodes_add().

Referenced by rofi_collect_modes().

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

◆ rofi_collectmodes_setup()

void rofi_collectmodes_setup ( void )
static

Setup configuration for config.

Definition at line 720 of file rofi.c.

References available_modes, mode_set_config(), and num_available_modes.

Referenced by main().

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

◆ rofi_custom_log_function()

void rofi_custom_log_function ( const char * log_domain,
G_GNUC_UNUSED GLogLevelFlags log_level,
const gchar * message,
gpointer user_data )
static

Definition at line 927 of file rofi.c.

Referenced by main().

Here is the caller graph for this function:

◆ rofi_theme_rasi_validate()

int rofi_theme_rasi_validate ( const char * filename)
Parameters
filenameThe file to validate.
Returns
the program exit code.

Definition at line 1346 of file rofi.c.

References list_of_error_msgs, list_of_warning_msgs, rofi_theme_parse_file(), and rofi_theme_parse_process_links().

Referenced by main().

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

◆ run_mode_index()

void run_mode_index ( ModeMode mode)
static

Definition at line 204 of file rofi.c.

References config, curr_mode, ERROR_MSG_MARKUP, find_arg(), find_arg_uint(), main_loop, mode_get_name(), mode_init(), modes, num_modes, process_result(), rofi_view_create(), rofi_view_error_dialog(), rofi_view_get_active(), rofi_view_set_active(), and rofi_view_set_selected_line().

Referenced by startup().

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

◆ setup_modes()

gboolean setup_modes ( void )
static

Definition at line 770 of file rofi.c.

References add_mode(), config, and help_print_mode_not_found().

Referenced by main().

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

◆ show_error_dialog()

void show_error_dialog ( void )
static

Definition at line 798 of file rofi.c.

References ERROR_MSG_MARKUP, list_of_error_msgs, rofi_set_return_code(), and rofi_view_error_dialog().

Referenced by startup().

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

◆ startup()

◆ take_screenshot_quit()

gboolean take_screenshot_quit ( G_GNUC_UNUSED void * data)
static

Definition at line 918 of file rofi.c.

References rofi_capture_screenshot(), and rofi_quit_main_loop().

Referenced by main().

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

◆ teardown()

void teardown ( int pfd)
static

Teardown the gui.

Definition at line 191 of file rofi.c.

References display_early_cleanup(), remove_pid_file(), rofi_view_cleanup(), and textbox_cleanup().

Referenced by main().

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

Variable Documentation

◆ available_modes

◆ bindings

NkBindings* bindings = NULL

Handle to NkBindings object for input devices.

Definition at line 136 of file rofi.c.

Referenced by cleanup(), display_init(), display_setup(), main(), parse_keys_abe(), wayland_display_setup(), and xcb_display_setup().

◆ cache_dir_alloc

char* cache_dir_alloc = NULL

if the cache_dir string is allocated, keep pointer here so it can be freed.

Definition at line 85 of file rofi.c.

Referenced by cleanup(), and main().

◆ config_path

G_MODULE_EXPORT char* config_path = NULL

Path to the configuration file

Definition at line 121 of file rofi.c.

Referenced by cleanup(), help(), and main().

◆ curr_mode

unsigned int curr_mode = 0

Current selected mode

Definition at line 133 of file rofi.c.

Referenced by process_result(), and run_mode_index().

◆ display_setup_success

gboolean display_setup_success = FALSE

Switches to TRUE when display is set up and ready

Definition at line 139 of file rofi.c.

Referenced by help(), and main().

◆ list_of_error_msgs

GList * list_of_error_msgs = NULL

List of error messages.

Definition at line 88 of file rofi.c.

Referenced by main(), rofi_add_error_message(), rofi_clear_error_messages(), rofi_theme_rasi_validate(), show_error_dialog(), and startup().

◆ list_of_warning_msgs

GList* list_of_warning_msgs = NULL

List of warning messages for the user.

Definition at line 90 of file rofi.c.

Referenced by rofi_add_warning_message(), rofi_clear_warning_messages(), rofi_theme_rasi_validate(), rofi_view_reload_message_bar(), and startup().

◆ main_loop

◆ modes

Mode** modes = NULL

Path to the configuration file in the new format Array holding all activated modes.

Definition at line 124 of file rofi.c.

Referenced by add_mode(), cleanup(), help_print_mode_not_found(), help_print_no_arguments(), mode_lookup(), print_list_of_modes(), process_result(), rofi_get_mode(), and run_mode_index().

◆ num_available_modes

◆ num_modes

unsigned int num_modes = 0

◆ pidfile

char* pidfile = NULL

Location of pidfile for this instance.

Definition at line 80 of file rofi.c.

Referenced by create_pid_file(), and main().

◆ return_code

int return_code = EXIT_SUCCESS

Rofi's return code

Definition at line 147 of file rofi.c.

Referenced by main(), and rofi_set_return_code().

◆ rofi_is_in_dmenu_mode

int rofi_is_in_dmenu_mode = FALSE

Flag indicating we are in dmenu mode.

Definition at line 145 of file rofi.c.

Referenced by main(), and startup().