lillinput

Crates.iolillinput
lib.rslillinput
version0.3.0
sourcesrc
created_at2021-08-01 13:46:46.120946
updated_at2022-11-04 17:57:26.628744
descriptionLibrary for connecting libinput gestures to i3 and others
homepage
repositoryhttps://github.com/diego-plan9/lillinput/
max_upload_size
id430013
size51,450
Diego M. Rodríguez (diego-plan9)

documentation

README

lillinput

crates.io

lillinput logo

The lillinput library provides the building blocks for connecting libinput events with different actions.

Building blocks

Traits and implementations

The following traits are the main building blocks of the library:

Trait Description Implementations
action::Action Handler for a specific action, that is triggered by an application event actions::I3Action, actions::CommandAction
events::Processor Responsible for interacting with libinput and dispatching its events, converting them to application events events::DefaultProcessor
controllers::Controller Contains the logic for connecting application events to Actions, and orchestrating controllers::DefaultController

The library also includes basic Implementations of the main traits, in a "batteries included" approach.

Enums

The following enums represent different concepts of the library:

Enum Description
events::ActionEvent Higher-level application event, emitted by the Processor and used by the Controller for mapping to one or more Actions
actions::ActionType Identifier for a specific family of actions

Overview

The following diagram represents the flow and relationships between the components:

flowchart LR
    libinput[fa:fa-external-link-alt libinput]

    subgraph ::controllers
    Controller([fa:fa-code Controller])
    DefaultController
    end

    subgraph ::processor
    Processor([fa:fa-code Processor])
    DefaultProcessor
    end

    subgraph ::actions
    Action([fa:fa-code Action])
    I3Action
    CommandAction
    end

    i3[fa:fa-external-link-alt i3 IPC]
    shell[fa:fa-external-link-alt shell]

    libinput -.-> |input::event::Event| Controller
    Controller --> |::events::ActionEvent | Processor
    Processor --> |executes associated| Action

    DefaultController --> DefaultProcessor
    DefaultProcessor --> I3Action
    DefaultProcessor --> CommandAction

    I3Action -.-> i3
    CommandAction -.-> shell

    classDef trait stroke-dasharray: 5 5;
    class Controller,Processor,Action trait;

Other notes

Error handling

The errors emitted by the components are available in an errors module under each of the main modules, with the individual thiserror-based error Enums re-exported for convenience.

Controller execution

The Controller provides a run() method which enters a loop for receiving events from the Processor and invoking Actions depending on the events received:

%%{init: {'sequence': { 'mirrorActors': false, `0.`0.'actorMargin': 100, 'messageFontSize': 14}}}%%

sequenceDiagram
    autonumber

    actor User
    participant Controller
    participant Processor
    participant libinput as <libinput>
    participant Action

    User->>+Controller: run()
    loop

    rect beige
    note right of libinput: Receive events from Controller
    Controller->>+Processor: dispatch()
    Processor->>+libinput: dispatch()
    libinput-->>-Processor: [libinput events]
    Processor->>+Processor: process_event()
    Processor->>-Processor: _end_event_to_action_event()
    Processor-->>-Controller: [ActionEvents]
    end

    rect beige
    note left of Action: Process application events
    loop For each mapped action
    Controller->>+Controller: process_action_event()
    Controller->>Action: execute_command()
    Action-->>Controller: Result
    deactivate Controller
    deactivate Controller
    end
    end

    end

License

This project is licensed under BSD-3-Clause.

Commit count: 120

cargo fmt