How chinthanasathyajithcs/qpaste works
Purpose and Entry Point
QPaste is a Windows-resident clipboard utility that turns copied text into a bounded FIFO paste queue. It runs as a PyQt6 system-tray application, intercepting copy/paste-related events while avoiding foreground-window disruption. The process starts at src/main.py; packaging targets a Windows executable via qpaste.spec.
Application Composition
The entry point assembles the core services, UI surfaces, lifecycle handling, and event loop:
• src/main.py
• src/core/state.py
• src/core/single_instance.py
A Win32 named mutex rejects a second process before competing listeners or hotkeys can start. Application state centralizes whether Queue Mode is active and coordinates user-driven actions such as toggle and clear.
Clipboard Queue Domain
The queue is the primary in-memory domain model: thread-safe, FIFO, and capped at 25 items. Copy operations append text; eligible paste operations consume the oldest item. Empty queues deliberately fall back to normal Windows paste behavior.
• src/core/clipboard_queue.py
• src/core/state.py
The queue is ephemeral by design; auto-clear and explicit clear remove retained clipboard content rather than persisting it.
Native Event and Clipboard Boundary
src/core/listener.py bridges the app to Windows keyboard hooks and clipboard APIs. It observes Ctrl+C, captures clipboard text after copy, and on Ctrl+V supplies the queue head when Queue Mode is enabled. This layer owns clipboard contention handling, including retries for temporary clipboard locks, and must separate QPaste-originated clipboard writes from newly copied user content.
• src/core/listener.py
• src/core/clipboard_queue.py
This is the principal concurrency/native-API boundary: hook callbacks and clipboard notifications feed shared queue/state safely.
User Interaction Surfaces
The application is controlled primarily through tray actions and global shortcuts, with two transient PyQt6 interfaces:
• src/ui/toast.py presents a focusless status/count overlay.
• src/ui/inspector.py provides queue inspection, individual removal, full clearing, settings, and startup controls.
• src/main.py owns tray-oriented application execution.
UI actions invoke core state/queue operations; queue and mode changes are reflected back through toast and inspector views rather than requiring a main window.
Settings, Expiry, and Windows Startup
Persistent user preferences—including auto-clear duration and startup selection—are managed separately from the transient queue:
• src/core/config.py
• src/core/startup.py
• src/core/clipboard_queue.py
Auto-clear purges queued items after the configured interval (30 seconds to one hour). Windows boot launch is implemented through Registry integration, making startup.py a platform-specific infrastructure boundary.
Runtime and Distribution
The supported runtime is Python 3.11+ on Windows 10/11, using PyQt6 for the GUI and Win32 facilities for mutexes, keyboard/clipboard integration, and Registry startup. Dependencies are declared in src/requirements.txt. Distribution has two routes:
• PyInstaller portable executable: qpaste.spec
• Inno Setup installer: installer/qpaste_setup.iss
Main entry points: main.py Application Entry · state.py Application State · clipboard_queue.py Clipboard Queue · listener.py Native Listener
Components 15
Windows Runtime
- Application Entry · Assembles services, tray execution, and lifecycle.
src/main.py - Single Instance · Rejects competing QPaste processes.
src/core/single_instance.py - Native Listener · Handles hooks, clipboard contention, and QPaste-originated writes.
src/core/listener.py - Windows Startup · Registers optional boot launch.
src/core/startup.py - Windows Clipboard
- Windows Keyboard Hooks
Core Domain
- Application State · Coordinates Queue Mode and user actions.
src/core/state.py - Clipboard Queue · Thread-safe ephemeral queue capped at 25 items.
src/core/clipboard_queue.py - Preferences · Stores auto-clear duration and startup selection.
src/core/config.py
User Surfaces
- Tray Controls · Primary controls and global shortcut access.
src/main.py - Status Toast · Shows mode and queue count.
src/ui/toast.py - Queue Inspector · Inspects and manages queue, settings, and startup.
src/ui/inspector.py
Distribution
- Runtime Dependencies
src/requirements.txt - Portable Executable
qpaste.spec - Windows Installer
installer/qpaste_setup.iss
Connections 24
- Application Entry → Single Instance: acquires before startup
- Application Entry → Application State: initializes
- Application Entry → Native Listener: starts
- Application Entry → Tray Controls: runs
- Application Entry → Status Toast: owns
- Application Entry → Queue Inspector: opens
- Native Listener → Windows Keyboard Hooks: observes Ctrl+C / Ctrl+V
- Native Listener → Windows Clipboard: reads and writes
- Native Listener → Application State: checks Queue Mode
- Native Listener → Clipboard Queue: appends copies / consumes paste head
- Application State → Clipboard Queue: toggles and clears
- Preferences → Clipboard Queue: configures auto-clear
- Preferences → Windows Startup: controls enabled state
- Windows Startup → Application Entry: launches at Windows boot
- Tray Controls → Application State: invokes actions
- Queue Inspector → Application State: invokes mode and clear actions
- Queue Inspector → Clipboard Queue: inspects and removes items
- Queue Inspector → Preferences: edits preferences
- Application State → Status Toast: publishes mode changes
- Clipboard Queue → Status Toast: publishes count changes
- Clipboard Queue → Queue Inspector: publishes queue changes
- Runtime Dependencies → Application Entry: provides runtime dependencies
- Portable Executable → Application Entry: packages
- Windows Installer → Portable Executable: installs executable