Skip to content

abishek77s/envycontrol-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EnvyControl Go

A Go port of EnvyControl - a tool for switching graphics modes on NVIDIA Optimus laptops.

WARNING!!

This is a one shot port from python (original EnvyControl) -> golang version using bolt.new, I didn't expect this to work at the first try and it must be unstable so use it with caution. USE IT WITH CAUTION!! USE IT WITH CAUTION!!

Features

  • Graphics Mode Switching: Switch between integrated, hybrid, and NVIDIA-only modes
  • System Detection: Automatic detection of GPU hardware and display managers
  • Configuration Management: Automated creation and cleanup of system configuration files
  • Caching System: Optimized operations with intelligent caching
  • Cross-Distribution Support: Works across different Linux distributions
  • Service Management: Automatic handling of nvidia-persistenced service

Installation

Building from Source

# Clone the repository
git clone <repository-url>
cd envycontrol

# Build the project
./scripts/build.sh

# Install (requires root privileges)
sudo ./scripts/install.sh

Manual Installation

# Build for your platform
go build -o envycontrol .

# Copy to system directory
sudo cp envycontrol /usr/local/bin/
sudo chmod +x /usr/local/bin/envycontrol

Usage

Basic Commands

# Check current graphics mode
envycontrol query

# Switch to integrated graphics (power saving)
sudo envycontrol switch integrated

# Switch to hybrid mode (balanced)
sudo envycontrol switch hybrid

# Switch to NVIDIA-only mode (performance)
sudo envycontrol switch nvidia

# Reset all EnvyControl changes
sudo envycontrol reset

Advanced Options

# NVIDIA mode with additional options
sudo envycontrol switch nvidia \
    --dm sddm \
    --force-comp \
    --coolbits 28

# Hybrid mode with RTD3 power management
sudo envycontrol switch hybrid --rtd3 2

# Use nvidia-current drivers instead of nvidia
sudo envycontrol switch hybrid --use-nvidia-current

# Verbose output for debugging
sudo envycontrol switch nvidia --verbose

Cache Management

# Create cache (requires hybrid mode)
sudo envycontrol cache create

# View cache content
envycontrol cache query

# Delete cache
sudo envycontrol cache delete

Display Manager Support

EnvyControl supports the following display managers:

  • GDM / GDM3 (default, no additional configuration needed)
  • SDDM (automatic Xsetup script generation)
  • LightDM (automatic configuration)

Graphics Modes

Integrated Mode

  • Uses only the integrated GPU (Intel/AMD)
  • Best battery life
  • NVIDIA GPU is powered off
  • Suitable for basic tasks

Hybrid Mode

  • Both GPUs available
  • Automatic switching based on application requirements
  • Balanced performance and battery life
  • Supports RTD3 power management

NVIDIA Mode

  • Uses NVIDIA GPU for all rendering
  • Best performance for gaming and GPU-intensive tasks
  • Higher power consumption
  • Supports additional NVIDIA features

Configuration Options

RTD3 Power Management (Hybrid Mode)

  • 0: Disabled
  • 1: Enabled
  • 2: Fine-grained control (default)
  • 3: Coarse-grained control

Coolbits (NVIDIA Mode)

Enables GPU overclocking and fan control:

  • 28: Standard overclocking (default)
  • Custom values: 0-255

Force Composition Pipeline (NVIDIA Mode)

Reduces screen tearing by forcing composition pipeline.

System Requirements

  • Linux distribution with systemd
  • NVIDIA Optimus laptop with dual GPUs
  • Root privileges for system configuration
  • Go 1.21+ for building from source

Supported Distributions

EnvyControl automatically detects and supports:

  • Ubuntu/Debian (update-initramfs)
  • Fedora/RHEL/CentOS (dracut)
  • Arch Linux/Manjaro (mkinitcpio)
  • openSUSE (dracut)
  • EndeavourOS (dracut-rebuild)
  • ALT Linux (make-initrd)
  • OSTree-based systems (rpm-ostree)

Architecture

The Go port follows a clean, modular architecture:

envycontrol/
├── cmd/           # CLI commands and argument parsing
├── internal/      # Private application logic
│   ├── config/    # Configuration templates and caching
│   ├── system/    # System detection and file operations
│   ├── modes/     # Graphics mode switching logic
│   └── utils/     # Utilities and helpers
├── pkg/           # Public API and types
└── scripts/       # Build and installation scripts

Error Handling

The application provides comprehensive error handling with detailed error messages:

  • SystemError: File system and command execution errors
  • ConfigError: Configuration-related errors
  • ValidationError: Input validation errors
  • DetectionError: Hardware detection errors

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project maintains the same license as the original Python EnvyControl project.

Credits

This Go port is based on the original EnvyControl Python project by geminis3.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors