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
101 iter = g_list_next(iter)) {
102 g_string_free((GString *)iter->data, TRUE);
114 iter = g_list_next(iter)) {
115 g_string_free((GString *)iter->data, TRUE);
164 for (
unsigned int i = 0; i <
num_modes; i++) {
205 for (
unsigned int i = 0; i <
num_modes; i++) {
207 GString *str = g_string_new(
"Failed to initialize the mode: ");
208 g_string_append(str,
modes[i]->name);
209 g_string_append(str,
"\n");
212 g_string_free(str, FALSE);
225 if (
find_arg(
"-selected-row") >= 0) {
300 gboolean active = FALSE;
301 for (
unsigned int j = 0; j <
num_modes; j++) {
307 printf(
" • %s%s%s%s\n", active ?
"+" :
"",
313 print_help_msg(
"-config",
"[file]",
"Load an alternative configuration.",
316 "Do not load configuration, use default values.", NULL,
318 print_help_msg(
"-v,-version",
"",
"Print the version number and exit.", NULL,
320 print_help_msg(
"-dmenu",
"",
"Start in dmenu mode.", NULL, is_term);
321 print_help_msg(
"-display",
"[string]",
"X server to contact.",
"${DISPLAY}",
323 print_help_msg(
"-h,-help",
"",
"This help message.", NULL, is_term);
325 "Show a dialog displaying the passed message and exit.", NULL,
327 print_help_msg(
"-markup",
"",
"Enable pango markup where possible.", NULL,
330 "Behave as a normal window. (experimental)", NULL, is_term);
332 "Behave as a modal dialog that is transient to the currently "
333 "focused window. (experimental)",
336 "Show the mode 'mode' and exit. The mode has to be enabled.",
339 "Disable lazy grab that, when fail to grab keyboard, does not "
340 "block but retry later.",
342 print_help_msg(
"-no-plugins",
"",
"Disable loading of external plugins.",
345 "Directory used to search for rofi plugins. *DEPRECATED*",
348 "Dump the current configuration in rasi format and exit.",
351 "Dump the current theme in rasi format and exit.", NULL,
354 "Print a list of current keybindings and exit.", NULL,
357static void help(G_GNUC_UNUSED
int argc,
char **argv) {
358 int is_term = isatty(fileno(stdout));
359 printf(
"%s usage:\n", argv[0]);
360 printf(
"\t%s [-options ...]\n\n", argv[0]);
361 printf(
"Command line only options:\n");
363 printf(
"DMENU command line options:\n");
365 printf(
"Global options:\n");
368 printf(
"Detected Window manager:\n");
371 printf(
"\t• %s\n", wm);
374 printf(
"\t• No window manager detected.\n");
379 printf(
"Detected modes:\n");
382 printf(
"Detected user scripts:\n");
385 printf(
"Compile time options:\n");
386 printf(
"\t• Pango version %s\n", pango_version_string());
388 printf(
"\t• window %senabled%s\n", is_term ?
color_green :
"",
391 printf(
"\t• window %sdisabled%s\n", is_term ?
color_red :
"",
395 printf(
"\t• drun %senabled%s\n", is_term ?
color_green :
"",
398 printf(
"\t• drun %sdisabled%s\n", is_term ?
color_red :
"",
402 printf(
"\t• gcov %senabled%s\n", is_term ?
color_green :
"",
405 printf(
"\t• gcov %sdisabled%s\n", is_term ?
color_red :
"",
409 printf(
"\t• asan %senabled%s\n", is_term ?
color_green :
"",
412 printf(
"\t• asan %sdisabled%s\n", is_term ?
color_red :
"",
416 printf(
"\t• imdkit %senabled%s\n", is_term ?
color_green :
"",
419 printf(
"\t• imdkit %sdisabled%s\n", is_term ?
color_red :
"",
423 printf(
"For more information see: %sman rofi%s\n", is_term ?
color_bold :
"",
426 printf(
" Version: %s" GIT_VERSION
"%s\n",
429 printf(
" Version: %s" VERSION
"%s\n",
432 printf(
" Bugreports: %s" PACKAGE_BUGREPORT
"%s\n",
434 printf(
" Support: %s" PACKAGE_URL
"%s\n",
436 printf(
" %s#rofi @ libera.chat%s\n",
440 printf(
" Configuration file: %s%s%s\n", is_term ?
color_bold :
"",
444 printf(
" Configuration file: %sDisabled%s\n",
451 int is_term = isatty(fileno(stdout));
454 fprintf(stderr,
"Mode %s%s%s is not enabled. I have enabled it for now.\n",
457 "Please consider adding %s%s%s to the list of enabled modes: "
458 "%smodes: [%s%s%s,%s]%s.\n",
464 GString *str = g_string_new(
"");
466 str,
"Mode %s is not found.\nThe following modes are known:\n", mode);
468 gboolean active = FALSE;
469 for (
unsigned int j = 0; j <
num_modes; j++) {
475 g_string_append_printf(str,
" * %s%s\n", active ?
"+" :
"",
482 GString *emesg = g_string_new(
483 "<span size=\"x-large\">Rofi is unsure what to show.</span>\n\n");
484 g_string_append(emesg,
"Please specify the mode you want to show.\n\n");
486 emesg,
" <b>rofi</b> -show <span color=\"green\">{mode}</span>\n\n");
487 g_string_append(emesg,
"The following modes are enabled:\n");
488 for (
unsigned int j = 0; j <
num_modes; j++) {
489 g_string_append_printf(emesg,
" • <span color=\"green\">%s</span>\n",
492 g_string_append(emesg,
"\nThe following modes can be enabled:\n");
494 gboolean active = FALSE;
495 for (
unsigned int j = 0; j <
num_modes; j++) {
502 g_string_append_printf(emesg,
" • <span color=\"red\">%s</span>\n",
506 g_string_append(emesg,
"\nTo activate a mode, add it to the list in "
507 "the <span color=\"green\">modes</span> "
517 for (
unsigned int i = 0; i <
num_modes; i++) {
591 g_debug(
"Looking into: %s for plugins", base_dir);
592 GDir *dir = g_dir_open(base_dir, 0, NULL);
594 const char *dn = NULL;
595 while ((dn = g_dir_read_name(dir))) {
596 if (!g_str_has_suffix(dn, G_MODULE_SUFFIX)) {
599 char *fn = g_build_filename(base_dir, dn, NULL);
600 g_debug(
"Trying to open: %s plugin", fn);
602 g_module_open(fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
605 if (g_module_symbol(mod,
"mode", (gpointer *)&m)) {
607 g_warning(
"ABI version of plugin: '%s' does not match: %08X "
618 g_warning(
"Symbol 'mode' not found in module: %s", dn);
622 g_warning(
"Failed to open 'mode' plugin: '%s', error: %s", dn,
651 g_debug(
"Parse plugin path: %s",
config.plugin_path);
654 const char *path = g_getenv(
"ROFI_PLUGIN_PATH");
656 gchar **paths = g_strsplit(path,
":", -1);
657 for (
unsigned int i = 0; paths[i]; i++) {
717 return (index ==
num_modes) ? -1 : (int)index;
720 const char *
const sep =
",#";
723 char *mode_str = g_strdup(
config.modes);
725 for (
char *token = strtok_r(mode_str, sep, &savept); token != NULL;
726 token = strtok_r(NULL, sep, &savept)) {
745 return G_SOURCE_CONTINUE;
749 g_string_new(
"The following errors were detected when starting rofi:\n");
752 for (; iter != NULL && index < 2; iter = g_list_next(iter)) {
753 GString *msg = (GString *)(iter->data);
754 g_string_append(emesg,
"\n\n");
755 g_string_append(emesg, msg->str);
758 if (g_list_length(iter) > 1) {
759 g_string_append_printf(emesg,
"\nThere are <b>%u</b> more errors.",
760 g_list_length(iter) - 1);
763 g_string_free(emesg, TRUE);
767static gboolean
startup(G_GNUC_UNUSED gpointer data) {
774 if (
find_arg(
"-normal-window") >= 0) {
777 if (
find_arg(
"-transient-window") >= 0) {
787 TICK_N(
"Config sanity check");
791 return G_SOURCE_REMOVE;
795 iter = g_list_next(iter)) {
796 fputs(((GString *)iter->data)->str, stderr);
803 config.sidebar_mode = FALSE;
816 if (g_strcmp0(msg,
"-") == 0) {
817 size_t index = 0, i = 0;
818 size_t length = 1024;
819 msg = malloc(length *
sizeof(
char));
820 while ((i = fread(&msg[index], 1, 1024, stdin)) > 0) {
823 msg = realloc(msg, length *
sizeof(
char));
852 return G_SOURCE_REMOVE;
862 return G_SOURCE_REMOVE;
868 return G_SOURCE_REMOVE;
870static gboolean
record(G_GNUC_UNUSED
void *data) {
872 return G_SOURCE_CONTINUE;
875 G_GNUC_UNUSED GLogLevelFlags log_level,
876 const gchar *message, gpointer user_data) {
877 int fp = GPOINTER_TO_INT(user_data);
878 dprintf(fp,
"[%s]: %s\n", log_domain == NULL ?
"default" : log_domain,
889int main(
int argc,
char *argv[]) {
892 char *logfile = NULL;
894 if (logfile != NULL) {
895 int fp = open(logfile, O_CLOEXEC | O_APPEND | O_CREAT | O_WRONLY,
899 GINT_TO_POINTER(fp));
902 g_error(
"Failed to open logfile '%s': %s.", logfile, strerror(errno));
906 g_warning(
"Option '-log' should pass in a filename.");
914 g_print(
"Version: " GIT_VERSION
"\n");
916 g_print(
"Version: " VERSION
"\n");
921 if (
find_arg(
"-rasi-validate") >= 0) {
929 fprintf(stderr,
"Usage: %s -rasi-validate my-theme.rasi", argv[0]);
934 const char *ro_pid = g_getenv(
"ROFI_OUTSIDE");
935 if (ro_pid != NULL) {
936 pid_t ro_pidi = (pid_t)g_ascii_strtoll(ro_pid, NULL, 0);
937 if (kill(ro_pidi, 0) == 0) {
938 printf(
"Do not launch rofi from inside rofi.\r\n");
953 char *base_name = g_path_get_basename(argv[0]);
954 const char *
const dmenu_str =
"dmenu";
962 const char *path = g_get_user_runtime_dir();
964 if (g_mkdir_with_parents(path, 0700) < 0) {
965 g_warning(
"Failed to create user runtime directory: %s with error: %s",
966 path, g_strerror(errno));
967 pidfile = g_build_filename(g_get_home_dir(),
".rofi.pid", NULL);
969 pidfile = g_build_filename(path,
"rofi.pid", NULL);
976 if (
find_arg(
"-no-default-config") < 0) {
977 GBytes *theme_data = g_resource_lookup_data(
978 resources_get_resource(),
"/org/qtools/rofi/default_configuration.rasi",
979 G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
981 const char *theme = g_bytes_get_data(theme_data, NULL);
983 g_warning(
"Failed to parse default configuration. Giving up..");
986 iter = g_list_next(iter)) {
987 g_warning(
"Error: %s%s%s",
color_bold, ((GString *)iter->data)->str,
995 g_bytes_unref(theme_data);
1000 const char *cpath = g_get_user_config_dir();
1002 config_path = g_build_filename(cpath,
"rofi",
"config.rasi", NULL);
1011 if (setlocale(LC_ALL,
"") == NULL) {
1012 g_warning(
"Failed to set locale.");
1014 return EXIT_FAILURE;
1023 main_loop = g_main_loop_new(NULL, FALSE);
1025 TICK_N(
"Setup mainloop");
1031 g_warning(
"Connection has error");
1033 return EXIT_FAILURE;
1043 gboolean found_system = FALSE;
1044 const char *
const *dirs = g_get_system_config_dirs();
1046 for (
unsigned int i = 0; !found_system && dirs[i]; i++) {
1048 gchar *etc = g_build_filename(dirs[i],
"rofi.rasi", NULL);
1049 g_debug(
"Look for default config file: %s", etc);
1050 if (g_file_test(etc, G_FILE_TEST_IS_REGULAR)) {
1051 g_debug(
"Parsing: %s", etc);
1053 found_system = TRUE;
1058 if (!found_system) {
1060 gchar *etc = g_build_filename(SYSCONFDIR,
"rofi.rasi", NULL);
1061 g_debug(
"Look for default config file: %s", etc);
1062 if (g_file_test(etc, G_FILE_TEST_IS_REGULAR)) {
1063 g_debug(
"Look for default config file: %s", etc);
1071 extern const char *rasi_theme_file_extensions[];
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)
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)
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)
char * rofi_theme_parse_prepare_file(const char *file)
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