# wdbm/spin architecture

> Architecture diagram of the GitHub repository wdbm/spin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wdbm/spin
- Repository: https://github.com/wdbm/spin

## Overview

#### Purpose and Operating Model
`spin` is a Linux laptop-tablet mode utility for X11 systems. It automates input-device and orientation behavior as convertible hardware changes posture, while also allowing manual control. The package is centered on `python_spin/__init__.py`, with installation metadata in `setup.py`.

#### Entry Points
The installed command is `spin`, supporting:
- Default graphical operation.
- Headless operation via `spin --no_GUI`.
- Additional command-line options exposed through `spin --help`.

The package implementation and likely CLI/bootstrap logic are in:
- `python_spin/__init__.py`
- `setup.py`

#### Device-State Automation
The primary control loop detects changes relevant to convertible use:
1. Start in laptop configuration.
2. Detect a transition between laptop and tablet states.
3. Enable or disable the touchpad and pointing stick (“nipple”) to match that state.
4. Apply display/input orientation changes where required.

This behavior is provided in both GUI and non-GUI modes. The core device-state boundary is the local X11 input/display stack; this repository is not a network service.

Relevant paths:
- `python_spin/__init__.py`
- `README.md`

#### Stylus and Palm-Rejection Flow
A separate input-policy flow monitors stylus proximity. When a stylus is detected, spin disables the touchscreen to prevent accidental palm input; it restores expected behavior when stylus proximity ends. This depends on X11 exposing the relevant input devices and event information.

Relevant paths:
- `python_spin/__init__.py`
- `README.md`

#### User Interface and Manual Controls
The default runtime includes a PyQt5 graphical interface for observing or manually applying display orientation and input-device settings. The same automatic policies remain active in GUI mode. Headless mode retains automation without the graphical layer.

Relevant paths:
- `python_spin/__init__.py`
- `setup.py`

#### Runtime, Packaging, and Desktop Integration
Material runtime dependencies are Linux, X11, and PyQt5. The package is distributed through Python packaging metadata in `setup.py`. A desktop launcher is provided for system-wide installation:
- `python_spin/static/spin.desktop`
- `setup.py`

The README references a launcher icon (`spin.svg`), but that asset is not present in the supplied tree; deployment may retrieve it externally rather than package it.

#### Experimental Acceleration Control
An optional, disabled-by-default acceleration-control capability can be enabled from the GUI. It is a secondary policy layer rather than part of the required laptop/tablet and stylus flows.

Relevant paths:
- `python_spin/__init__.py`
- `README.md`

Main entry points: [`python_spin/__init__.py`](https://github.com/wdbm/spin/blob/master/python_spin/__init__.py) (spin command), [`setup.py`](https://github.com/wdbm/spin/blob/master/setup.py) (Python package metadata), [`python_spin/static/spin.desktop`](https://github.com/wdbm/spin/blob/master/python_spin/static/spin.desktop) (Desktop launcher), [`README.md`](https://github.com/wdbm/spin/blob/master/README.md) (Usage documentation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_delivery["Packaging &amp; Launch"]
  node_setup["Python package metadata<br/>packaging<br/>[setup.py]"]
  node_desktop_launcher["Desktop launcher<br/>desktop entry<br/>[spin.desktop]"]
  node_readme["Usage documentation<br/>[README.md]"]
end

subgraph group_runtime["Spin Runtime"]
  node_spin_command["spin command<br/>CLI entry point<br/>[__init__.py]"]
  node_runtime_core["Runtime controller<br/>Python runtime<br/>[__init__.py]"]
  node_gui["PyQt5 GUI<br/>graphical controls<br/>[__init__.py]"]
  node_headless["Headless mode<br/>automation mode<br/>[__init__.py]"]
end

subgraph group_policies["Device Policies"]
  node_posture_detection["Laptop/tablet detection<br/>state monitor<br/>[__init__.py]"]
  node_posture_policy["Posture input policy<br/>device policy<br/>[__init__.py]"]
  node_orientation_policy["Orientation policy<br/>display/input policy<br/>[__init__.py]"]
  node_stylus_policy["Stylus palm rejection<br/>input policy<br/>[__init__.py]"]
  node_acceleration_policy["Acceleration control<br/>optional policy<br/>[__init__.py]"]
end

subgraph group_platform["Local Platform"]
  node_x11{{"X11 input &amp; display stack<br/>local system boundary"}}
  node_linux{{"Linux system<br/>host platform"}}
end

node_setup -->|"installs"| node_spin_command
node_setup -->|"packages"| node_desktop_launcher
node_desktop_launcher -->|"launches"| node_spin_command
node_spin_command -->|"starts"| node_runtime_core
node_spin_command -->|"default mode"| node_gui
node_spin_command -->|"--no_GUI"| node_headless
node_gui -->|"runs automation"| node_runtime_core
node_headless -->|"runs automation"| node_runtime_core
node_gui -->|"manual controls"| node_orientation_policy
node_gui -->|"enables"| node_acceleration_policy
node_runtime_core -->|"monitors"| node_posture_detection
node_runtime_core -->|"monitors"| node_stylus_policy
node_posture_detection -->|"state transition"| node_posture_policy
node_posture_detection -->|"orientation change"| node_orientation_policy
node_posture_detection -->|"reads state"| node_x11
node_stylus_policy -->|"reads proximity and controls touchscreen"| node_x11
node_posture_policy -->|"controls touchpad and pointing stick"| node_x11
node_orientation_policy -->|"applies orientation"| node_x11
node_acceleration_policy -->|"applies optional control"| node_x11
node_x11 -->|"runs on"| node_linux
node_readme -.->|"documents"| node_spin_command

click node_setup "https://github.com/wdbm/spin/blob/master/setup.py"
click node_desktop_launcher "https://github.com/wdbm/spin/blob/master/python_spin/static/spin.desktop"
click node_spin_command "https://github.com/wdbm/spin/blob/master/python_spin/__init__.py"
click node_runtime_core "https://github.com/wdbm/spin/blob/master/python_spin/__init__.py"
click node_gui "https://github.com/wdbm/spin/blob/master/python_spin/__init__.py"
click node_headless "https://github.com/wdbm/spin/blob/master/python_spin/__init__.py"
click node_posture_detection "https://github.com/wdbm/spin/blob/master/python_spin/__init__.py"
click node_posture_policy "https://github.com/wdbm/spin/blob/master/python_spin/__init__.py"
click node_orientation_policy "https://github.com/wdbm/spin/blob/master/python_spin/__init__.py"
click node_stylus_policy "https://github.com/wdbm/spin/blob/master/python_spin/__init__.py"
click node_acceleration_policy "https://github.com/wdbm/spin/blob/master/python_spin/__init__.py"
click node_readme "https://github.com/wdbm/spin/blob/master/README.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_setup,node_desktop_launcher,node_readme toneBlue
class node_spin_command,node_runtime_core,node_gui,node_headless toneAmber
class node_posture_detection,node_posture_policy,node_orientation_policy,node_stylus_policy,node_acceleration_policy toneMint
class node_x11,node_linux toneRose
```

## Components

### Packaging & Launch

- [Python package metadata](https://github.com/wdbm/spin/blob/master/setup.py): packaging · Defines installation and the spin command. · `setup.py`
- [Desktop launcher](https://github.com/wdbm/spin/blob/master/python_spin/static/spin.desktop): desktop entry · `python_spin/static/spin.desktop`
- [Usage documentation](https://github.com/wdbm/spin/blob/master/README.md): documentation · Documents modes, policies, and dependencies. · `README.md`

### Spin Runtime

- [spin command](https://github.com/wdbm/spin/blob/master/python_spin/__init__.py): CLI entry point · Selects GUI or --no_GUI operation. · `python_spin/__init__.py`
- [Runtime controller](https://github.com/wdbm/spin/blob/master/python_spin/__init__.py): Python runtime · Coordinates automatic policies and device actions. · `python_spin/__init__.py`
- [PyQt5 GUI](https://github.com/wdbm/spin/blob/master/python_spin/__init__.py): graphical controls · Shows and manually applies orientation and input settings. · `python_spin/__init__.py`
- [Headless mode](https://github.com/wdbm/spin/blob/master/python_spin/__init__.py): automation mode · Runs policies without the graphical layer. · `python_spin/__init__.py`

### Device Policies

- [Laptop/tablet detection](https://github.com/wdbm/spin/blob/master/python_spin/__init__.py): state monitor · `python_spin/__init__.py`
- [Posture input policy](https://github.com/wdbm/spin/blob/master/python_spin/__init__.py): device policy · Enables or disables touchpad and pointing stick by posture. · `python_spin/__init__.py`
- [Orientation policy](https://github.com/wdbm/spin/blob/master/python_spin/__init__.py): display/input policy · `python_spin/__init__.py`
- [Stylus palm rejection](https://github.com/wdbm/spin/blob/master/python_spin/__init__.py): input policy · Disables touchscreen while the stylus is in proximity. · `python_spin/__init__.py`
- [Acceleration control](https://github.com/wdbm/spin/blob/master/python_spin/__init__.py): optional policy · Disabled by default and enabled from the GUI. · `python_spin/__init__.py`

### Local Platform

- **X11 input & display stack**: local system boundary · Provides device state, events, and display/input control.
- **Linux system**: host platform

## Connections

- Python package metadata → spin command: installs
- Python package metadata → Desktop launcher: packages
- Desktop launcher → spin command: launches
- spin command → Runtime controller: starts
- spin command → PyQt5 GUI: default mode
- spin command → Headless mode: --no_GUI
- PyQt5 GUI → Runtime controller: runs automation
- Headless mode → Runtime controller: runs automation
- PyQt5 GUI → Orientation policy: manual controls
- PyQt5 GUI → Acceleration control: enables
- Runtime controller → Laptop/tablet detection: monitors
- Runtime controller → Stylus palm rejection: monitors
- Laptop/tablet detection → Posture input policy: state transition
- Laptop/tablet detection → Orientation policy: orientation change
- Laptop/tablet detection → X11 input & display stack: reads state
- Stylus palm rejection → X11 input & display stack: reads proximity and controls touchscreen
- Posture input policy → X11 input & display stack: controls touchpad and pointing stick
- Orientation policy → X11 input & display stack: applies orientation
- Acceleration control → X11 input & display stack: applies optional control
- X11 input & display stack → Linux system: runs on
- Usage documentation → spin command: documents
