19 kB 284 lines
cc41ca5b
⋯
compositor/CLAUDE.md
download raw history
at main Markdown

cont8nuum: the compositor (src/) #

The compositor, binary c8 (wlroots 0.20), and c8-panorama (libexec: decodes the glasses' background for it). Depends on: c8-protocols, c8ui-core (icons), libinput, gdk-pixbuf (c8-panorama).

Second screen, XR and everything of the glasses (output.c's roles, glasses.c, hologram.c, tracker.c, imu.c, slatebar.c, placement.c, stereo.c, panorama.c, xdgoutput.c, and for VR games lease.c, xrruntime.c, xrclient.c, glassesmode.c) is in XR.md beside this file: read it before touching any of those, or anything that behaves differently in XR (c8_xr_active). Headless testing is in the root CLAUDE.md.

  • main.c startup order; server.h holds every shared struct and the cross-file API, grouped by source file. Listeners are hooked up with c8_listen(&listener, &signal, fn) (server.h), not by hand.
  • config.c reads ~/.config/cont8nuum/config.ini (documented sample in data/config.ini; keep it in sync when adding keys), including [appearance] (moved there from start.ini on first run). start.ini (tiles and groups) belongs to c8-shell. c8_config_patch edits config.ini in place, preserving comments. c8_ini_parse is the one ini reader (placement.c's too). c8_config_reload + apply_reload (settings.c) diff-apply live, also when config.ini is edited by hand (inotify on its folder, 200 ms after the last write; text equal to the last applied is let be, so our own patches don't apply twice).
  • Small shared pieces: math3d.h has pose_point, quat_yaw_pitch, vec3_yaw_pitch for the holograms' arithmetic; c8_view_raise (focus unless already in front; a click, never a summon), c8_shell_osd_shown, c8_output_is_sink (mirror or glasses), c8_cross_path (the close cross of chrome, the slate bar and snip).
  • settings.c serves cont8nuum-settings-v1. Only c8-settings may use it: the compositor spawns c8-settings itself over a socketpair (WAYLAND_SOCKET) and a global filter hides the global from every other client. Launching c8-settings from anywhere routes through c8_settings_launch. Snapshot model: all entries + done, resent on every change. The one other client is c8-sync (settings sync, in c8-settings): c8_sync_start spawns it the same private way for the session (not nested, unless C8_SYNC is set), and again 30 s after it exits, five times at most.
  • output.c implements wlr-output-management (works with wlr-randr, kanshi, PC settings) and applies [output NAME] sections on hotplug.
  • input.c libinput config (tap, natural scroll, …), bindings, and keyboard-shortcuts-inhibit (so PC settings can record Super+Q etc.). Media keys are bound by default to actions (volume-up, brightness-up, play-pause, …) that go to the shell, which does them. Clipboard: data-device, primary selection and ext/wlr data-control. Implicit grab: while a button is held the pointer stays with the surface it went down on (server->press, c8_pointer_motion), so the release reaches the same client; a seat grab (drag and drop) is left to move between surfaces. c8ui drops a held press on leave. Clock: [general] clock = auto (as LC_TIME does), 12 or 24, sent to the shell as the clock appearance key and read from config.ini by c8-lock and c8-widget themselves; clock.h (c8-base) formats the time from it; the shell and locker setlocale(LC_TIME, "") for it. PC settings' General page sets it. Pointer theme: [general] cursor_theme/cursor_size (PC settings' General page); c8_cursor_theme_changed swaps the xcursor manager live (the cursor first, it keeps a pointer to it), resets Xwayland's root cursor and passes XCURSOR_THEME/XCURSOR_SIZE on to systemd + D-Bus.
  • Stealth mode (c8-base's stealth.h, which c8 links for it): c8_view_title is the title scrubbed with c8_stealth_text while it's on (titles in the chrome, switcher, shell protocol and XR all come through it), cached per view against server->stealth_gen; apply_reload's c8_stealth_reload bumps that and restyles every view (c8_views_stealth_changed). Untested: titles by eye, XR.
  • view.c arranges the apps: one fills the usable area, or two share it with a snapped one (server->snapped, snap_left, snap_fraction) beside the primary and the black divider between. With two, focus_border (four accent-coloured rects, recoloured on every arrange, so an accent change re-arranges) is drawn along the focused one's edge in layers.border, a tree above the views that node_at (input.c) never looks at, so the app keeps its full size and the pointer at the edge still reaches it. split-left/split-right (Super+Shift+Left/Right, c8_view_split_step) move the split to the next quarter of the width; at 0 or 4 quarters the app left with all of it is alone, as unsnap. tween.c animates every change of that layout that involves a snap (a step, a swap, snapping, unsnapping, one taking the whole screen, one of the pair closing, an app dropped by its title bar): arrange hands it the tiled apps' boxes (c8_tween_layout). Each app that was on screen before is shown by a frame (a scene buffer of the buffer it last showed, in tween.tree over the apps; the lock keeps the app's next frames out of it) stretched from its old box (or where it is mid-move; a drop: the card, c8_tween_drop) to the new one, while the app itself and its dialogs are hidden (c8_tween_restack, end of arrange) and redraw at the new size. The move holds at its end until each has drawn that size, or WAIT_MS; then the apps are shown under their frames, which fade (FADE_MS). An app with no buffer is cropped live instead (wlr_scene_subsurface_tree_set_clip, held against the edge that stays). An app leaving the layout stays under the others as a frame till the move ends; one that closed fades meanwhile (c8_tween_view_gone, while its buffer is still there). Going to one app arranges twice (snap_to, then focus): a move already running isn't stopped by the second, nor a fade by a re-arrange to the same layout. The focus border waits. Not while the divider is dragged, Start is up or in XR (c8_tween_stop). Frames aren't surfaces, so a click during a move hits nothing. While the shell's pick is open beside the snapped app (picking_over), the app that would be there is hidden (hidden to the tween: no frame), so it doesn't show past the pick as that follows the split; pick_done arranges it back. Arranging ends with c8_cursor_rebase: after Alt+Tab a still pointer's click or scroll went to the app it was last over (and focused it again) until the pointer moved. Not while the pointer is on a shell surface (a toast mid-swipe must keep it), nor while the chrome grabs it (c8_chrome_grabbing): dragging the divider arranges from the chrome's motion, whose rebase moved it again, and so on till the stack overflowed (crashed the session, 2026-12-06; the fix is untested by hand, wlrctl can't hold a button). Tested headless (click after Alt+Tab stays with the new app); not tested: the old build reproducing it. Tried and dropped (2026-12-03): covers of the app's colour and icon (Windows 8's way; the user found them disorienting: don't go back), then cropping the live apps alone (jumped as they redrew). Tested headless with foot (2026-12-03): steps, the step to the whole screen (the second arrange used to cancel it), closing the snapped one (its picture fades as the other stretches over), the pick through a step and Escape. Untested: dropping by the title bar (wlrctl can't hold a button; reasoned from end_drag), apps with a scaled or viewported buffer (the frame's source box assumes the buffer/surface size ratio), popups.
  • drag.c drag and drop: a drag starts only from a valid pointer or touch grab serial (not while locked); the icon goes in layers.drag (over everything but the lock screen); a touch drag moves the finger's focus to the surface under it (c8_drag_touch_motion).
  • touch.c touchscreen and pen, mapped to the built-in panel (eDP). Apps that bound wl_touch get real touch; elsewhere (Start, panels, chrome) the first finger drives the pointer (c8_pointer_button/motion). The pen is a pointer too (no tablet-v2 yet). Edge swipes: a first finger landing within EDGE_SIZE of the built-in screen's edge is held back; swiping in from the left opens the switcher (switcher 0, 0: stays until dismissed), from the right the charms, from the top pulls the title bar down pinned (chrome.pinned, until a press elsewhere) and pulling on past EDGE_PULL turns the finger into the pointer carrying the app. Taps, slides along the edge and rests are replayed as a normal touch. One finger on the screen is two on the touchpad, so two are three: two landing within SWIPE_GATHER ms stay touches until they move SWIPE_START px together (the gap changing first is a pinch, left to the app); then their touches are cancelled, the pointer goes where they landed and the app there gets a 3-finger pointer-gestures swipe (the first finger up ends it; the rest are ignored until lifted).
  • session.c the desktop session: imports the environment into systemd + D-Bus (SESSION_VARS; XDG_DATA_DIRS too, so a release tarball's /opt/cont8nuum/share, put there by its launcher, reaches D-Bus activated apps) and starts cont8nuum-session.target (binds graphical-session.target, pulls XDG autostart and cont8nuum-polkit-agent.service); stops it on exit. It runs systemctl --user daemon-reload first so XDG autostart is regenerated (the user has lingering on, so the user manager outlives logins). Also idle: screens off / sleep after [power] screen_off_after / sleep_after minutes, honouring idle-inhibit, plus ext-idle-notify. All of this is skipped when nested (server->session == NULL). A real session also sets SUDO_ASKPASS/SSH_ASKPASS to c8-askpass from $PATH unless already set, and with no SSH_AUTH_SOCK from the login points it at cont8nuum-ssh-agent.service (PartOf graphical-session, so logging out forgets the keys), which it starts with the target.
  • Units/scripts live in compositor/data/ (systemd/, c8-polkit-agent, cont8nuum-portals.conf). Decorations are always the server's: xdg-decoration, plus KDE's org_kde_kwin_server_decoration (view.c) for GTK3, which drops its title bar but keeps an app's own header bar. GTK4 always draws its own, so cont8nuum-gtk.service (oneshot, c8-gtk-settings) sets GTK's button layout to : (none) in GSettings and both GTK settings.ini files at session start (C8_GTK_BUTTONS overrides, empty = leave alone); Plasma's kde-gtk-config writes its own back when Plasma starts. Screen sharing and screenshots go through xdg-desktop-portal-wlr (a package the user installs); its settings ship as data/xdg-desktop-portal-wlr.conf, installed to /etc/xdg/xdg-desktop-portal-wlr/cont8nuum (it reads only ~/.config and /etc/xdg; xdpw_dir option), chooser_type=simple with chooser_cmd=c8-share (c8-shell: the picker), force_mod_linear=1 (Intel's CCS buffers reached OBS black). Sharing one window (protocols.c capture_request): wlroots' scene-node source renders the whole scene over the node's box (what covers the window was in the picture, a hidden window gave nothing), so each window shared gets a private wlr_scene holding only a subsurface tree of its surface (view->listed.capture_scene/capture, one per window, dropped on unmap; popups aren't in it), which also keeps it drawing while hidden.
  • nightlight.c Night light, [nightlight] in config.ini (enabled, temperature 1500-6000 K, schedule = times (from..to), sunset (sunset to sunrise at place = "lat, lon", worked out here by NOAA's short form and logged once; no place: the times) or always). Each display's gamma ramps (wlr_color_transform_init_lut_3x1d of the output's gamma size, committed as its colour transform) are scaled towards that white by nl.shown, which eases to the schedule's strength (RAMP_MIN, 30 minutes, at its ends; a second when switched). tick looks at the clock every 30 s. The shell's tile and the night-light action are "warm now" (c8_nightlight_set): against the schedule that's forced, dropped when the schedule next turns or [nightlight] changes; with it off (or always) they flip enabled. The shell hears night_light on/off as an appearance key and asks with set_appearance("night_light", ...). A gamma-control client (gammastep) setting a display's ramps has it until it lets go (output->gamma_client). Displays without ramps (headless, nested) are skipped. C8_NIGHT_NOW=HH:MM fakes the clock for tests. Tested headless: the schedule and ramp by the log, sunset for a test city to the minute, the tile forcing it off and on, PC settings. Untested: on a real screen (what it looks like, the fade, the glasses, a display turned off and on again keeping it).
  • lock.c ext-session-lock: c8 spawns the locker ([power] locker, default c8-lock) privately like the shell; only it sees the global. @lock (launch / c8 -s) locks; the default [power] lock command. While locked (c8_locked) only the layers.lock tree gets input and only media bindings run. A locker that dies leaves it locked and is respawned (5 tries). locked is sent once every output drew the cover. The shell protocol tells the shell (locked event).
  • screenshot.c Print (screenshot: screens to the clipboard), Alt+Print (screenshot-window: the app in front) and Super+Print (screenshot-save: dims, then Pictures/Screenshots/Screenshot (N).png). Each output's scene is built once more (read back by c8_buffer_read, the glasses' dumps and screenshots too) into a swapchain of its own and read back; a forked child encodes the PNG (per paste for the clipboard source) and posts the notification with notify-send, waiting on the saved one's click to xdg-open the file or folder. In XR (c8_xr_screenshot, glasses.c) the picture is the glasses' view (draw_space once more into their swapchain, the left eye in 3D), Alt+Print the front window flat (c8_view_capture), no flash. With Monado holding the glasses the lease destroys their output (blank pictures, 2026-12-02): Print asks Monado for one frame of what it shows, games included (c8_xr_runtime_share('1'); the picture comes back through c8_xr_share_frame → c8_screenshot_finish, XR.md's XR-VIEW), and after 1 s with none (shot_timer) falls back to our own drawing in a buffer of ours (c8_capture_buffer, no game). Tested nested: Monado's picture, right colours. Snip still works on the shell's screen only.
  • snip.c Super+Shift+S (snip, also @snip): one capture shown frozen in layers.snip (above drag, below lock; first in node_at, so a finger is the pointer), dimmed by four scene rects round the selection, a bar at the top of the pointer's screen: rectangle, freeform (drawn in pieces of 32 segments, cut out with alpha), window (layers.views hit-test, view->geo), full screen, close. While up it takes the pointer and key presses (releases still go to the app); Escape ends it, so does locking. The result goes through c8_screenshot_snipped: clipboard, and a toast whose click saves it to Screenshots. The mode is remembered for the session.
  • protocols.c xdg-activation (needs a shell token, or a seat serial newer than the last focus change, focus_serial: Electron apps call window.focus() on blur and would otherwise come straight back), xdg-foreign, gamma control, ext/wlr foreign toplevel lists, ext-image-copy-capture (outputs and windows), drm-syncobj, alpha modifier, xdg-dialog. xdg popups (view.c, layer.c) are fitted to the primary output on their first commit and again on every reposition (GTK moves a popup that grows that way: LibreWolf's add-on prompt). pointer.c relative pointer, constraints, gestures, tablet-v2 (the pen goes to apps that bound it, else it is the pointer). im.c text-input-v3 ↔ input-method-v2 relay; a keyboard grab gets keys only while a text input is enabled on the focused surface (grab_takes_keys), or any client asking for one would read every key. Sandboxed clients (wp_security_context_v1, which Flatpak uses when it's there) aren't shown the globals that reach past a sandbox: virtual keyboard and pointer, input method, data control, screencopy and the capture managers, the toplevel lists, layer shell, output management, gamma (sandbox_hidden in settings.c's global_filter; add any new such global to its list). An exclusive layer surface keeps the keyboard from X11 override-redirect windows, and of several the topmost layer's newest has it (layer.c). Untested: a real Flatpak app. lease.c serves wp_drm_lease_device_v1 (also sandbox-hidden): headsets that say non-desktop are offered at once and kept out of the layout, as sway does; the XR glasses only on the Monado path (XR.md).
  • shell.c runs c8-shell the same private way as c8-settings (shared c8_spawn_client, same global filter) and restarts it with backoff when it exits. It serves cont8nuum-shell-v1: shell surfaces (start in layers.start, panels in layers.shell, splash in layers.splash), the Start mode (server->start_visible, owned here: c8_start_show), window objects (MRU via focused; capture: c8_view_capture in screenshot.c draws the window's own surfaces from their textures into the shell's memfd, so what covers it isn't in the picture, unlike wlroots' scene node capture, which renders the screen over the window's box). A shell surface that moves (set_rect; toasts slide in that way) rebases the cursor when it comes under the pointer, so one sliding under a still pointer gets the click (it went to Start's account menu before; tested headless again 2026-12-03). One moving away doesn't: a toast swiped off on the touchpad slid out from under the pointer, lost it, and so the rest of the swipe and its end, and stopped where it was. Bindings, Super tap and hot corners become action/switcher events. Window chrome (chrome.c) stays here and draws the colour/icon the shell sets per window. The icon loads in the background (c8ui_icon_request through the loader's fd); icon_arrived redraws the chrome, the slate bar and the beacon, which draw without it meanwhile (the bar leaves no gap). A restyle or the view going cancels the request; an icon theme change asks again.