30#define G_LOG_DOMAIN "Rofi"
48#include <libgwater-xcb.h>
50#ifdef USE_NK_GIT_VERSION
51#include "nkutils-git-version.h"
53#define GIT_VERSION NK_GIT_VERSION
97 iter = g_list_next(iter)) {
98 g_string_free((GString *)iter->data, TRUE);
110 iter = g_list_next(iter)) {
111 g_string_free((GString *)iter->data, TRUE);
160 for (
unsigned int i = 0; i <
num_modes; i++) {
201 for (
unsigned int i = 0; i <
num_modes; i++) {
203 GString *str = g_string_new(
"Failed to initialize the mode: ");
205 g_string_append(str,
"\n");
208 g_string_free(str, FALSE);
221 if (
find_arg(
"-selected-row") >= 0) {
296 gboolean active = FALSE;
297 for (
unsigned int j = 0; j <
num_modes; j++) {
303 printf(
" • %s%s%s%s\n", active ?
"+" :
"",
309 print_help_msg(
"-config",
"[file]",
"Load an alternative configuration.",
312 "Do not load configuration, use default values.", NULL,
314 print_help_msg(
"-v,-version",
"",
"Print the version number and exit.", NULL,
316 print_help_msg(
"-dmenu",
"",
"Start in dmenu mode.", NULL, is_term);
317 print_help_msg(
"-display",
"[string]",
"X server to contact.",
"${DISPLAY}",
319 print_help_msg(
"-h,-help",
"",
"This help message.", NULL, is_term);
321 "Show a dialog displaying the passed message and exit.", NULL,
323 print_help_msg(
"-markup",
"",
"Enable pango markup where possible.", NULL,
326 "Behave as a normal window. (experimental)", NULL, is_term);
328 "Behave as a modal dialog that is transient to the currently "
329 "focused window. (experimental)",
332 "Show the mode 'mode' and exit. The mode has to be enabled.",
335 "Disable lazy grab that, when fail to grab keyboard, does not "
336 "block but retry later.",
338 print_help_msg(
"-no-plugins",
"",
"Disable loading of external plugins.",
341 "Directory used to search for rofi plugins. *DEPRECATED*",
344 "Dump the current configuration in rasi format and exit.",
347 "Dump the current theme in rasi format and exit.", NULL,
350 "Print a list of current keybindings and exit.", NULL,
353static void help(G_GNUC_UNUSED
int argc,
char **argv) {
354 int is_term = isatty(fileno(stdout));
355 printf(
"%s usage:\n", argv[0]);
356 printf(
"\t%s [-options ...]\n\n", argv[0]);
357 printf(
"Command line only options:\n");
359 printf(
"DMENU command line options:\n");
361 printf(
"Global options:\n");
364 printf(
"Detected Window manager:\n");
367 printf(
"\t• %s\n", wm);
370 printf(
"\t• No window manager detected.\n");
375 printf(
"Detected modes:\n");
378 printf(
"Detected user scripts:\n");
381 printf(
"Compile time options:\n");
382 printf(
"\t• Pango version %s\n", pango_version_string());
384 printf(
"\t• window %senabled%s\n", is_term ?
color_green :
"",
387 printf(
"\t• window %sdisabled%s\n", is_term ?
color_red :
"",
391 printf(
"\t• drun %senabled%s\n", is_term ?
color_green :
"",
394 printf(
"\t• drun %sdisabled%s\n", is_term ?
color_red :
"",
398 printf(
"\t• gcov %senabled%s\n", is_term ?
color_green :
"",
401 printf(
"\t• gcov %sdisabled%s\n", is_term ?
color_red :
"",
405 printf(
"\t• asan %senabled%s\n", is_term ?
color_green :
"",
408 printf(
"\t• asan %sdisabled%s\n", is_term ?
color_red :
"",
412 printf(
"\t• imdkit %senabled%s\n", is_term ?
color_green :
"",
415 printf(
"\t• imdkit %sdisabled%s\n", is_term ?
color_red :
"",
419 printf(
"For more information see: %sman rofi%s\n", is_term ?
color_bold :
"",
422 printf(
" Version: %s" GIT_VERSION
"%s\n",
425 printf(
" Version: %s" VERSION
"%s\n",
428 printf(
" Bugreports: %s" PACKAGE_BUGREPORT
"%s\n",
430 printf(
" Support: %s" PACKAGE_URL
"%s\n",
432 printf(
" %s#rofi @ libera.chat%s\n",
436 printf(
" Configuration file: %s%s%s\n", is_term ?
color_bold :
"",
440 printf(
" Configuration file: %sDisabled%s\n",
447 int is_term = isatty(fileno(stdout));
450 fprintf(stderr,
"Mode %s%s%s is not enabled. I have enabled it for now.\n",
453 "Please consider adding %s%s%s to the list of enabled modes: "
454 "%smodes: [%s%s%s,%s]%s.\n",
460 GString *str = g_string_new(
"");
462 str,
"Mode %s is not found.\nThe following modes are known:\n", mode);
464 gboolean active = FALSE;
465 for (
unsigned int j = 0; j <
num_modes; j++) {
471 g_string_append_printf(str,
" * %s%s\n", active ?
"+" :
"",
478 GString *emesg = g_string_new(
479 "<span size=\"x-large\">Rofi is unsure what to show.</span>\n\n");
480 g_string_append(emesg,
"Please specify the mode you want to show.\n\n");
482 emesg,
" <b>rofi</b> -show <span color=\"green\">{mode}</span>\n\n");
483 g_string_append(emesg,
"The following modes are enabled:\n");
484 for (
unsigned int j = 0; j <
num_modes; j++) {
485 g_string_append_printf(emesg,
" • <span color=\"green\">%s</span>\n",
488 g_string_append(emesg,
"\nThe following modes can be enabled:\n");
490 gboolean active = FALSE;
491 for (
unsigned int j = 0; j <
num_modes; j++) {
498 g_string_append_printf(emesg,
" • <span color=\"red\">%s</span>\n",
502 g_string_append(emesg,
"\nTo activate a mode, add it to the list in "
503 "the <span color=\"green\">modes</span> "
513 for (
unsigned int i = 0; i <
num_modes; i++) {
587 g_debug(
"Looking into: %s for plugins", base_dir);
588 GDir *dir = g_dir_open(base_dir, 0, NULL);
590 const char *dn = NULL;
591 while ((dn = g_dir_read_name(dir))) {
592 if (!g_str_has_suffix(dn, G_MODULE_SUFFIX)) {
595 char *fn = g_build_filename(base_dir, dn, NULL);
596 g_debug(
"Trying to open: %s plugin", fn);
598 g_module_open(fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
601 if (g_module_symbol(mod,
"mode", (gpointer *)&m)) {
603 g_warning(
"ABI version of plugin: '%s' does not match: %08X "
614 g_warning(
"Symbol 'mode' not found in module: %s", dn);
618 g_warning(
"Failed to open 'mode' plugin: '%s', error: %s", dn,
647 g_debug(
"Parse plugin path: %s",
config.plugin_path);
650 const char *path = g_getenv(
"ROFI_PLUGIN_PATH");
652 gchar **paths = g_strsplit(path,
":", -1);
653 for (
unsigned int i = 0; paths[i]; i++) {
713 return (index ==
num_modes) ? -1 : (int)index;
716 const char *
const sep =
",#";
719 char *mode_str = g_strdup(
config.modes);
721 for (
char *token = strtok_r(mode_str, sep, &savept); token != NULL;
722 token = strtok_r(NULL, sep, &savept)) {
741 return G_SOURCE_CONTINUE;
745 g_string_new(
"The following errors were detected when starting rofi:\n");
748 for (; iter != NULL && index < 2; iter = g_list_next(iter)) {
749 GString *msg = (GString *)(iter->data);
750 g_string_append(emesg,
"\n\n");
751 g_string_append(emesg, msg->str);
754 if (g_list_length(iter) > 1) {
755 g_string_append_printf(emesg,
"\nThere are <b>%u</b> more errors.",
756 g_list_length(iter) - 1);
759 g_string_free(emesg, TRUE);
763static gboolean
startup(G_GNUC_UNUSED gpointer data) {
770 if (
find_arg(
"-normal-window") >= 0) {
773 if (
find_arg(
"-transient-window") >= 0) {
783 TICK_N(
"Config sanity check");
787 return G_SOURCE_REMOVE;
791 iter = g_list_next(iter)) {
792 fputs(((GString *)iter->data)->str, stderr);
799 config.sidebar_mode = FALSE;
812 if (g_strcmp0(msg,
"-") == 0) {
813 size_t index = 0, i = 0;
814 size_t length = 1024;
815 msg = malloc(length *
sizeof(
char));
816 while ((i = fread(&msg[index], 1, 1024, stdin)) > 0) {
819 msg = realloc(msg, length *
sizeof(
char));
850 return G_SOURCE_REMOVE;
860 return G_SOURCE_REMOVE;
866 return G_SOURCE_REMOVE;
868static gboolean
record(G_GNUC_UNUSED
void *data) {
870 return G_SOURCE_CONTINUE;
873 G_GNUC_UNUSED GLogLevelFlags log_level,
874 const gchar *message, gpointer user_data) {
875 int fp = GPOINTER_TO_INT(user_data);
876 dprintf(fp,
"[%s]: %s\n", log_domain == NULL ?
"default" : log_domain,
887int main(
int argc,
char *argv[]) {
890 char *logfile = NULL;
892 if (logfile != NULL) {
893 int fp = open(logfile, O_CLOEXEC | O_APPEND | O_CREAT | O_WRONLY,
897 GINT_TO_POINTER(fp));
900 g_error(
"Failed to open logfile '%s': %s.", logfile, strerror(errno));
904 g_warning(
"Option '-log' should pass in a filename.");
912 g_print(
"Version: " GIT_VERSION
"\n");
914 g_print(
"Version: " VERSION
"\n");
919 if (
find_arg(
"-rasi-validate") >= 0) {
927 fprintf(stderr,
"Usage: %s -rasi-validate my-theme.rasi", argv[0]);
932 const char *ro_pid = g_getenv(
"ROFI_OUTSIDE");
933 if (ro_pid != NULL) {
934 pid_t ro_pidi = (pid_t)g_ascii_strtoll(ro_pid, NULL, 0);
935 if (kill(ro_pidi, 0) == 0) {
936 printf(
"Do not launch rofi from inside rofi.\r\n");
951 char *base_name = g_path_get_basename(argv[0]);
952 const char *
const dmenu_str =
"dmenu";
960 const char *path = g_get_user_runtime_dir();
962 if (g_mkdir_with_parents(path, 0700) < 0) {
963 g_warning(
"Failed to create user runtime directory: %s with error: %s",
964 path, g_strerror(errno));
965 pidfile = g_build_filename(g_get_home_dir(),
".rofi.pid", NULL);
967 pidfile = g_build_filename(path,
"rofi.pid", NULL);
974 if (
find_arg(
"-no-default-config") < 0) {
975 GBytes *theme_data = g_resource_lookup_data(
976 resources_get_resource(),
"/org/qtools/rofi/default_configuration.rasi",
977 G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
979 const char *theme = g_bytes_get_data(theme_data, NULL);
981 g_warning(
"Failed to parse default configuration. Giving up..");
984 iter = g_list_next(iter)) {
985 g_warning(
"Error: %s%s%s",
color_bold, ((GString *)iter->data)->str,
993 g_bytes_unref(theme_data);
998 const char *cpath = g_get_user_config_dir();
1000 config_path = g_build_filename(cpath,
"rofi",
"config.rasi", NULL);
1009 if (setlocale(LC_ALL,
"") == NULL) {
1010 g_warning(
"Failed to set locale.");
1012 return EXIT_FAILURE;
1021 main_loop = g_main_loop_new(NULL, FALSE);
1023 TICK_N(
"Setup mainloop");
1029 g_warning(
"Connection has error");
1031 return EXIT_FAILURE;
1041 gboolean found_system = FALSE;
1042 const char *
const *dirs = g_get_system_config_dirs();
1044 for (
unsigned int i = 0; !found_system && dirs[i]; i++) {
1046 gchar *etc = g_build_filename(dirs[i],
"rofi.rasi", NULL);
1047 g_debug(
"Look for default config file: %s", etc);
1048 if (g_file_test(etc, G_FILE_TEST_IS_REGULAR)) {
1049 g_debug(
"Parsing: %s", etc);
1051 found_system = TRUE;
1056 if (!found_system) {
1058 gchar *etc = g_build_filename(SYSCONFDIR,
"rofi.rasi", NULL);
1059 g_debug(
"Look for default config file: %s", etc);
1060 if (g_file_test(etc, G_FILE_TEST_IS_REGULAR)) {
1061 g_debug(
"Look for default config file: %s", etc);
1069 extern const char *rasi_theme_file_extensions[];
1072 GFile *gf = g_file_new_for_path(file2);
1073 char *filename = g_file_get_path(gf);
1076 if (filename && g_file_test(filename, G_FILE_TEST_EXISTS)) {
1090 g_warning(
"Failed to parse theme: \"%s\"",
config.theme);
1105 g_debug(
"Failed to load theme. Try to load default: ");
1108 TICK_N(
"Load cmd config ");
1113 if (
config.cache_dir != NULL) {
1117 if (g_mkdir_with_parents(
cache_dir, 0700) < 0) {
1118 g_warning(
"Failed to create cache directory: %s", g_strerror(errno));
1119 return EXIT_FAILURE;
1123 char *windowid = NULL;
1128 return EXIT_FAILURE;
1134 config.monitor = g_strdup_printf(
"wid:%s", windowid);
1135 windowid =
config.monitor;
1144 for (
int index = 0; theme_str[index]; index++) {
1146 g_warning(
"Failed to parse -theme-str option: \"%s\"",
1156 if (
find_arg(
"-dump-theme") >= 0) {
1159 return EXIT_SUCCESS;
1161 if (
find_arg(
"-dump-processed-theme") >= 0) {
1165 return EXIT_SUCCESS;
1167 if (
find_arg(
"-dump-config") >= 0) {
1170 return EXIT_SUCCESS;
1178 return EXIT_SUCCESS;
1180 if (
find_arg(
"-list-keybindings") >= 0) {
1181 int is_term = isatty(fileno(stdout));
1183 return EXIT_SUCCESS;
1186 unsigned int interval = 1;
1188 g_timeout_add((guint)(1000 / (
double)interval),
record, NULL);
1193 if (
find_arg(
"-benchmark-ui") >= 0) {
1194 config.benchmark_ui = TRUE;
1198 TICK_N(
"Workers initialize");
1200 TICK_N(
"Icon fetcher initialize");
1202 gboolean kill_running = FALSE;
1204 kill_running = TRUE;
1208 TICK_N(
"Pid file created");
1211 return EXIT_FAILURE;
1214 TICK_N(
"Text box setup");
1217 g_warning(
"Failed to properly finish display setup");
1219 return EXIT_FAILURE;
1221 TICK_N(
"Setup late Display");
1249 return EXIT_SUCCESS;
1253 iter = g_list_next(iter)) {
1254 fputs(((GString *)iter->data)->str, stderr);
1255 fputs(
"\n", stderr);
1258 iter = g_list_next(iter)) {
1259 fputs(((GString *)iter->data)->str, stderr);
1260 fputs(
"\n", stderr);
1263 return EXIT_FAILURE;
1268 if (index != NULL) {
1272 config.completer_mode == NULL ?
"(null)" :
config.completer_mode;
1273 g_warning(
"Mode: %s not found or is not valid for use as completer.", name);
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)
Mode recursive_browser_mode
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 abe_list_all_bindings(gboolean is_term)
void mode_destroy(Mode *mode)
const char * mode_get_name(const Mode *mode)
int mode_init(Mode *mode)
void mode_free(Mode **mode)
int mode_get_abi_version(Mode *const mode)
ModeMode mode_result(Mode *mode, int menu_retv, char **input, unsigned int selected_line)
void mode_plugin_set_module(Mode *mode, GModule *mod)
GModule * mode_plugin_get_module(Mode *mode)
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)
const Mode * rofi_get_completer(void)
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 rofi_view_cleanup(void)
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)
char * helper_get_theme_path(const char *file, const char **ext, const char *parent_file)
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 gboolean take_screenshot_quit(G_GNUC_UNUSED void *data)
static void rofi_collectmodes_destroy(void)
void process_result(RofiViewState *state)
static const Mode * mode_available_lookup(const char *name)
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)
int rofi_is_in_dmenu_mode
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)
void rofi_theme_free_parsed_files(void)
void rofi_theme_print_parsed_files(gboolean is_term)
void rofi_theme_print(ThemeWidget *wid)
void rofi_theme_parse_process_links(void)
void rofi_theme_parse_process_conditionals(void)
void rofi_theme_free(ThemeWidget *wid)
void rofi_theme_reset(void)
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)
char * x11_helper_get_window_manager(void)
gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings)
void display_dump_monitor_layout(void)
ThemeWidget * rofi_configuration