30 #define G_LOG_DOMAIN "Rofi" 43 #include <sys/types.h> 45 #include <glib-unix.h> 47 #include <libgwater-xcb.h> 49 #ifdef USE_NK_GIT_VERSION 50 #include "nkutils-git-version.h" 52 #define GIT_VERSION NK_GIT_VERSION 56 #include "resources.h" 147 for (
unsigned int i = 0; i <
num_modi; i++ ) {
160 g_debug (
"Teardown" );
174 for (
unsigned int i = 0; i <
num_modi; i++ ) {
176 GString *str = g_string_new (
"Failed to initialize the mode: " );
177 g_string_append ( str,
modi[i]->name );
178 g_string_append ( str,
"\n" );
181 g_string_free ( str, FALSE );
253 gboolean active = FALSE;
254 for (
unsigned int j = 0; j <
num_modi; j++ ) {
260 printf (
" * %s%s%s%s\n",
270 print_help_msg (
"-no-config",
"",
"Do not load configuration, use default values.", NULL, is_term );
271 print_help_msg (
"-v,-version",
"",
"Print the version number and exit.", NULL, is_term );
272 print_help_msg (
"-dmenu",
"",
"Start in dmenu mode.", NULL, is_term );
273 print_help_msg (
"-display",
"[string]",
"X server to contact.",
"${DISPLAY}", is_term );
274 print_help_msg (
"-h,-help",
"",
"This help message.", NULL, is_term );
275 print_help_msg (
"-dump-xresources",
"",
"Dump the current configuration in Xresources format and exit.", NULL, is_term );
276 print_help_msg (
"-e",
"[string]",
"Show a dialog displaying the passed message and exit.", NULL, is_term );
277 print_help_msg (
"-markup",
"",
"Enable pango markup where possible.", NULL, is_term );
278 print_help_msg (
"-normal-window",
"",
"In dmenu mode, behave as a normal window. (experimental)", NULL, is_term );
279 print_help_msg (
"-show",
"[mode]",
"Show the mode 'mode' and exit. The mode has to be enabled.", NULL, is_term );
280 print_help_msg (
"-no-lazy-grab",
"",
"Disable lazy grab that, when fail to grab keyboard, does not block but retry later.", NULL, is_term );
281 print_help_msg (
"-no-plugins",
"",
"Disable loading of external plugins.", NULL, is_term );
282 print_help_msg (
"-plugin-path",
"",
"Directory used to search for rofi plugins.", NULL, is_term );
283 print_help_msg (
"-dump-config",
"",
"Dump the current configuration in rasi format and exit.", NULL, is_term );
284 print_help_msg (
"-dump-theme",
"",
"Dump the current theme in rasi format and exit.", NULL, is_term );
286 static void help ( G_GNUC_UNUSED
int argc,
char **argv )
288 int is_term = isatty ( fileno ( stdout ) );
289 printf (
"%s usage:\n", argv[0] );
290 printf (
"\t%s [-options ...]\n\n", argv[0] );
291 printf (
"Command line only options:\n" );
293 printf (
"DMENU command line options:\n" );
295 printf (
"Global options:\n" );
300 printf (
"Detected modi:\n" );
303 printf (
"Compile time options:\n" );
330 printf (
"For more information see: %sman rofi%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
336 printf (
" Bugreports: %s"PACKAGE_BUGREPORT
"%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
339 if (
find_arg (
"-no-config" ) < 0 ) {
348 printf (
" Configuration file: %sDisabled%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
354 int is_term = isatty ( fileno ( stdout ) );
357 fprintf ( stderr,
"Mode %s%s%s is not enabled. I have enabled it for now.\n",
359 fprintf ( stderr,
"Please consider adding %s%s%s to the list of enabled modi: %smodi: %s%s%s,%s%s.\n",
368 int is_term = isatty ( fileno ( stdout ) );
369 fprintf ( stderr,
"Mode %s%s%s is not found.\n",
371 fprintf ( stderr,
"The following modi are known:\n" );
377 int is_term = isatty ( fileno ( stdout ) );
379 fprintf ( stderr,
"Rofi is unsure what to show.\n" );
380 fprintf ( stderr,
"Please specify the mode you want to show.\n\n" );
381 fprintf ( stderr,
" %srofi%s -show %s{mode}%s\n\n",
384 fprintf ( stderr,
"The following modi are enabled:\n" );
385 for (
unsigned int j = 0; j <
num_modi; j++ ) {
386 fprintf ( stderr,
" * %s%s%s\n",
391 fprintf ( stderr,
"\nThe following can be enabled:\n" );
393 gboolean active = FALSE;
394 for (
unsigned int j = 0; j <
num_modi; j++ ) {
401 fprintf ( stderr,
" * %s%s%s\n",
407 fprintf ( stderr,
"\nTo activate a mode, add it to the list of modi in the %smodi%s setting.\n",
416 for (
unsigned int i = 0; i <
num_modi; i++ ) {
438 iter != NULL; iter = g_list_next ( iter ) ) {
439 g_string_free ( (GString *) iter->data, TRUE );
491 GDir *dir = g_dir_open ( base_dir, 0, NULL );
493 const char *dn = NULL;
494 while ( ( dn = g_dir_read_name ( dir ) ) ) {
495 if ( !g_str_has_suffix ( dn, G_MODULE_SUFFIX ) ) {
498 char *fn = g_build_filename ( base_dir, dn, NULL );
499 GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL );
502 if ( g_module_symbol ( mod,
"mode", (gpointer *) &m ) ) {
504 g_warning (
"ABI version of plugin: '%s' does not match: %08X expecting: %08X", dn, m->abi_version,
ABI_VERSION );
505 g_module_close ( mod );
510 g_module_close ( mod );
515 g_warning (
"Symbol 'mode' not found in module: %s", dn );
516 g_module_close ( mod );
520 g_warning (
"Failed to open 'mode' plugin: '%s', error: %s", dn, g_module_error () );
545 if (
find_arg (
"-no-plugins" ) < 0 ) {
567 g_module_close ( mod );
606 return ( index ==
num_modi ) ? -1 : (int) index;
610 const char *
const sep =
",#";
613 char *switcher_str = g_strdup (
config.
modi );
615 for (
char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) {
618 g_free ( switcher_str );
623 g_free ( switcher_str );
640 return G_SOURCE_CONTINUE;
643 static gboolean
startup ( G_GNUC_UNUSED gpointer data )
651 if (
find_arg (
"-normal-window" ) >= 0 ) {
654 TICK_N (
"Grab keyboard" );
656 TICK_N (
"Create Window" );
661 TICK_N (
"Config sanity check" );
664 GString *emesg = g_string_new (
"The following errors were detected when starting rofi:\n" );
667 for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) {
668 GString *msg = (GString *) ( iter->data );
669 g_string_append ( emesg,
"\n\n" );
670 g_string_append ( emesg, msg->str );
673 if ( g_list_length ( iter ) > 1 ) {
674 g_string_append_printf ( emesg,
"\nThere are <b>%d</b> more errors.", g_list_length ( iter ) - 1 );
677 g_string_free ( emesg, TRUE );
678 return G_SOURCE_REMOVE;
693 if (
find_arg (
"-markup" ) >= 0 ) {
717 return G_SOURCE_REMOVE;
729 return G_SOURCE_REMOVE;
732 static gboolean
record ( G_GNUC_UNUSED
void *data )
735 return G_SOURCE_CONTINUE;
745 int main (
int argc,
char *argv[] )
754 g_print (
"Version: "GIT_VERSION
"\n" );
756 g_print (
"Version: "VERSION
"\n" );
770 char *base_name = g_path_get_basename ( argv[0] );
771 const char *
const dmenu_str =
"dmenu";
772 dmenu_mode = ( strcmp ( base_name, dmenu_str ) == 0 );
774 g_free ( base_name );
780 if ( g_mkdir_with_parents (
cache_dir, 0700 ) < 0 ) {
781 g_warning (
"Failed to create cache directory: %s", g_strerror ( errno ) );
786 const char *path = g_get_user_runtime_dir ();
788 if ( g_mkdir_with_parents ( path, 0700 ) < 0 ) {
789 g_warning (
"Failed to create user runtime directory: %s with error: %s", path, g_strerror ( errno ) );
790 pidfile = g_build_filename ( g_get_home_dir (),
".rofi.pid", NULL );
793 pidfile = g_build_filename ( path,
"rofi.pid", NULL );
799 const char *cpath = g_get_user_config_dir ();
801 config_path = g_build_filename ( cpath,
"rofi",
"config", NULL );
808 if ( g_str_has_suffix ( c,
".rasi" ) ) {
817 if ( setlocale ( LC_ALL,
"" ) == NULL ) {
818 g_warning (
"Failed to set locale." );
823 TICK_N (
"Setup Locale" );
825 TICK_N (
"Collect MODI" );
829 main_loop = g_main_loop_new ( NULL, FALSE );
831 TICK_N (
"Setup mainloop" );
837 g_warning (
"Connection has error" );
841 TICK_N (
"Setup Display" );
847 if (
find_arg (
"-no-config" ) < 0 ) {
849 gchar *etc = g_build_filename ( SYSCONFDIR,
"rofi.conf", NULL );
850 if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
876 TICK_N (
"Parsed theme" );
880 TICK_N (
"Load cmd config " );
885 char *windowid = NULL;
902 GBytes *theme_data = g_resource_lookup_data (
903 resources_get_resource (),
904 "/org/qtools/rofi/default_theme.rasi",
905 G_RESOURCE_LOOKUP_FLAGS_NONE,
908 const char *theme = g_bytes_get_data ( theme_data, NULL );
910 g_warning (
"Failed to parse default theme. Giving up.." );
913 iter != NULL; iter = g_list_next ( iter ) ) {
914 g_warning (
"Error: %s%s%s",
922 g_bytes_unref ( theme_data );
924 rofi_theme_convert_old ();
932 for (
int index = 0; theme_str && theme_str[index]; index++ ) {
938 g_free ( theme_str );
941 if (
find_arg (
"-dump-theme" ) >= 0 ) {
946 if (
find_arg (
"-dump-config" ) >= 0 ) {
958 if (
find_arg (
"-dump-xresources" ) >= 0 ) {
964 unsigned int interval = 1;
966 g_timeout_add ( 1000 / (
double) interval,
record, NULL );
981 g_warning (
"Failed to properly finish display setup" );
985 TICK_N (
"Setup late Display" );
void rofi_theme_free(ThemeWidget *widget)
void rofi_icon_fetcher_destroy(void)
void rofi_quit_main_loop(void)
void textbox_cleanup(void)
void display_early_cleanup(void)
void rofi_set_return_code(int code)
void rofi_view_clear_input(RofiViewState *state)
unsigned int sidebar_mode
static void rofi_collect_modi_destroy(void)
void rofi_view_workers_finalize(void)
static gboolean startup(G_GNUC_UNUSED gpointer data)
const char * rofi_view_get_user_input(const RofiViewState *state)
void __create_window(MenuFlags menu_flags)
void config_parse_xresource_dump(void)
static void rofi_collect_modi(void)
static void print_list_of_modi(int is_term)
int config_sanity_check(void)
void mode_free(Mode **mode)
static void teardown(int pfd)
static void rofi_collect_modi_setup(void)
RofiViewState * rofi_view_get_active(void)
int find_arg_uint(const char *const key, unsigned int *val)
unsigned int rofi_get_num_enabled_modi(void)
MenuReturn rofi_view_get_return_value(const RofiViewState *state)
int find_arg_str(const char *const key, char **val)
const char ** find_arg_strv(const char *const key)
void config_parse_xresource_options_file(const char *filename)
unsigned int num_available_modi
void rofi_view_workers_initialize(void)
G_MODULE_EXPORT char * config_path_new
void rofi_view_free(RofiViewState *state)
void display_cleanup(void)
gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings)
void print_help_msg(const char *option, const char *type, const char *text, const char *def, int isatty)
void config_parse_xresource_options(xcb_stuff *xcb)
void mode_set_config(Mode *mode)
Mode * rofi_collect_modi_search(const char *name)
void remove_pid_file(int fd)
static int switcher_get(const char *name)
void mode_destroy(Mode *mode)
gboolean rofi_theme_parse_file(const char *file)
void config_xresource_free(void)
static void help_print_disabled_mode(const char *mode)
static void help_print_mode_not_found(const char *mode)
void rofi_view_set_active(RofiViewState *state)
static int add_mode(const char *token)
int rofi_view_error_dialog(const char *msg, int markup)
G_MODULE_EXPORT char * config_path
int main(int argc, char *argv[])
void rofi_add_error_message(GString *str)
void cmd_set_arguments(int argc, char **argv)
gboolean script_switcher_is_valid(const char *token)
char * rofi_expand_path(const char *input)
void rofi_theme_print(ThemeWidget *widget)
void display_dump_monitor_layout(void)
static void print_main_application_options(int is_term)
void rofi_view_switch_mode(RofiViewState *state, Mode *mode)
int create_pid_file(const char *pidfile)
GList * list_of_error_msgs
unsigned int curr_switcher
const char * mode_get_name(const Mode *mode)
Mode * script_switcher_parse_setup(const char *str)
void process_result(RofiViewState *state)
ModeMode mode_result(Mode *mode, int menu_retv, char **input, unsigned int selected_line)
void config_parse_dump_config_rasi_format(gboolean changes)
Dump configuration in rasi format.
static void help(G_GNUC_UNUSED int argc, char **argv)
void rofi_icon_fetcher_init(void)
const Mode * rofi_get_mode(unsigned int index)
static gboolean main_loop_signal_handler_int(G_GNUC_UNUSED gpointer data)
gboolean parse_keys_abe(NkBindings *bindings)
void config_parse_cmd_options(void)
unsigned int rofi_view_get_selected_line(const RofiViewState *state)
int find_arg(const char *const key)
static void help_print_no_arguments(void)
void config_parser_add_option(XrmOptionType type, const char *key, void **value, const char *comment)
static gboolean record(G_GNUC_UNUSED void *data)
static void rofi_collect_modi_dir(const char *base_dir)
static gboolean rofi_collect_modi_add(Mode *mode)
gboolean rofi_theme_parse_string(const char *string)
void rofi_capture_screenshot(void)
gboolean rofi_theme_is_empty(void)
RofiViewState * rofi_view_create(Mode *sw, const char *input, MenuFlags menu_flags, void(*finalize)(RofiViewState *))
static void run_switcher(ModeMode mode)
static gboolean setup_modi(void)
gboolean display_late_setup(void)
int mode_init(Mode *mode)