30 #define G_LOG_DOMAIN "Rofi"
43 #include <sys/types.h>
46 #include <glib-unix.h>
48 #include <libgwater-xcb.h>
50 #ifdef USE_NK_GIT_VERSION
51 #include "nkutils-git-version.h"
53 #define GIT_VERSION NK_GIT_VERSION
57 #include "resources.h"
150 for (
unsigned int i = 0; i <
num_modi; i++ ) {
163 g_debug (
"Teardown" );
177 for (
unsigned int i = 0; i <
num_modi; i++ ) {
179 GString *str = g_string_new (
"Failed to initialize the mode: " );
180 g_string_append ( str,
modi[i]->name );
181 g_string_append ( str,
"\n" );
184 g_string_free ( str, FALSE );
196 if (
find_arg (
"-selected-row" ) >= 0 ) {
270 gboolean active = FALSE;
271 for (
unsigned int j = 0; j <
num_modi; j++ ) {
277 printf (
" * %s%s%s%s\n",
287 print_help_msg (
"-no-config",
"",
"Do not load configuration, use default values.", NULL, is_term );
288 print_help_msg (
"-v,-version",
"",
"Print the version number and exit.", NULL, is_term );
289 print_help_msg (
"-dmenu",
"",
"Start in dmenu mode.", NULL, is_term );
290 print_help_msg (
"-display",
"[string]",
"X server to contact.",
"${DISPLAY}", is_term );
291 print_help_msg (
"-h,-help",
"",
"This help message.", NULL, is_term );
292 print_help_msg (
"-dump-xresources",
"",
"Dump the current configuration in Xresources format and exit.", NULL, is_term );
293 print_help_msg (
"-e",
"[string]",
"Show a dialog displaying the passed message and exit.", NULL, is_term );
294 print_help_msg (
"-markup",
"",
"Enable pango markup where possible.", NULL, is_term );
295 print_help_msg (
"-normal-window",
"",
"Behave as a normal window. (experimental)", NULL, is_term );
296 print_help_msg (
"-show",
"[mode]",
"Show the mode 'mode' and exit. The mode has to be enabled.", NULL, is_term );
297 print_help_msg (
"-no-lazy-grab",
"",
"Disable lazy grab that, when fail to grab keyboard, does not block but retry later.", NULL, is_term );
298 print_help_msg (
"-no-plugins",
"",
"Disable loading of external plugins.", NULL, is_term );
299 print_help_msg (
"-plugin-path",
"",
"Directory used to search for rofi plugins. *DEPRECATED*", NULL, is_term );
300 print_help_msg (
"-dump-config",
"",
"Dump the current configuration in rasi format and exit.", NULL, is_term );
301 print_help_msg (
"-upgrade-config",
"",
"Upgrade the old-style configuration file in the new rasi format and exit.", NULL, is_term );
302 print_help_msg (
"-dump-theme",
"",
"Dump the current theme in rasi format and exit.", NULL, is_term );
304 static void help ( G_GNUC_UNUSED
int argc,
char **argv )
306 int is_term = isatty ( fileno ( stdout ) );
307 printf (
"%s usage:\n", argv[0] );
308 printf (
"\t%s [-options ...]\n\n", argv[0] );
309 printf (
"Command line only options:\n" );
311 printf (
"DMENU command line options:\n" );
313 printf (
"Global options:\n" );
318 printf (
"Detected modi:\n" );
321 printf (
"Compile time options:\n" );
343 printf (
"For more information see: %sman rofi%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
349 printf (
" Bugreports: %s"PACKAGE_BUGREPORT
"%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
352 if (
find_arg (
"-no-config" ) < 0 ) {
361 printf (
" Configuration file: %sDisabled%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
367 int is_term = isatty ( fileno ( stdout ) );
370 fprintf ( stderr,
"Mode %s%s%s is not enabled. I have enabled it for now.\n",
372 fprintf ( stderr,
"Please consider adding %s%s%s to the list of enabled modi: %smodi: %s%s%s,%s%s.\n",
381 GString *str = g_string_new (
"" );
382 g_string_printf ( str,
"Mode %s is not found.\nThe following modi are known:\n", mode );
384 gboolean active = FALSE;
385 for (
unsigned int j = 0; j <
num_modi; j++ ) {
391 g_string_append_printf ( str,
" * %s%s\n",
400 int is_term = isatty ( fileno ( stdout ) );
402 fprintf ( stderr,
"Rofi is unsure what to show.\n" );
403 fprintf ( stderr,
"Please specify the mode you want to show.\n\n" );
404 fprintf ( stderr,
" %srofi%s -show %s{mode}%s\n\n",
407 fprintf ( stderr,
"The following modi are enabled:\n" );
408 for (
unsigned int j = 0; j <
num_modi; j++ ) {
409 fprintf ( stderr,
" * %s%s%s\n",
414 fprintf ( stderr,
"\nThe following can be enabled:\n" );
416 gboolean active = FALSE;
417 for (
unsigned int j = 0; j <
num_modi; j++ ) {
424 fprintf ( stderr,
" * %s%s%s\n",
430 fprintf ( stderr,
"\nTo activate a mode, add it to the list of modi in the %smodi%s setting.\n",
439 for (
unsigned int i = 0; i <
num_modi; i++ ) {
461 iter != NULL; iter = g_list_next ( iter ) ) {
462 g_string_free ( (GString *) iter->data, TRUE );
514 g_debug (
"Looking into: %s for plugins", base_dir );
515 GDir *dir = g_dir_open ( base_dir, 0, NULL );
517 const char *dn = NULL;
518 while ( ( dn = g_dir_read_name ( dir ) ) ) {
519 if ( !g_str_has_suffix ( dn, G_MODULE_SUFFIX ) ) {
522 char *fn = g_build_filename ( base_dir, dn, NULL );
523 g_debug (
"Trying to open: %s plugin", fn );
524 GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL );
527 if ( g_module_symbol ( mod,
"mode", (gpointer *) &m ) ) {
529 g_warning (
"ABI version of plugin: '%s' does not match: %08X expecting: %08X", dn, m->
abi_version,
ABI_VERSION );
530 g_module_close ( mod );
535 g_module_close ( mod );
540 g_warning (
"Symbol 'mode' not found in module: %s", dn );
541 g_module_close ( mod );
545 g_warning (
"Failed to open 'mode' plugin: '%s', error: %s", dn, g_module_error () );
571 if (
find_arg (
"-no-plugins" ) < 0 ) {
576 const char *path = g_getenv (
"ROFI_PLUGIN_PATH" );
577 if ( path != NULL ) {
578 gchar ** paths = g_strsplit ( path,
":", -1 );
579 for (
unsigned int i = 0; paths[i]; i++ ) {
582 g_strfreev ( paths );
602 g_module_close ( mod );
641 return ( index ==
num_modi ) ? -1 : (int) index;
645 const char *
const sep =
",#";
648 char *switcher_str = g_strdup (
config.
modi );
650 for (
char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) {
656 g_free ( switcher_str );
673 return G_SOURCE_CONTINUE;
677 GString *emesg = g_string_new (
"The following errors were detected when starting rofi:\n" );
680 for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) {
681 GString *msg = (GString *) ( iter->data );
682 g_string_append ( emesg,
"\n\n" );
683 g_string_append ( emesg, msg->str );
686 if ( g_list_length ( iter ) > 1 ) {
687 g_string_append_printf ( emesg,
"\nThere are <b>%d</b> more errors.", g_list_length ( iter ) - 1 );
690 g_string_free ( emesg, TRUE );
694 static gboolean
startup ( G_GNUC_UNUSED gpointer data )
702 if (
find_arg (
"-normal-window" ) >= 0 ) {
705 TICK_N (
"Grab keyboard" );
707 TICK_N (
"Create Window" );
712 TICK_N (
"Config sanity check" );
716 return G_SOURCE_REMOVE;
731 if (
find_arg (
"-markup" ) >= 0 ) {
755 return G_SOURCE_REMOVE;
767 return G_SOURCE_REMOVE;
770 static gboolean
record ( G_GNUC_UNUSED
void *data )
773 return G_SOURCE_CONTINUE;
783 int main (
int argc,
char *argv[] )
792 g_print (
"Version: "GIT_VERSION
"\n" );
794 g_print (
"Version: "VERSION
"\n" );
800 const char *ro_pid = g_getenv (
"ROFI_OUTSIDE" );
801 if ( ro_pid != NULL ) {
802 int ro_pidi = g_ascii_strtoll ( ro_pid, NULL, 0 );
803 if ( kill ( ro_pidi, 0 ) == 0 ) {
804 printf (
"Do not launch rofi from inside rofi.\r\n" );
819 char *base_name = g_path_get_basename ( argv[0] );
820 const char *
const dmenu_str =
"dmenu";
821 dmenu_mode = ( strcmp ( base_name, dmenu_str ) == 0 );
823 g_free ( base_name );
828 const char *path = g_get_user_runtime_dir ();
830 if ( g_mkdir_with_parents ( path, 0700 ) < 0 ) {
831 g_warning (
"Failed to create user runtime directory: %s with error: %s", path, g_strerror ( errno ) );
832 pidfile = g_build_filename ( g_get_home_dir (),
".rofi.pid", NULL );
835 pidfile = g_build_filename ( path,
"rofi.pid", NULL );
841 const char *cpath = g_get_user_config_dir ();
843 config_path = g_build_filename ( cpath,
"rofi",
"config", NULL );
850 if ( g_str_has_suffix ( c,
".rasi" ) ) {
859 if ( setlocale ( LC_ALL,
"" ) == NULL ) {
860 g_warning (
"Failed to set locale." );
865 TICK_N (
"Setup Locale" );
867 TICK_N (
"Collect MODI" );
871 main_loop = g_main_loop_new ( NULL, FALSE );
873 TICK_N (
"Setup mainloop" );
879 g_warning (
"Connection has error" );
883 TICK_N (
"Setup Display" );
889 if (
find_arg (
"-no-config" ) < 0 ) {
891 gboolean found_system = FALSE;
892 const char *
const * dirs = g_get_system_config_dirs ();
894 for (
unsigned int i = 0; !found_system && dirs[i]; i++ ) {
896 gchar *etc = g_build_filename ( dirs[i],
"rofi.rasi", NULL );
897 g_debug (
"Look for default config file: %s", etc );
898 if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
899 g_debug (
"Parsing: %s", etc );
905 gchar *xetc = g_build_filename ( dirs[i],
"rofi.conf", NULL );
906 g_debug (
"Look for default config file: %s", xetc );
907 if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) {
917 if ( !found_system ) {
919 gchar *etc = g_build_filename ( SYSCONFDIR,
"rofi.rasi", NULL );
920 g_debug (
"Look for default config file: %s", etc );
921 if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
922 g_debug (
"Look for default config file: %s", etc );
927 gchar *xetc = g_build_filename ( SYSCONFDIR,
"rofi.conf", NULL );
928 g_debug (
"Look for default config file: %s", xetc );
929 if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) {
949 if ( g_file_test (
config_path, G_FILE_TEST_IS_REGULAR ) ) {
963 TICK_N (
"Parsed theme" );
967 TICK_N (
"Load cmd config " );
970 g_warning (
"The old Xresources based configuration format is deprecated." );
971 g_warning (
"Please upgrade: rofi -upgrade-config." );
982 if ( g_mkdir_with_parents (
cache_dir, 0700 ) < 0 ) {
983 g_warning (
"Failed to create cache directory: %s", g_strerror ( errno ) );
988 char *windowid = NULL;
1005 GBytes *theme_data = g_resource_lookup_data (
1006 resources_get_resource (),
1007 "/org/qtools/rofi/default_theme.rasi",
1008 G_RESOURCE_LOOKUP_FLAGS_NONE,
1011 const char *theme = g_bytes_get_data ( theme_data, NULL );
1013 g_warning (
"Failed to parse default theme. Giving up.." );
1016 iter != NULL; iter = g_list_next ( iter ) ) {
1017 g_warning (
"Error: %s%s%s",
1023 return EXIT_FAILURE;
1025 g_bytes_unref ( theme_data );
1027 rofi_theme_convert_old ();
1035 for (
int index = 0; theme_str && theme_str[index]; index++ ) {
1041 g_free ( theme_str );
1044 if (
find_arg (
"-dump-theme" ) >= 0 ) {
1047 return EXIT_SUCCESS;
1049 if (
find_arg (
"-upgrade-config" ) >= 0 ) {
1052 for (
unsigned int i = 0; i <
num_modi; i++ ) {
1056 const char *cpath = g_get_user_config_dir ();
1058 char *fcpath = g_build_filename ( cpath,
"rofi", NULL );
1059 if ( !g_file_test ( fcpath, G_FILE_TEST_IS_DIR ) && g_mkdir_with_parents ( fcpath, 0700 ) < 0 ) {
1060 g_warning (
"Failed to create rofi configuration directory: %s", fcpath );
1063 return EXIT_FAILURE;
1066 fcpath = g_build_filename ( cpath,
"rofi",
"config.rasi", NULL );
1067 if ( g_file_test ( fcpath, G_FILE_TEST_IS_REGULAR ) ) {
1068 g_warning (
"New configuration file already exists: %s", fcpath );
1071 return EXIT_FAILURE;
1073 FILE *fd = fopen ( fcpath,
"w" );
1075 g_warning (
"Failed to open new rofi configuration file: %s: %s", fcpath, strerror ( errno ) );
1078 return EXIT_FAILURE;
1081 fprintf ( stdout,
"\n***** Generated configuration file in: %s *****\n", fcpath );
1088 g_warning (
"Failed to get user configuration directory." );
1090 return EXIT_FAILURE;
1093 return EXIT_SUCCESS;
1095 if (
find_arg (
"-dump-config" ) >= 0 ) {
1098 return EXIT_SUCCESS;
1103 help ( argc, argv );
1105 return EXIT_SUCCESS;
1107 if (
find_arg (
"-dump-xresources" ) >= 0 ) {
1110 return EXIT_SUCCESS;
1113 unsigned int interval = 1;
1115 g_timeout_add ( 1000 / (
double) interval,
record, NULL );
1117 if (
find_arg (
"-benchmark-ui" ) >= 0 ) {
1122 TICK_N (
"Workers initialize" );
1124 TICK_N (
"Icon fetcher initialize" );
1128 TICK_N (
"Pid file created" );
1131 return EXIT_FAILURE;
1134 TICK_N (
"Text box setup" );
1137 g_warning (
"Failed to properly finish display setup" );
1139 return EXIT_FAILURE;
1141 TICK_N (
"Setup late Display" );
1144 TICK_N (
"Theme setup" );
1158 g_free ( windowid );
void config_parse_cmd_options(void)
void config_parse_xresource_options_file(const char *filename)
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 config_parse_xresource_dump(void)
void config_parse_xresource_options(xcb_stuff *xcb)
void cmd_set_arguments(int argc, char **argv)
int create_pid_file(const char *pidfile)
const char ** find_arg_strv(const char *const key)
void remove_pid_file(int fd)
char * rofi_expand_path(const char *input)
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 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)
int mode_init(Mode *mode)
void mode_free(Mode **mode)
ModeMode mode_result(Mode *mode, int menu_retv, char **input, unsigned int selected_line)
const char * mode_get_name(const Mode *mode)
void mode_set_config(Mode *mode)
void rofi_quit_main_loop(void)
Mode * rofi_collect_modi_search(const char *name)
void rofi_set_return_code(int code)
unsigned int rofi_get_num_enabled_modi(void)
const Mode * rofi_get_mode(unsigned int index)
void rofi_add_error_message(GString *str)
Mode * script_switcher_parse_setup(const char *str)
gboolean script_switcher_is_valid(const char *token)
void textbox_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)
RofiViewState * rofi_view_get_active(void)
int rofi_view_error_dialog(const char *msg, int markup)
void rofi_view_set_active(RofiViewState *state)
MenuReturn rofi_view_get_return_value(const RofiViewState *state)
void rofi_view_set_selected_line(RofiViewState *state, unsigned int selected_line)
RofiViewState * rofi_view_create(Mode *sw, const char *input, MenuFlags menu_flags, void(*finalize)(RofiViewState *))
void rofi_view_free(RofiViewState *state)
const char * rofi_view_get_user_input(const RofiViewState *state)
unsigned int rofi_view_get_selected_line(const RofiViewState *state)
static void help(G_GNUC_UNUSED int argc, char **argv)
static void rofi_collect_modi_setup(void)
static void rofi_collect_modi_destroy(void)
int main(int argc, char *argv[])
static int switcher_get(const char *name)
static gboolean record(G_GNUC_UNUSED void *data)
GList * list_of_error_msgs
G_MODULE_EXPORT char * config_path
static void print_main_application_options(int is_term)
static void run_switcher(ModeMode mode)
static gboolean old_config_format
static void help_print_mode_not_found(const char *mode)
static void print_list_of_modi(int is_term)
static void rofi_collect_modi_dir(const char *base_dir)
static gboolean startup(G_GNUC_UNUSED gpointer data)
static void rofi_collect_modi(void)
static void teardown(int pfd)
static void show_error_dialog()
void process_result(RofiViewState *state)
unsigned int num_available_modi
static int add_mode(const char *token)
static gboolean main_loop_signal_handler_int(G_GNUC_UNUSED gpointer data)
static gboolean setup_modi(void)
unsigned int curr_switcher
static void help_print_no_arguments(void)
static void help_print_disabled_mode(const char *mode)
static gboolean rofi_collect_modi_add(Mode *mode)
G_MODULE_EXPORT char * config_path_new
unsigned int sidebar_mode
void rofi_theme_parse_process_conditionals(void)
void rofi_theme_print(ThemeWidget *widget)
void rofi_theme_free(ThemeWidget *widget)
gboolean rofi_theme_is_empty(void)
gboolean rofi_theme_parse_string(const char *string)
gboolean rofi_theme_parse_file(const char *file)
void rofi_capture_screenshot(void)
void rofi_view_workers_initialize(void)
void rofi_view_workers_finalize(void)
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)