clickdust 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. clickdust-0.4.0/.gitignore +10 -0
  2. clickdust-0.4.0/LICENSE +21 -0
  3. clickdust-0.4.0/PKG-INFO +194 -0
  4. clickdust-0.4.0/README.md +170 -0
  5. clickdust-0.4.0/pyproject.toml +43 -0
  6. clickdust-0.4.0/src/clickdust/__init__.py +3 -0
  7. clickdust-0.4.0/src/clickdust/__main__.py +3 -0
  8. clickdust-0.4.0/src/clickdust/backends/__init__.py +29 -0
  9. clickdust-0.4.0/src/clickdust/backends/generic.py +45 -0
  10. clickdust-0.4.0/src/clickdust/backends/hid.py +153 -0
  11. clickdust-0.4.0/src/clickdust/backends/macos.py +115 -0
  12. clickdust-0.4.0/src/clickdust/claude.py +132 -0
  13. clickdust-0.4.0/src/clickdust/cli.py +214 -0
  14. clickdust-0.4.0/src/clickdust/daemon.py +58 -0
  15. clickdust-0.4.0/src/clickdust/demo.py +65 -0
  16. clickdust-0.4.0/src/clickdust/doctor.py +102 -0
  17. clickdust-0.4.0/src/clickdust/landscape/__init__.py +1 -0
  18. clickdust-0.4.0/src/clickdust/landscape/demo.py +59 -0
  19. clickdust-0.4.0/src/clickdust/landscape/export.py +59 -0
  20. clickdust-0.4.0/src/clickdust/landscape/model.py +234 -0
  21. clickdust-0.4.0/src/clickdust/landscape/site.py +55 -0
  22. clickdust-0.4.0/src/clickdust/lock.py +40 -0
  23. clickdust-0.4.0/src/clickdust/paths.py +35 -0
  24. clickdust-0.4.0/src/clickdust/probe.py +103 -0
  25. clickdust-0.4.0/src/clickdust/render/__init__.py +14 -0
  26. clickdust-0.4.0/src/clickdust/render/canvas.py +98 -0
  27. clickdust-0.4.0/src/clickdust/render/palette.py +38 -0
  28. clickdust-0.4.0/src/clickdust/render/styles.py +92 -0
  29. clickdust-0.4.0/src/clickdust/screens.py +24 -0
  30. clickdust-0.4.0/src/clickdust/store.py +204 -0
  31. clickdust-0.4.0/src/clickdust/tracker.py +164 -0
  32. clickdust-0.4.0/src/clickdust/web/index.html +38 -0
  33. clickdust-0.4.0/src/clickdust/web/viewer.css +40 -0
  34. clickdust-0.4.0/src/clickdust/web/viewer.js +744 -0
  35. clickdust-0.4.0/src/clickdust/weekly.py +113 -0
  36. clickdust-0.4.0/tests/test_clickdust.py +537 -0
@@ -0,0 +1,10 @@
1
+ .venv/
2
+ dist/
3
+ __pycache__/
4
+ *.egg-info/
5
+ .pytest_cache/
6
+ .lavish/
7
+ *.db
8
+ out/
9
+ brag-output/
10
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sanketsans
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.5
2
+ Name: clickdust
3
+ Version: 0.4.0
4
+ Summary: Your Claude Code sessions grow an ink forest: a tree each session, a forest each month. Local-first.
5
+ Project-URL: Homepage, https://github.com/sanketsans/clickdust
6
+ Project-URL: Source, https://github.com/sanketsans/clickdust
7
+ Project-URL: Issues, https://github.com/sanketsans/clickdust/issues
8
+ Author: sanketsans
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: claude-code,data-art,generative-art,keyboard,mouse,quantified-self
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Artistic Software
17
+ Requires-Python: >=3.9
18
+ Requires-Dist: pynput>=1.8; sys_platform != 'darwin'
19
+ Requires-Dist: pyobjc-framework-quartz>=10; sys_platform == 'darwin'
20
+ Requires-Dist: screeninfo>=0.8; sys_platform != 'darwin'
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=8; extra == 'dev'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # clickdust
26
+
27
+ Your Claude Code sessions grow an ink forest: a tree for each session, a new scene each month.
28
+ Drag the sun to travel through the year.
29
+
30
+ ![A month of sessions as a maple forest](docs/forest.png)
31
+
32
+ *All pictures here use made-up data (`clickdust landscape --demo`).*
33
+
34
+ ## How to read it
35
+
36
+ | In the picture | Comes from |
37
+ |---|---|
38
+ | Tree | one Claude Code session |
39
+ | Name | made up from a hash of the session; the title reflects its shape (*the Boomerang*, *the One-Liner*) |
40
+ | Limb | a day you worked in that session; a new one grows from the fork each time you come back, in lighter bark |
41
+ | Cloud of leaves | one message you sent, on the limb of its day |
42
+ | **Red** leaves | your side: `3 + 4 × √(typed ÷ 100)` for each message |
43
+ | **Gold** leaves | Claude: `2 × √(output tokens ÷ 1,000)` for each answer |
44
+ | Left to right | day of the month |
45
+ | Trees, sky, ground | the season of the month: winter plum, cherry, willow, maple |
46
+ | Near and large | bigger sessions; small ones form the distant treeline |
47
+ | Dark mountains | your typing per day |
48
+ | Gold mountains behind | Claude's output tokens per day; each range is scaled to its own busiest day of the month |
49
+ | Sun | high in summer, low in winter; its flares are long pointer movements, each pointing the way you moved (months before tracking began have none) |
50
+ | Snow, rain, glow, falling leaves | weather for the season: decoration, not data |
51
+ | Dry leaves | mouse clicks that day |
52
+ | Bird | a day with 55 minutes of messages, no pause over 15 |
53
+ | Deer | a weekend without a message |
54
+ | Owl | lives in the tree whose session had a message between midnight and 5 am, on that day's limb; open the tree to meet it |
55
+
56
+ *Typed* is the key presses counted in the five minutes before a message. Where the tracker saw none,
57
+ it is the length of the message (long pastes capped at 2,000).
58
+
59
+ ## Explore
60
+
61
+ ![One tree with its history](docs/tree.png)
62
+
63
+ Growth never moves what is already there: a tree keeps its shape as messages arrive, and its wood
64
+ thickens. Where it stands in the forest can change as bigger sessions arrive.
65
+
66
+ | Move | Mouse / trackpad | Keys |
67
+ |---|---|---|
68
+ | Open a tree | click it, or its dot under the picture | `←` `→` or `h` `l` |
69
+ | Reach a tree behind | scroll while pointing at it, or hover its dot | `b` |
70
+ | Travel | drag, or two fingers sideways | |
71
+ | Zoom | pinch, double-click, `+` `−` buttons | `+` `-` `0` |
72
+ | Change month | drag the sun, flick it, or scroll on it | `↑` `↓` or `k` `j` |
73
+ | Play the month | ▶ button, or drag the time line | `Space` |
74
+ | Close a tree | ✕ | `Esc` |
75
+
76
+ **Auto** shows ink by day and dusk by night. **Sound** plays a tree: ticks for your leaves, notes for Claude's.
77
+
78
+ ![The same month at dusk](docs/dusk.png)
79
+
80
+ ## Install
81
+
82
+ ```bash
83
+ uv tool install . # or: pipx install .
84
+ clickdust landscape --demo --open # look first; records nothing
85
+ ```
86
+
87
+ ## Start
88
+
89
+ | Step | Command | |
90
+ |---|---|---|
91
+ | 1 | `clickdust landscape --open` | trees from your existing Claude Code logs, straight away |
92
+ | 2 | `clickdust doctor --request` | allow your terminal under *System Settings → Privacy & Security → Input Monitoring*, then reopen it |
93
+ | 3 | `clickdust probe` | 30-second live test; says why anything is missing, saves nothing |
94
+ | 4 | `clickdust start` | record keys and pointer, and keep saving session numbers |
95
+ | 5 | `clickdust status` | today's counts and how many trees are saved |
96
+
97
+ **Keep it running.** Claude Code deletes session logs after 30 days (its `cleanupPeriodDays`
98
+ setting). clickdust copies the numbers every 15 minutes while it runs, and whenever you run
99
+ `landscape`, `publish` or `harvest`. Recording does not restart after a reboot or logout.
100
+
101
+ **Upgrading:** `clickdust stop && uv tool install --reinstall . && clickdust start`
102
+
103
+ | Option | Effect |
104
+ |---|---|
105
+ | `start --no-claude` | do not read Claude Code logs (also on `landscape`, `publish`) |
106
+ | `start --no-keys`, `--no-trail` | leave out key counts or cursor movement |
107
+ | `landscape --trees maple` | maple all year (default: a tree for each season); also on `publish` |
108
+ | `--south` | southern hemisphere seasons |
109
+
110
+ ## Put it on your website
111
+
112
+ ```bash
113
+ clickdust publish --site ~/path/to/your-site # writes your-site/forest/
114
+ ```
115
+
116
+ ```
117
+ up to last Sunday ──▶ reduced ──▶ forest/ ──▶ you review ──▶ git commit + push
118
+ ```
119
+
120
+ `publish` only writes files and prints the git commands. It never runs git, never includes the current
121
+ week, and never deletes months already there. The folder is plain static files, so GitHub Pages
122
+ (including Jekyll) serves it at `/forest/`. Add a menu link yourself, or frame it in one of your pages.
123
+
124
+ | In the public files | Left out |
125
+ |---|---|
126
+ | each tree's day, red and gold leaves for each message, message order, which days had a message after midnight | clock times, typed and token counts for each tree |
127
+ | typing per day, rounded to 500; Claude's output tokens per day, rounded to 5,000 | active minutes, compactions, helper agents |
128
+ | dry leaves per day, sun flares as direction and distance (rounded, no screen position), animal days | session ids, prompts, replies, titles, project names |
129
+
130
+ Leaf counts follow the equation, so a reader can estimate the size of a message or answer, and sees
131
+ which days you were active and how much.
132
+
133
+ ### Publish every week by itself (macOS)
134
+
135
+ `publish` only writes files. `autopublish` is the one command that runs git: it pulls your site, publishes the finished week, commits **only** the forest folder and pushes. It refuses to run if the site is not on the Pages branch.
136
+
137
+ ```
138
+ clickdust schedule --site ~/path/to/you.github.io # every Monday at 09:00 (a missed run happens when the Mac wakes)
139
+ clickdust autopublish --site ~/path/to/you.github.io # the same job, once, right now
140
+ clickdust schedule --remove # stop it
141
+ ```
142
+
143
+ The log is `autopublish.log` in the clickdust data folder. What goes public is the same reduced data as `publish`.
144
+
145
+ ## Privacy
146
+
147
+ | Stored on your machine | Never stored |
148
+ |---|---|
149
+ | click and cursor positions, time, button | which keys you press, or their order |
150
+ | how many keys went down in each 10-second slot | the text you type or Claude writes |
151
+ | device class: built-in or external | window titles, application or project names, screenshots |
152
+ | for Claude Code: time and length of your messages, time and output tokens of replies, compactions, helper agents, a hash per session | session titles, file paths |
153
+ | monitor rectangles | |
154
+
155
+ - On macOS the key code is never read from the event; only whether it is an auto-repeat.
156
+ - Keys are ignored while macOS Secure Input is on (password fields).
157
+ - Session logs are read to count; message text is measured and discarded.
158
+ - There is no network code. `clickdust doctor` prints where the database lives.
159
+ - `clickdust purge --all` deletes the data, and older sessions are not read back in. Pages you already
160
+ built or published stay as they are.
161
+
162
+ If this is a work computer, check that your employer allows input tracking and publishing activity data.
163
+
164
+ ## Platforms
165
+
166
+ | | Keys and clicks | Claude Code logs |
167
+ |---|---|---|
168
+ | macOS | event tap | `~/.claude` or `CLAUDE_CONFIG_DIR` |
169
+ | Windows | through pynput, untested | same, untested |
170
+ | Linux X11 | through pynput, untested | same, untested |
171
+ | Linux Wayland | not supported | works without the tracker |
172
+
173
+ The log format is Claude Code's own and may change with its versions. Without Claude Code there are
174
+ no trees.
175
+
176
+ ## Also included: single-day pictures
177
+
178
+ `clickdust render --style dots|constellation|ripples|trails --open` draws one day's pointer data as SVG.
179
+
180
+ ## Develop
181
+
182
+ ```bash
183
+ uv venv && uv pip install -e '.[dev]' && .venv/bin/pytest
184
+ ```
185
+
186
+ ```
187
+ src/clickdust/
188
+ backends/ OS input → sink calls (macos.py, hid.py, generic.py)
189
+ tracker.py recording loop claude.py session log numbers
190
+ store.py SQLite
191
+ landscape/ model.py → export.py → site.py
192
+ web/ the page: viewer.js, viewer.css, index.html
193
+ render/ the single-day SVG styles
194
+ ```
@@ -0,0 +1,170 @@
1
+ # clickdust
2
+
3
+ Your Claude Code sessions grow an ink forest: a tree for each session, a new scene each month.
4
+ Drag the sun to travel through the year.
5
+
6
+ ![A month of sessions as a maple forest](docs/forest.png)
7
+
8
+ *All pictures here use made-up data (`clickdust landscape --demo`).*
9
+
10
+ ## How to read it
11
+
12
+ | In the picture | Comes from |
13
+ |---|---|
14
+ | Tree | one Claude Code session |
15
+ | Name | made up from a hash of the session; the title reflects its shape (*the Boomerang*, *the One-Liner*) |
16
+ | Limb | a day you worked in that session; a new one grows from the fork each time you come back, in lighter bark |
17
+ | Cloud of leaves | one message you sent, on the limb of its day |
18
+ | **Red** leaves | your side: `3 + 4 × √(typed ÷ 100)` for each message |
19
+ | **Gold** leaves | Claude: `2 × √(output tokens ÷ 1,000)` for each answer |
20
+ | Left to right | day of the month |
21
+ | Trees, sky, ground | the season of the month: winter plum, cherry, willow, maple |
22
+ | Near and large | bigger sessions; small ones form the distant treeline |
23
+ | Dark mountains | your typing per day |
24
+ | Gold mountains behind | Claude's output tokens per day; each range is scaled to its own busiest day of the month |
25
+ | Sun | high in summer, low in winter; its flares are long pointer movements, each pointing the way you moved (months before tracking began have none) |
26
+ | Snow, rain, glow, falling leaves | weather for the season: decoration, not data |
27
+ | Dry leaves | mouse clicks that day |
28
+ | Bird | a day with 55 minutes of messages, no pause over 15 |
29
+ | Deer | a weekend without a message |
30
+ | Owl | lives in the tree whose session had a message between midnight and 5 am, on that day's limb; open the tree to meet it |
31
+
32
+ *Typed* is the key presses counted in the five minutes before a message. Where the tracker saw none,
33
+ it is the length of the message (long pastes capped at 2,000).
34
+
35
+ ## Explore
36
+
37
+ ![One tree with its history](docs/tree.png)
38
+
39
+ Growth never moves what is already there: a tree keeps its shape as messages arrive, and its wood
40
+ thickens. Where it stands in the forest can change as bigger sessions arrive.
41
+
42
+ | Move | Mouse / trackpad | Keys |
43
+ |---|---|---|
44
+ | Open a tree | click it, or its dot under the picture | `←` `→` or `h` `l` |
45
+ | Reach a tree behind | scroll while pointing at it, or hover its dot | `b` |
46
+ | Travel | drag, or two fingers sideways | |
47
+ | Zoom | pinch, double-click, `+` `−` buttons | `+` `-` `0` |
48
+ | Change month | drag the sun, flick it, or scroll on it | `↑` `↓` or `k` `j` |
49
+ | Play the month | ▶ button, or drag the time line | `Space` |
50
+ | Close a tree | ✕ | `Esc` |
51
+
52
+ **Auto** shows ink by day and dusk by night. **Sound** plays a tree: ticks for your leaves, notes for Claude's.
53
+
54
+ ![The same month at dusk](docs/dusk.png)
55
+
56
+ ## Install
57
+
58
+ ```bash
59
+ uv tool install . # or: pipx install .
60
+ clickdust landscape --demo --open # look first; records nothing
61
+ ```
62
+
63
+ ## Start
64
+
65
+ | Step | Command | |
66
+ |---|---|---|
67
+ | 1 | `clickdust landscape --open` | trees from your existing Claude Code logs, straight away |
68
+ | 2 | `clickdust doctor --request` | allow your terminal under *System Settings → Privacy & Security → Input Monitoring*, then reopen it |
69
+ | 3 | `clickdust probe` | 30-second live test; says why anything is missing, saves nothing |
70
+ | 4 | `clickdust start` | record keys and pointer, and keep saving session numbers |
71
+ | 5 | `clickdust status` | today's counts and how many trees are saved |
72
+
73
+ **Keep it running.** Claude Code deletes session logs after 30 days (its `cleanupPeriodDays`
74
+ setting). clickdust copies the numbers every 15 minutes while it runs, and whenever you run
75
+ `landscape`, `publish` or `harvest`. Recording does not restart after a reboot or logout.
76
+
77
+ **Upgrading:** `clickdust stop && uv tool install --reinstall . && clickdust start`
78
+
79
+ | Option | Effect |
80
+ |---|---|
81
+ | `start --no-claude` | do not read Claude Code logs (also on `landscape`, `publish`) |
82
+ | `start --no-keys`, `--no-trail` | leave out key counts or cursor movement |
83
+ | `landscape --trees maple` | maple all year (default: a tree for each season); also on `publish` |
84
+ | `--south` | southern hemisphere seasons |
85
+
86
+ ## Put it on your website
87
+
88
+ ```bash
89
+ clickdust publish --site ~/path/to/your-site # writes your-site/forest/
90
+ ```
91
+
92
+ ```
93
+ up to last Sunday ──▶ reduced ──▶ forest/ ──▶ you review ──▶ git commit + push
94
+ ```
95
+
96
+ `publish` only writes files and prints the git commands. It never runs git, never includes the current
97
+ week, and never deletes months already there. The folder is plain static files, so GitHub Pages
98
+ (including Jekyll) serves it at `/forest/`. Add a menu link yourself, or frame it in one of your pages.
99
+
100
+ | In the public files | Left out |
101
+ |---|---|
102
+ | each tree's day, red and gold leaves for each message, message order, which days had a message after midnight | clock times, typed and token counts for each tree |
103
+ | typing per day, rounded to 500; Claude's output tokens per day, rounded to 5,000 | active minutes, compactions, helper agents |
104
+ | dry leaves per day, sun flares as direction and distance (rounded, no screen position), animal days | session ids, prompts, replies, titles, project names |
105
+
106
+ Leaf counts follow the equation, so a reader can estimate the size of a message or answer, and sees
107
+ which days you were active and how much.
108
+
109
+ ### Publish every week by itself (macOS)
110
+
111
+ `publish` only writes files. `autopublish` is the one command that runs git: it pulls your site, publishes the finished week, commits **only** the forest folder and pushes. It refuses to run if the site is not on the Pages branch.
112
+
113
+ ```
114
+ clickdust schedule --site ~/path/to/you.github.io # every Monday at 09:00 (a missed run happens when the Mac wakes)
115
+ clickdust autopublish --site ~/path/to/you.github.io # the same job, once, right now
116
+ clickdust schedule --remove # stop it
117
+ ```
118
+
119
+ The log is `autopublish.log` in the clickdust data folder. What goes public is the same reduced data as `publish`.
120
+
121
+ ## Privacy
122
+
123
+ | Stored on your machine | Never stored |
124
+ |---|---|
125
+ | click and cursor positions, time, button | which keys you press, or their order |
126
+ | how many keys went down in each 10-second slot | the text you type or Claude writes |
127
+ | device class: built-in or external | window titles, application or project names, screenshots |
128
+ | for Claude Code: time and length of your messages, time and output tokens of replies, compactions, helper agents, a hash per session | session titles, file paths |
129
+ | monitor rectangles | |
130
+
131
+ - On macOS the key code is never read from the event; only whether it is an auto-repeat.
132
+ - Keys are ignored while macOS Secure Input is on (password fields).
133
+ - Session logs are read to count; message text is measured and discarded.
134
+ - There is no network code. `clickdust doctor` prints where the database lives.
135
+ - `clickdust purge --all` deletes the data, and older sessions are not read back in. Pages you already
136
+ built or published stay as they are.
137
+
138
+ If this is a work computer, check that your employer allows input tracking and publishing activity data.
139
+
140
+ ## Platforms
141
+
142
+ | | Keys and clicks | Claude Code logs |
143
+ |---|---|---|
144
+ | macOS | event tap | `~/.claude` or `CLAUDE_CONFIG_DIR` |
145
+ | Windows | through pynput, untested | same, untested |
146
+ | Linux X11 | through pynput, untested | same, untested |
147
+ | Linux Wayland | not supported | works without the tracker |
148
+
149
+ The log format is Claude Code's own and may change with its versions. Without Claude Code there are
150
+ no trees.
151
+
152
+ ## Also included: single-day pictures
153
+
154
+ `clickdust render --style dots|constellation|ripples|trails --open` draws one day's pointer data as SVG.
155
+
156
+ ## Develop
157
+
158
+ ```bash
159
+ uv venv && uv pip install -e '.[dev]' && .venv/bin/pytest
160
+ ```
161
+
162
+ ```
163
+ src/clickdust/
164
+ backends/ OS input → sink calls (macos.py, hid.py, generic.py)
165
+ tracker.py recording loop claude.py session log numbers
166
+ store.py SQLite
167
+ landscape/ model.py → export.py → site.py
168
+ web/ the page: viewer.js, viewer.css, index.html
169
+ render/ the single-day SVG styles
170
+ ```
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "clickdust"
7
+ version = "0.4.0"
8
+ description = "Your Claude Code sessions grow an ink forest: a tree each session, a forest each month. Local-first."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "sanketsans" }]
13
+ requires-python = ">=3.9"
14
+ keywords = ["claude-code", "keyboard", "mouse", "generative-art", "quantified-self", "data-art"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: Console",
18
+ "Operating System :: MacOS",
19
+ "Programming Language :: Python :: 3",
20
+ "Topic :: Artistic Software",
21
+ ]
22
+ dependencies = [
23
+ "pyobjc-framework-Quartz>=10; sys_platform == 'darwin'",
24
+ "pynput>=1.8; sys_platform != 'darwin'",
25
+ "screeninfo>=0.8; sys_platform != 'darwin'",
26
+ ]
27
+
28
+ [project.optional-dependencies]
29
+ dev = ["pytest>=8"]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/sanketsans/clickdust"
33
+ Source = "https://github.com/sanketsans/clickdust"
34
+ Issues = "https://github.com/sanketsans/clickdust/issues"
35
+
36
+ [project.scripts]
37
+ clickdust = "clickdust.cli:main"
38
+
39
+ [tool.hatch.build.targets.wheel]
40
+ packages = ["src/clickdust"]
41
+
42
+ [tool.hatch.build.targets.sdist]
43
+ include = ["src", "tests", "README.md", "LICENSE", "pyproject.toml"]
@@ -0,0 +1,3 @@
1
+ """clickdust: turn a day of clicking into generative art."""
2
+
3
+ __version__ = "0.4.0"
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,29 @@
1
+ """Input backends turn operating-system events into calls on a sink.
2
+
3
+ A sink has three methods:
4
+
5
+ on_key(device) one key went down (which key is never passed)
6
+ on_click(x, y, button, pressed, device)
7
+ on_move(x, y, device)
8
+
9
+ `device` is "int" (built into the computer), "ext" (plugged in or wireless) or "unknown".
10
+ """
11
+
12
+ import sys
13
+
14
+ UNKNOWN = "unknown"
15
+
16
+
17
+ class BackendError(RuntimeError):
18
+ """The operating system would not let us listen."""
19
+
20
+
21
+ def open_backend(sink, keys: bool = True):
22
+ """Return a started backend with pump(seconds), alive(), close() and a list of `notes`."""
23
+ if sys.platform == "darwin":
24
+ from .macos import MacBackend
25
+
26
+ return MacBackend(sink, keys)
27
+ from .generic import PynputBackend
28
+
29
+ return PynputBackend(sink, keys)
@@ -0,0 +1,45 @@
1
+ """Windows and Linux (X11) through pynput. Devices are not told apart here."""
2
+
3
+ import time
4
+
5
+ from . import UNKNOWN, BackendError
6
+
7
+
8
+ class PynputBackend:
9
+ def __init__(self, sink, keys: bool = True):
10
+ try:
11
+ from pynput import keyboard, mouse
12
+ except Exception as error:
13
+ raise BackendError(f"Cannot load the input library: {error}")
14
+ self.notes = ["Built-in and external devices are not told apart on this system."]
15
+ # Held keys stay in memory only, to ignore auto-repeat. Nothing about them is passed on.
16
+ held = set()
17
+
18
+ def press(key):
19
+ if key not in held:
20
+ held.add(key)
21
+ sink.on_key(UNKNOWN)
22
+
23
+ self._listeners = [
24
+ mouse.Listener(
25
+ on_move=lambda x, y: sink.on_move(x, y),
26
+ on_click=lambda x, y, button, pressed: sink.on_click(
27
+ x, y, getattr(button, "name", str(button)), pressed, UNKNOWN
28
+ ),
29
+ )
30
+ ]
31
+ if keys:
32
+ self._listeners.append(keyboard.Listener(on_press=press, on_release=held.discard))
33
+ for listener in self._listeners:
34
+ listener.start()
35
+ listener.wait()
36
+
37
+ def pump(self, seconds: float) -> None:
38
+ time.sleep(seconds)
39
+
40
+ def alive(self) -> bool:
41
+ return all(listener.is_alive() for listener in self._listeners)
42
+
43
+ def close(self) -> None:
44
+ for listener in self._listeners:
45
+ listener.stop()
@@ -0,0 +1,153 @@
1
+ """Which physical device was used last? (macOS, via IOKit's HID manager.)
2
+
3
+ The event tap says *what* happened but not on which keyboard or mouse. IOKit does know the
4
+ device behind each raw input value, so we remember the most recent one for each kind.
5
+
6
+ Privacy: for a raw value we read only its usage *page* (is it a key, a button, a pointer?),
7
+ never its usage (which key) and never its value (what was typed).
8
+ """
9
+
10
+ import ctypes
11
+ from ctypes import c_char_p, c_int32, c_long, c_uint32, c_void_p
12
+
13
+ from . import UNKNOWN
14
+
15
+ GENERIC_DESKTOP, KEYBOARD_PAGE, BUTTON_PAGE, DIGITIZER_PAGE = 0x01, 0x07, 0x09, 0x0D
16
+ # (usage page, usage): keyboard, mouse, pointer, touchpad, multitouch surface
17
+ WANTED = [(GENERIC_DESKTOP, 6), (GENERIC_DESKTOP, 2), (GENERIC_DESKTOP, 1), (DIGITIZER_PAGE, 5), (DIGITIZER_PAGE, 12)]
18
+ BUILT_IN_TRANSPORTS = {"FIFO", "SPI", "SPU"}
19
+ _UTF8 = 0x08000100
20
+ _SINT32 = 3
21
+
22
+ _Callback = ctypes.CFUNCTYPE(None, c_void_p, c_int32, c_void_p, c_void_p)
23
+
24
+
25
+ def classify(built_in, transport) -> str:
26
+ if built_in or transport in BUILT_IN_TRANSPORTS:
27
+ return "int"
28
+ if built_in is None and not transport:
29
+ return UNKNOWN
30
+ return "ext"
31
+
32
+
33
+ def kind_of(usage_page: int):
34
+ if usage_page == KEYBOARD_PAGE:
35
+ return "keyboard"
36
+ if usage_page in (GENERIC_DESKTOP, BUTTON_PAGE, DIGITIZER_PAGE):
37
+ return "pointer"
38
+ return None
39
+
40
+
41
+ def _libraries():
42
+ cf = ctypes.CDLL("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")
43
+ io = ctypes.CDLL("/System/Library/Frameworks/IOKit.framework/IOKit")
44
+
45
+ def declare(lib, name, result, *arguments):
46
+ function = getattr(lib, name)
47
+ function.restype, function.argtypes = result, list(arguments)
48
+
49
+ declare(cf, "CFStringCreateWithCString", c_void_p, c_void_p, c_char_p, c_uint32)
50
+ declare(cf, "CFStringGetCString", ctypes.c_bool, c_void_p, c_char_p, c_long, c_uint32)
51
+ declare(cf, "CFGetTypeID", c_long, c_void_p)
52
+ declare(cf, "CFStringGetTypeID", c_long)
53
+ declare(cf, "CFNumberGetTypeID", c_long)
54
+ declare(cf, "CFBooleanGetTypeID", c_long)
55
+ declare(cf, "CFNumberGetValue", ctypes.c_bool, c_void_p, c_long, c_void_p)
56
+ declare(cf, "CFBooleanGetValue", ctypes.c_bool, c_void_p)
57
+ declare(cf, "CFSetGetCount", c_long, c_void_p)
58
+ declare(cf, "CFSetGetValues", None, c_void_p, ctypes.POINTER(c_void_p))
59
+ declare(cf, "CFRunLoopGetCurrent", c_void_p)
60
+ declare(cf, "CFRelease", None, c_void_p)
61
+ declare(io, "IOHIDManagerCreate", c_void_p, c_void_p, c_uint32)
62
+ declare(io, "IOHIDManagerSetDeviceMatchingMultiple", None, c_void_p, c_void_p)
63
+ declare(io, "IOHIDManagerRegisterInputValueCallback", None, c_void_p, _Callback, c_void_p)
64
+ declare(io, "IOHIDManagerScheduleWithRunLoop", None, c_void_p, c_void_p, c_void_p)
65
+ declare(io, "IOHIDManagerUnscheduleFromRunLoop", None, c_void_p, c_void_p, c_void_p)
66
+ declare(io, "IOHIDManagerOpen", c_int32, c_void_p, c_uint32)
67
+ declare(io, "IOHIDManagerClose", c_int32, c_void_p, c_uint32)
68
+ declare(io, "IOHIDManagerCopyDevices", c_void_p, c_void_p)
69
+ declare(io, "IOHIDDeviceGetProperty", c_void_p, c_void_p, c_void_p)
70
+ declare(io, "IOHIDValueGetElement", c_void_p, c_void_p)
71
+ declare(io, "IOHIDElementGetDevice", c_void_p, c_void_p)
72
+ declare(io, "IOHIDElementGetUsagePage", c_uint32, c_void_p)
73
+ return cf, io
74
+
75
+
76
+ class DeviceTracker:
77
+ def __init__(self):
78
+ import objc
79
+ from Foundation import NSArray
80
+
81
+ self.cf, self.io = _libraries()
82
+ self.last = {"keyboard": UNKNOWN, "pointer": UNKNOWN}
83
+ self._cache = {}
84
+ self._keys = {name: self._string(name) for name in ("Built-In", "Transport", "Product")}
85
+ # NSArray is toll-free bridged to CFArray; keep a reference for as long as the manager lives
86
+ self._matching = NSArray.arrayWithArray_(
87
+ [{"DeviceUsagePage": page, "DeviceUsage": usage} for page, usage in WANTED]
88
+ )
89
+ self.manager = self.io.IOHIDManagerCreate(None, 0)
90
+ self.io.IOHIDManagerSetDeviceMatchingMultiple(self.manager, objc.pyobjc_id(self._matching))
91
+ self._callback = None
92
+ self._mode = c_void_p.in_dll(self.cf, "kCFRunLoopDefaultMode")
93
+
94
+ def _string(self, text):
95
+ return self.cf.CFStringCreateWithCString(None, text.encode(), _UTF8)
96
+
97
+ def _property(self, device, name):
98
+ ref = self.io.IOHIDDeviceGetProperty(device, self._keys[name])
99
+ if not ref:
100
+ return None
101
+ kind = self.cf.CFGetTypeID(ref)
102
+ if kind == self.cf.CFBooleanGetTypeID():
103
+ return bool(self.cf.CFBooleanGetValue(ref))
104
+ if kind == self.cf.CFNumberGetTypeID():
105
+ number = c_int32()
106
+ self.cf.CFNumberGetValue(ref, _SINT32, ctypes.byref(number))
107
+ return number.value
108
+ if kind == self.cf.CFStringGetTypeID():
109
+ buffer = ctypes.create_string_buffer(256)
110
+ if self.cf.CFStringGetCString(ref, buffer, len(buffer), _UTF8):
111
+ return buffer.value.decode("utf-8", "replace")
112
+ return None
113
+
114
+ def _class_of(self, device) -> str:
115
+ if device not in self._cache:
116
+ self._cache[device] = classify(self._property(device, "Built-In"), self._property(device, "Transport"))
117
+ return self._cache[device]
118
+
119
+ def devices(self):
120
+ """Connected keyboards and pointers as (product, class). Reads no input."""
121
+ found = self.io.IOHIDManagerCopyDevices(self.manager)
122
+ if not found:
123
+ return []
124
+ count = self.cf.CFSetGetCount(found)
125
+ values = (c_void_p * count)()
126
+ self.cf.CFSetGetValues(found, values)
127
+ result = sorted({(self._property(d, "Product") or "unnamed", self._class_of(d)) for d in values})
128
+ self._cache.clear()
129
+ self.cf.CFRelease(found)
130
+ return result
131
+
132
+ def start(self) -> bool:
133
+ """Listen on the current run loop. False if macOS refuses."""
134
+
135
+ def seen(_context, _result, _sender, value):
136
+ element = self.io.IOHIDValueGetElement(value)
137
+ kind = kind_of(self.io.IOHIDElementGetUsagePage(element))
138
+ if kind:
139
+ self.last[kind] = self._class_of(self.io.IOHIDElementGetDevice(element))
140
+
141
+ self._callback = _Callback(seen)
142
+ self.io.IOHIDManagerRegisterInputValueCallback(self.manager, self._callback, None)
143
+ self.io.IOHIDManagerScheduleWithRunLoop(self.manager, self.cf.CFRunLoopGetCurrent(), self._mode)
144
+ if self.io.IOHIDManagerOpen(self.manager, 0) != 0:
145
+ self.close()
146
+ return False
147
+ return True
148
+
149
+ def close(self):
150
+ if self._callback:
151
+ self.io.IOHIDManagerUnscheduleFromRunLoop(self.manager, self.cf.CFRunLoopGetCurrent(), self._mode)
152
+ self.io.IOHIDManagerClose(self.manager, 0)
153
+ self._callback = None