30#define G_LOG_DOMAIN "Rofi"
47#ifdef USE_NK_GIT_VERSION
48#include "nkutils-git-version.h"
50#define GIT_VERSION NK_GIT_VERSION
75#include <wayland-version.h>
99 iter = g_list_next(iter)) {
100 g_string_free((GString *)iter->data, TRUE);
112 iter = g_list_next(iter)) {
113 g_string_free((GString *)iter->data, TRUE);
165 for (
unsigned int i = 0; i <
num_modes; i++) {
206 for (
unsigned int i = 0; i <
num_modes; i++) {
208 GString *str = g_string_new(
"Failed to initialize the mode: ");
210 g_string_append(str,
"\n");
213 g_string_free(str, FALSE);
226 if (
find_arg(
"-selected-row") >= 0) {
301 gboolean active = FALSE;
302 for (
unsigned int j = 0; j <
num_modes; j++) {
308 printf(
" • %s%s%s%s\n", active ?
"+" :
"",
314 print_help_msg(
"-config",
"[file]",
"Load an alternative configuration.",
317 "Do not load configuration, use default values.", NULL,
319 print_help_msg(
"-v,-version",
"",
"Print the version number and exit.", NULL,
321 print_help_msg(
"-dmenu",
"",
"Start in dmenu mode.", NULL, is_term);
322 print_help_msg(
"-display",
"[string]",
"X server to contact.",
"${DISPLAY}",
324 print_help_msg(
"-h,-help",
"",
"This help message.", NULL, is_term);
326 "Show a dialog displaying the passed message and exit.", NULL,
328 print_help_msg(
"-markup",
"",
"Enable pango markup where possible.", NULL,
331 "Behave as a normal window. (experimental)", NULL, is_term);
333 "Behave as a modal dialog that is transient to the currently "
334 "focused window. (experimental)",
337 "Show the mode 'mode' and exit. The mode has to be enabled.",
340 "Disable lazy grab that, when fail to grab keyboard, does not "
341 "block but retry later.",
343 print_help_msg(
"-no-plugins",
"",
"Disable loading of external plugins.",
346 "Directory used to search for rofi plugins. *DEPRECATED*",
349 "Dump the current configuration in rasi format and exit.",
352 "Dump the current theme in rasi format and exit.", NULL,
355 "Print a list of current keybindings and exit.", NULL,
360 int is_term = isatty(fileno(stdout));
361 printf(
"Display backends:\n");
365 printf(
": %sselected%s\n", is_term ?
color_bold :
"",
372 printf(
"\t• wayland");
374 printf(
": %sselected%s\n", is_term ?
color_bold :
"",
383static void help(G_GNUC_UNUSED
int argc,
char **argv,
const gboolean compact) {
384 int is_term = isatty(fileno(stdout));
386 printf(
"%s usage:\n", argv[0]);
387 printf(
"\t%s [-options ...]\n\n", argv[0]);
388 printf(
"Command line only options:\n");
390 printf(
"DMENU command line options:\n");
392 printf(
"Global options:\n");
400 printf(
"Detected Window manager:\n");
403 printf(
"\t• %s\n", wm);
406 printf(
"\t• No window manager detected.\n");
414 printf(
"Detected modes:\n");
417 printf(
"Detected user scripts:\n");
420 printf(
"Compile time options:\n");
421 printf(
"\t• Pango version %s\n", pango_version_string());
423 printf(
"\t• window %senabled%s\n", is_term ?
color_green :
"",
426 printf(
"\t• window %sdisabled%s\n", is_term ?
color_red :
"",
430 printf(
"\t• drun %senabled%s\n", is_term ?
color_green :
"",
433 printf(
"\t• drun %sdisabled%s\n", is_term ?
color_red :
"",
437 printf(
"\t• asan %senabled%s\n", is_term ?
color_green :
"",
440 printf(
"\t• asan %sdisabled%s\n", is_term ?
color_red :
"",
444 printf(
"\t• imdkit %senabled%s\n", is_term ?
color_green :
"",
447 printf(
"\t• imdkit %sdisabled%s\n", is_term ?
color_red :
"",
451 printf(
"\t• xcb %senabled%s\n", is_term ?
color_green :
"",
454 printf(
"\t• xcb %sdisabled%s\n", is_term ?
color_red :
"",
458 printf(
"\t• wayland %senabled%s (%s)\n", is_term ?
color_green :
"",
461 printf(
"\t• wayland %sdisabled%s\n", is_term ?
color_red :
"",
465 printf(
"For more information see: %sman rofi%s\n", is_term ?
color_bold :
"",
468 printf(
" Version: %s" GIT_VERSION
"%s\n",
471 printf(
" Version: %s" VERSION
"%s\n",
474 printf(
" Bugreports: %s" PACKAGE_BUGREPORT
"%s\n",
476 printf(
" Support: %s" PACKAGE_URL
"%s\n",
478 printf(
" %s#rofi @ libera.chat%s\n",
482 printf(
" Configuration file: %s%s%s\n", is_term ?
color_bold :
"",
486 printf(
" Configuration file: %sDisabled%s\n",
493 int is_term = isatty(fileno(stdout));
496 fprintf(stderr,
"Mode %s%s%s is not enabled. I have enabled it for now.\n",
499 "Please consider adding %s%s%s to the list of enabled modes: "
500 "%smodes: [%s%s%s,%s]%s.\n",
506 GString *str = g_string_new(
"");
508 str,
"Mode %s is not found.\nThe following modes are known:\n", mode);
510 gboolean active = FALSE;
511 for (
unsigned int j = 0; j <
num_modes; j++) {
517 g_string_append_printf(str,
" * %s%s\n", active ?
"+" :
"",
524 GString *emesg = g_string_new(
525 "<span size=\"x-large\">Rofi is unsure what to show.</span>\n\n");
526 g_string_append(emesg,
"Please specify the mode you want to show.\n\n");
528 emesg,
" <b>rofi</b> -show <span color=\"green\">{mode}</span>\n\n");
529 g_string_append(emesg,
"The following modes are enabled:\n");
530 for (
unsigned int j = 0; j <
num_modes; j++) {
531 g_string_append_printf(emesg,
" • <span color=\"green\">%s</span>\n",
534 g_string_append(emesg,
"\nThe following modes can be enabled:\n");
536 gboolean active = FALSE;
537 for (
unsigned int j = 0; j <
num_modes; j++) {
544 g_string_append_printf(emesg,
" • <span color=\"red\">%s</span>\n",
548 g_string_append(emesg,
"\nTo activate a mode, add it to the list in "
549 "the <span color=\"green\">modes</span> "
559 for (
unsigned int i = 0; i <
num_modes; i++) {
633 g_debug(
"Looking into: %s for plugins", base_dir);
634 GDir *dir = g_dir_open(base_dir, 0, NULL);
636 const char *dn = NULL;
637 while ((dn = g_dir_read_name(dir))) {
638 if (!g_str_has_suffix(dn, G_MODULE_SUFFIX)) {
641 char *fn = g_build_filename(base_dir, dn, NULL);
642 g_debug(
"Trying to open: %s plugin", fn);
644 g_module_open(fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
647 if (g_module_symbol(mod,
"mode", (gpointer *)&m)) {
649 g_warning(
"ABI version of plugin: '%s' does not match: %08X "
660 g_warning(
"Symbol 'mode' not found in module: %s", dn);
664 g_warning(
"Failed to open 'mode' plugin: '%s', error: %s", dn,
702 g_debug(
"Parse plugin path: %s",
config.plugin_path);
705 const char *path = g_getenv(
"ROFI_PLUGIN_PATH");
707 gchar **paths = g_strsplit(path,
":", -1);
708 for (
unsigned int i = 0; paths[i]; i++) {
768 return (index ==
num_modes) ? -1 : (int)index;
771 const char *
const sep =
",#";
774 char *mode_str = g_strdup(
config.modes);
776 for (
char *token = strtok_r(mode_str, sep, &savept); token != NULL;
777 token = strtok_r(NULL, sep, &savept)) {
796 return G_SOURCE_CONTINUE;
800 g_string_new(
"The following errors were detected when starting rofi:\n");
803 for (; iter != NULL && index < 2; iter = g_list_next(iter)) {
804 GString *msg = (GString *)(iter->data);
805 g_string_append(emesg,
"\n\n");
806 g_string_append(emesg, msg->str);
809 if (g_list_length(iter) > 1) {
810 g_string_append_printf(emesg,
"\nThere are <b>%u</b> more errors.",
811 g_list_length(iter) - 1);
814 g_string_free(emesg, TRUE);
818static gboolean
startup(G_GNUC_UNUSED gpointer data) {
825 if (
find_arg(
"-normal-window") >= 0) {
828 if (
find_arg(
"-transient-window") >= 0) {
838 TICK_N(
"Config sanity check");
842 return G_SOURCE_REMOVE;
846 iter = g_list_next(iter)) {
847 fputs(((GString *)iter->data)->str, stderr);
854 config.sidebar_mode = FALSE;
867 if (g_strcmp0(msg,
"-") == 0) {
868 size_t index = 0, i = 0;
869 size_t length = 1024;
870 msg = malloc(length *
sizeof(
char));
871 while ((i = fread(&msg[index], 1, 1024, stdin)) > 0) {
874 msg = realloc(msg, length *
sizeof(
char));
905 return G_SOURCE_REMOVE;
915 return G_SOURCE_REMOVE;
921 return G_SOURCE_REMOVE;
923static gboolean
record(G_GNUC_UNUSED
void *data) {
925 return G_SOURCE_CONTINUE;
928 G_GNUC_UNUSED GLogLevelFlags log_level,
929 const gchar *message, gpointer user_data) {
930 int fp = GPOINTER_TO_INT(user_data);
931 dprintf(fp,
"[%s]: %s\n", log_domain == NULL ?
"default" : log_domain,
942int main(
int argc,
char *argv[]) {
945 char *logfile = NULL;
947 if (logfile != NULL) {
948 int fp = open(logfile, O_CLOEXEC | O_APPEND | O_CREAT | O_WRONLY,
952 GINT_TO_POINTER(fp));
955 g_error(
"Failed to open logfile '%s': %s.", logfile, strerror(errno));
959 g_warning(
"Option '-log' should pass in a filename.");
967 g_print(
"Version: " GIT_VERSION
"\n");
969 g_print(
"Version: " VERSION
"\n");
974 if (
find_arg(
"-rasi-validate") >= 0) {
982 fprintf(stderr,
"Usage: %s -rasi-validate my-theme.rasi", argv[0]);
987 const char *ro_pid = g_getenv(
"ROFI_OUTSIDE");
988 if (ro_pid != NULL) {
989 pid_t ro_pidi = (pid_t)g_ascii_strtoll(ro_pid, NULL, 0);
990 if (kill(ro_pidi, 0) == 0) {
991 printf(
"Do not launch rofi from inside rofi.\r\n");
1006 char *base_name = g_path_get_basename(argv[0]);
1007 const char *
const dmenu_str =
"dmenu";
1015 const char *path = g_get_user_runtime_dir();
1017 if (g_mkdir_with_parents(path, 0700) < 0) {
1018 g_warning(
"Failed to create user runtime directory: %s with error: %s",
1019 path, g_strerror(errno));
1020 pidfile = g_build_filename(g_get_home_dir(),
".rofi.pid", NULL);
1022 pidfile = g_build_filename(path,
"rofi.pid", NULL);
1026 "Pidfile location");
1029 if (
find_arg(
"-no-default-config") < 0) {
1030 GBytes *theme_data = g_resource_lookup_data(
1031 resources_get_resource(),
"/org/qtools/rofi/default_configuration.rasi",
1032 G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
1034 const char *theme = g_bytes_get_data(theme_data, NULL);
1036 g_warning(
"Failed to parse default configuration. Giving up..");
1039 iter = g_list_next(iter)) {
1040 g_warning(
"Error: %s%s%s",
color_bold, ((GString *)iter->data)->str,
1046 return EXIT_FAILURE;
1048 g_bytes_unref(theme_data);
1053 const char *cpath = g_get_user_config_dir();
1055 config_path = g_build_filename(cpath,
"rofi",
"config.rasi", NULL);
1070#ifdef ENABLE_WAYLAND
1072 const gchar *wl_display = g_getenv(
"WAYLAND_DISPLAY");
1074 strlen(wl_display) > 0) {
1086 if (setlocale(LC_ALL,
"") == NULL) {
1087 g_warning(
"Failed to set locale.");
1089 return EXIT_FAILURE;
1098 main_loop = g_main_loop_new(NULL, FALSE);
1100 TICK_N(
"Setup mainloop");
1111 gboolean found_system = FALSE;
1112 const char *
const *dirs = g_get_system_config_dirs();
1114 for (
unsigned int i = 0; !found_system && dirs[i]; i++) {
1116 gchar *etc = g_build_filename(dirs[i],
"rofi.rasi", NULL);
1117 g_debug(
"Look for default config file: %s", etc);
1118 if (g_file_test(etc, G_FILE_TEST_IS_REGULAR)) {
1119 g_debug(
"Parsing: %s", etc);
1121 found_system = TRUE;
1126 if (!found_system) {
1128 gchar *etc = g_build_filename(SYSCONFDIR,
"rofi.rasi", NULL);
1129 g_debug(
"Look for default config file: %s", etc);
1130 if (g_file_test(etc, G_FILE_TEST_IS_REGULAR)) {
1131 g_debug(
"Look for default config file: %s", etc);
1139 extern const char *rasi_theme_file_extensions[];
1142 GFile *gf = g_file_new_for_path(file2);
1143 char *filename = g_file_get_path(gf);
1146 if (filename && g_file_test(filename, G_FILE_TEST_EXISTS)) {
1160 g_warning(
"Failed to parse theme: \"%s\"",
config.theme);
1175 g_debug(
"Failed to load theme. Try to load default: ");
1178 TICK_N(
"Load cmd config ");
1183 if (
config.cache_dir != NULL) {
1187 if (g_mkdir_with_parents(
cache_dir, 0700) < 0) {
1188 g_warning(
"Failed to create cache directory: %s", g_strerror(errno));
1189 return EXIT_FAILURE;
1193 char *windowid = NULL;
1198 return EXIT_FAILURE;
1204 config.monitor = g_strdup_printf(
"wid:%s", windowid);
1205 windowid =
config.monitor;
1214 for (
int index = 0; theme_str[index]; index++) {
1216 g_warning(
"Failed to parse -theme-str option: \"%s\"",
1226 if (
find_arg(
"-dump-theme") >= 0) {
1229 return EXIT_SUCCESS;
1231 if (
find_arg(
"-dump-processed-theme") >= 0) {
1235 return EXIT_SUCCESS;
1237 if (
find_arg(
"-dump-config") >= 0) {
1240 return EXIT_SUCCESS;
1243 if (
find_arg(
"-list-keybindings") >= 0) {
1244 int is_term = isatty(fileno(stdout));
1246 return EXIT_SUCCESS;
1249 unsigned int interval = 1;
1251 g_timeout_add((guint)(1000 / (
double)interval),
record, NULL);
1256 if (
find_arg(
"-benchmark-ui") >= 0) {
1257 config.benchmark_ui = TRUE;
1266 help(argc, argv, FALSE);
1268 return EXIT_SUCCESS;
1271 help(argc, argv, TRUE);
1273 return EXIT_SUCCESS;
1277#ifdef ENABLE_WAYLAND
1279 g_warning(
"No valid backend was found. Make sure to launch %s from a valid "
1280 "X11 or Wayland session.",
1283 g_warning(
"No valid backend was found. Make sure to launch %s from a valid "
1289 g_warning(
"No valid backend was found. Make sure to launch %s from a valid "
1294 return EXIT_FAILURE;
1298 TICK_N(
"Workers initialize");
1300 TICK_N(
"Icon fetcher initialize");
1302 gboolean kill_running = FALSE;
1304 kill_running = TRUE;
1308 TICK_N(
"Pid file created");
1311 return EXIT_FAILURE;
1314 TICK_N(
"Text box setup");
1317 g_warning(
"Failed to properly finish display setup");
1319 return EXIT_FAILURE;
1321 TICK_N(
"Setup late Display");
1350 return EXIT_SUCCESS;
1354 iter = g_list_next(iter)) {
1355 fputs(((GString *)iter->data)->str, stderr);
1356 fputs(
"\n", stderr);
1359 iter = g_list_next(iter)) {
1360 fputs(((GString *)iter->data)->str, stderr);
1361 fputs(
"\n", stderr);
1364 return EXIT_FAILURE;
1369 if (index != NULL) {
1373 config.completer_mode == NULL ?
"(null)" :
config.completer_mode;
1374 g_warning(
"Mode: %s not found or is not valid for use as completer.", name);
gboolean display_late_setup(void)
void display_early_cleanup(void)
void display_init(const display_proxy *disp_in)
void display_cleanup(void)
guint display_scale(void)
static const display_proxy * proxy
gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings)
void display_dump_monitor_layout(void)
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 rofi_collect_modes(void)
int main(int argc, char *argv[])
GList * list_of_warning_msgs
GList * list_of_error_msgs
static void help(G_GNUC_UNUSED int argc, char **argv, const gboolean compact)
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)
gboolean display_setup_success
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 print_backend_info()
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)
void rofi_theme_set_disp_scale_func(disp_scale_func func)
gboolean rofi_theme_parse_string(const char *string)
gboolean rofi_theme_parse_file(const char *file)
display_proxy *const wayland_proxy
display_proxy *const xcb_proxy
char * x11_helper_get_window_manager(void)
ThemeWidget * rofi_configuration