30#define G_LOG_DOMAIN "Rofi"
47#include <libgwater-xcb.h>
49#ifdef USE_NK_GIT_VERSION
50#include "nkutils-git-version.h"
52#define GIT_VERSION NK_GIT_VERSION
96 iter = g_list_next(iter)) {
97 g_string_free((GString *)iter->data, TRUE);
109 iter = g_list_next(iter)) {
110 g_string_free((GString *)iter->data, TRUE);
159 for (
unsigned int i = 0; i <
num_modes; i++) {
185 for (
unsigned int i = 0; i <
num_modes; i++) {
187 GString *str = g_string_new(
"Failed to initialize the mode: ");
188 g_string_append(str,
modes[i]->name);
189 g_string_append(str,
"\n");
192 g_string_free(str, FALSE);
205 if (
find_arg(
"-selected-row") >= 0) {
280 gboolean active = FALSE;
281 for (
unsigned int j = 0; j <
num_modes; j++) {
287 printf(
" • %s%s%s%s\n", active ?
"+" :
"",
293 print_help_msg(
"-config",
"[file]",
"Load an alternative configuration.",
296 "Do not load configuration, use default values.", NULL,
298 print_help_msg(
"-v,-version",
"",
"Print the version number and exit.", NULL,
300 print_help_msg(
"-dmenu",
"",
"Start in dmenu mode.", NULL, is_term);
301 print_help_msg(
"-display",
"[string]",
"X server to contact.",
"${DISPLAY}",
303 print_help_msg(
"-h,-help",
"",
"This help message.", NULL, is_term);
305 "Show a dialog displaying the passed message and exit.", NULL,
307 print_help_msg(
"-markup",
"",
"Enable pango markup where possible.", NULL,
310 "Behave as a normal window. (experimental)", NULL, is_term);
312 "Show the mode 'mode' and exit. The mode has to be enabled.",
315 "Disable lazy grab that, when fail to grab keyboard, does not "
316 "block but retry later.",
318 print_help_msg(
"-no-plugins",
"",
"Disable loading of external plugins.",
321 "Directory used to search for rofi plugins. *DEPRECATED*",
324 "Dump the current configuration in rasi format and exit.",
327 "Dump the current theme in rasi format and exit.", NULL,
330static void help(G_GNUC_UNUSED
int argc,
char **argv) {
331 int is_term = isatty(fileno(stdout));
332 printf(
"%s usage:\n", argv[0]);
333 printf(
"\t%s [-options ...]\n\n", argv[0]);
334 printf(
"Command line only options:\n");
336 printf(
"DMENU command line options:\n");
338 printf(
"Global options:\n");
343 printf(
"Detected modes:\n");
346 printf(
"Detected user scripts:\n");
349 printf(
"Compile time options:\n");
350 printf(
"\t• Pango version %s\n", pango_version_string());
352 printf(
"\t• window %senabled%s\n", is_term ?
color_green :
"",
355 printf(
"\t• window %sdisabled%s\n", is_term ?
color_red :
"",
359 printf(
"\t• drun %senabled%s\n", is_term ?
color_green :
"",
362 printf(
"\t• drun %sdisabled%s\n", is_term ?
color_red :
"",
366 printf(
"\t• gcov %senabled%s\n", is_term ?
color_green :
"",
369 printf(
"\t• gcov %sdisabled%s\n", is_term ?
color_red :
"",
373 printf(
"\t• asan %senabled%s\n", is_term ?
color_green :
"",
376 printf(
"\t• asan %sdisabled%s\n", is_term ?
color_red :
"",
380 printf(
"For more information see: %sman rofi%s\n", is_term ?
color_bold :
"",
383 printf(
" Version: %s" GIT_VERSION
"%s\n",
386 printf(
" Version: %s" VERSION
"%s\n",
389 printf(
" Bugreports: %s" PACKAGE_BUGREPORT
"%s\n",
391 printf(
" Support: %s" PACKAGE_URL
"%s\n",
393 printf(
" %s#rofi @ libera.chat%s\n",
397 printf(
" Configuration file: %s%s%s\n", is_term ?
color_bold :
"",
401 printf(
" Configuration file: %sDisabled%s\n",
408 int is_term = isatty(fileno(stdout));
411 fprintf(stderr,
"Mode %s%s%s is not enabled. I have enabled it for now.\n",
414 "Please consider adding %s%s%s to the list of enabled modes: "
415 "%smodes: [%s%s%s,%s]%s.\n",
421 GString *str = g_string_new(
"");
423 str,
"Mode %s is not found.\nThe following modes are known:\n", mode);
425 gboolean active = FALSE;
426 for (
unsigned int j = 0; j <
num_modes; j++) {
432 g_string_append_printf(str,
" * %s%s\n", active ?
"+" :
"",
439 GString *emesg = g_string_new(
440 "<span size=\"x-large\">Rofi is unsure what to show.</span>\n\n");
441 g_string_append(emesg,
"Please specify the mode you want to show.\n\n");
443 emesg,
" <b>rofi</b> -show <span color=\"green\">{mode}</span>\n\n");
444 g_string_append(emesg,
"The following modes are enabled:\n");
445 for (
unsigned int j = 0; j <
num_modes; j++) {
446 g_string_append_printf(emesg,
" • <span color=\"green\">%s</span>\n",
449 g_string_append(emesg,
"\nThe following modes can be enabled:\n");
451 gboolean active = FALSE;
452 for (
unsigned int j = 0; j <
num_modes; j++) {
459 g_string_append_printf(emesg,
" • <span color=\"red\">%s</span>\n",
463 g_string_append(emesg,
"\nTo activate a mode, add it to the list in "
464 "the <span color=\"green\">modes</span> "
474 for (
unsigned int i = 0; i <
num_modes; i++) {
543 g_debug(
"Looking into: %s for plugins", base_dir);
544 GDir *dir = g_dir_open(base_dir, 0, NULL);
546 const char *dn = NULL;
547 while ((dn = g_dir_read_name(dir))) {
548 if (!g_str_has_suffix(dn, G_MODULE_SUFFIX)) {
551 char *fn = g_build_filename(base_dir, dn, NULL);
552 g_debug(
"Trying to open: %s plugin", fn);
554 g_module_open(fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
557 if (g_module_symbol(mod,
"mode", (gpointer *)&m)) {
559 g_warning(
"ABI version of plugin: '%s' does not match: %08X "
570 g_warning(
"Symbol 'mode' not found in module: %s", dn);
574 g_warning(
"Failed to open 'mode' plugin: '%s', error: %s", dn,
605 const char *path = g_getenv(
"ROFI_PLUGIN_PATH");
607 gchar **paths = g_strsplit(path,
":", -1);
608 for (
unsigned int i = 0; paths[i]; i++) {
668 return (index ==
num_modes) ? -1 : (int)index;
671 const char *
const sep =
",#";
676 for (
char *token = strtok_r(mode_str, sep, &savept); token != NULL;
677 token = strtok_r(NULL, sep, &savept)) {
696 return G_SOURCE_CONTINUE;
700 g_string_new(
"The following errors were detected when starting rofi:\n");
703 for (; iter != NULL && index < 2; iter = g_list_next(iter)) {
704 GString *msg = (GString *)(iter->data);
705 g_string_append(emesg,
"\n\n");
706 g_string_append(emesg, msg->str);
709 if (g_list_length(iter) > 1) {
710 g_string_append_printf(emesg,
"\nThere are <b>%u</b> more errors.",
711 g_list_length(iter) - 1);
714 g_string_free(emesg, TRUE);
718static gboolean
startup(G_GNUC_UNUSED gpointer data) {
725 if (
find_arg(
"-normal-window") >= 0) {
735 TICK_N(
"Config sanity check");
739 return G_SOURCE_REMOVE;
743 iter = g_list_next(iter)) {
744 fputs(((GString *)iter->data)->str, stderr);
782 return G_SOURCE_REMOVE;
792 return G_SOURCE_REMOVE;
795static gboolean
record(G_GNUC_UNUSED
void *data) {
797 return G_SOURCE_CONTINUE;
800 G_GNUC_UNUSED GLogLevelFlags log_level,
801 const gchar *message, gpointer user_data) {
802 int fp = GPOINTER_TO_INT(user_data);
803 dprintf(fp,
"[%s]: %s\n", log_domain == NULL ?
"default" : log_domain,
814int main(
int argc,
char *argv[]) {
817 char *logfile = NULL;
819 if (logfile != NULL) {
820 int fp = open(logfile, O_CLOEXEC | O_APPEND | O_CREAT | O_WRONLY,
824 GINT_TO_POINTER(fp));
827 g_error(
"Failed to open logfile '%s': %s.", logfile, strerror(errno));
831 g_warning(
"Option '-log' should pass in a filename.");
839 g_print(
"Version: " GIT_VERSION
"\n");
841 g_print(
"Version: " VERSION
"\n");
846 if (
find_arg(
"-rasi-validate") >= 0) {
854 fprintf(stderr,
"Usage: %s -rasi-validate my-theme.rasi", argv[0]);
859 const char *ro_pid = g_getenv(
"ROFI_OUTSIDE");
860 if (ro_pid != NULL) {
861 pid_t ro_pidi = (pid_t)g_ascii_strtoll(ro_pid, NULL, 0);
862 if (kill(ro_pidi, 0) == 0) {
863 printf(
"Do not launch rofi from inside rofi.\r\n");
878 char *base_name = g_path_get_basename(argv[0]);
879 const char *
const dmenu_str =
"dmenu";
880 dmenu_mode = (strcmp(base_name, dmenu_str) == 0);
887 const char *path = g_get_user_runtime_dir();
889 if (g_mkdir_with_parents(path, 0700) < 0) {
890 g_warning(
"Failed to create user runtime directory: %s with error: %s",
891 path, g_strerror(errno));
892 pidfile = g_build_filename(g_get_home_dir(),
".rofi.pid", NULL);
894 pidfile = g_build_filename(path,
"rofi.pid", NULL);
901 if (
find_arg(
"-no-default-config") < 0) {
902 GBytes *theme_data = g_resource_lookup_data(
903 resources_get_resource(),
"/org/qtools/rofi/default_configuration.rasi",
904 G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
906 const char *theme = g_bytes_get_data(theme_data, NULL);
908 g_warning(
"Failed to parse default configuration. Giving up..");
911 iter = g_list_next(iter)) {
912 g_warning(
"Error: %s%s%s",
color_bold, ((GString *)iter->data)->str,
920 g_bytes_unref(theme_data);
925 const char *cpath = g_get_user_config_dir();
927 config_path = g_build_filename(cpath,
"rofi",
"config.rasi", NULL);
936 if (setlocale(LC_ALL,
"") == NULL) {
937 g_warning(
"Failed to set locale.");
948 main_loop = g_main_loop_new(NULL, FALSE);
956 g_warning(
"Connection has error");
968 gboolean found_system = FALSE;
969 const char *
const *dirs = g_get_system_config_dirs();
971 for (
unsigned int i = 0; !found_system && dirs[i]; i++) {
973 gchar *etc = g_build_filename(dirs[i],
"rofi.rasi", NULL);
974 g_debug(
"Look for default config file: %s", etc);
975 if (g_file_test(etc, G_FILE_TEST_IS_REGULAR)) {
976 g_debug(
"Parsing: %s", etc);
985 gchar *etc = g_build_filename(SYSCONFDIR,
"rofi.rasi", NULL);
986 g_debug(
"Look for default config file: %s", etc);
987 if (g_file_test(etc, G_FILE_TEST_IS_REGULAR)) {
988 g_debug(
"Look for default config file: %s", etc);
1006 g_warning(
"Failed to parse theme: \"%s\"",
config.
theme);
1019 TICK_N(
"Load cmd config ");
1028 if (g_mkdir_with_parents(
cache_dir, 0700) < 0) {
1029 g_warning(
"Failed to create cache directory: %s", g_strerror(errno));
1030 return EXIT_FAILURE;
1034 char *windowid = NULL;
1039 return EXIT_FAILURE;
1055 for (
int index = 0; theme_str && theme_str[index]; index++) {
1057 g_warning(
"Failed to parse -theme-str option: \"%s\"",
1067 if (
find_arg(
"-dump-theme") >= 0) {
1070 return EXIT_SUCCESS;
1072 if (
find_arg(
"-dump-processed-theme") >= 0) {
1076 return EXIT_SUCCESS;
1078 if (
find_arg(
"-dump-config") >= 0) {
1081 return EXIT_SUCCESS;
1089 return EXIT_SUCCESS;
1092 unsigned int interval = 1;
1094 g_timeout_add((guint)(1000 / (
double)interval),
record, NULL);
1096 if (
find_arg(
"-benchmark-ui") >= 0) {
1101 TICK_N(
"Workers initialize");
1103 TICK_N(
"Icon fetcher initialize");
1105 gboolean kill_running = FALSE;
1107 kill_running = TRUE;
1111 TICK_N(
"Pid file created");
1114 return EXIT_FAILURE;
1117 TICK_N(
"Text box setup");
1120 g_warning(
"Failed to properly finish display setup");
1122 return EXIT_FAILURE;
1124 TICK_N(
"Setup late Display");
1152 return EXIT_SUCCESS;
1156 iter = g_list_next(iter)) {
1157 fputs(((GString *)iter->data)->str, stderr);
1158 fputs(
"\n", stderr);
1161 iter = g_list_next(iter)) {
1162 fputs(((GString *)iter->data)->str, stderr);
1163 fputs(
"\n", stderr);
1166 return EXIT_FAILURE;
void config_parse_cmd_options(void)
void config_parser_add_option(XrmOptionType type, const char *key, void **value, const char *comment)
void print_help_msg(const char *option, const char *type, const char *text, const char *def, int isatty)
void config_parse_dump_config_rasi_format(FILE *out, gboolean changes)
Dump configuration in rasi format.
void config_xresource_free(void)
void cmd_set_arguments(int argc, char **argv)
const char ** find_arg_strv(const char *const key)
char * rofi_expand_path(const char *input)
void remove_pid_file(int fd)
int find_arg_str(const char *const key, char **val)
int find_arg_uint(const char *const key, unsigned int *val)
int find_arg(const char *const key)
int create_pid_file(const char *pidfile, gboolean kill_running)
int config_sanity_check(void)
void rofi_icon_fetcher_destroy(void)
void rofi_icon_fetcher_init(void)
gboolean parse_keys_abe(NkBindings *bindings)
void mode_destroy(Mode *mode)
const char * mode_get_name(const Mode *mode)
int mode_init(Mode *mode)
void mode_free(Mode **mode)
ModeMode mode_result(Mode *mode, int menu_retv, char **input, unsigned int selected_line)
void mode_set_config(Mode *mode)
const Mode * rofi_get_mode(unsigned int index)
void rofi_quit_main_loop(void)
unsigned int rofi_get_num_enabled_modes(void)
void rofi_clear_error_messages(void)
void rofi_clear_warning_messages(void)
void rofi_set_return_code(int code)
Mode * rofi_collect_modes_search(const char *name)
void rofi_add_error_message(GString *str)
void rofi_add_warning_message(GString *str)
void script_mode_gather_user_scripts(void)
gboolean script_mode_is_valid(const char *token)
void script_user_list(gboolean is_term)
void script_mode_cleanup(void)
Mode * script_mode_parse_setup(const char *str)
void textbox_cleanup(void)
void textbox_cursor_end(textbox *tb)
void textbox_text(textbox *tb, const char *text)
void __create_window(MenuFlags menu_flags)
void rofi_view_clear_input(RofiViewState *state)
void rofi_view_switch_mode(RofiViewState *state, Mode *mode)
void rofi_view_remove_active(RofiViewState *state)
int rofi_view_error_dialog(const char *msg, int markup)
void rofi_view_set_active(RofiViewState *state)
RofiViewState * rofi_view_get_active(void)
MenuReturn rofi_view_get_return_value(const RofiViewState *state)
const char * rofi_view_get_user_input(const RofiViewState *state)
void rofi_view_set_selected_line(RofiViewState *state, unsigned int selected_line)
void rofi_view_free(RofiViewState *state)
RofiViewState * rofi_view_create(Mode *sw, const char *input, MenuFlags menu_flags, void(*finalize)(RofiViewState *))
unsigned int rofi_view_get_selected_line(const RofiViewState *state)
void rofi_capture_screenshot(void)
void rofi_view_workers_initialize(void)
void rofi_view_workers_finalize(void)
static void help(G_GNUC_UNUSED int argc, char **argv)
static void rofi_collect_modes(void)
int main(int argc, char *argv[])
GList * list_of_warning_msgs
GList * list_of_error_msgs
static gboolean record(G_GNUC_UNUSED void *data)
G_MODULE_EXPORT char * config_path
static void print_main_application_options(int is_term)
static void print_list_of_modes(int is_term)
static void run_mode_index(ModeMode mode)
static void rofi_custom_log_function(const char *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level, const gchar *message, gpointer user_data)
static void help_print_mode_not_found(const char *mode)
static void cleanup(void)
static gboolean startup(G_GNUC_UNUSED gpointer data)
static gboolean setup_modes(void)
int rofi_theme_rasi_validate(const char *filename)
static void rofi_collectmodes_setup(void)
static void teardown(int pfd)
static gboolean rofi_collectmodes_add(Mode *mode)
static void rofi_collectmodes_destroy(void)
void process_result(RofiViewState *state)
static int add_mode(const char *token)
static gboolean main_loop_signal_handler_int(G_GNUC_UNUSED gpointer data)
static void show_error_dialog(void)
static void help_print_no_arguments(void)
static int mode_lookup(const char *name)
static void help_print_disabled_mode(const char *mode)
unsigned int num_available_modes
static void rofi_collectmodes_dir(const char *base_dir)
unsigned int sidebar_mode
void rofi_theme_free_parsed_files(void)
void rofi_theme_print_parsed_files(gboolean is_term)
void rofi_theme_parse_process_links(void)
void rofi_theme_parse_process_conditionals(void)
void rofi_theme_print(ThemeWidget *widget)
void rofi_theme_reset(void)
void rofi_theme_free(ThemeWidget *widget)
gboolean rofi_theme_parse_string(const char *string)
gboolean rofi_theme_parse_file(const char *file)
gboolean display_late_setup(void)
void display_early_cleanup(void)
void display_cleanup(void)
gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings)
void display_dump_monitor_layout(void)
ThemeWidget * rofi_configuration