kb-auto-switch-hyprland

Crates.iokb-auto-switch-hyprland
lib.rskb-auto-switch-hyprland
version0.1.0
created_at2025-08-28 02:04:02.059371+00
updated_at2025-08-28 02:04:02.059371+00
descriptionA simple Rust-based console utility that automatically switches keyboard layouts per active window in **Hyprland**.
homepagehttps://gitlab.com/itcreator/kb-auto-switch-hyprland.git
repositoryhttps://gitlab.com/itcreator/kb-auto-switch-hyprland.git
max_upload_size
id1813463
size29,348
Vital Leshchyk (itcreator)

documentation

https://gitlab.com/itcreator/kb-auto-switch-hyprland.git

README

kb-auto-switch-hyprland Automatic Keyboard Layout Switcher

A simple Rust-based console utility that automatically switches keyboard layouts per active window in Hyprland.

This tool monitors the currently active window and remembers the keyboard layout used for each application, restoring it when switching back. It supports multiple keyboard layouts and uses hyprctl to interact with Hyprland.


Features

  • Tracks the active window's PID using hyprctl activewindow -j.
  • Detects the main keyboard and available layouts via hyprctl devices -j.
  • Automatically switches keyboard layout per application.
  • Maintains a mapping between window PIDs and keyboard layouts.
  • Lightweight and fast, using polling every 50 ms.
  • Logging support with configurable levels (trace, info, warn) using the log crate.

Requirements

  • Hyprland window manager
  • hyprctl command-line tool
  • Rust 1.72+ (for building)

Installation

You can install the utility directly from crates.io using Cargo:

cargo install kb-auto-switch-hyprland

After installation, the kb-auto-switch-hyprland binary will be available in your Cargo bin directory ($HOME/.cargo/bin by default).

To run the program:

kb-auto-switch-hyprland

Alternatively, you can still build from source:

git clone https://github.com/yourusername/hypr-layout-switcher.git
cd hypr-layout-switcher
cargo build --release
./target/release/hypr-layout-switcher

Usage

By default, the program:

  1. Detects your main keyboard.
  2. Scans and records all available keyboard layouts.
  3. Monitors the active window.
  4. Switches the keyboard layout automatically based on previous usage for that window.

Logging

Logging is controlled via the RUST_LOG environment variable:

RUST_LOG=info ./kb-auto-switch-hyprland   # default info level
RUST_LOG=trace ./kb-auto-switch-hyprland  # debug everything, including PID-to-layout mappings
  • trace — verbose output for debugging
  • info — main actions and active layouts
  • warn — warnings

Example

[INFO] Automatic keyboard switch initialization...
[INFO] Active layouts:
  LAYOUT: us; ID: 0
  LAYOUT: ru; ID: 1
[INFO] Automatic keyboard switch initialization... Done.
[TRACE] [Window] New PID: 12345
[TRACE] [Layout] Switching to saved layout for PID 12345: ru

Notes

  • Switcher doesn't affect your system layout configuratio such as kb_layout = "us,fr";, kb_options = "grp:alt_space_toggle";
  • The utility relies on hyprctl and JSON parsing via serde. Ensure hyprctl works correctly on your system.
  • The program currently uses polling every 50ms. Future versions could leverage event-based notifications from Hyprland for efficiency.
  • PID-to-layout mapping is maintained only during runtime; it does not persist across restarts.

License

This project is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0).

Commit count: 0

cargo fmt