29 #define G_LOG_DOMAIN "Dialogs.Script" 81 gchar **extras = g_strsplit ( buffer,
"\x1f", -1 );
83 for ( extra = extras; *extra != NULL && *( extra + 1 ) != NULL; extra += 2 ) {
85 gchar *value = *( extra + 1 );
86 if ( strcasecmp ( key,
"icon" ) == 0 ) {
89 else if ( strcasecmp ( key,
"meta" ) == 0 ) {
92 else if ( strcasecmp ( key,
"info" ) == 0 ) {
95 else if ( strcasecmp ( key,
"nonselectable" ) == 0 ) {
114 ssize_t length_key = 0;
115 while ( length_key < length && line[length_key] !=
'\x1f' ) {
119 if ( ( length_key + 1 ) < length ) {
120 line[length_key] =
'\0';
121 char *value = line + length_key + 1;
122 if ( strcasecmp ( line,
"message" ) == 0 ) {
124 pd->
message = strlen ( value ) ? g_strdup ( value ) : NULL;
126 else if ( strcasecmp ( line,
"prompt" ) == 0 ) {
128 pd->
prompt = g_strdup ( value );
131 else if ( strcasecmp ( line,
"markup-rows" ) == 0 ) {
132 pd->
do_markup = ( strcasecmp ( value,
"true" ) == 0 );
134 else if ( strcasecmp ( line,
"urgent" ) == 0 ) {
137 else if ( strcasecmp ( line,
"active" ) == 0 ) {
140 else if ( strcasecmp ( line,
"delim" ) == 0 ) {
143 else if ( strcasecmp ( line,
"no-custom" ) == 0 ) {
144 pd->
no_custom = ( strcasecmp ( value,
"true" ) == 0 );
153 GError *error = NULL;
160 char ** env = g_get_environ ();
162 char *str_value = g_strdup_printf (
"%d", value );
163 env = g_environ_setenv ( env,
"ROFI_RETV", str_value, TRUE );
164 g_free ( str_value );
166 str_value = g_strdup_printf (
"%d", (
int) getpid () );
167 env = g_environ_setenv ( env,
"ROFI_OUTSIDE", str_value, TRUE );
168 g_free ( str_value );
170 if ( entry && entry->
info ) {
171 env = g_environ_setenv ( env,
"ROFI_INFO", entry->
info, TRUE );
174 if ( g_shell_parse_argv ( sw->
ed, &argc, &argv, &error ) ) {
175 argv = g_realloc ( argv, ( argc + 2 ) *
sizeof (
char* ) );
176 argv[argc] = g_strdup ( arg );
177 argv[argc + 1] = NULL;
178 g_spawn_async_with_pipes ( NULL, argv, env, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &fd, NULL, &error );
181 if ( error != NULL ) {
182 char *msg = g_strdup_printf (
"Failed to execute: '%s'\nError: '%s'", (
char *) sw->
ed, error->message );
186 g_error_free ( error );
190 FILE *inp = fdopen ( fd,
"r" );
193 size_t buffer_length = 0;
194 ssize_t read_length = 0;
195 size_t actual_size = 0;
196 while ( ( read_length = getdelim ( &buffer, &buffer_length, pd->
delim, inp ) ) > 0 ) {
198 if ( buffer[read_length - 1] == pd->
delim ) {
199 buffer[read_length - 1] =
'\0';
201 if ( buffer[0] ==
'\0' ) {
205 if ( actual_size < ( ( *length ) + 2 ) ) {
209 size_t buf_length = strlen ( buffer ) + 1;
210 retv[( *length )].entry = g_memdup ( buffer, buf_length );
211 retv[( *length )].icon_name = NULL;
212 retv[( *length )].meta = NULL;
213 retv[( *length )].info = NULL;
214 retv[( *length )].icon_fetch_uid = 0;
215 retv[( *length )].nonselectable = FALSE;
216 if ( buf_length > 0 && ( read_length > (ssize_t) buf_length ) ) {
219 retv[( *length ) + 1].entry = NULL;
226 if ( fclose ( inp ) != 0 ) {
227 g_warning (
"Failed to close stdout off executor script: '%s'",
228 g_strerror ( errno ) );
279 unsigned int new_length = 0;
284 if ( selected_line != UINT32_MAX ) {
303 else if ( ( mretv &
MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] !=
'\0' ) {
314 if ( new_list != NULL ) {
332 if ( rmpd != NULL ) {
347 static inline unsigned int get_index (
unsigned int length,
int index )
352 if ( ( (
unsigned int) -index ) <= length ) {
353 return length + index;
358 static char *
_get_display_value (
const Mode *sw,
unsigned int selected_line, G_GNUC_UNUSED
int *state, G_GNUC_UNUSED GList **list,
int get_entry )
364 if ( selected_line >=
start && selected_line <=
stop ) {
371 if ( selected_line >=
start && selected_line <=
stop ) {
378 return get_entry ? g_strdup ( pd->
cmd_list[selected_line].
entry ) : NULL;
386 for (
int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
390 if ( test == tokens[j]->invert && rmpd->
cmd_list[index].
meta ) {
404 return g_strdup ( pd->
message );
409 g_return_val_if_fail ( pd->
cmd_list != NULL, NULL );
424 Mode *sw = g_malloc0 (
sizeof ( *sw ) );
426 char *parse = g_strdup ( str );
427 unsigned int index = 0;
428 const char *
const sep =
":";
429 for (
char *token = strtok_r ( parse, sep, &endp ); token != NULL; token = strtok_r ( NULL, sep, &endp ) ) {
431 sw->
name = g_strdup ( token );
433 else if ( index == 1 ) {
454 fprintf ( stderr,
"The script command '%s' has %u options, but needs 2: <name>:<script>.", str, index );
461 return strchr ( token,
':' ) != NULL;
_mode_get_message _get_message
static int script_mode_init(Mode *sw)
_mode_token_match _token_match
static DmenuScriptEntry * execute_executor(Mode *sw, char *arg, unsigned int *length, int value, DmenuScriptEntry *entry)
unsigned int num_urgent_list
static char * _get_display_value(const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **list, int get_entry)
static void script_switcher_free(Mode *sw)
cairo_surface_t * rofi_icon_fetcher_get(const uint32_t uid)
static unsigned int script_mode_get_num_entries(const Mode *sw)
void * mode_get_private_data(const Mode *mode)
unsigned int num_active_list
_mode_preprocess_input _preprocess_input
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
uint32_t rofi_icon_fetcher_query(const char *name, const int size)
unsigned int cmd_list_length
int rofi_view_error_dialog(const char *msg, int markup)
static cairo_surface_t * script_get_icon(const Mode *sw, unsigned int selected_line, int height)
static void script_mode_destroy(Mode *sw)
gboolean script_switcher_is_valid(const char *token)
char * rofi_expand_path(const char *input)
static void parse_header_entry(Mode *sw, char *line, ssize_t length)
void parse_ranges(char *input, rofi_range_pair **list, unsigned int *length)
DmenuScriptEntry * cmd_list
Mode * script_switcher_parse_setup(const char *str)
static unsigned int get_index(unsigned int length, int index)
struct rofi_range_pair * active_list
static int script_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
static ModeMode script_mode_result(Mode *sw, int mretv, char **input, unsigned int selected_line)
char helper_parse_char(const char *arg)
_mode_get_display_value _get_display_value
static char * script_get_message(const Mode *sw)
void dmenuscript_parse_entry_extras(G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *entry, char *buffer, size_t length)
__mode_get_num_entries _get_num_entries
struct rofi_range_pair * urgent_list
static void script_mode_reset_highlight(Mode *sw)
_mode_get_completion _get_completion