Skip to content

Commit

Permalink
feat: 添加检查是否支持色温的接口
Browse files Browse the repository at this point in the history
dock插件迁移需要该接口
  • Loading branch information
fuleyi authored and deepin-bot[bot] committed Jun 14, 2024
1 parent 9cde664 commit d71a900
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 8 deletions.
2 changes: 2 additions & 0 deletions display/color_temp.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (m *Manager) setColorTempMode(mode int32) error {
return errors.New("mode out of range, not 0 or 1 or 2")
}
m.setPropColorTemperatureMode(mode)
m.setPropColorTemperatureEnabled(mode != 0)
m.setColorTempModeReal(mode)
m.saveColorTempModeInCfg(mode)
return nil
Expand Down Expand Up @@ -269,6 +270,7 @@ func (m *Manager) applyColorTempConfig(displayMode byte) {
cfg = getDefaultUserMonitorModeConfig()
}
m.setPropColorTemperatureMode(cfg.ColorTemperatureMode)
m.setPropColorTemperatureEnabled(cfg.ColorTemperatureMode != 0)
m.setPropColorTemperatureManual(cfg.ColorTemperatureManual)
m.setColorTempModeReal(m.ColorTemperatureMode)
}
Expand Down
32 changes: 27 additions & 5 deletions display/display_dbusutil.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions display/exported_methods_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions display/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ type Manager struct {
gsColorTemperatureMode int32
// 存在gsetting中的色温值
gsColorTemperatureManual int32

// 不支持调节色温的显卡型号
unsupportGammaDrmList []string
drmSupportGamma bool

ColorTemperatureEnabled bool `prop:"access:rw"`
SupportColorTemperature bool
}

type monitorSizeInfo struct {
Expand All @@ -224,6 +231,9 @@ func newManager(service *dbusutil.Service) *Manager {
monitorMap: make(map[uint32]*Monitor),
Brightness: make(map[string]float64),
redshiftRunner: newRedshiftRunner(),
unsupportGammaDrmList: []string{
"Loongson",
},
}
m.redshiftRunner.cb = func(value int) {
m.setColorTempOneShot()
Expand Down Expand Up @@ -392,6 +402,15 @@ func (m *Manager) initSysDisplay() {
if err != nil {
logger.Warning(err)
}
go func() {
// 依赖dsettings数据,需要在initDSettings后执行
m.drmSupportGamma = m.detectDrmSupportGamma()
if m.drmSupportGamma {
logger.Debug("setColorTempModeReal")
m.setColorTempModeReal(ColorTemperatureModeNone)
}
m.setPropSupportColorTemperature(!_inVM && m.drmSupportGamma)
}()
}

// 处理系统级别的配置更新
Expand Down Expand Up @@ -2966,3 +2985,34 @@ func GetForceScaleFactor() (float64, error) {
}
return 1.0, fmt.Errorf("no valid force-scale-factor")
}

func getLspci() string {
out, err := exec.Command("lspci").Output()
if err != nil {
logger.Warning(err)
return ""
} else {
return string(out)
}
}

func (m *Manager) detectDrmSupportGamma() bool {
pciInfos := strings.Split(getLspci(), "\n")
for _, info := range pciInfos {
if strings.Contains(info, "VGA") {
vgaSupportGamma := true
for _, drm := range m.unsupportGammaDrmList {
lowDrm := strings.ToLower(drm)
lowInfo := strings.ToLower(info)
if strings.Contains(lowInfo, lowDrm) {
vgaSupportGamma = false
break
}
}
if vgaSupportGamma {
return true
}
}
}
return false
}
4 changes: 4 additions & 0 deletions display/manager_ifc.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,7 @@ func (m *Manager) GetRealDisplayMode() (uint8, *dbus.Error) {

return mode, nil
}

func (m *Manager) SupportSetColorTemperature() (bool, *dbus.Error) {
return !(_inVM || !m.drmSupportGamma), nil
}
5 changes: 4 additions & 1 deletion display/xorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ var _hasRandr1d2 bool // 是否 randr 版本大于等于 1.2

var _useWayland bool

func Init(xConn *x.Conn, useWayland bool) {
var _inVM bool

func Init(xConn *x.Conn, useWayland bool, inVM bool) {
_xConn = xConn
_useWayland = useWayland
_inVM = inVM
randrVersion, err := randr.QueryVersion(xConn, randr.MajorVersion, randr.MinorVersion).Reply(xConn)
if err != nil {
logger.Warning(err)
Expand Down
20 changes: 18 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var _xConn *x.Conn

var _useWayland bool

var _inVM bool

var _useKWin bool

func init() {
Expand Down Expand Up @@ -77,7 +79,7 @@ func greeterDisplayMain() {
os.Exit(1)
}
// TODO
display.Init(xConn, false)
display.Init(xConn, false, false)
logger.Debug("greeter mode")
service, err := dbusutil.NewSessionService()
if err != nil {
Expand Down Expand Up @@ -121,7 +123,10 @@ func main() {
logger.Info("in wayland mode")
_useWayland = true
}
display.Init(xConn, _useWayland)

_inVM, err = isInVM()

display.Init(xConn, _useWayland, _inVM)
// TODO
recommendedScaleFactor = display.GetRecommendedScaleFactor()

Expand Down Expand Up @@ -182,3 +187,14 @@ func doSetLogLevel(level log.Priority) {
}
// watchdog.SetLogLevel(level)
}

func isInVM() (bool, error) {
cmd := exec.Command("systemd-detect-virt", "-v", "-q")
err := cmd.Start()
if err != nil {
return false, err
}

err = cmd.Wait()
return err == nil, nil
}

0 comments on commit d71a900

Please sign in to comment.