rofi 2.0.0
helper.c
Go to the documentation of this file.
1/*
2 * rofi
3 *
4 * MIT/X11 License
5 * Copyright © 2012 Sean Pringle <sean.pringle@gmail.com>
6 * Copyright © 2013-2023 Qball Cow <qball@gmpclient.org>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 */
28
30#include "config.h"
31#define G_LOG_DOMAIN "Helper"
32
33#include "display.h"
34#include "helper-theme.h"
35#include "helper.h"
36#include "rofi.h"
37#include "settings.h"
38#include "view.h"
39#include <ctype.h>
40#include <errno.h>
41#include <fcntl.h>
42#include <glib.h>
43#include <glib/gstdio.h>
44#include <limits.h>
45#include <pango/pango-fontmap.h>
46#include <pango/pango.h>
47#include <pango/pangocairo.h>
48#include <pwd.h>
49#include <stdio.h>
50#include <stdlib.h>
51#include <string.h>
52#include <sys/file.h>
53#include <sys/stat.h>
54#include <sys/types.h>
55#include <unistd.h>
56
57const char *const MatchingMethodStr[MM_NUM_MATCHERS] = {
58 "Normal", "Regex", "Glob", "Fuzzy", "Prefix"};
59
62 -1,
63};
65static int CurrentMatchingMethod = 0;
66
70const char *const monitor_position_entries[] = {
71 "on focused monitor", "on focused window", "at mouse pointer",
72 "on monitor with focused window", "on monitor that has mouse pointer"};
73
76char **stored_argv = NULL;
77
78char *helper_string_replace_if_exists_v(char *string, GHashTable *h);
79
81 return MatchingMethodStr[config.matching_method];
82}
96
97void cmd_set_arguments(int argc, char **argv) {
98 stored_argc = argc;
99 stored_argv = argv;
100}
101
102int helper_parse_setup(char *string, char ***output, int *length, ...) {
103 GError *error = NULL;
104 GHashTable *h;
105 h = g_hash_table_new(g_str_hash, g_str_equal);
106 // By default, we insert terminal and ssh-client
107 g_hash_table_insert(h, "{terminal}", config.terminal_emulator);
108 g_hash_table_insert(h, "{ssh-client}", config.ssh_client);
109 // Add list from variable arguments.
110 va_list ap;
111 va_start(ap, length);
112 while (1) {
113 char *key = va_arg(ap, char *);
114 if (key == (char *)0) {
115 break;
116 }
117 char *value = va_arg(ap, char *);
118 if (value == (char *)0) {
119 break;
120 }
121 g_hash_table_insert(h, key, value);
122 }
123 va_end(ap);
124
125 char *res = helper_string_replace_if_exists_v(string, h);
126 // Destroy key-value storage.
127 g_hash_table_destroy(h);
128 // Parse the string into shell arguments.
129 if (g_shell_parse_argv(res, length, output, &error)) {
130 g_free(res);
131 return TRUE;
132 }
133 g_free(res);
134 // Throw error if shell parsing fails.
135 if (error) {
136 char *msg = g_strdup_printf("Failed to parse: '%s'\nError: '%s'", string,
137 error->message);
138 rofi_view_error_dialog(msg, FALSE);
139 g_free(msg);
140 // print error.
141 g_error_free(error);
142 }
143 return FALSE;
144}
145
147 for (size_t i = 0; tokens && tokens[i]; i++) {
148 g_regex_unref((GRegex *)tokens[i]->regex);
149 g_free(tokens[i]);
150 }
151 g_free(tokens);
152}
153
154static gchar *glob_to_regex(const char *input) {
155 gchar *r = g_regex_escape_string(input, -1);
156 size_t str_l = strlen(r);
157 for (size_t i = 0; i < str_l; i++) {
158 if (r[i] == '\\') {
159 if (r[i + 1] == '*') {
160 r[i] = '.';
161 } else if (r[i + 1] == '?') {
162 r[i + 1] = 'S';
163 }
164 i++;
165 }
166 }
167 return r;
168}
169static gchar *fuzzy_to_regex(const char *input) {
170 char *retv = NULL;
171 GString *str = g_string_new("");
172 gchar *r = g_regex_escape_string(input, -1);
173 gchar *iter;
174 int first = 1;
175 for (iter = r; iter && *iter != '\0'; iter = g_utf8_next_char(iter)) {
176 if (first) {
177 g_string_append(str, "(");
178 } else {
179 g_string_append(str, ".*?(");
180 }
181 if (*iter == '\\') {
182 g_string_append_c(str, '\\');
183 iter = g_utf8_next_char(iter);
184 // If EOL, break out of for loop.
185 if ((*iter) == '\0') {
186 break;
187 }
188 }
189 g_string_append_unichar(str, g_utf8_get_char(iter));
190 g_string_append(str, ")");
191 first = 0;
192 }
193 g_free(r);
194 retv = g_string_free(str, FALSE);
195 return retv;
196}
197
198static gchar *prefix_regex(const char *input) {
199 gchar *r = g_regex_escape_string(input, -1);
200 char *retv = g_strconcat("\\b", r, NULL);
201 g_free(r);
202 return retv;
203}
204
205static char *utf8_helper_simplify_string(const char *os) {
206 char buf[6] = {
207 0,
208 };
209
210 // Normalize the string to a fully decomposed form, then filter out
211 // mark/accent characters.
212 char *s = g_utf8_normalize(os, -1, G_NORMALIZE_ALL);
213 ssize_t str_size = (g_utf8_strlen(s, -1) * 6 + 2 + 1) * sizeof(char);
214 char *str = g_malloc0(str_size);
215 char *striter = str;
216 for (const char *iter = s; iter && *iter; iter = g_utf8_next_char(iter)) {
217 gunichar uc = g_utf8_get_char(iter);
218 if (!g_unichar_ismark(uc)) {
219 int l = g_unichar_to_utf8(uc, buf);
220 memcpy(striter, buf, l);
221 striter += l;
222 }
223 }
224 g_free(s);
225
226 return str;
227}
228
229// Macro for quickly generating regex for matching.
230static inline GRegex *R(const char *s, int case_sensitive) {
231 if (config.normalize_match) {
232 char *str = utf8_helper_simplify_string(s);
233
234 GRegex *r = g_regex_new(
235 str, G_REGEX_OPTIMIZE | ((case_sensitive) ? 0 : G_REGEX_CASELESS), 0,
236 NULL);
237
238 g_free(str);
239 return r;
240 }
241 return g_regex_new(
242 s, G_REGEX_OPTIMIZE | ((case_sensitive) ? 0 : G_REGEX_CASELESS), 0, NULL);
243}
244
245static rofi_int_matcher *create_regex(const char *input, int case_sensitive) {
246 GRegex *retv = NULL;
247 gchar *r;
248 rofi_int_matcher *rv = g_malloc0(sizeof(rofi_int_matcher));
249 if (input && input[0] == config.matching_negate_char) {
250 rv->invert = 1;
251 input++;
252 }
253 switch (config.matching_method) {
254 case MM_GLOB:
255 r = glob_to_regex(input);
256 retv = R(r, case_sensitive);
257 g_free(r);
258 break;
259 case MM_REGEX:
260 retv = R(input, case_sensitive);
261 if (retv == NULL) {
262 r = g_regex_escape_string(input, -1);
263 retv = R(r, case_sensitive);
264 g_free(r);
265 }
266 break;
267 case MM_FUZZY:
268 r = fuzzy_to_regex(input);
269 retv = R(r, case_sensitive);
270 g_free(r);
271 break;
272 case MM_PREFIX:
273 r = prefix_regex(input);
274 retv = R(r, case_sensitive);
275 g_free(r);
276 break;
277 default:
278 r = g_regex_escape_string(input, -1);
279 retv = R(r, case_sensitive);
280 g_free(r);
281 break;
282 }
283 rv->regex = retv;
284 return rv;
285}
286rofi_int_matcher **helper_tokenize(const char *input, int case_sensitive) {
287 if (input == NULL) {
288 return NULL;
289 }
290 size_t len = strlen(input);
291 if (len == 0) {
292 return NULL;
293 }
294
295 char *saveptr = NULL, *token;
296 rofi_int_matcher **retv = NULL;
297 if (!config.tokenize) {
298 retv = g_malloc0(sizeof(rofi_int_matcher *) * 2);
299 retv[0] = create_regex(input, case_sensitive);
300 return retv;
301 }
302
303 // First entry is always full (modified) stringtext.
304 int num_tokens = 0;
305
306 // Copy the string, 'strtok_r' modifies it.
307 char *str = g_strdup(input);
308
309 // Iterate over tokens.
310 // strtok should still be valid for utf8.
311 const char *const sep = " ";
312 for (token = strtok_r(str, sep, &saveptr); token != NULL;
313 token = strtok_r(NULL, sep, &saveptr)) {
314 retv = g_realloc(retv, sizeof(rofi_int_matcher *) * (num_tokens + 2));
315 retv[num_tokens] = create_regex(token, case_sensitive);
316 retv[num_tokens + 1] = NULL;
317 num_tokens++;
318 }
319 // Free str.
320 g_free(str);
321 return retv;
322}
323
324// cli arg handling
325int find_arg(const char *const key) {
326 int i;
327
328 for (i = 0; i < stored_argc && strcasecmp(stored_argv[i], key); i++) {
329 ;
330 }
331
332 return i < stored_argc ? i : -1;
333}
334int find_arg_str(const char *const key, char **val) {
335 int i = find_arg(key);
336
337 if (val != NULL && i > 0 && i < stored_argc - 1) {
338 *val = stored_argv[i + 1];
339 return TRUE;
340 }
341 return FALSE;
342}
343
344const char **find_arg_strv(const char *const key) {
345 const char **retv = NULL;
346 int length = 0;
347 for (int i = 0; i < stored_argc; i++) {
348 if (i < (stored_argc - 1) && strcasecmp(stored_argv[i], key) == 0) {
349 length++;
350 }
351 }
352 if (length > 0) {
353 retv = g_malloc0((length + 1) * sizeof(char *));
354 int index = 0;
355 for (int i = 0; i < stored_argc; i++) {
356 if (i < (stored_argc - 1) && strcasecmp(stored_argv[i], key) == 0) {
357 retv[index++] = stored_argv[i + 1];
358 }
359 }
360 }
361 return retv;
362}
363
364int find_arg_int(const char *const key, int *val) {
365 int i = find_arg(key);
366
367 if (val != NULL && i > 0 && i < (stored_argc - 1)) {
368 *val = strtol(stored_argv[i + 1], NULL, 10);
369 return TRUE;
370 }
371 return FALSE;
372}
373int find_arg_uint(const char *const key, unsigned int *val) {
374 int i = find_arg(key);
375
376 if (val != NULL && i > 0 && i < (stored_argc - 1)) {
377 *val = strtoul(stored_argv[i + 1], NULL, 10);
378 return TRUE;
379 }
380 return FALSE;
381}
382
383char helper_parse_char(const char *arg) {
384 const size_t len = strlen(arg);
385 // If the length is 1, it is not escaped.
386 if (len == 1) {
387 return arg[0];
388 }
389 // If the length is 2 and the first character is '\', we unescape it.
390 if (len == 2 && arg[0] == '\\') {
391 switch (arg[1]) {
392 // New line
393 case 'n':
394 return '\n';
395 // Bell
396 case 'a':
397 return '\a';
398 // Backspace
399 case 'b':
400 return '\b';
401 // Tab
402 case 't':
403 return '\t';
404 // Vertical tab
405 case 'v':
406 return '\v';
407 // Form feed
408 case 'f':
409 return '\f';
410 // Carriage return
411 case 'r':
412 return '\r';
413 // Forward slash
414 case '\\':
415 return '\\';
416 // 0 line.
417 case '0':
418 return '\0';
419 default:
420 break;
421 }
422 }
423 if (len > 2 && arg[0] == '\\' && arg[1] == 'x') {
424 return (char)strtol(&arg[2], NULL, 16);
425 }
426 g_warning("Failed to parse character string: \"%s\"", arg);
427 // for now default to newline.
428 return '\n';
429}
430
431int find_arg_char(const char *const key, char *val) {
432 int i = find_arg(key);
433
434 if (val != NULL && i > 0 && i < (stored_argc - 1)) {
435 *val = helper_parse_char(stored_argv[i + 1]);
436 return TRUE;
437 }
438 return FALSE;
439}
440
441void helper_token_match_set_pango_attr_on_style(PangoAttrList *retv, int start,
442 int end,
444 if (th.style & ROFI_HL_BOLD) {
445 PangoAttribute *pa = pango_attr_weight_new(PANGO_WEIGHT_BOLD);
446 pa->start_index = start;
447 pa->end_index = end;
448 pango_attr_list_insert(retv, pa);
449 }
450#if PANGO_VERSION_CHECK(1, 50, 0)
451 if (th.style & ROFI_HL_UPPERCASE) {
452 PangoAttribute *pa =
453 pango_attr_text_transform_new(PANGO_TEXT_TRANSFORM_UPPERCASE);
454 pa->start_index = start;
455 pa->end_index = end;
456 pango_attr_list_insert(retv, pa);
457 }
458 if (th.style & ROFI_HL_LOWERCASE) {
459 PangoAttribute *pa =
460 pango_attr_text_transform_new(PANGO_TEXT_TRANSFORM_LOWERCASE);
461 pa->start_index = start;
462 pa->end_index = end;
463 pango_attr_list_insert(retv, pa);
464 }
465 if (th.style & ROFI_HL_CAPITALIZE) {
466#if 0
467 PangoAttribute *pa =
468 pango_attr_text_transform_new(PANGO_TEXT_TRANSFORM_CAPITALIZE);
469 pa->start_index = start;
470 pa->end_index = end;
471 pango_attr_list_insert(retv, pa);
472#endif
473 // Disabled because of bug in pango
474 }
475#endif
476 if (th.style & ROFI_HL_UNDERLINE) {
477 PangoAttribute *pa = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
478 pa->start_index = start;
479 pa->end_index = end;
480 pango_attr_list_insert(retv, pa);
481 }
482 if (th.style & ROFI_HL_STRIKETHROUGH) {
483 PangoAttribute *pa = pango_attr_strikethrough_new(TRUE);
484 pa->start_index = start;
485 pa->end_index = end;
486 pango_attr_list_insert(retv, pa);
487 }
488 if (th.style & ROFI_HL_ITALIC) {
489 PangoAttribute *pa = pango_attr_style_new(PANGO_STYLE_ITALIC);
490 pa->start_index = start;
491 pa->end_index = end;
492 pango_attr_list_insert(retv, pa);
493 }
494 if (th.style & ROFI_HL_COLOR) {
495 PangoAttribute *pa = pango_attr_foreground_new(
496 th.color.red * 65535, th.color.green * 65535, th.color.blue * 65535);
497 pa->start_index = start;
498 pa->end_index = end;
499 pango_attr_list_insert(retv, pa);
500
501 if (th.color.alpha < 1.0) {
502 pa = pango_attr_foreground_alpha_new(th.color.alpha * 65535);
503 pa->start_index = start;
504 pa->end_index = end;
505 pango_attr_list_insert(retv, pa);
506 }
507 }
508}
509
511 rofi_int_matcher **tokens,
512 const char *input,
513 PangoAttrList *retv) {
514 // Disable highlighting for normalize match, not supported atm.
515 if (config.normalize_match) {
516 return retv;
517 }
518 // Do a tokenized match.
519 if (tokens) {
520 for (int j = 0; tokens[j]; j++) {
521 GMatchInfo *gmi = NULL;
522 if (tokens[j]->invert) {
523 continue;
524 }
525 g_regex_match(tokens[j]->regex, input, G_REGEX_MATCH_PARTIAL, &gmi);
526 while (g_match_info_matches(gmi)) {
527 int count = g_match_info_get_match_count(gmi);
528 for (int index = (count > 1) ? 1 : 0; index < count; index++) {
529 int start, end;
530 g_match_info_fetch_pos(gmi, index, &start, &end);
531 helper_token_match_set_pango_attr_on_style(retv, start, end, th);
532 }
533 g_match_info_next(gmi, NULL);
534 }
535 g_match_info_free(gmi);
536 }
537 }
538 return retv;
539}
540
541int helper_token_match(rofi_int_matcher *const *tokens, const char *input) {
542 int match = TRUE;
543 // Do a tokenized match.
544 if (tokens) {
545 if (config.normalize_match) {
546 char *r = utf8_helper_simplify_string(input);
547 for (int j = 0; match && tokens[j]; j++) {
548 match = g_regex_match(tokens[j]->regex, r, 0, NULL);
549 match ^= tokens[j]->invert;
550 }
551 g_free(r);
552 } else {
553 for (int j = 0; match && tokens[j]; j++) {
554 match = g_regex_match(tokens[j]->regex, input, 0, NULL);
555 match ^= tokens[j]->invert;
556 }
557 }
558 }
559 return match;
560}
561
562int execute_generator(const char *cmd) {
563 char **args = NULL;
564 int argv = 0;
565 helper_parse_setup(config.run_command, &args, &argv, "{cmd}", cmd, (char *)0);
566
567 int fd = -1;
568 GError *error = NULL;
569 g_spawn_async_with_pipes(NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
570 NULL, NULL, &fd, NULL, &error);
571
572 if (error != NULL) {
573 char *msg = g_strdup_printf("Failed to execute: '%s'\nError: '%s'", cmd,
574 error->message);
575 rofi_view_error_dialog(msg, FALSE);
576 g_free(msg);
577 // print error.
578 g_error_free(error);
579 fd = -1;
580 }
581 g_strfreev(args);
582 return fd;
583}
584
585int create_pid_file(const char *pidfile, gboolean kill_running) {
586 if (pidfile == NULL) {
587 return -1;
588 }
589
590 int fd = g_open(pidfile, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
591 if (fd < 0) {
592 g_warning("Failed to create pid file: '%s'.", pidfile);
593 return -1;
594 }
595 // Set it to close the File Descriptor on exit.
596 int flags = fcntl(fd, F_GETFD, NULL);
597 flags = flags | FD_CLOEXEC;
598 if (fcntl(fd, F_SETFD, flags, NULL) < 0) {
599 g_warning("Failed to set CLOEXEC on pidfile.");
600 remove_pid_file(fd);
601 return -1;
602 }
603 // Try to get exclusive write lock on FD
604 int retv = flock(fd, LOCK_EX | LOCK_NB);
605 if (retv != 0) {
606 g_warning("Failed to set lock on pidfile: Rofi already running?");
607 g_warning("Got error: %d %s", retv, g_strerror(errno));
608 if (kill_running) {
609 char buffer[64] = {
610 0,
611 };
612 ssize_t l = read(fd, &(buffer[0]), 63);
613 if (l > 1) {
614 buffer[l] = 0;
615 pid_t pid = g_ascii_strtoll(buffer, NULL, 0);
616 kill(pid, SIGTERM);
617 while (1) {
618 retv = flock(fd, LOCK_EX | LOCK_NB);
619 if (retv == 0) {
620 break;
621 }
622 g_usleep(100);
623 }
624 }
625 remove_pid_file(fd);
626 return create_pid_file(pidfile, FALSE);
627 }
628
629 remove_pid_file(fd);
630 return -1;
631 }
632 if (ftruncate(fd, (off_t)0) == 0) {
633 // Write pid, not needed, but for completeness sake.
634 char buffer[64];
635 int length = snprintf(buffer, 64, "%i", getpid());
636 ssize_t l = 0;
637 while (l < length) {
638 l += write(fd, &buffer[l], length - l);
639 }
640 }
641 return fd;
642}
643
644void remove_pid_file(int fd) {
645 if (fd >= 0) {
646 if (close(fd)) {
647 g_warning("Failed to close pidfile: '%s'", g_strerror(errno));
648 }
649 }
650}
651
652gboolean helper_validate_font(PangoFontDescription *pfd, const char *font) {
653 const char *fam = pango_font_description_get_family(pfd);
654 int size = pango_font_description_get_size(pfd);
655 if (fam == NULL || size == 0) {
656 g_debug("Pango failed to parse font: '%s'", font);
657 g_debug("Got family: <b>%s</b> at size: <b>%d</b>", fam ? fam : "{unknown}",
658 size);
659 return FALSE;
660 }
661 return TRUE;
662}
663
672 int found_error = FALSE;
673 GString *msg =
674 g_string_new("<big><b>The configuration failed to validate:</b></big>\n");
675
676 if (config.sorting_method) {
677 if (g_strcmp0(config.sorting_method, "normal") == 0) {
678 config.sorting_method_enum = SORT_NORMAL;
679 } else if (g_strcmp0(config.sorting_method, "levenshtein") == 0) {
680 config.sorting_method_enum = SORT_NORMAL;
681 } else if (g_strcmp0(config.sorting_method, "fzf") == 0) {
682 config.sorting_method_enum = SORT_FZF;
683 } else {
684 g_string_append_printf(
685 msg,
686 "\t<b>config.sorting_method</b>=%s is not a valid sorting "
687 "strategy.\nValid options are: normal or fzf.\n",
688 config.sorting_method);
689 found_error = 1;
690 }
691 }
692
693 if (config.matching) {
694 char **strv = g_strsplit(config.matching, ",", 0);
695 if (strv) {
696 int matching_method_index = 0;
697 for (char **str = strv; *str && matching_method_index < MM_NUM_MATCHERS;
698 str++) {
699 gboolean found = FALSE;
700 for (unsigned i = 0;
701 i < MM_NUM_MATCHERS && matching_method_index < MM_NUM_MATCHERS;
702 i++) {
703 if (g_ascii_strcasecmp(*str, MatchingMethodStr[i]) == 0) {
704 MatchingMethodEnabled[matching_method_index] = i;
705 matching_method_index++;
706 NUMMatchingMethodEnabled = matching_method_index;
707 if (matching_method_index == MM_NUM_MATCHERS) {
708 found_error = 1;
709 g_string_append_printf(msg,
710 "\t<b>config.matching</b> = %s to many "
711 "matching options enabled.\n",
712 config.matching);
713 }
714 found = TRUE;
715 }
716 }
717 if (!found) {
718 g_string_append_printf(msg,
719 "\t<b>config.matching</b>=%s is not a valid "
720 "matching strategy.\nValid options are: glob, "
721 "regex, fuzzy, prefix or normal.\n",
722 *str);
723 found_error = 1;
724 }
725 }
726 config.matching_method = MatchingMethodEnabled[0];
727 g_strfreev(strv);
728 }
729 }
730
731 if (config.element_height < 1) {
732 g_string_append_printf(msg,
733 "\t<b>config.element_height</b>=%d is invalid. An "
734 "element needs to be at least 1 line high.\n",
735 config.element_height);
736 config.element_height = 1;
737 found_error = TRUE;
738 }
739 if (!(config.location >= 0 && config.location <= 8)) {
740 g_string_append_printf(msg,
741 "\t<b>config.location</b>=%d is invalid. Value "
742 "should be between %d and %d.\n",
743 config.location, 0, 8);
744 config.location = WL_CENTER;
745 found_error = 1;
746 }
747
748#ifdef ENABLE_XCB
749 // Check size
750 {
752 if (config.backend == DISPLAY_XCB && !monitor_active(&mon)) {
753 const char *name = config.monitor;
754 if (name && name[0] == '-') {
755 int index = name[1] - '0';
756 if (index < 5 && index > 0) {
757 name = monitor_position_entries[index - 1];
758 }
759 }
760 g_string_append_printf(
761 msg, "\t<b>config.monitor</b>=%s Could not find monitor.\n", name);
762 found_error = TRUE;
763 }
764 }
765#endif
766
767 if (g_strcmp0(config.monitor, "-3") == 0) {
768 // On -3, set to location 1.
769 config.location = 1;
770 }
771
772 if (found_error) {
773 g_string_append(msg, "Please update your configuration.");
775 return TRUE;
776 }
777
778 g_string_free(msg, TRUE);
779 return FALSE;
780}
781
782char *rofi_expand_path(const char *input) {
783 char **str = g_strsplit(input, G_DIR_SEPARATOR_S, -1);
784 for (unsigned int i = 0; str && str[i]; i++) {
785 // Replace ~ with current user homedir.
786 if (str[i][0] == '~' && str[i][1] == '\0') {
787 g_free(str[i]);
788 str[i] = g_strdup(g_get_home_dir());
789 }
790 // If other user, ask getpwnam.
791 else if (str[i][0] == '~') {
792 struct passwd *p = getpwnam(&(str[i][1]));
793 if (p != NULL) {
794 g_free(str[i]);
795 str[i] = g_strdup(p->pw_dir);
796 }
797 } else if (i == 0) {
798 char *s = str[i];
799 if (input[0] == G_DIR_SEPARATOR) {
800 str[i] = g_strdup_printf("%s%s", G_DIR_SEPARATOR_S, s);
801 g_free(s);
802 }
803 }
804 }
805 char *retv = g_build_filenamev(str);
806 g_strfreev(str);
807 return retv;
808}
809
811#define MIN3(a, b, c) \
812 ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))
813
814unsigned int levenshtein(const char *needle, const glong needlelen,
815 const char *haystack, const glong haystacklen,
816 int case_sensitive) {
817 if (needlelen == G_MAXLONG) {
818 // String to long, we cannot handle this.
819 return UINT_MAX;
820 }
821 unsigned int column[needlelen + 1];
822 for (glong y = 0; y < needlelen; y++) {
823 column[y] = y;
824 }
825 // Removed out of the loop, otherwise static code analyzers think it is
826 // unset.. silly but true. old loop: for ( glong y = 0; y <= needlelen; y++)
827 column[needlelen] = needlelen;
828 for (glong x = 1; x <= haystacklen; x++) {
829 const char *needles = needle;
830 column[0] = x;
831 gunichar haystackc = g_utf8_get_char(haystack);
832 if (!case_sensitive) {
833 haystackc = g_unichar_tolower(haystackc);
834 }
835 for (glong y = 1, lastdiag = x - 1; y <= needlelen; y++) {
836 gunichar needlec = g_utf8_get_char(needles);
837 if (!case_sensitive) {
838 needlec = g_unichar_tolower(needlec);
839 }
840 unsigned int olddiag = column[y];
841 column[y] = MIN3(column[y] + 1, column[y - 1] + 1,
842 lastdiag + (needlec == haystackc ? 0 : 1));
843 lastdiag = olddiag;
844 needles = g_utf8_next_char(needles);
845 }
846 haystack = g_utf8_next_char(haystack);
847 }
848 return column[needlelen];
849}
850
851char *rofi_latin_to_utf8_strdup(const char *input, gssize length) {
852 gsize slength = 0;
853 return g_convert_with_fallback(input, length, "UTF-8", "latin1", "\uFFFD",
854 NULL, &slength, NULL);
855}
856
857char *rofi_force_utf8(const gchar *data, ssize_t length) {
858 if (data == NULL) {
859 return NULL;
860 }
861 const char *end;
862 GString *string;
863
864 if (g_utf8_validate(data, length, &end)) {
865 return g_memdup2(data, length + 1);
866 }
867 string = g_string_sized_new(length + 16);
868
869 do {
870 /* Valid part of the string */
871 g_string_append_len(string, data, end - data);
872 /* Replacement character */
873 g_string_append(string, "\uFFFD");
874 length -= (end - data) + 1;
875 data = end + 1;
876 } while (!g_utf8_validate(data, length, &end));
877
878 if (length) {
879 g_string_append_len(string, data, length);
880 }
881
882 return g_string_free(string, FALSE);
883}
884
885/****
886 * FZF like scorer
887 */
888
890#define FUZZY_SCORER_MAX_LENGTH 256
892#define MIN_SCORE (INT_MIN / 2)
894#define LEADING_GAP_SCORE -4
896#define GAP_SCORE -5
898#define WORD_START_SCORE 50
900#define NON_WORD_SCORE 40
902#define CAMEL_SCORE (WORD_START_SCORE + GAP_SCORE - 1)
904#define CONSECUTIVE_SCORE (WORD_START_SCORE + GAP_SCORE)
906#define PATTERN_NON_START_MULTIPLIER 1
908#define PATTERN_START_MULTIPLIER 2
909
914 /* Lower case */
916 /* Upper case */
918 /* Number */
920 /* non word character */
922};
923
930 if (g_unichar_islower(c)) {
931 return LOWER;
932 }
933 if (g_unichar_isupper(c)) {
934 return UPPER;
935 }
936 if (g_unichar_isdigit(c)) {
937 return DIGIT;
938 }
939 return NON_WORD;
940}
941
950static int rofi_scorer_get_score_for(enum CharClass prev, enum CharClass curr) {
951 if (prev == NON_WORD && curr != NON_WORD) {
952 return WORD_START_SCORE;
953 }
954 if ((prev == LOWER && curr == UPPER) || (prev != DIGIT && curr == DIGIT)) {
955 return CAMEL_SCORE;
956 }
957 if (curr == NON_WORD) {
958 return NON_WORD_SCORE;
959 }
960 return 0;
961}
962
963int rofi_scorer_fuzzy_evaluate(const char *pattern, glong plen, const char *str,
964 glong slen, int case_sensitive) {
965 if (slen > FUZZY_SCORER_MAX_LENGTH) {
966 return -MIN_SCORE;
967 }
968 glong pi, si;
969 // whether we are aligning the first character of pattern
970 gboolean pfirst = TRUE;
971 // whether the start of a word in pattern
972 gboolean pstart = TRUE;
973 // score for each position
974 int *score = g_malloc_n(slen, sizeof(int));
975 // dp[i]: maximum value by aligning pattern[0..pi] to str[0..si]
976 int *dp = g_malloc_n(slen, sizeof(int));
977 // uleft: value of the upper left cell; ulefts: maximum value of uleft and
978 // cells on the left. The arbitrary initial values suppress warnings.
979 int uleft = 0, ulefts = 0, left, lefts;
980 const gchar *pit = pattern, *sit;
981 enum CharClass prev = NON_WORD;
982 for (si = 0, sit = str; si < slen; si++, sit = g_utf8_next_char(sit)) {
983 enum CharClass cur = rofi_scorer_get_character_class(g_utf8_get_char(sit));
984 score[si] = rofi_scorer_get_score_for(prev, cur);
985 prev = cur;
986 dp[si] = MIN_SCORE;
987 }
988 for (pi = 0; pi < plen; pi++, pit = g_utf8_next_char(pit)) {
989 gunichar pc = g_utf8_get_char(pit), sc;
990 if (g_unichar_isspace(pc)) {
991 pstart = TRUE;
992 continue;
993 }
994 lefts = MIN_SCORE;
995 for (si = 0, sit = str; si < slen; si++, sit = g_utf8_next_char(sit)) {
996 left = dp[si];
997 lefts = MAX(lefts + GAP_SCORE, left);
998 sc = g_utf8_get_char(sit);
999 if (case_sensitive ? pc == sc
1000 : g_unichar_tolower(pc) == g_unichar_tolower(sc)) {
1001 int t = score[si] * (pstart ? PATTERN_START_MULTIPLIER
1003 dp[si] = pfirst ? LEADING_GAP_SCORE * si + t
1004 : MAX(uleft + CONSECUTIVE_SCORE, ulefts + t);
1005 } else {
1006 dp[si] = MIN_SCORE;
1007 }
1008 uleft = left;
1009 ulefts = lefts;
1010 }
1011 pfirst = pstart = FALSE;
1012 }
1013 lefts = MIN_SCORE;
1014 for (si = 0; si < slen; si++) {
1015 lefts = MAX(lefts + GAP_SCORE, dp[si]);
1016 }
1017 g_free(score);
1018 g_free(dp);
1019 return -lefts;
1020}
1021
1033int utf8_strncmp(const char *a, const char *b, size_t n) {
1034 char *na = g_utf8_normalize(a, -1, G_NORMALIZE_ALL_COMPOSE);
1035 char *nb = g_utf8_normalize(b, -1, G_NORMALIZE_ALL_COMPOSE);
1036 *g_utf8_offset_to_pointer(na, n) = '\0';
1037 *g_utf8_offset_to_pointer(nb, n) = '\0';
1038 int r = g_utf8_collate(na, nb);
1039 g_free(na);
1040 g_free(nb);
1041 return r;
1042}
1043
1044gboolean helper_execute(const char *wd, char **args, const char *error_precmd,
1045 const char *error_cmd,
1046 RofiHelperExecuteContext *context) {
1047 gboolean retv = TRUE;
1048 GError *error = NULL;
1049
1050 GSpawnChildSetupFunc child_setup = NULL;
1051 gpointer user_data = NULL;
1052
1053 display_startup_notification(context, &child_setup, &user_data);
1054
1055 g_spawn_async(wd, args, NULL, G_SPAWN_SEARCH_PATH, child_setup, user_data,
1056 NULL, &error);
1057 if (error != NULL) {
1058 char *msg = g_strdup_printf("Failed to execute: '%s%s'\nError: '%s'",
1059 error_precmd, error_cmd, error->message);
1060 rofi_view_error_dialog(msg, FALSE);
1061 g_free(msg);
1062 // print error.
1063 g_error_free(error);
1064 retv = FALSE;
1065 }
1066
1067 // Free the args list.
1068 g_strfreev(args);
1069 return retv;
1070}
1071
1072gboolean helper_execute_command(const char *wd, const char *cmd,
1073 gboolean run_in_term,
1074 RofiHelperExecuteContext *context) {
1075 char **args = NULL;
1076 int argc = 0;
1077
1078 if (run_in_term) {
1079 helper_parse_setup(config.run_shell_command, &args, &argc, "{cmd}", cmd,
1080 (char *)0);
1081 } else {
1082 helper_parse_setup(config.run_command, &args, &argc, "{cmd}", cmd,
1083 (char *)0);
1084 }
1085
1086 if (args == NULL) {
1087 return FALSE;
1088 }
1089
1090 if (context != NULL) {
1091 if (context->name == NULL) {
1092 context->name = args[0];
1093 }
1094 if (context->binary == NULL) {
1095 context->binary = args[0];
1096 }
1097 if (context->description == NULL) {
1098 gsize l = strlen("Launching '' via rofi") + strlen(cmd) + 1;
1099 gchar *description = g_newa(gchar, l);
1100
1101 g_snprintf(description, l, "Launching '%s' via rofi", cmd);
1102 context->description = description;
1103 }
1104 if (context->command == NULL) {
1105 context->command = cmd;
1106 }
1107 }
1108
1109 return helper_execute(wd, args, "", cmd, context);
1110}
1111
1112static char *helper_get_theme_path_check_file(const char *filename,
1113 const char *parent_file) {
1114
1115 // Check if absolute path.
1116 if (g_path_is_absolute(filename)) {
1117 g_debug("Opening theme, path is absolute: %s", filename);
1118 if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
1119 return g_strdup(filename);
1120 }
1121 g_debug("Opening theme, path is absolute but does not exists: %s",
1122 filename);
1123 } else {
1124 if (parent_file != NULL) {
1125 // If no absolute path specified, expand it.
1126 char *basedir = g_path_get_dirname(parent_file);
1127 char *path = g_build_filename(basedir, filename, NULL);
1128 g_free(basedir);
1129 g_debug("Opening theme, check in dir where file is included: %s", path);
1130 if (g_file_test(path, G_FILE_TEST_EXISTS)) {
1131 return path;
1132 }
1133 g_debug("Opening theme, file does not exists in dir where file is "
1134 "included: %s\n",
1135 filename);
1136 }
1137 }
1138 // Check config's themes directory.
1139 const char *cpath = g_get_user_config_dir();
1140 if (cpath) {
1141 char *themep = g_build_filename(cpath, "rofi", "themes", filename, NULL);
1142 g_debug("Opening theme, testing: %s", themep);
1143 if (themep && g_file_test(themep, G_FILE_TEST_EXISTS)) {
1144 return themep;
1145 }
1146 g_free(themep);
1147 }
1148 // Check config directory.
1149 if (cpath) {
1150 char *themep = g_build_filename(cpath, "rofi", filename, NULL);
1151 g_debug("Opening theme, testing: %s", themep);
1152 if (g_file_test(themep, G_FILE_TEST_EXISTS)) {
1153 return themep;
1154 }
1155 g_free(themep);
1156 }
1157 const char *datadir = g_get_user_data_dir();
1158 if (datadir) {
1159 char *theme_path =
1160 g_build_filename(datadir, "rofi", "themes", filename, NULL);
1161 if (theme_path) {
1162 g_debug("Opening theme, testing: %s", theme_path);
1163 if (g_file_test(theme_path, G_FILE_TEST_EXISTS)) {
1164 return theme_path;
1165 }
1166 g_free(theme_path);
1167 }
1168 }
1169
1170 const gchar *const *system_data_dirs = g_get_system_data_dirs();
1171 if (system_data_dirs) {
1172 for (uint_fast32_t i = 0; system_data_dirs[i] != NULL; i++) {
1173 const char *const sdatadir = system_data_dirs[i];
1174 g_debug("Opening theme directory: %s", sdatadir);
1175 char *theme_path =
1176 g_build_filename(sdatadir, "rofi", "themes", filename, NULL);
1177 if (theme_path) {
1178 g_debug("Opening theme, testing: %s", theme_path);
1179 if (g_file_test(theme_path, G_FILE_TEST_EXISTS)) {
1180 return theme_path;
1181 }
1182 g_free(theme_path);
1183 }
1184 }
1185 }
1186
1187 char *theme_path = g_build_filename(THEME_DIR, filename, NULL);
1188 if (theme_path) {
1189 g_debug("Opening theme, testing: %s", theme_path);
1190 if (g_file_test(theme_path, G_FILE_TEST_EXISTS)) {
1191 return theme_path;
1192 }
1193 g_free(theme_path);
1194 }
1195 return NULL;
1196}
1197
1198char *helper_get_theme_path(const char *file, const char **ext,
1199 const char *parent_file) {
1200
1201 char *filename = rofi_expand_path(file);
1202 g_debug("Opening theme, testing: %s\n", filename);
1203 if (g_path_is_absolute(filename)) {
1204 g_debug("Opening theme, path is absolute: %s", filename);
1205 if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
1206 return filename;
1207 }
1208 }
1209 gboolean ext_found = FALSE;
1210 for (const char **i = ext; *i != NULL; i++) {
1211 if (g_str_has_suffix(file, *i)) {
1212 ext_found = TRUE;
1213 break;
1214 }
1215 }
1216 if (ext_found) {
1217 filename = rofi_expand_path(file);
1218
1219 char *retv = helper_get_theme_path_check_file(filename, parent_file);
1220 if (retv) {
1221 g_free(filename);
1222 return retv;
1223 }
1224 } else {
1225 g_assert_nonnull(ext[0]);
1226 // Iterate through extensions.
1227 char *temp = filename;
1228 for (const char **i = ext; *i != NULL; i++) {
1229 filename = g_strconcat(temp, *i, NULL);
1230 char *retv = helper_get_theme_path_check_file(filename, parent_file);
1231 if (retv) {
1232 g_free(filename);
1233 g_free(temp);
1234 return retv;
1235 }
1236 }
1237 g_free(temp);
1238 }
1239
1240 return filename;
1241}
1242
1243static gboolean parse_pair(char *input, rofi_range_pair *item) {
1244 // Skip leading blanks.
1245 while (input != NULL && isblank(*input)) {
1246 ++input;
1247 }
1248
1249 if (input == NULL) {
1250 return FALSE;
1251 }
1252
1253 const char *sep[] = {"-", ":"};
1254 int pythonic = (strchr(input, ':') || input[0] == '-') ? 1 : 0;
1255 int index = 0;
1256
1257 for (char *token = strsep(&input, sep[pythonic]); token != NULL;
1258 token = strsep(&input, sep[pythonic])) {
1259 if (index == 0) {
1260 item->start = item->stop = (int)strtol(token, NULL, 10);
1261 index++;
1262 continue;
1263 }
1264
1265 if (token[0] == '\0') {
1266 item->stop = -1;
1267 continue;
1268 }
1269
1270 item->stop = (int)strtol(token, NULL, 10);
1271 if (pythonic) {
1272 --item->stop;
1273 }
1274 }
1275 return TRUE;
1276}
1277void parse_ranges(char *input, rofi_range_pair **list, unsigned int *length) {
1278 char *endp;
1279 if (input == NULL) {
1280 return;
1281 }
1282 const char *const sep = ",";
1283 for (char *token = strtok_r(input, sep, &endp); token != NULL;
1284 token = strtok_r(NULL, sep, &endp)) {
1285 // Make space.
1286 *list =
1287 g_realloc((*list), ((*length) + 1) * sizeof(struct rofi_range_pair));
1288 // Parse a single pair.
1289 if (parse_pair(token, &((*list)[*length]))) {
1290 (*length)++;
1291 }
1292 }
1293}
1294
1295int parse_case_sensitivity(const char *input) {
1296 int case_sensitive = config.case_sensitive;
1297 if (config.case_smart) {
1298 // By default case is false, unless the search query has a
1299 // uppercase in it?
1300 case_sensitive = FALSE;
1301 const char *end;
1302 if (g_utf8_validate(input, -1, &end)) {
1303 for (const char *c = (input); !case_sensitive && c != NULL && *c;
1304 c = g_utf8_next_char(c)) {
1305 gunichar uc = g_utf8_get_char(c);
1306 if (g_unichar_isupper(uc)) {
1307 case_sensitive = TRUE;
1308 }
1309 }
1310 }
1311 }
1312
1313 return case_sensitive;
1314}
1315
1316void rofi_output_formatted_line(const char *format, const char *string,
1317 int selected_line, const char *filter) {
1318 for (int i = 0; format && format[i]; i++) {
1319 if (format[i] == 'i') {
1320 fprintf(stdout, "%d", selected_line);
1321 } else if (format[i] == 'd') {
1322 fprintf(stdout, "%d", (selected_line + 1));
1323 } else if (format[i] == 's') {
1324 fputs(string, stdout);
1325 } else if (format[i] == 'p') {
1326 char *esc = NULL;
1327 pango_parse_markup(string, -1, 0, NULL, &esc, NULL, NULL);
1328 if (esc) {
1329 fputs(esc, stdout);
1330 g_free(esc);
1331 } else {
1332 fputs("invalid string", stdout);
1333 }
1334 } else if (format[i] == 'q') {
1335 char *quote = g_shell_quote(string);
1336 fputs(quote, stdout);
1337 g_free(quote);
1338 } else if (format[i] == 'f') {
1339 if (filter) {
1340 fputs(filter, stdout);
1341 }
1342 } else if (format[i] == 'F') {
1343 if (filter) {
1344 char *quote = g_shell_quote(filter);
1345 fputs(quote, stdout);
1346 g_free(quote);
1347 }
1348 } else {
1349 fputc(format[i], stdout);
1350 }
1351 }
1352 fputc('\n', stdout);
1353 fflush(stdout);
1354}
1355
1356static gboolean helper_eval_cb2(const GMatchInfo *info, GString *res,
1357 gpointer data) {
1358 gchar *match;
1359 // Get the match
1360 int num_match = g_match_info_get_match_count(info);
1361 // Just {text} This is inside () 5.
1362 if (num_match == 5) {
1363 match = g_match_info_fetch(info, 4);
1364 if (match != NULL) {
1365 // Lookup the match, so we can replace it.
1366 gchar *r = g_hash_table_lookup((GHashTable *)data, match);
1367 if (r != NULL) {
1368 // Append the replacement to the string.
1369 g_string_append(res, r);
1370 }
1371 // Free match.
1372 g_free(match);
1373 }
1374 }
1375 // {} with [] guard around it.
1376 else if (num_match == 4) {
1377 match = g_match_info_fetch(info, 2);
1378 if (match != NULL) {
1379 // Lookup the match, so we can replace it.
1380 gchar *r = g_hash_table_lookup((GHashTable *)data, match);
1381 if (r != NULL) {
1382 // Add (optional) prefix
1383 gchar *prefix = g_match_info_fetch(info, 1);
1384 g_string_append(res, prefix);
1385 g_free(prefix);
1386 // Append the replacement to the string.
1387 g_string_append(res, r);
1388 // Add (optional) postfix
1389 gchar *post = g_match_info_fetch(info, 3);
1390 g_string_append(res, post);
1391 g_free(post);
1392 }
1393 // Free match.
1394 g_free(match);
1395 }
1396 }
1397 // Else we have an invalid match.
1398 // Continue replacement.
1399 return FALSE;
1400}
1401
1402char *helper_string_replace_if_exists(char *string, ...) {
1403 GHashTable *h;
1404 h = g_hash_table_new(g_str_hash, g_str_equal);
1405 va_list ap;
1406 va_start(ap, string);
1407 // Add list from variable arguments.
1408 while (1) {
1409 char *key = va_arg(ap, char *);
1410 if (key == (char *)0) {
1411 break;
1412 }
1413 char *value = va_arg(ap, char *);
1414 g_hash_table_insert(h, key, value);
1415 }
1416 char *retv = helper_string_replace_if_exists_v(string, h);
1417 va_end(ap);
1418 // Destroy key-value storage.
1419 g_hash_table_destroy(h);
1420 return retv;
1421}
1422
1437char *helper_string_replace_if_exists_v(char *string, GHashTable *h) {
1438 GError *error = NULL;
1439 char *res = NULL;
1440
1441 // Replace hits within {-\w+}.
1442 GRegex *reg = g_regex_new("\\[(.*)({[-\\w]+})(.*)\\]|({[\\w-]+})",
1443 G_REGEX_UNGREEDY, 0, &error);
1444 if (error == NULL) {
1445 res =
1446 g_regex_replace_eval(reg, string, -1, 0, 0, helper_eval_cb2, h, &error);
1447 }
1448 // Free regex.
1449 g_regex_unref(reg);
1450 // Throw error if shell parsing fails.
1451 if (error != NULL) {
1452 char *msg = g_strdup_printf("Failed to parse: '%s'\nError: '%s'", string,
1453 error->message);
1454 rofi_view_error_dialog(msg, FALSE);
1455 g_free(msg);
1456 // print error.
1457 g_error_free(error);
1458 g_free(res);
1459 return NULL;
1460 }
1461 return res;
1462}
int monitor_active(workarea *mon)
Definition display.c:18
void display_startup_notification(RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data)
Definition display.c:36
struct _workarea workarea
@ WL_CENTER
Definition rofi-types.h:235
@ MM_NORMAL
Definition settings.h:39
@ MM_REGEX
Definition settings.h:40
@ MM_PREFIX
Definition settings.h:43
@ MM_FUZZY
Definition settings.h:42
@ MM_NUM_MATCHERS
Definition settings.h:44
@ MM_GLOB
Definition settings.h:41
void helper_token_match_set_pango_attr_on_style(PangoAttrList *retv, int start, int end, RofiHighlightColorStyle th)
Definition helper.c:441
PangoAttrList * helper_token_match_get_pango_attr(RofiHighlightColorStyle th, rofi_int_matcher **tokens, const char *input, PangoAttrList *retv)
Definition helper.c:510
gboolean helper_validate_font(PangoFontDescription *pfd, const char *font)
Definition helper.c:652
char * rofi_latin_to_utf8_strdup(const char *input, gssize length)
Definition helper.c:851
void parse_ranges(char *input, rofi_range_pair **list, unsigned int *length)
Definition helper.c:1277
void cmd_set_arguments(int argc, char **argv)
Definition helper.c:97
rofi_int_matcher ** helper_tokenize(const char *input, int case_sensitive)
Definition helper.c:286
unsigned int levenshtein(const char *needle, const glong needlelen, const char *haystack, const glong haystacklen, int case_sensitive)
Definition helper.c:814
int find_arg_char(const char *const key, char *val)
Definition helper.c:431
gboolean helper_execute_command(const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context)
Definition helper.c:1072
void helper_select_next_matching_mode(void)
Definition helper.c:83
void helper_tokenize_free(rofi_int_matcher **tokens)
Definition helper.c:146
char helper_parse_char(const char *arg)
Definition helper.c:383
void rofi_output_formatted_line(const char *format, const char *string, int selected_line, const char *filter)
Definition helper.c:1316
const char * helper_get_matching_mode_str(void)
Definition helper.c:80
gboolean helper_execute(const char *wd, char **args, const char *error_precmd, const char *error_cmd, RofiHelperExecuteContext *context)
Definition helper.c:1044
char * helper_string_replace_if_exists(char *string,...)
Definition helper.c:1402
const char ** find_arg_strv(const char *const key)
Definition helper.c:344
int helper_parse_setup(char *string, char ***output, int *length,...)
Definition helper.c:102
int execute_generator(const char *cmd)
Definition helper.c:562
void helper_select_previous_matching_mode(void)
Definition helper.c:89
int find_arg_int(const char *const key, int *val)
Definition helper.c:364
char * rofi_expand_path(const char *input)
Definition helper.c:782
void remove_pid_file(int fd)
Definition helper.c:644
int find_arg_str(const char *const key, char **val)
Definition helper.c:334
int parse_case_sensitivity(const char *input)
Definition helper.c:1295
int rofi_scorer_fuzzy_evaluate(const char *pattern, glong plen, const char *str, glong slen, int case_sensitive)
Definition helper.c:963
int find_arg_uint(const char *const key, unsigned int *val)
Definition helper.c:373
int find_arg(const char *const key)
Definition helper.c:325
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
Definition helper.c:541
int create_pid_file(const char *pidfile, gboolean kill_running)
Definition helper.c:585
int config_sanity_check(void)
Definition helper.c:671
char * rofi_force_utf8(const gchar *data, ssize_t length)
Definition helper.c:857
void rofi_add_error_message(GString *str)
Definition rofi.c:93
int rofi_view_error_dialog(const char *msg, int markup)
Definition view.c:1915
#define CONSECUTIVE_SCORE
Definition helper.c:904
#define GAP_SCORE
Definition helper.c:896
#define LEADING_GAP_SCORE
Definition helper.c:894
static gchar * prefix_regex(const char *input)
Definition helper.c:198
static int MatchingMethodEnabled[MM_NUM_MATCHERS]
Definition helper.c:60
char ** stored_argv
Definition helper.c:76
static char * utf8_helper_simplify_string(const char *os)
Definition helper.c:205
#define MIN3(a, b, c)
Definition helper.c:811
#define CAMEL_SCORE
Definition helper.c:902
static gchar * glob_to_regex(const char *input)
Definition helper.c:154
const char *const monitor_position_entries[]
Definition helper.c:70
static enum CharClass rofi_scorer_get_character_class(gunichar c)
Definition helper.c:929
int utf8_strncmp(const char *a, const char *b, size_t n)
Definition helper.c:1033
#define MIN_SCORE
Definition helper.c:892
#define PATTERN_NON_START_MULTIPLIER
Definition helper.c:906
char * helper_string_replace_if_exists_v(char *string, GHashTable *h)
Definition helper.c:1437
static int NUMMatchingMethodEnabled
Definition helper.c:64
#define WORD_START_SCORE
Definition helper.c:898
static char * helper_get_theme_path_check_file(const char *filename, const char *parent_file)
Definition helper.c:1112
static int CurrentMatchingMethod
Definition helper.c:65
#define FUZZY_SCORER_MAX_LENGTH
Definition helper.c:890
static gboolean helper_eval_cb2(const GMatchInfo *info, GString *res, gpointer data)
Definition helper.c:1356
#define PATTERN_START_MULTIPLIER
Definition helper.c:908
char * helper_get_theme_path(const char *file, const char **ext, const char *parent_file)
Definition helper.c:1198
static rofi_int_matcher * create_regex(const char *input, int case_sensitive)
Definition helper.c:245
static GRegex * R(const char *s, int case_sensitive)
Definition helper.c:230
#define NON_WORD_SCORE
Definition helper.c:900
static gchar * fuzzy_to_regex(const char *input)
Definition helper.c:169
const char *const MatchingMethodStr[MM_NUM_MATCHERS]
Definition helper.c:57
CharClass
Definition helper.c:913
@ DIGIT
Definition helper.c:919
@ LOWER
Definition helper.c:915
@ NON_WORD
Definition helper.c:921
@ UPPER
Definition helper.c:917
int stored_argc
Definition helper.c:74
static gboolean parse_pair(char *input, rofi_range_pair *item)
Definition helper.c:1243
static int rofi_scorer_get_score_for(enum CharClass prev, enum CharClass curr)
Definition helper.c:950
struct rofi_int_matcher_t rofi_int_matcher
@ ROFI_HL_UPPERCASE
Definition rofi-types.h:64
@ ROFI_HL_STRIKETHROUGH
Definition rofi-types.h:58
@ ROFI_HL_ITALIC
Definition rofi-types.h:60
@ ROFI_HL_UNDERLINE
Definition rofi-types.h:56
@ ROFI_HL_CAPITALIZE
Definition rofi-types.h:68
@ ROFI_HL_BOLD
Definition rofi-types.h:54
@ ROFI_HL_LOWERCASE
Definition rofi-types.h:66
@ ROFI_HL_COLOR
Definition rofi-types.h:62
char * pidfile
Definition rofi.c:80
Settings config
@ DISPLAY_XCB
Definition settings.h:53
@ SORT_FZF
Definition settings.h:50
@ SORT_NORMAL
Definition settings.h:50
const gchar * binary
Definition helper.h:293
const gchar * description
Definition helper.h:295
const gchar * name
Definition helper.h:291
const gchar * command
Definition helper.h:303
RofiHighlightStyle style
Definition rofi-types.h:219
double blue
Definition rofi-types.h:162
double green
Definition rofi-types.h:160
double red
Definition rofi-types.h:158
double alpha
Definition rofi-types.h:164
MenuFlags flags
Definition view.c:72
unsigned long long count
Definition view.c:76
workarea mon
Definition view.c:117