Skip to content

Commit d71a900

Browse files
fly602deepin-bot[bot]
authored andcommitted
feat: 添加检查是否支持色温的接口
dock插件迁移需要该接口
1 parent 9cde664 commit d71a900

7 files changed

Lines changed: 110 additions & 8 deletions

File tree

display/color_temp.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (m *Manager) setColorTempMode(mode int32) error {
3838
return errors.New("mode out of range, not 0 or 1 or 2")
3939
}
4040
m.setPropColorTemperatureMode(mode)
41+
m.setPropColorTemperatureEnabled(mode != 0)
4142
m.setColorTempModeReal(mode)
4243
m.saveColorTempModeInCfg(mode)
4344
return nil
@@ -269,6 +270,7 @@ func (m *Manager) applyColorTempConfig(displayMode byte) {
269270
cfg = getDefaultUserMonitorModeConfig()
270271
}
271272
m.setPropColorTemperatureMode(cfg.ColorTemperatureMode)
273+
m.setPropColorTemperatureEnabled(cfg.ColorTemperatureMode != 0)
272274
m.setPropColorTemperatureManual(cfg.ColorTemperatureManual)
273275
m.setColorTempModeReal(m.ColorTemperatureMode)
274276
}

display/display_dbusutil.go

Lines changed: 27 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

display/exported_methods_auto.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

display/manager.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ type Manager struct {
209209
gsColorTemperatureMode int32
210210
// 存在gsetting中的色温值
211211
gsColorTemperatureManual int32
212+
213+
// 不支持调节色温的显卡型号
214+
unsupportGammaDrmList []string
215+
drmSupportGamma bool
216+
217+
ColorTemperatureEnabled bool `prop:"access:rw"`
218+
SupportColorTemperature bool
212219
}
213220

214221
type monitorSizeInfo struct {
@@ -224,6 +231,9 @@ func newManager(service *dbusutil.Service) *Manager {
224231
monitorMap: make(map[uint32]*Monitor),
225232
Brightness: make(map[string]float64),
226233
redshiftRunner: newRedshiftRunner(),
234+
unsupportGammaDrmList: []string{
235+
"Loongson",
236+
},
227237
}
228238
m.redshiftRunner.cb = func(value int) {
229239
m.setColorTempOneShot()
@@ -392,6 +402,15 @@ func (m *Manager) initSysDisplay() {
392402
if err != nil {
393403
logger.Warning(err)
394404
}
405+
go func() {
406+
// 依赖dsettings数据,需要在initDSettings后执行
407+
m.drmSupportGamma = m.detectDrmSupportGamma()
408+
if m.drmSupportGamma {
409+
logger.Debug("setColorTempModeReal")
410+
m.setColorTempModeReal(ColorTemperatureModeNone)
411+
}
412+
m.setPropSupportColorTemperature(!_inVM && m.drmSupportGamma)
413+
}()
395414
}
396415

397416
// 处理系统级别的配置更新
@@ -2966,3 +2985,34 @@ func GetForceScaleFactor() (float64, error) {
29662985
}
29672986
return 1.0, fmt.Errorf("no valid force-scale-factor")
29682987
}
2988+
2989+
func getLspci() string {
2990+
out, err := exec.Command("lspci").Output()
2991+
if err != nil {
2992+
logger.Warning(err)
2993+
return ""
2994+
} else {
2995+
return string(out)
2996+
}
2997+
}
2998+
2999+
func (m *Manager) detectDrmSupportGamma() bool {
3000+
pciInfos := strings.Split(getLspci(), "\n")
3001+
for _, info := range pciInfos {
3002+
if strings.Contains(info, "VGA") {
3003+
vgaSupportGamma := true
3004+
for _, drm := range m.unsupportGammaDrmList {
3005+
lowDrm := strings.ToLower(drm)
3006+
lowInfo := strings.ToLower(info)
3007+
if strings.Contains(lowInfo, lowDrm) {
3008+
vgaSupportGamma = false
3009+
break
3010+
}
3011+
}
3012+
if vgaSupportGamma {
3013+
return true
3014+
}
3015+
}
3016+
}
3017+
return false
3018+
}

display/manager_ifc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,7 @@ func (m *Manager) GetRealDisplayMode() (uint8, *dbus.Error) {
311311

312312
return mode, nil
313313
}
314+
315+
func (m *Manager) SupportSetColorTemperature() (bool, *dbus.Error) {
316+
return !(_inVM || !m.drmSupportGamma), nil
317+
}

display/xorg.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ var _hasRandr1d2 bool // 是否 randr 版本大于等于 1.2
2525

2626
var _useWayland bool
2727

28-
func Init(xConn *x.Conn, useWayland bool) {
28+
var _inVM bool
29+
30+
func Init(xConn *x.Conn, useWayland bool, inVM bool) {
2931
_xConn = xConn
3032
_useWayland = useWayland
33+
_inVM = inVM
3134
randrVersion, err := randr.QueryVersion(xConn, randr.MajorVersion, randr.MinorVersion).Reply(xConn)
3235
if err != nil {
3336
logger.Warning(err)

main.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ var _xConn *x.Conn
3737

3838
var _useWayland bool
3939

40+
var _inVM bool
41+
4042
var _useKWin bool
4143

4244
func init() {
@@ -77,7 +79,7 @@ func greeterDisplayMain() {
7779
os.Exit(1)
7880
}
7981
// TODO
80-
display.Init(xConn, false)
82+
display.Init(xConn, false, false)
8183
logger.Debug("greeter mode")
8284
service, err := dbusutil.NewSessionService()
8385
if err != nil {
@@ -121,7 +123,10 @@ func main() {
121123
logger.Info("in wayland mode")
122124
_useWayland = true
123125
}
124-
display.Init(xConn, _useWayland)
126+
127+
_inVM, err = isInVM()
128+
129+
display.Init(xConn, _useWayland, _inVM)
125130
// TODO
126131
recommendedScaleFactor = display.GetRecommendedScaleFactor()
127132

@@ -182,3 +187,14 @@ func doSetLogLevel(level log.Priority) {
182187
}
183188
// watchdog.SetLogLevel(level)
184189
}
190+
191+
func isInVM() (bool, error) {
192+
cmd := exec.Command("systemd-detect-virt", "-v", "-q")
193+
err := cmd.Start()
194+
if err != nil {
195+
return false, err
196+
}
197+
198+
err = cmd.Wait()
199+
return err == nil, nil
200+
}

0 commit comments

Comments
 (0)