hyprpolkitagent

repository·main·Indexed 42 days ago

https://github.com/hyprwm/hyprpolkitagent

A lightweight polkit authentication agent designed for Hyprland, built using C++ and the hyprtoolkit library. It provides a configurable authentication dialog with support for custom window dimensions and visual styling via hyprtoolkit.

Tokens
1.2K
Snippets
5
Records
7
Agent score
53%

What's inside hyprpolkitagent

  1. Theme hyprpolkitagent using hyprtoolkit

    main

    Visual styling for hyprpolkitagent (colors, corner rounding, font family, and font sizes) is managed by hyprtoolkit, not by the agent's own configuration.

    To change the theme, create or edit ~/.config/hypr/hyprtoolkit.conf (or $XDG_CONFIG_HOME/hypr/hyprtoolkit.conf). Unlike the agent's main configuration, changes to the hyprtoolkit config are applied immediately to the next dialog shown without requiring an agent restart.

  2. Configure hyprpolkitagent settings

    main

    hyprpolkitagent is configured via a hyprlang file located at ~/.config/hyprpolkitagent/hyprpolkitagent.conf (or $XDG_CONFIG_HOME/hyprpolkitagent/hyprpolkitagent.conf). The configuration file is optional; if it is missing or incomplete, the agent uses default values. To apply changes, you must restart the agent.

    Currently, only the general section is supported.

    general {
        password_field_width = 340
        window_width         = 520
        window_height        = 440
        show_details         = true
    }
  3. Configure hyprpolkitagent settings via SHPAConfig

    main

    The SHPAConfig structure defines the available configuration parameters for the agent. These settings control the visual dimensions of the authentication window and the behavior of the password input field.

    Available configuration keys:

    • passwordFieldWidth (int): The width of the password input field. Default is 340.
    • windowWidth (int): The width of the authentication window. Default is 520.
    • windowHeight (int): The height of the authentication window. Default is 440.
    • showDetails (bool): Whether to show additional details in the authentication dialog. Default is true.
    struct SHPAConfig {
        int  passwordFieldWidth = 340;
        int  windowWidth        = 520;
        int  windowHeight       = 440;
        bool showDetails        = true;
    };
  4. Reference the hyprpolkitagent configuration keys

    main

    The following keys are available within the general section of hyprpolkitagent.conf:

    • password_field_width: The width of the password input field in pixels.
    • window_width: The width of the authentication dialog in pixels.
    • window_height: The height of the authentication dialog in pixels.
    • show_details: A boolean determining whether the action and command panel can be toggled.
  5. Manage the authentication dialog with CDialog

    main

    The CDialog class provides the interface for displaying the authentication UI to the user. It is initialized with a polkit authentication request (CPolkitListener::SAuthRequest) and a Hyprtoolkit::IBackend pointer.

    Key lifecycle methods:

    • show(): Displays the dialog to the user.
    • close(): Closes the dialog.

    You can customize the content of the dialog using the following methods:

    • setPrompt(const std::string& text, bool echo): Sets the main prompt text (e.g., "Enter Password") and determines if the input should be echoed.
    • setInfo(const std::string& text): Sets informational text within the dialog.
    • setError(const std::string& text): Sets error message text to be displayed to the user.
    // Example initialization and usage
    CDialog dialog(auth_request, backend_ptr);
    
    dialog.setPrompt("Authentication Required", false);
    dialog.setInfo("Please enter your user password to continue.");
    
    dialog.show();
  6. Use CConfigManager to manage agent configuration

    main

    The CConfigManager class is responsible for loading and providing access to the agent's configuration.

    • load(): Loads the configuration from the stored file path.
    • get(): Returns a constant reference to the current SHPAConfig object.

    A global pointer g_pConfigManager is provided for easy access to the manager instance within the application.

    CConfigManager manager;
    manager.load();
    const SHPAConfig& cfg = manager.get();
    
    // Example access:
    int width = cfg.windowWidth;
    bool details = cfg.showDetails;
  7. Run the hyprpolkitagent application

    main

    The hyprpolkitagent application is the entrypoint for the Polkit authentication agent. It initializes a CAgent instance and starts the agent's main loop. The application returns exit code 0 on successful startup and 1 otherwise.

    # No direct CLI flags are exposed in the entrypoint; the application is executed as a standalone binary.
    # Execution: ./hyprpolkitagent