29 #define G_LOG_DOMAIN "Dialogs.DMenu" 41 #include <gio/gunixinputstream.h> 42 #include <sys/types.h> 53 static inline unsigned int bitget ( uint32_t *array,
unsigned int index )
55 uint32_t bit = index % 32;
56 uint32_t val = array[index / 32];
57 return ( val >> bit ) & 1;
60 static inline void bittoggle ( uint32_t *array,
unsigned int index )
62 uint32_t bit = index % 32;
63 uint32_t *v = &array[index / 32];
100 static void async_close_callback ( GObject *source_object, GAsyncResult *res, G_GNUC_UNUSED gpointer user_data )
102 g_input_stream_close_finish ( G_INPUT_STREAM ( source_object ), res, NULL );
103 g_debug (
"Closing data stream." );
120 GDataInputStream *stream = (GDataInputStream *) source_object;
123 char *data = g_data_input_stream_read_upto_finish ( stream, res, &len, NULL );
124 if ( data != NULL ) {
126 g_data_input_stream_read_byte ( stream, NULL, NULL );
136 GError *error = NULL;
139 g_data_input_stream_read_byte ( stream, NULL, &error );
140 if ( error == NULL ) {
150 g_error_free ( error );
153 if ( !g_cancellable_is_cancelled ( pd->
cancel ) ) {
155 g_debug (
"Clearing overlay" );
161 static void async_read_cancel ( G_GNUC_UNUSED GCancellable *cancel, G_GNUC_UNUSED gpointer data )
163 g_debug (
"Cancelled the async read." );
168 while ( sync_pre_read-- ) {
171 if ( data == NULL ) {
188 if ( data == NULL ) {
207 return g_strdup ( input );
210 char ** splitted = g_regex_split_simple ( pd->
column_separator, input, G_REGEX_CASELESS, 00 );
212 for (; splitted && splitted[ns]; ns++ ) {
216 unsigned int index = (
unsigned int ) g_ascii_strtoull ( pd->
columns[i], NULL, 10 );
217 if ( index < ns && index > 0 ) {
218 if ( retv == NULL ) {
219 retv = g_strdup ( splitted[index - 1] );
222 gchar *t = g_strjoin (
"\t", retv, splitted[index - 1], NULL );
228 g_strfreev ( splitted );
229 return retv ? retv : g_strdup (
"" );
232 static char *
get_display_data (
const Mode *data,
unsigned int index,
int *state, G_GNUC_UNUSED GList **list,
int get_entry )
236 char **retv = (
char * *) pd->
cmd_list;
238 if ( index >= pd->
active_list[i].
start && index <= pd->active_list[i].stop ) {
243 if ( index >= pd->
urgent_list[i].
start && index <= pd->urgent_list[i].stop ) {
266 g_cancellable_cancel ( pd->
cancel );
275 g_object_unref ( pd->
cancel );
343 int fd = STDIN_FILENO;
347 fd = open ( str, O_RDONLY );
349 char *msg = g_markup_printf_escaped (
"Failed to open file: <b>%s</b>:\n\t<i>%s</i>", estr, g_strerror ( errno ) );
358 if ( !( fd == STDIN_FILENO && isatty ( fd ) == 1 ) ) {
359 pd->
cancel = g_cancellable_new ();
361 pd->
input_stream = g_unix_input_stream_new ( fd, fd != STDIN_FILENO );
364 gchar *columns = NULL;
366 pd->
columns = g_strsplit ( columns,
",", 0 );
382 return g_strdup ( pd->
message );
392 .cfg_name_key =
"display-combi",
399 ._get_completion = NULL,
400 ._preprocess_input = NULL,
402 .private_data = NULL,
404 .display_name =
"dmenu" 409 if ( retv == FALSE ) {
412 else if ( retv >= 10 ) {
436 const char *cmd = input;
465 restart = (
find_arg (
"-only-match" ) >= 0 );
568 find_arg (
"-selected-row" ) >= 0 ) {
572 if ( pd->
cancel != NULL ) {
574 unsigned int pre_read = 25;
588 if (
find_arg (
"-multi-select" ) >= 0 ) {
592 if (
find_arg (
"-markup-rows" ) >= 0 ) {
597 if ( cmd_list_length == 0 ) {
605 if (
find_arg (
"-password" ) >= 0 ) {
613 if ( select != NULL ) {
616 for ( i = 0; i < cmd_list_length; i++ ) {
627 for ( i = 0; i < cmd_list_length; i++ ) {
640 if ( async && ( pd->
cancel != NULL ) ) {
651 int is_term = isatty ( fileno ( stdout ) );
652 print_help_msg (
"-mesg",
"[string]",
"Print a small user message under the prompt (uses pango markup)", NULL, is_term );
653 print_help_msg (
"-p",
"[string]",
"Prompt to display left of entry field", NULL, is_term );
654 print_help_msg (
"-selected-row",
"[integer]",
"Select row", NULL, is_term );
655 print_help_msg (
"-format",
"[string]",
"Output format string",
"s", is_term );
656 print_help_msg (
"-u",
"[list]",
"List of row indexes to mark urgent", NULL, is_term );
657 print_help_msg (
"-a",
"[list]",
"List of row indexes to mark active", NULL, is_term );
658 print_help_msg (
"-l",
"[integer] ",
"Number of rows to display", NULL, is_term );
659 print_help_msg (
"-i",
"",
"Set filter to be case insensitive", NULL, is_term );
660 print_help_msg (
"-only-match",
"",
"Force selection or custom entry", NULL, is_term );
661 print_help_msg (
"-no-custom",
"",
"Don't accept custom entry", NULL, is_term );
662 print_help_msg (
"-select",
"[string]",
"Select the first row that matches", NULL, is_term );
663 print_help_msg (
"-password",
"",
"Do not show what the user inputs. Show '*' instead.", NULL, is_term );
664 print_help_msg (
"-markup-rows",
"",
"Allow and render pango markup as input data.", NULL, is_term );
665 print_help_msg (
"-sep",
"[char]",
"Element separator.",
"'\\n'", is_term );
666 print_help_msg (
"-input",
"[filename]",
"Read input from file instead from standard input.", NULL, is_term );
667 print_help_msg (
"-sync",
"",
"Force dmenu to first read all input data, then show dialog.", NULL, is_term );
668 print_help_msg (
"-async-pre-read",
"[number]",
"Read several entries blocking before switching to async mode",
"25", is_term );
669 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)