29 #define G_LOG_DOMAIN "Dialogs.DMenu"
41 #include <gio/gunixinputstream.h>
42 #include <sys/types.h>
56 static inline unsigned int bitget ( uint32_t *array,
unsigned int index )
58 uint32_t bit = index % 32;
59 uint32_t val = array[index / 32];
60 return ( val >> bit ) & 1;
63 static inline void bittoggle ( uint32_t *array,
unsigned int index )
65 uint32_t bit = index % 32;
66 uint32_t *v = &array[index / 32];
103 static void async_close_callback ( GObject *source_object, GAsyncResult *res, G_GNUC_UNUSED gpointer user_data )
105 g_input_stream_close_finish ( G_INPUT_STREAM ( source_object ), res, NULL );
106 g_debug (
"Closing data stream." );
111 gsize data_len = len;
119 char *end = strchr(data,
'\0');
132 GDataInputStream *stream = (GDataInputStream *) source_object;
135 char *data = g_data_input_stream_read_upto_finish ( stream, res, &len, NULL );
136 if ( data != NULL ) {
138 g_data_input_stream_read_byte ( stream, NULL, NULL );
148 GError *error = NULL;
151 g_data_input_stream_read_byte ( stream, NULL, &error );
152 if ( error == NULL ) {
162 g_error_free ( error );
165 if ( !g_cancellable_is_cancelled ( pd->
cancel ) ) {
167 g_debug (
"Clearing overlay" );
173 static void async_read_cancel ( G_GNUC_UNUSED GCancellable *cancel, G_GNUC_UNUSED gpointer data )
175 g_debug (
"Cancelled the async read." );
180 while ( sync_pre_read-- ) {
183 if ( data == NULL ) {
200 if ( data == NULL ) {
219 return g_strdup ( input );
222 char ** splitted = g_regex_split_simple ( pd->
column_separator, input, G_REGEX_CASELESS, 00 );
224 for (; splitted && splitted[ns]; ns++ ) {
228 unsigned int index = (
unsigned int ) g_ascii_strtoull ( pd->
columns[i], NULL, 10 );
229 if ( index < ns && index > 0 ) {
230 if ( retv == NULL ) {
231 retv = g_strdup ( splitted[index - 1] );
234 gchar *t = g_strjoin (
"\t", retv, splitted[index - 1], NULL );
240 g_strfreev ( splitted );
241 return retv ? retv : g_strdup (
"" );
244 static char *
get_display_data (
const Mode *data,
unsigned int index,
int *state, G_GNUC_UNUSED GList **list,
int get_entry )
250 if ( index >= pd->
active_list[i].
start && index <= pd->active_list[i].stop ) {
255 if ( index >= pd->
urgent_list[i].
start && index <= pd->urgent_list[i].stop ) {
278 g_cancellable_cancel ( pd->
cancel );
287 g_object_unref ( pd->
cancel );
356 int fd = STDIN_FILENO;
360 fd = open ( str, O_RDONLY );
362 char *msg = g_markup_printf_escaped (
"Failed to open file: <b>%s</b>:\n\t<i>%s</i>", estr, g_strerror ( errno ) );
371 if ( !( fd == STDIN_FILENO && isatty ( fd ) == 1 ) ) {
372 pd->
cancel = g_cancellable_new ();
374 pd->
input_stream = g_unix_input_stream_new ( fd, fd != STDIN_FILENO );
377 gchar *columns = NULL;
379 pd->
columns = g_strsplit ( columns,
",", 0 );
395 return g_strdup ( pd->
message );
402 g_return_val_if_fail ( pd->
cmd_list != NULL, NULL );
419 .cfg_name_key =
"display-combi",
427 ._get_completion = NULL,
428 ._preprocess_input = NULL,
430 .private_data = NULL,
432 .display_name =
"dmenu"
437 if ( retv == FALSE ) {
440 else if ( retv >= 10 ) {
464 const char *cmd = input;
493 restart = (
find_arg (
"-only-match" ) >= 0 );
596 find_arg (
"-selected-row" ) >= 0 ) {
600 if ( pd->
cancel != NULL ) {
602 unsigned int pre_read = 25;
616 if (
find_arg (
"-multi-select" ) >= 0 ) {
620 if (
find_arg (
"-markup-rows" ) >= 0 ) {
625 if ( cmd_list_length == 0 ) {
633 if (
find_arg (
"-password" ) >= 0 ) {
641 if ( select != NULL ) {
644 for ( i = 0; i < cmd_list_length; i++ ) {
655 for ( i = 0; i < cmd_list_length; i++ ) {
668 if ( async && ( pd->
cancel != NULL ) ) {
679 int is_term = isatty ( fileno ( stdout ) );
680 print_help_msg (
"-mesg",
"[string]",
"Print a small user message under the prompt (uses pango markup)", NULL, is_term );
681 print_help_msg (
"-p",
"[string]",
"Prompt to display left of entry field", NULL, is_term );
682 print_help_msg (
"-selected-row",
"[integer]",
"Select row", NULL, is_term );
683 print_help_msg (
"-format",
"[string]",
"Output format string",
"s", is_term );
684 print_help_msg (
"-u",
"[list]",
"List of row indexes to mark urgent", NULL, is_term );
685 print_help_msg (
"-a",
"[list]",
"List of row indexes to mark active", NULL, is_term );
686 print_help_msg (
"-l",
"[integer] ",
"Number of rows to display", NULL, is_term );
687 print_help_msg (
"-i",
"",
"Set filter to be case insensitive", NULL, is_term );
688 print_help_msg (
"-only-match",
"",
"Force selection or custom entry", NULL, is_term );
689 print_help_msg (
"-no-custom",
"",
"Don't accept custom entry", NULL, is_term );
690 print_help_msg (
"-select",
"[string]",
"Select the first row that matches", NULL, is_term );
691 print_help_msg (
"-password",
"",
"Do not show what the user inputs. Show '*' instead.", NULL, is_term );
692 print_help_msg (
"-markup-rows",
"",
"Allow and render pango markup as input data.", NULL, is_term );
693 print_help_msg (
"-sep",
"[char]",
"Element separator.",
"'\\n'", is_term );
694 print_help_msg (
"-input",
"[filename]",
"Read input from file instead from standard input.", NULL, is_term );
695 print_help_msg (
"-sync",
"",
"Force dmenu to first read all input data, then show dialog.", NULL, is_term );
696 print_help_msg (
"-async-pre-read",
"[number]",
"Read several entries blocking before switching to async mode",
"25", is_term );
697 print_help_msg (
"-w",
"windowid",
"Position over window with X11 windowid.", NULL, is_term );