ab566dc44dfd3b035105c812e4a9739f52c1b053
Hyprmonitors
A Rust web server for controlling Hyprland desktop monitors via HTTP API using hyprctl dispatch dpms commands.
Features
- Turn all monitors on/off
- Control individual monitors by name
- Get current monitor status
- RESTful API with JSON responses
- CORS enabled for web applications
Prerequisites
- Hyprland window manager
- Rust toolchain (1.70+)
- Running Hyprland session
Installation
- Clone or download this project
- Build the project:
cargo build --release
Usage
Starting the Server
cargo run
The server will start on http://0.0.0.0:3000 by default.
API Endpoints
Health Check
curl http://localhost:3000/health
Turn All Monitors On
curl -X POST http://localhost:3000/monitors/on
Turn All Monitors Off
curl -X POST http://localhost:3000/monitors/off
Turn Specific Monitor On
curl -X POST http://localhost:3000/monitors/DP-1/on
Turn Specific Monitor Off
curl -X POST http://localhost:3000/monitors/DP-1/off
Get Monitor Status
curl http://localhost:3000/monitors/status
Example Responses
Success Response
{
"success": true,
"message": "Monitor DP-1 turned on",
"monitor": "DP-1"
}
Status Response
{
"success": true,
"monitors": {
"DP-1": "on",
"HDMI-A-1": "off"
}
}
Monitor Names
To find your monitor names, you can use:
hyprctl monitors
Common monitor names include:
DP-1,DP-2(DisplayPort)HDMI-A-1,HDMI-A-2(HDMI)eDP-1(Laptop screen)
Development
Dependencies
axum- Web frameworkhyprland- Hyprland IPC clienttokio- Async runtimeserde- Serializationtower-http- HTTP middleware
Building
# Debug build
cargo build
# Release build
cargo build --release
# Run with logging
RUST_LOG=info cargo run
Testing
Test the endpoints manually:
# Test health
curl http://localhost:3000/health
# Test turning monitors off and on
curl -X POST http://localhost:3000/monitors/off
sleep 2
curl -X POST http://localhost:3000/monitors/on
# Check status
curl http://localhost:3000/monitors/status
Configuration
The server binds to 0.0.0.0:3000 by default. To change the port, modify the main.rs file:
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
Systemd Service (Optional)
Create a systemd service to run the server automatically:
[Unit]
Description=Hyprland Monitor Control Server
After=graphical-session.target
[Service]
Type=simple
ExecStart=/path/to/hyprmonitors/target/release/hyprmonitors
Restart=always
User=%i
Environment=DISPLAY=:0
[Install]
WantedBy=default.target
License
This project is open source. Feel free to modify and distribute.
Troubleshooting
Server won't start
- Ensure you're running inside a Hyprland session
- Check that port 3000 is available
- Verify Rust toolchain is installed
Monitor commands fail
- Confirm monitor names with
hyprctl monitors - Ensure Hyprland IPC is accessible
- Check server logs for error details
Permission issues
- The server needs access to Hyprland's IPC socket
- Run the server as the same user running Hyprland
Description
Languages
Python
47.1%
Rust
21.7%
Shell
18.4%
Nix
10.3%
Makefile
2.5%