rofi  1.5.2
dmenu.c
Go to the documentation of this file.
1 /*
2  * rofi
3  *
4  * MIT/X11 License
5  * Copyright © 2013-2017 Qball Cow <qball@gmpclient.org>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  */
27 
29 #define G_LOG_DOMAIN "Dialogs.DMenu"
30 
31 #include <config.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <strings.h>
36 #include <string.h>
37 #include <ctype.h>
38 #include <stdint.h>
39 #include <errno.h>
40 #include <gio/gio.h>
41 #include <gio/gunixinputstream.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <fcntl.h>
45 #include "rofi.h"
46 #include "settings.h"
47 #include "widgets/textbox.h"
48 #include "dialogs/dmenu.h"
49 #include "helper.h"
50 #include "xrmoptions.h"
51 #include "view.h"
52 
53 static inline unsigned int bitget ( uint32_t *array, unsigned int index )
54 {
55  uint32_t bit = index % 32;
56  uint32_t val = array[index / 32];
57  return ( val >> bit ) & 1;
58 }
59 
60 static inline void bittoggle ( uint32_t *array, unsigned int index )
61 {
62  uint32_t bit = index % 32;
63  uint32_t *v = &array[index / 32];
64  *v ^= 1 << bit;
65 }
66 
67 typedef struct
68 {
70  // Separator.
71  char separator;
72 
73  unsigned int selected_line;
74  char *message;
75  char *format;
77  unsigned int num_urgent_list;
79  unsigned int num_active_list;
80  uint32_t *selected_list;
81  unsigned int num_selected_list;
82  unsigned int do_markup;
83  // List with entries.
84  char **cmd_list;
85  unsigned int cmd_list_real_length;
86  unsigned int cmd_list_length;
87  unsigned int only_selected;
88  unsigned int selected_count;
89 
90  gchar **columns;
92  gboolean multi_select;
93 
94  GCancellable *cancel;
95  gulong cancel_source;
96  GInputStream *input_stream;
97  GDataInputStream *data_input_stream;
99 
100 static void async_close_callback ( GObject *source_object, GAsyncResult *res, G_GNUC_UNUSED gpointer user_data )
101 {
102  g_input_stream_close_finish ( G_INPUT_STREAM ( source_object ), res, NULL );
103  g_debug ( "Closing data stream." );
104 }
105 
106 static void read_add ( DmenuModePrivateData * pd, char *data, gsize len )
107 {
108  if ( ( pd->cmd_list_length + 2 ) > pd->cmd_list_real_length ) {
109  pd->cmd_list_real_length = MAX ( pd->cmd_list_real_length * 2, 512 );
110  pd->cmd_list = g_realloc ( pd->cmd_list, ( pd->cmd_list_real_length ) * sizeof ( char* ) );
111  }
112  char *utfstr = rofi_force_utf8 ( data, len );
113  pd->cmd_list[pd->cmd_list_length] = utfstr;
114  pd->cmd_list[pd->cmd_list_length + 1] = NULL;
115 
116  pd->cmd_list_length++;
117 }
118 static void async_read_callback ( GObject *source_object, GAsyncResult *res, gpointer user_data )
119 {
120  GDataInputStream *stream = (GDataInputStream *) source_object;
121  DmenuModePrivateData *pd = (DmenuModePrivateData *) user_data;
122  gsize len;
123  char *data = g_data_input_stream_read_upto_finish ( stream, res, &len, NULL );
124  if ( data != NULL ) {
125  // Absorb separator, already in buffer so should not block.
126  g_data_input_stream_read_byte ( stream, NULL, NULL );
127  read_add ( pd, data, len );
128  g_free ( data );
129  rofi_view_reload ();
130 
131  g_data_input_stream_read_upto_async ( pd->data_input_stream, &( pd->separator ), 1, G_PRIORITY_LOW, pd->cancel,
132  async_read_callback, pd );
133  return;
134  }
135  else {
136  GError *error = NULL;
137  // Absorb separator, already in buffer so should not block.
138  // If error == NULL end of stream..
139  g_data_input_stream_read_byte ( stream, NULL, &error );
140  if ( error == NULL ) {
141  // Add empty line.
142  read_add ( pd, "", 0 );
143  rofi_view_reload ();
144 
145  g_data_input_stream_read_upto_async ( pd->data_input_stream, &( pd->separator ), 1, G_PRIORITY_LOW, pd->cancel,
146  async_read_callback, pd );
147  return;
148  }
149  else {
150  g_error_free ( error );
151  }
152  }
153  if ( !g_cancellable_is_cancelled ( pd->cancel ) ) {
154  // Hack, don't use get active.
155  g_debug ( "Clearing overlay" );
157  g_input_stream_close_async ( G_INPUT_STREAM ( stream ), G_PRIORITY_LOW, pd->cancel, async_close_callback, pd );
158  }
159 }
160 
161 static void async_read_cancel ( G_GNUC_UNUSED GCancellable *cancel, G_GNUC_UNUSED gpointer data )
162 {
163  g_debug ( "Cancelled the async read." );
164 }
165 
166 static int get_dmenu_async ( DmenuModePrivateData *pd, int sync_pre_read )
167 {
168  while ( sync_pre_read-- ) {
169  gsize len = 0;
170  char *data = g_data_input_stream_read_upto ( pd->data_input_stream, &( pd->separator ), 1, &len, NULL, NULL );
171  if ( data == NULL ) {
172  g_input_stream_close_async ( G_INPUT_STREAM ( pd->input_stream ), G_PRIORITY_LOW, pd->cancel, async_close_callback, pd );
173  return FALSE;
174  }
175  g_data_input_stream_read_byte ( pd->data_input_stream, NULL, NULL );
176  read_add ( pd, data, len );
177  g_free ( data );
178  }
179  g_data_input_stream_read_upto_async ( pd->data_input_stream, &( pd->separator ), 1, G_PRIORITY_LOW, pd->cancel,
180  async_read_callback, pd );
181  return TRUE;
182 }
184 {
185  while ( TRUE ) {
186  gsize len = 0;
187  char *data = g_data_input_stream_read_upto ( pd->data_input_stream, &( pd->separator ), 1, &len, NULL, NULL );
188  if ( data == NULL ) {
189  break;
190  }
191  g_data_input_stream_read_byte ( pd->data_input_stream, NULL, NULL );
192  read_add ( pd, data, len );
193  g_free ( data );
194  }
195  g_input_stream_close_async ( G_INPUT_STREAM ( pd->input_stream ), G_PRIORITY_LOW, pd->cancel, async_close_callback, pd );
196 }
197 
198 static unsigned int dmenu_mode_get_num_entries ( const Mode *sw )
199 {
200  const DmenuModePrivateData *rmpd = (const DmenuModePrivateData *) mode_get_private_data ( sw );
201  return rmpd->cmd_list_length;
202 }
203 
204 static gchar * dmenu_format_output_string ( const DmenuModePrivateData *pd, const char *input )
205 {
206  if ( pd->columns == NULL ) {
207  return g_strdup ( input );
208  }
209  char *retv = NULL;
210  char ** splitted = g_regex_split_simple ( pd->column_separator, input, G_REGEX_CASELESS, 00 );
211  uint32_t ns = 0;
212  for (; splitted && splitted[ns]; ns++ ) {
213  ;
214  }
215  for ( uint32_t i = 0; pd->columns && pd->columns[i]; i++ ) {
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] );
220  }
221  else {
222  gchar *t = g_strjoin ( "\t", retv, splitted[index - 1], NULL );
223  g_free ( retv );
224  retv = t;
225  }
226  }
227  }
228  g_strfreev ( splitted );
229  return retv ? retv : g_strdup ( "" );
230 }
231 
232 static char *get_display_data ( const Mode *data, unsigned int index, int *state, G_GNUC_UNUSED GList **list, int get_entry )
233 {
234  Mode *sw = (Mode *) data;
236  char **retv = (char * *) pd->cmd_list;
237  for ( unsigned int i = 0; i < pd->num_active_list; i++ ) {
238  if ( index >= pd->active_list[i].start && index <= pd->active_list[i].stop ) {
239  *state |= ACTIVE;
240  }
241  }
242  for ( unsigned int i = 0; i < pd->num_urgent_list; i++ ) {
243  if ( index >= pd->urgent_list[i].start && index <= pd->urgent_list[i].stop ) {
244  *state |= URGENT;
245  }
246  }
247  if ( pd->selected_list && bitget ( pd->selected_list, index ) == TRUE ) {
248  *state |= SELECTED;
249  }
250  if ( pd->do_markup ) {
251  *state |= MARKUP;
252  }
253  return get_entry ? dmenu_format_output_string ( pd, retv[index] ) : NULL;
254 }
255 
256 static void dmenu_mode_free ( Mode *sw )
257 {
258  if ( mode_get_private_data ( sw ) == NULL ) {
259  return;
260  }
262  if ( pd != NULL ) {
263  if ( pd->cancel ) {
264  // If open, cancel reads.
265  if ( pd->input_stream && !g_input_stream_is_closed ( pd->input_stream ) ) {
266  g_cancellable_cancel ( pd->cancel );
267  }
268  // This blocks until cancel is done.
269  g_cancellable_disconnect ( pd->cancel, pd->cancel_source );
270  if ( pd->input_stream ) {
271  // Should close the stream if not yet done.
272  g_object_unref ( pd->data_input_stream );
273  g_object_unref ( pd->input_stream );
274  }
275  g_object_unref ( pd->cancel );
276  }
277 
278  for ( size_t i = 0; i < pd->cmd_list_length; i++ ) {
279  if ( pd->cmd_list[i] ) {
280  free ( pd->cmd_list[i] );
281  }
282  }
283  g_free ( pd->cmd_list );
284  g_free ( pd->urgent_list );
285  g_free ( pd->active_list );
286  g_free ( pd->selected_list );
287 
288  g_free ( pd );
289  mode_set_private_data ( sw, NULL );
290  }
291 }
292 
293 static int dmenu_mode_init ( Mode *sw )
294 {
295  if ( mode_get_private_data ( sw ) != NULL ) {
296  return TRUE;
297  }
298  mode_set_private_data ( sw, g_malloc0 ( sizeof ( DmenuModePrivateData ) ) );
300 
301  pd->separator = '\n';
302  pd->selected_line = UINT32_MAX;
303 
304  find_arg_str ( "-mesg", &( pd->message ) );
305 
306  // Input data separator.
307  find_arg_char ( "-sep", &( pd->separator ) );
308 
309  find_arg_uint ( "-selected-row", &( pd->selected_line ) );
310  // By default we print the unescaped line back.
311  pd->format = "s";
312 
313  // Allow user to override the output format.
314  find_arg_str ( "-format", &( pd->format ) );
315  // Urgent.
316  char *str = NULL;
317  find_arg_str ( "-u", &str );
318  if ( str != NULL ) {
319  parse_ranges ( str, &( pd->urgent_list ), &( pd->num_urgent_list ) );
320  }
321  // Active
322  str = NULL;
323  find_arg_str ( "-a", &str );
324  if ( str != NULL ) {
325  parse_ranges ( str, &( pd->active_list ), &( pd->num_active_list ) );
326  }
327 
328  // DMENU COMPATIBILITY
329  find_arg_uint ( "-l", &( config.menu_lines ) );
330 
335  if ( find_arg ( "-b" ) >= 0 ) {
336  config.location = 6;
337  }
338  /* -i case insensitive */
339  config.case_sensitive = TRUE;
340  if ( find_arg ( "-i" ) >= 0 ) {
341  config.case_sensitive = FALSE;
342  }
343  int fd = STDIN_FILENO;
344  str = NULL;
345  if ( find_arg_str ( "-input", &str ) ) {
346  char *estr = rofi_expand_path ( str );
347  fd = open ( str, O_RDONLY );
348  if ( fd < 0 ) {
349  char *msg = g_markup_printf_escaped ( "Failed to open file: <b>%s</b>:\n\t<i>%s</i>", estr, g_strerror ( errno ) );
350  rofi_view_error_dialog ( msg, TRUE );
351  g_free ( msg );
352  g_free ( estr );
353  return TRUE;
354  }
355  g_free ( estr );
356  }
357  // If input is stdin, and a tty, do not read as rofi grabs input and therefor blocks.
358  if ( !( fd == STDIN_FILENO && isatty ( fd ) == 1 ) ) {
359  pd->cancel = g_cancellable_new ();
360  pd->cancel_source = g_cancellable_connect ( pd->cancel, G_CALLBACK ( async_read_cancel ), pd, NULL );
361  pd->input_stream = g_unix_input_stream_new ( fd, fd != STDIN_FILENO );
362  pd->data_input_stream = g_data_input_stream_new ( pd->input_stream );
363  }
364  gchar *columns = NULL;
365  if ( find_arg_str ( "-display-columns", &columns ) ) {
366  pd->columns = g_strsplit ( columns, ",", 0 );
367  pd->column_separator = "\t";
368  find_arg_str ( "-display-column-separator", &pd->column_separator );
369  }
370  return TRUE;
371 }
372 
373 static int dmenu_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
374 {
376  return helper_token_match ( tokens, rmpd->cmd_list[index] );
377 }
378 static char *dmenu_get_message ( const Mode *sw )
379 {
381  if ( pd->message ) {
382  return g_strdup ( pd->message );
383  }
384  return NULL;
385 }
386 
387 #include "mode-private.h"
390 {
391  .name = "dmenu",
392  .cfg_name_key = "display-combi",
393  ._init = dmenu_mode_init,
394  ._get_num_entries = dmenu_mode_get_num_entries,
395  ._result = NULL,
396  ._destroy = dmenu_mode_free,
397  ._token_match = dmenu_token_match,
398  ._get_display_value = get_display_data,
399  ._get_completion = NULL,
400  ._preprocess_input = NULL,
401  ._get_message = dmenu_get_message,
402  .private_data = NULL,
403  .free = NULL,
404  .display_name = "dmenu"
405 };
406 
407 static void dmenu_finish ( RofiViewState *state, int retv )
408 {
409  if ( retv == FALSE ) {
410  rofi_set_return_code ( EXIT_FAILURE );
411  }
412  else if ( retv >= 10 ) {
413  rofi_set_return_code ( retv );
414  }
415  else{
416  rofi_set_return_code ( EXIT_SUCCESS );
417  }
418  rofi_view_set_active ( NULL );
419  rofi_view_free ( state );
421 }
422 
423 static void dmenu_print_results ( DmenuModePrivateData *pd, const char *input )
424 {
425  char **cmd_list = pd->cmd_list;
426  int seen = FALSE;
427  if ( pd->selected_list != NULL ) {
428  for ( unsigned int st = 0; st < pd->cmd_list_length; st++ ) {
429  if ( bitget ( pd->selected_list, st ) ) {
430  seen = TRUE;
431  rofi_output_formatted_line ( pd->format, cmd_list[st], st, input );
432  }
433  }
434  }
435  if ( !seen ) {
436  const char *cmd = input;
437  if ( pd->selected_line != UINT32_MAX ) {
438  cmd = cmd_list[pd->selected_line];
439  }
440  rofi_output_formatted_line ( pd->format, cmd, pd->selected_line, input );
441  }
442 }
443 
444 static void dmenu_finalize ( RofiViewState *state )
445 {
446  int retv = FALSE;
448  unsigned int cmd_list_length = pd->cmd_list_length;
449  char **cmd_list = pd->cmd_list;
450 
451  char *input = g_strdup ( rofi_view_get_user_input ( state ) );
453  MenuReturn mretv = rofi_view_get_return_value ( state );
454  unsigned int next_pos = rofi_view_get_next_position ( state );
455  int restart = 0;
456  // Special behavior.
457  if ( pd->only_selected ) {
461  restart = 1;
462  // Skip if no valid item is selected.
463  if ( ( mretv & MENU_CANCEL ) == MENU_CANCEL ) {
464  // In no custom mode we allow canceling.
465  restart = ( find_arg ( "-only-match" ) >= 0 );
466  }
467  else if ( pd->selected_line != UINT32_MAX ) {
468  if ( ( mretv & MENU_CUSTOM_ACTION ) && pd->multi_select ) {
469  restart = TRUE;
470  if ( pd->selected_list == NULL ) {
471  pd->selected_list = g_malloc0 ( sizeof ( uint32_t ) * ( pd->cmd_list_length / 32 + 1 ) );
472  }
473  pd->selected_count += ( bitget ( pd->selected_list, pd->selected_line ) ? ( -1 ) : ( 1 ) );
475  // Move to next line.
476  pd->selected_line = MIN ( next_pos, cmd_list_length - 1 );
477  if ( pd->selected_count > 0 ) {
478  char *str = g_strdup_printf ( "%u/%u", pd->selected_count, pd->cmd_list_length );
479  rofi_view_set_overlay ( state, str );
480  g_free ( str );
481  }
482  else {
483  rofi_view_set_overlay ( state, NULL );
484  }
485  }
486  else if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && cmd_list[pd->selected_line] != NULL ) {
487  dmenu_print_results ( pd, input );
488  retv = TRUE;
489  if ( ( mretv & MENU_QUICK_SWITCH ) ) {
490  retv = 10 + ( mretv & MENU_LOWER_MASK );
491  }
492  g_free ( input );
493  dmenu_finish ( state, retv );
494  return;
495  }
496  else {
497  pd->selected_line = next_pos - 1;
498  }
499  }
500  // Restart
501  rofi_view_restart ( state );
503  if ( !restart ) {
504  dmenu_finish ( state, retv );
505  }
506  return;
507  }
508  // We normally do not want to restart the loop.
509  restart = FALSE;
510  // Normal mode
511  if ( ( mretv & MENU_OK ) && pd->selected_line != UINT32_MAX && cmd_list[pd->selected_line] != NULL ) {
512  if ( ( mretv & MENU_CUSTOM_ACTION ) && pd->multi_select ) {
513  restart = TRUE;
514  if ( pd->selected_list == NULL ) {
515  pd->selected_list = g_malloc0 ( sizeof ( uint32_t ) * ( pd->cmd_list_length / 32 + 1 ) );
516  }
517  pd->selected_count += ( bitget ( pd->selected_list, pd->selected_line ) ? ( -1 ) : ( 1 ) );
519  // Move to next line.
520  pd->selected_line = MIN ( next_pos, cmd_list_length - 1 );
521  if ( pd->selected_count > 0 ) {
522  char *str = g_strdup_printf ( "%u/%u", pd->selected_count, pd->cmd_list_length );
523  rofi_view_set_overlay ( state, str );
524  g_free ( str );
525  }
526  else {
527  rofi_view_set_overlay ( state, NULL );
528  }
529  }
530  else {
531  dmenu_print_results ( pd, input );
532  }
533  retv = TRUE;
534  }
535  // Custom input
536  else if ( ( mretv & ( MENU_CUSTOM_INPUT ) ) ) {
537  dmenu_print_results ( pd, input );
538 
539  retv = TRUE;
540  }
541  // Quick switch with entry selected.
542  else if ( ( mretv & MENU_QUICK_SWITCH ) ) {
543  dmenu_print_results ( pd, input );
544 
545  restart = FALSE;
546  retv = 10 + ( mretv & MENU_LOWER_MASK );
547  }
548  g_free ( input );
549  if ( restart ) {
550  rofi_view_restart ( state );
552  }
553  else {
554  dmenu_finish ( state, retv );
555  }
556 }
557 
559 {
560  mode_init ( &dmenu_mode );
561  MenuFlags menu_flags = MENU_NORMAL;
563  int async = TRUE;
564 
565  // For now these only work in sync mode.
566  if ( find_arg ( "-sync" ) >= 0 || find_arg ( "-dump" ) >= 0 || find_arg ( "-select" ) >= 0
567  || find_arg ( "-no-custom" ) >= 0 || find_arg ( "-only-match" ) >= 0 || config.auto_select ||
568  find_arg ( "-selected-row" ) >= 0 ) {
569  async = FALSE;
570  }
571  // Check if the subsystem is setup for reading, otherwise do not read.
572  if ( pd->cancel != NULL ) {
573  if ( async ) {
574  unsigned int pre_read = 25;
575  find_arg_uint ( "-async-pre-read", &pre_read );
576  async = get_dmenu_async ( pd, pre_read );
577  }
578  else {
579  get_dmenu_sync ( pd );
580  }
581  }
582  char *input = NULL;
583  unsigned int cmd_list_length = pd->cmd_list_length;
584  char **cmd_list = pd->cmd_list;
585 
586  pd->only_selected = FALSE;
587  pd->multi_select = FALSE;
588  if ( find_arg ( "-multi-select" ) >= 0 ) {
589  menu_flags = MENU_INDICATOR;
590  pd->multi_select = TRUE;
591  }
592  if ( find_arg ( "-markup-rows" ) >= 0 ) {
593  pd->do_markup = TRUE;
594  }
595  if ( find_arg ( "-only-match" ) >= 0 || find_arg ( "-no-custom" ) >= 0 ) {
596  pd->only_selected = TRUE;
597  if ( cmd_list_length == 0 ) {
598  return TRUE;
599  }
600  }
601  if ( config.auto_select && cmd_list_length == 1 ) {
602  rofi_output_formatted_line ( pd->format, cmd_list[0], 0, config.filter );
603  return TRUE;
604  }
605  if ( find_arg ( "-password" ) >= 0 ) {
606  menu_flags |= MENU_PASSWORD;
607  }
608  /* copy filter string */
609  input = g_strdup ( config.filter );
610 
611  char *select = NULL;
612  find_arg_str ( "-select", &select );
613  if ( select != NULL ) {
614  rofi_int_matcher **tokens = helper_tokenize ( select, config.case_sensitive );
615  unsigned int i = 0;
616  for ( i = 0; i < cmd_list_length; i++ ) {
617  if ( helper_token_match ( tokens, cmd_list[i] ) ) {
618  pd->selected_line = i;
619  break;
620  }
621  }
622  helper_tokenize_free ( tokens );
623  }
624  if ( find_arg ( "-dump" ) >= 0 ) {
626  unsigned int i = 0;
627  for ( i = 0; i < cmd_list_length; i++ ) {
628  if ( tokens == NULL || helper_token_match ( tokens, cmd_list[i] ) ) {
629  rofi_output_formatted_line ( pd->format, cmd_list[i], i, config.filter );
630  }
631  }
632  helper_tokenize_free ( tokens );
634  g_free ( input );
635  return TRUE;
636  }
637  find_arg_str ( "-p", &( dmenu_mode.display_name ) );
638  RofiViewState *state = rofi_view_create ( &dmenu_mode, input, menu_flags, dmenu_finalize );
639  // @TODO we should do this better.
640  if ( async && ( pd->cancel != NULL ) ) {
641  rofi_view_set_overlay ( state, "Loading.. " );
642  }
644  rofi_view_set_active ( state );
645 
646  return FALSE;
647 }
648 
649 void print_dmenu_options ( void )
650 {
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 );
670 }
char * message
Definition: dmenu.c:74
MenuReturn
Definition: mode.h:66
unsigned int cmd_list_real_length
Definition: dmenu.c:85
unsigned int auto_select
Definition: settings.h:134
void rofi_set_return_code(int code)
Definition: rofi.c:123
WindowLocation location
Definition: settings.h:100
int find_arg_char(const char *const key, char *val)
Definition: helper.c:400
static char * get_display_data(const Mode *data, unsigned int index, int *state, G_GNUC_UNUSED GList **list, int get_entry)
Definition: dmenu.c:232
unsigned int case_sensitive
Definition: settings.h:124
Definition: mode.h:69
static void async_read_callback(GObject *source_object, GAsyncResult *res, gpointer user_data)
Definition: dmenu.c:118
Mode dmenu_mode
Definition: dmenu.c:389
static int dmenu_mode_init(Mode *sw)
Definition: dmenu.c:293
void rofi_view_reload(void)
Definition: view.c:425
unsigned int cmd_list_length
Definition: dmenu.c:86
gboolean multi_select
Definition: dmenu.c:92
gchar * column_separator
Definition: dmenu.c:91
unsigned int menu_lines
Definition: settings.h:65
Mode * rofi_view_get_mode(RofiViewState *state)
Definition: view.c:1883
struct rofi_range_pair * active_list
Definition: dmenu.c:78
const char * rofi_view_get_user_input(const RofiViewState *state)
Definition: view.c:538
unsigned int selected_count
Definition: dmenu.c:88
int dmenu_switcher_dialog(void)
Definition: dmenu.c:558
char ** cmd_list
Definition: dmenu.c:84
static unsigned int dmenu_mode_get_num_entries(const Mode *sw)
Definition: dmenu.c:198
gulong cancel_source
Definition: dmenu.c:95
void rofi_view_set_selected_line(RofiViewState *state, unsigned int selected_line)
Definition: view.c:475
void print_dmenu_options(void)
Definition: dmenu.c:649
uint32_t * selected_list
Definition: dmenu.c:80
static gchar * dmenu_format_output_string(const DmenuModePrivateData *pd, const char *input)
Definition: dmenu.c:204
RofiViewState * rofi_view_get_active(void)
Definition: view.c:447
int find_arg_uint(const char *const key, unsigned int *val)
Definition: helper.c:348
MenuReturn rofi_view_get_return_value(const RofiViewState *state)
Definition: view.c:513
int find_arg_str(const char *const key, char **val)
Definition: helper.c:306
static void dmenu_finalize(RofiViewState *state)
Definition: dmenu.c:444
rofi_int_matcher ** helper_tokenize(const char *input, int case_sensitive)
Definition: helper.c:257
void rofi_view_free(RofiViewState *state)
Definition: view.c:491
gchar ** columns
Definition: dmenu.c:90
static int get_dmenu_async(DmenuModePrivateData *pd, int sync_pre_read)
Definition: dmenu.c:166
unsigned int only_selected
Definition: dmenu.c:87
void * mode_get_private_data(const Mode *mode)
Definition: mode.c:128
void print_help_msg(const char *option, const char *type, const char *text, const char *def, int isatty)
Definition: xrmoptions.c:750
void mode_destroy(Mode *mode)
Definition: mode.c:49
unsigned int rofi_view_get_next_position(const RofiViewState *state)
Definition: view.c:523
unsigned int selected_line
Definition: dmenu.c:73
unsigned int num_active_list
Definition: dmenu.c:79
static void dmenu_print_results(DmenuModePrivateData *pd, const char *input)
Definition: dmenu.c:423
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
Definition: helper.c:474
unsigned int num_urgent_list
Definition: dmenu.c:77
static char * dmenu_get_message(const Mode *sw)
Definition: dmenu.c:378
static int dmenu_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
Definition: dmenu.c:373
void rofi_view_set_active(RofiViewState *state)
Definition: view.c:452
void * private_data
Definition: mode-private.h:185
int rofi_view_error_dialog(const char *msg, int markup)
Definition: view.c:1760
struct rofi_range_pair * urgent_list
Definition: dmenu.c:76
static void get_dmenu_sync(DmenuModePrivateData *pd)
Definition: dmenu.c:183
Definition: textbox.h:98
static void bittoggle(uint32_t *array, unsigned int index)
Definition: dmenu.c:60
static void async_close_callback(GObject *source_object, GAsyncResult *res, G_GNUC_UNUSED gpointer user_data)
Definition: dmenu.c:100
char * rofi_expand_path(const char *input)
Definition: helper.c:687
GInputStream * input_stream
Definition: dmenu.c:96
void parse_ranges(char *input, rofi_range_pair **list, unsigned int *length)
Definition: helper.c:1166
char * filter
Definition: settings.h:150
static void async_read_cancel(G_GNUC_UNUSED GCancellable *cancel, G_GNUC_UNUSED gpointer data)
Definition: dmenu.c:161
static void read_add(DmenuModePrivateData *pd, char *data, gsize len)
Definition: dmenu.c:106
void mode_set_private_data(Mode *mode, void *pd)
Definition: mode.c:134
char * rofi_force_utf8(const gchar *data, ssize_t length)
Definition: helper.c:771
void rofi_view_restart(RofiViewState *state)
Definition: view.c:441
char * display_name
Definition: mode-private.h:158
void helper_tokenize_free(rofi_int_matcher **tokens)
Definition: helper.c:156
unsigned int start
Definition: rofi-types.h:225
unsigned int num_selected_list
Definition: dmenu.c:81
unsigned int do_markup
Definition: dmenu.c:82
static void dmenu_finish(RofiViewState *state, int retv)
Definition: dmenu.c:407
void rofi_output_formatted_line(const char *format, const char *string, int selected_line, const char *filter)
Definition: helper.c:1200
unsigned int rofi_view_get_selected_line(const RofiViewState *state)
Definition: view.c:518
Settings config
int find_arg(const char *const key)
Definition: helper.c:296
void rofi_view_set_overlay(RofiViewState *state, const char *text)
Definition: view.c:1888
static void dmenu_mode_free(Mode *sw)
Definition: dmenu.c:256
GCancellable * cancel
Definition: dmenu.c:94
GDataInputStream * data_input_stream
Definition: dmenu.c:97
static unsigned int bitget(uint32_t *array, unsigned int index)
Definition: dmenu.c:53
char * name
Definition: mode-private.h:156
RofiViewState * rofi_view_create(Mode *sw, const char *input, MenuFlags menu_flags, void(*finalize)(RofiViewState *))
Definition: view.c:1688
MenuFlags
Definition: view.h:43
int mode_init(Mode *mode)
Definition: mode.c:42