showpid
Bring a window of a specified process ID (PID) to the foreground. Cross-platform support for Windows, Linux, and macOS.
Features
- ๐ Fast & Lightweight - Pure Rust implementation with minimal dependencies
- ๐ Cross-Platform - Supports Windows, Linux (X11), and macOS
- ๐ Retry Logic - Configurable retry mechanism for transient failures
- ๐ช Multiple Windows - Handles processes with multiple windows
- ๐ง Platform-Native - Uses native APIs for optimal performance on each platform
- ๐ Verbose Mode - Detailed logging for troubleshooting
- ๐ก๏ธ Error Handling - Comprehensive error handling with meaningful messages
- โก Zero-Cost Abstractions - Safe Rust wrapper over platform-specific APIs
- ๐ฆ Standalone Binary - Single executable, no runtime dependencies required
- ๐งช Well Tested - Unit tests and cross-platform CI testing
Platform Support
| Platform | API Used | Minimum Version | Notes |
|---|---|---|---|
| Windows | Windows API (Win32) | Windows 10+ | Native Win32 API through windows-rs |
| Linux | X11 (Xlib) | X11 compatible | Requires libx11-dev on some distributions |
| macOS | CoreGraphics + AppleScript | macOS 10.12+ | Uses osascript for reliable window activation |
Installation
From Crates.io
From Source
# Linux: Install dependencies first
# or
# Build and install
Pre-built Binaries
Download the latest release for your platform from the Releases page:
- Windows:
showpid-windows-x86_64.zip - Linux:
showpid-linux-x86_64.tar.gz - macOS:
showpid-macos-x86_64.tar.gz
Platform-Specific Requirements
Linux
# Ubuntu/Debian
# Fedora/RHEL
# Arch Linux
macOS
No additional dependencies required. Uses built-in CoreGraphics and AppleScript frameworks.
Windows
No additional dependencies required. Uses built-in Windows API.
Usage
Basic Usage
# Bring window of PID 1234 to foreground
# Verbose mode with detailed output
# Show help
Command Line Options
Usage: showpid [OPTIONS] <PID>
Brings the window of the specified PID to the foreground.
Arguments:
<PID> Process ID to bring to foreground
Options:
-v, --verbose Enable verbose output
-h, --help Show this help message
-V, --version Print version information
Platform-Specific Examples
Windows
# Find notepad PID
|
# Bring to foreground
# With verbose output
Linux
# Find Firefox PID
# Bring to foreground
# With verbose output
macOS
# Find Safari PID
# Bring to foreground
# With verbose output
Using as a Library
use ;
How It Works
Windows
- Enumerates all visible windows using
EnumWindows - Filters windows by process ID using
GetWindowThreadProcessId - Restores window if minimized with
ShowWindow - Attaches thread input for reliable foreground activation
- Sets window as foreground with
SetForegroundWindow
Linux (X11)
- Connects to X display and queries all windows
- Reads
_NET_WM_PIDproperty to match process IDs - Raises window with
XRaiseWindow - Sets input focus with
XSetInputFocus - Maps window if unmapped with
XMapWindow
macOS
- Uses
CGWindowListCopyWindowInfoto enumerate windows - Filters by owner PID from window properties
- Uses AppleScript to bring process to foreground
- Handles permissions and accessibility requirements
Exit Codes
0- Success: Window brought to foreground1- Error: No window found, operation failed, or invalid input
Environment Variables
RUST_LOG- Set logging level (e.g.,RUST_LOG=debug showpid 1234)- Levels:
error,warn,info,debug,trace
- Levels:
Troubleshooting
Linux
- Error: "Failed to open X display": Make sure you're running in an X11 session (not Wayland)
- No windows found: Ensure the process has visible windows and you have proper permissions
macOS
- Permission denied: Grant accessibility permissions in System Preferences > Security & Privacy > Privacy > Accessibility
- osascript errors: Ensure you have AppleScript permissions enabled
Windows
- Access denied: Run as administrator if targeting system processes
- No windows found: Some processes may not have visible windows
Development
Prerequisites
- Rust 1.70 or later
- Platform-specific dependencies (see Installation section)
Building
# Debug build
# Release build (optimized)
# Run tests
# Run clippy lints
# Format code
Cross-Compilation
# Cross-compile for Windows from Linux
# Cross-compile for macOS from Linux
Project Structure
showpid/
โโโ src/
โ โโโ main.rs # Main application with platform modules
โ โโโ platform/
โ โ โโโ windows.rs # Windows-specific implementation
โ โ โโโ linux.rs # Linux/X11-specific implementation
โ โ โโโ macos.rs # macOS-specific implementation
โโโ Cargo.toml # Package configuration
โโโ Cargo.lock # Dependency lock file
โโโ README.md # Project documentation
โโโ LICENSE # MIT License
โโโ CHANGELOG.md # Version history
โโโ .gitignore # Git ignore rules
โโโ .github/
โโโ workflows/
โโโ ci.yml # Multi-platform CI workflow
โโโ publish.yml # Multi-platform publish workflow
Comparison with Original Python Version
| Feature | Python (showpid.py) | Rust (showpid) |
|---|---|---|
| Speed | Moderate | Fast (compiled) |
| Binary Size | ~0 KB + Python | ~2-5 MB standalone |
| Dependencies | win32gui, win32process | Platform-native APIs |
| Platform Support | Windows only | Windows, Linux, macOS |
| Error Handling | Basic | Comprehensive |
| Retry Logic | โ | โ (configurable) |
| Multiple Windows | First only | All windows tried |
| Verbose Mode | โ | โ |
| Logging | Print statements | Structured logging (log/env_logger) |
| Thread Safety | N/A | โ |
| Testing | โ | โ (unit tests + CI) |
| Cross-compilation | N/A | โ |
| CI/CD | N/A | โ (GitHub Actions) |
| Package Registry | N/A | โ (crates.io) |
Changelog
See CHANGELOG.md for version history.
API Documentation
Full API documentation is available on docs.rs.
Main API Types
Config- Configuration for window activationWindowActivator- Main window finder and activatorWindowInfo- Platform-specific window information
Example: Programmatic Usage
use ;
// Create configuration
let config = new
.with_verbose
.with_retries
.with_retry_delay;
// Create activator
let mut activator = new;
// Execute with custom error handling
match activator.execute
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Ensure cross-platform compatibility
- Add tests for new features
- Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Adding Support for New Platforms
To add support for a new platform:
- Create a new conditionally compiled module in
src/main.rs - Implement
WindowActivatorfor the new platform - Add platform-specific dependencies to
Cargo.toml - Update CI workflow to test the new platform
- Update this README with new platform requirements
License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ค Author
Hadi Cahyadi - cumulus13@gmail.com
- GitHub: @cumulus13
Acknowledgments
- Original Python version by Hadi Cahyadi
- Windows API bindings provided by windows-rs
- X11 bindings provided by the Rust community
- CoreGraphics bindings for macOS support
- All contributors and users of this project
Support
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Search existing issues
- Open a new issue with:
- Your operating system and version
- Steps to reproduce
- Verbose output (
showpid -v <PID>) - Expected vs actual behavior
Roadmap
- Wayland support for Linux
- Apple Silicon (ARM64) native builds
- Window selection by title pattern matching
- Multiple window selection interface
- Configuration file support
- Shell completion scripts
- System tray integration
- Web interface for remote control
