29 #define G_LOG_DOMAIN "Dialogs.Script"
81 G_GNUC_UNUSED
size_t length) {
82 gchar **extras = g_strsplit(buffer,
"\x1f", -1);
84 for (extra = extras; *extra != NULL && *(extra + 1) != NULL; extra += 2) {
86 gchar *value = *(extra + 1);
87 if (strcasecmp(key,
"icon") == 0) {
89 }
else if (strcasecmp(key,
"meta") == 0) {
91 }
else if (strcasecmp(key,
"info") == 0) {
93 }
else if (strcasecmp(key,
"nonselectable") == 0) {
110 ssize_t length_key = 0;
111 while (length_key < length && line[length_key] !=
'\x1f') {
115 if ((length_key + 1) < length) {
116 line[length_key] =
'\0';
117 char *value = line + length_key + 1;
118 if (strcasecmp(line,
"message") == 0) {
120 pd->
message = strlen(value) ? g_strdup(value) : NULL;
121 }
else if (strcasecmp(line,
"prompt") == 0) {
123 pd->
prompt = g_strdup(value);
125 }
else if (strcasecmp(line,
"markup-rows") == 0) {
126 pd->
do_markup = (strcasecmp(value,
"true") == 0);
127 }
else if (strcasecmp(line,
"urgent") == 0) {
129 }
else if (strcasecmp(line,
"active") == 0) {
131 }
else if (strcasecmp(line,
"delim") == 0) {
133 }
else if (strcasecmp(line,
"no-custom") == 0) {
134 pd->
no_custom = (strcasecmp(value,
"true") == 0);
135 }
else if (strcasecmp(line,
"use-hot-keys") == 0) {
142 unsigned int *length,
int value,
146 GError *error = NULL;
153 char **env = g_get_environ();
155 char *str_value = g_strdup_printf(
"%d", value);
156 env = g_environ_setenv(env,
"ROFI_RETV", str_value, TRUE);
159 str_value = g_strdup_printf(
"%d", (
int)getpid());
160 env = g_environ_setenv(env,
"ROFI_OUTSIDE", str_value, TRUE);
163 if (entry && entry->
info) {
164 env = g_environ_setenv(env,
"ROFI_INFO", entry->
info, TRUE);
167 if (g_shell_parse_argv(sw->
ed, &argc, &argv, &error)) {
168 argv = g_realloc(argv, (argc + 2) *
sizeof(
char *));
169 argv[argc] = g_strdup(arg);
170 argv[argc + 1] = NULL;
171 g_spawn_async_with_pipes(NULL, argv, env, G_SPAWN_SEARCH_PATH, NULL, NULL,
172 NULL, NULL, &fd, NULL, &error);
176 char *msg = g_strdup_printf(
"Failed to execute: '%s'\nError: '%s'",
177 (
char *)sw->
ed, error->message);
185 FILE *inp = fdopen(fd,
"r");
188 size_t buffer_length = 0;
189 ssize_t read_length = 0;
190 size_t actual_size = 0;
191 while ((read_length = getdelim(&buffer, &buffer_length, pd->
delim, inp)) >
194 if (buffer[read_length - 1] == pd->
delim) {
195 buffer[read_length - 1] =
'\0';
197 if (buffer[0] ==
'\0') {
200 if (actual_size < ((*length) + 2)) {
204 size_t buf_length = strlen(buffer) + 1;
205 retv[(*length)].entry = g_memdup(buffer, buf_length);
206 retv[(*length)].icon_name = NULL;
207 retv[(*length)].meta = NULL;
208 retv[(*length)].info = NULL;
209 retv[(*length)].icon_fetch_uid = 0;
210 retv[(*length)].nonselectable = FALSE;
211 if (buf_length > 0 && (read_length > (ssize_t)buf_length)) {
214 read_length - buf_length);
216 retv[(*length) + 1].entry = NULL;
223 if (fclose(inp) != 0) {
224 g_warning(
"Failed to close stdout off executor script: '%s'",
269 unsigned int selected_line) {
273 unsigned int new_length = 0;
278 if (selected_line != UINT32_MAX) {
301 1, &(rmpd->
cmd_list[selected_line]));
313 if (new_list != NULL) {
345 static inline unsigned int get_index(
unsigned int length,
int index) {
349 if (((
unsigned int)-index) <= length) {
350 return length + index;
356 G_GNUC_UNUSED
int *state,
357 G_GNUC_UNUSED GList **list,
int get_entry) {
363 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;
382 unsigned int index) {
386 for (
int j = 0; match && tokens != NULL && tokens[j] != NULL; j++) {
390 if (test == tokens[j]->invert && rmpd->
cmd_list[index].
meta) {
405 static cairo_surface_t *
409 g_return_val_if_fail(pd->
cmd_list != NULL, NULL);
423 Mode *sw = g_malloc0(
sizeof(*sw));
425 char *parse = g_strdup(str);
426 unsigned int index = 0;
427 const char *
const sep =
":";
428 for (
char *token = strtok_r(parse, sep, &endp); token != NULL;
429 token = strtok_r(NULL, sep, &endp)) {
431 sw->
name = g_strdup(token);
432 }
else if (index == 1) {
454 "The script command '%s' has %u options, but needs 2: <name>:<script>.",
461 return strchr(token,
':') != NULL;
void parse_ranges(char *input, rofi_range_pair **list, unsigned int *length)
char helper_parse_char(const char *arg)
char * rofi_expand_path(const char *input)
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
cairo_surface_t * rofi_icon_fetcher_get(const uint32_t uid)
uint32_t rofi_icon_fetcher_query(const char *name, const int size)
void * mode_get_private_data(const Mode *mode)
Mode * script_switcher_parse_setup(const char *str)
gboolean script_switcher_is_valid(const char *token)
int rofi_view_error_dialog(const char *msg, int markup)
static void script_mode_destroy(Mode *sw)
static cairo_surface_t * script_get_icon(const Mode *sw, unsigned int selected_line, int height)
static void script_switcher_free(Mode *sw)
static void parse_header_entry(Mode *sw, char *line, ssize_t length)
static ModeMode script_mode_result(Mode *sw, int mretv, char **input, unsigned int selected_line)
void dmenuscript_parse_entry_extras(G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *entry, char *buffer, G_GNUC_UNUSED size_t length)
static unsigned int get_index(unsigned int length, int index)
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 char * script_get_message(const Mode *sw)
static DmenuScriptEntry * execute_executor(Mode *sw, char *arg, unsigned int *length, int value, DmenuScriptEntry *entry)
static void script_mode_reset_highlight(Mode *sw)
static int script_mode_init(Mode *sw)
static int script_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
static unsigned int script_mode_get_num_entries(const Mode *sw)
struct rofi_range_pair * urgent_list
struct rofi_range_pair * active_list
unsigned int num_urgent_list
unsigned int cmd_list_length
unsigned int num_active_list
DmenuScriptEntry * cmd_list
__mode_get_num_entries _get_num_entries
_mode_preprocess_input _preprocess_input
_mode_token_match _token_match
_mode_get_display_value _get_display_value
_mode_get_completion _get_completion
_mode_get_message _get_message