feat: initail commit

This commit is contained in:
uttarayan21
2025-08-15 16:28:28 +05:30
commit f0dce3f233
16 changed files with 2453 additions and 0 deletions

189
README.md Normal file
View File

@@ -0,0 +1,189 @@
# 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
1. Clone or download this project
2. Build the project:
```bash
cargo build --release
```
## Usage
### Starting the Server
```bash
cargo run
```
The server will start on `http://0.0.0.0:3000` by default.
### API Endpoints
#### Health Check
```bash
curl http://localhost:3000/health
```
#### Turn All Monitors On
```bash
curl -X POST http://localhost:3000/monitors/on
```
#### Turn All Monitors Off
```bash
curl -X POST http://localhost:3000/monitors/off
```
#### Turn Specific Monitor On
```bash
curl -X POST http://localhost:3000/monitors/DP-1/on
```
#### Turn Specific Monitor Off
```bash
curl -X POST http://localhost:3000/monitors/DP-1/off
```
#### Get Monitor Status
```bash
curl http://localhost:3000/monitors/status
```
### Example Responses
#### Success Response
```json
{
"success": true,
"message": "Monitor DP-1 turned on",
"monitor": "DP-1"
}
```
#### Status Response
```json
{
"success": true,
"monitors": {
"DP-1": "on",
"HDMI-A-1": "off"
}
}
```
## Monitor Names
To find your monitor names, you can use:
```bash
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 framework
- `hyprland` - Hyprland IPC client
- `tokio` - Async runtime
- `serde` - Serialization
- `tower-http` - HTTP middleware
### Building
```bash
# Debug build
cargo build
# Release build
cargo build --release
# Run with logging
RUST_LOG=info cargo run
```
### Testing
Test the endpoints manually:
```bash
# 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:
```rust
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:
```ini
[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