28 #define G_LOG_DOMAIN "Dialogs.DMenu" 40 #include <gio/gunixinputstream.h> 41 #include <sys/types.h> 52 static inline unsigned int bitget ( uint32_t *array,
unsigned int index )
54 uint32_t bit = index % 32;
55 uint32_t val = array[index / 32];
56 return ( val >> bit ) & 1;
59 static inline void bittoggle ( uint32_t *array,
unsigned int index )
61 uint32_t bit = index % 32;
62 uint32_t *v = &array[index / 32];
99 static void async_close_callback ( GObject *source_object, GAsyncResult *res, G_GNUC_UNUSED gpointer user_data )
101 g_input_stream_close_finish ( G_INPUT_STREAM ( source_object ), res, NULL );
102 g_debug (
"Closing data stream." );
119 GDataInputStream *stream = (GDataInputStream *) source_object;
122 char *data = g_data_input_stream_read_upto_finish ( stream, res, &len, NULL );
123 if ( data != NULL ) {
125 g_data_input_stream_read_byte ( stream, NULL, NULL );
135 GError *error = NULL;
138 g_data_input_stream_read_byte ( stream, NULL, &error );
139 if ( error == NULL ) {
149 g_error_free ( error );
152 if ( !g_cancellable_is_cancelled ( pd->
cancel ) ) {
154 g_debug (
"Clearing overlay" );
160 static void async_read_cancel ( G_GNUC_UNUSED GCancellable *cancel, G_GNUC_UNUSED gpointer data )
162 g_debug (
"Cancelled the async read." );
167 while ( sync_pre_read-- ) {
170 if ( data == NULL ) {
187 if ( data == NULL ) {
206 return g_strdup ( input );
209 char ** splitted = g_regex_split_simple ( pd->
column_separator, input, G_REGEX_CASELESS, 00 );
211 for (; splitted && splitted[ns]; ns++ ) {
215 unsigned int index = (
unsigned int ) g_ascii_strtoull ( pd->
columns[i], NULL, 10 );
216 if ( index < ns && index > 0 ) {
217 if ( retv == NULL ) {
218 retv = g_strdup ( splitted[index - 1] );
221 gchar *t = g_strjoin (
"\t", retv, splitted[index - 1], NULL );
227 g_strfreev ( splitted );
228 return retv ? retv : g_strdup (
"" );
231 static char *
get_display_data (
const Mode *data,
unsigned int index,
int *state, G_GNUC_UNUSED GList **list,
int get_entry )
235 char **retv = (
char * *) pd->
cmd_list;
237 if ( index >= pd->
active_list[i].
start && index <= pd->active_list[i].stop ) {
242 if ( index >= pd->
urgent_list[i].
start && index <= pd->urgent_list[i].stop ) {
265 g_cancellable_cancel ( pd->
cancel );
274 g_object_unref ( pd->
cancel );
342 int fd = STDIN_FILENO;
346 fd = open ( str, O_RDONLY );
348 char *msg = g_markup_printf_escaped (
"Failed to open file: <b>%s</b>:\n\t<i>%s</i>", estr, g_strerror ( errno ) );
357 if ( !( fd == STDIN_FILENO && isatty ( fd ) == 1 ) ) {
358 pd->
cancel = g_cancellable_new ();
360 pd->
input_stream = g_unix_input_stream_new ( fd, fd != STDIN_FILENO );
363 gchar *columns = NULL;
365 pd->
columns = g_strsplit ( columns,
",", 0 );
381 return g_strdup ( pd->
message );
391 .cfg_name_key =
"display-combi",
398 ._get_completion = NULL,
399 ._preprocess_input = NULL,
401 .private_data = NULL,
403 .display_name =
"dmenu" 408 if ( retv == FALSE ) {
411 else if ( retv >= 10 ) {
435 const char *cmd = input;
464 restart = (
find_arg (
"-only-match" ) >= 0 );
567 find_arg (
"-selected-row" ) >= 0 ) {
571 if ( pd->
cancel != NULL ) {
573 unsigned int pre_read = 25;
587 if (
find_arg (
"-multi-select" ) >= 0 ) {
591 if (
find_arg (
"-markup-rows" ) >= 0 ) {
596 if ( cmd_list_length == 0 ) {
604 if (
find_arg (
"-password" ) >= 0 ) {
612 if ( select != NULL ) {
615 for ( i = 0; i < cmd_list_length; i++ ) {
626 for ( i = 0; i < cmd_list_length; i++ ) {
639 if ( async && ( pd->
cancel != NULL ) ) {
650 int is_term = isatty ( fileno ( stdout ) );
651 print_help_msg (
"-mesg",
"[string]",
"Print a small user message under the prompt (uses pango markup)", NULL, is_term );
652 print_help_msg (
"-p",
"[string]",
"Prompt to display left of entry field", NULL, is_term );
653 print_help_msg (
"-selected-row",
"[integer]",
"Select row", NULL, is_term );
654 print_help_msg (
"-format",
"[string]",
"Output format string",
"s", is_term );
655 print_help_msg (
"-u",
"[list]",
"List of row indexes to mark urgent", NULL, is_term );
656 print_help_msg (
"-a",
"[list]",
"List of row indexes to mark active", NULL, is_term );
657 print_help_msg (
"-l",
"[integer] ",
"Number of rows to display", NULL, is_term );
658 print_help_msg (
"-i",
"",
"Set filter to be case insensitive", NULL, is_term );
659 print_help_msg (
"-only-match",
"",
"Force selection or custom entry", NULL, is_term );
660 print_help_msg (
"-no-custom",
"",
"Don't accept custom entry", NULL, is_term );
661 print_help_msg (
"-select",
"[string]",
"Select the first row that matches", NULL, is_term );
662 print_help_msg (
"-password",
"",
"Do not show what the user inputs. Show '*' instead.", NULL, is_term );
663 print_help_msg (
"-markup-rows",
"",
"Allow and render pango markup as input data.", NULL, is_term );
664 print_help_msg (
"-sep",
"[char]",
"Element separator.",
"'\\n'", is_term );
665 print_help_msg (
"-input",
"[filename]",
"Read input from file instead from standard input.", NULL, is_term );
666 print_help_msg (
"-sync",
"",
"Force dmenu to first read all input data, then show dialog.", NULL, is_term );
667 print_help_msg (
"-async-pre-read",
"[number]",
"Read several entries blocking before switching to async mode",
"25", is_term );
668 print_help_msg (
"-w",
"windowid",
"Position over window with X11 windowid.", NULL, is_term );
void rofi_set_return_code(int code)
int find_arg_char(const char *const key, char *val)
unsigned int case_sensitive
void rofi_view_reload(void)
Mode * rofi_view_get_mode(RofiViewState *state)
const char * rofi_view_get_user_input(const RofiViewState *state)
void rofi_view_set_selected_line(RofiViewState *state, unsigned int selected_line)
RofiViewState * rofi_view_get_active(void)
int find_arg_uint(const char *const key, unsigned int *val)
MenuReturn rofi_view_get_return_value(const RofiViewState *state)
int find_arg_str(const char *const key, char **val)
rofi_int_matcher ** helper_tokenize(const char *input, int case_sensitive)
void rofi_view_free(RofiViewState *state)
void * mode_get_private_data(const Mode *mode)
void print_help_msg(const char *option, const char *type, const char *text, const char *def, int isatty)
void mode_destroy(Mode *mode)
unsigned int rofi_view_get_next_position(const RofiViewState *state)
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
void rofi_view_set_active(RofiViewState *state)
int rofi_view_error_dialog(const char *msg, int markup)
char * rofi_expand_path(const char *input)
void parse_ranges(char *input, rofi_range_pair **list, unsigned int *length)
void mode_set_private_data(Mode *mode, void *pd)
char * rofi_force_utf8(const gchar *data, ssize_t length)
void rofi_view_restart(RofiViewState *state)
void helper_tokenize_free(rofi_int_matcher **tokens)
void rofi_output_formatted_line(const char *format, const char *string, int selected_line, const char *filter)
unsigned int rofi_view_get_selected_line(const RofiViewState *state)
int find_arg(const char *const key)
void rofi_view_set_overlay(RofiViewState *state, const char *text)
RofiViewState * rofi_view_create(Mode *sw, const char *input, MenuFlags menu_flags, void(*finalize)(RofiViewState *))
int mode_init(Mode *mode)