mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
gamma: fix transition on enable
This commit is contained in:
@@ -562,53 +562,62 @@ func (m *Manager) transitionWorker() {
|
|||||||
case <-m.stopChan:
|
case <-m.stopChan:
|
||||||
return
|
return
|
||||||
case targetTemp := <-m.transitionChan:
|
case targetTemp := <-m.transitionChan:
|
||||||
|
m.runTransition(targetTemp, steps, stepDur)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) runTransition(targetTemp int, steps int, stepDur time.Duration) {
|
||||||
|
for {
|
||||||
m.transitionMutex.Lock()
|
m.transitionMutex.Lock()
|
||||||
currentTemp := m.currentTemp
|
currentTemp := m.currentTemp
|
||||||
m.targetTemp = targetTemp
|
m.targetTemp = targetTemp
|
||||||
m.transitionMutex.Unlock()
|
m.transitionMutex.Unlock()
|
||||||
|
|
||||||
if currentTemp == targetTemp {
|
if currentTemp == targetTemp {
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Starting smooth transition: %dK -> %dK over %v", currentTemp, targetTemp, dur)
|
log.Debugf("Starting smooth transition: %dK -> %dK over %v", currentTemp, targetTemp, stepDur*time.Duration(steps))
|
||||||
|
|
||||||
stepLoop:
|
redirected := false
|
||||||
for i := 0; i <= steps; i++ {
|
for i := 0; i <= steps; i++ {
|
||||||
select {
|
select {
|
||||||
case newTarget := <-m.transitionChan:
|
case newTarget := <-m.transitionChan:
|
||||||
m.transitionMutex.Lock()
|
m.transitionMutex.Lock()
|
||||||
m.targetTemp = newTarget
|
m.targetTemp = newTarget
|
||||||
m.transitionMutex.Unlock()
|
m.transitionMutex.Unlock()
|
||||||
log.Debugf("Transition %dK -> %dK aborted (newer transition started)", currentTemp, targetTemp)
|
if newTarget != targetTemp {
|
||||||
break stepLoop
|
log.Debugf("Transition %dK -> %dK redirected to %dK", currentTemp, targetTemp, newTarget)
|
||||||
|
targetTemp = newTarget
|
||||||
|
redirected = true
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
m.transitionMutex.RLock()
|
if redirected {
|
||||||
if m.targetTemp != targetTemp {
|
|
||||||
m.transitionMutex.RUnlock()
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.transitionMutex.RLock()
|
||||||
|
currentTarget := m.targetTemp
|
||||||
m.transitionMutex.RUnlock()
|
m.transitionMutex.RUnlock()
|
||||||
|
|
||||||
|
if currentTarget != targetTemp {
|
||||||
|
targetTemp = currentTarget
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
progress := float64(i) / float64(steps)
|
progress := float64(i) / float64(steps)
|
||||||
temp := currentTemp + int(float64(targetTemp-currentTemp)*progress)
|
temp := currentTemp + int(float64(targetTemp-currentTemp)*progress)
|
||||||
|
|
||||||
m.post(func() { m.applyNowOnActor(temp) })
|
m.post(func() { m.applyNowOnActor(temp) })
|
||||||
|
|
||||||
if i < steps {
|
if i == steps {
|
||||||
time.Sleep(stepDur)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m.transitionMutex.RLock()
|
|
||||||
finalTarget := m.targetTemp
|
|
||||||
m.transitionMutex.RUnlock()
|
|
||||||
|
|
||||||
if finalTarget == targetTemp {
|
|
||||||
log.Debugf("Transition complete: now at %dK", targetTemp)
|
log.Debugf("Transition complete: now at %dK", targetTemp)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(stepDur)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1206,17 +1215,18 @@ func (m *Manager) SetGamma(gamma float64) error {
|
|||||||
|
|
||||||
func (m *Manager) SetEnabled(enabled bool) {
|
func (m *Manager) SetEnabled(enabled bool) {
|
||||||
m.configMutex.Lock()
|
m.configMutex.Lock()
|
||||||
|
wasEnabled := m.config.Enabled
|
||||||
m.config.Enabled = enabled
|
m.config.Enabled = enabled
|
||||||
|
highTemp := m.config.HighTemp
|
||||||
m.configMutex.Unlock()
|
m.configMutex.Unlock()
|
||||||
|
|
||||||
if enabled {
|
if enabled {
|
||||||
targetTemp := m.calculateTemperature(time.Now())
|
if !m.controlsInitialized {
|
||||||
m.transitionMutex.Lock()
|
m.transitionMutex.Lock()
|
||||||
m.currentTemp = targetTemp
|
m.currentTemp = highTemp
|
||||||
m.targetTemp = targetTemp
|
m.targetTemp = highTemp
|
||||||
m.transitionMutex.Unlock()
|
m.transitionMutex.Unlock()
|
||||||
|
|
||||||
if !m.controlsInitialized {
|
|
||||||
m.post(func() {
|
m.post(func() {
|
||||||
log.Info("Creating gamma controls")
|
log.Info("Creating gamma controls")
|
||||||
gammaMgr := m.gammaControl.(*wlr_gamma_control.ZwlrGammaControlManagerV1)
|
gammaMgr := m.gammaControl.(*wlr_gamma_control.ZwlrGammaControlManagerV1)
|
||||||
@@ -1227,9 +1237,10 @@ func (m *Manager) SetEnabled(enabled bool) {
|
|||||||
log.Errorf("Failed to create gamma controls: %v", err)
|
log.Errorf("Failed to create gamma controls: %v", err)
|
||||||
} else {
|
} else {
|
||||||
m.controlsInitialized = true
|
m.controlsInitialized = true
|
||||||
|
m.triggerUpdate()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else if !wasEnabled {
|
||||||
m.triggerUpdate()
|
m.triggerUpdate()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user