### Build and install bemenu from source Source: https://context7.com/cloudef/bemenu/llms.txt Use GNU Make to compile specific backends and install the utility on your system. ```bash # Install dependencies (Ubuntu/Debian) sudo apt install scdoc wayland-protocols libcairo-dev libpango1.0-dev \ libxkbcommon-dev libwayland-dev libncursesw5-dev libx11-dev libxinerama-dev # Build everything make # Build specific backends only make clients wayland # Only wayland backend make clients x11 # Only X11 backend make clients curses # Only curses backend # Install (default prefix: /usr/local) sudo make install # Install with custom prefix sudo make install PREFIX=/usr # Custom library directory sudo make install PREFIX=/usr libdir=/lib/x86_64-linux-gnu # Generate API documentation (requires doxygen) make doxygen # Test from source directory LD_LIBRARY_PATH=. BEMENU_RENDERERS=. ./bemenu-run # Nix installation nix-env -i -f default.nix # macOS with Homebrew brew install make pkg-config PKG_CONFIG_PATH="/usr/local/opt/ncurses/lib/pkgconfig" sh build-osx.sh curses ``` -------------------------------- ### Install bemenu via Nix Source: https://github.com/cloudef/bemenu/blob/master/README.md Command to install the curses backend using the provided default.nix file. ```sh nix-env -i -f default.nix ``` -------------------------------- ### Build and Test bemenu Source: https://github.com/cloudef/bemenu/blob/master/README.md Commands to compile the project, install binaries, and run the application from the source directory. ```sh # Build everything make # To build only certain features, pass the targets which you are interested into # # You can also use the following meta-targets for common features: # - clients (bemenu, bemenu-run) # - x11 # - wayland # - curses # # For example this would build the bemenu and bemenu-run binaries and the x11 backend: make clients x11 # To install the built features, simply run: make install # NOTE: You may get errors during install when not building all the features. # These errors are free to ignore if `Install OK!` is printed. # By default that will install to /usr/local, but you can change this with PREFIX make install PREFIX=/usr # Other usual variables are available for modifying such as DESTDIR, bindir, libdir and mandir # Note that if you want a custom PREFIX or libdir, you should pass those during build as well, # since they will be used compile-time to figure out where to load backends from! # HTML API documentation (requires doxygen installed): make doxygen # To test from source, you have to point the LD_LIBRARY_PATH and BEMENU_RENDERERS variables: LD_LIBRARY_PATH=. BEMENU_RENDERERS=. ./bemenu-run ``` -------------------------------- ### Install Dependencies on Ubuntu Source: https://github.com/cloudef/bemenu/blob/master/README.md Command to install required development libraries for building bemenu on Ubuntu 20.04. ```sh sudo apt install scdoc wayland-protocols libcairo-dev libpango1.0-dev libxkbcommon-dev libwayland-dev ``` -------------------------------- ### Build bemenu on OSX Source: https://github.com/cloudef/bemenu/blob/master/README.md Steps to install build tools and compile the project using the provided build script. ```sh # Make sure you have GNU Make and pkg-config installed brew install make pkg-config # You may need to setup your pkg-config to point to the brew version of the libraries # For example to build curses backend, you'd do: PKG_CONFIG_PATH="/usr/local/opt/ncurses/lib/pkgconfig" sh build-osx.sh curses # Other than that, follow the normal build steps, but use `build-osx.sh` instead of make ``` -------------------------------- ### Configure Doxyfile for Qmi Theme Source: https://github.com/cloudef/bemenu/blob/master/doxygen/doxygen-qmi-style/README.md Modify your Doxyfile to include Qmi theme settings. Ensure the paths to HTML_HEADER, HTML_FOOTER, and HTML_STYLESHEET are correct for your setup. ```doxygen BRIEF_MEMBER_DESC = NO ``` ```doxygen HTML_HEADER = ${path_to_qmi}/header.html ``` ```doxygen HTML_FOOTER = ${path_to_qmi}/footer.html ``` ```doxygen HTML_STYLESHEET = ${path_to_qmi}/qmi.css ``` -------------------------------- ### Create and Configure Menu Instances Source: https://context7.com/cloudef/bemenu/llms.txt Demonstrates creating a menu instance and applying various configuration settings for appearance, behavior, and colors. ```c #include #include int main(void) { if (!bm_init()) return EXIT_FAILURE; // Create menu with auto-detected renderer (respects BEMENU_BACKEND env var) struct bm_menu *menu = bm_menu_new(NULL); if (!menu) { fprintf(stderr, "Failed to create menu\n"); return EXIT_FAILURE; } // Configure basic properties bm_menu_set_title(menu, "Select an option:"); bm_menu_set_font(menu, "Monospace 12"); bm_menu_set_lines(menu, 10); // Show 10 vertical lines bm_menu_set_wrap(menu, true); // Wrap around when reaching end // Configure filter behavior bm_menu_set_filter_mode(menu, BM_FILTER_MODE_DMENU_CASE_INSENSITIVE); bm_menu_set_prefix(menu, "> "); // Prefix for highlighted item // Configure appearance bm_menu_set_scrollbar(menu, BM_SCROLLBAR_AUTOHIDE); bm_menu_set_align(menu, BM_ALIGN_CENTER); // Center on screen bm_menu_set_line_height(menu, 24); bm_menu_set_border_size(menu, 2); bm_menu_set_border_radius(menu, 8); // Set colors (hex format with alpha: #RRGGBBAA or #RRGGBB) bm_menu_set_color(menu, BM_COLOR_TITLE_BG, "#1a1a2e"); bm_menu_set_color(menu, BM_COLOR_TITLE_FG, "#eaeaea"); bm_menu_set_color(menu, BM_COLOR_HIGHLIGHTED_BG, "#4a4e69"); bm_menu_set_color(menu, BM_COLOR_HIGHLIGHTED_FG, "#ffffff"); bm_menu_set_color(menu, BM_COLOR_ITEM_BG, "#16161e"); bm_menu_set_color(menu, BM_COLOR_ITEM_FG, "#a9b1d6"); bm_menu_set_color(menu, BM_COLOR_BORDER, "#7aa2f7"); // Configure display settings bm_menu_set_monitor(menu, -1); // -1 for active monitor, -2 for all bm_menu_set_width(menu, 100, 0.5); // 100px margin, 50% width factor // Enable password mode for sensitive input // bm_menu_set_password(menu, BM_PASSWORD_INDICATOR); // Shows asterisks // Enable vim keybindings // bm_menu_set_key_binding(menu, BM_KEY_BINDING_VIM); // Use the menu... bm_menu_free(menu); return EXIT_SUCCESS; } ``` -------------------------------- ### Initialize bemenu and Query Renderers Source: https://context7.com/cloudef/bemenu/llms.txt Initializes the library and lists available rendering backends. bm_init() must be called before any other library functions. ```c #include #include #include int main(void) { // Initialize the bemenu library - must be called first if (!bm_init()) { fprintf(stderr, "Failed to initialize bemenu\n"); return EXIT_FAILURE; } // Get library version printf("bemenu version: %s\n", bm_version()); // List available renderers uint32_t renderer_count; const struct bm_renderer **renderers = bm_get_renderers(&renderer_count); for (uint32_t i = 0; i < renderer_count; i++) { printf("Renderer: %s (priority: %s)\n", bm_renderer_get_name(renderers[i]), bm_renderer_get_priorty(renderers[i]) == BM_PRIO_GUI ? "GUI" : "Terminal"); } return EXIT_SUCCESS; } ``` -------------------------------- ### Integrate bemenu with i3 window manager Source: https://context7.com/cloudef/bemenu/llms.txt Add this line to your i3 configuration file to launch bemenu with a keybinding. ```bash bindsym $mod+d exec --no-startup-id bemenu-run ``` -------------------------------- ### Implement a Menu Event Loop in C Source: https://context7.com/cloudef/bemenu/llms.txt Shows how to render the menu, poll for keyboard input, and process run results to handle user selection or cancellation. ```c #include #include #include int main(void) { if (!bm_init()) return EXIT_FAILURE; struct bm_menu *menu = bm_menu_new(NULL); if (!menu) return EXIT_FAILURE; bm_menu_set_title(menu, "Select:"); bm_menu_set_lines(menu, 5); // Add some items const char *options[] = {"Option 1", "Option 2", "Option 3", "Option 4"}; for (int i = 0; i < 4; i++) { struct bm_item *item = bm_item_new(options[i]); bm_menu_add_item(menu, item); } // Grab keyboard focus bm_menu_grab_keyboard(menu, true); // Main event loop uint32_t unicode; enum bm_key key; enum bm_run_result status = BM_RUN_RESULT_RUNNING; while (status == BM_RUN_RESULT_RUNNING) { // Render the menu if (!bm_menu_render(menu)) { status = BM_RUN_RESULT_CANCEL; break; } // Poll for keyboard input key = bm_menu_poll_key(menu, &unicode); // Process the input and advance menu logic status = bm_menu_run_with_key(menu, key, unicode); } // Handle the result switch (status) { case BM_RUN_RESULT_SELECTED: { uint32_t count; struct bm_item **selected = bm_menu_get_selected_items(menu, &count); for (uint32_t i = 0; i < count; i++) { printf("Selected: %s\n", bm_item_get_text(selected[i])); } break; } case BM_RUN_RESULT_CANCEL: printf("Selection cancelled\n"); break; case BM_RUN_RESULT_CUSTOM_1: case BM_RUN_RESULT_CUSTOM_2: // ... handle custom exit codes (Alt+1 through Alt+0) default: break; } bm_menu_free(menu); return (status == BM_RUN_RESULT_SELECTED) ? EXIT_SUCCESS : EXIT_FAILURE; } ``` -------------------------------- ### Manage Menu Items and Userdata in C Source: https://context7.com/cloudef/bemenu/llms.txt Demonstrates creating menu items, attaching custom application data, inserting items at specific indices, and filtering the menu list. ```c #include #include #include // Custom data structure to attach to menu items struct app_data { int id; const char *command; }; int main(void) { if (!bm_init()) return EXIT_FAILURE; struct bm_menu *menu = bm_menu_new(NULL); if (!menu) return EXIT_FAILURE; bm_menu_set_title(menu, "Applications"); // Create and add items with userdata const char *apps[] = {"Firefox", "Terminal", "File Manager", "Text Editor"}; const char *cmds[] = {"firefox", "alacritty", "nautilus", "gedit"}; for (int i = 0; i < 4; i++) { struct bm_item *item = bm_item_new(apps[i]); if (!item) continue; // Attach custom data to the item struct app_data *data = malloc(sizeof(struct app_data)); data->id = i; data->command = cmds[i]; bm_item_set_userdata(item, data); bm_menu_add_item(menu, item); } // Add item at specific index struct bm_item *priority_item = bm_item_new("Priority App"); bm_menu_add_item_at(menu, priority_item, 0); // Insert at beginning // Get all items uint32_t item_count; struct bm_item **items = bm_menu_get_items(menu, &item_count); printf("Total items: %u\n", item_count); // Highlight specific item bm_menu_set_highlighted_index(menu, 2); // Get highlighted item struct bm_item *highlighted = bm_menu_get_highlighted_item(menu); if (highlighted) { printf("Highlighted: %s\n", bm_item_get_text(highlighted)); } // Set initial filter text bm_menu_set_filter(menu, "Fire"); bm_menu_filter(menu); // Apply the filter // Get filtered items uint32_t filtered_count; struct bm_item **filtered = bm_menu_get_filtered_items(menu, &filtered_count); printf("Filtered items: %u\n", filtered_count); // Remove an item bm_menu_remove_item_at(menu, 0); // Clean up - free items and their userdata items = bm_menu_get_items(menu, &item_count); for (uint32_t i = 0; i < item_count; i++) { void *userdata = bm_item_get_userdata(items[i]); free(userdata); } bm_menu_free(menu); // Also frees all items return EXIT_SUCCESS; } // Output: // Total items: 5 // Highlighted: Terminal // Filtered items: 1 ``` -------------------------------- ### Implement Menu with Pointer and Touch Support in C Source: https://context7.com/cloudef/bemenu/llms.txt Use bm_menu_run_with_events to process keyboard, pointer, and touch input simultaneously. Requires initializing the menu and polling input types within the render loop. ```c #include #include #include int main(void) { if (!bm_init()) return EXIT_FAILURE; struct bm_menu *menu = bm_menu_new(NULL); if (!menu) return EXIT_FAILURE; // Configure menu bm_menu_set_title(menu, "Application Launcher"); bm_menu_set_lines(menu, 8); bm_menu_set_scrollbar(menu, BM_SCROLLBAR_AUTOHIDE); bm_menu_set_counter(menu, true); // Show matched/total counter // Add items const char *apps[] = { "Firefox Web Browser", "Chromium", "Terminal Emulator", "File Manager", "Text Editor", "System Settings", "Music Player", "Video Player", "Image Viewer" }; for (size_t i = 0; i < sizeof(apps)/sizeof(apps[0]); i++) { bm_menu_add_item(menu, bm_item_new(apps[i])); } bm_menu_grab_keyboard(menu, true); // Event loop with full input support uint32_t unicode; enum bm_key key = BM_KEY_NONE; struct bm_pointer pointer = {0}; struct bm_touch touch = {0}; enum bm_run_result status = BM_RUN_RESULT_RUNNING; while (status == BM_RUN_RESULT_RUNNING) { if (!bm_menu_render(menu)) { status = BM_RUN_RESULT_CANCEL; break; } // Poll all input types key = bm_menu_poll_key(menu, &unicode); pointer = bm_menu_poll_pointer(menu); touch = bm_menu_poll_touch(menu); // Process all events together status = bm_menu_run_with_events(menu, key, pointer, touch, unicode); } if (status == BM_RUN_RESULT_SELECTED) { struct bm_item *item = bm_menu_get_highlighted_item(menu); if (item) { printf("%s\n", bm_item_get_text(item)); } } bm_menu_free(menu); return EXIT_SUCCESS; } ``` -------------------------------- ### Configure bemenu via environment variables Source: https://context7.com/cloudef/bemenu/llms.txt Set these variables to define system-wide defaults for backends, renderers, and visual styles. ```bash # Force a specific backend export BEMENU_BACKEND=wayland # Options: wayland, x11, curses # Load a specific renderer shared object export BEMENU_RENDERER=/usr/lib/bemenu/bemenu-renderer-wayland.so # Override backend search path export BEMENU_RENDERERS=/custom/path/to/renderers # Set default command-line options export BEMENU_OPTS="-i -l 10 -p '>' --fn 'Hack 11' --tb '#1d1f21' --tf '#c5c8c6'" # Override rendering scale factor (for HiDPI) export BEMENU_SCALE=2.0 # Example shell script using environment configuration #!/bin/bash export BEMENU_BACKEND=wayland export BEMENU_OPTS="-c -l 8 -W 0.5 --scrollbar autohide" # All bemenu calls will now use these settings selected=$(echo -e "Edit\nView\nDelete" | bemenu -p "Action:") echo "Selected: $selected" ``` -------------------------------- ### Execute bemenu-run Application Launcher Source: https://context7.com/cloudef/bemenu/llms.txt Use bemenu-run to list and execute applications from the system PATH. Provides various configuration flags for styling and behavior. ```bash # Basic application launcher bemenu-run # Launch at bottom of screen with custom prompt bemenu-run -b -p "Run:" # Centered launcher with styling bemenu-run -c -l 12 -W 0.4 \ --fn "Ubuntu Mono 13" \ --tb "#2e3440" --tf "#eceff4" \ --hb "#5e81ac" --hf "#ffffff" \ --nb "#3b4252" --nf "#d8dee9" # Don't execute, just print the selection bemenu-run --no-exec # Output: firefox (prints instead of executing) # Fork before executing (default for GUI backends) bemenu-run --fork # Case-insensitive with vim bindings bemenu-run -i --binding vim # Specific monitor in multi-monitor setup bemenu-run -m 0 # First monitor bemenu-run -m focused # Active monitor (default) bemenu-run -m all # All monitors # With border and rounded corners bemenu-run -B 3 -R 10 --bdr "#7aa2f7" # Wayland-specific: no overlap with panels bemenu-run -n # Integration with sway window manager (in config) # bindsym $mod+d exec bemenu-run -p "Run:" -i -l 10 ``` -------------------------------- ### Bemenu Script for Database Selection Source: https://github.com/cloudef/bemenu/wiki/How-I-am-using-bemenu-with-[ID]-at-line-ends A comprehensive bash script that utilizes bemenu for interactive selection from PostgreSQL database entries. It configures bemenu based on the terminal environment and provides functions for selecting accounts and hyperdocuments. ```bash #!/bin/bash # Because Bemenu is installed by using Guix, I have to remove $LD_LIBRARY_PATH unset LD_LIBRARY_PATH export BEMENU_BACKEND=curses fuzzy_program="bemenu -i" if test $TERM = "dumb" && test $DISPLAY; then BEMENU_BACKEND=x11; # BEMENU_SCALE=1.4; fuzzy_program='bemenu -i -b -l 10 -nb yellow -nb black --fn "DejaVu Mono 20"' fi # rcd_sql() { psql -AXtqc "$1" } string_cut_id() { sed -n 's/\(.*\)\[\(.*\)\]$/\2/p' } fuzzy_id() { $fuzzy_program | string_cut_id } rcd_accounts_list() { rcd_sql "SELECT accounts_name || ' [' || accounts_id || ']' FROM accounts ORDER BY accounts_name" } rcd_account() { id=$(rcd_accounts_list | fuzzy_id) echo $id } hyperdocument_affiliate_list() { rcd_sql "SELECT hlinks_name || ' [' || hlinks_id || ']' FROM hlinks WHERE hlinks_parent = 35720" } hyperdocument_affiliate() { id=$(hyperdocument_affiliate_list | fuzzy_id) rcd_sql "SELECT hlinks_name || ' ' || hlinks_link FROM hlinks WHERE hlinks_id = `echo -n $id`" } hyperdocument_set_list() { rcd_sql "SELECT hlinks_name || ' [' || hlinks_id || ']' FROM hlinks WHERE hlinks_hlinktypes = 5 ORDER BY hlinks_name" } hyperdocument_set() { id=$(hyperdocument_set_list | fuzzy_id) echo $id } arg=$1 case $arg in 'account') rcd_account ;; 'set') hyperdocument_set ;; 'affiliate' ) hyperdocument_affiliate ;; *) echo "No recognized parameter" exit 0 ;; esac ``` -------------------------------- ### Execute bemenu Command-Line Operations Source: https://context7.com/cloudef/bemenu/llms.txt Interact with the bemenu executable to process stdin and output selections to stdout. Supports various styling, filtering, and input modes. ```bash # Basic usage - select from a list echo -e "Option 1\nOption 2\nOption 3" | bemenu # Output: Option 2 (if user selects it) # Custom prompt and case-insensitive matching echo -e "Firefox\nChromium\nTerminal" | bemenu -p "Open:" -i # Output: firefox (if typed "fire" and selected) # Vertical list with 10 lines, bottom of screen ls /usr/bin | bemenu -l 10 -b # Centered menu with custom dimensions echo -e "Yes\nNo\nCancel" | bemenu -c -W 0.3 -M 50 # Custom colors and font echo -e "Dark\nLight" | bemenu \ --fn "JetBrains Mono 14" \ --tb "#1a1a2e" --tf "#ffffff" \ --hb "#4a4e69" --hf "#ffffff" \ --nb "#16161e" --nf "#a9b1d6" # Password input mode (shows asterisks) bemenu -x indicator -p "Password:" # Vim keybindings echo -e "item1\nitem2\nitem3" | bemenu --binding vim # With scrollbar and item counter find ~/Documents -type f -name "*.pdf" | bemenu -l 15 --scrollbar autohide --counter always # Pre-filter items before display echo -e "apple\nbanana\norange\ngrape" | bemenu -F "an" # Shows menu pre-filtered to items matching "an" # Return if only one match, with initial filter echo -e "unique_item\nother" | bemenu --accept-single -F "unique" # Output: unique_item (returned immediately without showing menu) # Custom exit codes with Alt+1 through Alt+0 echo -e "Edit\nDelete\nCancel" | bemenu -p "Action:" # Exit code 10-19 if Alt+1 through Alt+0 pressed # Use environment variable for persistent options export BEMENU_OPTS="-i -l 10 --fn 'Monospace 12' --tb '#282a36'" echo -e "item1\nitem2" | bemenu ``` -------------------------------- ### Define UI colors for bemenu Source: https://context7.com/cloudef/bemenu/llms.txt Reference the C API color elements or apply themes via command-line flags. ```c // Available color elements in the library API enum bm_color { BM_COLOR_TITLE_BG, // --tb Title/prompt background BM_COLOR_TITLE_FG, // --tf Title/prompt foreground BM_COLOR_FILTER_BG, // --fb Filter input background BM_COLOR_FILTER_FG, // --ff Filter input foreground BM_COLOR_CURSOR_BG, // --cb Text cursor background BM_COLOR_CURSOR_FG, // --cf Text cursor foreground BM_COLOR_ITEM_BG, // --nb Normal item background BM_COLOR_ITEM_FG, // --nf Normal item foreground BM_COLOR_HIGHLIGHTED_BG, // --hb Highlighted item background BM_COLOR_HIGHLIGHTED_FG, // --hf Highlighted item foreground BM_COLOR_FEEDBACK_BG, // --fbb Feedback background BM_COLOR_FEEDBACK_FG, // --fbf Feedback foreground BM_COLOR_SELECTED_BG, // --sb Selected item background BM_COLOR_SELECTED_FG, // --sf Selected item foreground BM_COLOR_ALTERNATE_BG, // --ab Alternating row background BM_COLOR_ALTERNATE_FG, // --af Alternating row foreground BM_COLOR_SCROLLBAR_BG, // --scb Scrollbar background BM_COLOR_SCROLLBAR_FG, // --scf Scrollbar foreground BM_COLOR_BORDER, // --bdr Border color }; // Example: Nord theme via command line // bemenu --tb "#2e3440" --tf "#88c0d0" --fb "#2e3440" --ff "#d8dee9" \ // --nb "#2e3440" --nf "#d8dee9" --hb "#4c566a" --hf "#eceff4" \ // --sb "#5e81ac" --sf "#eceff4" --scb "#3b4252" --scf "#81a1c1" ``` -------------------------------- ### Extract ID from String using sed Source: https://github.com/cloudef/bemenu/wiki/How-I-am-using-bemenu-with-[ID]-at-line-ends This function uses sed to extract an ID enclosed in square brackets from the end of a line. It's useful for parsing output where items are formatted like 'Item Name [ID]'. ```bash string_cut_id() { sed -n 's/\(.*\)\[\(.*\)\]$/\2/p' } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.