29#define G_LOG_DOMAIN "Modes.Script"
86 G_GNUC_UNUSED
size_t length) {
87 gchar **extras = g_strsplit(buffer,
"\x1f", -1);
88 gchar **extra = extras;
89 for (; *extra != NULL && *(extra + 1) != NULL; extra += 2) {
91 gchar *value = *(extra + 1);
95 if (strcasecmp(key,
"icon") == 0) {
97 }
else if (strcasecmp(key,
"display") == 0) {
99 }
else if (strcasecmp(key,
"meta") == 0) {
101 }
else if (strcasecmp(key,
"info") == 0) {
103 }
else if (strcasecmp(key,
"nonselectable") == 0) {
104 entry->
nonselectable = g_ascii_strcasecmp(value,
"true") == 0;
106 }
else if (strcasecmp(key,
"permanent") == 0) {
107 entry->
permanent = g_ascii_strcasecmp(value,
"true") == 0;
109 }
else if (strcasecmp(key,
"urgent") == 0) {
110 entry->
urgent = g_ascii_strcasecmp(value,
"true") == 0;
112 }
else if (strcasecmp(key,
"active") == 0) {
113 entry->
active = g_ascii_strcasecmp(value,
"true") == 0;
121 if (*extras != NULL) {
133 ssize_t length_key = 0;
134 while (length_key < length && line[length_key] !=
'\x1f') {
138 if ((length_key + 1) < length) {
139 line[length_key] =
'\0';
140 char *value = line + length_key + 1;
141 if (strcasecmp(line,
"message") == 0) {
143 pd->
message = strlen(value) ? g_strdup(value) : NULL;
144 }
else if (strcasecmp(line,
"prompt") == 0) {
146 pd->
prompt = g_strdup(value);
148 }
else if (strcasecmp(line,
"markup-rows") == 0) {
149 pd->
do_markup = (strcasecmp(value,
"true") == 0);
150 }
else if (strcasecmp(line,
"urgent") == 0) {
152 }
else if (strcasecmp(line,
"active") == 0) {
154 }
else if (strcasecmp(line,
"delim") == 0) {
156 }
else if (strcasecmp(line,
"no-custom") == 0) {
157 pd->
no_custom = (strcasecmp(value,
"true") == 0);
158 }
else if (strcasecmp(line,
"use-hot-keys") == 0) {
160 }
else if (strcasecmp(line,
"keep-selection") == 0) {
162 }
else if (strcasecmp(line,
"keep-filter") == 0) {
163 pd->
keep_filter = (strcasecmp(value,
"true") == 0);
164 }
else if (strcasecmp(line,
"new-selection") == 0) {
165 pd->
new_selection = (int64_t)g_ascii_strtoll(value, NULL, 0);
166 }
else if (strcasecmp(line,
"data") == 0) {
168 pd->
data = g_strdup(value);
169 }
else if (strcasecmp(line,
"theme") == 0) {
171 g_warning(
"Failed to parse: '%s'", value);
179 unsigned int *length,
int value,
183 GError *error = NULL;
193 char **env = g_get_environ();
195 char *str_value = g_strdup_printf(
"%d", value);
196 env = g_environ_setenv(env,
"ROFI_RETV", str_value, TRUE);
199 str_value = g_strdup_printf(
"%d", (
int)getpid());
200 env = g_environ_setenv(env,
"ROFI_OUTSIDE", str_value, TRUE);
203 if (entry && entry->
info) {
204 env = g_environ_setenv(env,
"ROFI_INFO", entry->
info, TRUE);
207 env = g_environ_setenv(env,
"ROFI_DATA", pd->
data, TRUE);
210 if (g_shell_parse_argv(sw->
ed, &argc, &argv, &error)) {
211 argv = g_realloc(argv, (argc + 2) *
sizeof(
char *));
212 argv[argc] = g_strdup(arg);
213 argv[argc + 1] = NULL;
214 g_spawn_async_with_pipes(NULL, argv, env, G_SPAWN_SEARCH_PATH, NULL, NULL,
215 NULL, NULL, &fd, NULL, &error);
219 char *msg = g_strdup_printf(
"Failed to execute: '%s'\nError: '%s'",
220 (
char *)sw->
ed, error->message);
228 FILE *inp = fdopen(fd,
"r");
231 size_t buffer_length = 0;
232 ssize_t read_length = 0;
233 size_t actual_size = 0;
234 while ((read_length = getdelim(&buffer, &buffer_length, pd->
delim, inp)) >
237 if (buffer[read_length - 1] == pd->
delim) {
238 buffer[read_length - 1] =
'\0';
240 if (buffer[0] ==
'\0') {
243 if (actual_size < ((*length) + 2)) {
248 size_t buf_length = strlen(buffer) + 1;
249#if GLIB_CHECK_VERSION(2, 68, 0)
250 retv[(*length)].
entry = g_memdup2(buffer, buf_length);
252 retv[(*length)].
entry = g_memdup(buffer, buf_length);
255 retv[(*length)].
display = NULL;
256 retv[(*length)].
meta = NULL;
257 retv[(*length)].
info = NULL;
258 retv[(*length)].
active = FALSE;
259 retv[(*length)].
urgent = FALSE;
264 if (buf_length > 0 && (read_length > (ssize_t)buf_length)) {
267 read_length - buf_length);
277 if (fclose(inp) != 0) {
278 g_warning(
"Failed to close stdout off executor script: '%s'",
323 unsigned int selected_line) {
327 unsigned int new_length = 0;
335 if (selected_line != UINT32_MAX) {
358 1, &(rmpd->
cmd_list[selected_line]));
369 if (new_list != NULL) {
381 if (keep_selection) {
392 if (keep_filter == FALSE) {
420static inline unsigned int get_index(
unsigned int length,
int index) {
424 if (((
unsigned int)-index) <= length) {
425 return length + index;
431 G_GNUC_UNUSED
int *state,
432 G_GNUC_UNUSED GList **list,
int get_entry) {
438 if (selected_line >=
start && selected_line <=
stop) {
446 if (selected_line >=
start && selected_line <=
stop) {
460 return get_entry ? g_strdup(pd->
cmd_list[selected_line].
display) : NULL;
462 return get_entry ? g_strdup(pd->
cmd_list[selected_line].
entry) : NULL;
467 unsigned int index) {
478 pango_parse_markup(rmpd->
cmd_list[index].
entry, -1, 0, NULL, &esc, NULL,
486 for (
int j = 0; match && tokens[j] != NULL; j++) {
490 if (test == tokens[j]->invert && rmpd->
cmd_list[index].
meta) {
511 unsigned int selected_line,
512 unsigned int height) {
515 g_return_val_if_fail(pd->
cmd_list != NULL, NULL);
553 const char *cpath = g_get_user_config_dir();
554 char *script_dir = g_build_filename(cpath,
"rofi",
"scripts", NULL);
555 if (g_file_test(script_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ==
560 GDir *sd = g_dir_open(script_dir, 0, NULL);
562 const char *file = NULL;
563 while ((file = g_dir_read_name(sd)) != NULL) {
564 char *sp = g_build_filename(cpath,
"rofi",
"scripts", file, NULL);
594 Mode *sw = g_malloc0(
sizeof(*sw));
610 Mode *sw = g_malloc0(
sizeof(*sw));
611 unsigned int index = 0;
612 const char *
const sep =
":";
613 char **tokens = g_strsplit(str, sep, 2);
615 index = g_strv_length(tokens);
616 sw->
name = g_strdup(tokens[0]);
637 "The script command '%s' has %u options, but needs 2: <name>:<script>.",
647 return strchr(token,
':') != NULL;
653 printf(
" • %s%s%s (%s)\n", is_term ? (
color_bold) :
"",
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)
void rofi_clear_error_messages(void)
void script_mode_gather_user_scripts(void)
gboolean script_mode_is_valid(const char *token)
void script_user_list(gboolean is_term)
void script_mode_cleanup(void)
Mode * script_mode_parse_setup(const char *str)
int rofi_view_error_dialog(const char *msg, int markup)
RofiViewState * rofi_view_get_active(void)
void rofi_view_set_selected_line(RofiViewState *state, unsigned int selected_line)
static void script_mode_destroy(Mode *sw)
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)
static cairo_surface_t * script_get_icon(const Mode *sw, unsigned int selected_line, unsigned int height)
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 * script_get_message(const Mode *sw)
ScriptUser * user_scripts
static int script_mode_has_user_script(char const *const user)
static void script_mode_reset_highlight(Mode *sw)
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 int script_mode_init(Mode *sw)
static DmenuScriptEntry * execute_executor(Mode *sw, char *arg, unsigned int *length, int value, DmenuScriptEntry *entry)
static int script_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
struct ScriptUser ScriptUser
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
gboolean rofi_theme_parse_string(const char *string)