Files
deckrotate/internal/daemon/tracker.go
T
Ziad ArafatandClaude Opus 5.5 81d2a986b6 Add deckrotate: Steam Deck screen rotation for Plasma
Go daemon reads the controller's accelerometer from hidraw (re-enabling
the IMU that Steam switches off), debounces it into an orientation and
rotates eDP-1 through kscreen-doctor in auto mode, or offers a
layer-shell tap-to-rotate button in manual mode, with a persistent lock.

Includes a D-Bus service, a CLI for global shortcuts (kglobalaccel
service file), a Plasma system tray applet, a systemd user unit and
hardware notes from probing the Deck OLED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 16:18:17 -07:00

53 lines
1.3 KiB
Go

// Package daemon wires the IMU, orientation detector, controller, overlay
// and D-Bus service together.
package daemon
import (
"context"
"log"
"time"
"github.com/RustyRaptor/deckrotate/internal/imu"
"github.com/RustyRaptor/deckrotate/internal/orient"
)
type Sink interface {
DeviceTurned(context.Context, orient.Orientation) error
SetIMUAvailable(bool)
}
// Tracker turns raw IMU samples into settled orientation changes. It is not
// safe for concurrent use; feed it from the single IMU reader goroutine.
type Tracker struct {
sink Sink
det *orient.Detector
alive bool
}
func NewTracker(sink Sink, settle time.Duration) *Tracker {
return &Tracker{sink: sink, det: orient.NewDetector(settle)}
}
func (t *Tracker) Sample(at time.Time, s imu.Sample) {
if !t.alive {
t.alive = true
t.sink.SetIMUAvailable(true)
}
if o, changed := t.det.Update(at, s.Vec()); changed {
log.Printf("deck turned to %v", o)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
if err := t.sink.DeviceTurned(ctx, o); err != nil {
log.Printf("rotate to %v: %v", o, err)
}
cancel()
}
}
// Lost records that the IMU stopped delivering (device gone, read error).
func (t *Tracker) Lost() {
if t.alive {
t.alive = false
t.sink.SetIMUAvailable(false)
}
}