The project has been refactored from two large files into a modular, maintainable structure:
MiddleDrag/
├── Core/ # Core functionality
│ ├── MultitouchFramework.swift # Private API bindings and framework management
│ ├── GestureRecognizer.swift # Gesture detection and state management
│ ├── MouseEventGenerator.swift # Mouse event generation and cursor control
│ └── TouchDeviceProviding.swift # Protocol for device monitoring/dependency injection
│
├── Models/ # Data models
│ ├── TouchModels.swift # Touch data structures (MTPoint, MTTouch, etc.)
│ └── GestureModels.swift # Gesture state and configuration models
│
├── Managers/ # Business logic managers
│ ├── MultitouchManager.swift # Main coordinator for gesture system
│ ├── DeviceMonitor.swift # Device monitoring and callback management
│ ├── AccessibilityMonitor.swift # Accessibility permission polling and app handling
│ └── AccessibilityWrappers.swift # Wrappers for accessibility system APIs (testability)
│
├── UI/ # User interface
│ ├── MenuBarController.swift # Menu bar UI management
│ └── AlertHelper.swift # Alert dialogs and user notifications
│
├── Utilities/ # Helper utilities
│ ├── PreferencesManager.swift # User preferences persistence
│ ├── LaunchAtLoginManager.swift # Launch at login functionality
│ ├── AnalyticsManager.swift # Analytics and telemetry management
│ ├── ScreenHelper.swift # Multi-monitor screen coordinate handling
│ ├── SystemGestureHelper.swift # System trackpad settings and process management
│ ├── UpdateManager.swift # App updates via Sparkle framework
│ └── WindowHelper.swift # Window detection under cursor
│
├── MiddleDragApp.swift # SwiftUI app entry point
├── AppDelegate.swift # Application delegate
├── Info.plist # App configuration
└── MiddleDrag.entitlements # App entitlements
│
MiddleDragTests/ # Unit test target
├── AccessibilityMonitorTests.swift # Tests for accessibility permissions
├── AlertHelperTests.swift # Tests for alert dialogs
├── AnalyticsManagerTests.swift # Tests for analytics
├── DeviceMonitorTests.swift # Tests for device monitoring
├── GestureModelsTests.swift # Tests for gesture models
├── GestureRecognizerTests.swift # Tests for gesture recognition logic
├── LaunchAtLoginManagerTests.swift # Tests for launch at login
├── MenuBarControllerTests.swift # Tests for menu bar UI
├── MouseEventGeneratorTests.swift # Tests for mouse event generation
├── MultitouchFrameworkTests.swift # Tests for multitouch framework bindings
├── MultitouchManagerTests.swift # Tests for main coordinator
├── PreferencesManagerTests.swift # Tests for preferences persistence
├── ScreenHelperTests.swift # Tests for screen coordinate handling
├── SystemGestureHelperTests.swift # Tests for system gesture settings
├── TouchModelsTests.swift # Tests for touch data structures
├── WindowHelperTests.swift # Tests for window detection
└── Mocks/ # Mock objects for testing
└── MockDeviceMonitor.swift # Mock device monitor
│
.github/ # GitHub configuration
├── workflows/ # CI/CD workflows
│ └── *.yml # GitHub Actions workflow files
└── ISSUE_TEMPLATE/ # Issue templates
│
Root Files:
├── README.md # Project documentation
├── PROJECT_STRUCTURE.md # This file
├── LICENSE # MIT License
├── CODE_OF_CONDUCT.md # Community guidelines
├── CONTRIBUTING.md # Contribution guide
├── SECURITY.md # Security policy
├── build.sh # Build automation script
├── bump-version.sh # Version bump script
├── codecov.yml # Codecov configuration
└── .gitignore # Git ignore rules
- Each class has a single, well-defined responsibility
- Easy to understand and modify individual components
- Clear boundaries between layers
- Core functionality separated from UI
- Models independent of implementation
- Managers coordinate between components
- Each component can be tested in isolation
- Mock delegates and protocols for testing
- Clear interfaces between modules
- Comprehensive test coverage with 17 test files
- Easy to locate specific functionality
- Reduced file sizes (no more 500+ line files)
- Logical grouping of related code
- Easy to add new gesture types
- Simple to support new device types
- UI can be extended without touching core logic
- MultitouchFramework: Interfaces with private Apple framework
- GestureRecognizer: Converts touch data into gestures
- MouseEventGenerator: Handles all mouse event synthesis
- TouchDeviceProviding: Protocol for device monitoring and dependency injection
- TouchModels: Raw touch data structures
- GestureModels: Application state and configuration
- MultitouchManager: Main coordinator, implements business logic
- DeviceMonitor: Manages device lifecycle and callbacks
- AccessibilityMonitor: Manages accessibility permission polling and app handling
- AccessibilityWrappers: Wrappers for system accessibility APIs (enables testability)
- MenuBarController: All menu bar UI logic
- AlertHelper: Centralized alert management
- PreferencesManager: UserDefaults persistence
- LaunchAtLoginManager: System integration for auto-launch
- AnalyticsManager: Analytics and telemetry management
- ScreenHelper: Multi-monitor screen coordinate conversion (Cocoa ↔ Quartz)
- SystemGestureHelper: Trackpad settings and process management for testing
- UpdateManager: App updates via Sparkle framework (offline by default)
- WindowHelper: Detects window information under the cursor
- Comprehensive unit tests for all components
- Mock objects for isolated testing
- Tests for gesture recognition, touch models, and UI components
- Delegate Pattern: For loose coupling between components
- Singleton Pattern: For shared managers (with care)
- Observer Pattern: Using NotificationCenter for preferences
- Factory Pattern: Device creation in MultitouchFramework
- Strategy Pattern: Configurable gesture recognition
- Protocol-Oriented Design: For dependency injection and testability
To add a new feature, identify which layer it belongs to:
- New gesture type? → Modify GestureRecognizer
- New mouse action? → Extend MouseEventGenerator
- New preference? → Update PreferencesManager and GestureModels
- New menu item? → Add to MenuBarController
- New device support? → Extend DeviceMonitor
- New test? → Add to MiddleDragTests target
- Accessibility feature? → Update AccessibilityMonitor
- Multi-monitor handling? → Update ScreenHelper
The refactored code maintains minimal dependencies:
- No external Swift packages required (except Sparkle for updates and Sentry for analytics/error reporting)
- Uses only system frameworks
- Private framework access isolated to one file
- GitHub Actions: Automated build, test, and release workflows
- Codecov: Code coverage reporting and tracking
- Build Scripts:
build.shfor local builds,bump-version.shfor version management