{"id":13533293,"url":"https://github.com/philj56/tofi","last_synced_at":"2025-05-14T22:07:50.654Z","repository":{"id":38614278,"uuid":"425324233","full_name":"philj56/tofi","owner":"philj56","description":"Tiny dynamic menu for Wayland","archived":false,"fork":false,"pushed_at":"2024-12-30T15:19:27.000Z","size":940,"stargazers_count":1058,"open_issues_count":100,"forks_count":48,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T18:44:39.179Z","etag":null,"topics":["application-launcher","c","dmenu","dmenu-replacement","linux","sway","swaywm","wayland","wlroots"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/philj56.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-06T18:56:26.000Z","updated_at":"2025-04-13T17:56:51.000Z","dependencies_parsed_at":"2024-06-21T04:58:29.564Z","dependency_job_id":"65ece792-8c4b-45e4-b692-0ec75f15f812","html_url":"https://github.com/philj56/tofi","commit_stats":{"total_commits":240,"total_committers":10,"mean_commits":24.0,"dds":0.04166666666666663,"last_synced_commit":"574eff0df1aff9bdc6d32939a03312cc08803de3"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philj56%2Ftofi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philj56%2Ftofi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philj56%2Ftofi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philj56%2Ftofi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/philj56","download_url":"https://codeload.github.com/philj56/tofi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235696,"owners_count":22036963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["application-launcher","c","dmenu","dmenu-replacement","linux","sway","swaywm","wayland","wlroots"],"created_at":"2024-08-01T07:01:18.434Z","updated_at":"2025-05-14T22:07:45.621Z","avatar_url":"https://github.com/philj56.png","language":"C","funding_links":[],"categories":["Tools","Application Launcher","Launchers","C"],"sub_categories":["Runners, Menus, and Application Launchers","Utilities"],"readme":"# Tofi\n\nAn extremely fast and simple [dmenu](https://tools.suckless.org/dmenu/) /\n[rofi](https://github.com/davatorium/rofi) replacement for\n[wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)-based\n[Wayland](https://wayland.freedesktop.org/) compositors such as\n[Sway](https://github.com/swaywm/sway/).\n\nThe aim is to do just what I want it to as quick as possible.\n\nWhen [configured correctly](#performance), tofi can get on screen within a\nsingle frame.\n\n![](screenshot_fullscreen.png)\n\n## Table of Contents\n* [Install](#install)\n  * [Building](#building)\n  * [Arch](#arch)\n* [Usage](#usage)\n  * [Theming](#theming)\n* [Performance](#performance)\n  * [Options](#options)\n  * [Benchmarks](#benchmarks)\n  * [Where is the time spent?](#where-is-the-time-spent)\n\n## Install\n### Building\n\nInstall the necessary dependencies.\n\n#### For Arch:\n```sh\n# Runtime dependencies\nsudo pacman -S freetype2 harfbuzz cairo pango wayland libxkbcommon\n\n# Build-time dependencies\nsudo pacman -S meson scdoc wayland-protocols\n```\n\n#### For Fedora\n```sh\n# Runtime dependencies\nsudo dnf install freetype-devel cairo-devel pango-devel wayland-devel libxkbcommon-devel harfbuzz\n\n# Build-time dependencies\nsudo dnf install meson scdoc wayland-protocols-devel\n```\n\n#### For Debian/Ubuntu\n\n```sh\n# Runtime dependencies\nsudo apt install libfreetype-dev libcairo2-dev libpango1.0-dev libwayland-dev libxkbcommon-dev libharfbuzz-dev\n\n# Build-time dependencies\nsudo apt install meson scdoc wayland-protocols\n```\n\nThen build:\n```sh\nmeson build \u0026\u0026 ninja -C build install\n```\n\n### Arch\nTofi is available in the [AUR](https://aur.archlinux.org/packages/tofi):\n```sh\nparu -S tofi\n```\n\n## Usage\n\nBy default, running `tofi` causes it to act like dmenu, accepting options on\n`stdin` and printing the selection to `stdout`.\n\n`tofi-run` is a symlink to `tofi`, which will cause tofi to display a list of\nexecutables under the user's `$PATH`.\n\n`tofi-drun` is also a symlink to `tofi`, which will cause tofi to display a\nlist of applications found in desktop files as described by the [Desktop Entry\nSpecification](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html).\n\nTo use as a launcher for Sway, add something similar to the following to your\nSway config file:\n```\nset $menu tofi-run | xargs swaymsg exec --\nbindsym $mod+d exec $menu\n```\n\nFor `tofi-drun`, there are two possible methods:\n```\n# Launch via Sway\nset $drun tofi-drun | xargs swaymsg exec --\nbindsym $mod+Shift+d exec $drun\n\n# Launch directly\nset $drun tofi-drun --drun-launch=true\nbindsym $mod+Shift+d exec $drun\n```\n\nSee the main [manpage](doc/tofi.1.md) for more info.\n\n### Theming\n\nTofi supports a fair number of theming options - see the default [config\nfile](doc/config) or the config file [manpage](doc/tofi.5.md) for a complete\ndescription. Theming is based on the box model shown below:\n\n![Default theme screenshot](screenshot_default.png)\n\nThis consists of a box with a border, border outlines and optionally rounded\ncorners. Text inside the box can either be laid out vertically:\n```\n╔═══════════════════╗\n║ prompt   input    ║\n║          result 1 ║\n║          result 2 ║\n║          ...      ║\n╚═══════════════════╝\n```\nor horizontally:\n```\n╔═══════════════════════════════════════════╗\n║ prompt   input    result 1  result 2  ... ║\n╚═══════════════════════════════════════════╝\n```\nEach piece of text can have its colour customised, and be surrounded by a box\nwith optionally rounded corners,\n\nA few example themes are included and shown below. Note that you may need to\ntweak them to look correct on your display.\n\n[`themes/fullscreen`](themes/fullscreen)\n![Fullscreen theme screenshot](screenshot_fullscreen.png)\n\n[`themes/dmenu`](themes/dmenu)\n![dmenu theme screenshot](screenshot_dmenu.png)\n\n[`themes/dos`](themes/dos)\n![DOS theme screenshot](screenshot_dos.png)\n\n[`themes/dark-paper`](themes/dark-paper)\n![Dark paper theme screenshot](screenshot_dark_paper.png)\n\n[`themes/soy-milk`](themes/soy-milk)\n![Soy milk theme screenshot](screenshot_soy_milk.png)\n\n## Performance\n\nBy default, tofi isn't really any faster than its alternatives. However, when\nconfigured correctly, it can startup and get on screen within a single frame,\nor about 2ms in the ideal case.\n\n### Options\nIn roughly descending order, the most important options for performance are:\n\n* `--font` - This is *by far* the most important option. By default, tofi uses\n  [Pango](https://pango.gnome.org/) for font rendering, which (on Linux) looks\n  up fonts via\n  [Fontconfig](https://www.freedesktop.org/wiki/Software/fontconfig/).\n  Unfortunately, this font lookup is about as slow as wading through treacle\n  (relatively speaking). On battery power on my laptop (Arch linux, AMD Ryzen 5\n  5600U), with ~10000 fonts as the output of `fc-list`, loading a single font\n  with Pango \u0026 Fontconfig takes ~120ms.\n\n  The solution is to pass a path to a font file to `--font`, e.g. `--font\n  /usr/share/fonts/noto/NotoSansMono-Regular.ttf`. Tofi will then skip any font\n  searching, and use [Harfbuzz](https://harfbuzz.github.io/) and\n  [Cairo](https://www.cairographics.org/) directly to load the font and display\n  text. This massively speeds up startup (font loading takes \u003c1ms). The (minor\n  for me) downside is that any character not in the specified font won't render\n  correctly, but unless you have commands (or items) with CJK characters or\n  emojis in their names, that shouldn't be an issue.\n  \n* `--width`, `--height` - Larger windows take longer to draw (mostly just for\n  the first frame). Again, on battery power on my laptop, drawing a fullscreen\n  window (2880px × 1800px) takes ~20ms on the first frame, whereas a dmenu-like\n  ribbon (2880px × 60px) takes ~1ms.\n  \n* `--num-results` - By default, tofi auto-detects how many results will fit in\n  the window. This is quite tricky when `--horizontal=true` is passed, and\n  leads to a few ms slowdown (only in this case). Setting a fixed number of\n  results will speed this up, but since this likely only applies to dmenu-like\n  themes (which are already very quick) it's probably not worth setting this.\n\n* `--*-background` - Drawing background boxes around text effectively requires\n  drawing the text twice, so specifying a lot of these options can lead to a\n  couple of ms slowdown.\n\n* `--hint-font` - Getting really into it now, one of the remaining slow points\n  is hinting fonts. For the dmenu theme on battery power on my laptop, with a\n  specific font file chosen, the initial text render with the default font\n  hinting takes ~4-6ms. Specifying `--hint-font false` drops this to ~1ms. For\n  hidpi screens or large font sizes, this doesn't noticeably impact font\n  sharpness, but your mileage may vary. This option has no effect if a path to\n  a font file hasn't been passed to `--font`.\n\n* `--ascii-input` - Proper Unicode handling is slower than plain ASCII - on the\n  order of a few ms for ~40 kB of input. Specifying `--ascii-input true` will\n  disable some of this handling, speeding up tofi's startup, but searching for\n  non-ASCII characters may not work properly.\n\n* `--late-keyboard-init` - The last avoidable thing that slows down startup is\n  initialisation of the keyboard. This only takes 1-2ms on my laptop, but up\n  to 60ms on a Raspberry Pi Zero 2 W. Passing this option will delay keyboard\n  initialisation until after the first draw to screen, meaning that *keypresses\n  will be missed* until then, so it's disabled by default.\n\n### Benchmarks\n\nBelow are some rough benchmarks of the included themes on different machines.\nThese were generated with version 0.1.0 of tofi. The time shown is measured\nfrom program launch to Sway reporting that the window has entered the screen.\nResults are the mean and standard deviation of 10 runs. All tests were\nperformed with `--font /path/to/font/file.ttf`, `--hint-font false` and the\nequivalent of `--ascii-input true` (as tofi 0.1.0 didn't support Unicode text).\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth colspan=2 rowspan=2/\u003e\n      \u003cth colspan=3\u003e Theme \u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e fullscreen \u003c/th\u003e\n      \u003cth\u003e dmenu \u003c/th\u003e\n      \u003cth\u003e dos \u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003cth rowspan=4\u003e Machine \u003c/th\u003e\n      \u003cth\u003e Ryzen 7 3700X \u003cbr\u003e 2560px × 1440px \u003c/th\u003e\n      \u003ctd align=right\u003e 9.5ms ± 1.8ms \u003c/td\u003e\n      \u003ctd align=right\u003e 5.2ms ± 1.5ms \u003c/td\u003e\n      \u003ctd align=right\u003e 6.1ms ± 1.3ms \u003c/td\u003e    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e Ryzen 5 5600U (AC) \u003cbr\u003e 2880px × 1800px \u003c/th\u003e\n      \u003ctd align=right\u003e 17.1ms ± 1.4ms \u003c/td\u003e\n      \u003ctd align=right\u003e 4.0ms ± 0.5ms \u003c/td\u003e\n      \u003ctd align=right\u003e 6.7ms ± 1.1ms \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e Ryzen 5 5600U (battery) \u003cbr\u003e 2880px × 1800px \u003c/th\u003e\n      \u003ctd align=right\u003e 28.1ms ± 3.7ms \u003c/td\u003e\n      \u003ctd align=right\u003e 6.0ms ± 1.6ms \u003c/td\u003e\n      \u003ctd align=right\u003e 12.3ms ± 3.4ms \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e Raspberry Pi Zero 2 W \u003cbr\u003e 1920px × 1080px \u003c/th\u003e\n      \u003ctd align=right\u003e 119.0ms ± 5.9ms \u003c/td\u003e\n      \u003ctd align=right\u003e 67.3ms ± 10.2ms \u003c/td\u003e\n      \u003ctd align=right\u003e 110.0ms ± 10.3ms \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\nThe table below additionally includes `--late-keyboard-init` in the arguments.\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth colspan=2 rowspan=2/\u003e\n      \u003cth colspan=3\u003e Theme \u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e fullscreen \u003c/th\u003e\n      \u003cth\u003e dmenu \u003c/th\u003e\n      \u003cth\u003e dos \u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003cth rowspan=4\u003e Machine \u003c/th\u003e\n      \u003cth\u003e Ryzen 7 3700X \u003cbr\u003e 2560px × 1440px \u003c/th\u003e\n      \u003ctd align=right\u003e 7.9ms ± 1.0ms \u003c/td\u003e\n      \u003ctd align=right\u003e 2.3ms ± 0.8ms \u003c/td\u003e\n      \u003ctd align=right\u003e 3.8ms ± 0.8ms \u003c/td\u003e    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e Ryzen 5 5600U (AC) \u003cbr\u003e 2880px × 1800px \u003c/th\u003e\n      \u003ctd align=right\u003e 13.4ms ± 0.8ms \u003c/td\u003e\n      \u003ctd align=right\u003e 2.6ms ± 0.5ms \u003c/td\u003e\n      \u003ctd align=right\u003e 5.5ms ± 0.51ms \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e Ryzen 5 5600U (battery) \u003cbr\u003e 2880px × 1800px \u003c/th\u003e\n      \u003ctd align=right\u003e 21.8ms ± 1.8ms \u003c/td\u003e\n      \u003ctd align=right\u003e 3.6ms ± 0.7ms \u003c/td\u003e\n      \u003ctd align=right\u003e 8.1ms ± 0.7ms \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e Raspberry Pi Zero 2 W \u003cbr\u003e 1920px × 1080px \u003c/th\u003e\n      \u003ctd align=right\u003e 98.3ms ± 5.7ms \u003c/td\u003e\n      \u003ctd align=right\u003e 44.8ms ± 16.3ms \u003c/td\u003e\n      \u003ctd align=right\u003e 87.4ms ± 9.9ms \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n#### Bonus Round: Transparent HugePages\n\nIt turns out that it's possible to speed up fullscreen windows somewhat with\nsome advanced memory tweaks. See [this Stack Overflow\nquestion](https://stackoverflow.com/questions/73278608/can-mmaps-performance-be-improved-for-shared-memory)\nif you want full details, but basically by setting\n`/sys/kernel/mm/transparent_hugepage/shmem_enabled` to `advise`, we can tell\nthe kernel we're going to be working with large memory areas. This results in\nfewer page faults when first allocating memory, speeding up tofi.\n\nNote that I don't recommend you play with this unless you know what you're\ndoing (I don't), but I've included it just in case, and to show that the\nslowdown on large screens is partially due to factors beyond tofi's control.\n\nThe table below shows the effects of additionally enabling hugepages from the\ntable above. The dmenu theme has been skipped, as the window it creates is too\nsmall to benefit from them. The Raspberry Pi is also omitted, as it doesn't\nsupport hugepages.\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth colspan=2 rowspan=2/\u003e\n      \u003cth colspan=2\u003e Theme \u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e fullscreen \u003c/th\u003e\n      \u003cth\u003e dos \u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003cth rowspan=3\u003e Machine \u003c/th\u003e\n      \u003cth\u003e Ryzen 7 3700X \u003cbr\u003e 2560px × 1440px \u003c/th\u003e\n      \u003ctd align=right\u003e 6.9ms ± 1.1ms \u003c/td\u003e\n      \u003ctd align=right\u003e 3.2ms ± 0.4ms \u003c/td\u003e    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e Ryzen 5 5600U (AC) \u003cbr\u003e 2880px × 1800px \u003c/th\u003e\n      \u003ctd align=right\u003e 7.9ms ± 1.2ms \u003c/td\u003e\n      \u003ctd align=right\u003e 3.4ms ± 1.0ms \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e Ryzen 5 5600U (battery) \u003cbr\u003e 2880px × 1800px \u003c/th\u003e\n      \u003ctd align=right\u003e 13.7ms ± 0.9ms \u003c/td\u003e\n      \u003ctd align=right\u003e 5.6ms ± 0.8ms \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n### Where is the time spent?\n\nFor those who are interested in how much time there is even left to save, I've\nplotted the startup performance of version 0.8.0 of `tofi-run` below, alongside\nthe corresponding debug output. This is the data from 1000 runs of the dmenu\ntheme on a Ryzen 7 3700X machine, with all performance options set as mentioned\nabove, along with `--num-results 10`. I've highlighted some points of interest,\nmost of which are out of tofi's control.\n\n[![Startup performance plot](startup_performance.svg)](https://raw.githubusercontent.com/philj56/tofi/master/startup_performance.svg)\n\n(You may want to click the image to see it at full size).\n\nNote that this is slightly faster than shown in previous benchmarks (with some\nruns under 1.5ms!), due to some string handling improvements made in version\n0.8.0. Also note that the real performance is slightly better still, as the\nperformance logging used slows down the code by roughly 10%.\n\nAs you can see, there's not a huge amount of time that could even theoretically\nbe saved. Somewhere around 50% of the startup time is simply spent waiting, and\nmost of the code isn't parallelisable, as many steps depend on the result of\nprevious steps. One idea would be to daemonize tofi, skipping much of this\nstartup. I don't want to do this, however, for two main reasons: complexity,\nand I think it's probably about fast enough already!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilj56%2Ftofi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphilj56%2Ftofi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilj56%2Ftofi/lists"}