29 #define G_LOG_DOMAIN "Rofi" 42 #include <sys/types.h> 44 #include <glib-unix.h> 46 #include <libgwater-xcb.h> 48 #ifdef USE_NK_GIT_VERSION 49 #include "nkutils-git-version.h" 51 #define GIT_VERSION NK_GIT_VERSION 55 #include "resources.h" 142 for (
unsigned int i = 0; i <
num_modi; i++ ) {
155 g_debug (
"Teardown" );
169 for (
unsigned int i = 0; i <
num_modi; i++ ) {
171 GString *str = g_string_new (
"Failed to initialize the mode: " );
172 g_string_append ( str,
modi[i]->name );
173 g_string_append ( str,
"\n" );
176 g_string_free ( str, FALSE );
248 gboolean active = FALSE;
249 for (
unsigned int j = 0; j <
num_modi; j++ ) {
255 printf (
" * %s%s%s%s\n",
265 print_help_msg (
"-no-config",
"",
"Do not load configuration, use default values.", NULL, is_term );
266 print_help_msg (
"-v,-version",
"",
"Print the version number and exit.", NULL, is_term );
267 print_help_msg (
"-dmenu",
"",
"Start in dmenu mode.", NULL, is_term );
268 print_help_msg (
"-display",
"[string]",
"X server to contact.",
"${DISPLAY}", is_term );
269 print_help_msg (
"-h,-help",
"",
"This help message.", NULL, is_term );
270 print_help_msg (
"-dump-xresources",
"",
"Dump the current configuration in Xresources format and exit.", NULL, is_term );
271 print_help_msg (
"-e",
"[string]",
"Show a dialog displaying the passed message and exit.", NULL, is_term );
272 print_help_msg (
"-markup",
"",
"Enable pango markup where possible.", NULL, is_term );
273 print_help_msg (
"-normal-window",
"",
"In dmenu mode, behave as a normal window. (experimental)", NULL, is_term );
274 print_help_msg (
"-show",
"[mode]",
"Show the mode 'mode' and exit. The mode has to be enabled.", NULL, is_term );
275 print_help_msg (
"-no-lazy-grab",
"",
"Disable lazy grab that, when fail to grab keyboard, does not block but retry later.", NULL, is_term );
276 print_help_msg (
"-no-plugins",
"",
"Disable loading of external plugins.", NULL, is_term );
277 print_help_msg (
"-plugin-path",
"",
"Directory used to search for rofi plugins.", NULL, is_term );
278 print_help_msg (
"-dump-config",
"",
"Dump the current configuration in rasi format and exit.", NULL, is_term );
279 print_help_msg (
"-dump-theme",
"",
"Dump the current theme in rasi format and exit.", NULL, is_term );
281 static void help ( G_GNUC_UNUSED
int argc,
char **argv )
283 int is_term = isatty ( fileno ( stdout ) );
284 printf (
"%s usage:\n", argv[0] );
285 printf (
"\t%s [-options ...]\n\n", argv[0] );
286 printf (
"Command line only options:\n" );
288 printf (
"DMENU command line options:\n" );
290 printf (
"Global options:\n" );
295 printf (
"Detected modi:\n" );
298 printf (
"Compile time options:\n" );
325 printf (
"For more information see: %sman rofi%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
331 printf (
" Bugreports: %s"PACKAGE_BUGREPORT
"%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
334 if (
find_arg (
"-no-config" ) < 0 ) {
343 printf (
" Configuration file: %sDisabled%s\n", is_term ?
color_bold :
"", is_term ?
color_reset :
"" );
349 int is_term = isatty ( fileno ( stdout ) );
352 fprintf ( stderr,
"Mode %s%s%s is not enabled. I have enabled it for now.\n",
354 fprintf ( stderr,
"Please consider adding %s%s%s to the list of enabled modi: %smodi: %s%s%s,%s%s.\n",
363 int is_term = isatty ( fileno ( stdout ) );
364 fprintf ( stderr,
"Mode %s%s%s is not found.\n",
366 fprintf ( stderr,
"The following modi are known:\n" );
372 int is_term = isatty ( fileno ( stdout ) );
374 fprintf ( stderr,
"Rofi is unsure what to show.\n" );
375 fprintf ( stderr,
"Please specify the mode you want to show.\n\n" );
376 fprintf ( stderr,
" %srofi%s -show %s{mode}%s\n\n",
379 fprintf ( stderr,
"The following modi are enabled:\n" );
380 for (
unsigned int j = 0; j <
num_modi; j++ ) {
381 fprintf ( stderr,
" * %s%s%s\n",
386 fprintf ( stderr,
"\nThe following can be enabled:\n" );
388 gboolean active = FALSE;
389 for (
unsigned int j = 0; j <
num_modi; j++ ) {
396 fprintf ( stderr,
" * %s%s%s\n",
402 fprintf ( stderr,
"\nTo activate a mode, add it to the list of modi in the %smodi%s setting.\n",
411 for (
unsigned int i = 0; i <
num_modi; i++ ) {
433 iter != NULL; iter = g_list_next ( iter ) ) {
434 g_string_free ( (GString *) iter->data, TRUE );
485 GDir *dir = g_dir_open ( base_dir, 0, NULL );
487 const char *dn = NULL;
488 while ( ( dn = g_dir_read_name ( dir ) ) ) {
489 if ( !g_str_has_suffix ( dn, G_MODULE_SUFFIX ) ) {
492 char *fn = g_build_filename ( base_dir, dn, NULL );
493 GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL );
496 if ( g_module_symbol ( mod,
"mode", (gpointer *) &m ) ) {
498 g_warning (
"ABI version of plugin: '%s' does not match: %08X expecting: %08X", dn, m->abi_version,
ABI_VERSION );
499 g_module_close ( mod );
504 g_module_close ( mod );
509 g_warning (
"Symbol 'mode' not found in module: %s", dn );
510 g_module_close ( mod );
514 g_warning (
"Failed to open 'mode' plugin: '%s', error: %s", dn, g_module_error () );
539 if (
find_arg (
"-no-plugins" ) < 0 ) {
561 g_module_close ( mod );
600 return ( index ==
num_modi ) ? -1 : (int) index;
604 const char *
const sep =
",#";
607 char *switcher_str = g_strdup (
config.
modi );
609 for (
char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) {
612 g_free ( switcher_str );
617 g_free ( switcher_str );
630 return G_SOURCE_CONTINUE;
633 static gboolean
startup ( G_GNUC_UNUSED gpointer data )
641 if (
find_arg (
"-normal-window" ) >= 0 ) {
644 TICK_N (
"Grab keyboard" );
646 TICK_N (
"Create Window" );
651 TICK_N (
"Config sanity check" );
654 GString *emesg = g_string_new (
"The following errors were detected when starting rofi:\n" );
657 for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) {
658 GString *msg = (GString *) ( iter->data );
659 g_string_append ( emesg,
"\n\n" );
660 g_string_append ( emesg, msg->str );
663 if ( g_list_length ( iter ) > 1 ) {
664 g_string_append_printf ( emesg,
"\nThere are <b>%d</b> more errors.", g_list_length ( iter ) - 1 );
667 g_string_free ( emesg, TRUE );
668 return G_SOURCE_REMOVE;
683 if (
find_arg (
"-markup" ) >= 0 ) {
707 return G_SOURCE_REMOVE;
719 return G_SOURCE_REMOVE;
722 static gboolean
record ( G_GNUC_UNUSED
void *data )
725 return G_SOURCE_CONTINUE;
735 int main (
int argc,
char *argv[] )
744 g_print (
"Version: "GIT_VERSION
"\n" );
746 g_print (
"Version: "VERSION
"\n" );
760 char *base_name = g_path_get_basename ( argv[0] );
761 const char *
const dmenu_str =
"dmenu";
762 dmenu_mode = ( strcmp ( base_name, dmenu_str ) == 0 );
764 g_free ( base_name );
770 if ( g_mkdir_with_parents (
cache_dir, 0700 ) < 0 ) {
771 g_warning (
"Failed to create cache directory: %s", g_strerror ( errno ) );
776 const char *path = g_get_user_runtime_dir ();
778 if ( g_mkdir_with_parents ( path, 0700 ) < 0 ) {
779 g_warning (
"Failed to create user runtime directory: %s with error: %s", path, g_strerror ( errno ) );
780 pidfile = g_build_filename ( g_get_home_dir (),
".rofi.pid", NULL );
783 pidfile = g_build_filename ( path,
"rofi.pid", NULL );
789 const char *cpath = g_get_user_config_dir ();
791 config_path = g_build_filename ( cpath,
"rofi",
"config", NULL );
798 if ( g_str_has_suffix ( c,
".rasi" ) ) {
807 if ( setlocale ( LC_ALL,
"" ) == NULL ) {
808 g_warning (
"Failed to set locale." );
813 TICK_N (
"Setup Locale" );
815 TICK_N (
"Collect MODI" );
819 main_loop = g_main_loop_new ( NULL, FALSE );
821 TICK_N (
"Setup mainloop" );
827 g_warning (
"Connection has error" );
831 TICK_N (
"Setup Display" );
837 if (
find_arg (
"-no-config" ) < 0 ) {
839 gchar *etc = g_build_filename ( SYSCONFDIR,
"rofi.conf", NULL );
840 if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
865 TICK_N (
"Parsed theme" );
869 TICK_N (
"Load cmd config " );
874 char *windowid = NULL;
891 GBytes *theme_data = g_resource_lookup_data (
892 resources_get_resource (),
893 "/org/qtools/rofi/default_theme.rasi",
894 G_RESOURCE_LOOKUP_FLAGS_NONE,
897 const char *theme = g_bytes_get_data ( theme_data, NULL );
899 g_warning (
"Failed to parse default theme. Giving up.." );
902 iter != NULL; iter = g_list_next ( iter ) ) {
903 g_warning (
"Error: %s%s%s",
911 g_bytes_unref ( theme_data );
913 rofi_theme_convert_old ();
921 for (
int index = 0; theme_str && theme_str[index]; index++ ) {
927 g_free ( theme_str );
930 if (
find_arg (
"-dump-theme" ) >= 0 ) {
935 if (
find_arg (
"-dump-config" ) >= 0 ) {
947 if (
find_arg (
"-dump-xresources" ) >= 0 ) {
953 unsigned int interval = 1;
955 g_timeout_add ( 1000 / (
double) interval,
record, NULL );
969 g_warning (
"Failed to properly finish display setup" );
973 TICK_N (
"Setup late Display" );
void rofi_theme_free(ThemeWidget *widget)
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)
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)