tesserae-shell 0.1.1__py3-none-any.whl

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 (177) hide show
  1. tess_shell/__init__.py +22 -0
  2. tess_shell/__main__.py +3 -0
  3. tess_shell/app.py +509 -0
  4. tess_shell/appearance.py +27 -0
  5. tess_shell/binder/__init__.py +5 -0
  6. tess_shell/binder/build.py +1423 -0
  7. tess_shell/binder/controls.py +724 -0
  8. tess_shell/binder/convert.py +472 -0
  9. tess_shell/binder/defaults.py +154 -0
  10. tess_shell/binder/focus.py +70 -0
  11. tess_shell/binder/images.py +165 -0
  12. tess_shell/binder/marquee.py +192 -0
  13. tess_shell/binder/model.py +361 -0
  14. tess_shell/binder/motion.py +185 -0
  15. tess_shell/binder/rebuild.py +202 -0
  16. tess_shell/binder/shadow.py +87 -0
  17. tess_shell/binder/shapes.py +70 -0
  18. tess_shell/binder/tables.py +450 -0
  19. tess_shell/cli.py +163 -0
  20. tess_shell/client.py +236 -0
  21. tess_shell/commands.py +154 -0
  22. tess_shell/config/__init__.py +1 -0
  23. tess_shell/config/discovery.py +49 -0
  24. tess_shell/config/lock.py +55 -0
  25. tess_shell/config/paths.py +82 -0
  26. tess_shell/config/registry.py +163 -0
  27. tess_shell/config/settings.py +597 -0
  28. tess_shell/config/uids.py +104 -0
  29. tess_shell/exit_codes.py +35 -0
  30. tess_shell/files/__init__.py +1 -0
  31. tess_shell/files/header.py +63 -0
  32. tess_shell/files/icons.py +108 -0
  33. tess_shell/files/loader.py +205 -0
  34. tess_shell/logging.py +280 -0
  35. tess_shell/model/__init__.py +5 -0
  36. tess_shell/model/args.py +170 -0
  37. tess_shell/model/expand.py +528 -0
  38. tess_shell/model/field.py +215 -0
  39. tess_shell/model/icons.py +42 -0
  40. tess_shell/model/live.py +596 -0
  41. tess_shell/model/look.py +505 -0
  42. tess_shell/model/marquee.py +69 -0
  43. tess_shell/model/store.py +148 -0
  44. tess_shell/model/uses.py +104 -0
  45. tess_shell/module.py +86 -0
  46. tess_shell/modules/__init__.py +1 -0
  47. tess_shell/modules/context.py +322 -0
  48. tess_shell/modules/host.py +783 -0
  49. tess_shell/modules/ticks.py +117 -0
  50. tess_shell/options.py +12 -0
  51. tess_shell/py.typed +0 -0
  52. tess_shell/reloader.py +317 -0
  53. tess_shell/scanner.py +317 -0
  54. tess_shell/schema/__init__.py +1 -0
  55. tess_shell/schema/blocks.py +687 -0
  56. tess_shell/schema/default_popups.py +118 -0
  57. tess_shell/schema/docs.py +1087 -0
  58. tess_shell/schema/export.py +1514 -0
  59. tess_shell/schema/findings.py +76 -0
  60. tess_shell/schema/graph.py +64 -0
  61. tess_shell/schema/keys.py +264 -0
  62. tess_shell/schema/look.py +340 -0
  63. tess_shell/schema/model.py +323 -0
  64. tess_shell/schema/ranges.py +125 -0
  65. tess_shell/schema/shell.py +2946 -0
  66. tess_shell/schema/style.py +68 -0
  67. tess_shell/schema/tree.py +93 -0
  68. tess_shell/schema/values.py +569 -0
  69. tess_shell/services/__init__.py +0 -0
  70. tess_shell/services/api.py +384 -0
  71. tess_shell/services/audio.py +576 -0
  72. tess_shell/services/bus.py +820 -0
  73. tess_shell/services/control.py +416 -0
  74. tess_shell/services/icons.py +503 -0
  75. tess_shell/services/layer.py +762 -0
  76. tess_shell/services/portal.py +264 -0
  77. tess_shell/services/pulse_native.py +512 -0
  78. tess_shell/services/shortcuts.py +502 -0
  79. tess_shell/services/tray.py +216 -0
  80. tess_shell/shipped/Audio/Audio_Module.py +236 -0
  81. tess_shell/shipped/Audio/Audio_Module.tdl +124 -0
  82. tess_shell/shipped/Audio/Audio_Style.tdl +15 -0
  83. tess_shell/shipped/Audio_Outputs/Audio_Outputs_Module.py +18 -0
  84. tess_shell/shipped/Audio_Outputs/Audio_Outputs_Module.tdl +36 -0
  85. tess_shell/shipped/Badge/Badge_Module.py +9 -0
  86. tess_shell/shipped/Badge/Badge_Module.tdl +42 -0
  87. tess_shell/shipped/Battery/Battery_Module.py +174 -0
  88. tess_shell/shipped/Battery/Battery_Module.tdl +139 -0
  89. tess_shell/shipped/Battery/Battery_Style.tdl +15 -0
  90. tess_shell/shipped/Button/Button_Module.py +23 -0
  91. tess_shell/shipped/Button/Button_Module.tdl +58 -0
  92. tess_shell/shipped/Checkbox/Checkbox_Module.py +10 -0
  93. tess_shell/shipped/Checkbox/Checkbox_Module.tdl +59 -0
  94. tess_shell/shipped/Clock/Clock_Module.py +138 -0
  95. tess_shell/shipped/Clock/Clock_Module.tdl +57 -0
  96. tess_shell/shipped/Clock/Clock_Style.tdl +16 -0
  97. tess_shell/shipped/Expander/Expander_Module.py +20 -0
  98. tess_shell/shipped/Expander/Expander_Module.tdl +50 -0
  99. tess_shell/shipped/Handles/NOTICE.txt +5 -0
  100. tess_shell/shipped/Handles/tess_shell_bar.svg +3 -0
  101. tess_shell/shipped/Handles/tess_shell_chevron.svg +3 -0
  102. tess_shell/shipped/Handles/tess_shell_dots.svg +5 -0
  103. tess_shell/shipped/Icon/Icon_Module.py +17 -0
  104. tess_shell/shipped/Icon/Icon_Module.tdl +36 -0
  105. tess_shell/shipped/Icons/MDI-LICENSE.txt +20 -0
  106. tess_shell/shipped/Icons/NOTICE.txt +9 -0
  107. tess_shell/shipped/Icons/mdi.json +22357 -0
  108. tess_shell/shipped/Image/Image_Module.py +18 -0
  109. tess_shell/shipped/Image/Image_Module.tdl +48 -0
  110. tess_shell/shipped/Images/error.png +0 -0
  111. tess_shell/shipped/Label/Label_Module.py +9 -0
  112. tess_shell/shipped/Label/Label_Module.tdl +22 -0
  113. tess_shell/shipped/List/List_Module.py +22 -0
  114. tess_shell/shipped/List/List_Module.tdl +48 -0
  115. tess_shell/shipped/Marquee_Text/Marquee_Text_Module.py +22 -0
  116. tess_shell/shipped/Marquee_Text/Marquee_Text_Module.tdl +35 -0
  117. tess_shell/shipped/Media/Media_Module.py +503 -0
  118. tess_shell/shipped/Media/Media_Module.tdl +112 -0
  119. tess_shell/shipped/Menu/Menu_Module.py +10 -0
  120. tess_shell/shipped/Menu/Menu_Module.tdl +32 -0
  121. tess_shell/shipped/MenuItem/MenuItem_Module.py +20 -0
  122. tess_shell/shipped/MenuItem/MenuItem_Module.tdl +88 -0
  123. tess_shell/shipped/Network/Network_Module.py +416 -0
  124. tess_shell/shipped/Network/Network_Module.tdl +164 -0
  125. tess_shell/shipped/Network/Network_Style.tdl +15 -0
  126. tess_shell/shipped/ProgressBar/ProgressBar_Module.py +17 -0
  127. tess_shell/shipped/ProgressBar/ProgressBar_Module.tdl +39 -0
  128. tess_shell/shipped/Slider/Slider_Module.py +24 -0
  129. tess_shell/shipped/Slider/Slider_Module.tdl +70 -0
  130. tess_shell/shipped/Stylesheets/Default_Stylesheet.tdl +127 -0
  131. tess_shell/shipped/TextBox/TextBox_Module.py +19 -0
  132. tess_shell/shipped/TextBox/TextBox_Module.tdl +26 -0
  133. tess_shell/shipped/TextEditor/TextEditor_Module.py +27 -0
  134. tess_shell/shipped/TextEditor/TextEditor_Module.tdl +41 -0
  135. tess_shell/shipped/TextInput/TextInput_Module.py +18 -0
  136. tess_shell/shipped/TextInput/TextInput_Module.tdl +39 -0
  137. tess_shell/shipped/Themes/Default_Theme.tdl +100 -0
  138. tess_shell/shipped/Toggle/Toggle_Module.py +10 -0
  139. tess_shell/shipped/Toggle/Toggle_Module.tdl +47 -0
  140. tess_shell/shipped/Tray/Tray_Module.py +655 -0
  141. tess_shell/shipped/Tray/Tray_Module.tdl +59 -0
  142. tess_shell/shipped/Tray_Item/Tray_Item_Module.py +9 -0
  143. tess_shell/shipped/Tray_Item/Tray_Item_Module.tdl +71 -0
  144. tess_shell/shipped/Tray_Item/Tray_Item_Style.tdl +15 -0
  145. tess_shell/shipped/Tray_Menu/Tray_Menu_Module.py +52 -0
  146. tess_shell/shipped/Tray_Menu/Tray_Menu_Module.tdl +57 -0
  147. tess_shell/shipped/Workspaces/Workspaces_Module.py +168 -0
  148. tess_shell/shipped/Workspaces/Workspaces_Module.tdl +54 -0
  149. tess_shell/shipped/Workspaces/Workspaces_Style.tdl +20 -0
  150. tess_shell/shortcuts.py +265 -0
  151. tess_shell/signals.py +147 -0
  152. tess_shell/surfaces/__init__.py +1 -0
  153. tess_shell/surfaces/bar.py +264 -0
  154. tess_shell/surfaces/focus.py +53 -0
  155. tess_shell/surfaces/frame.py +2044 -0
  156. tess_shell/surfaces/frame_shader.py +569 -0
  157. tess_shell/surfaces/handle.py +243 -0
  158. tess_shell/surfaces/hotplug.py +199 -0
  159. tess_shell/surfaces/join.py +234 -0
  160. tess_shell/surfaces/join_concave.py +218 -0
  161. tess_shell/surfaces/join_param.py +152 -0
  162. tess_shell/surfaces/join_shader.py +235 -0
  163. tess_shell/surfaces/join_structure.py +96 -0
  164. tess_shell/surfaces/manager.py +1705 -0
  165. tess_shell/surfaces/mode.py +231 -0
  166. tess_shell/surfaces/mode_driver.py +390 -0
  167. tess_shell/surfaces/outline.py +240 -0
  168. tess_shell/surfaces/panel.py +156 -0
  169. tess_shell/surfaces/popup.py +1232 -0
  170. tess_shell/surfaces/popup_measure.py +256 -0
  171. tess_shell/surfaces/ring.py +679 -0
  172. tess_shell/watch.py +184 -0
  173. tesserae_shell-0.1.1.dist-info/METADATA +186 -0
  174. tesserae_shell-0.1.1.dist-info/RECORD +177 -0
  175. tesserae_shell-0.1.1.dist-info/WHEEL +4 -0
  176. tesserae_shell-0.1.1.dist-info/entry_points.txt +2 -0
  177. tesserae_shell-0.1.1.dist-info/licenses/LICENSE +21 -0
tess_shell/__init__.py ADDED
@@ -0,0 +1,22 @@
1
+ __version__ = "0.1.1"
2
+
3
+ from tess_shell.module import Event, Module, action # noqa: E402
4
+ from tess_shell.services.api import ( # noqa: E402
5
+ BlockingCallError,
6
+ ServiceError,
7
+ ServiceState,
8
+ ServiceTimeout,
9
+ ServiceUnavailable,
10
+ )
11
+
12
+ __all__ = [
13
+ "BlockingCallError",
14
+ "Event",
15
+ "Module",
16
+ "ServiceError",
17
+ "ServiceState",
18
+ "ServiceTimeout",
19
+ "ServiceUnavailable",
20
+ "__version__",
21
+ "action",
22
+ ]
tess_shell/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from tess_shell.cli import main
2
+
3
+ raise SystemExit(main())
tess_shell/app.py ADDED
@@ -0,0 +1,509 @@
1
+ """``tesserae-shell run``: the start and stop sequences (Shell Start and Stop).
2
+
3
+ M0 builds steps 1 to 7 and 9 of the start sequence and the stop sequence for what exists. The
4
+ resolve and compile step, the model, the surfaces and the modules are logged as not built.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ import os
11
+ import sys
12
+ import threading
13
+ from collections.abc import Callable
14
+ from importlib.metadata import version
15
+ from pathlib import Path
16
+ from types import TracebackType
17
+ from typing import Any, NoReturn
18
+
19
+ from loguru import logger
20
+
21
+ import tess_shell
22
+ from tess_shell.appearance import Appearance
23
+ from tess_shell.binder.images import IMAGES
24
+ from tess_shell.binder.model import Handler
25
+ from tess_shell.commands import ShellCommands
26
+ from tess_shell.config.lock import InstanceLock
27
+ from tess_shell.config.paths import check_runtime_dir, config_dir, ensure_config_dir, state_dir
28
+ from tess_shell.config.registry import Registry, RegistryError
29
+ from tess_shell.config.settings import LoggingSettings, Settings, load_settings
30
+ from tess_shell.config.uids import assign_uids
31
+ from tess_shell.exit_codes import EnvironmentFailure, ExitCode, ShellError
32
+ from tess_shell.logging import (
33
+ configure_logging,
34
+ current_state,
35
+ finding_sinks,
36
+ log_finding,
37
+ note_module_error,
38
+ shutdown_logging,
39
+ )
40
+ from tess_shell.model.store import ValueStore
41
+ from tess_shell.model.uses import Use
42
+ from tess_shell.modules.host import ModuleHost, report
43
+ from tess_shell.modules.ticks import TimeSource
44
+ from tess_shell.options import Options
45
+ from tess_shell.reloader import Reloader
46
+ from tess_shell.scanner import MAX_FINDINGS, build_look, print_findings, scan
47
+ from tess_shell.schema.findings import Finding
48
+ from tess_shell.services.api import ServiceUnavailable
49
+ from tess_shell.services.audio import AudioService
50
+ from tess_shell.services.bus import ServiceThread
51
+ from tess_shell.services.control import NAME, ControlService, ErrorLog
52
+ from tess_shell.services.icons import IconService
53
+ from tess_shell.services.layer import Layer
54
+ from tess_shell.services.portal import PortalReader
55
+ from tess_shell.services.shortcuts import STOP_TIMEOUT, Action, ShortcutService
56
+ from tess_shell.services.tray import TrayService
57
+ from tess_shell.shortcuts import (
58
+ drop_failed,
59
+ mode_keys,
60
+ registered,
61
+ shortcut_handlers,
62
+ shortcut_modules,
63
+ )
64
+ from tess_shell.signals import EarlyStop, LoopStopper, SignalWatcher
65
+ from tess_shell.surfaces.manager import SurfaceManager
66
+ from tess_shell.watch import OwnWrites, Watcher
67
+
68
+ MIN_ENGINE = (0, 6, 0)
69
+ MIN_PYTHON = (3, 14)
70
+
71
+
72
+ def check(options: Options) -> int:
73
+ """``tesserae-shell check``: settings, then every shell file, and nothing is created."""
74
+ config = config_dir(options.config_dir)
75
+ if not config.is_dir():
76
+ print(f"tesserae-shell: config directory does not exist: {config}", file=sys.stderr)
77
+ return int(ExitCode.ENVIRONMENT)
78
+ settings, findings = load_settings(config)
79
+ count = 0
80
+ if settings is not None:
81
+ result = scan(settings, config)
82
+ count, findings = result.count, result.findings
83
+ failed = any(f.severity == "error" for f in findings)
84
+ if options.json:
85
+ shown = findings[:MAX_FINDINGS]
86
+ print(
87
+ json.dumps(
88
+ {
89
+ "ok": not failed,
90
+ "config_dir": str(config),
91
+ "files": count,
92
+ "errors": [f.to_dict() for f in shown],
93
+ "omitted": len(findings) - len(shown),
94
+ }
95
+ )
96
+ )
97
+ else:
98
+ if findings:
99
+ print_findings(findings, config)
100
+ if not failed and not options.quiet:
101
+ print(f"ok: {count} files checked")
102
+ return int(ExitCode.CONFIG if failed else ExitCode.OK)
103
+
104
+
105
+ def _preflight() -> tuple[Path, bool]:
106
+ if sys.version_info < MIN_PYTHON:
107
+ raise EnvironmentFailure("tesserae-shell needs Python 3.14 or newer")
108
+ engine = tuple(int(p) for p in version("tesserae-engine").split(".")[:3] if p.isdigit())
109
+ if engine < MIN_ENGINE:
110
+ raise EnvironmentFailure(
111
+ f"tesserae-engine {version('tesserae-engine')} is too old; 0.6.0 or newer is needed"
112
+ )
113
+ runtime = check_runtime_dir()
114
+ import tess_re
115
+
116
+ try:
117
+ has_layer_shell = tess_re.supports("layer_shell")
118
+ except Exception:
119
+ has_layer_shell = False
120
+ if not has_layer_shell:
121
+ raise EnvironmentFailure(
122
+ "no Wayland compositor with layer-shell "
123
+ f"(WAYLAND_DISPLAY={os.environ.get('WAYLAND_DISPLAY', '')})"
124
+ )
125
+ return runtime
126
+
127
+
128
+ def _install_excepthooks() -> None:
129
+ def hook(exc_type: type[BaseException], exc: BaseException, tb: TracebackType | None) -> None:
130
+ logger.opt(exception=(exc_type, exc, tb)).critical("unhandled exception")
131
+
132
+ def thread_hook(args: threading.ExceptHookArgs) -> None:
133
+ if args.exc_type is not SystemExit and args.exc_value is not None:
134
+ logger.opt(exception=(args.exc_type, args.exc_value, args.exc_traceback)).critical(
135
+ f"unhandled exception in thread {args.thread.name if args.thread else '?'}"
136
+ )
137
+
138
+ sys.excepthook = hook
139
+ threading.excepthook = thread_hook
140
+
141
+
142
+ def _fail(message: str) -> None:
143
+ """Report a one-line failure: on stderr, and in the log once logging runs."""
144
+ state = current_state()
145
+ if state is None:
146
+ print(f"tesserae-shell: {message}", file=sys.stderr)
147
+ return
148
+ logger.error(message)
149
+ if state.console_sink is None:
150
+ print(f"tesserae-shell: {message}", file=sys.stderr)
151
+
152
+
153
+ def _force_exit() -> NoReturn:
154
+ """A second signal: leave at once, as the ``SignalWatcher`` does."""
155
+ shutdown_logging()
156
+ os._exit(int(ExitCode.FORCED))
157
+
158
+
159
+ def run(options: Options) -> int:
160
+ lock = InstanceLock()
161
+ early = EarlyStop(_force_exit)
162
+ early.install() # the first signal of the start is held for the watcher (EarlyStop)
163
+ try:
164
+ _install_excepthooks()
165
+ return int(_run(options, lock, early))
166
+ except ShellError as exc:
167
+ _fail(str(exc))
168
+ return int(exc.exit_code)
169
+ except KeyboardInterrupt:
170
+ return int(ExitCode.FORCED)
171
+ except Exception as exc:
172
+ if current_state() is None:
173
+ print(f"tesserae-shell: unexpected error: {exc!r}", file=sys.stderr)
174
+ else:
175
+ logger.opt(exception=True).critical("unexpected error")
176
+ return int(ExitCode.INTERNAL)
177
+ finally:
178
+ early.uninstall()
179
+ shutdown_logging()
180
+ lock.release()
181
+
182
+
183
+ def _start_control(
184
+ service: ServiceThread,
185
+ handle: Any,
186
+ manager: SurfaceManager,
187
+ reloader: Reloader,
188
+ commands: ShellCommands,
189
+ errors: ErrorLog,
190
+ ) -> ControlService | None:
191
+ """Export the control interface and own its bus name (Shell Start and Stop). ``None`` when
192
+ the session bus cannot be reached: the shell runs without control commands and says so."""
193
+ control = ControlService(service, handle.call_soon, commands, tess_shell.__version__, errors)
194
+ try:
195
+ service.submit(control.start()).result(timeout=START_TIMEOUT)
196
+ except (ServiceUnavailable, TimeoutError, OSError) as exc:
197
+ logger.info(f"control: no commands: the session bus is not reachable ({exc})")
198
+ return None
199
+ except Exception as exc:
200
+ logger.opt(exception=True).warning(f"control: no commands ({exc!r})")
201
+ return None
202
+ if control.owned:
203
+ reloader.on_reloaded = control.reloaded
204
+ manager.on_surface = control.surface_changed
205
+ finding_sinks.append(control.error_reported)
206
+ logger.info(f"control: owning {NAME}")
207
+ return control
208
+
209
+
210
+ def _stop_control(service: ServiceThread, control: ControlService) -> None:
211
+ if control.error_reported in finding_sinks:
212
+ finding_sinks.remove(control.error_reported)
213
+ try:
214
+ service.submit(control.stop()).result(timeout=START_TIMEOUT)
215
+ except Exception as exc:
216
+ logger.debug(f"control: stopping did not go through ({exc!r})")
217
+
218
+
219
+ START_TIMEOUT = 6.0 # seconds the shell waits for the bus when it takes its name
220
+
221
+
222
+ def _start_shortcuts(
223
+ service: ServiceThread,
224
+ handle: Any,
225
+ commands: ShellCommands,
226
+ call_problems: list[Finding],
227
+ declared: tuple[Action, ...],
228
+ settings: Settings,
229
+ ) -> ShortcutService:
230
+ """Register the shell's global shortcuts with the desktop's shortcut service, after the
231
+ shell's own bus name is owned and before the surfaces are shown (Global Shortcuts >
232
+ Registration). A missing service or a refused call is a warning and no keys: the shell runs and
233
+ the commands work."""
234
+ shortcuts = ShortcutService(service, handle.call_soon, commands.press)
235
+ actions = registered(drop_failed(declared, call_problems))
236
+ try:
237
+ service.submit(shortcuts.start(actions, settings.global_shortcuts)).result(
238
+ timeout=START_TIMEOUT
239
+ )
240
+ except Exception as exc:
241
+ logger.opt(exception=True).warning(f"shortcuts: no global keys ({exc!r})")
242
+ else:
243
+ if settings.global_shortcuts:
244
+ logger.info(
245
+ f"shortcuts: {len(shortcuts.registered)} of {len(actions)} actions registered"
246
+ )
247
+ return shortcuts
248
+
249
+
250
+ def _stop_shortcuts(service: ServiceThread, shortcuts: ShortcutService) -> None:
251
+ try:
252
+ service.submit(shortcuts.stop()).result(timeout=STOP_TIMEOUT + 0.5)
253
+ except Exception as exc:
254
+ logger.debug(f"shortcuts: stopping did not go through ({exc!r})")
255
+
256
+
257
+ def _run(options: Options, lock: InstanceLock, early: EarlyStop) -> ExitCode:
258
+ # 1. pre-flight
259
+ runtime_dir, loose = _preflight()
260
+ # 2. the config directory
261
+ cfg = config_dir(options.config_dir)
262
+ ensure_config_dir(cfg)
263
+ # 3. settings
264
+ settings, findings = load_settings(cfg)
265
+ if settings is None:
266
+ configure_logging(LoggingSettings(console=False), default_directory=cfg / "logs")
267
+ for f in findings:
268
+ log_finding(f)
269
+ print_findings(findings, cfg)
270
+ return ExitCode.CONFIG
271
+ # 4. logging
272
+ configure_logging(settings.logging, quiet=options.quiet, default_directory=cfg / "logs")
273
+ logger.info(f"starting tesserae-shell {tess_shell.__version__} (config {cfg})")
274
+ if loose:
275
+ logger.warning(f"{runtime_dir} is not mode 0700")
276
+ # 5. the instance lock
277
+ lock.acquire(runtime_dir)
278
+ if lock.sticky_refused:
279
+ logger.warning("the lock file could not be given the sticky bit")
280
+ # 6. the registry
281
+ try:
282
+ registry = Registry.open(settings.registry)
283
+ except RegistryError as exc:
284
+ log_finding(exc.finding)
285
+ print_findings([exc.finding], cfg)
286
+ return ExitCode.CONFIG
287
+ # 7. check and load every shell file
288
+ result = scan(settings, cfg)
289
+ for f in result.findings[:MAX_FINDINGS]:
290
+ log_finding(f)
291
+ if result.findings:
292
+ print_findings(result.findings, cfg)
293
+ if result.errors:
294
+ return ExitCode.CONFIG
295
+ logger.info(f"loaded {result.count} shell files")
296
+ if settings.main_shell_path is None:
297
+ logger.info(f"no {settings.main_shell} found; nothing to show")
298
+ # 8. resolve and compile
299
+ logger.info("step 8 (resolve and compile): not built in M0")
300
+ # 9. the engine and its loop
301
+ import tess_re
302
+
303
+ app = tess_re.App()
304
+ handle = app.thread_handle()
305
+ stopper = LoopStopper(handle.stop)
306
+
307
+ reload_signal: list[Callable[[], None]] = []
308
+ watcher = SignalWatcher(
309
+ stopper.request, _force_exit, lambda: reload_signal[-1]() if reload_signal else None
310
+ )
311
+ watcher.start(early)
312
+ try:
313
+ store = ValueStore()
314
+ ticks = TimeSource()
315
+ shell = result.shells.get(settings.main_shell_path) if settings.main_shell_path else None
316
+ module_defs = {name: mf.definition for name, mf in result.modules.items()}
317
+ # the desktop's look: one read of the Settings portal, on the D-Bus thread; a slow or
318
+ # missing portal gives the defaults and never delays the surfaces
319
+ # the D-Bus service thread: one thread, started now, that connects to nothing until a
320
+ # module or the portal reader uses a bus
321
+ service = ServiceThread()
322
+ service.start()
323
+ layer = Layer(service, handle.call_soon)
324
+ layer.on_module_error = note_module_error
325
+ portal: PortalReader | None = None
326
+ appearance = Appearance()
327
+ manager_box: list[SurfaceManager] = []
328
+ icon_box: list[IconService] = []
329
+
330
+ def appearance_changed(new: Appearance) -> None: # on the service thread
331
+ def apply() -> None:
332
+ if icon_box: # the portal's icon theme; a change makes the modules' icons again
333
+ icon_box[0].set_portal_theme(new.icon_theme)
334
+ manager_box[0].set_look(manager_box[0].look.with_appearance(new))
335
+
336
+ handle.call_soon(apply)
337
+
338
+ if settings.appearance.follow_desktop:
339
+ portal = PortalReader(service, appearance_changed)
340
+ portal.start()
341
+ appearance = portal.first()
342
+ else:
343
+ logger.debug("Appearance.Follow_Desktop is false: the portal is not read")
344
+ look = build_look(result, settings, appearance)
345
+ manager = SurfaceManager(
346
+ app,
347
+ module_defs,
348
+ registry.uid_for,
349
+ store,
350
+ look,
351
+ hide_mode=settings.debug.panel_hide,
352
+ positions=registry,
353
+ join_mode=settings.debug.frame_join,
354
+ blend_mode=settings.debug.frame_blend,
355
+ mode_keyboard=settings.debug.mode_keyboard,
356
+ )
357
+ manager_box.append(manager)
358
+ host = ModuleHost(store, ticks, cfg)
359
+
360
+ def route(handler: Handler, key: str, raw: object) -> None:
361
+ # a shell action (Show, Hide, Toggle) is the manager's; any other name is an @action
362
+ if handler.builtin:
363
+ manager.run_builtin(handler, raw)
364
+ else:
365
+ host.dispatch(handler, key, raw)
366
+
367
+ manager.sink = route
368
+ host.popups = manager.popups # ctx.popup() opens a Popup of the surfaces
369
+ host.dbus = layer # ctx.dbus: the D-Bus service layer
370
+ host.audio = AudioService(service) # ctx.audio: the sound server, on the same thread
371
+ icon_service = IconService(IMAGES.register) # ctx.icons: the theme lookup, files read here
372
+ icon_service.set_portal_theme(appearance.icon_theme)
373
+ icon_box.append(icon_service)
374
+ host.icons = icon_service
375
+ host.tray = TrayService(service) # ctx.tray: the shell as a StatusNotifier host
376
+ host.call_soon = handle.call_soon # ctx.call_soon: back to the loop thread
377
+ host.focus = manager.mode # ctx.focus: shortcut mode and the default focus
378
+ # a file the shell registers for the first time gets a UID in its metadata (G8)
379
+ own_files = [mf.path for mf in result.modules.values() if not mf.shipped]
380
+ own_writes = OwnWrites()
381
+ file_uids, uid_problems = assign_uids(
382
+ [*own_files, *result.shells],
383
+ cfg,
384
+ lambda key: registry.uid_for(key, "file"),
385
+ state_dir() / "backups",
386
+ on_write=own_writes.wrote,
387
+ )
388
+ report(uid_problems)
389
+ # 10. model: expand the module calls, load and start each module that is used
390
+ uses = manager.plan(shell) if shell is not None else []
391
+ by_module: dict[str, list[Use]] = {}
392
+ for use in uses:
393
+ by_module.setdefault(use.module, []).append(use)
394
+ for name in manager.dynamic_module_names():
395
+ by_module.setdefault(name, []) # called in a For: loaded, with no use until an entry
396
+ for name in shortcut_modules(result.shortcuts):
397
+ by_module.setdefault(name, []) # named by a Call shortcut: loaded, with no use
398
+ for name, module_uses in by_module.items():
399
+ mf = result.modules[name]
400
+ uid = file_uids.get(mf.path) or registry.uid_for(f"module:{name}", "module")
401
+ _, problems = host.load(mf.definition, mf.python, uid, module_uses)
402
+ report(problems)
403
+ # every Call names a loaded action, the shortcuts' too
404
+ call_problems = host.check_calls(
405
+ [*manager.planned_handlers(), *shortcut_handlers(result.shortcuts)]
406
+ )
407
+ report(call_problems)
408
+ report(host.start_all())
409
+ store.flush() # what the modules sent while starting, before the first build
410
+ logger.info(f"step 10 (model): {len(uses)} module uses, {len(host.loaded)} modules")
411
+ # 11. surfaces
412
+ # the entries of a For make uses while the surfaces are built: the modules hear of them
413
+ manager.dynamic_sink = lambda added, removed: report(host.dynamic(added, removed))
414
+ manager.build()
415
+ logger.info(f"step 11 (surfaces): {len(manager.surfaces)} opened")
416
+ store.on_change = manager.on_change
417
+ store.attach_loop(handle.call_soon)
418
+ ticks.start(handle.call_soon)
419
+ logger.info("step 12 (modules): started")
420
+ reloader = Reloader(
421
+ cfg,
422
+ settings,
423
+ options.quiet,
424
+ registry,
425
+ manager,
426
+ host,
427
+ store,
428
+ own_writes,
429
+ handle.call_soon,
430
+ result,
431
+ file_uids,
432
+ )
433
+ reload_signal.append(lambda: reloader.trigger(None))
434
+ manager.sync_uses = reloader.sync_uses # a monitor that comes or goes changes the uses
435
+ manager.hotplug.start() # output_added, output_removed, output_updated
436
+ files = None
437
+ file_watcher: Watcher | None = None
438
+ if settings.hot_reload:
439
+ trees = {d for folder, dirs in settings.directories.items() for d in dirs if d.is_dir()}
440
+ files = {cfg: frozenset({"settings.tdl"})}
441
+ file_watcher = Watcher(
442
+ trees,
443
+ reloader.trigger,
444
+ files=files,
445
+ debounce=settings.reload_debounce,
446
+ is_own=own_writes.is_own,
447
+ )
448
+ own_writes.clear() # the writes of the start made no event: nothing to drop yet
449
+ file_watcher.start()
450
+ if not file_watcher.ok:
451
+ logger.warning("some folders are not watched; SIGHUP still reloads everything")
452
+ control: ControlService | None = None
453
+ shortcuts: ShortcutService | None = None
454
+ errors = ErrorLog()
455
+ commands = ShellCommands(manager, host, reloader, stopper.request, errors.last)
456
+ manager.mode.set_keys(mode_keys(result.shortcuts)) # the keys of shortcut mode
457
+ manager.mode.watch_focus = True # a real compositor: warn when it does not hand focus over
458
+ taken = False
459
+ if settings.control:
460
+ control = _start_control(service, handle, manager, reloader, commands, errors)
461
+ taken = control is not None and not control.owned
462
+ if taken:
463
+ _fail(
464
+ f"the bus name {NAME} is owned: another tesserae-shell is running on this "
465
+ "session bus"
466
+ )
467
+ stopper.loop_finished()
468
+ if file_watcher is not None:
469
+ file_watcher.stop()
470
+ else:
471
+ shortcuts = _start_shortcuts(
472
+ service, handle, commands, call_problems, result.shortcuts, settings
473
+ )
474
+ reloader.shortcuts = shortcuts
475
+ logger.info("running")
476
+ if control is not None:
477
+ control.set_state("running")
478
+ try:
479
+ app.run(keep_alive=True)
480
+ finally:
481
+ stopper.loop_finished()
482
+ if file_watcher is not None:
483
+ file_watcher.stop()
484
+ if not stopper.requested.is_set():
485
+ _fail("event loop ended without a stop request")
486
+ return ExitCode.ENVIRONMENT
487
+ # stop sequence: modules, then the time source (no D-Bus yet)
488
+ logger.info("stopping")
489
+ if shortcuts is not None:
490
+ shortcuts.begin_stop() # a press from here on is dropped
491
+ if control is not None:
492
+ control.set_state("stopping")
493
+ _stop_control(service, control)
494
+ if shortcuts is not None:
495
+ _stop_shortcuts(service, shortcuts)
496
+ host.stop_all()
497
+ ticks.close()
498
+ if portal is not None:
499
+ portal.stop()
500
+ service.stop()
501
+ try:
502
+ registry.save()
503
+ except OSError as exc:
504
+ _fail(f"cannot save the registry: {exc}")
505
+ return ExitCode.CONFIG
506
+ logger.info("stopped")
507
+ return ExitCode.ALREADY_RUNNING if taken else ExitCode.OK
508
+ finally:
509
+ watcher.close()
@@ -0,0 +1,27 @@
1
+ """What the desktop says about its look (Portals > The Settings Portal): one small value type
2
+ shared by the portal reader, which fills it, and the theme resolver, which reads it. Standard
3
+ library only."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from dataclasses import dataclass
8
+ from typing import Literal
9
+
10
+ Scheme = Literal["default", "dark", "light"]
11
+
12
+
13
+ @dataclass(frozen=True, slots=True)
14
+ class Appearance:
15
+ scheme: Scheme = "default" # no preference: the theme's default variant
16
+ accent: tuple[int, int, int] | None = None # sRGB, 0 to 255
17
+ high_contrast: bool = False
18
+ reduced_motion: bool = False # ``org.freedesktop.appearance`` ``reduced-motion`` is 1
19
+ animations: bool = True # ``org.gnome.desktop.interface`` ``enable-animations``
20
+ icon_theme: str | None = None # ``org.gnome.desktop.interface`` ``icon-theme``
21
+ font_family: str | None = None # the family of ``org.gnome.desktop.interface`` ``font-name``
22
+
23
+ @property
24
+ def motion_reduced(self) -> bool:
25
+ """No animation: either the desktop's reduced-motion preference or its animations switch
26
+ says so (Portals > Settings Read in M5h)."""
27
+ return self.reduced_motion or not self.animations
@@ -0,0 +1,5 @@
1
+ """The render binder: a typed tree in, tre nodes out (Render Binder Design).
2
+
3
+ Imports only the standard library, ``tess_re`` and ``tess_utils``; nothing from the rest of the
4
+ shell, and nothing from ``tess_dl``.
5
+ """