mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-07 22:18:30 -04:00
gamma: validate config before write and publish state every scheduler
wakeup
fixes #2967
port 1.5
(cherry picked from commit 0c811e3417)
This commit is contained in:
@@ -760,6 +760,9 @@ func (m *Manager) schedulerLoop() {
|
|||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
m.recalcSchedule(now)
|
m.recalcSchedule(now)
|
||||||
|
// publish independent of output readiness so night status never
|
||||||
|
// presents a stale schedule while applies are blocked (#2967)
|
||||||
|
m.updateStateFromSchedule()
|
||||||
|
|
||||||
var waitDur time.Duration
|
var waitDur time.Duration
|
||||||
if enabled {
|
if enabled {
|
||||||
@@ -1120,13 +1123,15 @@ func (m *Manager) SetTemperature(low, high int) error {
|
|||||||
m.configMutex.Unlock()
|
m.configMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m.config.LowTemp = low
|
updated := m.config
|
||||||
m.config.HighTemp = high
|
updated.LowTemp = low
|
||||||
err := m.config.Validate()
|
updated.HighTemp = high
|
||||||
m.configMutex.Unlock()
|
if err := updated.Validate(); err != nil {
|
||||||
if err != nil {
|
m.configMutex.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
m.config = updated
|
||||||
|
m.configMutex.Unlock()
|
||||||
m.triggerUpdate()
|
m.triggerUpdate()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1138,14 +1143,16 @@ func (m *Manager) SetLocation(lat, lon float64) error {
|
|||||||
m.configMutex.Unlock()
|
m.configMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m.config.Latitude = &lat
|
updated := m.config
|
||||||
m.config.Longitude = &lon
|
updated.Latitude = &lat
|
||||||
m.config.UseIPLocation = false
|
updated.Longitude = &lon
|
||||||
err := m.config.Validate()
|
updated.UseIPLocation = false
|
||||||
m.configMutex.Unlock()
|
if err := updated.Validate(); err != nil {
|
||||||
if err != nil {
|
m.configMutex.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
m.config = updated
|
||||||
|
m.configMutex.Unlock()
|
||||||
m.triggerUpdate()
|
m.triggerUpdate()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1180,13 +1187,15 @@ func (m *Manager) SetManualTimes(sunrise, sunset time.Time) error {
|
|||||||
m.configMutex.Unlock()
|
m.configMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m.config.ManualSunrise = &sunrise
|
updated := m.config
|
||||||
m.config.ManualSunset = &sunset
|
updated.ManualSunrise = &sunrise
|
||||||
err := m.config.Validate()
|
updated.ManualSunset = &sunset
|
||||||
m.configMutex.Unlock()
|
if err := updated.Validate(); err != nil {
|
||||||
if err != nil {
|
m.configMutex.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
m.config = updated
|
||||||
|
m.configMutex.Unlock()
|
||||||
m.triggerUpdate()
|
m.triggerUpdate()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1209,12 +1218,14 @@ func (m *Manager) SetGamma(gamma float64) error {
|
|||||||
m.configMutex.Unlock()
|
m.configMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m.config.Gamma = gamma
|
updated := m.config
|
||||||
err := m.config.Validate()
|
updated.Gamma = gamma
|
||||||
m.configMutex.Unlock()
|
if err := updated.Validate(); err != nil {
|
||||||
if err != nil {
|
m.configMutex.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
m.config = updated
|
||||||
|
m.configMutex.Unlock()
|
||||||
m.triggerUpdate()
|
m.triggerUpdate()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
mocks_wlclient "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/wlclient"
|
mocks_wlclient "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/wlclient"
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/proto/wlr_gamma_control"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestManager_ActorSerializesOutputStateAccess(t *testing.T) {
|
func TestManager_ActorSerializesOutputStateAccess(t *testing.T) {
|
||||||
@@ -412,3 +413,75 @@ func TestNewManager_InvalidConfig(t *testing.T) {
|
|||||||
_, err := NewManager(mockDisplay, config)
|
_, err := NewManager(mockDisplay, config)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetters_RejectedValuesLeaveConfigUntouched(t *testing.T) {
|
||||||
|
newManager := func() *Manager {
|
||||||
|
return &Manager{
|
||||||
|
config: DefaultConfig(),
|
||||||
|
updateTrigger: make(chan struct{}, 1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("SetTemperature", func(t *testing.T) {
|
||||||
|
m := newManager()
|
||||||
|
before := m.config
|
||||||
|
|
||||||
|
err := m.SetTemperature(3200, 2500)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, before, m.config)
|
||||||
|
assert.Empty(t, m.updateTrigger)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetLocation", func(t *testing.T) {
|
||||||
|
m := newManager()
|
||||||
|
before := m.config
|
||||||
|
|
||||||
|
err := m.SetLocation(120.0, 10.0)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, before, m.config)
|
||||||
|
assert.Empty(t, m.updateTrigger)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetGamma", func(t *testing.T) {
|
||||||
|
m := newManager()
|
||||||
|
before := m.config
|
||||||
|
|
||||||
|
err := m.SetGamma(-1.0)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, before, m.config)
|
||||||
|
assert.Empty(t, m.updateTrigger)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetters_ValidValuesCommitAndTrigger(t *testing.T) {
|
||||||
|
m := &Manager{
|
||||||
|
config: DefaultConfig(),
|
||||||
|
updateTrigger: make(chan struct{}, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
err := m.SetTemperature(3000, 6000)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, 3000, m.config.LowTemp)
|
||||||
|
assert.Equal(t, 6000, m.config.HighTemp)
|
||||||
|
assert.Len(t, m.updateTrigger, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyGamma_SkipsUnchangedTempAndGamma(t *testing.T) {
|
||||||
|
m := &Manager{config: DefaultConfig()}
|
||||||
|
m.controlsInitialized = true
|
||||||
|
|
||||||
|
out := &outputState{
|
||||||
|
id: 1,
|
||||||
|
rampSize: 256,
|
||||||
|
gammaControl: &wlr_gamma_control.ZwlrGammaControlV1{},
|
||||||
|
lastTemp: 5000,
|
||||||
|
lastGamma: m.config.Gamma,
|
||||||
|
}
|
||||||
|
m.outputs.Store(out.id, out)
|
||||||
|
|
||||||
|
m.applyGamma(5000)
|
||||||
|
|
||||||
|
assert.False(t, out.failed, "unchanged temp must not reach the compositor write path")
|
||||||
|
assert.Equal(t, 5000, out.lastTemp)
|
||||||
|
assert.Equal(t, uint32(256), out.rampSize)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1155,6 +1155,8 @@ Singleton {
|
|||||||
return "Temperature must be between 2500K and 6000K";
|
return "Temperature must be between 2500K and 6000K";
|
||||||
|
|
||||||
const rounded = Math.round(temp / 500) * 500;
|
const rounded = Math.round(temp / 500) * 500;
|
||||||
|
if (rounded > SessionData.nightModeHighTemperature)
|
||||||
|
return "Night temperature must not exceed the day temperature (" + SessionData.nightModeHighTemperature + "K)";
|
||||||
SessionData.setNightModeTemperature(rounded);
|
SessionData.setNightModeTemperature(rounded);
|
||||||
|
|
||||||
if (root.nightModeEnabled) {
|
if (root.nightModeEnabled) {
|
||||||
@@ -1184,6 +1186,8 @@ Singleton {
|
|||||||
return "Temperature must be between 2500K and 6500K";
|
return "Temperature must be between 2500K and 6500K";
|
||||||
|
|
||||||
const rounded = Math.round(temp / 500) * 500;
|
const rounded = Math.round(temp / 500) * 500;
|
||||||
|
if (rounded < SessionData.nightModeTemperature)
|
||||||
|
return "Day temperature must be at least the night temperature (" + SessionData.nightModeTemperature + "K)";
|
||||||
SessionData.setNightModeHighTemperature(rounded);
|
SessionData.setNightModeHighTemperature(rounded);
|
||||||
|
|
||||||
if (root.nightModeEnabled && SessionData.nightModeAutoEnabled)
|
if (root.nightModeEnabled && SessionData.nightModeAutoEnabled)
|
||||||
|
|||||||
Reference in New Issue
Block a user