# Temperlux

[![CI](https://ci.angussoftware.dev/api/badges/RhoMancer/temperlux/status.svg)](https://ci.angussoftware.dev/RhoMancer/temperlux)
[![crates.io](https://img.shields.io/crates/v/temperlux.svg)](https://crates.io/crates/temperlux)
[![License: GPL-3.0-or-later](https://img.shields.io/badge/license-GPL--3.0--or--later-blue.svg)](LICENSE)

A brightness controller for external (DDC/CI) and internal (backlight) displays, written in Rust with GTK4/Libadwaita GUI.

Based on [Luminance](https://github.com/sidevesh/Luminance) by sidevesh — rewritten from scratch with FFI-based DDC for performance and a testable architecture.

![Temperlux GUI](docs/screenshot-gui.png)

## Features

- **GUI** — per-display brightness sliders with live hardware control
- **CLI** — get/set/increase/decrease brightness from the command line
- **JSON output** — `temperlux list --json` for scripting/waybar/polybar
- **Sync modes** — Off, Same Value, or Proportional across all displays
- **Min/Max caps** — per-display brightness range limits
- **Display rename** — custom names persisted in config
- **Autostart** — optional "Start on login" via Preferences
- **Error auto-expiry** — error messages auto-clear after 5 seconds

## Install

### From source

```bash
# Install dependencies
sudo apt install ddcutil libddcutil-dev libgtk-4-dev libadwaita-1-dev pkg-config

# Build and install (CLI + GUI)
make && sudo make install
```

This installs:
- `temperlux` (CLI) → `/usr/local/bin/`
- `temperlux-gui` (GUI) → `/usr/local/bin/`
- Desktop entry → `/usr/local/share/applications/`
- App icon → `/usr/local/share/icons/hicolor/`

### From crates.io

```bash
# CLI only (no GUI)
cargo install temperlux

# With GUI
cargo install temperlux --features gui
```

### Uninstall

```bash
sudo make uninstall
```

## Usage

### GUI

```bash
temperlux-gui
```

### CLI

```bash
# List all displays
temperlux list

# JSON output for scripting
temperlux list --json

# Get brightness of display 1
temperlux get 1

# Set display 1 to 75%
temperlux set 1 --percent 75

# Set all displays to 50%
temperlux set --percent 50

# Increase all displays by 10%
temperlux increase --percent 10

# Rename a display
temperlux rename 1 "Left Monitor"
```

### Shell completions

```bash
# Bash
temperlux completions bash > ~/.local/share/bash-completion/completions/temperlux

# Zsh
temperlux completions zsh > ~/.zfunc/_temperlux

# Fish
temperlux completions fish > ~/.config/fish/completions/temperlux.fish
```

## Build

```bash
# CLI only (default)
cargo build --release

# With GUI
cargo build --release --features gui

# Run tests
cargo test
```

### Requirements

- Rust 1.82+
- `libddcutil` development headers
- GTK4 + Libadwaita 1.2+ (for GUI feature)

### Install dependencies (Debian/Ubuntu)

```bash
sudo apt install ddcutil libddcutil-dev libgtk-4-dev libadwaita-1-dev pkg-config
```

## Architecture

```
src/
  main.rs          CLI entry point
  cli.rs           clap argument definitions + shell completions
  autostart.rs     Autostart .desktop file management
  lib.rs           Library root
  settings.rs      JSON config (~/.config/temperlux/settings.json)
  sync.rs          Sync mode math (proportional map, delta apply)
  caps.rs          Min/max brightness clamping
  display/
    ddc_ffi.rs     DdcService (FFI libddcutil, parallel writes, command coalescing)
    backlight.rs   RealBacklightProvider (/sys/class/backlight)
    manager.rs     DisplayManager (unified display operations)
    provider.rs    BacklightProvider trait
  gui/
    window.rs      Main window, display rows, dialogs
    viewmodel.rs   DisplayRow data model
    debounce.rs    Slider debouncing + worker pool
```

Both CLI and GUI use `DdcService` (FFI libddcutil) for reliable display detection and fast parallel DDC writes with command coalescing. Hardware access is behind provider traits with mock implementations for testing.

## Configuration

Config file: `~/.config/temperlux/settings.json`

```json
{
  "sync_mode": "Proportional",
  "show_display_numbers": true,
  "autostart": false,
  "display_order": ["ddc:2", "ddc:1", "ddc:3"],
  "displays": {
    "ddc:1": {
      "min_brightness": 20.0,
      "max_brightness": 80.0,
      "custom_name": "Left Monitor"
    },
    "ddc:2": {
      "min_brightness": 0.0,
      "max_brightness": 100.0,
      "custom_name": "Right Monitor"
    }
  }
}
```

## License

GPL-3.0-or-later. See [LICENSE](LICENSE) and [NOTICE](NOTICE).

This project is a rewrite of [Luminance](https://github.com/sidevesh/Luminance) by sidevesh, which is also licensed under GPL-3.0-or-later.
