Rofi Window Switcher and Application Launcher

repository·next·Indexed 12 days ago

https://github.com/davatorium/rofi

A highly extensible window switcher, application launcher, and dmenu replacement for Linux and BSD. Rofi features advanced filtering (fuzzy, regex, glob), robust Wayland and X11 support, and a powerful theming engine using the .rasi format. It includes built-in modes such as run, drun, window, ssh, and combi, and supports custom script modes and plugins.

Tokens
95K
Snippets
326
Records
463
Agent score
80%

What's inside Rofi

  1. Overview of Rofi

    next
    Rofi is a versatile window switcher, application launcher, and dmenu replacement. It provides a textual list of options that a user can select from, such as running an application, selecting a window, or choosing options provided by an external script. It is highly configurable, supports UTF-8, and features advanced theming and extensible modes via scripts and plugins.
  2. Access Rofi documentation and manpages

    next

    Rofi documentation is organized into two main tracks: Development (current/bleeding edge) and Stable (version-specific).

    • Use the Development links to access the latest manpages, theme specifications, and feature guides (such as Dmenu, Script mode, and Debugging).
    • Use the Stable links to access documentation specifically for the current stable release (e.g., version 2.0.0).

    Key documentation areas include:

    • Manpages: Detailed command-line interface and mode references.
    • Themes: Specifications for rofi-theme.5 and rofi-dmenu.5.
    • Guides: Specialized topics like Transparency, Positioning, Plugins, and Dynamic Themes.
  3. How Rofi script mode works (API and Lifecycle)

    next

    Rofi script mode operates via a simple request-response loop using an executable.

    Execution Flow

    • Initial Call: Rofi executes the script with no arguments. The script's standard output becomes the list of selectable entries.
    • User Action: When an entry is selected, Rofi re-runs the script, providing the selected text as the first command-line argument.

    Environment Variables

    Rofi provides context to your script via these variables:

    • ROFI_RETV: An integer representing the current state:
      • 0: Initial call.
      • 1: An entry was selected.
      • 2: A custom entry was selected.
      • 10-28: Custom keybindings 1-19 (must be explicitly enabled via script options).
    • ROFI_INFO: Contains the value of the info row option if a user selects an entry with that property set.
    • ROFI_DATA: Contains data passed from the script to its next execution via the data mode option.

    Example Script

    This script provides two options: 'reload' and 'quit'. Selecting 'quit' exits the script.

    #!/usr/bin/env bash
    
    if [ x"$@" = x"quit" ]
    then
        exit 0
    fi
    echo "reload"
    echo "quit"
  4. Handle icons in themes

    next

    Rofi supports three methods for specifying icons:

    1. Filename: A direct path to an image file.
    2. icon-name: A name looked up via the system's icon-theme (uses GdkPixbuf).
    3. Markup String: A string rendered as an icon using Pango. This requires a <span tag to define color and font.

    Markup String Example:

    To use a markup string, the string must start with a <span tag. For example, to render a red power icon via dmenu:

    echo -en "testing\0icon\x1f<span color='red'>⏻</span>" | ./rofi -dmenu
  5. Handle icons via filenames, names, or markup

    next

    Rofi supports three methods for specifying icons:

    1. Filename: A direct path to an image file.
    2. icon-name: A name looked up via the system icon theme.
    3. Markup String: A string rendered as an icon using Pango. This requires a <span tag to define color and font.

    For filenames and icon-names, GdkPixbuf is used for rendering.

    # Example of using a markup string as an icon in dmenu mode
    echo -en "testing\0icon\x1f<span color='red'>⏻</span>" | ./rofi -dmenu
  6. Understand the rofi layout model and hierarchy

    next

    The rofi window is structured as a hierarchy of boxes that pack other boxes or widgets. Boxes can be oriented either vertical or horizontal.

    Default Hierarchy

    The default layout follows this structure:

    • window {BOX:vertical}
      • mainbox {BOX:vertical}
        • inputbar {BOX:horizontal}
          • prompt
          • entry
          • case-indicator (ci)
          • num-filtered-rows (fr)
          • num-rows (ns)
        • message
          • textbox
        • listview
          • element
            • element-icon
            • element-text
        • mode-switcher {BOX:horizontal}
          • Button (multiple)

    Fixed Widgets

    The following widgets are considered 'fixed' and provide core functionality:

    • prompt
    • entry
    • overlay
    • case-indicator
    • message
    • listview
    • mode-switcher
    • num-rows
    • num-filtered-rows
  7. Configure mouse button identifiers in rofi

    next

    When binding mouse actions, you can use specific button identifiers. The identifier format is Mouse<D><Button>, where D is an optional indicator for a double press.

    Available Buttons

    • Primary: Primary (Left) mouse button
    • Secondary: Secondary (Right) mouse button
    • Middle: Middle mouse button
    • Forward: Forward mouse button
    • Back: Back mouse button
    • ExtraN: The N-th mouse button (hardware dependent)

    Double Click Example

    To represent a double click on the primary button, use MouseDPrimary.

    Example usage in configuration:

    configuration {
      me-accept-entry: "MouseDPrimary";
    }
  8. How Rofi theme loading and overriding works

    next

    Rofi always loads a default theme. To use a different theme, add an @theme statement to your config.rasi file.

    Overriding Mechanism: If you use @theme "name", you can override any property of that theme by defining the same widget section later in your config.rasi file. Multiple properties for the same widget can be grouped using commas (e.g., entry, element-text { ... }).

    To inspect the default theme without your local config, run: rofi -no-config -dump-theme

    rofi -no-config -dump-theme
  9. Understand the rofi layout model and box structure

    next

    The rofi window layout is built using a hierarchical structure of boxes that pack other boxes or widgets. Boxes can be oriented either vertical or horizontal (similar to GTK).

    Core Hierarchy

    By default, the layout follows this structure:

    • window (vertical box)
      • mainbox (vertical box)
        • inputbar (horizontal box)
          • prompt, entry, case-indicator, overlay, num-filtered-rows, num-rows
        • message (contains a textbox)
        • listview (contains element widgets)
        • mode-switcher (horizontal box containing button widgets)

    Fixed Widgets

    The following widgets are considered 'fixed' and provide core functionality:

    • prompt
    • entry
    • overlay
    • case-indicator
    • message
    • listview
    • mode-switcher
    • num-rows
    • num-filtered-rows
    /* Default packing keywords */
    mainbox Packs: `inputbar, message, listview, mode-switcher`
    inputbar Packs: `prompt,entry,case-indicator`"
  10. Available rofi modes and their behaviors

    next

    Rofi operates in several distinct modes, each serving a different purpose:

    • window: Lists all windows for switching. shift-delete closes a window; control-enter or shift-enter runs a command on the window (configured via window-command).
    • windowcd: Similar to window but only shows windows on the current desktop. shift-delete kills the window.
    • run: Lists executables in $PATH. shift-delete removes an entry from history; control-enter runs the command; shift-enter runs it in a terminal. Control-l opens File Browser mode.
    • drun: Launches applications based on installed .desktop files (XDG specification). shift-delete removes history; control-enter runs the command; shift-enter runs in a terminal. Control-l opens File Browser mode.
    • ssh: Lists SSH targets from your ssh config.
    • keys: Shows a searchable list of keybindings.
    • script: Allows for custom scripted modes.
    • combi: Combines multiple modes into one list. Use -combi-modes to specify which modes to include. You can filter results using a ! bang prefix (e.g., !w to filter for modes starting with 'w').
  11. Use @media queries for conditional theme loading

    next

    Rofi themes support @media blocks to conditionally load CSS rules based on constraints like window dimensions, aspect ratio, or environment. Constraints can use integers or fractions (e.g., 120px).

    Supported keys:

    • min-width / max-width: Width constraints.
    • min-height / max-height: Height constraints.
    • min-aspect-ratio / max-aspect-ratio: Aspect ratio constraints.
    • monitor-id: The monitor ID (check rofi -help for IDs).
    • enabled: Boolean option. Supports environment variables or the DMENU keyword to detect if running in dmenu mode.
    /* Load when width is at least 120px */
    @media ( min-width: 120 px ) {
    }
    
    /* Load based on environment variable */
    @media ( enabled: env(DO_LIGHT, false )) {
    }
    
    /* Load only when in dmenu mode */
    @media ( enabled: DMENU) {
    }
  12. Understand how transparency layers work in rofi

    next

    Rofi builds its window by drawing the background first, then layering each widget on top with its own transparency factor. Because transparency is applied cumulatively (one layer on top of another), setting a transparency value on every widget will result in a much less transparent final appearance than expected.

    To achieve a clean transparent look, use this pattern:

    1. Set all elements (*) to be fully transparent.
    2. Set the background color specifically on the window element.
    3. Only set background colors on specific widgets where you want distinct coloring.
    /* 1. Make everything transparent by default */
    * {
        background: transparent;
    }
    
    /* 2. Set the base background on the window */
    window {
        background: #cc1c1c1c;
    }
    
    /* 3. Only color specific widgets as needed */