Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Desktop Entry Discovery

Daemon-launcher discovers launchable applications by scanning XDG desktop entry files, builds a fuzzy search index, and ranks results using frecency (frequency + recency).

XDG Desktop Entry Scanning

The scanner in daemon-launcher/src/scanner.rs uses the freedesktop-desktop-entry crate to enumerate .desktop files from $XDG_DATA_DIRS/applications/. Scanning is synchronous and runs in a tokio::task::spawn_blocking context at daemon startup.

Filtering Rules

Entries are filtered before indexing:

ConditionAction
Hidden=trueSkipped. The entry is deleted, per the Desktop Entry Specification.
No Exec= fieldSkipped. Not a launchable application.
NoDisplay=trueCached for launching by ID, not indexed for search: a desktop’s default application may be one.
Duplicate IDOnly the first occurrence (highest precedence) is kept.

Indexed Fields

For each surviving entry, the scanner produces a MatchItem with:

  • id: the desktop entry ID (e.g., org.mozilla.firefox).
  • name: the localized Name= field, falling back to the entry ID.
  • extra: a space-joined string of Keywords= and Categories= values, used to broaden fuzzy match surface.

The Exec line, StartupWMClass, and Terminal flag are cached separately in a CachedEntry for post-scan use during launch execution and default-application resolution. The cache is stored as a HashMap<String, CachedEntry> keyed by entry ID.

Default Applications

LaunchDefaultApps asks daemon-launcher which application each desktop role (AppRole: web browser, files, mail, music, video, photos, calendar, terminal, text editor, app store, settings, system monitor) resolves to; daemon-wm asks when an activation starts (Snapshot). daemon-launcher/src/default_apps.rs answers from the files as they are at each request.

The [Default Applications] groups of the XDG MIME Applications Associations specification’s mimeapps.list files (Layout::mimeapps_lists) are read, highest precedence first:

  1. $XDG_CONFIG_HOME/<desktop>-mimeapps.list, then $XDG_CONFIG_HOME/mimeapps.list
  2. the same in each $XDG_CONFIG_DIRS directory (default /etc/xdg)
  3. the same in $XDG_DATA_HOME/applications
  4. the same in each $XDG_DATA_DIRS directory’s applications

<desktop> is each $XDG_CURRENT_DESKTOP name, lowercased, most specific first (unity is gnome). The first file naming an eligible entry for any of the role’s MIME types decides the role; within a file the role’s MIME types are taken in order (the types COSMIC Settings’ Default Applications page writes: x-scheme-handler/http for the web browser, inode/directory for files, x-scheme-handler/terminal for the terminal, text/plain for the text editor), and within a type its listed entries in order. An entry is eligible when it is cached (installed, not Hidden, with Exec) and not Terminal=true: such an entry’s windows belong to the terminal it runs in. When no file decides, the desktop’s shipped application is the last resort (on COSMIC: Files, Player, Viewer, Terminal, Edit, Store, Settings, and Monitor).

A resolved application’s window app IDs are its entry ID and, when different, its StartupWMClass. A role with no eligible application is absent from the answer.

Daemon-launcher uses the nucleo fuzzy matching library (via the core-fuzzy crate). Items are injected into the matcher at startup via an Injector. Queries arrive as LaunchQuery IPC messages and are dispatched to SearchEngine::query(), which combines fuzzy match scores with frecency boosts.

Query results are returned as LaunchResult values containing the entry ID, display name, icon, and composite score.

Frecency Ranking

Launch frequency and recency are tracked in a per-profile SQLite database managed by core-fuzzy::FrecencyDb. The database file is stored at:

~/.config/pds/launcher/{profile_name}.frecency.db

Each trust profile has its own frecency database, providing isolation between profiles. When a LaunchQuery specifies a different profile than the current one, the search engine switches its frecency context via engine.switch_profile().

When a LaunchExecute succeeds, engine.record_launch(entry_id) updates the frecency database. The frecency boost is refreshed periodically via engine.refresh_frecency().

Desktop Entry Field Code Stripping

Before executing an Exec line, the scanner strips freedesktop %-prefixed field codes. These are placeholder tokens defined by the Desktop Entry Specification that would normally be replaced by a file manager:

Stripped codes: %f, %F, %u, %U, %d, %D, %n, %N, %i, %c, %k, %v, %m.

The literal %% sequence is collapsed to a single %.

After stripping, multiple consecutive spaces from removed codes are collapsed. The result is then tokenized using freedesktop quoting rules (double-quote escaping for \", \`, \\, \$). The tokenizer does not invoke a shell.

3-Strategy Resolution Fallback

When a LaunchExecute request arrives, the entry ID is resolved against the cached entries using three strategies in order:

  1. Exact match: the entry ID matches a cache key exactly (e.g., org.mozilla.firefox).
  2. Last segment match: the entry ID matches the last dot-separated segment of a cached ID, case-insensitively (e.g., firefox matches org.mozilla.firefox).
  3. Case-insensitive full ID match: the entry ID matches a cached ID when both are lowercased (e.g., alacritty matches Alacritty).

If none of the three strategies produces a match, LaunchDenial::EntryNotFound is returned.