Skip to content
Myr

Merge branch 'dmenu-index'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Closes #88

authored by Daniel Eklöf · committed by Daniel Eklöf · parents 917c785, baf63b5 · Browse files · 10 files+92 added−50 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

10 files+92 added−50 removed

  • other:+92 added−50 removed

10 files+92 added−50 removed

modified:completions/zsh/_fuzzel+4 added-3 removed
22 unmodified lines
23 '(-S --selection-text-color)'{-S,--selection-text-color}'[text color of selected item (657b83ff)]:selection-text-color:()' \24 '(-B --border-width)'{-B,--border-width}'[width of border, in pixels (1)]:border-width:()' \25 '(-r --border-radius)'{-r,--border-radius}'[amount of corner "roundness" (10)]:border-radius:()' \26 '(-C --border-color)'{-C,--border-color}'[border color (002b36ff)]:border-color:()' \27 '(-d --dmenu)'{-d,--dmenu}'[dmenu compatibility mode; list entries are read from stdin]' \28 '(-R --no-run-if-empty)'{-R,--no-run-if-empty}'[exit immediately without showing the UI if stdin is empty (dmenu mode only)]' \27 '--show-actions[include desktop actions (e.g "New Window") in the list]' \28 '--no-fuzzy[disable fuzzy matching]' \29 '--fuzzy-min-length[search strings shorter than this will not be fuzzy matched (3)]:()' \30 '--fuzzy-max-length-discrepancy[maximum allowed length difference between the search string and a fuzzy match (2)]:()' \31 '--fuzzy-max-distance[maximum allowed levenshtein distance between the search string and a fuzzy match (1)]:()' \32 '--line-height[override line height from font metrics, in points or pixels]:()' \35 '--letter-spacing[additional letter spacing, in points or pixels]:()'33 '--letter-spacing[additional letter spacing, in points or pixels]:()' \34 '(-d --dmenu)'{-d,--dmenu}'[dmenu compatibility mode; list entries are read from stdin]' \35 "--index[print selected entry's index instead of its text (dmenu mode only)]" \36 '(-R --no-run-if-empty)'{-R,--no-run-if-empty}'[exit immediately without showing the UI if stdin is empty (dmenu mode only)]'3738case "${state}" in39 fonts)40 if command -v fc-list > /dev/null; then
18 unmodified lines
modified:doc/fuzzel.scd+14 added-10 removed
136 unmodified lines
137138*-C*,*--border-color*=_HEX_139 The color of the border. See *COLORS*. Default: _002b36ff_.140141*-d*,*--dmenu*142 dmenu compatibility mode. In this mode, the list entries are read143 from stdin (newline separated). The selected entry is printed to144 stdout. If the input string does not match any of the entries, the145 input string is printed as is on stdout.146147*-R*,*--no-run-if-empty*148 Exit immediately, without showing the UI, if stdin is149 empty. **dmenu** mode only.150141*--show-actions*142 Include desktop actions in the list. Desktop actions are143 alternative actions some desktop entries have. Examples include144 "New Window", "New Document", etc.
30 unmodified lines
175*--launch-prefix*=_COMMAND_176 Command to launch XDG applications with. Example: _swaymsg exec --_.177 Default: _not set_.178179*-d*,*--dmenu*180 dmenu compatibility mode. In this mode, the list entries are read181 from stdin (newline separated). The selected entry is printed to182 stdout. If the input string does not match any of the entries, the183 input string is printed as is on stdout.184185*--index*186 Print selected entry's index instead of its text. **dmenu** mode187 only.188189*-R*,*--no-run-if-empty*190 Exit immediately, without showing the UI, if stdin is191 empty. **dmenu** mode only.192193*-v*,*--version*194 Show the version number and quit195196# FONT FORMAT
31 unmodified lines
modified:CHANGELOG.md+3 added
26 unmodified lines
27* Fuzzy matching. This is enabled by default, but can be disabled with28 `--no-fuzzy`. When enabled, the fuzziness can be adjusted with29 `--fuzzy-max-length-discrepancy` and `--fuzzy-max-distance`30 (https://codeberg.org/dnkl/fuzzel/issues/56).31* `--index` (dmenu mode only): print selected entry’s index instead of32 its text (https://codeberg.org/dnkl/fuzzel/issues/88).333435### Changed3637* Fuzzel now refuses to start if there is another fuzzel instance38 running (https://codeberg.org/dnkl/fuzzel/issues/57).
261 unmodified lines
modified:dmenu.c+19 added-5 removed
61 unmodified lines
62 tll_free(entries);63}6465bool66dmenu_execute(const struct application *app, const struct prompt *prompt)66dmenu_execute(const struct application *app, ssize_t index,67 const struct prompt *prompt, enum dmenu_mode format)68{69 switch (format) {70 case DMENU_MODE_NONE:71 assert(false);72 return false;7374 case DMENU_MODE_TEXT:68 if (app != NULL)69 printf("%ls\n", app->title);70 else71 printf("%ls\n", prompt_text(prompt));75 if (app != NULL)76 printf("%ls\n", app->title);77 else78 printf("%ls\n", prompt_text(prompt));79 break;8081 case DMENU_MODE_INDEX:82 printf("%zd\n", index);83 break;84 }8586 return true;87}
modified:dmenu.h+6 added-1 removed
1#pragma once23#include <sys/types.h>45#include "application.h"6#include "prompt.h"78enum dmenu_mode { DMENU_MODE_NONE, DMENU_MODE_TEXT, DMENU_MODE_INDEX };910void dmenu_load_entries(struct application_list *applications);7bool dmenu_execute(const struct application *app, const struct prompt *prompt);11bool dmenu_execute(const struct application *app, ssize_t index,12 const struct prompt *prompt, enum dmenu_mode format);
modified:main.c+31 added-16 removed
223 unmodified lines
224 " -S,--selection-text-color=HEX text color of selected item (ffffffff)\n"225 " -B,--border-width=INT width of border, in pixels (1)\n"226 " -r,--border-radius=INT amount of corner \"roundness\" (10)\n"227 " -C,--border-color=HEX border color (ffffffff)\n"228 " -d,--dmenu dmenu compatibility mode\n"229 " -R,--no-run-if-empty exit immediately without showing UI if stdin\n"230 " is empty (dmenu mode only)\n"228 " --show-actions include desktop actions in the list\n"229 " --no-fuzzy disable fuzzy matching\n"230 " --fuzzy-min-length=VALUE search strings shorter than this will not be\n"231 " fuzzy matched (3)\n"
6 unmodified lines
238 " mean more fuzzy matches\n"239 " --line-height=HEIGHT override line height from font metrics\n"240 " --letter-spacing=AMOUNT additional letter spacing\n"241 " --launch-prefix=COMMAND prefix to add before argv of executed program\n"242 " -d,--dmenu dmenu compatibility mode\n"243 " --index print selected entry's index instead of of the \n"244 " entry's text (dmenu mode only)\n"245 " -R,--no-run-if-empty exit immediately without showing UI if stdin\n"246 " is empty (dmenu mode only)\n"247 " -v,--version show the version number and quit\n");248 printf("\n");249 printf("All colors are RGBA - i.e. 8-digit hex values, without prefix.\n");250}
209 unmodified lines
460 #define OPT_NO_FUZZY 259461 #define OPT_FUZZY_MIN_LENGTH 260462 #define OPT_FUZZY_MAX_LENGTH_DISCREPANCY 261463 #define OPT_FUZZY_MAX_DISTANCE 262464 #define OPT_DMENU_INDEX 263465466 static const struct option longopts[] = {467 {"output" , required_argument, 0, 'o'},468 {"font", required_argument, 0, 'f'},
15 unmodified lines
484 {"border-radius", required_argument, 0, 'r'},485 {"border-color", required_argument, 0, 'C'},486 {"prompt", required_argument, 0, 'P'},487 {"terminal", required_argument, 0, 'T'},485 {"dmenu", no_argument, 0, 'd'},486 {"no-run-if-empty", no_argument, 0, 'R'},488 {"show-actions", no_argument, 0, OPT_SHOW_ACTIONS},489 {"no-fuzzy", no_argument, 0, OPT_NO_FUZZY},490 {"fuzzy-min-length", required_argument, 0, OPT_FUZZY_MIN_LENGTH},491 {"fuzzy-max-length-discrepancy", required_argument, 0, OPT_FUZZY_MAX_LENGTH_DISCREPANCY},492 {"fuzzy-max-distance", required_argument, 0, OPT_FUZZY_MAX_DISTANCE},493 {"line-height", required_argument, 0, 'H'},494 {"letter-spacing", required_argument, 0, OPT_LETTER_SPACING},495 {"launch-prefix", required_argument, 0, OPT_LAUNCH_PREFIX},496497 /* dmenu mode */498 {"dmenu", no_argument, 0, 'd'},499 {"no-run-if-empty", no_argument, 0, 'R'},500 {"index", no_argument, 0, OPT_DMENU_INDEX},501502 /* Misc */503 {"version", no_argument, 0, 'v'},504 {"help", no_argument, 0, 'h'},505 {NULL, no_argument, 0, 0},506 };
4 unmodified lines
511 const char *icon_theme = "hicolor";512 const char *terminal = NULL;513 const wchar_t *prompt_content = L"> ";514 wchar_t *prompt_allocated = NULL;507 bool dmenu_mode = false;508 bool no_run_if_empty = false;515 bool icons_enabled = true;516 bool actions_enabled = false;517 bool fuzzy = true;518 size_t fuzzy_min_length = 3;519 size_t fuzzy_max_length_discrepancy = 2;520 size_t fuzzy_max_distance = 1;521 const char *launch_prefix = NULL;522523 bool dmenu_mode = false;524 enum dmenu_mode dmenu_format = DMENU_MODE_TEXT;525 bool no_run_if_empty = false;526527 enum match_fields match_fields =528 MATCH_FILENAME | MATCH_NAME | MATCH_GENERIC;529530 struct render_options render_options = {
235 unmodified lines
766 render_options.border_color = hex_to_rgba(border_color);767 break;768 }769760 case 'd':761 dmenu_mode = true;762 break;763764 case 'R':765 no_run_if_empty = true;766 break;767770 case OPT_SHOW_ACTIONS:771 actions_enabled = true;772 break;773
47 unmodified lines
821 launch_prefix = optarg;822 break;823 }824825 case 'd':826 dmenu_mode = true;827 break;828829 case 'R':830 no_run_if_empty = true;831 break;832833 case OPT_DMENU_INDEX:834 dmenu_format = DMENU_MODE_INDEX;835 break;836837 case 'v':838 printf("fuzzel version %s\n", FUZZEL_VERSION);839 return EXIT_SUCCESS;840
97 unmodified lines
938 };939940 if ((wayl = wayl_init(941 fdm, render, prompt, matches, &render_options,942 dmenu_mode ? dmenu_format : DMENU_MODE_NONE,928 dmenu_mode, launch_prefix, output_name, font_name, dpi_aware,943 launch_prefix, output_name, font_name, dpi_aware,944 &font_reloaded, &ctx)) == NULL)945 goto out;946947 ctx.wayl = wayl;
82 unmodified lines
modified:match.c+2 added
413 unmodified lines
414 matches->matches[i] = (struct match){415 .matched_type = MATCHED_NONE,416 .application = &matches->applications->v[i],417 .start_title = -1,418 .index = i,419 };420 }421422 /* Sort */
128 unmodified lines
551 matches->matches[matches->match_count++] = (struct match){552 .matched_type = matched_type,553 .application = app,554 .start_title = start_title,555 .index = i,556 };557 }558559 LOG_DBG("match update done");
11 unmodified lines
modified:match.h+1 added
14 unmodified lines
15struct match {16 enum matched_type matched_type;17 struct application *application;18 ssize_t start_title;19 size_t index;20};2122enum match_fields {23 MATCH_FILENAME = 0x01,
37 unmodified lines
modified:wayland.c+7 added-6 removed
167 unmodified lines
168 bool font_is_sized_by_dpi;169170 enum { KEEP_RUNNING, EXIT_UPDATE_CACHE, EXIT} status;171 int exit_code;172 bool dmenu_mode;172 enum dmenu_mode dmenu_mode;173 const char *launch_prefix;174175 bool frame_is_scheduled;176 struct buffer *pending;
264 unmodified lines
441 wayl->status = EXIT;442443 const struct match *match = matches_get_match(wayl->matches);444 struct application *app = match != NULL ? match->application : NULL;445 ssize_t index = match != NULL ? match->index : -1;446446 if (wayl->dmenu_mode) {447 dmenu_execute(app, wayl->prompt);447 if (wayl->dmenu_mode != DMENU_MODE_NONE) {448 dmenu_execute(app, index, wayl->prompt, wayl->dmenu_mode);449 wayl->exit_code = EXIT_SUCCESS;450 } else {451 bool success = application_execute(app, wayl->prompt, wayl->launch_prefix);452 wayl->exit_code = success ? EXIT_SUCCESS : EXIT_FAILURE;
1188 unmodified lines
16411642struct wayland *1643wayl_init(struct fdm *fdm,1644 struct render *render, struct prompt *prompt, struct matches *matches,1644 const struct render_options *render_options, bool dmenu_mode, const char *launch_prefix,1645 const char *output_name, const char *font_spec,1646 enum dpi_aware dpi_aware,1645 const struct render_options *render_options, enum dmenu_mode dmenu_mode,1646 const char *launch_prefix, const char *output_name,1647 const char *font_spec, enum dpi_aware dpi_aware,1648 font_reloaded_t font_reloaded_cb, void *data)1649{1650 struct wayland *wayl = malloc(sizeof(*wayl));1651 *wayl = (struct wayland){
206 unmodified lines
modified:wayland.h+5 added-9 removed
1#pragma once23#include <fcft/fcft.h>45#include "dmenu.h"6#include "fdm.h"67#include "prompt.h"7#include "match.h"8#include "prompt.h"9#include "render.h"1011/* TODO? */12#include "application.h"13#include "icon.h"1411struct wayland;1213typedef void (*font_reloaded_t)(14 struct wayland *wayl, struct fcft_font *font, void *data);
2 unmodified lines
1718struct wayland *wayl_init(19 struct fdm *fdm,20 struct render *render, struct prompt *prompt, struct matches *matches,25 const struct render_options *render_options, bool dmenu_mode, const char *launch_prefix,26 const char *output_name, const char *font_spec, enum dpi_aware dpi_aware,27 font_reloaded_t font_reloaded_cb, void *data);21 const struct render_options *render_options, enum dmenu_mode dmenu_mode,22 const char *launch_prefix, const char *output_name, const char *font_spec,23 enum dpi_aware dpi_aware, font_reloaded_t font_reloaded_cb, void *data);2425void wayl_destroy(struct wayland *wayl);2627void wayl_refresh(struct wayland *wayl);
6 unmodified lines