Go to the documentation of this file.
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"
148 for (
unsigned int i = 0; i <
num_modi; i++ ) {
161 g_debug (
"Teardown" );
175 for (
unsigned int i = 0; i <
num_modi; i++ ) {
177 GString *str = g_string_new (
"Failed to initialize the mode: " );
178 g_string_append ( str,
modi[i]->name );
179 g_string_append ( str,
"\n" );
182 g_string_free ( str, FALSE );
254 gboolean active = FALSE;
255 for (
unsigned int j = 0; j <
num_modi; j++ ) {
261 printf (
" * %s%s%s%s\n",
271 print_help_msg (
"-no-config",
"",
"Do not load configuration, use default values.", NULL, is_term );
272 print_help_msg (
"-v,-version",
"",
"Print the version number and exit.", NULL, is_term );
273 print_help_msg (
"-dmenu",
"",
"Start in dmenu mode.", NULL, is_term );
274 print_help_msg (
"-display",
"[string]",
"X server to contact.",
"${DISPLAY}", is_term );
275 print_help_msg (
"-h,-help",
"",
"This help message.", NULL, is_term );
276 print_help_msg (
"-dump-xresources",
"",
"Dump the current configuration in Xresources format and exit.", NULL, is_term );
277 print_help_msg (
"-e",
"[string]",
"Show a dialog displaying the passed message and exit.", NULL, is_term );
278 print_help_msg (
"-markup",
"",
"Enable pango markup where possible.", NULL, is_term );
279 print_help_msg (
"-normal-window",
"",
"In dmenu mode, behave as a normal window. (experimental)", NULL, is_term );
280 print_help_msg (
"-show",
"[mode]",
"Show the mode 'mode' and exit. The mode has to be enabled.", NULL, is_term );
281 print_help_msg (
"-no-lazy-grab",
"",
"Disable lazy grab that, when fail to grab keyboard, does not block but retry later.", NULL, is_term );
282 print_help_msg (
"-no-plugins",
"",
"Disable loading of external plugins.", NULL, is_term );
283 print_help_msg (
"-plugin-path",
"",
"Directory used to search for rofi plugins.", NULL, is_term );
284 print_help_msg (
"-dump-config",
"",
"Dump the current configuration in rasi format and exit.", NULL, is_term );
285 print_help_msg (
"-dump-theme",
"",
"Dump the current theme in rasi format and exit.", NULL, is_term );
287 static void help ( G_GNUC_UNUSED
int argc,
char **argv )
289 int is_term = isatty ( fileno ( stdout ) );
290 printf (
"%s usage:\n", argv[0] );
291 printf (
"\t%s [-options ...]\n\n", argv[0] );
292 printf (
"Command line only options:\n" );
294 printf (
"DMENU command line options:\n" );
296 printf (
"Global options:\n" );
301 printf (
"Detected modi:\n" );
304 printf (
"Compile time options:\n" );
326 printf (
"For more information see: %sman rofi%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
332 printf (
" Bugreports: %s"PACKAGE_BUGREPORT
"%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
335 if (
find_arg (
"-no-config" ) < 0 ) {
344 printf (
" Configuration file: %sDisabled%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
350 int is_term = isatty ( fileno ( stdout ) );
353 fprintf ( stderr,
"Mode %s%s%s is not enabled. I have enabled it for now.\n",
355 fprintf ( stderr,
"Please consider adding %s%s%s to the list of enabled modi: %smodi: %s%s%s,%s%s.\n",
364 GString *str = g_string_new (
"");
365 g_string_printf(str,
"Mode %s is not found.\nThe following modi are known:\n", mode );
367 gboolean active = FALSE;
368 for (
unsigned int j = 0; j <
num_modi; j++ ) {
374 g_string_append_printf (str,
" * %s%s\n",
383 int is_term = isatty ( fileno ( stdout ) );
385 fprintf ( stderr,
"Rofi is unsure what to show.\n" );
386 fprintf ( stderr,
"Please specify the mode you want to show.\n\n" );
387 fprintf ( stderr,
" %srofi%s -show %s{mode}%s\n\n",
390 fprintf ( stderr,
"The following modi are enabled:\n" );
391 for (
unsigned int j = 0; j <
num_modi; j++ ) {
392 fprintf ( stderr,
" * %s%s%s\n",
397 fprintf ( stderr,
"\nThe following can be enabled:\n" );
399 gboolean active = FALSE;
400 for (
unsigned int j = 0; j <
num_modi; j++ ) {
407 fprintf ( stderr,
" * %s%s%s\n",
413 fprintf ( stderr,
"\nTo activate a mode, add it to the list of modi in the %smodi%s setting.\n",
422 for (
unsigned int i = 0; i <
num_modi; i++ ) {
444 iter != NULL; iter = g_list_next ( iter ) ) {
445 g_string_free ( (GString *) iter->data, TRUE );
497 GDir *dir = g_dir_open ( base_dir, 0, NULL );
499 const char *dn = NULL;
500 while ( ( dn = g_dir_read_name ( dir ) ) ) {
501 if ( !g_str_has_suffix ( dn, G_MODULE_SUFFIX ) ) {
504 char *fn = g_build_filename ( base_dir, dn, NULL );
505 GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL );
508 if ( g_module_symbol ( mod,
"mode", (gpointer *) &m ) ) {
510 g_warning (
"ABI version of plugin: '%s' does not match: %08X expecting: %08X", dn, m->abi_version,
ABI_VERSION );
511 g_module_close ( mod );
516 g_module_close ( mod );
521 g_warning (
"Symbol 'mode' not found in module: %s", dn );
522 g_module_close ( mod );
526 g_warning (
"Failed to open 'mode' plugin: '%s', error: %s", dn, g_module_error () );
551 if (
find_arg (
"-no-plugins" ) < 0 ) {
573 g_module_close ( mod );
612 return ( index ==
num_modi ) ? -1 : (int) index;
616 const char *
const sep =
",#";
619 char *switcher_str = g_strdup (
config.
modi );
621 for (
char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) {
627 g_free ( switcher_str );
644 return G_SOURCE_CONTINUE;
648 GString *emesg = g_string_new (
"The following errors were detected when starting rofi:\n" );
651 for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) {
652 GString *msg = (GString *) ( iter->data );
653 g_string_append ( emesg,
"\n\n" );
654 g_string_append ( emesg, msg->str );
657 if ( g_list_length ( iter ) > 1 ) {
658 g_string_append_printf ( emesg,
"\nThere are <b>%d</b> more errors.", g_list_length ( iter ) - 1 );
661 g_string_free ( emesg, TRUE );
666 static gboolean
startup ( G_GNUC_UNUSED gpointer data )
674 if (
find_arg (
"-normal-window" ) >= 0 ) {
677 TICK_N (
"Grab keyboard" );
679 TICK_N (
"Create Window" );
684 TICK_N (
"Config sanity check" );
688 return G_SOURCE_REMOVE;
703 if (
find_arg (
"-markup" ) >= 0 ) {
727 return G_SOURCE_REMOVE;
739 return G_SOURCE_REMOVE;
742 static gboolean
record ( G_GNUC_UNUSED
void *data )
745 return G_SOURCE_CONTINUE;
755 int main (
int argc,
char *argv[] )
764 g_print (
"Version: "GIT_VERSION
"\n" );
766 g_print (
"Version: "VERSION
"\n" );
780 char *base_name = g_path_get_basename ( argv[0] );
781 const char *
const dmenu_str =
"dmenu";
782 dmenu_mode = ( strcmp ( base_name, dmenu_str ) == 0 );
784 g_free ( base_name );
789 const char *path = g_get_user_runtime_dir ();
791 if ( g_mkdir_with_parents ( path, 0700 ) < 0 ) {
792 g_warning (
"Failed to create user runtime directory: %s with error: %s", path, g_strerror ( errno ) );
793 pidfile = g_build_filename ( g_get_home_dir (),
".rofi.pid", NULL );
796 pidfile = g_build_filename ( path,
"rofi.pid", NULL );
802 const char *cpath = g_get_user_config_dir ();
804 config_path = g_build_filename ( cpath,
"rofi",
"config", NULL );
811 if ( g_str_has_suffix ( c,
".rasi" ) ) {
820 if ( setlocale ( LC_ALL,
"" ) == NULL ) {
821 g_warning (
"Failed to set locale." );
826 TICK_N (
"Setup Locale" );
828 TICK_N (
"Collect MODI" );
832 main_loop = g_main_loop_new ( NULL, FALSE );
834 TICK_N (
"Setup mainloop" );
840 g_warning (
"Connection has error" );
844 TICK_N (
"Setup Display" );
850 if (
find_arg (
"-no-config" ) < 0 ) {
852 gchar *etc = g_build_filename ( SYSCONFDIR,
"rofi.conf", NULL );
853 if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
879 TICK_N (
"Parsed theme" );
883 TICK_N (
"Load cmd config " );
894 if ( g_mkdir_with_parents (
cache_dir, 0700 ) < 0 ) {
895 g_warning (
"Failed to create cache directory: %s", g_strerror ( errno ) );
900 char *windowid = NULL;
917 GBytes *theme_data = g_resource_lookup_data (
918 resources_get_resource (),
919 "/org/qtools/rofi/default_theme.rasi",
920 G_RESOURCE_LOOKUP_FLAGS_NONE,
923 const char *theme = g_bytes_get_data ( theme_data, NULL );
925 g_warning (
"Failed to parse default theme. Giving up.." );
928 iter != NULL; iter = g_list_next ( iter ) ) {
929 g_warning (
"Error: %s%s%s",
937 g_bytes_unref ( theme_data );
939 rofi_theme_convert_old ();
947 for (
int index = 0; theme_str && theme_str[index]; index++ ) {
953 g_free ( theme_str );
956 if (
find_arg (
"-dump-theme" ) >= 0 ) {
961 if (
find_arg (
"-dump-config" ) >= 0 ) {
973 if (
find_arg (
"-dump-xresources" ) >= 0 ) {
979 unsigned int interval = 1;
981 g_timeout_add ( 1000 / (
double) interval,
record, NULL );
996 g_warning (
"Failed to properly finish display setup" );
1000 TICK_N (
"Setup late Display" );
1014 g_free ( windowid );
const char ** find_arg_strv(const char *const key)
static void print_main_application_options(int is_term)
static gboolean rofi_collect_modi_add(Mode *mode)
gboolean parse_keys_abe(NkBindings *bindings)
GList * list_of_error_msgs
unsigned int num_available_modi
void rofi_view_workers_initialize(void)
void rofi_capture_screenshot(void)
static gboolean main_loop_signal_handler_int(G_GNUC_UNUSED gpointer data)
void rofi_view_clear_input(RofiViewState *state)
static void help(G_GNUC_UNUSED int argc, char **argv)
RofiViewState * rofi_view_get_active(void)
G_MODULE_EXPORT char * config_path
gboolean display_late_setup(void)
int main(int argc, char *argv[])
int rofi_view_error_dialog(const char *msg, int markup)
void display_cleanup(void)
const Mode * rofi_get_mode(unsigned int index)
void config_parse_xresource_dump(void)
void print_help_msg(const char *option, const char *type, const char *text, const char *def, int isatty)
unsigned int rofi_view_get_selected_line(const RofiViewState *state)
int mode_init(Mode *mode)
void config_parse_xresource_options_file(const char *filename)
void remove_pid_file(int fd)
void __create_window(MenuFlags menu_flags)
int find_arg(const char *const key)
void rofi_view_free(RofiViewState *state)
void rofi_icon_fetcher_destroy(void)
gboolean rofi_theme_parse_file(const char *file)
void cmd_set_arguments(int argc, char **argv)
MenuReturn rofi_view_get_return_value(const RofiViewState *state)
unsigned int sidebar_mode
void rofi_quit_main_loop(void)
void rofi_view_set_active(RofiViewState *state)
const char * mode_get_name(const Mode *mode)
Mode * script_switcher_parse_setup(const char *str)
static void rofi_collect_modi_destroy(void)
void mode_free(Mode **mode)
void rofi_theme_print(ThemeWidget *widget)
static void help_print_no_arguments(void)
int find_arg_uint(const char *const key, unsigned int *val)
void rofi_theme_free(ThemeWidget *widget)
void display_dump_monitor_layout(void)
void mode_destroy(Mode *mode)
Mode * rofi_collect_modi_search(const char *name)
static void print_list_of_modi(int is_term)
gboolean rofi_theme_parse_string(const char *string)
static void teardown(int pfd)
static gboolean record(G_GNUC_UNUSED void *data)
char * rofi_expand_path(const char *input)
static void rofi_collect_modi_dir(const char *base_dir)
static void show_error_dialog()
int config_sanity_check(void)
void config_xresource_free(void)
gboolean rofi_theme_is_empty(void)
void config_parse_cmd_options(void)
void config_parser_add_option(XrmOptionType type, const char *key, void **value, const char *comment)
int create_pid_file(const char *pidfile)
void textbox_cleanup(void)
void config_parse_dump_config_rasi_format(gboolean changes)
Dump configuration in rasi format.
void rofi_add_error_message(GString *str)
unsigned int rofi_get_num_enabled_modi(void)
int find_arg_str(const char *const key, char **val)
gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings)
static gboolean setup_modi(void)
void display_early_cleanup(void)
gboolean script_switcher_is_valid(const char *token)
void config_parse_xresource_options(xcb_stuff *xcb)
static void run_switcher(ModeMode mode)
void rofi_set_return_code(int code)
static void help_print_disabled_mode(const char *mode)
RofiViewState * rofi_view_create(Mode *sw, const char *input, MenuFlags menu_flags, void(*finalize)(RofiViewState *))
unsigned int curr_switcher
static int add_mode(const char *token)
const char * rofi_view_get_user_input(const RofiViewState *state)
static int switcher_get(const char *name)
void rofi_view_workers_finalize(void)
ModeMode mode_result(Mode *mode, int menu_retv, char **input, unsigned int selected_line)
static gboolean startup(G_GNUC_UNUSED gpointer data)
void rofi_icon_fetcher_init(void)
static void rofi_collect_modi_setup(void)
static void help_print_mode_not_found(const char *mode)
void mode_set_config(Mode *mode)
static void rofi_collect_modi(void)
G_MODULE_EXPORT char * config_path_new
void rofi_view_switch_mode(RofiViewState *state, Mode *mode)
void process_result(RofiViewState *state)